forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescriptor_sets.cpp
3862 lines (3647 loc) · 224 KB
/
descriptor_sets.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.
*
* 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: Tobin Ehlis <[email protected]>
* John Zulauf <[email protected]>
* Jeremy Kniager <[email protected]>
*/
#include "chassis.h"
#include "core_validation_error_enums.h"
#include "core_validation.h"
#include "descriptor_sets.h"
#include "hash_vk_types.h"
#include "vk_enum_string_helper.h"
#include "vk_safe_struct.h"
#include "vk_typemap_helper.h"
#include "buffer_validation.h"
#include <sstream>
#include <algorithm>
#include <array>
#include <memory>
static DESCRIPTOR_POOL_STATE::TypeCountMap GetMaxTypeCounts(const VkDescriptorPoolCreateInfo *create_info) {
DESCRIPTOR_POOL_STATE::TypeCountMap counts;
// Collect maximums per descriptor type.
for (uint32_t i = 0; i < create_info->poolSizeCount; ++i) {
const auto &pool_size = create_info->pPoolSizes[i];
uint32_t type = static_cast<uint32_t>(pool_size.type);
// Same descriptor types can appear several times
counts[type] += pool_size.descriptorCount;
}
return counts;
}
DESCRIPTOR_POOL_STATE::DESCRIPTOR_POOL_STATE(ValidationStateTracker *dev, const VkDescriptorPool pool,
const VkDescriptorPoolCreateInfo *pCreateInfo)
: BASE_NODE(pool, kVulkanObjectTypeDescriptorPool),
dev_data(dev),
maxSets(pCreateInfo->maxSets),
availableSets(pCreateInfo->maxSets),
createInfo(pCreateInfo),
maxDescriptorTypeCount(GetMaxTypeCounts(pCreateInfo)),
availableDescriptorTypeCount(maxDescriptorTypeCount) {}
void DESCRIPTOR_POOL_STATE::Allocate(const VkDescriptorSetAllocateInfo *alloc_info, const VkDescriptorSet *descriptor_sets,
const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
// Account for sets and individual descriptors allocated from pool
availableSets -= alloc_info->descriptorSetCount;
for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
}
const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(alloc_info->pNext);
bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == alloc_info->descriptorSetCount;
// Create tracking object for each descriptor set; insert into global map and the pool's set.
for (uint32_t i = 0; i < alloc_info->descriptorSetCount; i++) {
uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], this, ds_data->layout_nodes[i],
variable_count, dev_data);
sets.emplace(descriptor_sets[i], new_ds.get());
dev_data->Add(std::move(new_ds));
}
}
void DESCRIPTOR_POOL_STATE::Free(uint32_t count, const VkDescriptorSet *descriptor_sets) {
// Update available descriptor sets in pool
availableSets += count;
// For each freed descriptor add its resources back into the pool as available and remove from pool and device data
for (uint32_t i = 0; i < count; ++i) {
if (descriptor_sets[i] != VK_NULL_HANDLE) {
auto iter = sets.find(descriptor_sets[i]);
assert(iter != sets.end());
auto *set_state = iter->second;
uint32_t type_index = 0, descriptor_count = 0;
for (uint32_t j = 0; j < set_state->GetBindingCount(); ++j) {
type_index = static_cast<uint32_t>(set_state->GetTypeFromIndex(j));
descriptor_count = set_state->GetDescriptorCountFromIndex(j);
availableDescriptorTypeCount[type_index] += descriptor_count;
}
dev_data->Destroy<cvdescriptorset::DescriptorSet>(iter->first);
sets.erase(iter);
}
}
}
void DESCRIPTOR_POOL_STATE::Reset() {
// For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet
for (auto entry : sets) {
dev_data->Destroy<cvdescriptorset::DescriptorSet>(entry.first);
}
sets.clear();
// Reset available count for each type and available sets for this pool
availableDescriptorTypeCount = maxDescriptorTypeCount;
availableSets = maxSets;
}
void DESCRIPTOR_POOL_STATE::Destroy() {
Reset();
BASE_NODE::Destroy();
}
// ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended
// state that comes from a different array/structure so they can stay together
// while being sorted by binding number.
struct ExtendedBinding {
ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlags f) : layout_binding(l), binding_flags(f) {}
const VkDescriptorSetLayoutBinding *layout_binding;
VkDescriptorBindingFlags binding_flags;
};
struct BindingNumCmp {
bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const {
return a.layout_binding->binding < b.layout_binding->binding;
}
};
using DescriptorSet = cvdescriptorset::DescriptorSet;
using DescriptorSetLayout = cvdescriptorset::DescriptorSetLayout;
using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef;
using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId;
// Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information)
cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict;
DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) {
return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info));
}
// Construct DescriptorSetLayout instance from given create info
// Proactively reserve and resize as possible, as the reallocation was visible in profiling
cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info)
: flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) {
const auto *flags_create_info = LvlFindInChain<VkDescriptorSetLayoutBindingFlagsCreateInfo>(p_create_info->pNext);
binding_type_stats_ = {0, 0};
std::set<ExtendedBinding, BindingNumCmp> sorted_bindings;
const uint32_t input_bindings_count = p_create_info->bindingCount;
// Sort the input bindings in binding number order, eliminating duplicates
for (uint32_t i = 0; i < input_bindings_count; i++) {
VkDescriptorBindingFlags flags = 0;
if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) {
flags = flags_create_info->pBindingFlags[i];
}
sorted_bindings.emplace(p_create_info->pBindings + i, flags);
}
const auto *mutable_descriptor_type_create_info = LvlFindInChain<VkMutableDescriptorTypeCreateInfoVALVE>(p_create_info->pNext);
if (mutable_descriptor_type_create_info) {
mutable_types_.resize(mutable_descriptor_type_create_info->mutableDescriptorTypeListCount);
for (uint32_t i = 0; i < mutable_descriptor_type_create_info->mutableDescriptorTypeListCount; ++i) {
const auto &list = mutable_descriptor_type_create_info->pMutableDescriptorTypeLists[i];
mutable_types_[i].reserve(list.descriptorTypeCount);
for (uint32_t j = 0; j < list.descriptorTypeCount; ++j) {
mutable_types_[i].push_back(list.pDescriptorTypes[j]);
}
std::sort(mutable_types_[i].begin(), mutable_types_[i].end());
}
}
// Store the create info in the sorted order from above
uint32_t index = 0;
binding_count_ = static_cast<uint32_t>(sorted_bindings.size());
bindings_.reserve(binding_count_);
binding_flags_.reserve(binding_count_);
binding_to_index_map_.reserve(binding_count_);
for (const auto &input_binding : sorted_bindings) {
// Add to binding and map, s.t. it is robust to invalid duplication of binding_num
const auto binding_num = input_binding.layout_binding->binding;
binding_to_index_map_[binding_num] = index++;
bindings_.emplace_back(input_binding.layout_binding);
auto &binding_info = bindings_.back();
binding_flags_.emplace_back(input_binding.binding_flags);
descriptor_count_ += binding_info.descriptorCount;
if (binding_info.descriptorCount > 0) {
non_empty_bindings_.insert(binding_num);
}
if (IsDynamicDescriptor(binding_info.descriptorType)) {
dynamic_descriptor_count_ += binding_info.descriptorCount;
}
// Get stats depending on descriptor type for caching later
if (IsBufferDescriptor(binding_info.descriptorType)) {
if (IsDynamicDescriptor(binding_info.descriptorType)) {
binding_type_stats_.dynamic_buffer_count++;
} else {
binding_type_stats_.non_dynamic_buffer_count++;
}
}
}
assert(bindings_.size() == binding_count_);
assert(binding_flags_.size() == binding_count_);
uint32_t global_index = 0;
global_index_range_.reserve(binding_count_);
// Vector order is finalized so build vectors of descriptors and dynamic offsets by binding index
for (uint32_t i = 0; i < binding_count_; ++i) {
auto final_index = global_index + bindings_[i].descriptorCount;
global_index_range_.emplace_back(global_index, final_index);
global_index = final_index;
}
}
size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const {
hash_util::HashCombiner hc;
hc << flags_;
hc.Combine(bindings_);
hc.Combine(binding_flags_);
return hc.Value();
}
//
// Return valid index or "end" i.e. binding_count_;
// The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given
// Common code for all binding lookups.
uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const {
const auto &bi_itr = binding_to_index_map_.find(binding);
if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second;
return GetBindingCount();
}
VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex(
const uint32_t index) const {
if (index >= bindings_.size()) return nullptr;
return bindings_[index].ptr();
}
// Return descriptorCount for given index, 0 if index is unavailable
uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const {
if (index >= bindings_.size()) return 0;
return bindings_[index].descriptorCount;
}
// For the given index, return descriptorType
VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const {
assert(index < bindings_.size());
if (index < bindings_.size()) return bindings_[index].descriptorType;
return VK_DESCRIPTOR_TYPE_MAX_ENUM;
}
// For the given index, return stageFlags
VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const {
assert(index < bindings_.size());
if (index < bindings_.size()) return bindings_[index].stageFlags;
return VkShaderStageFlags(0);
}
// Return binding flags for given index, 0 if index is unavailable
VkDescriptorBindingFlags cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex(const uint32_t index) const {
if (index >= binding_flags_.size()) return 0;
return binding_flags_[index];
}
const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromIndex(uint32_t index) const {
const static IndexRange k_invalid_range = {0xFFFFFFFF, 0xFFFFFFFF};
if (index >= binding_flags_.size()) return k_invalid_range;
return global_index_range_[index];
}
// For the given binding, return the global index range (half open)
// As start and end are often needed in pairs, get both with a single lookup.
const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding(
const uint32_t binding) const {
uint32_t index = GetIndexFromBinding(binding);
return GetGlobalIndexRangeFromIndex(index);
}
// For given binding, return ptr to ImmutableSampler array
VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
const auto &bi_itr = binding_to_index_map_.find(binding);
if (bi_itr != binding_to_index_map_.end()) {
return bindings_[bi_itr->second].pImmutableSamplers;
}
return nullptr;
}
// Move to next valid binding having a non-zero binding count
uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const {
auto it = non_empty_bindings_.upper_bound(binding);
assert(it != non_empty_bindings_.cend());
if (it != non_empty_bindings_.cend()) return *it;
return GetMaxBinding() + 1;
}
// For given index, return ptr to ImmutableSampler array
VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
if (index < bindings_.size()) {
return bindings_[index].pImmutableSamplers;
}
return nullptr;
}
bool cvdescriptorset::DescriptorSetLayoutDef::IsTypeMutable(const VkDescriptorType type, uint32_t binding) const {
if (binding < mutable_types_.size()) {
if (mutable_types_[binding].size() > 0) {
for (const auto mutable_type : mutable_types_[binding]) {
if (type == mutable_type) {
return true;
}
}
return false;
}
}
// If mutableDescriptorTypeListCount is zero or if VkMutableDescriptorTypeCreateInfoVALVE structure is not included in the pNext
// chain, the VkMutableDescriptorTypeListVALVE for each element is considered to be zero or NULL for each member.
return false;
}
const std::vector<std::vector<VkDescriptorType>>& cvdescriptorset::DescriptorSetLayoutDef::GetMutableTypes() const {
return mutable_types_;
}
const std::vector<VkDescriptorType> &cvdescriptorset::DescriptorSetLayoutDef::GetMutableTypes(uint32_t binding) const {
if (binding >= mutable_types_.size()) {
static const std::vector<VkDescriptorType> empty = {};
return empty;
}
return mutable_types_[binding];
}
// If our layout is compatible with rh_ds_layout, return true.
bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *rh_ds_layout) const {
bool compatible = (this == rh_ds_layout) || (GetLayoutDef() == rh_ds_layout->GetLayoutDef());
return compatible;
}
// TODO: Find a way to add smarts to the autogenerated version of this
static std::string smart_string_VkShaderStageFlags(VkShaderStageFlags stage_flags) {
if (stage_flags == VK_SHADER_STAGE_ALL) {
return string_VkShaderStageFlagBits(VK_SHADER_STAGE_ALL);
}
return string_VkShaderStageFlags(stage_flags);
}
// If our layout is compatible with bound_dsl, return true,
// else return false and fill in error_msg will description of what causes incompatibility
bool cvdescriptorset::VerifySetLayoutCompatibility(const debug_report_data *report_data, DescriptorSetLayout const *layout_dsl,
DescriptorSetLayout const *bound_dsl, std::string *error_msg) {
// Short circuit the detailed check.
if (layout_dsl->IsCompatible(bound_dsl)) return true;
// Do a detailed compatibility check of this lhs def (referenced by layout_dsl), vs. the rhs (layout and def)
// Should only be run if trivial accept has failed, and in that context should return false.
VkDescriptorSetLayout layout_dsl_handle = layout_dsl->GetDescriptorSetLayout();
VkDescriptorSetLayout bound_dsl_handle = bound_dsl->GetDescriptorSetLayout();
DescriptorSetLayoutDef const *layout_ds_layout_def = layout_dsl->GetLayoutDef();
DescriptorSetLayoutDef const *bound_ds_layout_def = bound_dsl->GetLayoutDef();
// Check descriptor counts
const auto bound_total_count = bound_ds_layout_def->GetTotalDescriptorCount();
if (layout_ds_layout_def->GetTotalDescriptorCount() != bound_ds_layout_def->GetTotalDescriptorCount()) {
std::stringstream error_str;
error_str << report_data->FormatHandle(layout_dsl_handle) << " from pipeline layout has "
<< layout_ds_layout_def->GetTotalDescriptorCount() << " total descriptors, but "
<< report_data->FormatHandle(bound_dsl_handle) << ", which is bound, has " << bound_total_count
<< " total descriptors.";
*error_msg = error_str.str();
return false; // trivial fail case
}
// Descriptor counts match so need to go through bindings one-by-one
// and verify that type and stageFlags match
for (const auto &layout_binding : layout_ds_layout_def->GetBindings()) {
// TODO : Do we also need to check immutable samplers?
const auto bound_binding = bound_ds_layout_def->GetBindingInfoFromBinding(layout_binding.binding);
if (layout_binding.descriptorCount != bound_binding->descriptorCount) {
std::stringstream error_str;
error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle)
<< " from pipeline layout has a descriptorCount of " << layout_binding.descriptorCount << " but binding "
<< layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle)
<< ", which is bound, has a descriptorCount of " << bound_binding->descriptorCount;
*error_msg = error_str.str();
return false;
} else if (layout_binding.descriptorType != bound_binding->descriptorType) {
std::stringstream error_str;
error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle)
<< " from pipeline layout is type '" << string_VkDescriptorType(layout_binding.descriptorType)
<< "' but binding " << layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle)
<< ", which is bound, is type '" << string_VkDescriptorType(bound_binding->descriptorType) << "'";
*error_msg = error_str.str();
return false;
} else if (layout_binding.stageFlags != bound_binding->stageFlags) {
std::stringstream error_str;
error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle)
<< " from pipeline layout has stageFlags " << smart_string_VkShaderStageFlags(layout_binding.stageFlags)
<< " but binding " << layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle)
<< ", which is bound, has stageFlags " << smart_string_VkShaderStageFlags(bound_binding->stageFlags);
*error_msg = error_str.str();
return false;
}
}
const auto &ds_layout_flags = layout_ds_layout_def->GetBindingFlags();
const auto &bound_layout_flags = bound_ds_layout_def->GetBindingFlags();
if (bound_layout_flags != ds_layout_flags) {
std::stringstream error_str;
assert(ds_layout_flags.size() == bound_layout_flags.size());
size_t i;
for (i = 0; i < ds_layout_flags.size(); i++) {
if (ds_layout_flags[i] != bound_layout_flags[i]) break;
}
error_str << report_data->FormatHandle(layout_dsl_handle)
<< " from pipeline layout does not have the same binding flags at binding " << i << " ( "
<< string_VkDescriptorBindingFlagsEXT(ds_layout_flags[i]) << " ) as "
<< report_data->FormatHandle(bound_dsl_handle) << " ( "
<< string_VkDescriptorBindingFlagsEXT(bound_layout_flags[i]) << " ), which is bound";
*error_msg = error_str.str();
return false;
}
// No detailed check should succeed if the trivial check failed -- or the dictionary has failed somehow.
bool compatible = true;
assert(!compatible);
return compatible;
}
bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const {
if (!binding_to_index_map_.count(binding + 1)) return false;
auto const &bi_itr = binding_to_index_map_.find(binding);
if (bi_itr != binding_to_index_map_.end()) {
const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
if (next_bi_itr != binding_to_index_map_.end()) {
auto type = bindings_[bi_itr->second].descriptorType;
auto stage_flags = bindings_[bi_itr->second].stageFlags;
auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
auto flags = binding_flags_[bi_itr->second];
if ((type != bindings_[next_bi_itr->second].descriptorType) ||
(stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
(immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) ||
(flags != binding_flags_[next_bi_itr->second])) {
return false;
}
return true;
}
}
return false;
}
// The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the
// handle invariant portion
cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info,
const VkDescriptorSetLayout layout)
: BASE_NODE(layout, kVulkanObjectTypeDescriptorSetLayout), layout_id_(GetCanonicalId(p_create_info)) {}
// Validate descriptor set layout create info
bool cvdescriptorset::ValidateDescriptorSetLayoutCreateInfo(
const ValidationObject *val_obj, const VkDescriptorSetLayoutCreateInfo *create_info, const bool push_descriptor_ext,
const uint32_t max_push_descriptors, const bool descriptor_indexing_ext,
const VkPhysicalDeviceVulkan12Features *core12_features,
const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features,
const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props,
const VkPhysicalDeviceAccelerationStructureFeaturesKHR *acceleration_structure_features,
const DeviceExtensions *device_extensions) {
bool skip = false;
layer_data::unordered_set<uint32_t> bindings;
uint64_t total_descriptors = 0;
const auto *flags_create_info = LvlFindInChain<VkDescriptorSetLayoutBindingFlagsCreateInfo>(create_info->pNext);
const bool push_descriptor_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
if (push_descriptor_set && !push_descriptor_ext) {
skip |= val_obj->LogError(
val_obj->device, kVUID_Core_DrawState_ExtensionNotEnabled,
"vkCreateDescriptorSetLayout(): Attempted to use %s in %s but its required extension %s has not been enabled.\n",
"VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR", "VkDescriptorSetLayoutCreateInfo::flags",
VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
}
const bool update_after_bind_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT);
if (update_after_bind_set && !descriptor_indexing_ext) {
skip |= val_obj->LogError(
val_obj->device, kVUID_Core_DrawState_ExtensionNotEnabled,
"vkCreateDescriptorSetLayout(): Attemped to use %s in %s but its required extension %s has not been enabled.\n",
"VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT", "VkDescriptorSetLayoutCreateInfo::flags",
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
}
auto valid_type = [push_descriptor_set](const VkDescriptorType type) {
return !push_descriptor_set ||
((type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) && (type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) &&
(type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT));
};
uint32_t max_binding = 0;
uint32_t update_after_bind = create_info->bindingCount;
uint32_t uniform_buffer_dynamic = create_info->bindingCount;
uint32_t storage_buffer_dynamic = create_info->bindingCount;
for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
const auto &binding_info = create_info->pBindings[i];
max_binding = std::max(max_binding, binding_info.binding);
if (!bindings.insert(binding_info.binding).second) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-binding-00279",
"vkCreateDescriptorSetLayout(): pBindings[%u] has duplicated binding number (%u).", i,
binding_info.binding);
}
if (!valid_type(binding_info.descriptorType)) {
skip |= val_obj->LogError(val_obj->device,
(binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
? "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208"
: "VUID-VkDescriptorSetLayoutCreateInfo-flags-00280",
"vkCreateDescriptorSetLayout(): pBindings[%u] has invalid type %s , for push descriptors.", i,
string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
if (!inline_uniform_block_features->inlineUniformBlock) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-04604",
"vkCreateDescriptorSetLayout(): pBindings[%u] is creating VkDescriptorSetLayout with "
"descriptor type VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT "
"but the inlineUniformBlock feature is not enabled",
i);
} else {
if ((binding_info.descriptorCount % 4) != 0) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-02209",
"vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorCount =(%" PRIu32
") but must be a multiple of 4",
i, binding_info.descriptorCount);
}
if (binding_info.descriptorCount > inline_uniform_block_props->maxInlineUniformBlockSize) {
skip |=
val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-02210",
"vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorCount =(%" PRIu32
") but must be less than or equal to maxInlineUniformBlockSize (%u)",
i, binding_info.descriptorCount, inline_uniform_block_props->maxInlineUniformBlockSize);
}
}
} else if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
uniform_buffer_dynamic = i;
} else if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
storage_buffer_dynamic = i;
}
if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) &&
binding_info.pImmutableSamplers && IsExtEnabled(device_extensions->vk_ext_custom_border_color)) {
const CoreChecks *core_checks = reinterpret_cast<const CoreChecks *>(val_obj);
for (uint32_t j = 0; j < binding_info.descriptorCount; j++) {
const auto sampler_state = core_checks->Get<SAMPLER_STATE>(binding_info.pImmutableSamplers[j]);
if (sampler_state && (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT)) {
skip |= val_obj->LogError(
val_obj->device, "VUID-VkDescriptorSetLayoutBinding-pImmutableSamplers-04009",
"vkCreateDescriptorSetLayout(): pBindings[%u].pImmutableSamplers[%u] has VkSampler %s"
" presented as immutable has a custom border color",
i, j, val_obj->report_data->FormatHandle(binding_info.pImmutableSamplers[j]).c_str());
}
}
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE && binding_info.pImmutableSamplers != nullptr) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-04605",
"vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorType "
"VK_DESCRIPTOR_TYPE_MUTABLE_VALVE but pImmutableSamplers is not NULL.",
i);
}
total_descriptors += binding_info.descriptorCount;
}
if (flags_create_info) {
if (flags_create_info->bindingCount != 0 && flags_create_info->bindingCount != create_info->bindingCount) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-bindingCount-03002",
"vkCreateDescriptorSetLayout(): VkDescriptorSetLayoutCreateInfo::bindingCount (%d) != "
"VkDescriptorSetLayoutBindingFlagsCreateInfo::bindingCount (%d)",
create_info->bindingCount, flags_create_info->bindingCount);
}
if (flags_create_info->bindingCount == create_info->bindingCount) {
for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
const auto &binding_info = create_info->pBindings[i];
if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT) {
update_after_bind = i;
if (!update_after_bind_set) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-flags-03000",
"vkCreateDescriptorSetLayout(): pBindings[%u] does not have "
"VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT.",
i);
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER &&
!core12_features->descriptorBindingUniformBufferUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingUniformBufferUpdateAfterBind-03005",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingUniformBufferUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) &&
!core12_features->descriptorBindingSampledImageUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingSampledImageUpdateAfterBind-03006",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingSampledImageUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
!core12_features->descriptorBindingStorageImageUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingStorageImageUpdateAfterBind-03007",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingStorageImageUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER &&
!core12_features->descriptorBindingStorageBufferUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingStorageBufferUpdateAfterBind-03008",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingStorageBufferUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER &&
!core12_features->descriptorBindingUniformTexelBufferUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingUniformTexelBufferUpdateAfterBind-03009",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingUniformTexelBufferUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER &&
!core12_features->descriptorBindingStorageTexelBufferUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingStorageTexelBufferUpdateAfterBind-03010",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingStorageTexelBufferUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-None-03011",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have "
"VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT for %s.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT &&
!inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingInlineUniformBlockUpdateAfterBind-02211",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s since descriptorBindingInlineUniformBlockUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR ||
binding_info.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV) &&
!acceleration_structure_features->descriptorBindingAccelerationStructureUpdateAfterBind) {
skip |= val_obj->LogError(val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-"
"descriptorBindingAccelerationStructureUpdateAfterBind-03570",
"vkCreateDescriptorSetLayout(): pBindings[%" PRIu32
"] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"for %s if "
"VkPhysicalDeviceAccelerationStructureFeaturesKHR::"
"descriptorBindingAccelerationStructureUpdateAfterBind is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
}
if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT) {
if (!core12_features->descriptorBindingUpdateUnusedWhilePending) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingUpdateUnusedWhilePending-03012",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have "
"VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT for %s since "
"descriptorBindingUpdateUnusedWhilePending is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
}
if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT) {
if (!core12_features->descriptorBindingPartiallyBound) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingPartiallyBound-03013",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT for "
"%s since descriptorBindingPartiallyBound is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
}
if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT) {
if (binding_info.binding != max_binding) {
skip |= val_obj->LogError(
val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03004",
"vkCreateDescriptorSetLayout(): pBindings[%u] has VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT "
"but %u is the largest value of all the bindings.",
i, binding_info.binding);
}
if (!core12_features->descriptorBindingVariableDescriptorCount) {
skip |= val_obj->LogError(
val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingVariableDescriptorCount-03014",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have "
"VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for %s since "
"descriptorBindingVariableDescriptorCount is not enabled.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
(binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
skip |= val_obj->LogError(val_obj->device,
"VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03015",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have "
"VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for %s.",
i, string_VkDescriptorType(binding_info.descriptorType));
}
}
if (push_descriptor_set &&
(flags_create_info->pBindingFlags[i] &
(VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT |
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT))) {
skip |= val_obj->LogError(
val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-flags-03003",
"vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT, "
"VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT, or "
"VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for with "
"VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR.",
i);
}
}
}
}
if (update_after_bind < create_info->bindingCount) {
if (uniform_buffer_dynamic < create_info->bindingCount) {
skip |=
val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-descriptorType-03001",
"vkCreateDescriptorSetLayout(): binding (%" PRIi32
") has VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"flag, but binding (%" PRIi32 ") has descriptor type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC.",
update_after_bind, uniform_buffer_dynamic);
}
if (storage_buffer_dynamic < create_info->bindingCount) {
skip |=
val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-descriptorType-03001",
"vkCreateDescriptorSetLayout(): binding (%" PRIi32
") has VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT "
"flag, but binding (%" PRIi32 ") has descriptor type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC.",
update_after_bind, storage_buffer_dynamic);
}
}
if ((push_descriptor_set) && (total_descriptors > max_push_descriptors)) {
const char *undefined = push_descriptor_ext ? "" : " -- undefined";
skip |= val_obj->LogError(
val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-flags-00281",
"vkCreateDescriptorSetLayout(): for push descriptor, total descriptor count in layout (%" PRIu64
") must not be greater than VkPhysicalDevicePushDescriptorPropertiesKHR::maxPushDescriptors (%" PRIu32 "%s).",
total_descriptors, max_push_descriptors, undefined);
}
return skip;
}
void cvdescriptorset::AllocateDescriptorSetsData::Init(uint32_t count) {
layout_nodes.resize(count);
}
cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, DESCRIPTOR_POOL_STATE *pool_state,
const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count,
const cvdescriptorset::DescriptorSet::StateTracker *state_data)
: BASE_NODE(set, kVulkanObjectTypeDescriptorSet),
some_update_(false),
pool_state_(pool_state),
layout_(layout),
state_data_(state_data),
variable_count_(variable_count),
change_count_(0) {
if (pool_state_) {
pool_state_->AddParent(this);
}
// Foreach binding, create default descriptors of given type
descriptors_.reserve(layout_->GetTotalDescriptorCount());
descriptor_store_.resize(layout_->GetTotalDescriptorCount());
auto free_descriptor = descriptor_store_.data();
for (uint32_t i = 0; i < layout_->GetBindingCount(); ++i) {
auto type = layout_->GetTypeFromIndex(i);
switch (type) {
case VK_DESCRIPTOR_TYPE_SAMPLER: {
auto immut_sampler = layout_->GetImmutableSamplerPtrFromIndex(i);
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
if (immut_sampler) {
descriptors_.emplace_back(new ((free_descriptor++)->Sampler())
SamplerDescriptor(state_data, immut_sampler + di));
some_update_ = true; // Immutable samplers are updated at creation
} else {
descriptors_.emplace_back(new ((free_descriptor++)->Sampler()) SamplerDescriptor(state_data, nullptr));
}
descriptors_.back()->AddParent(this);
}
break;
}
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
auto immut = layout_->GetImmutableSamplerPtrFromIndex(i);
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
if (immut) {
descriptors_.emplace_back(new ((free_descriptor++)->ImageSampler())
ImageSamplerDescriptor(state_data, immut + di));
some_update_ = true; // Immutable samplers are updated at creation
} else {
descriptors_.emplace_back(new ((free_descriptor++)->ImageSampler())
ImageSamplerDescriptor(state_data, nullptr));
}
descriptors_.back()->AddParent(this);
}
break;
}
// ImageDescriptors
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->Image()) ImageDescriptor(type));
descriptors_.back()->AddParent(this);
}
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->Texel()) TexelDescriptor(type));
descriptors_.back()->AddParent(this);
}
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->Buffer()) BufferDescriptor(type));
descriptors_.back()->AddParent(this);
}
break;
case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->InlineUniform()) InlineUniformDescriptor(type));
descriptors_.back()->AddParent(this);
}
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->AccelerationStructure())
AccelerationStructureDescriptor(type));
descriptors_.back()->AddParent(this);
}
break;
case VK_DESCRIPTOR_TYPE_MUTABLE_VALVE:
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
descriptors_.emplace_back(new ((free_descriptor++)->Mutable()) MutableDescriptor());
descriptors_.back()->AddParent(this);
}
break;
default:
if (IsDynamicDescriptor(type) && IsBufferDescriptor(type)) {
for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) {
dynamic_offset_idx_to_descriptor_list_.push_back(descriptors_.size());
descriptors_.emplace_back(new ((free_descriptor++)->Buffer()) BufferDescriptor(type));
descriptors_.back()->AddParent(this);
}
} else {
assert(0); // Bad descriptor type specified
}
break;
}
}
}
void cvdescriptorset::DescriptorSet::Destroy() {
if (pool_state_) {
pool_state_->RemoveParent(this);
}
for (auto &desc: descriptors_) {
desc->RemoveParent(this);
}
BASE_NODE::Destroy();
}
static std::string StringDescriptorReqViewType(DescriptorReqFlags req) {
std::string result("");
for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; i++) {
if (req & (1 << i)) {
if (result.size()) result += ", ";
result += string_VkImageViewType(VkImageViewType(i));
}
}
if (!result.size()) result = "(none)";
return result;
}
static char const *StringDescriptorReqComponentType(DescriptorReqFlags req) {
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT";
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT";
if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT";
return "(none)";
}
unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) {
if (FormatIsSINT(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
if (FormatIsUINT(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
// Formats such as VK_FORMAT_D16_UNORM_S8_UINT are both
if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
if (fmt == VK_FORMAT_UNDEFINED) return 0;
// everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
}
// Validate that the state of this set is appropriate for the given bindings and dynamic_offsets at Draw time
// This includes validating that all descriptors in the given bindings are updated,
// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
// Return true if state is acceptable, or false and write an error message into error string
bool CoreChecks::ValidateDrawState(const DescriptorSet *descriptor_set, const BindingReqMap &bindings,
const std::vector<uint32_t> &dynamic_offsets, const CMD_BUFFER_STATE *cb_node,
const std::vector<IMAGE_VIEW_STATE *> *attachments, const std::vector<SUBPASS_INFO> *subpasses,
const char *caller, const DrawDispatchVuid &vuids) const {
layer_data::optional<layer_data::unordered_map<VkImageView, VkImageLayout>> checked_layouts;
if (descriptor_set->GetTotalDescriptorCount() > cvdescriptorset::PrefilterBindRequestMap::kManyDescriptors_) {
checked_layouts.emplace();
}
bool result = false;
VkFramebuffer framebuffer = cb_node->activeFramebuffer ? cb_node->activeFramebuffer->framebuffer() : VK_NULL_HANDLE;
for (const auto &binding_pair : bindings) {
const auto binding = binding_pair.first;
DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), binding);
if (binding_it.AtEnd()) { // End at construction is the condition for an invalid binding.
auto set = descriptor_set->GetSet();
result |= LogError(set, vuids.descriptor_valid,
"%s encountered the following validation error at %s time: Attempting to "
"validate DrawState for binding #%u which is an invalid binding for this descriptor set.",
report_data->FormatHandle(set).c_str(), caller, binding);
return result;
}
if (binding_it.GetDescriptorBindingFlags() &
(VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT)) {
// Can't validate the descriptor because it may not have been updated,
// or the view could have been destroyed
continue;
}
// // This is a record time only path
const bool record_time_validate = true;
result |= ValidateDescriptorSetBindingData(cb_node, descriptor_set, dynamic_offsets, binding_pair, framebuffer, attachments,
subpasses, record_time_validate, caller, vuids, checked_layouts);
}
return result;
}
bool CoreChecks::ValidateDescriptorSetBindingData(const CMD_BUFFER_STATE *cb_node, const DescriptorSet *descriptor_set,
const std::vector<uint32_t> &dynamic_offsets,
const std::pair<const uint32_t, DescriptorRequirement> &binding_info,
VkFramebuffer framebuffer, const std::vector<IMAGE_VIEW_STATE *> *attachments,
const std::vector<SUBPASS_INFO> *subpasses, bool record_time_validate,
const char *caller, const DrawDispatchVuid &vuids,
layer_data::optional<layer_data::unordered_map<VkImageView, VkImageLayout>> &checked_layouts) const {
using DescriptorClass = cvdescriptorset::DescriptorClass;
using BufferDescriptor = cvdescriptorset::BufferDescriptor;
using ImageDescriptor = cvdescriptorset::ImageDescriptor;
using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor;
using SamplerDescriptor = cvdescriptorset::SamplerDescriptor;
using TexelDescriptor = cvdescriptorset::TexelDescriptor;
using AccelerationStructureDescriptor = cvdescriptorset::AccelerationStructureDescriptor;
const auto binding = binding_info.first;
bool skip = false;
DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), binding);
{
// Copy the range, the end range is subject to update based on variable length descriptor arrays.