-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpushdesc.diff
542 lines (504 loc) · 22.4 KB
/
pushdesc.diff
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
diff --git a/3rdparty/wil b/3rdparty/wil
--- a/3rdparty/wil
+++ b/3rdparty/wil
@@ -1 +1 @@
-Subproject commit 3018875eaa4f8e3d86cf2da97fd577bae59f3aec
+Subproject commit 3018875eaa4f8e3d86cf2da97fd577bae59f3aec-dirty
diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl
index 6b6a683e1..72353f40d 100644
--- a/bin/resources/shaders/vulkan/tfx.glsl
+++ b/bin/resources/shaders/vulkan/tfx.glsl
@@ -350,16 +350,16 @@ layout(set = 1, binding = 1) uniform texture2D Palette;
#if PS_FEEDBACK_LOOP_IS_NEEDED
#if defined(DISABLE_TEXTURE_BARRIER)
- layout(set = 2, binding = 0) uniform texture2D RtSampler;
+ layout(set = 1, binding = 2) uniform texture2D RtSampler;
vec4 sample_from_rt() { return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); }
#else
- layout(input_attachment_index = 0, set = 2, binding = 0) uniform subpassInput RtSampler;
+ layout(input_attachment_index = 0, set = 1, binding = 2) uniform subpassInput RtSampler;
vec4 sample_from_rt() { return subpassLoad(RtSampler); }
#endif
#endif
#if PS_DATE > 0
-layout(set = 2, binding = 1) uniform texture2D PrimMinTexture;
+layout(set = 1, binding = 3) uniform texture2D PrimMinTexture;
#endif
#if NEEDS_TEX
diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
index ea7be9f68..30c6f0375 100644
--- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
+++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
@@ -597,20 +597,6 @@ static void SafeDestroyDescriptorSetLayout(VkDevice dev, VkDescriptorSetLayout&
VkFenceCreateInfo fence_info = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
res = vkCreateFence(m_device, &fence_info, nullptr, &resources.fence);
- if (res != VK_SUCCESS)
- return false;
- // TODO: A better way to choose the number of descriptors.
- VkDescriptorPoolSize pool_sizes[] = {
- {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_COMBINED_IMAGE_SAMPLER_DESCRIPTORS_PER_FRAME},
- {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_SAMPLED_IMAGE_DESCRIPTORS_PER_FRAME},
- {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MAX_STORAGE_IMAGE_DESCRIPTORS_PER_FRAME},
- {VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, MAX_INPUT_ATTACHMENT_IMAGE_DESCRIPTORS_PER_FRAME},
- };
-
- VkDescriptorPoolCreateInfo pool_create_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, nullptr, 0,
- MAX_DESCRIPTOR_SETS_PER_FRAME, static_cast<u32>(std::size(pool_sizes)), pool_sizes};
-
- res = vkCreateDescriptorPool(m_device, &pool_create_info, nullptr, &resources.descriptor_pool);
if (res != VK_SUCCESS)
return false;
@@ -635,11 +621,6 @@ static void SafeDestroyDescriptorSetLayout(VkDevice dev, VkDescriptorSetLayout&
vkDestroyFence(m_device, resources.fence, nullptr);
resources.fence = VK_NULL_HANDLE;
}
- if (resources.descriptor_pool != VK_NULL_HANDLE)
- {
- vkDestroyDescriptorPool(m_device, resources.descriptor_pool, nullptr);
- resources.descriptor_pool = VK_NULL_HANDLE;
- }
if (resources.command_buffers[0] != VK_NULL_HANDLE)
{
vkFreeCommandBuffers(m_device, resources.command_pool,
@@ -759,23 +740,6 @@ static void SafeDestroyDescriptorSetLayout(VkDevice dev, VkDescriptorSetLayout&
return buf;
}
- VkDescriptorSet GSDeviceVK::AllocateDescriptorSet(VkDescriptorSetLayout set_layout)
- {
- VkDescriptorSetAllocateInfo allocate_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
- nullptr,
- m_frame_resources[m_current_frame].descriptor_pool,
- 1,
- &set_layout};
-
- VkDescriptorSet descriptor_set;
- VkResult res = vkAllocateDescriptorSets(vk_init_info.device, &allocate_info, &descriptor_set);
- // Failing to allocate a descriptor set is not a fatal error, we can
- // recover by moving to the next command buffer.
- if (res != VK_SUCCESS)
- return VK_NULL_HANDLE;
- return descriptor_set;
- }
-
VkDescriptorSet GSDeviceVK::AllocatePersistentDescriptorSet(VkDescriptorSetLayout set_layout)
{
VkDescriptorSetAllocateInfo allocate_info = {
@@ -915,9 +879,6 @@ static void SafeDestroyDescriptorSetLayout(VkDevice dev, VkDescriptorSetLayout&
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, nullptr};
vkBeginCommandBuffer(resources.command_buffers[1], &begin_info);
- // Also can do the same for the descriptor pools
- vkResetDescriptorPool(m_device, resources.descriptor_pool, 0);
-
resources.fence_counter = m_next_fence_counter++;
resources.init_buffer_used = false;
@@ -2186,7 +2147,7 @@ void GSDeviceVK::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector
if (vkRt->GetLayout() != GSTextureVK::Layout::FeedbackLoop)
{
// need to update descriptors to reflect the new layout
- m_dirty_flags |= DIRTY_FLAG_TFX_SAMPLERS_DS;
+ m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << TFX_TEXTURE_RT);
vkRt->TransitionToLayout(GSTextureVK::Layout::FeedbackLoop);
}
}
@@ -2202,7 +2163,8 @@ void GSDeviceVK::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector
{
if (vkDs->GetLayout() != GSTextureVK::Layout::FeedbackLoop)
{
- m_dirty_flags |= DIRTY_FLAG_TFX_SAMPLERS_DS;
+ m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << TFX_TEXTURE_TEXTURE);
+
vkDs->TransitionToLayout(GSTextureVK::Layout::FeedbackLoop);
}
}
@@ -2412,7 +2374,8 @@ bool GSDeviceVK::CreatePipelineLayouts()
// Convert Pipeline Layout
//////////////////////////////////////////////////////////////////////////
- dslb.AddBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, NUM_CONVERT_SAMPLERS, VK_SHADER_STAGE_FRAGMENT_BIT);
+ dslb.SetPushFlag();
+ dslb.AddBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, NUM_UTILITY_SAMPLERS, VK_SHADER_STAGE_FRAGMENT_BIT);
if ((m_utility_ds_layout = dslb.Create(dev)) == VK_NULL_HANDLE)
return false;
@@ -2431,22 +2394,21 @@ bool GSDeviceVK::CreatePipelineLayouts()
dslb.AddBinding(2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT);
if ((m_tfx_ubo_ds_layout = dslb.Create(dev)) == VK_NULL_HANDLE)
return false;
- dslb.AddBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
- dslb.AddBinding(1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
- if ((m_tfx_sampler_ds_layout = dslb.Create(dev)) == VK_NULL_HANDLE)
- return false;
- dslb.AddBinding(0,
- m_features.texture_barrier
+
+ dslb.SetPushFlag();
+ dslb.AddBinding(TFX_TEXTURE_TEXTURE, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
+ dslb.AddBinding(TFX_TEXTURE_PALETTE, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
+ dslb.AddBinding(TFX_TEXTURE_RT,
+ (m_features.texture_barrier)
? VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1, VK_SHADER_STAGE_FRAGMENT_BIT);
- dslb.AddBinding(1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
- if ((m_tfx_rt_texture_ds_layout = dslb.Create(dev)) == VK_NULL_HANDLE)
+ dslb.AddBinding(TFX_TEXTURE_PRIMID, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
+ if ((m_tfx_texture_ds_layout = dslb.Create(dev)) == VK_NULL_HANDLE)
return false;
plb.AddDescriptorSet(m_tfx_ubo_ds_layout);
- plb.AddDescriptorSet(m_tfx_sampler_ds_layout);
- plb.AddDescriptorSet(m_tfx_rt_texture_ds_layout);
+ plb.AddDescriptorSet(m_tfx_texture_ds_layout);
if ((m_tfx_pipeline_layout = plb.Create(dev)) == VK_NULL_HANDLE)
return false;
return true;
@@ -2992,8 +2954,7 @@ void GSDeviceVK::DestroyResources()
}
SafeDestroyPipelineLayout(m_device, m_tfx_pipeline_layout);
- SafeDestroyDescriptorSetLayout(m_device, m_tfx_rt_texture_ds_layout);
- SafeDestroyDescriptorSetLayout(m_device, m_tfx_sampler_ds_layout);
+ SafeDestroyDescriptorSetLayout(m_device, m_tfx_texture_ds_layout);
SafeDestroyDescriptorSetLayout(m_device, m_tfx_ubo_ds_layout);
SafeDestroyPipelineLayout(m_device, m_utility_pipeline_layout);
SafeDestroyDescriptorSetLayout(m_device, m_utility_ds_layout);
@@ -3317,11 +3278,9 @@ void GSDeviceVK::ExecuteCommandBufferAndRestartRenderPass(bool wait_for_completi
void GSDeviceVK::InvalidateCachedState()
{
- m_dirty_flags |= DIRTY_FLAG_TFX_SAMPLERS_DS | DIRTY_FLAG_TFX_RT_TEXTURE_DS | DIRTY_FLAG_TFX_UBO |
- DIRTY_FLAG_UTILITY_TEXTURE | DIRTY_FLAG_BLEND_CONSTANTS | DIRTY_FLAG_LINE_WIDTH |
- DIRTY_FLAG_INDEX_BUFFER | DIRTY_FLAG_VIEWPORT | DIRTY_FLAG_SCISSOR | DIRTY_FLAG_PIPELINE |
- DIRTY_FLAG_VS_CONSTANT_BUFFER | DIRTY_FLAG_PS_CONSTANT_BUFFER;
-
+ m_dirty_flags = ALL_DIRTY_STATE;
+ if (m_index_buffer != VK_NULL_HANDLE)
+ m_dirty_flags |= DIRTY_FLAG_INDEX_BUFFER;
for (u32 i = 0; i < NUM_TFX_TEXTURES; i++)
m_tfx_textures[i] = m_null_texture.get();
m_utility_texture = m_null_texture.get();
@@ -3386,7 +3345,7 @@ void GSDeviceVK::PSSetShaderResource(int i, GSTexture* sr, bool check_state)
m_tfx_textures[i] = vkTex;
- m_dirty_flags |= (i < 2) ? DIRTY_FLAG_TFX_SAMPLERS_DS : DIRTY_FLAG_TFX_RT_TEXTURE_DS;
+ m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << i);
}
void GSDeviceVK::PSSetSampler(GSHWDrawConfig::SamplerSelector sel)
@@ -3396,7 +3355,7 @@ void GSDeviceVK::PSSetSampler(GSHWDrawConfig::SamplerSelector sel)
m_tfx_sampler_sel = sel.key;
m_tfx_sampler = GetSampler(sel);
- m_dirty_flags |= DIRTY_FLAG_TFX_SAMPLERS_DS;
+ m_dirty_flags |= DIRTY_FLAG_TFX_TEXTURE_0;
}
void GSDeviceVK::SetUtilityTexture(GSTexture* tex, VkSampler sampler)
@@ -3432,7 +3391,7 @@ void GSDeviceVK::UnbindTexture(GSTextureVK* tex)
if (m_tfx_textures[i] == tex)
{
m_tfx_textures[i] = m_null_texture.get();
- m_dirty_flags |= (i < 2) ? DIRTY_FLAG_TFX_SAMPLERS_DS : DIRTY_FLAG_TFX_RT_TEXTURE_DS;
+ m_dirty_flags |= (DIRTY_FLAG_TFX_TEXTURE_0 << i);
}
}
if (m_utility_texture == tex)
@@ -3623,118 +3582,62 @@ bool GSDeviceVK::ApplyTFXState(bool already_execed)
Vulkan::DescriptorSetUpdateBuilder dsub;
- VkDescriptorSet dsets[NUM_TFX_DESCRIPTOR_SETS];
- u32 num_dsets = 0;
- u32 start_dset = 0;
- const bool layout_changed = (m_current_pipeline_layout != PipelineLayout::TFX);
-
- if (!layout_changed && flags & DIRTY_FLAG_TFX_UBO)
- dsets[num_dsets++] = m_tfx_ubo_descriptor_set;
-
- if ((flags & DIRTY_FLAG_TFX_SAMPLERS_DS) || m_tfx_texture_descriptor_set == VK_NULL_HANDLE)
+ if (m_current_pipeline_layout != PipelineLayout::TFX)
{
- m_tfx_texture_descriptor_set = AllocateDescriptorSet(m_tfx_sampler_ds_layout);
- if (m_tfx_texture_descriptor_set == VK_NULL_HANDLE)
- {
- if (already_execed)
- {
- Console.Error("Failed to allocate TFX texture descriptors");
- return false;
- }
-
- /* Ran out of TFX texture descriptors */
- ExecuteCommandBufferAndRestartRenderPass(false);
- return ApplyTFXState(true);
- }
-
- dsub.AddCombinedImageSamplerDescriptorWrite(
- m_tfx_texture_descriptor_set, 0, m_tfx_textures[0]->GetView(), m_tfx_sampler, m_tfx_textures[0]->GetVkLayout());
- dsub.AddImageDescriptorWrite(m_tfx_texture_descriptor_set, 1, m_tfx_textures[1]->GetView(), m_tfx_textures[1]->GetVkLayout());
- dsub.Update(vk_init_info.device);
+ m_current_pipeline_layout = PipelineLayout::TFX;
+ flags |= DIRTY_FLAG_TFX_UBO | DIRTY_FLAG_TFX_TEXTURES;
- if (!layout_changed)
- {
- start_dset = (num_dsets == 0) ?
- TFX_DESCRIPTOR_SET_TEXTURES : start_dset;
- dsets[num_dsets++] = m_tfx_texture_descriptor_set;
- }
+ // Clear out the RT binding if feedback loop isn't on, because it'll be in the wrong state and make
+ // the validation layer cranky. Not a big deal since we need to write it anyway.
+ const GSTextureVK::Layout rt_tex_layout = m_tfx_textures[TFX_TEXTURE_RT]->GetLayout();
+ if (rt_tex_layout != GSTextureVK::Layout::FeedbackLoop && rt_tex_layout != GSTextureVK::Layout::ShaderReadOnly)
+ m_tfx_textures[TFX_TEXTURE_RT] = m_null_texture.get();
}
- if ((flags & DIRTY_FLAG_TFX_RT_TEXTURE_DS) || m_tfx_rt_descriptor_set == VK_NULL_HANDLE)
+ if (flags & DIRTY_FLAG_TFX_UBO)
{
- m_tfx_rt_descriptor_set = AllocateDescriptorSet(m_tfx_rt_texture_ds_layout);
- if (m_tfx_rt_descriptor_set == VK_NULL_HANDLE)
- {
- if (already_execed)
- {
- Console.Error("Failed to allocate TFX sampler descriptors");
- return false;
- }
-
- /* Ran out of TFX sampler descriptors */
- ExecuteCommandBufferAndRestartRenderPass(false);
- return ApplyTFXState(true);
- }
-
- if (m_features.texture_barrier)
+ // Still need to bind the UBO descriptor set.
+ vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_tfx_pipeline_layout, 0, 1,
+ &m_tfx_ubo_descriptor_set, NUM_TFX_DYNAMIC_OFFSETS, m_tfx_dynamic_offsets.data());
+ }
+
+ if (flags & DIRTY_FLAG_TFX_TEXTURES)
+ {
+ if (flags & DIRTY_FLAG_TFX_TEXTURE_TEX)
{
- dsub.AddInputAttachmentDescriptorWrite(
- m_tfx_rt_descriptor_set, 0, m_tfx_textures[NUM_TFX_DRAW_TEXTURES]->GetView(), VK_IMAGE_LAYOUT_GENERAL);
+ dsub.AddCombinedImageSamplerDescriptorWrite(VK_NULL_HANDLE, TFX_TEXTURE_TEXTURE,
+ m_tfx_textures[TFX_TEXTURE_TEXTURE]->GetView(), m_tfx_sampler,
+ m_tfx_textures[TFX_TEXTURE_TEXTURE]->GetVkLayout());
}
- else
+ if (flags & DIRTY_FLAG_TFX_TEXTURE_PALETTE)
{
- dsub.AddImageDescriptorWrite(m_tfx_rt_descriptor_set, 0, m_tfx_textures[NUM_TFX_DRAW_TEXTURES]->GetView(),
- m_tfx_textures[NUM_TFX_DRAW_TEXTURES]->GetVkLayout());
+ dsub.AddImageDescriptorWrite(VK_NULL_HANDLE, TFX_TEXTURE_PALETTE,
+ m_tfx_textures[TFX_TEXTURE_PALETTE]->GetView(), m_tfx_textures[TFX_TEXTURE_PALETTE]->GetVkLayout());
}
- dsub.AddImageDescriptorWrite(m_tfx_rt_descriptor_set, 1, m_tfx_textures[NUM_TFX_DRAW_TEXTURES + 1]->GetView(),
- m_tfx_textures[NUM_TFX_DRAW_TEXTURES + 1]->GetVkLayout());
- dsub.Update(vk_init_info.device);
- if (!layout_changed)
+ if (flags & DIRTY_FLAG_TFX_TEXTURE_RT)
{
// need to add textures in, can't leave a gap
- if (start_dset == TFX_DESCRIPTOR_SET_UBO && num_dsets == 1)
- dsets[num_dsets++] = m_tfx_texture_descriptor_set;
+ if (m_features.texture_barrier)
+ dsub.AddInputAttachmentDescriptorWrite(
+ VK_NULL_HANDLE, TFX_TEXTURE_RT, m_tfx_textures[TFX_TEXTURE_RT]->GetView(), VK_IMAGE_LAYOUT_GENERAL);
+
else
- start_dset = (num_dsets == 0) ? TFX_DESCRIPTOR_SET_RT : start_dset;
-
- dsets[num_dsets++] = m_tfx_rt_descriptor_set;
- }
- }
-
- if (layout_changed)
- {
- m_current_pipeline_layout = PipelineLayout::TFX;
-
- dsets[0] = m_tfx_ubo_descriptor_set;
- dsets[1] = m_tfx_texture_descriptor_set;
- dsets[2] = m_tfx_rt_descriptor_set;
-
- vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_tfx_pipeline_layout, 0,
- NUM_TFX_DESCRIPTOR_SETS, dsets, NUM_TFX_DYNAMIC_OFFSETS,
- m_tfx_dynamic_offsets.data());
- }
- else if (num_dsets > 0)
- {
- u32 dynamic_count;
- const u32* dynamic_offsets;
- if (start_dset == TFX_DESCRIPTOR_SET_UBO)
- {
- dynamic_count = NUM_TFX_DYNAMIC_OFFSETS;
- dynamic_offsets = m_tfx_dynamic_offsets.data();
+ {
+ dsub.AddImageDescriptorWrite(VK_NULL_HANDLE, TFX_TEXTURE_RT, m_tfx_textures[TFX_TEXTURE_RT]->GetView(),
+ m_tfx_textures[TFX_TEXTURE_RT]->GetVkLayout());
+ }
}
- else
+ if (flags & DIRTY_FLAG_TFX_TEXTURE_PRIMID)
{
- dynamic_count = 0;
- dynamic_offsets = nullptr;
+ dsub.AddImageDescriptorWrite(VK_NULL_HANDLE, TFX_TEXTURE_PRIMID,
+ m_tfx_textures[TFX_TEXTURE_PRIMID]->GetView(), m_tfx_textures[TFX_TEXTURE_PRIMID]->GetVkLayout());
+
}
- vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_tfx_pipeline_layout, start_dset, num_dsets,
- dsets, dynamic_count,
- dynamic_offsets);
+ dsub.PushUpdate(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_tfx_pipeline_layout, TFX_DESCRIPTOR_SET_TEXTURES);
}
-
ApplyBaseState(flags, cmdbuf);
return true;
}
@@ -3749,39 +3652,16 @@ bool GSDeviceVK::ApplyUtilityState(bool already_execed)
u32 flags = m_dirty_flags;
m_dirty_flags &= ~DIRTY_UTILITY_STATE;
- bool rebind = (m_current_pipeline_layout != PipelineLayout::Utility);
-
- if ((flags & DIRTY_FLAG_UTILITY_TEXTURE) || m_utility_descriptor_set == VK_NULL_HANDLE)
+ if (m_current_pipeline_layout != PipelineLayout::Utility || flags & DIRTY_FLAG_UTILITY_TEXTURE)
{
- m_utility_descriptor_set = AllocateDescriptorSet(m_utility_ds_layout);
- if (m_utility_descriptor_set == VK_NULL_HANDLE)
- {
- if (already_execed)
- {
- Console.Error("Failed to allocate utility descriptors");
- return false;
- }
-
- /* Ran out of utility descriptors */
- ExecuteCommandBufferAndRestartRenderPass(false);
- return ApplyUtilityState(true);
- }
+ m_current_pipeline_layout = PipelineLayout::Utility;
Vulkan::DescriptorSetUpdateBuilder dsub;
- dsub.AddCombinedImageSamplerDescriptorWrite(m_utility_descriptor_set, 0, m_utility_texture->GetView(),
- m_utility_sampler, m_utility_texture->GetVkLayout());
- dsub.Update(dev);
- rebind = true;
- }
-
- if (rebind)
- {
- vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_utility_pipeline_layout, 0, 1,
- &m_utility_descriptor_set, 0, nullptr);
+ dsub.AddCombinedImageSamplerDescriptorWrite(
+ VK_NULL_HANDLE, 0, m_utility_texture->GetView(), m_utility_sampler, m_utility_texture->GetVkLayout());
+ dsub.PushUpdate(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_utility_pipeline_layout, 0, false);
}
- m_current_pipeline_layout = PipelineLayout::Utility;
-
ApplyBaseState(flags, cmdbuf);
return true;
}
@@ -4070,7 +3950,7 @@ void GSDeviceVK::RenderHW(GSHWDrawConfig& config)
// If this is the first draw to the target as a feedback loop, make sure we re-generate the texture descriptor.
// Otherwise, we might have a previous descriptor left over, that has the RT in a different state.
- m_dirty_flags |= (skip_first_barrier ? DIRTY_FLAG_TFX_RT_TEXTURE_DS : 0);
+ m_dirty_flags |= (skip_first_barrier ? static_cast<u32>(DIRTY_FLAG_TFX_TEXTURE_RT) : 0);
}
// Begin render pass if new target or out of the area.
diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h
index 52ce8bc83..9fed68c47 100644
--- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h
+++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.h
@@ -119,11 +119,7 @@ public:
enum : u32
{
NUM_TFX_DYNAMIC_OFFSETS = 2,
- NUM_TFX_DRAW_TEXTURES = 2,
- NUM_TFX_RT_TEXTURES = 2,
- NUM_TFX_TEXTURES = NUM_TFX_DRAW_TEXTURES + NUM_TFX_RT_TEXTURES,
- NUM_CONVERT_TEXTURES = 1,
- NUM_CONVERT_SAMPLERS = 1,
+ NUM_UTILITY_SAMPLERS = 1,
CONVERT_PUSH_CONSTANTS_SIZE = 96,
VERTEX_BUFFER_SIZE = 32 * 1024 * 1024,
@@ -135,10 +131,18 @@ public:
{
TFX_DESCRIPTOR_SET_UBO,
TFX_DESCRIPTOR_SET_TEXTURES,
- TFX_DESCRIPTOR_SET_RT,
NUM_TFX_DESCRIPTOR_SETS,
};
+ enum TFX_TEXTURES : u32
+ {
+ TFX_TEXTURE_TEXTURE,
+ TFX_TEXTURE_PALETTE,
+ TFX_TEXTURE_RT,
+ TFX_TEXTURE_PRIMID,
+
+ NUM_TFX_TEXTURES
+ };
// Returns a list of Vulkan-compatible GPUs.
using GPUList = std::vector<VkPhysicalDevice>;
@@ -198,9 +202,6 @@ public:
__fi VKStreamBuffer& GetTextureUploadBuffer() { return m_texture_upload_buffer; }
VkCommandBuffer GetCurrentInitCommandBuffer();
- /// Allocates a descriptor set from the pool reserved for the current frame.
- VkDescriptorSet AllocateDescriptorSet(VkDescriptorSetLayout set_layout);
-
/// Allocates a descriptor set from the pool reserved for the current frame.
VkDescriptorSet AllocatePersistentDescriptorSet(VkDescriptorSetLayout set_layout);
@@ -287,7 +288,6 @@ private:
// [0] - Init (upload) command buffer, [1] - draw command buffer
VkCommandPool command_pool = VK_NULL_HANDLE;
std::array<VkCommandBuffer, 2> command_buffers{VK_NULL_HANDLE, VK_NULL_HANDLE};
- VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
VkFence fence = VK_NULL_HANDLE;
u64 fence_counter = 0;
bool init_buffer_used = false;
@@ -323,8 +323,7 @@ private:
VkPipelineLayout m_utility_pipeline_layout = VK_NULL_HANDLE;
VkDescriptorSetLayout m_tfx_ubo_ds_layout = VK_NULL_HANDLE;
- VkDescriptorSetLayout m_tfx_sampler_ds_layout = VK_NULL_HANDLE;
- VkDescriptorSetLayout m_tfx_rt_texture_ds_layout = VK_NULL_HANDLE;
+ VkDescriptorSetLayout m_tfx_texture_ds_layout = VK_NULL_HANDLE;
VkPipelineLayout m_tfx_pipeline_layout = VK_NULL_HANDLE;
VKStreamBuffer m_vertex_stream_buffer;
@@ -516,24 +515,34 @@ public:
private:
enum DIRTY_FLAG : u32
{
- DIRTY_FLAG_TFX_SAMPLERS_DS = (1 << 0),
- DIRTY_FLAG_TFX_RT_TEXTURE_DS = (1 << 1),
- DIRTY_FLAG_TFX_UBO = (1 << 2),
- DIRTY_FLAG_UTILITY_TEXTURE = (1 << 3),
- DIRTY_FLAG_BLEND_CONSTANTS = (1 << 4),
- DIRTY_FLAG_LINE_WIDTH = (1 << 5),
- DIRTY_FLAG_INDEX_BUFFER = (1 << 6),
- DIRTY_FLAG_VIEWPORT = (1 << 7),
- DIRTY_FLAG_SCISSOR = (1 << 8),
- DIRTY_FLAG_PIPELINE = (1 << 9),
- DIRTY_FLAG_VS_CONSTANT_BUFFER = (1 << 10),
- DIRTY_FLAG_PS_CONSTANT_BUFFER = (1 << 11),
-
- DIRTY_BASE_STATE = DIRTY_FLAG_INDEX_BUFFER | DIRTY_FLAG_PIPELINE |
- DIRTY_FLAG_VIEWPORT | DIRTY_FLAG_SCISSOR | DIRTY_FLAG_BLEND_CONSTANTS | DIRTY_FLAG_LINE_WIDTH,
- DIRTY_TFX_STATE = DIRTY_BASE_STATE | DIRTY_FLAG_TFX_SAMPLERS_DS | DIRTY_FLAG_TFX_RT_TEXTURE_DS,
- DIRTY_UTILITY_STATE = DIRTY_BASE_STATE | DIRTY_FLAG_UTILITY_TEXTURE,
- DIRTY_CONSTANT_BUFFER_STATE = DIRTY_FLAG_VS_CONSTANT_BUFFER | DIRTY_FLAG_PS_CONSTANT_BUFFER,
+ DIRTY_FLAG_TFX_TEXTURE_0 = (1 << 0), // 0, 1, 2, 3
+ DIRTY_FLAG_TFX_UBO = (1 << 4),
+ DIRTY_FLAG_UTILITY_TEXTURE = (1 << 5),
+ DIRTY_FLAG_BLEND_CONSTANTS = (1 << 6),
+ DIRTY_FLAG_LINE_WIDTH = (1 << 7),
+ DIRTY_FLAG_VERTEX_BUFFER = (1 << 8),
+ DIRTY_FLAG_INDEX_BUFFER = (1 << 9),
+ DIRTY_FLAG_VIEWPORT = (1 << 10),
+ DIRTY_FLAG_SCISSOR = (1 << 11),
+ DIRTY_FLAG_PIPELINE = (1 << 12),
+ DIRTY_FLAG_VS_CONSTANT_BUFFER = (1 << 13),
+ DIRTY_FLAG_PS_CONSTANT_BUFFER = (1 << 14),
+
+ DIRTY_FLAG_TFX_TEXTURE_TEX = (DIRTY_FLAG_TFX_TEXTURE_0 << 0),
+ DIRTY_FLAG_TFX_TEXTURE_PALETTE = (DIRTY_FLAG_TFX_TEXTURE_0 << 1),
+ DIRTY_FLAG_TFX_TEXTURE_RT = (DIRTY_FLAG_TFX_TEXTURE_0 << 2),
+ DIRTY_FLAG_TFX_TEXTURE_PRIMID = (DIRTY_FLAG_TFX_TEXTURE_0 << 3),
+
+ DIRTY_FLAG_TFX_TEXTURES = DIRTY_FLAG_TFX_TEXTURE_TEX | DIRTY_FLAG_TFX_TEXTURE_PALETTE |
+ DIRTY_FLAG_TFX_TEXTURE_RT | DIRTY_FLAG_TFX_TEXTURE_PRIMID,
+
+ DIRTY_BASE_STATE = DIRTY_FLAG_VERTEX_BUFFER | DIRTY_FLAG_INDEX_BUFFER | DIRTY_FLAG_PIPELINE |
+ DIRTY_FLAG_VIEWPORT | DIRTY_FLAG_SCISSOR | DIRTY_FLAG_BLEND_CONSTANTS |
+ DIRTY_FLAG_LINE_WIDTH,
+ DIRTY_TFX_STATE = DIRTY_BASE_STATE | DIRTY_FLAG_TFX_TEXTURES,
+ DIRTY_UTILITY_STATE = DIRTY_BASE_STATE | DIRTY_FLAG_UTILITY_TEXTURE,
+ DIRTY_CONSTANT_BUFFER_STATE = DIRTY_FLAG_VS_CONSTANT_BUFFER | DIRTY_FLAG_PS_CONSTANT_BUFFER,
+ ALL_DIRTY_STATE = DIRTY_BASE_STATE | DIRTY_TFX_STATE | DIRTY_UTILITY_STATE | DIRTY_CONSTANT_BUFFER_STATE,
};
enum class PipelineLayout