-
Notifications
You must be signed in to change notification settings - Fork 37
/
dxvk-async.patch
283 lines (248 loc) · 9.8 KB
/
dxvk-async.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
diff --git a/meson.build b/meson.build
index f044c8f4..36b22d39 100644
--- a/meson.build
+++ b/meson.build
@@ -122,7 +122,7 @@ glsl_generator = generator(glsl_compiler,
)
dxvk_version = vcs_tag(
- command: ['git', 'describe', '--dirty=+'],
+ command: ['git', 'describe', '--dirty=-async'],
input: 'version.h.in',
output: 'version.h',
)
diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp
index 6486d267..cc59297e 100644
--- a/src/dxvk/dxvk_context.cpp
+++ b/src/dxvk/dxvk_context.cpp
@@ -4540,7 +4540,8 @@ namespace dxvk {
: DxvkContextFlag::GpDirtyRasterizerState);
// Retrieve and bind actual Vulkan pipeline handle
- auto pipelineInfo = m_state.gp.pipeline->getPipelineHandle(m_state.gp.state);
+ auto pipelineInfo = m_state.gp.pipeline->getPipelineHandle(
+ m_state.gp.state, this->checkAsyncCompilationCompat());
if (unlikely(!pipelineInfo.first))
return false;
@@ -4890,7 +4891,7 @@ namespace dxvk {
}
- void DxvkContext::updateFramebuffer() {
+ void DxvkContext::updateFramebuffer(bool isDraw) {
if (m_flags.test(DxvkContextFlag::GpDirtyFramebuffer)) {
m_flags.clr(DxvkContextFlag::GpDirtyFramebuffer);
@@ -4914,6 +4915,11 @@ namespace dxvk {
m_state.gp.state.omSwizzle[i] = DxvkOmAttachmentSwizzle(mapping);
}
+ if (isDraw) {
+ for (uint32_t i = 0; i < fbInfo.numAttachments(); i++)
+ fbInfo.getAttachment(i).view->setRtBindingFrameId(m_device->getCurrentFrameId());
+ }
+
m_flags.set(DxvkContextFlag::GpDirtyPipelineState);
}
}
@@ -5363,7 +5369,7 @@ namespace dxvk {
}
if (m_flags.test(DxvkContextFlag::GpDirtyFramebuffer))
- this->updateFramebuffer();
+ this->updateFramebuffer(true);
if (!m_flags.test(DxvkContextFlag::GpRenderPassBound))
this->startRenderPass();
@@ -5774,6 +5780,14 @@ namespace dxvk {
return true;
}
+ bool DxvkContext::checkAsyncCompilationCompat() {
+ bool fbCompat = true;
+ for (uint32_t i = 0; fbCompat && i < m_state.om.framebufferInfo.numAttachments(); i++) {
+ const auto& attachment = m_state.om.framebufferInfo.getAttachment(i);
+ fbCompat &= attachment.view->getRtBindingAsyncCompilationCompat();
+ }
+ return fbCompat;
+ }
DxvkGraphicsPipeline* DxvkContext::lookupGraphicsPipeline(
const DxvkGraphicsPipelineShaders& shaders) {
diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h
index fe24c556..0930bd81 100644
--- a/src/dxvk/dxvk_context.h
+++ b/src/dxvk/dxvk_context.h
@@ -1493,7 +1493,7 @@ namespace dxvk {
DxvkFramebufferInfo makeFramebufferInfo(
const DxvkRenderTargets& renderTargets);
- void updateFramebuffer();
+ void updateFramebuffer(bool isDraw = false);
void applyRenderTargetLoadLayouts();
@@ -1576,6 +1576,8 @@ namespace dxvk {
const Rc<DxvkBuffer>& buffer,
VkDeviceSize copySize);
+ bool checkAsyncCompilationCompat();
+
DxvkGraphicsPipeline* lookupGraphicsPipeline(
const DxvkGraphicsPipelineShaders& shaders);
diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp
index c0ecbbb4..f4e4fd4f 100644
--- a/src/dxvk/dxvk_graphics.cpp
+++ b/src/dxvk/dxvk_graphics.cpp
@@ -899,7 +899,8 @@ namespace dxvk {
std::pair<VkPipeline, DxvkGraphicsPipelineType> DxvkGraphicsPipeline::getPipelineHandle(
- const DxvkGraphicsPipelineStateInfo& state) {
+ const DxvkGraphicsPipelineStateInfo& state,
+ bool async) {
DxvkGraphicsPipelineInstance* instance = this->findInstance(state);
if (unlikely(!instance)) {
@@ -907,28 +908,36 @@ namespace dxvk {
if (!this->validatePipelineState(state, true))
return std::make_pair(VK_NULL_HANDLE, DxvkGraphicsPipelineType::FastPipeline);
+ bool useAsync = m_device->config().enableAsync && async;
+
// Prevent other threads from adding new instances and check again
- std::unique_lock<dxvk::mutex> lock(m_mutex);
+ std::unique_lock<dxvk::mutex> lock(useAsync ? m_asyncMutex : m_mutex);
instance = this->findInstance(state);
if (!instance) {
- // Keep pipeline object locked, at worst we're going to stall
- // a state cache worker and the current thread needs priority.
- bool canCreateBasePipeline = this->canCreateBasePipeline(state);
- instance = this->createInstance(state, canCreateBasePipeline);
-
- // Unlock here since we may dispatch the pipeline to a worker,
- // which will then acquire it to increment the use counter.
- lock.unlock();
-
- // If necessary, compile an optimized pipeline variant
- if (!instance->fastHandle.load())
+ if (useAsync) {
+ lock.unlock();
m_workers->compileGraphicsPipeline(this, state);
-
- // Only store pipelines in the state cache that cannot benefit
- // from pipeline libraries, or if that feature is disabled.
- if (!canCreateBasePipeline)
- this->writePipelineStateToCache(state);
+ return std::make_pair(VK_NULL_HANDLE, DxvkGraphicsPipelineType::FastPipeline);
+ } else {
+ // Keep pipeline object locked, at worst we're going to stall
+ // a state cache worker and the current thread needs priority.
+ bool canCreateBasePipeline = this->canCreateBasePipeline(state);
+ instance = this->createInstance(state, canCreateBasePipeline);
+
+ // Unlock here since we may dispatch the pipeline to a worker,
+ // which will then acquire it to increment the use counter.
+ lock.unlock();
+
+ // If necessary, compile an optimized pipeline variant
+ if (!instance->fastHandle.load())
+ m_workers->compileGraphicsPipeline(this, state);
+
+ // Only store pipelines in the state cache that cannot benefit
+ // from pipeline libraries, or if that feature is disabled.
+ if (!canCreateBasePipeline)
+ this->writePipelineStateToCache(state);
+ }
}
}
diff --git a/src/dxvk/dxvk_graphics.h b/src/dxvk/dxvk_graphics.h
index cfc424cd..437c73a9 100644
--- a/src/dxvk/dxvk_graphics.h
+++ b/src/dxvk/dxvk_graphics.h
@@ -521,10 +521,12 @@ namespace dxvk {
* Retrieves a pipeline handle for the given pipeline
* state. If necessary, a new pipeline will be created.
* \param [in] state Pipeline state vector
+ * \param [in] async Compile asynchronously
* \returns Pipeline handle and handle type
*/
std::pair<VkPipeline, DxvkGraphicsPipelineType> getPipelineHandle(
- const DxvkGraphicsPipelineStateInfo& state);
+ const DxvkGraphicsPipelineStateInfo& state,
+ bool async);
/**
* \brief Compiles a pipeline
@@ -576,6 +578,8 @@ namespace dxvk {
alignas(CACHE_LINE_SIZE)
dxvk::mutex m_mutex;
+ alignas(CACHE_LINE_SIZE)
+ dxvk::mutex m_asyncMutex;
sync::List<DxvkGraphicsPipelineInstance> m_pipelines;
uint32_t m_useCount = 0;
diff --git a/src/dxvk/dxvk_image.h b/src/dxvk/dxvk_image.h
index 285c5e9e..989a240f 100644
--- a/src/dxvk/dxvk_image.h
+++ b/src/dxvk/dxvk_image.h
@@ -547,6 +547,37 @@ namespace dxvk {
view->imageSubresources());
}
+ /**
+ * \brief Sets render target usage frame number
+ *
+ * The image view will track internally when
+ * it was last used as a render target. This
+ * info is used for async shader compilation.
+ * \param [in] frameId Frame number
+ */
+ void setRtBindingFrameId(uint32_t frameId) {
+ if (frameId != m_rtBindingFrameId) {
+ if (frameId == m_rtBindingFrameId + 1)
+ m_rtBindingFrameCount += 1;
+ else
+ m_rtBindingFrameCount = 0;
+
+ m_rtBindingFrameId = frameId;
+ }
+ }
+
+ /**
+ * \brief Checks for async pipeline compatibility
+ *
+ * Asynchronous pipeline compilation may be enabled if the
+ * render target has been drawn to in the previous frames.
+ * \param [in] frameId Current frame ID
+ * \returns \c true if async compilation is supported
+ */
+ bool getRtBindingAsyncCompilationCompat() const {
+ return m_rtBindingFrameCount >= 5;
+ }
+
private:
Rc<vk::DeviceFn> m_vkd;
@@ -555,6 +586,9 @@ namespace dxvk {
DxvkImageViewCreateInfo m_info;
VkImageView m_views[ViewCount];
+ uint32_t m_rtBindingFrameId = 0;
+ uint32_t m_rtBindingFrameCount = 0;
+
void createView(VkImageViewType type, uint32_t numLayers);
};
diff --git a/src/dxvk/dxvk_options.cpp b/src/dxvk/dxvk_options.cpp
index 00f284aa..f13429eb 100644
--- a/src/dxvk/dxvk_options.cpp
+++ b/src/dxvk/dxvk_options.cpp
@@ -10,6 +10,14 @@ namespace dxvk {
trackPipelineLifetime = config.getOption<Tristate>("dxvk.trackPipelineLifetime", Tristate::Auto);
useRawSsbo = config.getOption<Tristate>("dxvk.useRawSsbo", Tristate::Auto);
hud = config.getOption<std::string>("dxvk.hud", "");
+
+ if (env::getEnvVar("DXVK_ASYNC") == "1")
+ enableAsync = true;
+ else
+ enableAsync = config.getOption<bool>("dxvk.enableAsync", false);
+
+ if (enableAsync)
+ enableGraphicsPipelineLibrary = Tristate::False;
}
}
diff --git a/src/dxvk/dxvk_options.h b/src/dxvk/dxvk_options.h
index da5bf406..05a7823e 100644
--- a/src/dxvk/dxvk_options.h
+++ b/src/dxvk/dxvk_options.h
@@ -2,6 +2,8 @@
#include "../util/config/config.h"
+#include "dxvk_include.h"
+
namespace dxvk {
struct DxvkOptions {
@@ -24,6 +26,9 @@ namespace dxvk {
/// Enables pipeline lifetime tracking
Tristate trackPipelineLifetime;
+ // Enable async pipelines
+ bool enableAsync;
+
/// Shader-related options
Tristate useRawSsbo;