forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameter_validation_utils.cpp
8037 lines (7400 loc) · 524 KB
/
parameter_validation_utils.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: Mark Lobodzinski <[email protected]>
* Author: John Zulauf <[email protected]>
*/
#include <cmath>
#include "chassis.h"
#include "stateless_validation.h"
#include "layer_chassis_dispatch.h"
#include "core_validation_error_enums.h"
static const int kMaxParamCheckerStringLength = 256;
template <typename T>
inline bool in_inclusive_range(const T &value, const T &min, const T &max) {
// Using only < for generality and || for early abort
return !((value < min) || (max < value));
}
ReadLockGuard StatelessValidation::ReadLock() { return ReadLockGuard(validation_object_mutex, std::defer_lock); }
WriteLockGuard StatelessValidation::WriteLock() { return WriteLockGuard(validation_object_mutex, std::defer_lock); }
static layer_data::unordered_map<VkCommandBuffer, VkCommandPool> secondary_cb_map{};
static ReadWriteLock secondary_cb_map_mutex;
static ReadLockGuard CBReadLock() { return ReadLockGuard(secondary_cb_map_mutex); }
static WriteLockGuard CBWriteLock() { return WriteLockGuard(secondary_cb_map_mutex); }
bool StatelessValidation::validate_string(const char *apiName, const ParameterName &stringName, const std::string &vuid,
const char *validateString) const {
bool skip = false;
VkStringErrorFlags result = vk_string_validate(kMaxParamCheckerStringLength, validateString);
if (result == VK_STRING_ERROR_NONE) {
return skip;
} else if (result & VK_STRING_ERROR_LENGTH) {
skip = LogError(device, vuid, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
kMaxParamCheckerStringLength);
} else if (result & VK_STRING_ERROR_BAD_DATA) {
skip = LogError(device, vuid, "%s: string %s contains invalid characters or is badly formed", apiName,
stringName.get_name().c_str());
}
return skip;
}
bool StatelessValidation::validate_api_version(uint32_t api_version, uint32_t effective_api_version) const {
bool skip = false;
uint32_t api_version_nopatch = VK_MAKE_VERSION(VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), 0);
if (api_version_nopatch != effective_api_version) {
if ((api_version_nopatch < VK_API_VERSION_1_0) && (api_version != 0)) {
skip |= LogError(instance, "VUID-VkApplicationInfo-apiVersion-04010",
"Invalid CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). "
"Using VK_API_VERSION_%" PRIu32 "_%" PRIu32 ".",
api_version, VK_VERSION_MAJOR(effective_api_version), VK_VERSION_MINOR(effective_api_version));
} else {
skip |= LogWarning(instance, kVUIDUndefined,
"Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). "
"Assuming VK_API_VERSION_%" PRIu32 "_%" PRIu32 ".",
api_version, VK_VERSION_MAJOR(effective_api_version), VK_VERSION_MINOR(effective_api_version));
}
}
return skip;
}
bool StatelessValidation::validate_instance_extensions(const VkInstanceCreateInfo *pCreateInfo) const {
bool skip = false;
// Create and use a local instance extension object, as an actual instance has not been created yet
uint32_t specified_version = (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0);
InstanceExtensions local_instance_extensions;
local_instance_extensions.InitFromInstanceCreateInfo(specified_version, pCreateInfo);
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
skip |= validate_extension_reqs(local_instance_extensions, "VUID-vkCreateInstance-ppEnabledExtensionNames-01388",
"instance", pCreateInfo->ppEnabledExtensionNames[i]);
}
return skip;
}
bool StatelessValidation::SupportedByPdev(const VkPhysicalDevice physical_device, const std::string ext_name) const {
if (instance_extensions.vk_khr_get_physical_device_properties2) {
// Struct is legal IF it's supported
const auto &dev_exts_enumerated = device_extensions_enumerated.find(physical_device);
if (dev_exts_enumerated == device_extensions_enumerated.end()) return true;
auto enum_iter = dev_exts_enumerated->second.find(ext_name);
if (enum_iter != dev_exts_enumerated->second.cend()) {
return true;
}
}
return false;
}
bool StatelessValidation::validate_validation_features(const VkInstanceCreateInfo *pCreateInfo,
const VkValidationFeaturesEXT *validation_features) const {
bool skip = false;
bool debug_printf = false;
bool gpu_assisted = false;
bool reserve_slot = false;
for (uint32_t i = 0; i < validation_features->enabledValidationFeatureCount; i++) {
switch (validation_features->pEnabledValidationFeatures[i]) {
case VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT:
gpu_assisted = true;
break;
case VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT:
debug_printf = true;
break;
case VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT:
reserve_slot = true;
break;
default:
break;
}
}
if (reserve_slot && !gpu_assisted) {
skip |= LogError(instance, "VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02967",
"If VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT is in pEnabledValidationFeatures, "
"VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT must also be in pEnabledValidationFeatures.");
}
if (gpu_assisted && debug_printf) {
skip |= LogError(instance, "VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02968",
"If VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT is in pEnabledValidationFeatures, "
"VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT must not also be in pEnabledValidationFeatures.");
}
return skip;
}
template <typename ExtensionState>
ExtEnabled extension_state_by_name(const ExtensionState &extensions, const char *extension_name) {
if (!extension_name) return kNotEnabled; // null strings specify nothing
auto info = ExtensionState::get_info(extension_name);
ExtEnabled state =
info.state ? extensions.*(info.state) : kNotEnabled; // unknown extensions can't be enabled in extension struct
return state;
}
bool StatelessValidation::manual_PreCallValidateCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkInstance *pInstance) const {
bool skip = false;
// Note: From the spec--
// Providing a NULL VkInstanceCreateInfo::pApplicationInfo or providing an apiVersion of 0 is equivalent to providing
// an apiVersion of VK_MAKE_VERSION(1, 0, 0). (a.k.a. VK_API_VERSION_1_0)
uint32_t local_api_version = (pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->apiVersion)
? pCreateInfo->pApplicationInfo->apiVersion
: VK_API_VERSION_1_0;
skip |= validate_api_version(local_api_version, api_version);
skip |= validate_instance_extensions(pCreateInfo);
const auto *validation_features = LvlFindInChain<VkValidationFeaturesEXT>(pCreateInfo->pNext);
if (validation_features) skip |= validate_validation_features(pCreateInfo, validation_features);
return skip;
}
void StatelessValidation::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
VkResult result) {
auto instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
// Copy extension data into local object
if (result != VK_SUCCESS) return;
this->instance_extensions = instance_data->instance_extensions;
}
void StatelessValidation::CommonPostCallRecordEnumeratePhysicalDevice(const VkPhysicalDevice *phys_devices, const int count) {
// Assume phys_devices is valid
assert(phys_devices);
for (int i = 0; i < count; ++i) {
const auto &phys_device = phys_devices[i];
if (0 == physical_device_properties_map.count(phys_device)) {
auto phys_dev_props = new VkPhysicalDeviceProperties;
DispatchGetPhysicalDeviceProperties(phys_device, phys_dev_props);
physical_device_properties_map[phys_device] = phys_dev_props;
// Enumerate the Device Ext Properties to save the PhysicalDevice supported extension state
uint32_t ext_count = 0;
layer_data::unordered_set<std::string> dev_exts_enumerated{};
std::vector<VkExtensionProperties> ext_props{};
instance_dispatch_table.EnumerateDeviceExtensionProperties(phys_device, nullptr, &ext_count, nullptr);
ext_props.resize(ext_count);
instance_dispatch_table.EnumerateDeviceExtensionProperties(phys_device, nullptr, &ext_count, ext_props.data());
for (uint32_t j = 0; j < ext_count; j++) {
dev_exts_enumerated.insert(ext_props[j].extensionName);
}
device_extensions_enumerated[phys_device] = std::move(dev_exts_enumerated);
}
}
}
void StatelessValidation::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
VkPhysicalDevice *pPhysicalDevices, VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) {
return;
}
if (pPhysicalDeviceCount && pPhysicalDevices) {
CommonPostCallRecordEnumeratePhysicalDevice(pPhysicalDevices, *pPhysicalDeviceCount);
}
}
void StatelessValidation::PostCallRecordEnumeratePhysicalDeviceGroups(
VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) {
return;
}
if (pPhysicalDeviceGroupCount && pPhysicalDeviceGroupProperties) {
for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) {
const auto &group = pPhysicalDeviceGroupProperties[i];
CommonPostCallRecordEnumeratePhysicalDevice(group.physicalDevices, group.physicalDeviceCount);
}
}
}
void StatelessValidation::PreCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
for (auto it = physical_device_properties_map.begin(); it != physical_device_properties_map.end();) {
delete (it->second);
it = physical_device_properties_map.erase(it);
}
};
void StatelessValidation::PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) {
auto device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
if (result != VK_SUCCESS) return;
ValidationObject *validation_data = GetValidationObject(device_data->object_dispatch, LayerObjectTypeParameterValidation);
StatelessValidation *stateless_validation = static_cast<StatelessValidation *>(validation_data);
// Parmeter validation also uses extension data
stateless_validation->device_extensions = this->device_extensions;
VkPhysicalDeviceProperties device_properties = {};
// Need to get instance and do a getlayerdata call...
DispatchGetPhysicalDeviceProperties(physicalDevice, &device_properties);
memcpy(&stateless_validation->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
if (IsExtEnabled(device_extensions.vk_nv_shading_rate_image)) {
// Get the needed shading rate image limits
auto shading_rate_image_props = LvlInitStruct<VkPhysicalDeviceShadingRateImagePropertiesNV>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&shading_rate_image_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.shading_rate_image_props = shading_rate_image_props;
}
if (IsExtEnabled(device_extensions.vk_nv_mesh_shader)) {
// Get the needed mesh shader limits
auto mesh_shader_props = LvlInitStruct<VkPhysicalDeviceMeshShaderPropertiesNV>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&mesh_shader_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.mesh_shader_props = mesh_shader_props;
}
if (IsExtEnabled(device_extensions.vk_nv_ray_tracing)) {
// Get the needed ray tracing limits
auto ray_tracing_props = LvlInitStruct<VkPhysicalDeviceRayTracingPropertiesNV>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&ray_tracing_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.ray_tracing_propsNV = ray_tracing_props;
}
if (IsExtEnabled(device_extensions.vk_khr_ray_tracing_pipeline)) {
// Get the needed ray tracing limits
auto ray_tracing_props = LvlInitStruct<VkPhysicalDeviceRayTracingPipelinePropertiesKHR>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&ray_tracing_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.ray_tracing_propsKHR = ray_tracing_props;
}
if (IsExtEnabled(device_extensions.vk_khr_acceleration_structure)) {
// Get the needed ray tracing acc structure limits
auto acc_structure_props = LvlInitStruct<VkPhysicalDeviceAccelerationStructurePropertiesKHR>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&acc_structure_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.acc_structure_props = acc_structure_props;
}
if (IsExtEnabled(device_extensions.vk_ext_transform_feedback)) {
// Get the needed transform feedback limits
auto transform_feedback_props = LvlInitStruct<VkPhysicalDeviceTransformFeedbackPropertiesEXT>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&transform_feedback_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.transform_feedback_props = transform_feedback_props;
}
if (IsExtEnabled(device_extensions.vk_ext_vertex_attribute_divisor)) {
// Get the needed vertex attribute divisor limits
auto vertex_attribute_divisor_props = LvlInitStruct<VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&vertex_attribute_divisor_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.vertex_attribute_divisor_props = vertex_attribute_divisor_props;
}
if (IsExtEnabled(device_extensions.vk_ext_blend_operation_advanced)) {
// Get the needed blend operation advanced properties
auto blend_operation_advanced_props = LvlInitStruct<VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&blend_operation_advanced_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.blend_operation_advanced_props = blend_operation_advanced_props;
}
if (IsExtEnabled(device_extensions.vk_khr_maintenance4)) {
// Get the needed maintenance4 properties
auto maintance4_props = LvlInitStruct<VkPhysicalDeviceMaintenance4PropertiesKHR>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&maintance4_props);
DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
phys_dev_ext_props.maintenance4_props = maintance4_props;
}
stateless_validation->phys_dev_ext_props = this->phys_dev_ext_props;
// Save app-enabled features in this device's validation object
// The enabled features can come from either pEnabledFeatures, or from the pNext chain
const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
safe_VkPhysicalDeviceFeatures2 tmp_features2_state;
tmp_features2_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
if (features2) {
tmp_features2_state.features = features2->features;
} else if (pCreateInfo->pEnabledFeatures) {
tmp_features2_state.features = *pCreateInfo->pEnabledFeatures;
} else {
tmp_features2_state.features = {};
}
// Use pCreateInfo->pNext to get full chain
stateless_validation->device_createinfo_pnext = SafePnextCopy(pCreateInfo->pNext);
stateless_validation->physical_device_features2 = tmp_features2_state;
}
bool StatelessValidation::manual_PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) const {
bool skip = false;
for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
skip |= validate_string("vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
"VUID-VkDeviceCreateInfo-ppEnabledLayerNames-parameter", pCreateInfo->ppEnabledLayerNames[i]);
}
// If this device supports VK_KHR_portability_subset, it must be enabled
const std::string portability_extension_name("VK_KHR_portability_subset");
const auto &dev_extensions = device_extensions_enumerated.at(physicalDevice);
const bool portability_supported = dev_extensions.count(portability_extension_name) != 0;
bool portability_requested = false;
for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
skip |=
validate_string("vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
"VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-parameter", pCreateInfo->ppEnabledExtensionNames[i]);
skip |= validate_extension_reqs(device_extensions, "VUID-vkCreateDevice-ppEnabledExtensionNames-01387", "device",
pCreateInfo->ppEnabledExtensionNames[i]);
if (portability_extension_name == pCreateInfo->ppEnabledExtensionNames[i]) {
portability_requested = true;
}
}
if (portability_supported && !portability_requested) {
skip |= LogError(physicalDevice, "VUID-VkDeviceCreateInfo-pProperties-04451",
"vkCreateDevice: VK_KHR_portability_subset must be enabled because physical device %s supports it",
report_data->FormatHandle(physicalDevice).c_str());
}
{
bool maint1 = IsExtEnabled(extension_state_by_name(device_extensions, VK_KHR_MAINTENANCE_1_EXTENSION_NAME));
bool negative_viewport =
IsExtEnabled(extension_state_by_name(device_extensions, VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME));
if (maint1 && negative_viewport) {
skip |= LogError(device, "VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-00374",
"VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
"VK_AMD_negative_viewport_height.");
}
}
{
bool khr_bda =
IsExtEnabledByCreateinfo(extension_state_by_name(device_extensions, VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME));
bool ext_bda =
IsExtEnabledByCreateinfo(extension_state_by_name(device_extensions, VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME));
if (khr_bda && ext_bda) {
skip |= LogError(device, "VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-03328",
"VkDeviceCreateInfo->ppEnabledExtensionNames must not contain both VK_KHR_buffer_device_address and "
"VK_EXT_buffer_device_address.");
}
}
if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
// Check for get_physical_device_properties2 struct
const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
if (features2) {
// Cannot include VkPhysicalDeviceFeatures2 and have non-null pEnabledFeatures
skip |= LogError(device, "VUID-VkDeviceCreateInfo-pNext-00373",
"VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2 struct when "
"pCreateInfo->pEnabledFeatures is non-NULL.");
}
}
auto features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
const VkPhysicalDeviceFeatures *features = features2 ? &features2->features : pCreateInfo->pEnabledFeatures;
const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
if (features && robustness2_features && robustness2_features->robustBufferAccess2 && !features->robustBufferAccess) {
skip |= LogError(device, "VUID-VkPhysicalDeviceRobustness2FeaturesEXT-robustBufferAccess2-04000",
"If robustBufferAccess2 is enabled then robustBufferAccess must be enabled.");
}
const auto *raytracing_features = LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
if (raytracing_features && raytracing_features->rayTracingPipelineShaderGroupHandleCaptureReplayMixed &&
!raytracing_features->rayTracingPipelineShaderGroupHandleCaptureReplay) {
skip |= LogError(
device,
"VUID-VkPhysicalDeviceRayTracingPipelineFeaturesKHR-rayTracingPipelineShaderGroupHandleCaptureReplayMixed-03575",
"If rayTracingPipelineShaderGroupHandleCaptureReplayMixed is VK_TRUE, rayTracingPipelineShaderGroupHandleCaptureReplay "
"must also be VK_TRUE.");
}
auto vertex_attribute_divisor_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
if (vertex_attribute_divisor_features && (!IsExtEnabled(device_extensions.vk_ext_vertex_attribute_divisor))) {
skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
"VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT "
"struct, VK_EXT_vertex_attribute_divisor must be enabled when it creates a device.");
}
const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
if (vulkan_11_features) {
const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(pCreateInfo->pNext);
while (current) {
if (current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-pNext-02829",
"If the pNext chain includes a VkPhysicalDeviceVulkan11Features structure, then it must not include a "
"VkPhysicalDevice16BitStorageFeatures, VkPhysicalDeviceMultiviewFeatures, "
"VkPhysicalDeviceVariablePointersFeatures, VkPhysicalDeviceProtectedMemoryFeatures, "
"VkPhysicalDeviceSamplerYcbcrConversionFeatures, or VkPhysicalDeviceShaderDrawParametersFeatures structure");
break;
}
current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
}
// Check features are enabled if matching extension is passed in as well
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
const char *extension = pCreateInfo->ppEnabledExtensionNames[i];
if ((0 == strncmp(extension, VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
(vulkan_11_features->shaderDrawParameters == VK_FALSE)) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-04476",
"vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan11Features::shaderDrawParameters is not VK_TRUE.",
VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME);
}
}
}
const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
if (vulkan_12_features) {
const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(pCreateInfo->pNext);
while (current) {
if (current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES ||
current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-pNext-02830",
"If the pNext chain includes a VkPhysicalDeviceVulkan12Features structure, then it must not include a "
"VkPhysicalDevice8BitStorageFeatures, VkPhysicalDeviceShaderAtomicInt64Features, "
"VkPhysicalDeviceShaderFloat16Int8Features, VkPhysicalDeviceDescriptorIndexingFeatures, "
"VkPhysicalDeviceScalarBlockLayoutFeatures, VkPhysicalDeviceImagelessFramebufferFeatures, "
"VkPhysicalDeviceUniformBufferStandardLayoutFeatures, VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures, "
"VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures, VkPhysicalDeviceHostQueryResetFeatures, "
"VkPhysicalDeviceTimelineSemaphoreFeatures, VkPhysicalDeviceBufferDeviceAddressFeatures, or "
"VkPhysicalDeviceVulkanMemoryModelFeatures structure");
break;
}
current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
}
// Check features are enabled if matching extension is passed in as well
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
const char *extension = pCreateInfo->ppEnabledExtensionNames[i];
if ((0 == strncmp(extension, VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
(vulkan_12_features->drawIndirectCount == VK_FALSE)) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02831",
"vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::drawIndirectCount is not VK_TRUE.",
VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME);
}
if ((0 == strncmp(extension, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
(vulkan_12_features->samplerMirrorClampToEdge == VK_FALSE)) {
skip |= LogError(instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02832",
"vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::samplerMirrorClampToEdge "
"is not VK_TRUE.",
VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME);
}
if ((0 == strncmp(extension, VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
(vulkan_12_features->descriptorIndexing == VK_FALSE)) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02833",
"vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::descriptorIndexing is not VK_TRUE.",
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
}
if ((0 == strncmp(extension, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
(vulkan_12_features->samplerFilterMinmax == VK_FALSE)) {
skip |= LogError(
instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02834",
"vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::samplerFilterMinmax is not VK_TRUE.",
VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME);
}
if ((0 == strncmp(extension, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
((vulkan_12_features->shaderOutputViewportIndex == VK_FALSE) ||
(vulkan_12_features->shaderOutputLayer == VK_FALSE))) {
skip |=
LogError(instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02835",
"vkCreateDevice(): %s is enabled but both VkPhysicalDeviceVulkan12Features::shaderOutputViewportIndex "
"and VkPhysicalDeviceVulkan12Features::shaderOutputLayer are not VK_TRUE.",
VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME);
}
}
if (vulkan_12_features->bufferDeviceAddress == VK_TRUE) {
if (IsExtEnabledByCreateinfo(extension_state_by_name(device_extensions, VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME))) {
skip |= LogError(instance, "VUID-VkDeviceCreateInfo-pNext-04748",
"vkCreateDevice(): pNext chain includes VkPhysicalDeviceVulkan12Features with bufferDeviceAddress "
"set to VK_TRUE and ppEnabledExtensionNames contains VK_EXT_buffer_device_address");
}
}
}
// Validate pCreateInfo->pQueueCreateInfos
if (pCreateInfo->pQueueCreateInfos) {
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
const uint32_t requested_queue_family = queue_create_info.queueFamilyIndex;
if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
skip |=
LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-queueFamilyIndex-00381",
"vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
"].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
"index value.",
i);
}
if (queue_create_info.pQueuePriorities != nullptr) {
for (uint32_t j = 0; j < queue_create_info.queueCount; ++j) {
const float queue_priority = queue_create_info.pQueuePriorities[j];
if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
skip |= LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-pQueuePriorities-00383",
"vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
"] (=%f) is not between 0 and 1 (inclusive).",
i, j, queue_priority);
}
}
}
// Need to know if protectedMemory feature is passed in preCall to creating the device
VkBool32 protected_memory = VK_FALSE;
const VkPhysicalDeviceProtectedMemoryFeatures *protected_features =
LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
if (protected_features) {
protected_memory = protected_features->protectedMemory;
} else if (vulkan_11_features) {
protected_memory = vulkan_11_features->protectedMemory;
}
if (((queue_create_info.flags & VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT) != 0) && (protected_memory == VK_FALSE)) {
skip |= LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-flags-02861",
"vkCreateDevice: pCreateInfo->flags contains VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT without the "
"protectedMemory feature being enabled as well.");
}
}
}
// feature dependencies for VK_KHR_variable_pointers
const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
VkBool32 variable_pointers = VK_FALSE;
VkBool32 variable_pointers_storage_buffer = VK_FALSE;
if (vulkan_11_features) {
variable_pointers = vulkan_11_features->variablePointers;
variable_pointers_storage_buffer = vulkan_11_features->variablePointersStorageBuffer;
} else if (variable_pointers_features) {
variable_pointers = variable_pointers_features->variablePointers;
variable_pointers_storage_buffer = variable_pointers_features->variablePointersStorageBuffer;
}
if ((variable_pointers == VK_TRUE) && (variable_pointers_storage_buffer == VK_FALSE)) {
skip |= LogError(instance, "VUID-VkPhysicalDeviceVariablePointersFeatures-variablePointers-01431",
"If variablePointers is VK_TRUE then variablePointersStorageBuffer also needs to be VK_TRUE");
}
// feature dependencies for VK_KHR_multiview
const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
VkBool32 multiview = VK_FALSE;
VkBool32 multiview_geometry_shader = VK_FALSE;
VkBool32 multiview_tessellation_shader = VK_FALSE;
if (vulkan_11_features) {
multiview = vulkan_11_features->multiview;
multiview_geometry_shader = vulkan_11_features->multiviewGeometryShader;
multiview_tessellation_shader = vulkan_11_features->multiviewTessellationShader;
} else if (multiview_features) {
multiview = multiview_features->multiview;
multiview_geometry_shader = multiview_features->multiviewGeometryShader;
multiview_tessellation_shader = multiview_features->multiviewTessellationShader;
}
if ((multiview == VK_FALSE) && (multiview_geometry_shader == VK_TRUE)) {
skip |= LogError(instance, "VUID-VkPhysicalDeviceMultiviewFeatures-multiviewGeometryShader-00580",
"If multiviewGeometryShader is VK_TRUE then multiview also needs to be VK_TRUE");
}
if ((multiview == VK_FALSE) && (multiview_tessellation_shader == VK_TRUE)) {
skip |= LogError(instance, "VUID-VkPhysicalDeviceMultiviewFeatures-multiviewTessellationShader-00581",
"If multiviewTessellationShader is VK_TRUE then multiview also needs to be VK_TRUE");
}
return skip;
}
bool StatelessValidation::require_device_extension(bool flag, char const *function_name, char const *extension_name) const {
if (!flag) {
return LogError(device, kVUID_PVError_ExtensionNotEnabled,
"%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
extension_name);
}
return false;
}
bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer) const {
bool skip = false;
if (pCreateInfo != nullptr) {
skip |=
ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", "VUID-VkBufferCreateInfo-size-00912", "vkCreateBuffer");
// Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
// If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
if (pCreateInfo->queueFamilyIndexCount <= 1) {
skip |= LogError(device, "VUID-VkBufferCreateInfo-sharingMode-00914",
"vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
"pCreateInfo->queueFamilyIndexCount must be greater than 1.");
}
// If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
// queueFamilyIndexCount uint32_t values
if (pCreateInfo->pQueueFamilyIndices == nullptr) {
skip |= LogError(device, "VUID-VkBufferCreateInfo-sharingMode-00913",
"vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
"pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
"pCreateInfo->queueFamilyIndexCount uint32_t values.");
}
}
if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!physical_device_features.sparseBinding)) {
skip |= LogError(device, "VUID-VkBufferCreateInfo-flags-00915",
"vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
"VK_BUFFER_CREATE_SPARSE_BINDING_BIT set.");
}
if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!physical_device_features.sparseResidencyBuffer)) {
skip |=
LogError(device, "VUID-VkBufferCreateInfo-flags-00916",
"vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with "
"the VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
}
if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!physical_device_features.sparseResidencyAliased)) {
skip |=
LogError(device, "VUID-VkBufferCreateInfo-flags-00917",
"vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with "
"the VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
}
// If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
// VK_BUFFER_CREATE_SPARSE_BINDING_BIT
if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
skip |= LogError(device, "VUID-VkBufferCreateInfo-flags-00918",
"vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
"VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT.");
}
const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(device_createinfo_pnext);
if (maintenance4_features && maintenance4_features->maintenance4) {
if (pCreateInfo->size > phys_dev_ext_props.maintenance4_props.maxBufferSize) {
skip |= LogError(device, "VUID-VkBufferCreateInfo-size-06409",
"vkCreateBuffer: pCreateInfo->size is larger than the maximum allowed buffer size "
"VkPhysicalDeviceMaintenance4Properties.maxBufferSize");
}
}
}
return skip;
}
bool StatelessValidation::manual_PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage) const {
bool skip = false;
if (pCreateInfo != nullptr) {
const VkFormat image_format = pCreateInfo->format;
const VkImageCreateFlags image_flags = pCreateInfo->flags;
// Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
// If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
if (pCreateInfo->queueFamilyIndexCount <= 1) {
skip |= LogError(device, "VUID-VkImageCreateInfo-sharingMode-00942",
"vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
"pCreateInfo->queueFamilyIndexCount must be greater than 1.");
}
// If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
// queueFamilyIndexCount uint32_t values
if (pCreateInfo->pQueueFamilyIndices == nullptr) {
skip |= LogError(device, "VUID-VkImageCreateInfo-sharingMode-00941",
"vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
"pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
"pCreateInfo->queueFamilyIndexCount uint32_t values.");
}
}
skip |= ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width",
"VUID-VkImageCreateInfo-extent-00944", "vkCreateImage");
skip |= ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height",
"VUID-VkImageCreateInfo-extent-00945", "vkCreateImage");
skip |= ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth",
"VUID-VkImageCreateInfo-extent-00946", "vkCreateImage");
skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", "VUID-VkImageCreateInfo-mipLevels-00947",
"vkCreateImage");
skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers",
"VUID-VkImageCreateInfo-arrayLayers-00948", "vkCreateImage");
// InitialLayout must be PREINITIALIZED or UNDEFINED
if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
(pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
skip |= LogError(
device, "VUID-VkImageCreateInfo-initialLayout-00993",
"vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.",
string_VkImageLayout(pCreateInfo->initialLayout));
}
// If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) &&
((pCreateInfo->extent.height != 1) || (pCreateInfo->extent.depth != 1))) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00956",
"vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
"pCreateInfo->extent.depth must be 1.");
}
if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
if (image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) {
if (pCreateInfo->extent.width != pCreateInfo->extent.height) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00954",
"vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
"pCreateInfo->extent.width (=%" PRIu32 ") and pCreateInfo->extent.height (=%" PRIu32
") are not equal.",
pCreateInfo->extent.width, pCreateInfo->extent.height);
}
if (pCreateInfo->arrayLayers < 6) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00954",
"vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
"pCreateInfo->arrayLayers (=%" PRIu32 ") is not greater than or equal to 6.",
pCreateInfo->arrayLayers);
}
}
if (pCreateInfo->extent.depth != 1) {
skip |= LogError(
device, "VUID-VkImageCreateInfo-imageType-00957",
"vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1.");
}
}
// 3D image may have only 1 layer
if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00961",
"vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1.");
}
if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
// At least one of the legal attachment bits must be set
if (0 == (pCreateInfo->usage & legal_flags)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-usage-00966",
"vkCreateImage(): Transient attachment image without a compatible attachment flag set.");
}
// No flags other than the legal attachment bits may be set
legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
if (0 != (pCreateInfo->usage & ~legal_flags)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-usage-00963",
"vkCreateImage(): Transient attachment image with incompatible usage flags set.");
}
}
// mipLevels must be less than or equal to the number of levels in the complete mipmap chain
uint32_t max_dim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
// Max mip levels is different for corner-sampled images vs normal images.
uint32_t max_mip_levels = (image_flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV)
? static_cast<uint32_t>(ceil(log2(max_dim)))
: static_cast<uint32_t>(floor(log2(max_dim)) + 1);
if (max_dim > 0 && pCreateInfo->mipLevels > max_mip_levels) {
skip |=
LogError(device, "VUID-VkImageCreateInfo-mipLevels-00958",
"vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
"floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1.");
}
if ((image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT) && (pCreateInfo->imageType != VK_IMAGE_TYPE_3D)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00950",
"vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT but "
"pCreateInfo->imageType is not VK_IMAGE_TYPE_3D.");
}
if ((image_flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!physical_device_features.sparseBinding)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00969",
"vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_BINDING_BIT, but the "
"VkPhysicalDeviceFeatures::sparseBinding feature is disabled.");
}
if ((image_flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!physical_device_features.sparseResidencyAliased)) {
skip |= LogError(
device, "VUID-VkImageCreateInfo-flags-01924",
"vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
"VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
}
// If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
// VK_IMAGE_CREATE_SPARSE_BINDING_BIT
if (((image_flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
((image_flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00987",
"vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
"VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT.");
}
// Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
if ((image_flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
// Linear tiling is unsupported
if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-04121",
"vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
"tiling of VK_IMAGE_TILING_LINEAR is not supported");
}
// Sparse 1D image isn't valid
if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00970",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image.");
}
// Sparse 2D image when device doesn't support it
if ((VK_FALSE == physical_device_features.sparseResidencyImage2D) && (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00971",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
"feature is not enabled on the device.");
}
// Sparse 3D image when device doesn't support it
if ((VK_FALSE == physical_device_features.sparseResidencyImage3D) && (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00972",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
"feature is not enabled on the device.");
}
// Multi-sample 2D image when device doesn't support it
if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
if ((VK_FALSE == physical_device_features.sparseResidency2Samples) &&
(VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00973",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
"corresponding feature is not enabled on the device.");
} else if ((VK_FALSE == physical_device_features.sparseResidency4Samples) &&
(VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00974",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
"corresponding feature is not enabled on the device.");
} else if ((VK_FALSE == physical_device_features.sparseResidency8Samples) &&
(VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00975",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
"corresponding feature is not enabled on the device.");
} else if ((VK_FALSE == physical_device_features.sparseResidency16Samples) &&
(VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00976",
"vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
"corresponding feature is not enabled on the device.");
}
}
}
if (pCreateInfo->usage & VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV) {
if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D) {
skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-02082",
"vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
"imageType must be VK_IMAGE_TYPE_2D.");
}
if (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) {
skip |= LogError(device, "VUID-VkImageCreateInfo-samples-02083",
"vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
"samples must be VK_SAMPLE_COUNT_1_BIT.");
}
if (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) {
skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-02084",
"vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
"tiling must be VK_IMAGE_TILING_OPTIMAL.");
}
}
if (image_flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV) {
if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D && pCreateInfo->imageType != VK_IMAGE_TYPE_3D) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02050",
"vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, "
"imageType must be VK_IMAGE_TYPE_2D or VK_IMAGE_TYPE_3D.");
}
if ((image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) || FormatIsDepthOrStencil(image_format)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02051",
"vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, "
"it must not also contain VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT and format (%s) must not be a "
"depth/stencil format.",
string_VkFormat(image_format));
}
if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D && (pCreateInfo->extent.width == 1 || pCreateInfo->extent.height == 1)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02052",
"vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and "
"imageType is VK_IMAGE_TYPE_2D, extent.width and extent.height must be "
"greater than 1.");
} else if (pCreateInfo->imageType == VK_IMAGE_TYPE_3D &&
(pCreateInfo->extent.width == 1 || pCreateInfo->extent.height == 1 || pCreateInfo->extent.depth == 1)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02053",
"vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and "
"imageType is VK_IMAGE_TYPE_3D, extent.width, extent.height, and extent.depth "
"must be greater than 1.");
}
}
if (((image_flags & VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT) != 0) &&
(FormatHasDepth(image_format) == false)) {
skip |= LogError(device, "VUID-VkImageCreateInfo-flags-01533",
"vkCreateImage(): if flags contain VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT the "
"format (%s) must be a depth or depth/stencil format.",
string_VkFormat(image_format));
}
const auto image_stencil_struct = LvlFindInChain<VkImageStencilUsageCreateInfo>(pCreateInfo->pNext);
if (image_stencil_struct != nullptr) {
if ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0) {
VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
// No flags other than the legal attachment bits may be set
legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
if ((image_stencil_struct->stencilUsage & ~legal_flags) != 0) {
skip |= LogError(device, "VUID-VkImageStencilUsageCreateInfo-stencilUsage-02539",
"vkCreateImage(): in pNext chain, VkImageStencilUsageCreateInfo::stencilUsage includes "
"VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, it must not include bits other than "
"VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT");
}
}
if (FormatIsDepthOrStencil(image_format)) {
if ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) != 0) {
if (pCreateInfo->extent.width > device_limits.maxFramebufferWidth) {
skip |=
LogError(device, "VUID-VkImageCreateInfo-Format-02536",
"vkCreateImage(): Depth-stencil image contains VkImageStencilUsageCreateInfo structure with "
"stencilUsage including VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT and image width (%" PRIu32
") exceeds device "
"maxFramebufferWidth (%" PRIu32 ")",
pCreateInfo->extent.width, device_limits.maxFramebufferWidth);
}
if (pCreateInfo->extent.height > device_limits.maxFramebufferHeight) {
skip |=
LogError(device, "VUID-VkImageCreateInfo-format-02537",
"vkCreateImage(): Depth-stencil image contains VkImageStencilUsageCreateInfo structure with "
"stencilUsage including VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT and image height (%" PRIu32