forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_tracker.cpp
6486 lines (5748 loc) · 351 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-2021 The Khronos Group Inc.
* Copyright (c) 2015-2021 Valve Corporation
* Copyright (c) 2015-2021 LunarG, Inc.
* Copyright (C) 2015-2021 Google Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* 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]>
* Author: Tobias Hector <[email protected]>
*/
#include <cmath>
#include <set>
#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"
#include "sync_utils.h"
const char *CommandTypeString(CMD_TYPE type) {
// Autogenerated as part of the vk_validation_error_message.h codegen
return kGeneratedCommandNameList[type];
}
VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag) {
switch (flag) {
case CBSTATUS_LINE_WIDTH_SET:
return VK_DYNAMIC_STATE_LINE_WIDTH;
case CBSTATUS_DEPTH_BIAS_SET:
return VK_DYNAMIC_STATE_DEPTH_BIAS;
case CBSTATUS_BLEND_CONSTANTS_SET:
return VK_DYNAMIC_STATE_BLEND_CONSTANTS;
case CBSTATUS_DEPTH_BOUNDS_SET:
return VK_DYNAMIC_STATE_DEPTH_BOUNDS;
case CBSTATUS_STENCIL_READ_MASK_SET:
return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK;
case CBSTATUS_STENCIL_WRITE_MASK_SET:
return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK;
case CBSTATUS_STENCIL_REFERENCE_SET:
return VK_DYNAMIC_STATE_STENCIL_REFERENCE;
case CBSTATUS_VIEWPORT_SET:
return VK_DYNAMIC_STATE_VIEWPORT;
case CBSTATUS_SCISSOR_SET:
return VK_DYNAMIC_STATE_SCISSOR;
case CBSTATUS_EXCLUSIVE_SCISSOR_SET:
return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV;
case CBSTATUS_SHADING_RATE_PALETTE_SET:
return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV;
case CBSTATUS_LINE_STIPPLE_SET:
return VK_DYNAMIC_STATE_LINE_STIPPLE_EXT;
case CBSTATUS_VIEWPORT_W_SCALING_SET:
return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV;
case CBSTATUS_CULL_MODE_SET:
return VK_DYNAMIC_STATE_CULL_MODE_EXT;
case CBSTATUS_FRONT_FACE_SET:
return VK_DYNAMIC_STATE_FRONT_FACE_EXT;
case CBSTATUS_PRIMITIVE_TOPOLOGY_SET:
return VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT;
case CBSTATUS_VIEWPORT_WITH_COUNT_SET:
return VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT;
case CBSTATUS_SCISSOR_WITH_COUNT_SET:
return VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT;
case CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET:
return VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT;
case CBSTATUS_DEPTH_TEST_ENABLE_SET:
return VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT;
case CBSTATUS_DEPTH_WRITE_ENABLE_SET:
return VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT;
case CBSTATUS_DEPTH_COMPARE_OP_SET:
return VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT;
case CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET:
return VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT;
case CBSTATUS_STENCIL_TEST_ENABLE_SET:
return VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT;
case CBSTATUS_STENCIL_OP_SET:
return VK_DYNAMIC_STATE_STENCIL_OP_EXT;
case CBSTATUS_DISCARD_RECTANGLE_SET:
return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT;
case CBSTATUS_SAMPLE_LOCATIONS_SET:
return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT;
case CBSTATUS_COARSE_SAMPLE_ORDER_SET:
return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV;
default:
// CBSTATUS_INDEX_BUFFER_BOUND is not in VkDynamicState
return VK_DYNAMIC_STATE_MAX_ENUM;
}
return VK_DYNAMIC_STATE_MAX_ENUM;
}
CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state) {
switch (state) {
case VK_DYNAMIC_STATE_VIEWPORT:
return CBSTATUS_VIEWPORT_SET;
case VK_DYNAMIC_STATE_SCISSOR:
return CBSTATUS_SCISSOR_SET;
case VK_DYNAMIC_STATE_LINE_WIDTH:
return CBSTATUS_LINE_WIDTH_SET;
case VK_DYNAMIC_STATE_DEPTH_BIAS:
return CBSTATUS_DEPTH_BIAS_SET;
case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
return CBSTATUS_BLEND_CONSTANTS_SET;
case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
return CBSTATUS_DEPTH_BOUNDS_SET;
case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
return CBSTATUS_STENCIL_READ_MASK_SET;
case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
return CBSTATUS_STENCIL_WRITE_MASK_SET;
case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
return CBSTATUS_STENCIL_REFERENCE_SET;
case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV:
return CBSTATUS_VIEWPORT_W_SCALING_SET;
case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT:
return CBSTATUS_DISCARD_RECTANGLE_SET;
case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT:
return CBSTATUS_SAMPLE_LOCATIONS_SET;
case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV:
return CBSTATUS_SHADING_RATE_PALETTE_SET;
case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV:
return CBSTATUS_COARSE_SAMPLE_ORDER_SET;
case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV:
return CBSTATUS_EXCLUSIVE_SCISSOR_SET;
case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT:
return CBSTATUS_LINE_STIPPLE_SET;
case VK_DYNAMIC_STATE_CULL_MODE_EXT:
return CBSTATUS_CULL_MODE_SET;
case VK_DYNAMIC_STATE_FRONT_FACE_EXT:
return CBSTATUS_FRONT_FACE_SET;
case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT:
return CBSTATUS_PRIMITIVE_TOPOLOGY_SET;
case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT:
return CBSTATUS_VIEWPORT_WITH_COUNT_SET;
case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT:
return CBSTATUS_SCISSOR_WITH_COUNT_SET;
case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT:
return CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT:
return CBSTATUS_DEPTH_TEST_ENABLE_SET;
case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT:
return CBSTATUS_DEPTH_WRITE_ENABLE_SET;
case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT:
return CBSTATUS_DEPTH_COMPARE_OP_SET;
case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT:
return CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET;
case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT:
return CBSTATUS_STENCIL_TEST_ENABLE_SET;
case VK_DYNAMIC_STATE_STENCIL_OP_EXT:
return CBSTATUS_STENCIL_OP_SET;
default:
return CBSTATUS_NONE;
}
return CBSTATUS_NONE;
}
void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
if (add_obj) {
instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
// Call base class
ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
}
}
uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
// Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
uint32_t mip_level_count = range->levelCount;
if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
mip_level_count = mip_levels - range->baseMipLevel;
}
return mip_level_count;
}
uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
// Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
uint32_t array_layer_count = range->layerCount;
if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
array_layer_count = layers - range->baseArrayLayer;
}
return array_layer_count;
}
VkImageSubresourceRange NormalizeSubresourceRange(const VkImageCreateInfo &image_create_info,
const VkImageSubresourceRange &range) {
VkImageSubresourceRange norm = range;
norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels);
// Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT flag bit, where <extent.depth> and
// <arrayLayers> can potentially alias.
uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT))
? image_create_info.extent.depth
: image_create_info.arrayLayers;
norm.layerCount = ResolveRemainingLayers(&range, layer_limit);
// For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes
VkImageAspectFlags &aspect_mask = norm.aspectMask;
if (FormatIsMultiplane(image_create_info.format)) {
if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) {
aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT;
aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT);
if (FormatPlaneCount(image_create_info.format) > 2) {
aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT;
}
}
}
return norm;
}
VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) {
const VkImageCreateInfo &image_create_info = image_state.createInfo;
return NormalizeSubresourceRange(image_create_info, range);
}
// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
// attachments won't persist past the API entry point exit.
std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
const FRAMEBUFFER_STATE &fb_state) {
const VkImageView *attachments = fb_state.createInfo.pAttachments;
uint32_t count = fb_state.createInfo.attachmentCount;
if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
if (framebuffer_attachments) {
attachments = framebuffer_attachments->pAttachments;
count = framebuffer_attachments->attachmentCount;
}
}
return std::make_pair(count, attachments);
}
template <typename ImageViewPointer, typename Get>
std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
const Get &get_fn) {
std::vector<ImageViewPointer> views;
const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
const auto attachment_count = count_attachment.first;
const auto *attachments = count_attachment.second;
views.resize(attachment_count, nullptr);
for (uint32_t i = 0; i < attachment_count; i++) {
if (attachments[i] != VK_NULL_HANDLE) {
views[i] = get_fn(attachments[i]);
}
}
return views;
}
std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetAttachmentViews(const VkRenderPassBeginInfo &rp_begin,
const FRAMEBUFFER_STATE &fb_state) const {
auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
return GetAttachmentViewsImpl<const IMAGE_VIEW_STATE *>(rp_begin, fb_state, get_fn);
}
std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetSharedAttachmentViews(
const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
auto get_fn = [this](VkImageView handle) { return this->GetShared<IMAGE_VIEW_STATE>(handle); };
return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
}
std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetCurrentAttachmentViews(const CMD_BUFFER_STATE &cb_state) const {
// Only valid *after* RecordBeginRenderPass and *before* RecordEndRenderpass as it relies on cb_state for the renderpass info.
std::vector<const IMAGE_VIEW_STATE *> views;
const auto *rp_state = cb_state.activeRenderPass.get();
if (!rp_state) return views;
const auto &rp_begin = *cb_state.activeRenderPassBeginInfo.ptr();
const auto *fb_state = Get<FRAMEBUFFER_STATE>(rp_begin.framebuffer);
if (!fb_state) return views;
return GetAttachmentViews(rp_begin, *fb_state);
}
PIPELINE_STATE *GetCurrentPipelineFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint) {
const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
return cmd.lastBound[lv_bind_point].pipeline_state;
}
void GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint,
const PIPELINE_STATE **rtn_pipe,
const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) {
const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
const auto &last_bound_it = cmd.lastBound[lv_bind_point];
if (!last_bound_it.IsUsing()) {
return;
}
*rtn_pipe = last_bound_it.pipeline_state;
*rtn_sets = &(last_bound_it.per_set);
}
#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 = LvlFindInChain<VkExternalMemoryImageCreateInfo>(create_info->pNext);
if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
is_node->external_ahb = true;
}
const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<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;
// VUID 01894 will catch if not found in map
auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
if (it != ahb_ext_formats_map.end()) {
is_node->format_features = it->second;
}
}
}
void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {
const VkExternalMemoryBufferCreateInfo *embci = LvlFindInChain<VkExternalMemoryBufferCreateInfo>(create_info->pNext);
if (embci && (embci->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
bs_node->external_ahb = true;
}
}
void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
VkSamplerYcbcrConversion ycbcr_conversion,
SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state) {
const VkExternalFormatANDROID *ext_format_android = LvlFindInChain<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);
// VUID 01894 will catch if not found in map
auto it = ahb_ext_formats_map.find(ext_format_android->externalFormat);
if (it != ahb_ext_formats_map.end()) {
ycbcr_state->format_features = it->second;
}
}
};
void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) {
ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion);
};
void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
if (VK_SUCCESS != result) return;
auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
if (ahb_format_props) {
ahb_ext_formats_map.insert({ahb_format_props->externalFormat, ahb_format_props->formatFeatures});
}
}
#else
void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {}
void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {}
void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
VkSamplerYcbcrConversion ycbcr_conversion,
SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state){};
void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){};
#endif // VK_USE_PLATFORM_ANDROID_KHR
std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDslFromPipelineLayout(PIPELINE_LAYOUT_STATE const *layout_data,
uint32_t set) {
std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr;
if (layout_data && (set < layout_data->set_layouts.size())) {
dsl = layout_data->set_layouts[set];
}
return dsl;
}
void AddImageStateProps(IMAGE_STATE &image_state, const VkDevice device, const VkPhysicalDevice physical_device) {
// Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
// if format is AHB external format then the features are already set
if (image_state.has_ahb_format == false) {
const VkImageTiling image_tiling = image_state.createInfo.tiling;
const VkFormat image_format = image_state.createInfo.format;
if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {
VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, nullptr};
DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state.image, &drm_format_properties);
VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
nullptr};
format_properties_2.pNext = (void *)&drm_properties_list;
DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2);
std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
drm_properties.resize(drm_properties_list.drmFormatModifierCount);
drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2);
for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier ==
drm_format_properties.drmFormatModifier) {
image_state.format_features =
drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
break;
}
}
} else {
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, image_format, &format_properties);
image_state.format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures
: format_properties.optimalTilingFeatures;
}
}
}
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>(device, *pImage, pCreateInfo);
is_node->disjoint = ((pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0);
if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
RecordCreateImageANDROID(pCreateInfo, is_node.get());
}
const auto swapchain_info = LvlFindInChain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext);
if (swapchain_info) {
is_node->create_from_swapchain = swapchain_info->swapchain;
}
// Record the memory requirements in case they won't be queried
// External AHB memory can't be queried until after memory is bound
if (is_node->external_ahb == false) {
if (is_node->disjoint == false) {
DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements);
} else {
uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr};
VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr};
VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2};
mem_req_info2.pNext = &image_plane_req;
mem_req_info2.image = *pImage;
assert(plane_count != 0); // assumes each format has at least first plane
image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT;
DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
is_node->plane0_requirements = mem_reqs2.memoryRequirements;
if (plane_count >= 2) {
image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_1_BIT;
DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
is_node->plane1_requirements = mem_reqs2.memoryRequirements;
}
if (plane_count >= 3) {
image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT;
DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
is_node->plane2_requirements = mem_reqs2.memoryRequirements;
}
}
}
AddImageStateProps(*is_node, device, physical_device);
is_node->unprotected = ((pCreateInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0);
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()) {
RemoveImageMemoryRange(image, mem_binding);
}
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::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
const VkCopyImageInfo2KHR *pCopyImageInfo) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(pCopyImageInfo->srcImage);
auto dst_image_state = GetImageState(pCopyImageInfo->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::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
const VkResolveImageInfo2KHR *pResolveImageInfo) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(pResolveImageInfo->srcImage);
auto dst_image_state = GetImageState(pResolveImageInfo->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::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
const VkBlitImageInfo2KHR *pBlitImageInfo) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(pBlitImageInfo->srcImage);
auto dst_image_state = GetImageState(pBlitImageInfo->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);
if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
RecordCreateBufferANDROID(pCreateInfo, buffer_state.get());
}
// Get a set of requirements in the case the app does not
DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements);
buffer_state->unprotected = ((pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) == 0);
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);
auto buffer_view_state = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo);
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
buffer_view_state->format_features = format_properties.bufferFeatures;
bufferViewMap.insert(std::make_pair(*pView, std::move(buffer_view_state)));
}
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);
auto image_view_state = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo);
// Add feature support according to Image View Format Features (vkspec.html#resources-image-view-format-features)
const VkImageTiling image_tiling = image_state->createInfo.tiling;
const VkFormat image_view_format = pCreateInfo->format;
if (image_state->has_ahb_format == true) {
// The ImageView uses same Image's format feature since they share same AHB
image_view_state->format_features = image_state->format_features;
} else if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
// Parameter validation should catch if this is used without VK_EXT_image_drm_format_modifier
assert(device_extensions.vk_ext_image_drm_format_modifier);
VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
nullptr};
DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state->image, &drm_format_properties);
VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
nullptr};
format_properties_2.pNext = (void *)&drm_properties_list;
DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2);
for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
image_view_state->format_features |=
drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
break;
}
}
} else {
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, image_view_format, &format_properties);
image_view_state->format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures
: format_properties.optimalTilingFeatures;
}
auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
image_view_state->inherited_usage = (usage_create_info) ? usage_create_info->usage : image_state->createInfo.usage;
// filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
image_view_state->filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
imageview_format_info.imageViewType = pCreateInfo->viewType;
auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
image_format_info.type = image_state->createInfo.imageType;
image_format_info.format = image_state->createInfo.format;
image_format_info.tiling = image_state->createInfo.tiling;
image_format_info.usage = image_view_state->inherited_usage;
image_format_info.flags = image_state->createInfo.flags;
auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&image_view_state->filter_cubic_props);
DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
}
imageViewMap.insert(std::make_pair(*pView, std::move(image_view_state)));
}
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::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
const VkCopyBufferInfo2KHR *pCopyBufferInfos) {
auto cb_node = GetCBState(commandBuffer);
auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer);
auto dst_buffer_state = GetBufferState(pCopyBufferInfos->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()) {
RemoveBufferMemoryRange(buffer, mem_binding);
}
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::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
auto cb_node = GetCBState(commandBuffer);
auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage);
auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->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);
}
void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
auto cb_node = GetCBState(commandBuffer);
auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer);
auto dst_image_state = GetImageState(pCopyBufferToImageInfo->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::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index,
const CMD_BUFFER_STATE *primary_cb) {
if (primary_cb) {
assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size()));
return primary_cb->active_attachments->at(index);
}
assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size()));
return cb->active_attachments->at(index);
}
// Get the image viewstate for a given framebuffer attachment
const IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index,
const CMD_BUFFER_STATE *primary_cb) const {
if (primary_cb) {
assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size()));
return primary_cb->active_attachments->at(index);
}
assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size()));
return cb->active_attachments->at(index);
}
void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state) {
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 {
if (image_state->binding.mem_state) {
bound_images = &image_state->binding.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 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->GetAccelerationStructureStateNV(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);
auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
memObjMap[mem] = std::make_shared<DEVICE_MEMORY_STATE>(object, mem, pAllocateInfo, fake_address);
auto mem_info = memObjMap[mem].get();
auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
if (dedicated) {
mem_info->is_dedicated = true;
mem_info->dedicated_buffer = dedicated->buffer;
mem_info->dedicated_image = dedicated->image;
}
auto export_info = LvlFindInChain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext);
if (export_info) {
mem_info->is_export = true;
mem_info->export_handle_type_flags = export_info->handleTypes;
}
auto alloc_flags = LvlFindInChain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext);
if (alloc_flags) {
auto dev_mask = alloc_flags->deviceMask;
if ((dev_mask != 0) && (dev_mask & (dev_mask - 1))) {
mem_info->multi_instance = true;
}
}
auto heap_index = phys_dev_mem_props.memoryTypes[mem_info->alloc_info.memoryTypeIndex].heapIndex;
mem_info->multi_instance |= (((phys_dev_mem_props.memoryHeaps[heap_index].flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) != 0) &&
physical_device_count > 1);
// Assumes validation already for only a single import operation in the pNext
#ifdef VK_USE_PLATFORM_WIN32_KHR
auto win32_import = LvlFindInChain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext);
if (win32_import) {
mem_info->is_import = true;
mem_info->import_handle_type_flags = win32_import->handleType;
}
#endif
auto fd_import = LvlFindInChain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext);
if (fd_import) {
mem_info->is_import = true;
mem_info->import_handle_type_flags = fd_import->handleType;
}
auto host_pointer_import = LvlFindInChain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext);
if (host_pointer_import) {
mem_info->is_import = true;
mem_info->import_handle_type_flags = host_pointer_import->handleType;
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// AHB Import doesn't have handle in the pNext struct
// It should be assumed that all imported AHB can only have the same, single handleType
auto ahb_import = LvlFindInChain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext);
if ((ahb_import) && (ahb_import->buffer != nullptr)) {
mem_info->is_import_ahb = true;
mem_info->is_import = true;
mem_info->import_handle_type_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
const VkMemoryType memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
mem_info->unprotected = ((memory_type.propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT) == 0);
}
// 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;