-
-
Notifications
You must be signed in to change notification settings - Fork 584
/
Copy pathvulkan_hooks_cmd.cpp
2082 lines (1693 loc) · 96.8 KB
/
vulkan_hooks_cmd.cpp
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2014 Patrick Mours
* SPDX-License-Identifier: BSD-3-Clause OR MIT
*/
#include "vulkan_hooks.hpp"
#include "vulkan_impl_device.hpp"
#include "vulkan_impl_command_list.hpp"
#include "vulkan_impl_type_convert.hpp"
#include "dll_log.hpp"
#include "addon_manager.hpp"
#include "lockfree_linear_map.hpp"
#include <cstring> // std::memcpy, std::memset
#include <algorithm> // std::copy_n, std::max, std::min, std::swap
extern lockfree_linear_map<void *, reshade::vulkan::device_impl *, 8> g_vulkan_devices;
#define GET_DISPATCH_PTR_FROM(name, data) \
assert((data) != nullptr); \
PFN_vk##name trampoline = (data)->_dispatch_table.name; \
assert(trampoline != nullptr)
#if RESHADE_ADDON
static void invoke_begin_render_pass_event(const reshade::vulkan::device_impl *device_impl, reshade::vulkan::object_data<VK_OBJECT_TYPE_COMMAND_BUFFER> *cmd_impl, const VkRenderPassBeginInfo *begin_info)
{
const auto render_pass_data = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_RENDER_PASS>(cmd_impl->current_render_pass);
const reshade::vulkan::object_data<VK_OBJECT_TYPE_RENDER_PASS>::subpass &subpass = render_pass_data->subpasses[cmd_impl->current_subpass];
const VkImageView *attachments = nullptr;
// Attachments may optionally be provided directly, rather than through the framebuffer object, when VK_KHR_imageless_framebuffer is used
if (const auto attachment_begin_info = find_in_structure_chain<VkRenderPassAttachmentBeginInfo>(begin_info, VK_STRUCTURE_TYPE_RENDER_PASS_ATTACHMENT_BEGIN_INFO))
{
attachments = attachment_begin_info->pAttachments;
assert(subpass.num_color_attachments <= attachment_begin_info->attachmentCount);
}
else
{
const auto framebuffer_data = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_FRAMEBUFFER>(cmd_impl->current_framebuffer);
attachments = framebuffer_data->attachments.data();
}
// Update current attachments on the command list
for (uint32_t i = 0; i < subpass.num_color_attachments; ++i)
{
const uint32_t a = subpass.color_attachments[i];
cmd_impl->current_color_attachments[i] = (a != VK_ATTACHMENT_UNUSED) ? attachments[a] : VK_NULL_HANDLE;
}
{
const uint32_t a = subpass.depth_stencil_attachment;
cmd_impl->current_depth_stencil_attachment = (a != VK_ATTACHMENT_UNUSED) ? attachments[a] : VK_NULL_HANDLE;
}
if (!reshade::has_addon_event<reshade::addon_event::begin_render_pass>())
return;
uint32_t num_transitions = 0;
temp_mem<VkImageMemoryBarrier, 8 + 1> transitions(subpass.num_color_attachments + 1);
temp_mem<reshade::api::render_pass_render_target_desc, 8> rts(subpass.num_color_attachments);
for (uint32_t i = 0; i < subpass.num_color_attachments; ++i)
{
reshade::api::render_pass_render_target_desc &rt = rts[i];
const uint32_t a = subpass.color_attachments[i];
if (a != VK_ATTACHMENT_UNUSED)
{
const VkAttachmentDescription &desc = render_pass_data->attachments[a];
rt.view = { (uint64_t)attachments[a] };
rt.load_op = reshade::vulkan::convert_render_pass_load_op(desc.loadOp);
rt.store_op = reshade::vulkan::convert_render_pass_store_op(desc.storeOp);
std::memset(rt.clear_color, 0, sizeof(rt.clear_color));
if (begin_info != nullptr)
{
if (desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR && begin_info->clearValueCount > a)
std::copy_n(begin_info->pClearValues[a].color.float32, 4, rt.clear_color);
if (desc.initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && desc.initialLayout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
{
VkImageMemoryBarrier &transition = transitions[num_transitions++];
transition = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
transition.oldLayout = desc.initialLayout;
transition.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
transition.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.image = (VkImage)device_impl->get_resource_from_view(rt.view).handle;
transition.subresourceRange = { reshade::vulkan::aspect_flags_from_format(desc.format), 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS };
}
}
}
else
{
rt.view = { 0 };
rt.load_op = reshade::api::render_pass_load_op::discard;
rt.store_op = reshade::api::render_pass_store_op::discard;
std::memset(rt.clear_color, 0, sizeof(rt.clear_color));
}
}
reshade::api::render_pass_depth_stencil_desc ds;
{
const uint32_t a = subpass.depth_stencil_attachment;
if (a != VK_ATTACHMENT_UNUSED)
{
const VkAttachmentDescription &desc = render_pass_data->attachments[a];
ds.view = { (uint64_t)attachments[a] };
ds.depth_load_op = reshade::vulkan::convert_render_pass_load_op(desc.loadOp);
ds.depth_store_op = reshade::vulkan::convert_render_pass_store_op(desc.storeOp);
ds.stencil_load_op = reshade::vulkan::convert_render_pass_load_op(desc.stencilLoadOp);
ds.stencil_store_op = reshade::vulkan::convert_render_pass_store_op(desc.stencilStoreOp);
ds.clear_depth = 0.0f;
ds.clear_stencil = 0;
if (begin_info != nullptr)
{
if (desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR && begin_info->clearValueCount > a)
{
ds.clear_depth = begin_info->pClearValues[a].depthStencil.depth;
ds.clear_stencil = static_cast<uint8_t>(begin_info->pClearValues[a].depthStencil.stencil);
}
if (desc.initialLayout != VK_IMAGE_LAYOUT_UNDEFINED && desc.initialLayout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
{
VkImageMemoryBarrier &transition = transitions[num_transitions++];
transition = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
transition.oldLayout = desc.initialLayout;
transition.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
transition.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.image = (VkImage)device_impl->get_resource_from_view(ds.view).handle;
transition.subresourceRange = { reshade::vulkan::aspect_flags_from_format(desc.format), 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS };
}
}
}
else
{
ds.view = { 0 };
ds.depth_load_op = reshade::api::render_pass_load_op::discard;
ds.depth_store_op = reshade::api::render_pass_store_op::discard;
ds.stencil_load_op = reshade::api::render_pass_load_op::discard;
ds.stencil_store_op = reshade::api::render_pass_store_op::discard;
ds.clear_depth = 0.0f;
ds.clear_stencil = 0;
}
}
// The 'begin_render_pass' event assumes the resource to be in 'resource_usage::render_target' or 'reshade_usage::depth_stencil' state, so need to transition here
if (num_transitions != 0)
device_impl->_dispatch_table.CmdPipelineBarrier(cmd_impl->_orig, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, num_transitions, transitions.p);
reshade::invoke_addon_event<reshade::addon_event::begin_render_pass>(cmd_impl, subpass.num_color_attachments, rts.p, subpass.depth_stencil_attachment != VK_ATTACHMENT_UNUSED ? &ds : nullptr);
// Revert back to previous state
for (uint32_t i = 0; i < num_transitions; ++i)
std::swap(transitions[i].oldLayout, transitions[i].newLayout);
if (num_transitions != 0)
device_impl->_dispatch_table.CmdPipelineBarrier(cmd_impl->_orig, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, num_transitions, transitions.p);
}
static void invoke_begin_render_pass_event(reshade::vulkan::object_data<VK_OBJECT_TYPE_COMMAND_BUFFER> *cmd_impl, const VkRenderingInfo *rendering_info)
{
assert(rendering_info != nullptr);
assert(rendering_info->colorAttachmentCount <= 8);
// Update current attachments on the command list
for (uint32_t i = 0; i < rendering_info->colorAttachmentCount && i < 8; ++i)
cmd_impl->current_color_attachments[i] = rendering_info->pColorAttachments[i].imageView;
if (rendering_info->pDepthAttachment != nullptr)
cmd_impl->current_depth_stencil_attachment = rendering_info->pDepthAttachment->imageView;
else if (rendering_info->pStencilAttachment != nullptr)
cmd_impl->current_depth_stencil_attachment = rendering_info->pStencilAttachment->imageView;
if (!reshade::has_addon_event<reshade::addon_event::begin_render_pass>())
return;
temp_mem<reshade::api::render_pass_render_target_desc, 8> rts(rendering_info->colorAttachmentCount);
for (uint32_t i = 0; i < rendering_info->colorAttachmentCount; ++i)
{
reshade::api::render_pass_render_target_desc &rt = rts[i];
rt.view = { (uint64_t)rendering_info->pColorAttachments[i].imageView };
rt.load_op = reshade::vulkan::convert_render_pass_load_op(rendering_info->pColorAttachments[i].loadOp);
rt.store_op = reshade::vulkan::convert_render_pass_store_op(rendering_info->pColorAttachments[i].storeOp);
std::copy_n(rendering_info->pColorAttachments[i].clearValue.color.float32, 4, rt.clear_color);
}
reshade::api::render_pass_depth_stencil_desc ds;
if (rendering_info->pDepthAttachment != nullptr)
{
ds.view = { (uint64_t)rendering_info->pDepthAttachment->imageView };
ds.depth_load_op = reshade::vulkan::convert_render_pass_load_op(rendering_info->pDepthAttachment->loadOp);
ds.depth_store_op = reshade::vulkan::convert_render_pass_store_op(rendering_info->pDepthAttachment->storeOp);
ds.clear_depth = rendering_info->pDepthAttachment->clearValue.depthStencil.depth;
}
else
{
ds.depth_load_op = reshade::api::render_pass_load_op::discard;
ds.depth_store_op = reshade::api::render_pass_store_op::discard;
ds.clear_depth = 0.0f;
}
if (rendering_info->pStencilAttachment != nullptr)
{
ds.view = { (uint64_t)rendering_info->pStencilAttachment->imageView };
ds.stencil_load_op = reshade::vulkan::convert_render_pass_load_op(rendering_info->pStencilAttachment->loadOp);
ds.stencil_store_op = reshade::vulkan::convert_render_pass_store_op(rendering_info->pStencilAttachment->storeOp);
ds.clear_stencil = static_cast<uint8_t>(rendering_info->pStencilAttachment->clearValue.depthStencil.stencil);
}
else
{
ds.stencil_load_op = reshade::api::render_pass_load_op::discard;
ds.stencil_store_op = reshade::api::render_pass_store_op::discard;
ds.clear_stencil = 0;
}
reshade::invoke_addon_event<reshade::addon_event::begin_render_pass>(cmd_impl, rendering_info->colorAttachmentCount, rts.p, rendering_info->pDepthAttachment != nullptr || rendering_info->pStencilAttachment != nullptr ? &ds : nullptr);
}
#endif
#if RESHADE_ADDON >= 2
static uint32_t calc_subresource_index(reshade::vulkan::device_impl *device, VkImage image, const VkImageSubresourceLayers &layers)
{
const uint32_t levels = device->get_private_data_for_object<VK_OBJECT_TYPE_IMAGE>(image)->create_info.mipLevels;
return layers.mipLevel + layers.baseArrayLayer * levels;
}
#endif
VkResult VKAPI_CALL vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
const auto cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
// Begin does perform an implicit reset if command pool was created with 'VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT'
reshade::invoke_addon_event<reshade::addon_event::reset_command_list>(cmd_impl);
assert(cmd_impl->current_render_pass == VK_NULL_HANDLE);
if (pBeginInfo->pInheritanceInfo != nullptr && (pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT) != 0)
{
const VkCommandBufferInheritanceInfo &inheritance_info = *pBeginInfo->pInheritanceInfo;
if (inheritance_info.renderPass != VK_NULL_HANDLE)
{
cmd_impl->current_subpass = inheritance_info.subpass;
cmd_impl->current_render_pass = inheritance_info.renderPass;
cmd_impl->_is_in_render_pass = true;
if (inheritance_info.framebuffer != VK_NULL_HANDLE)
{
cmd_impl->current_framebuffer = inheritance_info.framebuffer;
invoke_begin_render_pass_event(device_impl, cmd_impl, nullptr);
}
else
{
// Framebuffer is not known and therefore cannot provide any attachment information
reshade::invoke_addon_event<reshade::addon_event::begin_render_pass>(cmd_impl, 0, nullptr, nullptr);
}
}
}
#endif
GET_DISPATCH_PTR_FROM(BeginCommandBuffer, device_impl);
const VkResult result = trampoline(commandBuffer, pBeginInfo);
#if RESHADE_VERBOSE_LOG
if (result < VK_SUCCESS)
{
reshade::log::message(reshade::log::level::warning, "vkBeginCommandBuffer failed with error code %d.", static_cast<int>(result));
}
#endif
return result;
}
VkResult VKAPI_CALL vkEndCommandBuffer(VkCommandBuffer commandBuffer)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
const auto cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (cmd_impl->current_render_pass != VK_NULL_HANDLE)
{
reshade::invoke_addon_event<reshade::addon_event::end_render_pass>(cmd_impl);
cmd_impl->current_subpass = std::numeric_limits<uint32_t>::max();
cmd_impl->current_render_pass = VK_NULL_HANDLE;
cmd_impl->current_framebuffer = VK_NULL_HANDLE;
cmd_impl->_is_in_render_pass = false;
}
reshade::invoke_addon_event<reshade::addon_event::close_command_list>(cmd_impl);
#endif
GET_DISPATCH_PTR_FROM(EndCommandBuffer, device_impl);
const VkResult result = trampoline(commandBuffer);
#if RESHADE_VERBOSE_LOG
if (result < VK_SUCCESS)
{
reshade::log::message(reshade::log::level::warning, "vkEndCommandBuffer failed with error code %d.", static_cast<int>(result));
}
#endif
return result;
}
void VKAPI_CALL vkCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdBindPipeline, device_impl);
trampoline(commandBuffer, pipelineBindPoint, pipeline);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const auto pipeline_stages =
pipelineBindPoint == VK_PIPELINE_BIND_POINT_COMPUTE ? reshade::api::pipeline_stage::all_compute :
pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS ? reshade::api::pipeline_stage::all_graphics :
static_cast<reshade::api::pipeline_stage>(0); // Unknown pipeline bind point
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline>(
cmd_impl,
pipeline_stages,
reshade::api::pipeline { (uint64_t)pipeline });
#endif
}
void VKAPI_CALL vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetViewport, device_impl);
trampoline(commandBuffer, firstViewport, viewportCount, pViewports);
#if RESHADE_ADDON
if (!reshade::has_addon_event<reshade::addon_event::bind_viewports>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
temp_mem<reshade::api::viewport> viewport_data(viewportCount);
for (uint32_t i = 0; i < viewportCount; ++i)
{
std::memcpy(&viewport_data[i], &pViewports[i], sizeof(VkViewport));
// Flip viewport vertically (see 'command_list_impl::bind_viewports')
viewport_data[i].y += viewport_data[i].height;
viewport_data[i].height = -viewport_data[i].height;
}
reshade::invoke_addon_event<reshade::addon_event::bind_viewports>(cmd_impl, firstViewport, viewportCount, viewport_data.p);
#endif
}
void VKAPI_CALL vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetScissor, device_impl);
trampoline(commandBuffer, firstScissor, scissorCount, pScissors);
#if RESHADE_ADDON
if (!reshade::has_addon_event<reshade::addon_event::bind_scissor_rects>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
temp_mem<reshade::api::rect> rect_data(scissorCount);
for (uint32_t i = 0; i < scissorCount; ++i)
{
rect_data[i].left = pScissors[i].offset.x;
rect_data[i].top = pScissors[i].offset.y;
rect_data[i].right = pScissors[i].offset.x + static_cast<int32_t>(pScissors[i].extent.width);
rect_data[i].bottom = pScissors[i].offset.y + static_cast<int32_t>(pScissors[i].extent.height);
}
reshade::invoke_addon_event<reshade::addon_event::bind_scissor_rects>(cmd_impl, firstScissor, scissorCount, rect_data.p);
#endif
}
void VKAPI_CALL vkCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetDepthBias, device_impl);
trampoline(commandBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline_states>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const reshade::api::dynamic_state states[3] = { reshade::api::dynamic_state::depth_bias, reshade::api::dynamic_state::depth_bias_clamp, reshade::api::dynamic_state::depth_bias_slope_scaled };
const uint32_t values[3] = { *reinterpret_cast<const uint32_t *>(&depthBiasConstantFactor), *reinterpret_cast<const uint32_t *>(&depthBiasClamp), *reinterpret_cast<const uint32_t *>(&depthBiasSlopeFactor) };
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline_states>(cmd_impl, static_cast<uint32_t>(std::size(states)), states, values);
#endif
}
void VKAPI_CALL vkCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4])
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetBlendConstants, device_impl);
trampoline(commandBuffer, blendConstants);
#if RESHADE_ADDON >= 2
assert(blendConstants != nullptr);
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline_states>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const reshade::api::dynamic_state states[1] = { reshade::api::dynamic_state::blend_constant };
const uint32_t values[1] = {
((static_cast<uint32_t>(blendConstants[0] * 255.f) & 0xFF) ) |
((static_cast<uint32_t>(blendConstants[1] * 255.f) & 0xFF) << 8) |
((static_cast<uint32_t>(blendConstants[2] * 255.f) & 0xFF) << 16) |
((static_cast<uint32_t>(blendConstants[3] * 255.f) & 0xFF) << 24) };
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline_states>(cmd_impl, static_cast<uint32_t>(std::size(states)), states, values);
#endif
}
void VKAPI_CALL vkCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetStencilCompareMask, device_impl);
trampoline(commandBuffer, faceMask, compareMask);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline_states>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const reshade::api::dynamic_state states[2] = { reshade::api::dynamic_state::front_stencil_read_mask, reshade::api::dynamic_state::back_stencil_read_mask };
const uint32_t values[2] = { compareMask, compareMask };
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline_states>(cmd_impl, faceMask == VK_STENCIL_FACE_FRONT_AND_BACK ? 2 : 1, &states[faceMask == VK_STENCIL_FACE_BACK_BIT ? 1 : 0], values);
#endif
}
void VKAPI_CALL vkCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetStencilWriteMask, device_impl);
trampoline(commandBuffer, faceMask, writeMask);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline_states>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const reshade::api::dynamic_state states[2] = { reshade::api::dynamic_state::front_stencil_write_mask, reshade::api::dynamic_state::back_stencil_write_mask };
const uint32_t values[2] = { writeMask, writeMask };
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline_states>(cmd_impl, faceMask == VK_STENCIL_FACE_FRONT_AND_BACK ? 2 : 1, &states[faceMask == VK_STENCIL_FACE_BACK_BIT ? 1 : 0], values);
#endif
}
void VKAPI_CALL vkCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdSetStencilReference, device_impl);
trampoline(commandBuffer, faceMask, reference);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_pipeline_states>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const reshade::api::dynamic_state states[2] = { reshade::api::dynamic_state::front_stencil_reference_value, reshade::api::dynamic_state::back_stencil_reference_value };
const uint32_t values[2] = { reference, reference };
reshade::invoke_addon_event<reshade::addon_event::bind_pipeline_states>(cmd_impl, faceMask == VK_STENCIL_FACE_FRONT_AND_BACK ? 2 : 1, &states[faceMask == VK_STENCIL_FACE_BACK_BIT ? 1 : 0], values);
#endif
}
void VKAPI_CALL vkCmdBindDescriptorSets(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t *pDynamicOffsets)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdBindDescriptorSets, device_impl);
trampoline(commandBuffer, pipelineBindPoint, layout, firstSet, descriptorSetCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_descriptor_tables>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
const auto shader_stages =
pipelineBindPoint == VK_PIPELINE_BIND_POINT_COMPUTE ? reshade::api::shader_stage::all_compute :
pipelineBindPoint == VK_PIPELINE_BIND_POINT_GRAPHICS ? reshade::api::shader_stage::all_graphics :
static_cast<reshade::api::shader_stage>(0); // Unknown pipeline bind point
reshade::invoke_addon_event<reshade::addon_event::bind_descriptor_tables>(
cmd_impl,
shader_stages,
reshade::api::pipeline_layout { (uint64_t)layout },
firstSet, descriptorSetCount,
reinterpret_cast<const reshade::api::descriptor_table *>(pDescriptorSets));
#endif
}
void VKAPI_CALL vkCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdBindIndexBuffer, device_impl);
trampoline(commandBuffer, buffer, offset, indexType);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_index_buffer>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
reshade::invoke_addon_event<reshade::addon_event::bind_index_buffer>(
cmd_impl, reshade::api::resource { (uint64_t)buffer }, offset, indexType == VK_INDEX_TYPE_UINT8_EXT ? 1 : indexType == VK_INDEX_TYPE_UINT16 ? 2 : 4);
#endif
}
void VKAPI_CALL vkCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer *pBuffers, const VkDeviceSize *pOffsets)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdBindVertexBuffers, device_impl);
trampoline(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets);
#if RESHADE_ADDON >= 2
if (!reshade::has_addon_event<reshade::addon_event::bind_vertex_buffers>())
return;
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
reshade::invoke_addon_event<reshade::addon_event::bind_vertex_buffers>(
cmd_impl, firstBinding, bindingCount, reinterpret_cast<const reshade::api::resource *>(pBuffers), pOffsets, nullptr);
#endif
}
void VKAPI_CALL vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::draw>(cmd_impl, vertexCount, instanceCount, firstVertex, firstInstance))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDraw, device_impl);
trampoline(commandBuffer, vertexCount, instanceCount, firstVertex, firstInstance);
}
void VKAPI_CALL vkCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::draw_indexed>(cmd_impl, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDrawIndexed, device_impl);
trampoline(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
}
void VKAPI_CALL vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::draw_or_dispatch_indirect>(cmd_impl, reshade::api::indirect_command::draw, reshade::api::resource { (uint64_t)buffer }, offset, drawCount, stride))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDrawIndirect, device_impl);
trampoline(commandBuffer, buffer, offset, drawCount, stride);
}
void VKAPI_CALL vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::draw_or_dispatch_indirect>(cmd_impl, reshade::api::indirect_command::draw_indexed, reshade::api::resource { (uint64_t)buffer }, offset, drawCount, stride))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDrawIndexedIndirect, device_impl);
trampoline(commandBuffer, buffer, offset, drawCount, stride);
}
void VKAPI_CALL vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::dispatch>(cmd_impl, groupCountX, groupCountY, groupCountZ))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDispatch, device_impl);
trampoline(commandBuffer, groupCountX, groupCountY, groupCountZ);
}
void VKAPI_CALL vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
if (reshade::invoke_addon_event<reshade::addon_event::draw_or_dispatch_indirect>(cmd_impl, reshade::api::indirect_command::dispatch, reshade::api::resource { (uint64_t)buffer }, offset, 1, 0))
return;
#endif
GET_DISPATCH_PTR_FROM(CmdDispatchIndirect, device_impl);
trampoline(commandBuffer, buffer, offset);
}
void VKAPI_CALL vkCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy *pRegions)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdCopyBuffer, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::copy_buffer_region>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkBufferCopy ®ion = pRegions[i];
if (reshade::invoke_addon_event<reshade::addon_event::copy_buffer_region>(
cmd_impl,
reshade::api::resource { (uint64_t)srcBuffer }, region.srcOffset,
reshade::api::resource { (uint64_t)dstBuffer }, region.dstOffset, region.size))
continue;
// Handle each region separately, so that they can be individually skipped
trampoline(commandBuffer, srcBuffer, dstBuffer, 1, ®ion);
}
}
else
#endif
trampoline(commandBuffer, srcBuffer, dstBuffer, regionCount, pRegions);
}
void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdCopyImage, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::copy_texture_region>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkImageCopy ®ion = pRegions[i];
const reshade::api::subresource_box src_box = {
static_cast<uint32_t>(region.srcOffset.x),
static_cast<uint32_t>(region.srcOffset.y),
static_cast<uint32_t>(region.srcOffset.z),
static_cast<uint32_t>(region.srcOffset.x + region.extent.width),
static_cast<uint32_t>(region.srcOffset.y + region.extent.height),
static_cast<uint32_t>(region.srcOffset.z + region.extent.depth) + region.srcSubresource.layerCount
};
const reshade::api::subresource_box dst_box = {
static_cast<uint32_t>(region.dstOffset.x),
static_cast<uint32_t>(region.dstOffset.y),
static_cast<uint32_t>(region.dstOffset.z),
static_cast<uint32_t>(region.dstOffset.x + region.extent.width),
static_cast<uint32_t>(region.dstOffset.y + region.extent.height),
static_cast<uint32_t>(region.dstOffset.z + region.extent.depth) + region.dstSubresource.layerCount
};
if (reshade::invoke_addon_event<reshade::addon_event::copy_texture_region>(
cmd_impl,
reshade::api::resource { (uint64_t)srcImage }, calc_subresource_index(device_impl, srcImage, region.srcSubresource), &src_box,
reshade::api::resource { (uint64_t)dstImage }, calc_subresource_index(device_impl, dstImage, region.dstSubresource), &dst_box,
reshade::api::filter_mode::min_mag_mip_point))
continue;
// Handle each region separately, so that they can be individually skipped
trampoline(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, 1, ®ion);
}
}
else
#endif
trampoline(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions);
}
void VKAPI_CALL vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdBlitImage, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::copy_texture_region>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkImageBlit ®ion = pRegions[i];
const reshade::api::subresource_box src_box = {
static_cast<uint32_t>(region.srcOffsets[0].x),
static_cast<uint32_t>(region.srcOffsets[0].y),
static_cast<uint32_t>(region.srcOffsets[0].z),
static_cast<uint32_t>(region.srcOffsets[1].x),
static_cast<uint32_t>(region.srcOffsets[1].y),
static_cast<uint32_t>(region.srcOffsets[1].z) + region.srcSubresource.layerCount,
};
const reshade::api::subresource_box dst_box = {
static_cast<uint32_t>(region.srcOffsets[0].x),
static_cast<uint32_t>(region.srcOffsets[0].y),
static_cast<uint32_t>(region.srcOffsets[0].z),
static_cast<uint32_t>(region.srcOffsets[1].x),
static_cast<uint32_t>(region.srcOffsets[1].y),
static_cast<uint32_t>(region.srcOffsets[1].z) + region.srcSubresource.layerCount,
};
if (reshade::invoke_addon_event<reshade::addon_event::copy_texture_region>(
cmd_impl,
reshade::api::resource { (uint64_t)srcImage }, calc_subresource_index(device_impl, srcImage, region.srcSubresource), &src_box,
reshade::api::resource { (uint64_t)dstImage }, calc_subresource_index(device_impl, dstImage, region.dstSubresource), &dst_box,
filter == VK_FILTER_NEAREST ? reshade::api::filter_mode::min_mag_mip_point : reshade::api::filter_mode::min_mag_mip_linear))
continue;
trampoline(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, 1, ®ion, filter);
}
}
else
#endif
trampoline(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions, filter);
}
void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy *pRegions)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdCopyBufferToImage, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::copy_buffer_to_texture>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkBufferImageCopy ®ion = pRegions[i];
const reshade::api::subresource_box dst_box = {
static_cast<uint32_t>(region.imageOffset.x),
static_cast<uint32_t>(region.imageOffset.y),
static_cast<uint32_t>(region.imageOffset.z),
static_cast<uint32_t>(region.imageOffset.x + region.imageExtent.width),
static_cast<uint32_t>(region.imageOffset.y + region.imageExtent.height),
static_cast<uint32_t>(region.imageOffset.z + region.imageExtent.depth) + region.imageSubresource.layerCount
};
if (reshade::invoke_addon_event<reshade::addon_event::copy_buffer_to_texture>(
cmd_impl,
reshade::api::resource { (uint64_t)srcBuffer }, region.bufferOffset, region.bufferRowLength, region.bufferImageHeight,
reshade::api::resource { (uint64_t)dstImage }, calc_subresource_index(device_impl, dstImage, region.imageSubresource), &dst_box))
continue;
trampoline(commandBuffer, srcBuffer, dstImage, dstImageLayout, 1, ®ion);
}
}
else
#endif
trampoline(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions);
}
void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdCopyImageToBuffer, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::copy_texture_to_buffer>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkBufferImageCopy ®ion = pRegions[i];
const reshade::api::subresource_box src_box = {
static_cast<uint32_t>(region.imageOffset.x),
static_cast<uint32_t>(region.imageOffset.y),
static_cast<uint32_t>(region.imageOffset.z),
static_cast<uint32_t>(region.imageOffset.x + region.imageExtent.width),
static_cast<uint32_t>(region.imageOffset.y + region.imageExtent.height),
static_cast<uint32_t>(region.imageOffset.z + region.imageExtent.depth) + region.imageSubresource.layerCount
};
if (reshade::invoke_addon_event<reshade::addon_event::copy_texture_to_buffer>(
cmd_impl,
reshade::api::resource { (uint64_t)srcImage }, calc_subresource_index(device_impl, srcImage, region.imageSubresource), &src_box,
reshade::api::resource { (uint64_t)dstBuffer }, region.bufferOffset, region.bufferRowLength, region.bufferImageHeight))
continue;
trampoline(commandBuffer, srcImage, srcImageLayout, dstBuffer, 1, ®ion);
}
}
else
#endif
trampoline(commandBuffer, srcImage, srcImageLayout, dstBuffer, regionCount, pRegions);
}
void VKAPI_CALL vkCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue *pColor, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
if (reshade::has_addon_event<reshade::addon_event::clear_render_target_view>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
VkImageMemoryBarrier transition { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
transition.oldLayout = imageLayout;
transition.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
transition.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.image = image;
transition.subresourceRange.baseMipLevel = std::numeric_limits<uint32_t>::max();
transition.subresourceRange.baseArrayLayer = std::numeric_limits<uint32_t>::max();
for (uint32_t i = 0; i < rangeCount; ++i)
{
transition.subresourceRange.aspectMask |= pRanges[i].aspectMask;
transition.subresourceRange.baseMipLevel = std::min(transition.subresourceRange.baseMipLevel, pRanges[i].baseMipLevel);
transition.subresourceRange.levelCount = std::max(transition.subresourceRange.levelCount, pRanges[i].levelCount);
transition.subresourceRange.baseArrayLayer = std::min(transition.subresourceRange.baseArrayLayer, pRanges[i].baseArrayLayer);
transition.subresourceRange.layerCount = std::max(transition.subresourceRange.layerCount, pRanges[i].layerCount);
}
// The 'clear_render_target_view' event assumes the resource to be in 'resource_usage::render_target' state, so need to transition here
device_impl->_dispatch_table.CmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &transition);
const VkImageView default_view = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_IMAGE>(image)->default_view;
assert(default_view != VK_NULL_HANDLE); // A default view is created for every image that can potentially be cleared, see 'create_default_view' in vulkan_hooks_device.cpp
const bool skip = reshade::invoke_addon_event<reshade::addon_event::clear_render_target_view>(cmd_impl, reshade::api::resource_view { (uint64_t)default_view }, pColor->float32, 0, nullptr);
// Revert back to previous state
std::swap(transition.oldLayout, transition.newLayout);
device_impl->_dispatch_table.CmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &transition);
if (skip)
return;
}
#endif
GET_DISPATCH_PTR_FROM(CmdClearColorImage, device_impl);
trampoline(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
}
void VKAPI_CALL vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
#if RESHADE_ADDON
if (reshade::has_addon_event<reshade::addon_event::clear_depth_stencil_view>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
VkImageMemoryBarrier transition { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER };
transition.oldLayout = imageLayout;
transition.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
transition.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
transition.image = image;
transition.subresourceRange.baseMipLevel = std::numeric_limits<uint32_t>::max();
transition.subresourceRange.baseArrayLayer = std::numeric_limits<uint32_t>::max();
for (uint32_t i = 0; i < rangeCount; ++i)
{
transition.subresourceRange.aspectMask |= pRanges[i].aspectMask;
transition.subresourceRange.baseMipLevel = std::min(transition.subresourceRange.baseMipLevel, pRanges[i].baseMipLevel);
transition.subresourceRange.levelCount = std::max(transition.subresourceRange.levelCount, pRanges[i].levelCount);
transition.subresourceRange.baseArrayLayer = std::min(transition.subresourceRange.baseArrayLayer, pRanges[i].baseArrayLayer);
transition.subresourceRange.layerCount = std::max(transition.subresourceRange.layerCount, pRanges[i].layerCount);
}
// The 'clear_depth_stencil_view' event assumes the resource to be in 'resource_usage::depth_stencil' state, so need to transition here
device_impl->_dispatch_table.CmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &transition);
const VkImageView default_view = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_IMAGE>(image)->default_view;
assert(default_view != VK_NULL_HANDLE); // A default view is created for every image that can potentially be cleared, see 'create_default_view' in vulkan_hooks_device.cpp
const bool skip = reshade::invoke_addon_event<reshade::addon_event::clear_depth_stencil_view>(
cmd_impl,
reshade::api::resource_view { (uint64_t)default_view },
transition.subresourceRange.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT ? &pDepthStencil->depth : nullptr,
transition.subresourceRange.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT ? reinterpret_cast<const uint8_t *>(&pDepthStencil->stencil) : nullptr,
0, nullptr);
// Revert back to previous state
std::swap(transition.oldLayout, transition.newLayout);
device_impl->_dispatch_table.CmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &transition);
if (skip)
return;
}
#endif
GET_DISPATCH_PTR_FROM(CmdClearDepthStencilImage, device_impl);
trampoline(commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
}
void VKAPI_CALL vkCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment *pAttachments, uint32_t rectCount, const VkClearRect *pRects)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdClearAttachments, device_impl);
#if RESHADE_ADDON
if (reshade::has_addon_event<reshade::addon_event::clear_depth_stencil_view>() ||
reshade::has_addon_event<reshade::addon_event::clear_render_target_view>())
{
const auto cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
temp_mem<reshade::api::rect> rect_data(rectCount);
for (uint32_t i = 0; i < rectCount; ++i)
{
rect_data[i].left = pRects[i].rect.offset.x;
rect_data[i].top = pRects[i].rect.offset.y;
rect_data[i].right = pRects[i].rect.offset.x + static_cast<int32_t>(pRects[i].rect.extent.width);
rect_data[i].bottom = pRects[i].rect.offset.y + static_cast<int32_t>(pRects[i].rect.extent.height);
}
for (uint32_t i = 0; i < attachmentCount; ++i)
{
const VkClearAttachment &clear_attachment = pAttachments[i];
if (clear_attachment.aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
{
assert(clear_attachment.colorAttachment < 8);
assert(cmd_impl->current_color_attachments[clear_attachment.colorAttachment] != VK_NULL_HANDLE);
if (reshade::invoke_addon_event<reshade::addon_event::clear_render_target_view>(
cmd_impl,
reshade::api::resource_view { (uint64_t)cmd_impl->current_color_attachments[clear_attachment.colorAttachment] },
clear_attachment.clearValue.color.float32,
rectCount, rect_data.p))
continue;
}
else if (clear_attachment.aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))
{
assert(cmd_impl->current_depth_stencil_attachment != VK_NULL_HANDLE);
if (reshade::invoke_addon_event<reshade::addon_event::clear_depth_stencil_view>(
cmd_impl,
reshade::api::resource_view { (uint64_t)cmd_impl->current_depth_stencil_attachment },
clear_attachment.aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT ? &clear_attachment.clearValue.depthStencil.depth : nullptr,
clear_attachment.aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT ? reinterpret_cast<const uint8_t *>(&clear_attachment.clearValue.depthStencil.stencil) : nullptr,
rectCount, rect_data.p))
continue;
}
// Handle each attachment separately, so that they can be individually skipped
trampoline(commandBuffer, 1, &clear_attachment, rectCount, pRects);
}
}
else
#endif
trampoline(commandBuffer, attachmentCount, pAttachments, rectCount, pRects);
}
void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve *pRegions)
{
reshade::vulkan::device_impl *const device_impl = g_vulkan_devices.at(dispatch_key_from_handle(commandBuffer));
GET_DISPATCH_PTR_FROM(CmdResolveImage, device_impl);
#if RESHADE_ADDON >= 2
if (reshade::has_addon_event<reshade::addon_event::resolve_texture_region>())
{
reshade::vulkan::command_list_impl *const cmd_impl = device_impl->get_private_data_for_object<VK_OBJECT_TYPE_COMMAND_BUFFER>(commandBuffer);
for (uint32_t i = 0; i < regionCount; ++i)
{
const VkImageResolve ®ion = pRegions[i];
const reshade::api::subresource_box src_box = {
static_cast<uint32_t>(region.srcOffset.x),