forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_tracker.cpp
4618 lines (4097 loc) · 241 KB
/
state_tracker.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) 2015-2019 The Khronos Group Inc.
* Copyright (c) 2015-2019 Valve Corporation
* Copyright (c) 2015-2019 LunarG, Inc.
* Copyright (C) 2015-2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Mark Lobodzinski <[email protected]>
* Author: Dave Houlton <[email protected]>
* Shannon McPherson <[email protected]>
*/
// Allow use of STL min and max functions in Windows
#define NOMINMAX
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include "vk_enum_string_helper.h"
#include "vk_format_utils.h"
#include "vk_layer_data.h"
#include "vk_layer_utils.h"
#include "vk_layer_logging.h"
#include "vk_typemap_helper.h"
#include "chassis.h"
#include "state_tracker.h"
#include "shader_validation.h"
using std::max;
using std::string;
using std::stringstream;
using std::unique_ptr;
using std::unordered_map;
using std::unordered_set;
using std::vector;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
// This could also move into a seperate core_validation_android.cpp file... ?
void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {
const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext);
if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
is_node->imported_ahb = true;
}
const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext);
if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
is_node->has_ahb_format = true;
is_node->ahb_format = ext_fmt_android->externalFormat;
}
}
void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
VkSamplerYcbcrConversion ycbcr_conversion) {
const VkExternalFormatANDROID *ext_format_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext);
if (ext_format_android && (0 != ext_format_android->externalFormat)) {
ycbcr_conversion_ahb_fmt_map.emplace(ycbcr_conversion, ext_format_android->externalFormat);
}
};
void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) {
ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion);
};
#else
void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {}
void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
VkSamplerYcbcrConversion ycbcr_conversion){};
void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){};
#endif // VK_USE_PLATFORM_ANDROID_KHR
void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
if (VK_SUCCESS != result) return;
auto is_node = std::make_shared<IMAGE_STATE>(*pImage, pCreateInfo);
if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
RecordCreateImageANDROID(pCreateInfo, is_node.get());
}
const auto swapchain_info = lvl_find_in_chain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext);
if (swapchain_info) {
is_node->create_from_swapchain = swapchain_info->swapchain;
}
bool pre_fetch_memory_reqs = true;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
if (is_node->external_format_android) {
// Do not fetch requirements for external memory images
pre_fetch_memory_reqs = false;
}
#endif
// Record the memory requirements in case they won't be queried
if (pre_fetch_memory_reqs) {
DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements);
}
imageMap.insert(std::make_pair(*pImage, std::move(is_node)));
}
void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
if (!image) return;
IMAGE_STATE *image_state = GetImageState(image);
const VulkanTypedHandle obj_struct(image, kVulkanObjectTypeImage);
InvalidateCommandBuffers(image_state->cb_bindings, obj_struct);
// Clean up memory mapping, bindings and range references for image
for (auto mem_binding : image_state->GetBoundMemory()) {
auto mem_info = GetDevMemState(mem_binding);
if (mem_info) {
RemoveImageMemoryRange(image, mem_info);
}
}
if (image_state->bind_swapchain) {
auto swapchain = GetSwapchainState(image_state->bind_swapchain);
if (swapchain) {
swapchain->images[image_state->bind_swapchain_imageIndex].bound_images.erase(image_state->image);
}
}
RemoveAliasingImage(image_state);
ClearMemoryObjectBindings(obj_struct);
image_state->destroyed = true;
// Remove image from imageMap
imageMap.erase(image);
}
void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
VkImageLayout imageLayout, const VkClearColorValue *pColor,
uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
auto cb_node = GetCBState(commandBuffer);
auto image_state = GetImageState(image);
if (cb_node && image_state) {
AddCommandBufferBindingImage(cb_node, image_state);
}
}
void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
VkImageLayout imageLayout,
const VkClearDepthStencilValue *pDepthStencil,
uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
auto cb_node = GetCBState(commandBuffer);
auto image_state = GetImageState(image);
if (cb_node && image_state) {
AddCommandBufferBindingImage(cb_node, image_state);
}
}
void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
uint32_t regionCount, const VkImageCopy *pRegions) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(srcImage);
auto dst_image_state = GetImageState(dstImage);
// Update bindings between images and cmd buffer
AddCommandBufferBindingImage(cb_node, src_image_state);
AddCommandBufferBindingImage(cb_node, dst_image_state);
}
void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage,
VkImageLayout dstImageLayout, uint32_t regionCount,
const VkImageResolve *pRegions) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(srcImage);
auto dst_image_state = GetImageState(dstImage);
// Update bindings between images and cmd buffer
AddCommandBufferBindingImage(cb_node, src_image_state);
AddCommandBufferBindingImage(cb_node, dst_image_state);
}
void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(srcImage);
auto dst_image_state = GetImageState(dstImage);
// Update bindings between images and cmd buffer
AddCommandBufferBindingImage(cb_node, src_image_state);
AddCommandBufferBindingImage(cb_node, dst_image_state);
}
void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
VkResult result) {
if (result != VK_SUCCESS) return;
// TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo);
// Get a set of requirements in the case the app does not
DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements);
bufferMap.insert(std::make_pair(*pBuffer, std::move(buffer_state)));
}
void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
VkResult result) {
if (result != VK_SUCCESS) return;
auto buffer_state = GetBufferShared(pCreateInfo->buffer);
bufferViewMap[*pView] = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo);
}
void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImageView *pView,
VkResult result) {
if (result != VK_SUCCESS) return;
auto image_state = GetImageShared(pCreateInfo->image);
imageViewMap[*pView] = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo);
}
void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
uint32_t regionCount, const VkBufferCopy *pRegions) {
auto cb_node = GetCBState(commandBuffer);
auto src_buffer_state = GetBufferState(srcBuffer);
auto dst_buffer_state = GetBufferState(dstBuffer);
// Update bindings between buffers and cmd buffer
AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
}
void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
const VkAllocationCallbacks *pAllocator) {
IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView);
if (!image_view_state) return;
const VulkanTypedHandle obj_struct(imageView, kVulkanObjectTypeImageView);
// Any bound cmd buffers are now invalid
InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct);
image_view_state->destroyed = true;
imageViewMap.erase(imageView);
}
void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
if (!buffer) return;
auto buffer_state = GetBufferState(buffer);
const VulkanTypedHandle obj_struct(buffer, kVulkanObjectTypeBuffer);
InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct);
for (auto mem_binding : buffer_state->GetBoundMemory()) {
auto mem_info = GetDevMemState(mem_binding);
if (mem_info) {
RemoveBufferMemoryRange(buffer, mem_info);
}
}
ClearMemoryObjectBindings(obj_struct);
buffer_state->destroyed = true;
bufferMap.erase(buffer_state->buffer);
}
void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator) {
if (!bufferView) return;
auto buffer_view_state = GetBufferViewState(bufferView);
const VulkanTypedHandle obj_struct(bufferView, kVulkanObjectTypeBufferView);
// Any bound cmd buffers are now invalid
InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct);
buffer_view_state->destroyed = true;
bufferViewMap.erase(bufferView);
}
void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
VkDeviceSize size, uint32_t data) {
auto cb_node = GetCBState(commandBuffer);
auto buffer_state = GetBufferState(dstBuffer);
// Update bindings between buffer and cmd buffer
AddCommandBufferBindingBuffer(cb_node, buffer_state);
}
void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkBuffer dstBuffer,
uint32_t regionCount, const VkBufferImageCopy *pRegions) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(srcImage);
auto dst_buffer_state = GetBufferState(dstBuffer);
// Update bindings between buffer/image and cmd buffer
AddCommandBufferBindingImage(cb_node, src_image_state);
AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
}
void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
VkImageLayout dstImageLayout, uint32_t regionCount,
const VkBufferImageCopy *pRegions) {
auto cb_node = GetCBState(commandBuffer);
auto src_buffer_state = GetBufferState(srcBuffer);
auto dst_image_state = GetImageState(dstImage);
AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
AddCommandBufferBindingImage(cb_node, dst_image_state);
}
// Get the image viewstate for a given framebuffer attachment
IMAGE_VIEW_STATE *ValidationStateTracker::GetAttachmentImageViewState(FRAMEBUFFER_STATE *framebuffer, uint32_t index) {
assert(framebuffer && (index < framebuffer->createInfo.attachmentCount));
const VkImageView &image_view = framebuffer->createInfo.pAttachments[index];
return GetImageViewState(image_view);
}
// Get the image viewstate for a given framebuffer attachment
const IMAGE_VIEW_STATE *ValidationStateTracker::GetAttachmentImageViewState(const FRAMEBUFFER_STATE *framebuffer,
uint32_t index) const {
assert(framebuffer && (index < framebuffer->createInfo.attachmentCount));
const VkImageView &image_view = framebuffer->createInfo.pAttachments[index];
return GetImageViewState(image_view);
}
void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state) {
if (!(image_state->createInfo.flags & VK_IMAGE_CREATE_ALIAS_BIT)) return;
std::unordered_set<VkImage> *bound_images = nullptr;
if (image_state->bind_swapchain) {
auto swapchain_state = GetSwapchainState(image_state->bind_swapchain);
if (swapchain_state) {
bound_images = &swapchain_state->images[image_state->bind_swapchain_imageIndex].bound_images;
}
} else {
auto mem_state = GetDevMemState(image_state->binding.mem);
if (mem_state) {
bound_images = &mem_state->bound_images;
}
}
if (bound_images) {
for (const auto &handle : *bound_images) {
if (handle != image_state->image) {
auto is = GetImageState(handle);
if (is && is->IsCompatibleAliasing(image_state)) {
auto inserted = is->aliasing_images.emplace(image_state->image);
if (inserted.second) {
image_state->aliasing_images.emplace(handle);
}
}
}
}
}
}
void ValidationStateTracker::RemoveAliasingImage(IMAGE_STATE *image_state) {
for (const auto &image : image_state->aliasing_images) {
auto is = GetImageState(image);
if (is) {
is->aliasing_images.erase(image_state->image);
}
}
image_state->aliasing_images.clear();
}
void ValidationStateTracker::RemoveAliasingImages(const std::unordered_set<VkImage> &bound_images) {
// This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole
// reference. It doesn't need two ways clear.
for (const auto &handle : bound_images) {
auto is = GetImageState(handle);
if (is) {
is->aliasing_images.clear();
}
}
}
const EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) const {
auto it = eventMap.find(event);
if (it == eventMap.end()) {
return nullptr;
}
return &it->second;
}
EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) {
auto it = eventMap.find(event);
if (it == eventMap.end()) {
return nullptr;
}
return &it->second;
}
const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const {
auto it = queueMap.find(queue);
if (it == queueMap.cend()) {
return nullptr;
}
return &it->second;
}
QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) {
auto it = queueMap.find(queue);
if (it == queueMap.end()) {
return nullptr;
}
return &it->second;
}
const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const {
auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map);
auto it = phys_dev_map->find(phys);
if (it == phys_dev_map->end()) {
return nullptr;
}
return &it->second;
}
PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) {
auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map);
auto it = phys_dev_map->find(phys);
if (it == phys_dev_map->end()) {
return nullptr;
}
return &it->second;
}
PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; }
const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; }
// Return ptr to memory binding for given handle of specified type
template <typename State, typename Result>
static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) {
switch (typed_handle.type) {
case kVulkanObjectTypeImage:
return state->GetImageState(typed_handle.Cast<VkImage>());
case kVulkanObjectTypeBuffer:
return state->GetBufferState(typed_handle.Cast<VkBuffer>());
case kVulkanObjectTypeAccelerationStructureNV:
return state->GetAccelerationStructureState(typed_handle.Cast<VkAccelerationStructureNV>());
default:
break;
}
return nullptr;
}
const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const {
return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle);
}
BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) {
return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle);
}
void ValidationStateTracker::AddMemObjInfo(void *object, const VkDeviceMemory mem, const VkMemoryAllocateInfo *pAllocateInfo) {
assert(object != NULL);
memObjMap[mem] = std::make_shared<DEVICE_MEMORY_STATE>(object, mem, pAllocateInfo);
auto mem_info = memObjMap[mem].get();
auto dedicated = lvl_find_in_chain<VkMemoryDedicatedAllocateInfoKHR>(pAllocateInfo->pNext);
if (dedicated) {
mem_info->is_dedicated = true;
mem_info->dedicated_buffer = dedicated->buffer;
mem_info->dedicated_image = dedicated->image;
}
auto export_info = lvl_find_in_chain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext);
if (export_info) {
mem_info->is_export = true;
mem_info->export_handle_type_flags = export_info->handleTypes;
}
}
// Create binding link between given sampler and command buffer node
void ValidationStateTracker::AddCommandBufferBindingSampler(CMD_BUFFER_STATE *cb_node, SAMPLER_STATE *sampler_state) {
if (disabled.command_buffer_state) {
return;
}
AddCommandBufferBinding(sampler_state->cb_bindings,
VulkanTypedHandle(sampler_state->sampler, kVulkanObjectTypeSampler, sampler_state), cb_node);
}
// Create binding link between given image node and command buffer node
void ValidationStateTracker::AddCommandBufferBindingImage(CMD_BUFFER_STATE *cb_node, IMAGE_STATE *image_state) {
if (disabled.command_buffer_state) {
return;
}
// Skip validation if this image was created through WSI
if (image_state->create_from_swapchain == VK_NULL_HANDLE) {
// First update cb binding for image
if (AddCommandBufferBinding(image_state->cb_bindings,
VulkanTypedHandle(image_state->image, kVulkanObjectTypeImage, image_state), cb_node)) {
// Now update CB binding in MemObj mini CB list
for (auto mem_binding : image_state->GetBoundMemory()) {
DEVICE_MEMORY_STATE *pMemInfo = GetDevMemState(mem_binding);
if (pMemInfo) {
// Now update CBInfo's Mem reference list
AddCommandBufferBinding(pMemInfo->cb_bindings,
VulkanTypedHandle(mem_binding, kVulkanObjectTypeDeviceMemory, pMemInfo), cb_node);
}
}
}
}
}
// Create binding link between given image view node and its image with command buffer node
void ValidationStateTracker::AddCommandBufferBindingImageView(CMD_BUFFER_STATE *cb_node, IMAGE_VIEW_STATE *view_state) {
if (disabled.command_buffer_state) {
return;
}
// First add bindings for imageView
if (AddCommandBufferBinding(view_state->cb_bindings,
VulkanTypedHandle(view_state->image_view, kVulkanObjectTypeImageView, view_state), cb_node)) {
// Only need to continue if this is a new item
auto image_state = view_state->image_state.get();
// Add bindings for image within imageView
if (image_state) {
AddCommandBufferBindingImage(cb_node, image_state);
}
}
}
// Create binding link between given buffer node and command buffer node
void ValidationStateTracker::AddCommandBufferBindingBuffer(CMD_BUFFER_STATE *cb_node, BUFFER_STATE *buffer_state) {
if (disabled.command_buffer_state) {
return;
}
// First update cb binding for buffer
if (AddCommandBufferBinding(buffer_state->cb_bindings,
VulkanTypedHandle(buffer_state->buffer, kVulkanObjectTypeBuffer, buffer_state), cb_node)) {
// Now update CB binding in MemObj mini CB list
for (auto mem_binding : buffer_state->GetBoundMemory()) {
DEVICE_MEMORY_STATE *pMemInfo = GetDevMemState(mem_binding);
if (pMemInfo) {
// Now update CBInfo's Mem reference list
AddCommandBufferBinding(pMemInfo->cb_bindings,
VulkanTypedHandle(mem_binding, kVulkanObjectTypeDeviceMemory, pMemInfo), cb_node);
}
}
}
}
// Create binding link between given buffer view node and its buffer with command buffer node
void ValidationStateTracker::AddCommandBufferBindingBufferView(CMD_BUFFER_STATE *cb_node, BUFFER_VIEW_STATE *view_state) {
if (disabled.command_buffer_state) {
return;
}
// First add bindings for bufferView
if (AddCommandBufferBinding(view_state->cb_bindings,
VulkanTypedHandle(view_state->buffer_view, kVulkanObjectTypeBufferView, view_state), cb_node)) {
auto buffer_state = view_state->buffer_state.get();
// Add bindings for buffer within bufferView
if (buffer_state) {
AddCommandBufferBindingBuffer(cb_node, buffer_state);
}
}
}
// Create binding link between given acceleration structure and command buffer node
void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node,
ACCELERATION_STRUCTURE_STATE *as_state) {
if (disabled.command_buffer_state) {
return;
}
if (AddCommandBufferBinding(
as_state->cb_bindings,
VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureNV, as_state), cb_node)) {
// Now update CB binding in MemObj mini CB list
for (auto mem_binding : as_state->GetBoundMemory()) {
DEVICE_MEMORY_STATE *pMemInfo = GetDevMemState(mem_binding);
if (pMemInfo) {
// Now update CBInfo's Mem reference list
AddCommandBufferBinding(pMemInfo->cb_bindings,
VulkanTypedHandle(mem_binding, kVulkanObjectTypeDeviceMemory, pMemInfo), cb_node);
}
}
}
}
// Clear a single object binding from given memory object
void ValidationStateTracker::ClearMemoryObjectBinding(const VulkanTypedHandle &typed_handle, VkDeviceMemory mem) {
DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
// This obj is bound to a memory object. Remove the reference to this object in that memory object's list
if (mem_info) {
mem_info->obj_bindings.erase(typed_handle);
}
}
// ClearMemoryObjectBindings clears the binding of objects to memory
// For the given object it pulls the memory bindings and makes sure that the bindings
// no longer refer to the object being cleared. This occurs when objects are destroyed.
void ValidationStateTracker::ClearMemoryObjectBindings(const VulkanTypedHandle &typed_handle) {
BINDABLE *mem_binding = GetObjectMemBinding(typed_handle);
if (mem_binding) {
if (!mem_binding->sparse) {
ClearMemoryObjectBinding(typed_handle, mem_binding->binding.mem);
} else { // Sparse, clear all bindings
for (auto &sparse_mem_binding : mem_binding->sparse_bindings) {
ClearMemoryObjectBinding(typed_handle, sparse_mem_binding.mem);
}
}
}
}
// SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object.
// Corresponding valid usage checks are in ValidateSetMemBinding().
void ValidationStateTracker::SetMemBinding(VkDeviceMemory mem, BINDABLE *mem_binding, VkDeviceSize memory_offset,
const VulkanTypedHandle &typed_handle) {
assert(mem_binding);
mem_binding->binding.mem = mem;
mem_binding->UpdateBoundMemorySet(); // force recreation of cached set
mem_binding->binding.offset = memory_offset;
mem_binding->binding.size = mem_binding->requirements.size;
if (mem != VK_NULL_HANDLE) {
DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
if (mem_info) {
mem_info->obj_bindings.insert(typed_handle);
// For image objects, make sure default memory state is correctly set
// TODO : What's the best/correct way to handle this?
if (kVulkanObjectTypeImage == typed_handle.type) {
auto const image_state = reinterpret_cast<const IMAGE_STATE *>(mem_binding);
if (image_state) {
VkImageCreateInfo ici = image_state->createInfo;
if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
// TODO:: More memory state transition stuff.
}
}
}
}
}
}
// For NULL mem case, clear any previous binding Else...
// Make sure given object is in its object map
// IF a previous binding existed, update binding
// Add reference from objectInfo to memoryInfo
// Add reference off of object's binding info
// Return VK_TRUE if addition is successful, VK_FALSE otherwise
bool ValidationStateTracker::SetSparseMemBinding(MEM_BINDING binding, const VulkanTypedHandle &typed_handle) {
bool skip = VK_FALSE;
// Handle NULL case separately, just clear previous binding & decrement reference
if (binding.mem == VK_NULL_HANDLE) {
// TODO : This should cause the range of the resource to be unbound according to spec
} else {
BINDABLE *mem_binding = GetObjectMemBinding(typed_handle);
assert(mem_binding);
if (mem_binding) { // Invalid handles are reported by object tracker, but Get returns NULL for them, so avoid SEGV here
assert(mem_binding->sparse);
DEVICE_MEMORY_STATE *mem_info = GetDevMemState(binding.mem);
if (mem_info) {
mem_info->obj_bindings.insert(typed_handle);
// Need to set mem binding for this object
mem_binding->sparse_bindings.insert(binding);
mem_binding->UpdateBoundMemorySet();
}
}
}
return skip;
}
void ValidationStateTracker::UpdateDrawState(CMD_BUFFER_STATE *cb_state, const VkPipelineBindPoint bind_point) {
auto &state = cb_state->lastBound[bind_point];
PIPELINE_STATE *pPipe = state.pipeline_state;
if (VK_NULL_HANDLE != state.pipeline_layout) {
for (const auto &set_binding_pair : pPipe->active_slots) {
uint32_t setIndex = set_binding_pair.first;
// Pull the set node
cvdescriptorset::DescriptorSet *descriptor_set = state.per_set[setIndex].bound_descriptor_set;
if (!descriptor_set->IsPushDescriptor()) {
// For the "bindless" style resource usage with many descriptors, need to optimize command <-> descriptor binding
// TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the
// Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count
cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second);
const auto &binding_req_map = reduced_map.FilteredMap(*cb_state, *pPipe);
if (reduced_map.IsManyDescriptors()) {
// Only update validate binding tags if we meet the "many" criteria in the Prefilter class
descriptor_set->UpdateValidationCache(*cb_state, *pPipe, binding_req_map);
}
// We can skip updating the state if "nothing" has changed since the last validation.
// See CoreChecks::ValidateCmdBufDrawState for more details.
bool descriptor_set_changed =
!reduced_map.IsManyDescriptors() ||
// Update if descriptor set (or contents) has changed
state.per_set[setIndex].validated_set != descriptor_set ||
state.per_set[setIndex].validated_set_change_count != descriptor_set->GetChangeCount() ||
(!disabled.image_layout_validation &&
state.per_set[setIndex].validated_set_image_layout_change_count != cb_state->image_layout_change_count);
bool need_update = descriptor_set_changed ||
// Update if previous bindingReqMap doesn't include new bindingReqMap
!std::includes(state.per_set[setIndex].validated_set_binding_req_map.begin(),
state.per_set[setIndex].validated_set_binding_req_map.end(),
binding_req_map.begin(), binding_req_map.end());
if (need_update) {
// Bind this set and its active descriptor resources to the command buffer
if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) {
// Only record the bindings that haven't already been recorded
BindingReqMap delta_reqs;
std::set_difference(binding_req_map.begin(), binding_req_map.end(),
state.per_set[setIndex].validated_set_binding_req_map.begin(),
state.per_set[setIndex].validated_set_binding_req_map.end(),
std::inserter(delta_reqs, delta_reqs.begin()));
descriptor_set->UpdateDrawState(this, cb_state, pPipe, delta_reqs);
} else {
descriptor_set->UpdateDrawState(this, cb_state, pPipe, binding_req_map);
}
state.per_set[setIndex].validated_set = descriptor_set;
state.per_set[setIndex].validated_set_change_count = descriptor_set->GetChangeCount();
state.per_set[setIndex].validated_set_image_layout_change_count = cb_state->image_layout_change_count;
if (reduced_map.IsManyDescriptors()) {
// Check whether old == new before assigning, the equality check is much cheaper than
// freeing and reallocating the map.
if (state.per_set[setIndex].validated_set_binding_req_map != set_binding_pair.second) {
state.per_set[setIndex].validated_set_binding_req_map = set_binding_pair.second;
}
} else {
state.per_set[setIndex].validated_set_binding_req_map = BindingReqMap();
}
}
}
}
}
if (!pPipe->vertex_binding_descriptions_.empty()) {
cb_state->vertex_buffer_used = true;
}
}
// Remove set from setMap and delete the set
void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) {
descriptor_set->destroyed = true;
const VulkanTypedHandle obj_struct(descriptor_set->GetSet(), kVulkanObjectTypeDescriptorSet);
// Any bound cmd buffers are now invalid
InvalidateCommandBuffers(descriptor_set->cb_bindings, obj_struct);
setMap.erase(descriptor_set->GetSet());
}
// Free all DS Pools including their Sets & related sub-structs
// NOTE : Calls to this function should be wrapped in mutex
void ValidationStateTracker::DeleteDescriptorSetPools() {
for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) {
// Remove this pools' sets from setMap and delete them
for (auto ds : ii->second->sets) {
FreeDescriptorSet(ds);
}
ii->second->sets.clear();
ii = descriptorPoolMap.erase(ii);
}
}
// For given object struct return a ptr of BASE_NODE type for its wrapping struct
BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) {
if (object_struct.node) {
#ifdef _DEBUG
// assert that lookup would find the same object
VulkanTypedHandle other = object_struct;
other.node = nullptr;
assert(object_struct.node == GetStateStructPtrFromObject(other));
#endif
return object_struct.node;
}
BASE_NODE *base_ptr = nullptr;
switch (object_struct.type) {
case kVulkanObjectTypeDescriptorSet: {
base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>());
break;
}
case kVulkanObjectTypeSampler: {
base_ptr = GetSamplerState(object_struct.Cast<VkSampler>());
break;
}
case kVulkanObjectTypeQueryPool: {
base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>());
break;
}
case kVulkanObjectTypePipeline: {
base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>());
break;
}
case kVulkanObjectTypeBuffer: {
base_ptr = GetBufferState(object_struct.Cast<VkBuffer>());
break;
}
case kVulkanObjectTypeBufferView: {
base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>());
break;
}
case kVulkanObjectTypeImage: {
base_ptr = GetImageState(object_struct.Cast<VkImage>());
break;
}
case kVulkanObjectTypeImageView: {
base_ptr = GetImageViewState(object_struct.Cast<VkImageView>());
break;
}
case kVulkanObjectTypeEvent: {
base_ptr = GetEventState(object_struct.Cast<VkEvent>());
break;
}
case kVulkanObjectTypeDescriptorPool: {
base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>());
break;
}
case kVulkanObjectTypeCommandPool: {
base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>());
break;
}
case kVulkanObjectTypeFramebuffer: {
base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>());
break;
}
case kVulkanObjectTypeRenderPass: {
base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>());
break;
}
case kVulkanObjectTypeDeviceMemory: {
base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>());
break;
}
case kVulkanObjectTypeAccelerationStructureNV: {
base_ptr = GetAccelerationStructureState(object_struct.Cast<VkAccelerationStructureNV>());
break;
}
case kVulkanObjectTypeUnknown:
// This can happen if an element of the object_bindings vector has been
// zeroed out, after an object is destroyed.
break;
default:
// TODO : Any other objects to be handled here?
assert(0);
break;
}
return base_ptr;
}
// Tie the VulkanTypedHandle to the cmd buffer which includes:
// Add object_binding to cmd buffer
// Add cb_binding to object
bool ValidationStateTracker::AddCommandBufferBinding(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_bindings,
const VulkanTypedHandle &obj, CMD_BUFFER_STATE *cb_node) {
if (disabled.command_buffer_state) {
return false;
}
// Insert the cb_binding with a default 'index' of -1. Then push the obj into the object_bindings
// vector, and update cb_bindings[cb_node] with the index of that element of the vector.
auto inserted = cb_bindings.insert({cb_node, -1});
if (inserted.second) {
cb_node->object_bindings.push_back(obj);
inserted.first->second = (int)cb_node->object_bindings.size() - 1;
return true;
}
return false;
}
// For a given object, if cb_node is in that objects cb_bindings, remove cb_node
void ValidationStateTracker::RemoveCommandBufferBinding(VulkanTypedHandle const &object, CMD_BUFFER_STATE *cb_node) {
BASE_NODE *base_obj = GetStateStructPtrFromObject(object);
if (base_obj) base_obj->cb_bindings.erase(cb_node);
}
// Reset the command buffer state
// Maintain the createInfo and set state to CB_NEW, but clear all other state
void ValidationStateTracker::ResetCommandBufferState(const VkCommandBuffer cb) {
CMD_BUFFER_STATE *pCB = GetCBState(cb);
if (pCB) {
pCB->in_use.store(0);
// Reset CB state (note that createInfo is not cleared)
pCB->commandBuffer = cb;
memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
memset(&pCB->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
pCB->hasDrawCmd = false;
pCB->hasTraceRaysCmd = false;
pCB->hasBuildAccelerationStructureCmd = false;
pCB->hasDispatchCmd = false;
pCB->state = CB_NEW;
pCB->commandCount = 0;
pCB->submitCount = 0;
pCB->image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty
pCB->status = 0;
pCB->static_status = 0;
pCB->viewportMask = 0;
pCB->scissorMask = 0;
for (auto &item : pCB->lastBound) {
item.second.reset();
}
memset(&pCB->activeRenderPassBeginInfo, 0, sizeof(pCB->activeRenderPassBeginInfo));
pCB->activeRenderPass = nullptr;
pCB->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
pCB->activeSubpass = 0;
pCB->broken_bindings.clear();
pCB->waitedEvents.clear();
pCB->events.clear();
pCB->writeEventsBeforeWait.clear();
pCB->activeQueries.clear();
pCB->startedQueries.clear();
pCB->image_layout_map.clear();
pCB->current_vertex_buffer_binding_info.vertex_buffer_bindings.clear();
pCB->vertex_buffer_used = false;
pCB->primaryCommandBuffer = VK_NULL_HANDLE;
// If secondary, invalidate any primary command buffer that may call us.
if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
InvalidateLinkedCommandBuffers(pCB->linkedCommandBuffers, VulkanTypedHandle(cb, kVulkanObjectTypeCommandBuffer));
}
// Remove reverse command buffer links.
for (auto pSubCB : pCB->linkedCommandBuffers) {
pSubCB->linkedCommandBuffers.erase(pCB);
}
pCB->linkedCommandBuffers.clear();
pCB->queue_submit_functions.clear();
pCB->cmd_execute_commands_functions.clear();
pCB->eventUpdates.clear();
pCB->queryUpdates.clear();
// Remove object bindings
for (const auto &obj : pCB->object_bindings) {
RemoveCommandBufferBinding(obj, pCB);
}
pCB->object_bindings.clear();
// Remove this cmdBuffer's reference from each FrameBuffer's CB ref list
for (auto framebuffer : pCB->framebuffers) {
auto fb_state = GetFramebufferState(framebuffer);
if (fb_state) fb_state->cb_bindings.erase(pCB);
}
pCB->framebuffers.clear();
pCB->activeFramebuffer = VK_NULL_HANDLE;
memset(&pCB->index_buffer_binding, 0, sizeof(pCB->index_buffer_binding));
pCB->qfo_transfer_image_barriers.Reset();
pCB->qfo_transfer_buffer_barriers.Reset();
// Clean up the label data
ResetCmdDebugUtilsLabel(report_data, pCB->commandBuffer);
pCB->debug_label.Reset();
pCB->validate_descriptorsets_in_queuesubmit.clear();
}
if (command_buffer_reset_callback) {
(*command_buffer_reset_callback)(cb);
}
}
void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
VkResult result) {
if (VK_SUCCESS != result) return;
const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
if (nullptr == enabled_features_found) {
const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
if (features2) {
enabled_features_found = &(features2->features);
}
}
ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
if (nullptr == enabled_features_found) {
state_tracker->enabled_features.core = {};
} else {
state_tracker->enabled_features.core = *enabled_features_found;
}
// Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not
// previously set them through an explicit API call.
uint32_t count;
auto pd_state = GetPhysicalDeviceState(gpu);
DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count));
DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]);
// Save local link to this device's physical device state
state_tracker->physical_device_state = pd_state;
const auto *device_group_ci = lvl_find_in_chain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
state_tracker->physical_device_count =
device_group_ci && device_group_ci->physicalDeviceCount > 0 ? device_group_ci->physicalDeviceCount : 1;
const auto *descriptor_indexing_features = lvl_find_in_chain<VkPhysicalDeviceDescriptorIndexingFeaturesEXT>(pCreateInfo->pNext);
if (descriptor_indexing_features) {
state_tracker->enabled_features.descriptor_indexing = *descriptor_indexing_features;
}
const auto *eight_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice8BitStorageFeaturesKHR>(pCreateInfo->pNext);
if (eight_bit_storage_features) {
state_tracker->enabled_features.eight_bit_storage = *eight_bit_storage_features;
}
const auto *exclusive_scissor_features = lvl_find_in_chain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
if (exclusive_scissor_features) {
state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features;
}
const auto *shading_rate_image_features = lvl_find_in_chain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);