1 /* Copyright (c) 2015-2020 The Khronos Group Inc.
2  * Copyright (c) 2015-2020 Valve Corporation
3  * Copyright (c) 2015-2020 LunarG, Inc.
4  * Copyright (C) 2015-2020 Google Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Mark Lobodzinski <mark@LunarG.com>
19  * Author: John Zulauf <jzulauf@lunarg.com>
20  */
21 
22 #include <cmath>
23 
24 #include "chassis.h"
25 #include "stateless_validation.h"
26 #include "layer_chassis_dispatch.h"
27 
28 static const int MaxParamCheckerStringLength = 256;
29 
30 template <typename T>
in_inclusive_range(const T & value,const T & min,const T & max)31 inline bool in_inclusive_range(const T &value, const T &min, const T &max) {
32     // Using only < for generality and || for early abort
33     return !((value < min) || (max < value));
34 }
35 
validate_string(const char * apiName,const ParameterName & stringName,const std::string & vuid,const char * validateString) const36 bool StatelessValidation::validate_string(const char *apiName, const ParameterName &stringName, const std::string &vuid,
37                                           const char *validateString) const {
38     bool skip = false;
39 
40     VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
41 
42     if (result == VK_STRING_ERROR_NONE) {
43         return skip;
44     } else if (result & VK_STRING_ERROR_LENGTH) {
45         skip = LogError(device, vuid, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
46                         MaxParamCheckerStringLength);
47     } else if (result & VK_STRING_ERROR_BAD_DATA) {
48         skip = LogError(device, vuid, "%s: string %s contains invalid characters or is badly formed", apiName,
49                         stringName.get_name().c_str());
50     }
51     return skip;
52 }
53 
validate_api_version(uint32_t api_version,uint32_t effective_api_version) const54 bool StatelessValidation::validate_api_version(uint32_t api_version, uint32_t effective_api_version) const {
55     bool skip = false;
56     uint32_t api_version_nopatch = VK_MAKE_VERSION(VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), 0);
57     if (api_version_nopatch != effective_api_version) {
58         if (api_version_nopatch < VK_API_VERSION_1_0) {
59             skip |= LogError(instance, kVUIDUndefined,
60                              "Invalid CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). "
61                              "Using VK_API_VERSION_%" PRIu32 "_%" PRIu32 ".",
62                              api_version, VK_VERSION_MAJOR(effective_api_version), VK_VERSION_MINOR(effective_api_version));
63         } else {
64             skip |= LogWarning(instance, kVUIDUndefined,
65                                "Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). "
66                                "Assuming VK_API_VERSION_%" PRIu32 "_%" PRIu32 ".",
67                                api_version, VK_VERSION_MAJOR(effective_api_version), VK_VERSION_MINOR(effective_api_version));
68         }
69     }
70     return skip;
71 }
72 
validate_instance_extensions(const VkInstanceCreateInfo * pCreateInfo) const73 bool StatelessValidation::validate_instance_extensions(const VkInstanceCreateInfo *pCreateInfo) const {
74     bool skip = false;
75     // Create and use a local instance extension object, as an actual instance has not been created yet
76     uint32_t specified_version = (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0);
77     InstanceExtensions local_instance_extensions;
78     local_instance_extensions.InitFromInstanceCreateInfo(specified_version, pCreateInfo);
79 
80     for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
81         skip |= validate_extension_reqs(local_instance_extensions, "VUID-vkCreateInstance-ppEnabledExtensionNames-01388",
82                                         "instance", pCreateInfo->ppEnabledExtensionNames[i]);
83     }
84 
85     return skip;
86 }
87 
SupportedByPdev(const VkPhysicalDevice physical_device,const std::string ext_name) const88 bool StatelessValidation::SupportedByPdev(const VkPhysicalDevice physical_device, const std::string ext_name) const {
89     if (instance_extensions.vk_khr_get_physical_device_properties_2) {
90         // Struct is legal IF it's supported
91         const auto &dev_exts_enumerated = device_extensions_enumerated.find(physical_device);
92         if (dev_exts_enumerated == device_extensions_enumerated.end()) return true;
93         auto enum_iter = dev_exts_enumerated->second.find(ext_name);
94         if (enum_iter != dev_exts_enumerated->second.cend()) {
95             return true;
96         }
97     }
98     return false;
99 }
100 
validate_validation_features(const VkInstanceCreateInfo * pCreateInfo,const VkValidationFeaturesEXT * validation_features) const101 bool StatelessValidation::validate_validation_features(const VkInstanceCreateInfo *pCreateInfo,
102                                                        const VkValidationFeaturesEXT *validation_features) const {
103     bool skip = false;
104     bool debug_printf = false;
105     bool gpu_assisted = false;
106     bool reserve_slot = false;
107     for (uint32_t i = 0; i < validation_features->enabledValidationFeatureCount; i++) {
108         switch (validation_features->pEnabledValidationFeatures[i]) {
109             case VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT:
110                 gpu_assisted = true;
111                 break;
112 
113             case VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT:
114                 debug_printf = true;
115                 break;
116 
117             case VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT:
118                 reserve_slot = true;
119                 break;
120 
121             default:
122                 break;
123         }
124     }
125     if (reserve_slot && !gpu_assisted) {
126         skip |= LogError(instance, "VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02967",
127                          "If VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT is in pEnabledValidationFeatures, "
128                          "VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT must also be in pEnabledValidationFeatures.");
129     }
130     if (gpu_assisted && debug_printf) {
131         skip |= LogError(instance, "VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02968",
132                          "If VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT is in pEnabledValidationFeatures, "
133                          "VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT must not also be in pEnabledValidationFeatures.");
134     }
135 
136     return skip;
137 }
138 
139 template <typename ExtensionState>
extension_state_by_name(const ExtensionState & extensions,const char * extension_name)140 ExtEnabled extension_state_by_name(const ExtensionState &extensions, const char *extension_name) {
141     if (!extension_name) return kNotEnabled;  // null strings specify nothing
142     auto info = ExtensionState::get_info(extension_name);
143     ExtEnabled state =
144         info.state ? extensions.*(info.state) : kNotEnabled;  // unknown extensions can't be enabled in extension struct
145     return state;
146 }
147 
manual_PreCallValidateCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance) const148 bool StatelessValidation::manual_PreCallValidateCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
149                                                                const VkAllocationCallbacks *pAllocator,
150                                                                VkInstance *pInstance) const {
151     bool skip = false;
152     // Note: From the spec--
153     //  Providing a NULL VkInstanceCreateInfo::pApplicationInfo or providing an apiVersion of 0 is equivalent to providing
154     //  an apiVersion of VK_MAKE_VERSION(1, 0, 0).  (a.k.a. VK_API_VERSION_1_0)
155     uint32_t local_api_version = (pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->apiVersion)
156                                      ? pCreateInfo->pApplicationInfo->apiVersion
157                                      : VK_API_VERSION_1_0;
158     skip |= validate_api_version(local_api_version, api_version);
159     skip |= validate_instance_extensions(pCreateInfo);
160     const auto *validation_features = lvl_find_in_chain<VkValidationFeaturesEXT>(pCreateInfo->pNext);
161     if (validation_features) skip |= validate_validation_features(pCreateInfo, validation_features);
162 
163     return skip;
164 }
165 
PostCallRecordCreateInstance(const VkInstanceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkInstance * pInstance,VkResult result)166 void StatelessValidation::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
167                                                        const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
168                                                        VkResult result) {
169     auto instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map);
170     // Copy extension data into local object
171     if (result != VK_SUCCESS) return;
172     this->instance_extensions = instance_data->instance_extensions;
173 
174     uint32_t pdev_count = 0;
175     DispatchEnumeratePhysicalDevices(*pInstance, &pdev_count, nullptr);
176     std::vector<VkPhysicalDevice> physical_devices;
177     physical_devices.resize(pdev_count);
178     DispatchEnumeratePhysicalDevices(*pInstance, &pdev_count, physical_devices.data());
179 
180     for (uint32_t i = 0; i < physical_devices.size(); i++) {
181         auto phys_dev_props = new VkPhysicalDeviceProperties;
182         DispatchGetPhysicalDeviceProperties(physical_devices[i], phys_dev_props);
183         physical_device_properties_map[physical_devices[i]] = phys_dev_props;
184 
185         // Enumerate the Device Ext Properties to save the PhysicalDevice supported extension state
186         uint32_t ext_count = 0;
187         std::unordered_set<std::string> dev_exts_enumerated{};
188         std::vector<VkExtensionProperties> ext_props{};
189         instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_devices[i], nullptr, &ext_count, nullptr);
190         ext_props.resize(ext_count);
191         instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_devices[i], nullptr, &ext_count, ext_props.data());
192         for (uint32_t j = 0; j < ext_count; j++) {
193             dev_exts_enumerated.insert(ext_props[j].extensionName);
194         }
195         device_extensions_enumerated[physical_devices[i]] = std::move(dev_exts_enumerated);
196     }
197 }
198 
PreCallRecordDestroyInstance(VkInstance instance,const VkAllocationCallbacks * pAllocator)199 void StatelessValidation::PreCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
200     for (auto it = physical_device_properties_map.begin(); it != physical_device_properties_map.end();) {
201         delete (it->second);
202         it = physical_device_properties_map.erase(it);
203     }
204 };
205 
PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice,VkResult result)206 void StatelessValidation::PostCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
207                                                      const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, VkResult result) {
208     auto device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
209     if (result != VK_SUCCESS) return;
210     ValidationObject *validation_data = GetValidationObject(device_data->object_dispatch, LayerObjectTypeParameterValidation);
211     StatelessValidation *stateless_validation = static_cast<StatelessValidation *>(validation_data);
212 
213     // Parmeter validation also uses extension data
214     stateless_validation->device_extensions = this->device_extensions;
215 
216     VkPhysicalDeviceProperties device_properties = {};
217     // Need to get instance and do a getlayerdata call...
218     DispatchGetPhysicalDeviceProperties(physicalDevice, &device_properties);
219     memcpy(&stateless_validation->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
220 
221     if (device_extensions.vk_nv_shading_rate_image) {
222         // Get the needed shading rate image limits
223         auto shading_rate_image_props = lvl_init_struct<VkPhysicalDeviceShadingRateImagePropertiesNV>();
224         auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&shading_rate_image_props);
225         DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
226         phys_dev_ext_props.shading_rate_image_props = shading_rate_image_props;
227     }
228 
229     if (device_extensions.vk_nv_mesh_shader) {
230         // Get the needed mesh shader limits
231         auto mesh_shader_props = lvl_init_struct<VkPhysicalDeviceMeshShaderPropertiesNV>();
232         auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&mesh_shader_props);
233         DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
234         phys_dev_ext_props.mesh_shader_props = mesh_shader_props;
235     }
236 
237     if (device_extensions.vk_nv_ray_tracing) {
238         // Get the needed ray tracing limits
239         auto ray_tracing_props = lvl_init_struct<VkPhysicalDeviceRayTracingPropertiesNV>();
240         auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&ray_tracing_props);
241         DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
242         phys_dev_ext_props.ray_tracing_propsNV = ray_tracing_props;
243     }
244 
245     if (device_extensions.vk_khr_ray_tracing) {
246         // Get the needed ray tracing limits
247         auto ray_tracing_props = lvl_init_struct<VkPhysicalDeviceRayTracingPropertiesKHR>();
248         auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&ray_tracing_props);
249         DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
250         phys_dev_ext_props.ray_tracing_propsKHR = ray_tracing_props;
251     }
252 
253     if (device_extensions.vk_ext_transform_feedback) {
254         // Get the needed transform feedback limits
255         auto transform_feedback_props = lvl_init_struct<VkPhysicalDeviceTransformFeedbackPropertiesEXT>();
256         auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2KHR>(&transform_feedback_props);
257         DispatchGetPhysicalDeviceProperties2KHR(physicalDevice, &prop2);
258         phys_dev_ext_props.transform_feedback_props = transform_feedback_props;
259     }
260 
261     stateless_validation->phys_dev_ext_props = this->phys_dev_ext_props;
262 
263     // Save app-enabled features in this device's validation object
264     // The enabled features can come from either pEnabledFeatures, or from the pNext chain
265     const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
266     safe_VkPhysicalDeviceFeatures2 tmp_features2_state;
267     tmp_features2_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
268     if (features2) {
269         tmp_features2_state.features = features2->features;
270     } else if (pCreateInfo->pEnabledFeatures) {
271         tmp_features2_state.features = *pCreateInfo->pEnabledFeatures;
272     } else {
273         tmp_features2_state.features = {};
274     }
275     // Use pCreateInfo->pNext to get full chain
276     stateless_validation->device_createinfo_pnext = SafePnextCopy(pCreateInfo->pNext);
277     stateless_validation->physical_device_features2 = tmp_features2_state;
278 }
279 
manual_PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice,const VkDeviceCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDevice * pDevice) const280 bool StatelessValidation::manual_PreCallValidateCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
281                                                              const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) const {
282     bool skip = false;
283 
284     for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
285         skip |= validate_string("vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
286                                 "VUID-VkDeviceCreateInfo-ppEnabledLayerNames-parameter", pCreateInfo->ppEnabledLayerNames[i]);
287     }
288 
289     for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
290         skip |=
291             validate_string("vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
292                             "VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-parameter", pCreateInfo->ppEnabledExtensionNames[i]);
293         skip |= validate_extension_reqs(device_extensions, "VUID-vkCreateDevice-ppEnabledExtensionNames-01387", "device",
294                                         pCreateInfo->ppEnabledExtensionNames[i]);
295     }
296 
297     {
298         bool maint1 = IsExtEnabled(extension_state_by_name(device_extensions, VK_KHR_MAINTENANCE1_EXTENSION_NAME));
299         bool negative_viewport =
300             IsExtEnabled(extension_state_by_name(device_extensions, VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME));
301         if (maint1 && negative_viewport) {
302             skip |= LogError(device, "VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-00374",
303                              "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
304                              "VK_AMD_negative_viewport_height.");
305         }
306     }
307 
308     {
309         bool khr_bda = IsExtEnabled(extension_state_by_name(device_extensions, VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME));
310         bool ext_bda = IsExtEnabled(extension_state_by_name(device_extensions, VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME));
311         if (khr_bda && ext_bda) {
312             skip |= LogError(device, "VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-03328",
313                              "VkDeviceCreateInfo->ppEnabledExtensionNames must not contain both VK_KHR_buffer_device_address and "
314                              "VK_EXT_buffer_device_address.");
315         }
316     }
317 
318     if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
319         // Check for get_physical_device_properties2 struct
320         const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
321         if (features2) {
322             // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
323             skip |= LogError(device, "VUID-VkDeviceCreateInfo-pNext-00373",
324                              "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
325                              "pCreateInfo->pEnabledFeatures is non-NULL.");
326         }
327     }
328 
329     auto features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
330     const VkPhysicalDeviceFeatures *features = features2 ? &features2->features : pCreateInfo->pEnabledFeatures;
331     const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
332     if (features && robustness2_features && robustness2_features->robustBufferAccess2 && !features->robustBufferAccess) {
333         skip |= LogError(device, "VUID-VkPhysicalDeviceRobustness2FeaturesEXT-robustBufferAccess2-04000",
334                          "If robustBufferAccess2 is enabled then robustBufferAccess must be enabled.");
335     }
336     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(pCreateInfo->pNext);
337     if (raytracing_features && raytracing_features->rayTracingShaderGroupHandleCaptureReplayMixed &&
338         !raytracing_features->rayTracingShaderGroupHandleCaptureReplay) {
339         skip |= LogError(device, "VUID-VkPhysicalDeviceRayTracingFeaturesKHR-rayTracingShaderGroupHandleCaptureReplayMixed-03348",
340                          "If rayTracingShaderGroupHandleCaptureReplayMixed is VK_TRUE, rayTracingShaderGroupHandleCaptureReplay "
341                          "must also be VK_TRUE.");
342     }
343     auto vertex_attribute_divisor_features =
344         lvl_find_in_chain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
345     if (vertex_attribute_divisor_features && (!device_extensions.vk_ext_vertex_attribute_divisor)) {
346         skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
347                          "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT "
348                          "struct, VK_EXT_vertex_attribute_divisor must be enabled when it creates a device.");
349     }
350 
351     const auto *vulkan_11_features = lvl_find_in_chain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
352     if (vulkan_11_features) {
353         const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(pCreateInfo->pNext);
354         while (current) {
355             if (current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES ||
356                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES ||
357                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES ||
358                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES ||
359                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES ||
360                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES) {
361                 skip |= LogError(
362                     instance, "VUID-VkDeviceCreateInfo-pNext-02829",
363                     "If the pNext chain includes a VkPhysicalDeviceVulkan11Features structure, then it must not include a "
364                     "VkPhysicalDevice16BitStorageFeatures, VkPhysicalDeviceMultiviewFeatures, "
365                     "VkPhysicalDeviceVariablePointersFeatures, VkPhysicalDeviceProtectedMemoryFeatures, "
366                     "VkPhysicalDeviceSamplerYcbcrConversionFeatures, or VkPhysicalDeviceShaderDrawParametersFeatures structure");
367                 break;
368             }
369             current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
370         }
371     }
372 
373     const auto *vulkan_12_features = lvl_find_in_chain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
374     if (vulkan_12_features) {
375         const VkBaseOutStructure *current = reinterpret_cast<const VkBaseOutStructure *>(pCreateInfo->pNext);
376         while (current) {
377             if (current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES ||
378                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES ||
379                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES ||
380                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES ||
381                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES ||
382                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES ||
383                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES ||
384                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES ||
385                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES ||
386                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES ||
387                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES ||
388                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES ||
389                 current->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES) {
390                 skip |= LogError(
391                     instance, "VUID-VkDeviceCreateInfo-pNext-02830",
392                     "If the pNext chain includes a VkPhysicalDeviceVulkan12Features structure, then it must not include a "
393                     "VkPhysicalDevice8BitStorageFeatures, VkPhysicalDeviceShaderAtomicInt64Features, "
394                     "VkPhysicalDeviceShaderFloat16Int8Features, VkPhysicalDeviceDescriptorIndexingFeatures, "
395                     "VkPhysicalDeviceScalarBlockLayoutFeatures, VkPhysicalDeviceImagelessFramebufferFeatures, "
396                     "VkPhysicalDeviceUniformBufferStandardLayoutFeatures, VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures, "
397                     "VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures, VkPhysicalDeviceHostQueryResetFeatures, "
398                     "VkPhysicalDeviceTimelineSemaphoreFeatures, VkPhysicalDeviceBufferDeviceAddressFeatures, or "
399                     "VkPhysicalDeviceVulkanMemoryModelFeatures structure");
400                 break;
401             }
402             current = reinterpret_cast<const VkBaseOutStructure *>(current->pNext);
403         }
404         // Check features are enabled if matching extension is passed in as well
405         for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
406             const char *extension = pCreateInfo->ppEnabledExtensionNames[i];
407             if ((0 == strncmp(extension, VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
408                 (vulkan_12_features->drawIndirectCount == VK_FALSE)) {
409                 skip |= LogError(
410                     instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02831",
411                     "vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::drawIndirectCount is not VK_TRUE.",
412                     VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME);
413             }
414             if ((0 == strncmp(extension, VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
415                 (vulkan_12_features->samplerMirrorClampToEdge == VK_FALSE)) {
416                 skip |= LogError(instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02832",
417                                  "vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::samplerMirrorClampToEdge "
418                                  "is not VK_TRUE.",
419                                  VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME);
420             }
421             if ((0 == strncmp(extension, VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
422                 (vulkan_12_features->descriptorIndexing == VK_FALSE)) {
423                 skip |= LogError(
424                     instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02833",
425                     "vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::descriptorIndexing is not VK_TRUE.",
426                     VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
427             }
428             if ((0 == strncmp(extension, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
429                 (vulkan_12_features->samplerFilterMinmax == VK_FALSE)) {
430                 skip |= LogError(
431                     instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02834",
432                     "vkCreateDevice(): %s is enabled but VkPhysicalDeviceVulkan12Features::samplerFilterMinmax is not VK_TRUE.",
433                     VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME);
434             }
435             if ((0 == strncmp(extension, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE)) &&
436                 ((vulkan_12_features->shaderOutputViewportIndex == VK_FALSE) ||
437                  (vulkan_12_features->shaderOutputLayer == VK_FALSE))) {
438                 skip |=
439                     LogError(instance, "VUID-VkDeviceCreateInfo-ppEnabledExtensions-02835",
440                              "vkCreateDevice(): %s is enabled but both VkPhysicalDeviceVulkan12Features::shaderOutputViewportIndex "
441                              "and VkPhysicalDeviceVulkan12Features::shaderOutputLayer are not VK_TRUE.",
442                              VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME);
443             }
444         }
445     }
446 
447     // Validate pCreateInfo->pQueueCreateInfos
448     if (pCreateInfo->pQueueCreateInfos) {
449         std::unordered_set<uint32_t> set;
450 
451         for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
452             const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
453             const uint32_t requested_queue_family = queue_create_info.queueFamilyIndex;
454             if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
455                 skip |=
456                     LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-queueFamilyIndex-00381",
457                              "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
458                              "].queueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family "
459                              "index value.",
460                              i);
461             } else if (set.count(requested_queue_family)) {
462                 skip |= LogError(physicalDevice, "VUID-VkDeviceCreateInfo-queueFamilyIndex-00372",
463                                  "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
464                                  ") is not unique within pCreateInfo->pQueueCreateInfos array.",
465                                  i, requested_queue_family);
466             } else {
467                 set.insert(requested_queue_family);
468             }
469 
470             if (queue_create_info.pQueuePriorities != nullptr) {
471                 for (uint32_t j = 0; j < queue_create_info.queueCount; ++j) {
472                     const float queue_priority = queue_create_info.pQueuePriorities[j];
473                     if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
474                         skip |= LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-pQueuePriorities-00383",
475                                          "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
476                                          "] (=%f) is not between 0 and 1 (inclusive).",
477                                          i, j, queue_priority);
478                     }
479                 }
480             }
481 
482             // Need to know if protectedMemory feature is passed in preCall to creating the device
483             VkBool32 protectedMemory = VK_FALSE;
484             const VkPhysicalDeviceProtectedMemoryFeatures *protected_features =
485                 lvl_find_in_chain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
486             if (protected_features) {
487                 protectedMemory = protected_features->protectedMemory;
488             } else if (vulkan_11_features) {
489                 protectedMemory = vulkan_11_features->protectedMemory;
490             }
491             if ((queue_create_info.flags == VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT) && (protectedMemory == VK_FALSE)) {
492                 skip |= LogError(physicalDevice, "VUID-VkDeviceQueueCreateInfo-flags-02861",
493                                  "vkCreateDevice: pCreateInfo->flags set to VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT without the "
494                                  "protectedMemory feature being set as well.");
495             }
496         }
497     }
498 
499     // feature dependencies for VK_KHR_variable_pointers
500     const auto *variable_pointers_features = lvl_find_in_chain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
501     VkBool32 variablePointers = VK_FALSE;
502     VkBool32 variablePointersStorageBuffer = VK_FALSE;
503     if (vulkan_11_features) {
504         variablePointers = vulkan_11_features->variablePointers;
505         variablePointersStorageBuffer = vulkan_11_features->variablePointersStorageBuffer;
506     } else if (variable_pointers_features) {
507         variablePointers = variable_pointers_features->variablePointers;
508         variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
509     }
510     if ((variablePointers == VK_TRUE) && (variablePointersStorageBuffer == VK_FALSE)) {
511         skip |= LogError(instance, "VUID-VkPhysicalDeviceVariablePointersFeatures-variablePointers-01431",
512                          "If variablePointers is VK_TRUE then variablePointersStorageBuffer also needs to be VK_TRUE");
513     }
514 
515     // feature dependencies for VK_KHR_multiview
516     const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
517     VkBool32 multiview = VK_FALSE;
518     VkBool32 multiviewGeometryShader = VK_FALSE;
519     VkBool32 multiviewTessellationShader = VK_FALSE;
520     if (vulkan_11_features) {
521         multiview = vulkan_11_features->multiview;
522         multiviewGeometryShader = vulkan_11_features->multiviewGeometryShader;
523         multiviewTessellationShader = vulkan_11_features->multiviewTessellationShader;
524     } else if (multiview_features) {
525         multiview = multiview_features->multiview;
526         multiviewGeometryShader = multiview_features->multiviewGeometryShader;
527         multiviewTessellationShader = multiview_features->multiviewTessellationShader;
528     }
529     if ((multiview == VK_FALSE) && (multiviewGeometryShader == VK_TRUE)) {
530         skip |= LogError(instance, "VUID-VkPhysicalDeviceMultiviewFeatures-multiviewGeometryShader-00580",
531                          "If multiviewGeometryShader is VK_TRUE then multiview also needs to be VK_TRUE");
532     }
533     if ((multiview == VK_FALSE) && (multiviewTessellationShader == VK_TRUE)) {
534         skip |= LogError(instance, "VUID-VkPhysicalDeviceMultiviewFeatures-multiviewTessellationShader-00581",
535                          "If multiviewTessellationShader is VK_TRUE then multiview also needs to be VK_TRUE");
536     }
537 
538     return skip;
539 }
540 
require_device_extension(bool flag,char const * function_name,char const * extension_name) const541 bool StatelessValidation::require_device_extension(bool flag, char const *function_name, char const *extension_name) const {
542     if (!flag) {
543         return LogError(device, kVUID_PVError_ExtensionNotEnabled,
544                         "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
545                         extension_name);
546     }
547 
548     return false;
549 }
550 
manual_PreCallValidateCreateBuffer(VkDevice device,const VkBufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkBuffer * pBuffer) const551 bool StatelessValidation::manual_PreCallValidateCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
552                                                              const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer) const {
553     bool skip = false;
554 
555     if (pCreateInfo != nullptr) {
556         skip |=
557             ValidateGreaterThanZero(pCreateInfo->size, "pCreateInfo->size", "VUID-VkBufferCreateInfo-size-00912", "vkCreateBuffer");
558 
559         // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
560         if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
561             // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
562             if (pCreateInfo->queueFamilyIndexCount <= 1) {
563                 skip |= LogError(device, "VUID-VkBufferCreateInfo-sharingMode-00914",
564                                  "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
565                                  "pCreateInfo->queueFamilyIndexCount must be greater than 1.");
566             }
567 
568             // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
569             // queueFamilyIndexCount uint32_t values
570             if (pCreateInfo->pQueueFamilyIndices == nullptr) {
571                 skip |= LogError(device, "VUID-VkBufferCreateInfo-sharingMode-00913",
572                                  "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
573                                  "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
574                                  "pCreateInfo->queueFamilyIndexCount uint32_t values.");
575             }
576         }
577 
578         if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) && (!physical_device_features.sparseBinding)) {
579             skip |= LogError(device, "VUID-VkBufferCreateInfo-flags-00915",
580                              "vkCreateBuffer(): the sparseBinding device feature is disabled: Buffers cannot be created with the "
581                              "VK_BUFFER_CREATE_SPARSE_BINDING_BIT set.");
582         }
583 
584         if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) && (!physical_device_features.sparseResidencyBuffer)) {
585             skip |=
586                 LogError(device, "VUID-VkBufferCreateInfo-flags-00916",
587                          "vkCreateBuffer(): the sparseResidencyBuffer device feature is disabled: Buffers cannot be created with "
588                          "the VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT set.");
589         }
590 
591         if ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_ALIASED_BIT) && (!physical_device_features.sparseResidencyAliased)) {
592             skip |=
593                 LogError(device, "VUID-VkBufferCreateInfo-flags-00917",
594                          "vkCreateBuffer(): the sparseResidencyAliased device feature is disabled: Buffers cannot be created with "
595                          "the VK_BUFFER_CREATE_SPARSE_ALIASED_BIT set.");
596         }
597 
598         // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
599         // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
600         if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
601             ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
602             skip |= LogError(device, "VUID-VkBufferCreateInfo-flags-00918",
603                              "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
604                              "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT.");
605         }
606     }
607 
608     return skip;
609 }
610 
manual_PreCallValidateCreateImage(VkDevice device,const VkImageCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImage * pImage) const611 bool StatelessValidation::manual_PreCallValidateCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
612                                                             const VkAllocationCallbacks *pAllocator, VkImage *pImage) const {
613     bool skip = false;
614 
615     if (pCreateInfo != nullptr) {
616         // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
617         if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
618             // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
619             if (pCreateInfo->queueFamilyIndexCount <= 1) {
620                 skip |= LogError(device, "VUID-VkImageCreateInfo-sharingMode-00942",
621                                  "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
622                                  "pCreateInfo->queueFamilyIndexCount must be greater than 1.");
623             }
624 
625             // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
626             // queueFamilyIndexCount uint32_t values
627             if (pCreateInfo->pQueueFamilyIndices == nullptr) {
628                 skip |= LogError(device, "VUID-VkImageCreateInfo-sharingMode-00941",
629                                  "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
630                                  "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
631                                  "pCreateInfo->queueFamilyIndexCount uint32_t values.");
632             }
633         }
634 
635         skip |= ValidateGreaterThanZero(pCreateInfo->extent.width, "pCreateInfo->extent.width",
636                                         "VUID-VkImageCreateInfo-extent-00944", "vkCreateImage");
637         skip |= ValidateGreaterThanZero(pCreateInfo->extent.height, "pCreateInfo->extent.height",
638                                         "VUID-VkImageCreateInfo-extent-00945", "vkCreateImage");
639         skip |= ValidateGreaterThanZero(pCreateInfo->extent.depth, "pCreateInfo->extent.depth",
640                                         "VUID-VkImageCreateInfo-extent-00946", "vkCreateImage");
641 
642         skip |= ValidateGreaterThanZero(pCreateInfo->mipLevels, "pCreateInfo->mipLevels", "VUID-VkImageCreateInfo-mipLevels-00947",
643                                         "vkCreateImage");
644         skip |= ValidateGreaterThanZero(pCreateInfo->arrayLayers, "pCreateInfo->arrayLayers",
645                                         "VUID-VkImageCreateInfo-arrayLayers-00948", "vkCreateImage");
646 
647         // InitialLayout must be PREINITIALIZED or UNDEFINED
648         if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
649             (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
650             skip |= LogError(
651                 device, "VUID-VkImageCreateInfo-initialLayout-00993",
652                 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED.",
653                 string_VkImageLayout(pCreateInfo->initialLayout));
654         }
655 
656         // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
657         if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) &&
658             ((pCreateInfo->extent.height != 1) || (pCreateInfo->extent.depth != 1))) {
659             skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00956",
660                              "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both pCreateInfo->extent.height and "
661                              "pCreateInfo->extent.depth must be 1.");
662         }
663 
664         if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
665             if (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) {
666                 if (pCreateInfo->extent.width != pCreateInfo->extent.height) {
667                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00954",
668                                      "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
669                                      "pCreateInfo->extent.width (=%" PRIu32 ") and pCreateInfo->extent.height (=%" PRIu32
670                                      ") are not equal.",
671                                      pCreateInfo->extent.width, pCreateInfo->extent.height);
672                 }
673 
674                 if (pCreateInfo->arrayLayers < 6) {
675                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00954",
676                                      "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, but "
677                                      "pCreateInfo->arrayLayers (=%" PRIu32 ") is not greater than or equal to 6.",
678                                      pCreateInfo->arrayLayers);
679                 }
680             }
681 
682             if (pCreateInfo->extent.depth != 1) {
683                 skip |= LogError(
684                     device, "VUID-VkImageCreateInfo-imageType-00957",
685                     "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1.");
686             }
687         }
688 
689         // 3D image may have only 1 layer
690         if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
691             skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00961",
692                              "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1.");
693         }
694 
695         // If multi-sample, validate type, usage, tiling and mip levels.
696         if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
697             ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
698              (pCreateInfo->mipLevels != 1) || (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL))) {
699             skip |= LogError(device, "VUID-VkImageCreateInfo-samples-02257",
700                              "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips.");
701         }
702 
703         if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
704             VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
705                                              VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
706             // At least one of the legal attachment bits must be set
707             if (0 == (pCreateInfo->usage & legal_flags)) {
708                 skip |= LogError(device, "VUID-VkImageCreateInfo-usage-00966",
709                                  "vkCreateImage(): Transient attachment image without a compatible attachment flag set.");
710             }
711             // No flags other than the legal attachment bits may be set
712             legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
713             if (0 != (pCreateInfo->usage & ~legal_flags)) {
714                 skip |= LogError(device, "VUID-VkImageCreateInfo-usage-00963",
715                                  "vkCreateImage(): Transient attachment image with incompatible usage flags set.");
716             }
717         }
718 
719         // mipLevels must be less than or equal to the number of levels in the complete mipmap chain
720         uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
721         // Max mip levels is different for corner-sampled images vs normal images.
722         uint32_t maxMipLevels = (pCreateInfo->flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV) ? (uint32_t)(ceil(log2(maxDim)))
723                                                                                              : (uint32_t)(floor(log2(maxDim)) + 1);
724         if (maxDim > 0 && pCreateInfo->mipLevels > maxMipLevels) {
725             skip |=
726                 LogError(device, "VUID-VkImageCreateInfo-mipLevels-00958",
727                          "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
728                          "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1.");
729         }
730 
731         if ((pCreateInfo->flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT) && (pCreateInfo->imageType != VK_IMAGE_TYPE_3D)) {
732             skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00950",
733                              "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT but "
734                              "pCreateInfo->imageType is not VK_IMAGE_TYPE_3D.");
735         }
736 
737         if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && (!physical_device_features.sparseBinding)) {
738             skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00969",
739                              "vkCreateImage(): pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_BINDING_BIT, but the "
740                              "VkPhysicalDeviceFeatures::sparseBinding feature is disabled.");
741         }
742 
743         if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) && (!physical_device_features.sparseResidencyAliased)) {
744             skip |= LogError(
745                 device, "VUID-VkImageCreateInfo-flags-01924",
746                 "vkCreateImage(): the sparseResidencyAliased device feature is disabled: Images cannot be created with the "
747                 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT set.");
748         }
749 
750         // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
751         // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
752         if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
753             ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
754             skip |= LogError(device, "VUID-VkImageCreateInfo-flags-00987",
755                              "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
756                              "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT.");
757         }
758 
759         // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
760         if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
761             // Linear tiling is unsupported
762             if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
763                 skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-04121",
764                                  "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image "
765                                  "tiling of VK_IMAGE_TILING_LINEAR is not supported");
766             }
767 
768             // Sparse 1D image isn't valid
769             if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
770                 skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00970",
771                                  "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image.");
772             }
773 
774             // Sparse 2D image when device doesn't support it
775             if ((VK_FALSE == physical_device_features.sparseResidencyImage2D) && (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
776                 skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00971",
777                                  "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
778                                  "feature is not enabled on the device.");
779             }
780 
781             // Sparse 3D image when device doesn't support it
782             if ((VK_FALSE == physical_device_features.sparseResidencyImage3D) && (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
783                 skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00972",
784                                  "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
785                                  "feature is not enabled on the device.");
786             }
787 
788             // Multi-sample 2D image when device doesn't support it
789             if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
790                 if ((VK_FALSE == physical_device_features.sparseResidency2Samples) &&
791                     (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
792                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00973",
793                                      "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if "
794                                      "corresponding feature is not enabled on the device.");
795                 } else if ((VK_FALSE == physical_device_features.sparseResidency4Samples) &&
796                            (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
797                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00974",
798                                      "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if "
799                                      "corresponding feature is not enabled on the device.");
800                 } else if ((VK_FALSE == physical_device_features.sparseResidency8Samples) &&
801                            (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
802                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00975",
803                                      "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if "
804                                      "corresponding feature is not enabled on the device.");
805                 } else if ((VK_FALSE == physical_device_features.sparseResidency16Samples) &&
806                            (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
807                     skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-00976",
808                                      "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if "
809                                      "corresponding feature is not enabled on the device.");
810                 }
811             }
812         }
813 
814         if (pCreateInfo->usage & VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV) {
815             if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D) {
816                 skip |= LogError(device, "VUID-VkImageCreateInfo-imageType-02082",
817                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
818                                  "imageType must be VK_IMAGE_TYPE_2D.");
819             }
820             if (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) {
821                 skip |= LogError(device, "VUID-VkImageCreateInfo-samples-02083",
822                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
823                                  "samples must be VK_SAMPLE_COUNT_1_BIT.");
824             }
825             if (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) {
826                 skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-02084",
827                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV, "
828                                  "tiling must be VK_IMAGE_TILING_OPTIMAL.");
829             }
830         }
831 
832         if (pCreateInfo->flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV) {
833             if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D && pCreateInfo->imageType != VK_IMAGE_TYPE_3D) {
834                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02050",
835                                  "vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, "
836                                  "imageType must be VK_IMAGE_TYPE_2D or VK_IMAGE_TYPE_3D.");
837             }
838 
839             if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) || FormatIsDepthOrStencil(pCreateInfo->format)) {
840                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02051",
841                                  "vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV, "
842                                  "it must not also contain VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT and format must "
843                                  "not be a depth/stencil format.");
844             }
845 
846             if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D && (pCreateInfo->extent.width == 1 || pCreateInfo->extent.height == 1)) {
847                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02052",
848                                  "vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and "
849                                  "imageType is VK_IMAGE_TYPE_2D, extent.width and extent.height must be "
850                                  "greater than 1.");
851             } else if (pCreateInfo->imageType == VK_IMAGE_TYPE_3D &&
852                        (pCreateInfo->extent.width == 1 || pCreateInfo->extent.height == 1 || pCreateInfo->extent.depth == 1)) {
853                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02053",
854                                  "vkCreateImage: If flags contains VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and "
855                                  "imageType is VK_IMAGE_TYPE_3D, extent.width, extent.height, and extent.depth "
856                                  "must be greater than 1.");
857             }
858         }
859 
860         if (((pCreateInfo->flags & VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT) != 0) &&
861             (FormatHasDepth(pCreateInfo->format) == false)) {
862             skip |= LogError(device, "VUID-VkImageCreateInfo-flags-01533",
863                              "vkCreateImage(): if flags contain VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT the "
864                              "format must be a depth or depth/stencil format.");
865         }
866 
867         const auto image_stencil_struct = lvl_find_in_chain<VkImageStencilUsageCreateInfoEXT>(pCreateInfo->pNext);
868         if (image_stencil_struct != nullptr) {
869             if ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0) {
870                 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
871                 // No flags other than the legal attachment bits may be set
872                 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
873                 if ((image_stencil_struct->stencilUsage & ~legal_flags) != 0) {
874                     skip |= LogError(device, "VUID-VkImageStencilUsageCreateInfo-stencilUsage-02539",
875                                      "vkCreateImage(): in pNext chain, VkImageStencilUsageCreateInfo::stencilUsage includes "
876                                      "VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, it must not include bits other than "
877                                      "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT");
878                 }
879             }
880 
881             if (FormatIsDepthOrStencil(pCreateInfo->format)) {
882                 if ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) != 0) {
883                     if (pCreateInfo->extent.width > device_limits.maxFramebufferWidth) {
884                         skip |=
885                             LogError(device, "VUID-VkImageCreateInfo-Format-02536",
886                                      "vkCreateImage(): Depth-stencil image contains VkImageStencilUsageCreateInfo structure with "
887                                      "stencilUsage including VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT and image width exceeds device "
888                                      "maxFramebufferWidth");
889                     }
890 
891                     if (pCreateInfo->extent.height > device_limits.maxFramebufferHeight) {
892                         skip |=
893                             LogError(device, "VUID-VkImageCreateInfo-format-02537",
894                                      "vkCreateImage(): Depth-stencil image contains VkImageStencilUsageCreateInfo structure with "
895                                      "stencilUsage including VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT and image height exceeds device "
896                                      "maxFramebufferHeight");
897                     }
898                 }
899 
900                 if (!physical_device_features.shaderStorageImageMultisample &&
901                     ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_STORAGE_BIT) != 0) &&
902                     (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT)) {
903                     skip |=
904                         LogError(device, "VUID-VkImageCreateInfo-format-02538",
905                                  "vkCreateImage(): Depth-stencil image contains VkImageStencilUsageCreateInfo structure with "
906                                  "stencilUsage including VK_IMAGE_USAGE_STORAGE_BIT and the multisampled storage images feature is "
907                                  "not enabled, image samples must be VK_SAMPLE_COUNT_1_BIT");
908                 }
909 
910                 if (((pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0) &&
911                     ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0)) {
912                     skip |= LogError(
913                         device, "VUID-VkImageCreateInfo-format-02795",
914                         "vkCreateImage(): Depth-stencil image in which usage includes VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT "
915                         "contains VkImageStencilUsageCreateInfo structure, VkImageStencilUsageCreateInfo::stencilUsage must  "
916                         "also include VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT");
917                 } else if (((pCreateInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) &&
918                            ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)) {
919                     skip |= LogError(
920                         device, "VUID-VkImageCreateInfo-format-02796",
921                         "vkCreateImage(): Depth-stencil image in which usage does not include "
922                         "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT "
923                         "contains VkImageStencilUsageCreateInfo structure, VkImageStencilUsageCreateInfo::stencilUsage must  "
924                         "also not include VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT");
925                 }
926 
927                 if (((pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0) &&
928                     ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)) {
929                     skip |= LogError(
930                         device, "VUID-VkImageCreateInfo-format-02797",
931                         "vkCreateImage(): Depth-stencil image in which usage includes VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT "
932                         "contains VkImageStencilUsageCreateInfo structure, VkImageStencilUsageCreateInfo::stencilUsage must  "
933                         "also include VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT");
934                 } else if (((pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0) &&
935                            ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0)) {
936                     skip |= LogError(
937                         device, "VUID-VkImageCreateInfo-format-02798",
938                         "vkCreateImage(): Depth-stencil image in which usage does not include "
939                         "VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT "
940                         "contains VkImageStencilUsageCreateInfo structure, VkImageStencilUsageCreateInfo::stencilUsage must  "
941                         "also not include VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT");
942                 }
943             }
944         }
945 
946         if ((!physical_device_features.shaderStorageImageMultisample) && ((pCreateInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT) != 0) &&
947             (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT)) {
948             skip |= LogError(device, "VUID-VkImageCreateInfo-usage-00968",
949                              "vkCreateImage(): usage contains VK_IMAGE_USAGE_STORAGE_BIT and the multisampled storage images "
950                              "feature is not enabled, image samples must be VK_SAMPLE_COUNT_1_BIT");
951         }
952 
953         if (device_extensions.vk_ext_image_drm_format_modifier) {
954             const auto drm_format_mod_list = lvl_find_in_chain<VkImageDrmFormatModifierListCreateInfoEXT>(pCreateInfo->pNext);
955             const auto drm_format_mod_explict =
956                 lvl_find_in_chain<VkImageDrmFormatModifierExplicitCreateInfoEXT>(pCreateInfo->pNext);
957             if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
958                 if (((drm_format_mod_list != nullptr) && (drm_format_mod_explict != nullptr)) ||
959                     ((drm_format_mod_list == nullptr) && (drm_format_mod_explict == nullptr))) {
960                     skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-02261",
961                                      "vkCreateImage(): Tiling is VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT but pNext must have "
962                                      "either VkImageDrmFormatModifierListCreateInfoEXT or "
963                                      "VkImageDrmFormatModifierExplicitCreateInfoEXT in the pNext chain");
964                 }
965             } else if ((drm_format_mod_list != nullptr) || (drm_format_mod_explict != nullptr)) {
966                 skip |= LogError(device, "VUID-VkImageCreateInfo-pNext-02262",
967                                  "vkCreateImage(): Tiling is not VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT but there is a "
968                                  "VkImageDrmFormatModifierListCreateInfoEXT or VkImageDrmFormatModifierExplicitCreateInfoEXT "
969                                  "in the pNext chain");
970             }
971         }
972 
973         if (pCreateInfo->usage & VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT) {
974             if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D) {
975                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02557",
976                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT, "
977                                  "imageType must be VK_IMAGE_TYPE_2D.");
978             }
979             if (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) {
980                 skip |= LogError(device, "VUID-VkImageCreateInfo-samples-02558",
981                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT, "
982                                  "samples must be VK_SAMPLE_COUNT_1_BIT.");
983             }
984             if (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) {
985                 skip |= LogError(device, "VUID-VkImageCreateInfo-tiling-02084",
986                                  "vkCreateImage: if usage includes VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT, "
987                                  "tiling must be VK_IMAGE_TILING_OPTIMAL.");
988             }
989         }
990         if (pCreateInfo->flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT) {
991             if (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) {
992                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02565",
993                                  "vkCreateImage: if usage includes VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT, "
994                                  "tiling must be VK_IMAGE_TILING_OPTIMAL.");
995             }
996             if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D) {
997                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02566",
998                                  "vkCreateImage: if flags includes VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT, "
999                                  "imageType must be VK_IMAGE_TYPE_2D.");
1000             }
1001             if (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) {
1002                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02567",
1003                                  "vkCreateImage: if flags includes VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT, "
1004                                  "flags must not include VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT.");
1005             }
1006             if (pCreateInfo->mipLevels != 1) {
1007                 skip |= LogError(device, "VUID-VkImageCreateInfo-flags-02568",
1008                                  "vkCreateImage: if flags includes VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT, mipLevels (%d) must be 1.",
1009                                  pCreateInfo->mipLevels);
1010             }
1011         }
1012 
1013         const auto swapchain_create_info = lvl_find_in_chain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext);
1014         if (swapchain_create_info != nullptr) {
1015             if (swapchain_create_info->swapchain != VK_NULL_HANDLE) {
1016                 // All the following fall under the same VU that checks that the swapchain image uses parameters limited by the
1017                 // table in #swapchain-wsi-image-create-info. Breaking up into multiple checks allows for more useful information
1018                 // returned why this error occured. Check for matching Swapchain flags is done later in state tracking validation
1019                 const char *vuid = "VUID-VkImageSwapchainCreateInfoKHR-swapchain-00995";
1020                 const char *base_message = "vkCreateImage(): The image used for creating a presentable swapchain image";
1021 
1022                 if (pCreateInfo->imageType != VK_IMAGE_TYPE_2D) {
1023                     // also implicitly forces the check above that extent.depth is 1
1024                     skip |= LogError(device, vuid, "%s must have a imageType value VK_IMAGE_TYPE_2D instead of %s.", base_message,
1025                                      string_VkImageType(pCreateInfo->imageType));
1026                 }
1027                 if (pCreateInfo->mipLevels != 1) {
1028                     skip |= LogError(device, vuid, "%s must have a mipLevels value of 1 instead of %u.", base_message,
1029                                      pCreateInfo->mipLevels);
1030                 }
1031                 if (pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) {
1032                     skip |= LogError(device, vuid, "%s must have a samples value of VK_SAMPLE_COUNT_1_BIT instead of %s.",
1033                                      base_message, string_VkSampleCountFlagBits(pCreateInfo->samples));
1034                 }
1035                 if (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) {
1036                     skip |= LogError(device, vuid, "%s must have a tiling value of VK_IMAGE_TILING_OPTIMAL instead of %s.",
1037                                      base_message, string_VkImageTiling(pCreateInfo->tiling));
1038                 }
1039                 if (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) {
1040                     skip |= LogError(device, vuid, "%s must have a initialLayout value of VK_IMAGE_LAYOUT_UNDEFINED instead of %s.",
1041                                      base_message, string_VkImageLayout(pCreateInfo->initialLayout));
1042                 }
1043                 const VkImageCreateFlags valid_flags =
1044                     (VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT | VK_IMAGE_CREATE_PROTECTED_BIT |
1045                      VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR);
1046                 if ((pCreateInfo->flags & ~valid_flags) != 0) {
1047                     skip |= LogError(device, vuid, "%s flags are %" PRIu32 "and must only have valid flags set.", base_message,
1048                                      pCreateInfo->flags);
1049                 }
1050             }
1051         }
1052     }
1053 
1054     return skip;
1055 }
1056 
manual_PreCallValidateCreateImageView(VkDevice device,const VkImageViewCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkImageView * pView) const1057 bool StatelessValidation::manual_PreCallValidateCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
1058                                                                 const VkAllocationCallbacks *pAllocator, VkImageView *pView) const {
1059     bool skip = false;
1060 
1061     if (pCreateInfo != nullptr) {
1062         // Validate feature set if using CUBE_ARRAY
1063         if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) && (physical_device_features.imageCubeArray == false)) {
1064             skip |= LogError(pCreateInfo->image, "VUID-VkImageViewCreateInfo-viewType-01004",
1065                              "vkCreateImageView(): pCreateInfo->viewType can't be VK_IMAGE_VIEW_TYPE_CUBE_ARRAY without "
1066                              "enabling the imageCubeArray feature.");
1067         }
1068 
1069         if (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS) {
1070             if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE && pCreateInfo->subresourceRange.layerCount != 6) {
1071                 skip |= LogError(device, "VUID-VkImageViewCreateInfo-viewType-02960",
1072                                  "vkCreateImageView(): subresourceRange.layerCount (%d) must be 6 or VK_REMAINING_ARRAY_LAYERS.",
1073                                  pCreateInfo->subresourceRange.layerCount);
1074             }
1075             if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY && (pCreateInfo->subresourceRange.layerCount % 6) != 0) {
1076                 skip |= LogError(
1077                     device, "VUID-VkImageViewCreateInfo-viewType-02961",
1078                     "vkCreateImageView(): subresourceRange.layerCount (%d) must be a multiple of 6 or VK_REMAINING_ARRAY_LAYERS.",
1079                     pCreateInfo->subresourceRange.layerCount);
1080             }
1081         }
1082 
1083         auto astc_decode_mode = lvl_find_in_chain<VkImageViewASTCDecodeModeEXT>(pCreateInfo->pNext);
1084         if ((device_extensions.vk_ext_astc_decode_mode) && (astc_decode_mode != nullptr)) {
1085             if ((astc_decode_mode->decodeMode != VK_FORMAT_R16G16B16A16_SFLOAT) &&
1086                 (astc_decode_mode->decodeMode != VK_FORMAT_R8G8B8A8_UNORM) &&
1087                 (astc_decode_mode->decodeMode != VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)) {
1088                 skip |= LogError(device, "VUID-VkImageViewASTCDecodeModeEXT-decodeMode-02230",
1089                                  "vkCreateImageView(): VkImageViewASTCDecodeModeEXT::decodeMode must be "
1090                                  "VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R8G8B8A8_UNORM, or VK_FORMAT_E5B9G9R9_UFLOAT_PACK32.");
1091             }
1092             if (FormatIsCompressed_ASTC(pCreateInfo->format) == false) {
1093                 skip |= LogError(device, "VUID-VkImageViewASTCDecodeModeEXT-format-04084",
1094                                  "vkCreateImageView(): is using a VkImageViewASTCDecodeModeEXT but the image view format is %s and "
1095                                  "not an ASTC format.",
1096                                  string_VkFormat(pCreateInfo->format));
1097             }
1098         }
1099 
1100         auto ycbcr_conversion = lvl_find_in_chain<VkSamplerYcbcrConversionInfo>(pCreateInfo->pNext);
1101         if (ycbcr_conversion != nullptr) {
1102             if (ycbcr_conversion->conversion != VK_NULL_HANDLE) {
1103                 if (IsIdentitySwizzle(pCreateInfo->components) == false) {
1104                     skip |= LogError(
1105                         device, "VUID-VkImageViewCreateInfo-pNext-01970",
1106                         "vkCreateImageView(): If there is a VkSamplerYcbcrConversion, the imageView must "
1107                         "be created with the identity swizzle. Here are the actual swizzle values:\n"
1108                         "r swizzle = %s\n"
1109                         "g swizzle = %s\n"
1110                         "b swizzle = %s\n"
1111                         "a swizzle = %s\n",
1112                         string_VkComponentSwizzle(pCreateInfo->components.r), string_VkComponentSwizzle(pCreateInfo->components.g),
1113                         string_VkComponentSwizzle(pCreateInfo->components.b), string_VkComponentSwizzle(pCreateInfo->components.a));
1114                 }
1115             }
1116         }
1117     }
1118     return skip;
1119 }
1120 
manual_PreCallValidateViewport(const VkViewport & viewport,const char * fn_name,const ParameterName & parameter_name,VkCommandBuffer object) const1121 bool StatelessValidation::manual_PreCallValidateViewport(const VkViewport &viewport, const char *fn_name,
1122                                                          const ParameterName &parameter_name, VkCommandBuffer object) const {
1123     bool skip = false;
1124 
1125     // Note: for numerical correctness
1126     //       - float comparisons should expect NaN (comparison always false).
1127     //       - VkPhysicalDeviceLimits::maxViewportDimensions is uint32_t, not float -> careful.
1128 
1129     const auto f_lte_u32_exact = [](const float v1_f, const uint32_t v2_u32) {
1130         if (std::isnan(v1_f)) return false;
1131         if (v1_f <= 0.0f) return true;
1132 
1133         float intpart;
1134         const float fract = modff(v1_f, &intpart);
1135 
1136         assert(std::numeric_limits<float>::radix == 2);
1137         const float u32_max_plus1 = ldexpf(1.0f, 32);  // hopefully exact
1138         if (intpart >= u32_max_plus1) return false;
1139 
1140         uint32_t v1_u32 = static_cast<uint32_t>(intpart);
1141         if (v1_u32 < v2_u32)
1142             return true;
1143         else if (v1_u32 == v2_u32 && fract == 0.0f)
1144             return true;
1145         else
1146             return false;
1147     };
1148 
1149     const auto f_lte_u32_direct = [](const float v1_f, const uint32_t v2_u32) {
1150         const float v2_f = static_cast<float>(v2_u32);  // not accurate for > radix^digits; and undefined rounding mode
1151         return (v1_f <= v2_f);
1152     };
1153 
1154     // width
1155     bool width_healthy = true;
1156     const auto max_w = device_limits.maxViewportDimensions[0];
1157 
1158     if (!(viewport.width > 0.0f)) {
1159         width_healthy = false;
1160         skip |= LogError(object, "VUID-VkViewport-width-01770", "%s: %s.width (=%f) is not greater than 0.0.", fn_name,
1161                          parameter_name.get_name().c_str(), viewport.width);
1162     } else if (!(f_lte_u32_exact(viewport.width, max_w) || f_lte_u32_direct(viewport.width, max_w))) {
1163         width_healthy = false;
1164         skip |= LogError(object, "VUID-VkViewport-width-01771",
1165                          "%s: %s.width (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[0] (=%" PRIu32 ").", fn_name,
1166                          parameter_name.get_name().c_str(), viewport.width, max_w);
1167     }
1168 
1169     // height
1170     bool height_healthy = true;
1171     const bool negative_height_enabled = device_extensions.vk_khr_maintenance1 || device_extensions.vk_amd_negative_viewport_height;
1172     const auto max_h = device_limits.maxViewportDimensions[1];
1173 
1174     if (!negative_height_enabled && !(viewport.height > 0.0f)) {
1175         height_healthy = false;
1176         skip |= LogError(object, "VUID-VkViewport-height-01772", "%s: %s.height (=%f) is not greater 0.0.", fn_name,
1177                          parameter_name.get_name().c_str(), viewport.height);
1178     } else if (!(f_lte_u32_exact(fabsf(viewport.height), max_h) || f_lte_u32_direct(fabsf(viewport.height), max_h))) {
1179         height_healthy = false;
1180 
1181         skip |= LogError(object, "VUID-VkViewport-height-01773",
1182                          "%s: Absolute value of %s.height (=%f) exceeds VkPhysicalDeviceLimits::maxViewportDimensions[1] (=%" PRIu32
1183                          ").",
1184                          fn_name, parameter_name.get_name().c_str(), viewport.height, max_h);
1185     }
1186 
1187     // x
1188     bool x_healthy = true;
1189     if (!(viewport.x >= device_limits.viewportBoundsRange[0])) {
1190         x_healthy = false;
1191         skip |= LogError(object, "VUID-VkViewport-x-01774",
1192                          "%s: %s.x (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f).", fn_name,
1193                          parameter_name.get_name().c_str(), viewport.x, device_limits.viewportBoundsRange[0]);
1194     }
1195 
1196     // x + width
1197     if (x_healthy && width_healthy) {
1198         const float right_bound = viewport.x + viewport.width;
1199         if (!(right_bound <= device_limits.viewportBoundsRange[1])) {
1200             skip |= LogError(
1201                 object, "VUID-VkViewport-x-01232",
1202                 "%s: %s.x + %s.width (=%f + %f = %f) is greater than VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f).",
1203                 fn_name, parameter_name.get_name().c_str(), parameter_name.get_name().c_str(), viewport.x, viewport.width,
1204                 right_bound, device_limits.viewportBoundsRange[1]);
1205         }
1206     }
1207 
1208     // y
1209     bool y_healthy = true;
1210     if (!(viewport.y >= device_limits.viewportBoundsRange[0])) {
1211         y_healthy = false;
1212         skip |= LogError(object, "VUID-VkViewport-y-01775",
1213                          "%s: %s.y (=%f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f).", fn_name,
1214                          parameter_name.get_name().c_str(), viewport.y, device_limits.viewportBoundsRange[0]);
1215     } else if (negative_height_enabled && !(viewport.y <= device_limits.viewportBoundsRange[1])) {
1216         y_healthy = false;
1217         skip |= LogError(object, "VUID-VkViewport-y-01776",
1218                          "%s: %s.y (=%f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f).", fn_name,
1219                          parameter_name.get_name().c_str(), viewport.y, device_limits.viewportBoundsRange[1]);
1220     }
1221 
1222     // y + height
1223     if (y_healthy && height_healthy) {
1224         const float boundary = viewport.y + viewport.height;
1225 
1226         if (!(boundary <= device_limits.viewportBoundsRange[1])) {
1227             skip |= LogError(object, "VUID-VkViewport-y-01233",
1228                              "%s: %s.y + %s.height (=%f + %f = %f) exceeds VkPhysicalDeviceLimits::viewportBoundsRange[1] (=%f).",
1229                              fn_name, parameter_name.get_name().c_str(), parameter_name.get_name().c_str(), viewport.y,
1230                              viewport.height, boundary, device_limits.viewportBoundsRange[1]);
1231         } else if (negative_height_enabled && !(boundary >= device_limits.viewportBoundsRange[0])) {
1232             skip |=
1233                 LogError(object, "VUID-VkViewport-y-01777",
1234                          "%s: %s.y + %s.height (=%f + %f = %f) is less than VkPhysicalDeviceLimits::viewportBoundsRange[0] (=%f).",
1235                          fn_name, parameter_name.get_name().c_str(), parameter_name.get_name().c_str(), viewport.y, viewport.height,
1236                          boundary, device_limits.viewportBoundsRange[0]);
1237         }
1238     }
1239 
1240     if (!device_extensions.vk_ext_depth_range_unrestricted) {
1241         // minDepth
1242         if (!(viewport.minDepth >= 0.0) || !(viewport.minDepth <= 1.0)) {
1243             skip |= LogError(object, "VUID-VkViewport-minDepth-01234",
1244 
1245                              "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.minDepth (=%f) is not within the "
1246                              "[0.0, 1.0] range.",
1247                              fn_name, parameter_name.get_name().c_str(), viewport.minDepth);
1248         }
1249 
1250         // maxDepth
1251         if (!(viewport.maxDepth >= 0.0) || !(viewport.maxDepth <= 1.0)) {
1252             skip |= LogError(object, "VUID-VkViewport-maxDepth-01235",
1253 
1254                              "%s: VK_EXT_depth_range_unrestricted extension is not enabled and %s.maxDepth (=%f) is not within the "
1255                              "[0.0, 1.0] range.",
1256                              fn_name, parameter_name.get_name().c_str(), viewport.maxDepth);
1257         }
1258     }
1259 
1260     return skip;
1261 }
1262 
1263 struct SampleOrderInfo {
1264     VkShadingRatePaletteEntryNV shadingRate;
1265     uint32_t width;
1266     uint32_t height;
1267 };
1268 
1269 // All palette entries with more than one pixel per fragment
1270 static SampleOrderInfo sampleOrderInfos[] = {
1271     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_1X2_PIXELS_NV, 1, 2},
1272     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_2X1_PIXELS_NV, 2, 1},
1273     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_2X2_PIXELS_NV, 2, 2},
1274     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_4X2_PIXELS_NV, 4, 2},
1275     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_2X4_PIXELS_NV, 2, 4},
1276     {VK_SHADING_RATE_PALETTE_ENTRY_1_INVOCATION_PER_4X4_PIXELS_NV, 4, 4},
1277 };
1278 
ValidateCoarseSampleOrderCustomNV(const VkCoarseSampleOrderCustomNV * order) const1279 bool StatelessValidation::ValidateCoarseSampleOrderCustomNV(const VkCoarseSampleOrderCustomNV *order) const {
1280     bool skip = false;
1281 
1282     SampleOrderInfo *sampleOrderInfo;
1283     uint32_t infoIdx = 0;
1284     for (sampleOrderInfo = nullptr; infoIdx < ARRAY_SIZE(sampleOrderInfos); ++infoIdx) {
1285         if (sampleOrderInfos[infoIdx].shadingRate == order->shadingRate) {
1286             sampleOrderInfo = &sampleOrderInfos[infoIdx];
1287             break;
1288         }
1289     }
1290 
1291     if (sampleOrderInfo == nullptr) {
1292         skip |= LogError(device, "VUID-VkCoarseSampleOrderCustomNV-shadingRate-02073",
1293                          "VkCoarseSampleOrderCustomNV shadingRate must be a shading rate "
1294                          "that generates fragments with more than one pixel.");
1295         return skip;
1296     }
1297 
1298     if (order->sampleCount == 0 || (order->sampleCount & (order->sampleCount - 1)) ||
1299         !(order->sampleCount & device_limits.framebufferNoAttachmentsSampleCounts)) {
1300         skip |= LogError(device, "VUID-VkCoarseSampleOrderCustomNV-sampleCount-02074",
1301                          "VkCoarseSampleOrderCustomNV sampleCount (=%" PRIu32
1302                          ") must "
1303                          "correspond to a sample count enumerated in VkSampleCountFlags whose corresponding bit "
1304                          "is set in framebufferNoAttachmentsSampleCounts.",
1305                          order->sampleCount);
1306     }
1307 
1308     if (order->sampleLocationCount != order->sampleCount * sampleOrderInfo->width * sampleOrderInfo->height) {
1309         skip |= LogError(device, "VUID-VkCoarseSampleOrderCustomNV-sampleLocationCount-02075",
1310                          "VkCoarseSampleOrderCustomNV sampleLocationCount (=%" PRIu32
1311                          ") must "
1312                          "be equal to the product of sampleCount (=%" PRIu32
1313                          "), the fragment width for shadingRate "
1314                          "(=%" PRIu32 "), and the fragment height for shadingRate (=%" PRIu32 ").",
1315                          order->sampleLocationCount, order->sampleCount, sampleOrderInfo->width, sampleOrderInfo->height);
1316     }
1317 
1318     if (order->sampleLocationCount > phys_dev_ext_props.shading_rate_image_props.shadingRateMaxCoarseSamples) {
1319         skip |= LogError(
1320             device, "VUID-VkCoarseSampleOrderCustomNV-sampleLocationCount-02076",
1321             "VkCoarseSampleOrderCustomNV sampleLocationCount (=%" PRIu32
1322             ") must "
1323             "be less than or equal to VkPhysicalDeviceShadingRateImagePropertiesNV shadingRateMaxCoarseSamples (=%" PRIu32 ").",
1324             order->sampleLocationCount, phys_dev_ext_props.shading_rate_image_props.shadingRateMaxCoarseSamples);
1325     }
1326 
1327     // Accumulate a bitmask tracking which (x,y,sample) tuples are seen. Expect
1328     // the first width*height*sampleCount bits to all be set. Note: There is no
1329     // guarantee that 64 bits is enough, but practically it's unlikely for an
1330     // implementation to support more than 32 bits for samplemask.
1331     assert(phys_dev_ext_props.shading_rate_image_props.shadingRateMaxCoarseSamples <= 64);
1332     uint64_t sampleLocationsMask = 0;
1333     for (uint32_t i = 0; i < order->sampleLocationCount; ++i) {
1334         const VkCoarseSampleLocationNV *sampleLoc = &order->pSampleLocations[i];
1335         if (sampleLoc->pixelX >= sampleOrderInfo->width) {
1336             skip |= LogError(device, "VUID-VkCoarseSampleLocationNV-pixelX-02078",
1337                              "pixelX must be less than the width (in pixels) of the fragment.");
1338         }
1339         if (sampleLoc->pixelY >= sampleOrderInfo->height) {
1340             skip |= LogError(device, "VUID-VkCoarseSampleLocationNV-pixelY-02079",
1341                              "pixelY must be less than the height (in pixels) of the fragment.");
1342         }
1343         if (sampleLoc->sample >= order->sampleCount) {
1344             skip |= LogError(device, "VUID-VkCoarseSampleLocationNV-sample-02080",
1345                              "sample must be less than the number of coverage samples in each pixel belonging to the fragment.");
1346         }
1347         uint32_t idx = sampleLoc->sample + order->sampleCount * (sampleLoc->pixelX + sampleOrderInfo->width * sampleLoc->pixelY);
1348         sampleLocationsMask |= 1ULL << idx;
1349     }
1350 
1351     uint64_t expectedMask = (order->sampleLocationCount == 64) ? ~0ULL : ((1ULL << order->sampleLocationCount) - 1);
1352     if (sampleLocationsMask != expectedMask) {
1353         skip |= LogError(
1354             device, "VUID-VkCoarseSampleOrderCustomNV-pSampleLocations-02077",
1355             "The array pSampleLocations must contain exactly one entry for "
1356             "every combination of valid values for pixelX, pixelY, and sample in the structure VkCoarseSampleOrderCustomNV.");
1357     }
1358 
1359     return skip;
1360 }
1361 
manual_PreCallValidateCreateGraphicsPipelines(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkGraphicsPipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const1362 bool StatelessValidation::manual_PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache,
1363                                                                         uint32_t createInfoCount,
1364                                                                         const VkGraphicsPipelineCreateInfo *pCreateInfos,
1365                                                                         const VkAllocationCallbacks *pAllocator,
1366                                                                         VkPipeline *pPipelines) const {
1367     bool skip = false;
1368 
1369     if (pCreateInfos != nullptr) {
1370         for (uint32_t i = 0; i < createInfoCount; ++i) {
1371             bool has_dynamic_viewport = false;
1372             bool has_dynamic_scissor = false;
1373             bool has_dynamic_line_width = false;
1374             bool has_dynamic_depth_bias = false;
1375             bool has_dynamic_blend_constant = false;
1376             bool has_dynamic_depth_bounds = false;
1377             bool has_dynamic_stencil_compare = false;
1378             bool has_dynamic_stencil_write = false;
1379             bool has_dynamic_stencil_reference = false;
1380             bool has_dynamic_viewport_w_scaling_nv = false;
1381             bool has_dynamic_discard_rectangle_ext = false;
1382             bool has_dynamic_sample_locations_ext = false;
1383             bool has_dynamic_exclusive_scissor_nv = false;
1384             bool has_dynamic_shading_rate_palette_nv = false;
1385             bool has_dynamic_viewport_course_sample_order_nv = false;
1386             bool has_dynamic_line_stipple = false;
1387             bool has_dynamic_cull_mode = false;
1388             bool has_dynamic_front_face = false;
1389             bool has_dynamic_primitive_topology = false;
1390             bool has_dynamic_viewport_with_count = false;
1391             bool has_dynamic_scissor_with_count = false;
1392             bool has_dynamic_vertex_input_binding_stride = false;
1393             bool has_dynamic_depth_test_enable = false;
1394             bool has_dynamic_depth_write_enable = false;
1395             bool has_dynamic_depth_compare_op = false;
1396             bool has_dynamic_depth_bounds_test_enable = false;
1397             bool has_dynamic_stencil_test_enable = false;
1398             bool has_dynamic_stencil_op = false;
1399             if (pCreateInfos[i].pDynamicState != nullptr) {
1400                 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1401                 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1402                     const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1403                     if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) {
1404                         if (has_dynamic_viewport == true) {
1405                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1406                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VIEWPORT was listed twice in the "
1407                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1408                                              i);
1409                         }
1410                         has_dynamic_viewport = true;
1411                     }
1412                     if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) {
1413                         if (has_dynamic_scissor == true) {
1414                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1415                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_SCISSOR was listed twice in the "
1416                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1417                                              i);
1418                         }
1419                         has_dynamic_scissor = true;
1420                     }
1421                     if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) {
1422                         if (has_dynamic_line_width == true) {
1423                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1424                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_LINE_WIDTH was listed twice in the "
1425                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1426                                              i);
1427                         }
1428                         has_dynamic_line_width = true;
1429                     }
1430                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_BIAS) {
1431                         if (has_dynamic_depth_bias == true) {
1432                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1433                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_BIAS was listed twice in the "
1434                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1435                                              i);
1436                         }
1437                         has_dynamic_depth_bias = true;
1438                     }
1439                     if (dynamic_state == VK_DYNAMIC_STATE_BLEND_CONSTANTS) {
1440                         if (has_dynamic_blend_constant == true) {
1441                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1442                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_BLEND_CONSTANTS was listed twice in the "
1443                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1444                                              i);
1445                         }
1446                         has_dynamic_blend_constant = true;
1447                     }
1448                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_BOUNDS) {
1449                         if (has_dynamic_depth_bounds == true) {
1450                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1451                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_BOUNDS was listed twice in the "
1452                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1453                                              i);
1454                         }
1455                         has_dynamic_depth_bounds = true;
1456                     }
1457                     if (dynamic_state == VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK) {
1458                         if (has_dynamic_stencil_compare == true) {
1459                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1460                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK was listed twice in "
1461                                              "the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1462                                              i);
1463                         }
1464                         has_dynamic_stencil_compare = true;
1465                     }
1466                     if (dynamic_state == VK_DYNAMIC_STATE_STENCIL_WRITE_MASK) {
1467                         if (has_dynamic_stencil_write == true) {
1468                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1469                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_STENCIL_WRITE_MASK was listed twice in "
1470                                              "the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1471                                              i);
1472                         }
1473                         has_dynamic_stencil_write = true;
1474                     }
1475                     if (dynamic_state == VK_DYNAMIC_STATE_STENCIL_REFERENCE) {
1476                         if (has_dynamic_stencil_reference == true) {
1477                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1478                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_STENCIL_REFERENCE was listed twice in "
1479                                              "the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1480                                              i);
1481                         }
1482                         has_dynamic_stencil_reference = true;
1483                     }
1484                     if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) {
1485                         if (has_dynamic_viewport_w_scaling_nv == true) {
1486                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1487                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV was listed twice "
1488                                              "in the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1489                                              i);
1490                         }
1491                         has_dynamic_viewport_w_scaling_nv = true;
1492                     }
1493                     if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) {
1494                         if (has_dynamic_discard_rectangle_ext == true) {
1495                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1496                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT was listed twice "
1497                                              "in the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1498                                              i);
1499                         }
1500                         has_dynamic_discard_rectangle_ext = true;
1501                     }
1502                     if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) {
1503                         if (has_dynamic_sample_locations_ext == true) {
1504                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1505                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT was listed twice in "
1506                                              "the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1507                                              i);
1508                         }
1509                         has_dynamic_sample_locations_ext = true;
1510                     }
1511                     if (dynamic_state == VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV) {
1512                         if (has_dynamic_exclusive_scissor_nv == true) {
1513                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1514                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV was listed twice in "
1515                                              "the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1516                                              i);
1517                         }
1518                         has_dynamic_exclusive_scissor_nv = true;
1519                     }
1520                     if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV) {
1521                         if (has_dynamic_shading_rate_palette_nv == true) {
1522                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1523                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV was "
1524                                              "listed twice in the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1525                                              i);
1526                         }
1527                         has_dynamic_shading_rate_palette_nv = true;
1528                     }
1529                     if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV) {
1530                         if (has_dynamic_viewport_course_sample_order_nv == true) {
1531                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1532                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV was "
1533                                              "listed twice in the pCreateInfos[%d].pDynamicState->pDynamicStates array",
1534                                              i);
1535                         }
1536                         has_dynamic_viewport_course_sample_order_nv = true;
1537                     }
1538                     if (dynamic_state == VK_DYNAMIC_STATE_LINE_STIPPLE_EXT) {
1539                         if (has_dynamic_line_stipple == true) {
1540                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1541                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_LINE_STIPPLE_EXT was listed twice in the "
1542                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1543                                              i);
1544                         }
1545                         has_dynamic_line_stipple = true;
1546                     }
1547                     if (dynamic_state == VK_DYNAMIC_STATE_CULL_MODE_EXT) {
1548                         if (has_dynamic_cull_mode) {
1549                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1550                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_CULL_MODE_EXT was listed twice in the "
1551                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1552                                              i);
1553                         }
1554                         has_dynamic_cull_mode = true;
1555                     }
1556                     if (dynamic_state == VK_DYNAMIC_STATE_FRONT_FACE_EXT) {
1557                         if (has_dynamic_front_face) {
1558                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1559                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_FRONT_FACE_EXT was listed twice in the "
1560                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1561                                              i);
1562                         }
1563                         has_dynamic_front_face = true;
1564                     }
1565                     if (dynamic_state == VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT) {
1566                         if (has_dynamic_primitive_topology) {
1567                             skip |= LogError(
1568                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1569                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT was listed twice in the "
1570                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1571                                 i);
1572                         }
1573                         has_dynamic_primitive_topology = true;
1574                     }
1575                     if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) {
1576                         if (has_dynamic_viewport_with_count) {
1577                             skip |= LogError(
1578                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1579                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT was listed twice in the "
1580                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1581                                 i);
1582                         }
1583                         has_dynamic_viewport_with_count = true;
1584                     }
1585                     if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT) {
1586                         if (has_dynamic_scissor_with_count) {
1587                             skip |= LogError(
1588                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1589                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT was listed twice in the "
1590                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1591                                 i);
1592                         }
1593                         has_dynamic_scissor_with_count = true;
1594                     }
1595                     if (dynamic_state == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
1596                         if (has_dynamic_vertex_input_binding_stride) {
1597                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1598                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT was "
1599                                              "listed twice in the "
1600                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1601                                              i);
1602                         }
1603                         has_dynamic_vertex_input_binding_stride = true;
1604                     }
1605                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT) {
1606                         if (has_dynamic_depth_test_enable) {
1607                             skip |= LogError(
1608                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1609                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT was listed twice in the "
1610                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1611                                 i);
1612                         }
1613                         has_dynamic_depth_test_enable = true;
1614                     }
1615                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT) {
1616                         if (has_dynamic_depth_write_enable) {
1617                             skip |= LogError(
1618                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1619                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT was listed twice in the "
1620                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1621                                 i);
1622                         }
1623                         has_dynamic_depth_write_enable = true;
1624                     }
1625                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT) {
1626                         if (has_dynamic_depth_compare_op) {
1627                             skip |=
1628                                 LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1629                                          "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT was listed twice in the "
1630                                          "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1631                                          i);
1632                         }
1633                         has_dynamic_depth_compare_op = true;
1634                     }
1635                     if (dynamic_state == VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT) {
1636                         if (has_dynamic_depth_bounds_test_enable) {
1637                             skip |= LogError(
1638                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1639                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT was listed twice in the "
1640                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1641                                 i);
1642                         }
1643                         has_dynamic_depth_bounds_test_enable = true;
1644                     }
1645                     if (dynamic_state == VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT) {
1646                         if (has_dynamic_stencil_test_enable) {
1647                             skip |= LogError(
1648                                 device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1649                                 "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT was listed twice in the "
1650                                 "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1651                                 i);
1652                         }
1653                         has_dynamic_stencil_test_enable = true;
1654                     }
1655                     if (dynamic_state == VK_DYNAMIC_STATE_STENCIL_OP_EXT) {
1656                         if (has_dynamic_stencil_op) {
1657                             skip |= LogError(device, "VUID-VkPipelineDynamicStateCreateInfo-pDynamicStates-01442",
1658                                              "vkCreateGraphicsPipelines: VK_DYNAMIC_STATE_STENCIL_OP_EXT was listed twice in the "
1659                                              "pCreateInfos[%d].pDynamicState->pDynamicStates array",
1660                                              i);
1661                         }
1662                         has_dynamic_stencil_op = true;
1663                     }
1664                 }
1665             }
1666 
1667             auto feedback_struct = lvl_find_in_chain<VkPipelineCreationFeedbackCreateInfoEXT>(pCreateInfos[i].pNext);
1668             if ((feedback_struct != nullptr) &&
1669                 (feedback_struct->pipelineStageCreationFeedbackCount != pCreateInfos[i].stageCount)) {
1670                 skip |= LogError(device, "VUID-VkPipelineCreationFeedbackCreateInfoEXT-pipelineStageCreationFeedbackCount-02668",
1671                                  "vkCreateGraphicsPipelines(): in pCreateInfo[%" PRIu32
1672                                  "], VkPipelineCreationFeedbackEXT::pipelineStageCreationFeedbackCount"
1673                                  "(=%" PRIu32 ") must equal VkGraphicsPipelineCreateInfo::stageCount(=%" PRIu32 ").",
1674                                  i, feedback_struct->pipelineStageCreationFeedbackCount, pCreateInfos[i].stageCount);
1675             }
1676 
1677             // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1678 
1679             // Collect active stages and other information
1680             // Only want to loop through pStages once
1681             uint32_t active_shaders = 0;
1682             bool has_eval = false;
1683             bool has_control = false;
1684             if (pCreateInfos[i].pStages != nullptr) {
1685                 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1686                     active_shaders |= pCreateInfos[i].pStages[stage_index].stage;
1687 
1688                     if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1689                         has_control = true;
1690                     } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1691                         has_eval = true;
1692                     }
1693 
1694                     skip |= validate_string(
1695                         "vkCreateGraphicsPipelines",
1696                         ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, stage_index}),
1697                         "VUID-VkGraphicsPipelineCreateInfo-pStages-parameter", pCreateInfos[i].pStages[stage_index].pName);
1698                 }
1699             }
1700 
1701             if ((active_shaders & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) &&
1702                 (active_shaders & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) && (pCreateInfos[i].pTessellationState != nullptr)) {
1703                 skip |= validate_struct_type("vkCreateGraphicsPipelines", "pCreateInfos[i].pTessellationState",
1704                                              "VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO",
1705                                              pCreateInfos[i].pTessellationState,
1706                                              VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, false, kVUIDUndefined,
1707                                              "VUID-VkPipelineTessellationStateCreateInfo-sType-sType");
1708 
1709                 const VkStructureType allowed_structs_VkPipelineTessellationStateCreateInfo[] = {
1710                     VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO};
1711 
1712                 skip |= validate_struct_pnext("vkCreateGraphicsPipelines", "pCreateInfos[i].pTessellationState->pNext",
1713                                               "VkPipelineTessellationDomainOriginStateCreateInfo",
1714                                               pCreateInfos[i].pTessellationState->pNext,
1715                                               ARRAY_SIZE(allowed_structs_VkPipelineTessellationStateCreateInfo),
1716                                               allowed_structs_VkPipelineTessellationStateCreateInfo, GeneratedVulkanHeaderVersion,
1717                                               "VUID-VkPipelineTessellationStateCreateInfo-pNext-pNext",
1718                                               "VUID-VkPipelineTessellationStateCreateInfo-sType-unique");
1719 
1720                 skip |= validate_reserved_flags("vkCreateGraphicsPipelines", "pCreateInfos[i].pTessellationState->flags",
1721                                                 pCreateInfos[i].pTessellationState->flags,
1722                                                 "VUID-VkPipelineTessellationStateCreateInfo-flags-zerobitmask");
1723             }
1724 
1725             if (!(active_shaders & VK_SHADER_STAGE_MESH_BIT_NV) && (pCreateInfos[i].pInputAssemblyState != nullptr)) {
1726                 skip |= validate_struct_type("vkCreateGraphicsPipelines", "pCreateInfos[i].pInputAssemblyState",
1727                                              "VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO",
1728                                              pCreateInfos[i].pInputAssemblyState,
1729                                              VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, false, kVUIDUndefined,
1730                                              "VUID-VkPipelineInputAssemblyStateCreateInfo-sType-sType");
1731 
1732                 skip |= validate_struct_pnext("vkCreateGraphicsPipelines", "pCreateInfos[i].pInputAssemblyState->pNext", NULL,
1733                                               pCreateInfos[i].pInputAssemblyState->pNext, 0, NULL, GeneratedVulkanHeaderVersion,
1734                                               "VUID-VkPipelineInputAssemblyStateCreateInfo-pNext-pNext", nullptr);
1735 
1736                 skip |= validate_reserved_flags("vkCreateGraphicsPipelines", "pCreateInfos[i].pInputAssemblyState->flags",
1737                                                 pCreateInfos[i].pInputAssemblyState->flags,
1738                                                 "VUID-VkPipelineInputAssemblyStateCreateInfo-flags-zerobitmask");
1739 
1740                 skip |= validate_ranged_enum("vkCreateGraphicsPipelines", "pCreateInfos[i].pInputAssemblyState->topology",
1741                                              "VkPrimitiveTopology", AllVkPrimitiveTopologyEnums,
1742                                              pCreateInfos[i].pInputAssemblyState->topology,
1743                                              "VUID-VkPipelineInputAssemblyStateCreateInfo-topology-parameter");
1744 
1745                 skip |= validate_bool32("vkCreateGraphicsPipelines", "pCreateInfos[i].pInputAssemblyState->primitiveRestartEnable",
1746                                         pCreateInfos[i].pInputAssemblyState->primitiveRestartEnable);
1747             }
1748 
1749             if (!(active_shaders & VK_SHADER_STAGE_MESH_BIT_NV) && (pCreateInfos[i].pVertexInputState != nullptr)) {
1750                 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1751 
1752                 if (pCreateInfos[i].pVertexInputState->flags != 0) {
1753                     skip |= LogError(device, "VUID-VkPipelineVertexInputStateCreateInfo-flags-zerobitmask",
1754                                      "vkCreateGraphicsPipelines: pararameter "
1755                                      "pCreateInfos[%d].pVertexInputState->flags (%u) is reserved and must be zero.",
1756                                      i, vertex_input_state->flags);
1757                 }
1758 
1759                 const VkStructureType allowed_structs_VkPipelineVertexInputStateCreateInfo[] = {
1760                     VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT};
1761                 skip |= validate_struct_pnext("vkCreateGraphicsPipelines", "pCreateInfos[i].pVertexInputState->pNext",
1762                                               "VkPipelineVertexInputDivisorStateCreateInfoEXT",
1763                                               pCreateInfos[i].pVertexInputState->pNext, 1,
1764                                               allowed_structs_VkPipelineVertexInputStateCreateInfo, GeneratedVulkanHeaderVersion,
1765                                               "VUID-VkPipelineVertexInputStateCreateInfo-pNext-pNext",
1766                                               "VUID-VkPipelineVertexInputStateCreateInfo-sType-unique");
1767                 skip |= validate_struct_type("vkCreateGraphicsPipelines", "pCreateInfos[i].pVertexInputState",
1768                                              "VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO", vertex_input_state,
1769                                              VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, false, kVUIDUndefined,
1770                                              "VUID-VkPipelineVertexInputStateCreateInfo-sType-sType");
1771                 skip |=
1772                     validate_array("vkCreateGraphicsPipelines", "pCreateInfos[i].pVertexInputState->vertexBindingDescriptionCount",
1773                                    "pCreateInfos[i].pVertexInputState->pVertexBindingDescriptions",
1774                                    pCreateInfos[i].pVertexInputState->vertexBindingDescriptionCount,
1775                                    &pCreateInfos[i].pVertexInputState->pVertexBindingDescriptions, false, true, kVUIDUndefined,
1776                                    "VUID-VkPipelineVertexInputStateCreateInfo-pVertexBindingDescriptions-parameter");
1777 
1778                 skip |= validate_array(
1779                     "vkCreateGraphicsPipelines", "pCreateInfos[i].pVertexInputState->vertexAttributeDescriptionCount",
1780                     "pCreateInfos[i]->pVertexAttributeDescriptions", vertex_input_state->vertexAttributeDescriptionCount,
1781                     &vertex_input_state->pVertexAttributeDescriptions, false, true, kVUIDUndefined,
1782                     "VUID-VkPipelineVertexInputStateCreateInfo-pVertexAttributeDescriptions-parameter");
1783 
1784                 if (pCreateInfos[i].pVertexInputState->pVertexBindingDescriptions != NULL) {
1785                     for (uint32_t vertexBindingDescriptionIndex = 0;
1786                          vertexBindingDescriptionIndex < pCreateInfos[i].pVertexInputState->vertexBindingDescriptionCount;
1787                          ++vertexBindingDescriptionIndex) {
1788                         skip |= validate_ranged_enum(
1789                             "vkCreateGraphicsPipelines",
1790                             "pCreateInfos[i].pVertexInputState->pVertexBindingDescriptions[j].inputRate", "VkVertexInputRate",
1791                             AllVkVertexInputRateEnums,
1792                             pCreateInfos[i].pVertexInputState->pVertexBindingDescriptions[vertexBindingDescriptionIndex].inputRate,
1793                             "VUID-VkVertexInputBindingDescription-inputRate-parameter");
1794                     }
1795                 }
1796 
1797                 if (pCreateInfos[i].pVertexInputState->pVertexAttributeDescriptions != NULL) {
1798                     for (uint32_t vertexAttributeDescriptionIndex = 0;
1799                          vertexAttributeDescriptionIndex < pCreateInfos[i].pVertexInputState->vertexAttributeDescriptionCount;
1800                          ++vertexAttributeDescriptionIndex) {
1801                         skip |= validate_ranged_enum(
1802                             "vkCreateGraphicsPipelines",
1803                             "pCreateInfos[i].pVertexInputState->pVertexAttributeDescriptions[i].format", "VkFormat",
1804                             AllVkFormatEnums,
1805                             pCreateInfos[i].pVertexInputState->pVertexAttributeDescriptions[vertexAttributeDescriptionIndex].format,
1806                             "VUID-VkVertexInputAttributeDescription-format-parameter");
1807                     }
1808                 }
1809 
1810                 if (vertex_input_state->vertexBindingDescriptionCount > device_limits.maxVertexInputBindings) {
1811                     skip |= LogError(device, "VUID-VkPipelineVertexInputStateCreateInfo-vertexBindingDescriptionCount-00613",
1812                                      "vkCreateGraphicsPipelines: pararameter "
1813                                      "pCreateInfo[%d].pVertexInputState->vertexBindingDescriptionCount (%u) is "
1814                                      "greater than VkPhysicalDeviceLimits::maxVertexInputBindings (%u).",
1815                                      i, vertex_input_state->vertexBindingDescriptionCount, device_limits.maxVertexInputBindings);
1816                 }
1817 
1818                 if (vertex_input_state->vertexAttributeDescriptionCount > device_limits.maxVertexInputAttributes) {
1819                     skip |=
1820                         LogError(device, "VUID-VkPipelineVertexInputStateCreateInfo-vertexAttributeDescriptionCount-00614",
1821                                  "vkCreateGraphicsPipelines: pararameter "
1822                                  "pCreateInfo[%d].pVertexInputState->vertexAttributeDescriptionCount (%u) is "
1823                                  "greater than VkPhysicalDeviceLimits::maxVertexInputAttributes (%u).",
1824                                  i, vertex_input_state->vertexAttributeDescriptionCount, device_limits.maxVertexInputAttributes);
1825                 }
1826 
1827                 std::unordered_set<uint32_t> vertex_bindings(vertex_input_state->vertexBindingDescriptionCount);
1828                 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1829                     auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1830                     auto const &binding_it = vertex_bindings.find(vertex_bind_desc.binding);
1831                     if (binding_it != vertex_bindings.cend()) {
1832                         skip |= LogError(device, "VUID-VkPipelineVertexInputStateCreateInfo-pVertexBindingDescriptions-00616",
1833                                          "vkCreateGraphicsPipelines: parameter "
1834                                          "pCreateInfo[%d].pVertexInputState->pVertexBindingDescription[%d].binding "
1835                                          "(%" PRIu32 ") is not distinct.",
1836                                          i, d, vertex_bind_desc.binding);
1837                     }
1838                     vertex_bindings.insert(vertex_bind_desc.binding);
1839 
1840                     if (vertex_bind_desc.binding >= device_limits.maxVertexInputBindings) {
1841                         skip |= LogError(device, "VUID-VkVertexInputBindingDescription-binding-00618",
1842                                          "vkCreateGraphicsPipelines: parameter "
1843                                          "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1844                                          "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u).",
1845                                          i, d, vertex_bind_desc.binding, device_limits.maxVertexInputBindings);
1846                     }
1847 
1848                     if (vertex_bind_desc.stride > device_limits.maxVertexInputBindingStride) {
1849                         skip |=
1850                             LogError(device, "VUID-VkVertexInputBindingDescription-stride-00619",
1851                                      "vkCreateGraphicsPipelines: parameter "
1852                                      "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1853                                      "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u).",
1854                                      i, d, vertex_bind_desc.stride, device_limits.maxVertexInputBindingStride);
1855                     }
1856                 }
1857 
1858                 std::unordered_set<uint32_t> attribute_locations(vertex_input_state->vertexAttributeDescriptionCount);
1859                 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1860                     auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1861                     auto const &location_it = attribute_locations.find(vertex_attrib_desc.location);
1862                     if (location_it != attribute_locations.cend()) {
1863                         skip |= LogError(
1864                             device, "VUID-VkPipelineVertexInputStateCreateInfo-pVertexAttributeDescriptions-00617",
1865                             "vkCreateGraphicsPipelines: parameter "
1866                             "pCreateInfo[%d].pVertexInputState->vertexAttributeDescriptions[%d].location (%u) is not distinct.",
1867                             i, d, vertex_attrib_desc.location);
1868                     }
1869                     attribute_locations.insert(vertex_attrib_desc.location);
1870 
1871                     auto const &binding_it = vertex_bindings.find(vertex_attrib_desc.binding);
1872                     if (binding_it == vertex_bindings.cend()) {
1873                         skip |= LogError(
1874                             device, "VUID-VkPipelineVertexInputStateCreateInfo-binding-00615",
1875                             "vkCreateGraphicsPipelines: parameter "
1876                             " pCreateInfo[%d].pVertexInputState->vertexAttributeDescriptions[%d].binding (%u) does not exist "
1877                             "in any pCreateInfo[%d].pVertexInputState->pVertexBindingDescription.",
1878                             i, d, vertex_attrib_desc.binding, i);
1879                     }
1880 
1881                     if (vertex_attrib_desc.location >= device_limits.maxVertexInputAttributes) {
1882                         skip |= LogError(device, "VUID-VkVertexInputAttributeDescription-location-00620",
1883                                          "vkCreateGraphicsPipelines: parameter "
1884                                          "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1885                                          "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u).",
1886                                          i, d, vertex_attrib_desc.location, device_limits.maxVertexInputAttributes);
1887                     }
1888 
1889                     if (vertex_attrib_desc.binding >= device_limits.maxVertexInputBindings) {
1890                         skip |= LogError(device, "VUID-VkVertexInputAttributeDescription-binding-00621",
1891                                          "vkCreateGraphicsPipelines: parameter "
1892                                          "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1893                                          "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u).",
1894                                          i, d, vertex_attrib_desc.binding, device_limits.maxVertexInputBindings);
1895                     }
1896 
1897                     if (vertex_attrib_desc.offset > device_limits.maxVertexInputAttributeOffset) {
1898                         skip |= LogError(device, "VUID-VkVertexInputAttributeDescription-offset-00622",
1899                                          "vkCreateGraphicsPipelines: parameter "
1900                                          "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1901                                          "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u).",
1902                                          i, d, vertex_attrib_desc.offset, device_limits.maxVertexInputAttributeOffset);
1903                     }
1904                 }
1905             }
1906 
1907             // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1908             if (has_control && has_eval) {
1909                 if (pCreateInfos[i].pTessellationState == nullptr) {
1910                     skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-pStages-00731",
1911                                      "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1912                                      "shader stage and a tessellation evaluation shader stage, "
1913                                      "pCreateInfos[%d].pTessellationState must not be NULL.",
1914                                      i, i);
1915                 } else {
1916                     const VkStructureType allowed_type = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO;
1917                     skip |= validate_struct_pnext(
1918                         "vkCreateGraphicsPipelines",
1919                         ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}),
1920                         "VkPipelineTessellationDomainOriginStateCreateInfo", pCreateInfos[i].pTessellationState->pNext, 1,
1921                         &allowed_type, GeneratedVulkanHeaderVersion, "VUID-VkGraphicsPipelineCreateInfo-pNext-pNext",
1922                         "VUID-VkGraphicsPipelineCreateInfo-sType-unique");
1923 
1924                     skip |= validate_reserved_flags(
1925                         "vkCreateGraphicsPipelines",
1926                         ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1927                         pCreateInfos[i].pTessellationState->flags, "VUID-VkPipelineTessellationStateCreateInfo-flags-zerobitmask");
1928 
1929                     if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1930                         pCreateInfos[i].pTessellationState->patchControlPoints > device_limits.maxTessellationPatchSize) {
1931                         skip |= LogError(device, "VUID-VkPipelineTessellationStateCreateInfo-patchControlPoints-01214",
1932                                          "vkCreateGraphicsPipelines: invalid parameter "
1933                                          "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1934                                          "should be >0 and <=%u.",
1935                                          i, pCreateInfos[i].pTessellationState->patchControlPoints,
1936                                          device_limits.maxTessellationPatchSize);
1937                     }
1938                 }
1939             }
1940 
1941             // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1942             if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1943                 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1944                 if (pCreateInfos[i].pViewportState == nullptr) {
1945                     skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-rasterizerDiscardEnable-00750",
1946                                      "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1947                                      "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1948                                      "].pViewportState (=NULL) is not a valid pointer.",
1949                                      i, i);
1950                 } else {
1951                     const auto &viewport_state = *pCreateInfos[i].pViewportState;
1952 
1953                     if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1954                         skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-sType-sType",
1955                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1956                                          "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO.",
1957                                          i);
1958                     }
1959 
1960                     const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1961                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1962                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV,
1963                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_EXCLUSIVE_SCISSOR_STATE_CREATE_INFO_NV,
1964                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SHADING_RATE_IMAGE_STATE_CREATE_INFO_NV,
1965                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_COARSE_SAMPLE_ORDER_STATE_CREATE_INFO_NV,
1966                     };
1967                     skip |= validate_struct_pnext(
1968                         "vkCreateGraphicsPipelines",
1969                         ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1970                         "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV, "
1971                         "VkPipelineViewportExclusiveScissorStateCreateInfoNV, VkPipelineViewportShadingRateImageStateCreateInfoNV, "
1972                         "VkPipelineViewportCoarseSampleOrderStateCreateInfoNV",
1973                         viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1974                         allowed_structs_VkPipelineViewportStateCreateInfo, 65, "VUID-VkPipelineViewportStateCreateInfo-pNext-pNext",
1975                         "VUID-VkPipelineViewportStateCreateInfo-sType-unique");
1976 
1977                     skip |= validate_reserved_flags(
1978                         "vkCreateGraphicsPipelines",
1979                         ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
1980                         viewport_state.flags, "VUID-VkPipelineViewportStateCreateInfo-flags-zerobitmask");
1981 
1982                     auto exclusive_scissor_struct = lvl_find_in_chain<VkPipelineViewportExclusiveScissorStateCreateInfoNV>(
1983                         pCreateInfos[i].pViewportState->pNext);
1984                     auto shading_rate_image_struct = lvl_find_in_chain<VkPipelineViewportShadingRateImageStateCreateInfoNV>(
1985                         pCreateInfos[i].pViewportState->pNext);
1986                     auto coarse_sample_order_struct = lvl_find_in_chain<VkPipelineViewportCoarseSampleOrderStateCreateInfoNV>(
1987                         pCreateInfos[i].pViewportState->pNext);
1988                     const auto vp_swizzle_struct =
1989                         lvl_find_in_chain<VkPipelineViewportSwizzleStateCreateInfoNV>(pCreateInfos[i].pViewportState->pNext);
1990                     const auto vp_w_scaling_struct =
1991                         lvl_find_in_chain<VkPipelineViewportWScalingStateCreateInfoNV>(pCreateInfos[i].pViewportState->pNext);
1992 
1993                     if (!physical_device_features.multiViewport) {
1994                         if (!has_dynamic_viewport_with_count && (viewport_state.viewportCount != 1)) {
1995                             skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-viewportCount-01216",
1996                                              "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1997                                              "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1998                                              ") is not 1.",
1999                                              i, viewport_state.viewportCount);
2000                         }
2001 
2002                         if (!has_dynamic_scissor_with_count && (viewport_state.scissorCount != 1)) {
2003                             skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-scissorCount-01217",
2004                                              "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
2005                                              "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
2006                                              ") is not 1.",
2007                                              i, viewport_state.scissorCount);
2008                         }
2009 
2010                         if (exclusive_scissor_struct && (exclusive_scissor_struct->exclusiveScissorCount != 0 &&
2011                                                          exclusive_scissor_struct->exclusiveScissorCount != 1)) {
2012                             skip |= LogError(
2013                                 device, "VUID-VkPipelineViewportExclusiveScissorStateCreateInfoNV-exclusiveScissorCount-02027",
2014                                 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
2015                                 "disabled, but pCreateInfos[%" PRIu32
2016                                 "] VkPipelineViewportExclusiveScissorStateCreateInfoNV::exclusiveScissorCount (=%" PRIu32
2017                                 ") is not 1.",
2018                                 i, exclusive_scissor_struct->exclusiveScissorCount);
2019                         }
2020 
2021                         if (shading_rate_image_struct &&
2022                             (shading_rate_image_struct->viewportCount != 0 && shading_rate_image_struct->viewportCount != 1)) {
2023                             skip |= LogError(device, "VUID-VkPipelineViewportShadingRateImageStateCreateInfoNV-viewportCount-02054",
2024                                              "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
2025                                              "disabled, but pCreateInfos[%" PRIu32
2026                                              "] VkPipelineViewportShadingRateImageStateCreateInfoNV::viewportCount (=%" PRIu32
2027                                              ") is neither 0 nor 1.",
2028                                              i, shading_rate_image_struct->viewportCount);
2029                         }
2030 
2031                     } else {  // multiViewport enabled
2032                         if (viewport_state.viewportCount == 0) {
2033                             if (!has_dynamic_viewport_with_count) {
2034                                 skip |= LogError(
2035                                     device, "VUID-VkPipelineViewportStateCreateInfo-viewportCount-arraylength",
2036                                     "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32 "].pViewportState->viewportCount is 0.", i);
2037                             }
2038                         } else if (viewport_state.viewportCount > device_limits.maxViewports) {
2039                             skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-viewportCount-01218",
2040                                              "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2041                                              "].pViewportState->viewportCount (=%" PRIu32
2042                                              ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
2043                                              i, viewport_state.viewportCount, device_limits.maxViewports);
2044                         } else if (has_dynamic_viewport_with_count) {
2045                             skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-03379",
2046                                              "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2047                                              "].pViewportState->viewportCount (=%" PRIu32
2048                                              ") must be zero when VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT is used.",
2049                                              i, viewport_state.viewportCount);
2050                         }
2051 
2052                         if (viewport_state.scissorCount == 0) {
2053                             if (!has_dynamic_scissor_with_count) {
2054                                 skip |= LogError(
2055                                     device, "VUID-VkPipelineViewportStateCreateInfo-scissorCount-arraylength",
2056                                     "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32 "].pViewportState->scissorCount is 0.", i);
2057                             }
2058                         } else if (viewport_state.scissorCount > device_limits.maxViewports) {
2059                             skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-scissorCount-01219",
2060                                              "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2061                                              "].pViewportState->scissorCount (=%" PRIu32
2062                                              ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
2063                                              i, viewport_state.scissorCount, device_limits.maxViewports);
2064                         } else if (has_dynamic_scissor_with_count) {
2065                             skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-03380",
2066                                              "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2067                                              "].pViewportState->scissorCount (=%" PRIu32
2068                                              ") must be zero when VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT is used.",
2069                                              i, viewport_state.viewportCount);
2070                         }
2071                     }
2072 
2073                     if (exclusive_scissor_struct && exclusive_scissor_struct->exclusiveScissorCount > device_limits.maxViewports) {
2074                         skip |=
2075                             LogError(device, "VUID-VkPipelineViewportExclusiveScissorStateCreateInfoNV-exclusiveScissorCount-02028",
2076                                      "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32 "] exclusiveScissorCount (=%" PRIu32
2077                                      ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
2078                                      i, exclusive_scissor_struct->exclusiveScissorCount, device_limits.maxViewports);
2079                     }
2080 
2081                     if (shading_rate_image_struct && shading_rate_image_struct->viewportCount > device_limits.maxViewports) {
2082                         skip |= LogError(device, "VUID-VkPipelineViewportShadingRateImageStateCreateInfoNV-viewportCount-02055",
2083                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2084                                          "] VkPipelineViewportShadingRateImageStateCreateInfoNV viewportCount (=%" PRIu32
2085                                          ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
2086                                          i, shading_rate_image_struct->viewportCount, device_limits.maxViewports);
2087                     }
2088 
2089                     if (viewport_state.scissorCount != viewport_state.viewportCount &&
2090                         !(has_dynamic_viewport_with_count || has_dynamic_scissor_with_count)) {
2091                         skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-scissorCount-01220",
2092                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2093                                          "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
2094                                          "].pViewportState->viewportCount (=%" PRIu32 ").",
2095                                          i, viewport_state.scissorCount, i, viewport_state.viewportCount);
2096                     }
2097 
2098                     if (exclusive_scissor_struct && exclusive_scissor_struct->exclusiveScissorCount != 0 &&
2099                         exclusive_scissor_struct->exclusiveScissorCount != viewport_state.viewportCount) {
2100                         skip |=
2101                             LogError(device, "VUID-VkPipelineViewportExclusiveScissorStateCreateInfoNV-exclusiveScissorCount-02029",
2102                                      "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32 "] exclusiveScissorCount (=%" PRIu32
2103                                      ") must be zero or identical to pCreateInfos[%" PRIu32
2104                                      "].pViewportState->viewportCount (=%" PRIu32 ").",
2105                                      i, exclusive_scissor_struct->exclusiveScissorCount, i, viewport_state.viewportCount);
2106                     }
2107 
2108                     if (shading_rate_image_struct && shading_rate_image_struct->shadingRateImageEnable &&
2109                         shading_rate_image_struct->viewportCount != viewport_state.viewportCount) {
2110                         skip |= LogError(
2111                             device, "VUID-VkPipelineViewportShadingRateImageStateCreateInfoNV-shadingRateImageEnable-02056",
2112                             "vkCreateGraphicsPipelines: If shadingRateImageEnable is enabled, pCreateInfos[%" PRIu32
2113                             "] "
2114                             "VkPipelineViewportShadingRateImageStateCreateInfoNV viewportCount (=%" PRIu32
2115                             ") must identical to pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32 ").",
2116                             i, shading_rate_image_struct->viewportCount, i, viewport_state.viewportCount);
2117                     }
2118 
2119                     if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
2120                         skip |= LogError(
2121                             device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-00747",
2122                             "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
2123                             "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
2124                             "].pViewportState->pViewports (=NULL) is an invalid pointer.",
2125                             i, i);
2126                     }
2127 
2128                     if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
2129                         skip |= LogError(
2130                             device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-00748",
2131                             "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
2132                             "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
2133                             "].pViewportState->pScissors (=NULL) is an invalid pointer.",
2134                             i, i);
2135                     }
2136 
2137                     if (!has_dynamic_exclusive_scissor_nv && exclusive_scissor_struct &&
2138                         exclusive_scissor_struct->exclusiveScissorCount > 0 &&
2139                         exclusive_scissor_struct->pExclusiveScissors == nullptr) {
2140                         skip |=
2141                             LogError(device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04056",
2142                                      "vkCreateGraphicsPipelines: The exclusive scissor state is static (pCreateInfos[%" PRIu32
2143                                      "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV), but "
2144                                      "pCreateInfos[%" PRIu32 "] pExclusiveScissors (=NULL) is an invalid pointer.",
2145                                      i, i);
2146                     }
2147 
2148                     if (!has_dynamic_shading_rate_palette_nv && shading_rate_image_struct &&
2149                         shading_rate_image_struct->viewportCount > 0 &&
2150                         shading_rate_image_struct->pShadingRatePalettes == nullptr) {
2151                         skip |= LogError(
2152                             device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04057",
2153                             "vkCreateGraphicsPipelines: The shading rate palette state is static (pCreateInfos[%" PRIu32
2154                             "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV), "
2155                             "but pCreateInfos[%" PRIu32 "] pShadingRatePalettes (=NULL) is an invalid pointer.",
2156                             i, i);
2157                     }
2158 
2159                     if (vp_swizzle_struct) {
2160                         if (vp_swizzle_struct->viewportCount != viewport_state.viewportCount) {
2161                             skip |= LogError(device, "VUID-VkPipelineViewportSwizzleStateCreateInfoNV-viewportCount-01215",
2162                                              "vkCreateGraphicsPipelines: The viewport swizzle state vieport count of %" PRIu32
2163                                              " does "
2164                                              "not match the viewport count of %" PRIu32 " in VkPipelineViewportStateCreateInfo.",
2165                                              vp_swizzle_struct->viewportCount, viewport_state.viewportCount);
2166                         }
2167                     }
2168 
2169                     // validate the VkViewports
2170                     if (!has_dynamic_viewport && viewport_state.pViewports) {
2171                         for (uint32_t viewport_i = 0; viewport_i < viewport_state.viewportCount; ++viewport_i) {
2172                             const auto &viewport = viewport_state.pViewports[viewport_i];  // will crash on invalid ptr
2173                             const char *fn_name = "vkCreateGraphicsPipelines";
2174                             skip |= manual_PreCallValidateViewport(viewport, fn_name,
2175                                                                    ParameterName("pCreateInfos[%i].pViewportState->pViewports[%i]",
2176                                                                                  ParameterName::IndexVector{i, viewport_i}),
2177                                                                    VkCommandBuffer(0));
2178                         }
2179                     }
2180 
2181                     if (has_dynamic_viewport_w_scaling_nv && !device_extensions.vk_nv_clip_space_w_scaling) {
2182                         skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
2183                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2184                                          "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
2185                                          "VK_NV_clip_space_w_scaling extension is not enabled.",
2186                                          i);
2187                     }
2188 
2189                     if (has_dynamic_discard_rectangle_ext && !device_extensions.vk_ext_discard_rectangles) {
2190                         skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
2191                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2192                                          "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
2193                                          "VK_EXT_discard_rectangles extension is not enabled.",
2194                                          i);
2195                     }
2196 
2197                     if (has_dynamic_sample_locations_ext && !device_extensions.vk_ext_sample_locations) {
2198                         skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
2199                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2200                                          "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
2201                                          "VK_EXT_sample_locations extension is not enabled.",
2202                                          i);
2203                     }
2204 
2205                     if (has_dynamic_exclusive_scissor_nv && !device_extensions.vk_nv_scissor_exclusive) {
2206                         skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
2207                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2208                                          "].pDynamicState->pDynamicStates contains VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV, but "
2209                                          "VK_NV_scissor_exclusive extension is not enabled.",
2210                                          i);
2211                     }
2212 
2213                     if (coarse_sample_order_struct &&
2214                         coarse_sample_order_struct->sampleOrderType != VK_COARSE_SAMPLE_ORDER_TYPE_CUSTOM_NV &&
2215                         coarse_sample_order_struct->customSampleOrderCount != 0) {
2216                         skip |= LogError(device, "VUID-VkPipelineViewportCoarseSampleOrderStateCreateInfoNV-sampleOrderType-02072",
2217                                          "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2218                                          "] "
2219                                          "VkPipelineViewportCoarseSampleOrderStateCreateInfoNV sampleOrderType is not "
2220                                          "VK_COARSE_SAMPLE_ORDER_TYPE_CUSTOM_NV and customSampleOrderCount is not 0.",
2221                                          i);
2222                     }
2223 
2224                     if (coarse_sample_order_struct) {
2225                         for (uint32_t order_i = 0; order_i < coarse_sample_order_struct->customSampleOrderCount; ++order_i) {
2226                             skip |= ValidateCoarseSampleOrderCustomNV(&coarse_sample_order_struct->pCustomSampleOrders[order_i]);
2227                         }
2228                     }
2229 
2230                     if (vp_w_scaling_struct && (vp_w_scaling_struct->viewportWScalingEnable == VK_TRUE)) {
2231                         if (vp_w_scaling_struct->viewportCount != viewport_state.viewportCount) {
2232                             skip |= LogError(device, "VUID-VkPipelineViewportStateCreateInfo-viewportWScalingEnable-01726",
2233                                              "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2234                                              "] "
2235                                              "VkPipelineViewportWScalingStateCreateInfoNV.viewportCount (=%" PRIu32
2236                                              ") "
2237                                              "is not equal to VkPipelineViewportStateCreateInfo.viewportCount (=%" PRIu32 ").",
2238                                              i, vp_w_scaling_struct->viewportCount, viewport_state.viewportCount);
2239                         }
2240                         if (!has_dynamic_viewport_w_scaling_nv && !vp_w_scaling_struct->pViewportWScalings) {
2241                             skip |= LogError(
2242                                 device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-01715",
2243                                 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
2244                                 "] "
2245                                 "VkPipelineViewportWScalingStateCreateInfoNV.pViewportWScalings (=NULL) is not a valid array.",
2246                                 i);
2247                         }
2248                     }
2249                 }
2250 
2251                 if (pCreateInfos[i].pMultisampleState == nullptr) {
2252                     skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-rasterizerDiscardEnable-00751",
2253                                      "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
2254                                      "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL.",
2255                                      i, i);
2256                 } else {
2257                     const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
2258                                                                  LvlTypeMap<VkPipelineCoverageReductionStateCreateInfoNV>::kSType,
2259                                                                  LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
2260                                                                  LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
2261                     const char *valid_struct_names =
2262                         "VkPipelineCoverageModulationStateCreateInfoNV, VkPipelineCoverageToColorStateCreateInfoNV, "
2263                         "VkPipelineSampleLocationsStateCreateInfoEXT";
2264                     skip |= validate_struct_pnext(
2265                         "vkCreateGraphicsPipelines",
2266                         ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
2267                         valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 4, valid_next_stypes,
2268                         GeneratedVulkanHeaderVersion, "VUID-VkPipelineMultisampleStateCreateInfo-pNext-pNext",
2269                         "VUID-VkPipelineMultisampleStateCreateInfo-sType-unique");
2270 
2271                     skip |= validate_reserved_flags(
2272                         "vkCreateGraphicsPipelines",
2273                         ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
2274                         pCreateInfos[i].pMultisampleState->flags, "VUID-VkPipelineMultisampleStateCreateInfo-flags-zerobitmask");
2275 
2276                     skip |= validate_bool32(
2277                         "vkCreateGraphicsPipelines",
2278                         ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
2279                         pCreateInfos[i].pMultisampleState->sampleShadingEnable);
2280 
2281                     skip |= validate_array(
2282                         "vkCreateGraphicsPipelines",
2283                         ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
2284                         ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
2285                         pCreateInfos[i].pMultisampleState->rasterizationSamples, &pCreateInfos[i].pMultisampleState->pSampleMask,
2286                         true, false, kVUIDUndefined, kVUIDUndefined);
2287 
2288                     skip |= validate_flags(
2289                         "vkCreateGraphicsPipelines",
2290                         ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
2291                         "VkSampleCountFlagBits", AllVkSampleCountFlagBits, pCreateInfos[i].pMultisampleState->rasterizationSamples,
2292                         kRequiredSingleBit, "VUID-VkPipelineMultisampleStateCreateInfo-rasterizationSamples-parameter");
2293 
2294                     skip |= validate_bool32(
2295                         "vkCreateGraphicsPipelines",
2296                         ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
2297                         pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
2298 
2299                     skip |= validate_bool32(
2300                         "vkCreateGraphicsPipelines",
2301                         ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
2302                         pCreateInfos[i].pMultisampleState->alphaToOneEnable);
2303 
2304                     if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
2305                         skip |= LogError(device, "VUID-VkPipelineMultisampleStateCreateInfo-sType-sType",
2306                                          "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
2307                                          "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
2308                                          i);
2309                     }
2310                     if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
2311                         if (!physical_device_features.sampleRateShading) {
2312                             skip |= LogError(device, "VUID-VkPipelineMultisampleStateCreateInfo-sampleShadingEnable-00784",
2313                                              "vkCreateGraphicsPipelines(): parameter "
2314                                              "pCreateInfos[%d].pMultisampleState->sampleShadingEnable.",
2315                                              i);
2316                         }
2317                         // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
2318                         // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
2319                         if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
2320                             skip |= LogError(
2321                                 device,
2322 
2323                                 "VUID-VkPipelineMultisampleStateCreateInfo-minSampleShading-00786",
2324                                 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading.", i);
2325                         }
2326                     }
2327 
2328                     const auto *line_state = lvl_find_in_chain<VkPipelineRasterizationLineStateCreateInfoEXT>(
2329                         pCreateInfos[i].pRasterizationState->pNext);
2330 
2331                     if (line_state) {
2332                         if ((line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT ||
2333                              line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT)) {
2334                             if (pCreateInfos[i].pMultisampleState->alphaToCoverageEnable) {
2335                                 skip |=
2336                                     LogError(device, "VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766",
2337                                              "vkCreateGraphicsPipelines(): Bresenham/Smooth line rasterization not supported with "
2338                                              "pCreateInfos[%d].pMultisampleState->alphaToCoverageEnable == VK_TRUE.",
2339                                              i);
2340                             }
2341                             if (pCreateInfos[i].pMultisampleState->alphaToOneEnable) {
2342                                 skip |=
2343                                     LogError(device, "VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766",
2344                                              "vkCreateGraphicsPipelines(): Bresenham/Smooth line rasterization not supported with "
2345                                              "pCreateInfos[%d].pMultisampleState->alphaToOneEnable == VK_TRUE.",
2346                                              i);
2347                             }
2348                             if (pCreateInfos[i].pMultisampleState->sampleShadingEnable) {
2349                                 skip |=
2350                                     LogError(device, "VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766",
2351                                              "vkCreateGraphicsPipelines(): Bresenham/Smooth line rasterization not supported with "
2352                                              "pCreateInfos[%d].pMultisampleState->sampleShadingEnable == VK_TRUE.",
2353                                              i);
2354                             }
2355                         }
2356                         if (line_state->stippledLineEnable && !has_dynamic_line_stipple) {
2357                             if (line_state->lineStippleFactor < 1 || line_state->lineStippleFactor > 256) {
2358                                 skip |=
2359                                     LogError(device, "VUID-VkGraphicsPipelineCreateInfo-stippledLineEnable-02767",
2360                                              "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineStippleFactor = %d must be in the "
2361                                              "range [1,256].",
2362                                              i, line_state->lineStippleFactor);
2363                             }
2364                         }
2365                         const auto *line_features =
2366                             lvl_find_in_chain<VkPhysicalDeviceLineRasterizationFeaturesEXT>(device_createinfo_pnext);
2367                         if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT &&
2368                             (!line_features || !line_features->rectangularLines)) {
2369                             skip |=
2370                                 LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02768",
2371                                          "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2372                                          "VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT requires the rectangularLines feature.",
2373                                          i);
2374                         }
2375                         if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT &&
2376                             (!line_features || !line_features->bresenhamLines)) {
2377                             skip |=
2378                                 LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02769",
2379                                          "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2380                                          "VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT requires the bresenhamLines feature.",
2381                                          i);
2382                         }
2383                         if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT &&
2384                             (!line_features || !line_features->smoothLines)) {
2385                             skip |=
2386                                 LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02770",
2387                                          "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2388                                          "VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT requires the smoothLines feature.",
2389                                          i);
2390                         }
2391                         if (line_state->stippledLineEnable) {
2392                             if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT &&
2393                                 (!line_features || !line_features->stippledRectangularLines)) {
2394                                 skip |=
2395                                     LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02771",
2396                                              "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2397                                              "VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT with stipple requires the "
2398                                              "stippledRectangularLines feature.",
2399                                              i);
2400                             }
2401                             if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT &&
2402                                 (!line_features || !line_features->stippledBresenhamLines)) {
2403                                 skip |=
2404                                     LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02772",
2405                                              "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2406                                              "VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT with stipple requires the "
2407                                              "stippledBresenhamLines feature.",
2408                                              i);
2409                             }
2410                             if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT &&
2411                                 (!line_features || !line_features->stippledSmoothLines)) {
2412                                 skip |=
2413                                     LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02773",
2414                                              "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2415                                              "VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT with stipple requires the "
2416                                              "stippledSmoothLines feature.",
2417                                              i);
2418                             }
2419                             if (line_state->lineRasterizationMode == VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT &&
2420                                 (!line_features || !line_features->stippledSmoothLines || !device_limits.strictLines)) {
2421                                 skip |=
2422                                     LogError(device, "VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02774",
2423                                              "vkCreateGraphicsPipelines(): pCreateInfos[%d] lineRasterizationMode = "
2424                                              "VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT with stipple requires the "
2425                                              "stippledRectangularLines and strictLines features.",
2426                                              i);
2427                             }
2428                         }
2429                     }
2430                 }
2431 
2432                 bool uses_color_attachment = false;
2433                 bool uses_depthstencil_attachment = false;
2434                 {
2435                     std::unique_lock<std::mutex> lock(renderpass_map_mutex);
2436                     const auto subpasses_uses_it = renderpasses_states.find(pCreateInfos[i].renderPass);
2437                     if (subpasses_uses_it != renderpasses_states.end()) {
2438                         const auto &subpasses_uses = subpasses_uses_it->second;
2439                         if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
2440                             uses_color_attachment = true;
2441                         if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
2442                             uses_depthstencil_attachment = true;
2443                     }
2444                     lock.unlock();
2445                 }
2446 
2447                 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
2448                     skip |= validate_struct_pnext(
2449                         "vkCreateGraphicsPipelines",
2450                         ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
2451                         pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedVulkanHeaderVersion,
2452                         "VUID-VkPipelineDepthStencilStateCreateInfo-pNext-pNext", nullptr);
2453 
2454                     skip |= validate_reserved_flags(
2455                         "vkCreateGraphicsPipelines",
2456                         ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
2457                         pCreateInfos[i].pDepthStencilState->flags, "VUID-VkPipelineDepthStencilStateCreateInfo-flags-zerobitmask");
2458 
2459                     skip |= validate_bool32(
2460                         "vkCreateGraphicsPipelines",
2461                         ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
2462                         pCreateInfos[i].pDepthStencilState->depthTestEnable);
2463 
2464                     skip |= validate_bool32(
2465                         "vkCreateGraphicsPipelines",
2466                         ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
2467                         pCreateInfos[i].pDepthStencilState->depthWriteEnable);
2468 
2469                     skip |= validate_ranged_enum(
2470                         "vkCreateGraphicsPipelines",
2471                         ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
2472                         "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
2473                         "VUID-VkPipelineDepthStencilStateCreateInfo-depthCompareOp-parameter");
2474 
2475                     skip |= validate_bool32(
2476                         "vkCreateGraphicsPipelines",
2477                         ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
2478                         pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
2479 
2480                     skip |= validate_bool32(
2481                         "vkCreateGraphicsPipelines",
2482                         ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
2483                         pCreateInfos[i].pDepthStencilState->stencilTestEnable);
2484 
2485                     skip |= validate_ranged_enum(
2486                         "vkCreateGraphicsPipelines",
2487                         ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
2488                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
2489                         "VUID-VkStencilOpState-failOp-parameter");
2490 
2491                     skip |= validate_ranged_enum(
2492                         "vkCreateGraphicsPipelines",
2493                         ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
2494                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
2495                         "VUID-VkStencilOpState-passOp-parameter");
2496 
2497                     skip |= validate_ranged_enum(
2498                         "vkCreateGraphicsPipelines",
2499                         ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
2500                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
2501                         "VUID-VkStencilOpState-depthFailOp-parameter");
2502 
2503                     skip |= validate_ranged_enum(
2504                         "vkCreateGraphicsPipelines",
2505                         ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
2506                         "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
2507                         "VUID-VkPipelineDepthStencilStateCreateInfo-depthCompareOp-parameter");
2508 
2509                     skip |= validate_ranged_enum(
2510                         "vkCreateGraphicsPipelines",
2511                         ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
2512                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
2513                         "VUID-VkStencilOpState-failOp-parameter");
2514 
2515                     skip |= validate_ranged_enum(
2516                         "vkCreateGraphicsPipelines",
2517                         ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
2518                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
2519                         "VUID-VkStencilOpState-passOp-parameter");
2520 
2521                     skip |= validate_ranged_enum(
2522                         "vkCreateGraphicsPipelines",
2523                         ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
2524                         "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
2525                         "VUID-VkStencilOpState-depthFailOp-parameter");
2526 
2527                     skip |= validate_ranged_enum(
2528                         "vkCreateGraphicsPipelines",
2529                         ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
2530                         "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
2531                         "VUID-VkPipelineDepthStencilStateCreateInfo-depthCompareOp-parameter");
2532 
2533                     if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
2534                         skip |= LogError(device, "VUID-VkPipelineDepthStencilStateCreateInfo-sType-sType",
2535                                          "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
2536                                          "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
2537                                          i);
2538                     }
2539                 }
2540 
2541                 const VkStructureType allowed_structs_VkPipelineColorBlendStateCreateInfo[] = {
2542                     VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_ADVANCED_STATE_CREATE_INFO_EXT};
2543 
2544                 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
2545                     skip |= validate_struct_type("vkCreateGraphicsPipelines",
2546                                                  ParameterName("pCreateInfos[%i].pColorBlendState", ParameterName::IndexVector{i}),
2547                                                  "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
2548                                                  pCreateInfos[i].pColorBlendState,
2549                                                  VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, false, kVUIDUndefined,
2550                                                  "VUID-VkPipelineColorBlendStateCreateInfo-sType-sType");
2551 
2552                     skip |= validate_struct_pnext(
2553                         "vkCreateGraphicsPipelines",
2554                         ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}),
2555                         "VkPipelineColorBlendAdvancedStateCreateInfoEXT", pCreateInfos[i].pColorBlendState->pNext,
2556                         ARRAY_SIZE(allowed_structs_VkPipelineColorBlendStateCreateInfo),
2557                         allowed_structs_VkPipelineColorBlendStateCreateInfo, GeneratedVulkanHeaderVersion,
2558                         "VUID-VkPipelineColorBlendStateCreateInfo-pNext-pNext",
2559                         "VUID-VkPipelineColorBlendStateCreateInfo-sType-unique");
2560 
2561                     skip |= validate_reserved_flags(
2562                         "vkCreateGraphicsPipelines",
2563                         ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
2564                         pCreateInfos[i].pColorBlendState->flags, "VUID-VkPipelineColorBlendStateCreateInfo-flags-zerobitmask");
2565 
2566                     skip |= validate_bool32(
2567                         "vkCreateGraphicsPipelines",
2568                         ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
2569                         pCreateInfos[i].pColorBlendState->logicOpEnable);
2570 
2571                     skip |= validate_array(
2572                         "vkCreateGraphicsPipelines",
2573                         ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
2574                         ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
2575                         pCreateInfos[i].pColorBlendState->attachmentCount, &pCreateInfos[i].pColorBlendState->pAttachments, false,
2576                         true, kVUIDUndefined, kVUIDUndefined);
2577 
2578                     if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
2579                         for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
2580                              ++attachmentIndex) {
2581                             skip |= validate_bool32("vkCreateGraphicsPipelines",
2582                                                     ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
2583                                                                   ParameterName::IndexVector{i, attachmentIndex}),
2584                                                     pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
2585 
2586                             skip |= validate_ranged_enum(
2587                                 "vkCreateGraphicsPipelines",
2588                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
2589                                               ParameterName::IndexVector{i, attachmentIndex}),
2590                                 "VkBlendFactor", AllVkBlendFactorEnums,
2591                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
2592                                 "VUID-VkPipelineColorBlendAttachmentState-srcColorBlendFactor-parameter");
2593 
2594                             skip |= validate_ranged_enum(
2595                                 "vkCreateGraphicsPipelines",
2596                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
2597                                               ParameterName::IndexVector{i, attachmentIndex}),
2598                                 "VkBlendFactor", AllVkBlendFactorEnums,
2599                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
2600                                 "VUID-VkPipelineColorBlendAttachmentState-dstColorBlendFactor-parameter");
2601 
2602                             skip |= validate_ranged_enum(
2603                                 "vkCreateGraphicsPipelines",
2604                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
2605                                               ParameterName::IndexVector{i, attachmentIndex}),
2606                                 "VkBlendOp", AllVkBlendOpEnums,
2607                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
2608                                 "VUID-VkPipelineColorBlendAttachmentState-colorBlendOp-parameter");
2609 
2610                             skip |= validate_ranged_enum(
2611                                 "vkCreateGraphicsPipelines",
2612                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
2613                                               ParameterName::IndexVector{i, attachmentIndex}),
2614                                 "VkBlendFactor", AllVkBlendFactorEnums,
2615                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
2616                                 "VUID-VkPipelineColorBlendAttachmentState-srcAlphaBlendFactor-parameter");
2617 
2618                             skip |= validate_ranged_enum(
2619                                 "vkCreateGraphicsPipelines",
2620                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
2621                                               ParameterName::IndexVector{i, attachmentIndex}),
2622                                 "VkBlendFactor", AllVkBlendFactorEnums,
2623                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
2624                                 "VUID-VkPipelineColorBlendAttachmentState-dstAlphaBlendFactor-parameter");
2625 
2626                             skip |= validate_ranged_enum(
2627                                 "vkCreateGraphicsPipelines",
2628                                 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
2629                                               ParameterName::IndexVector{i, attachmentIndex}),
2630                                 "VkBlendOp", AllVkBlendOpEnums,
2631                                 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
2632                                 "VUID-VkPipelineColorBlendAttachmentState-alphaBlendOp-parameter");
2633 
2634                             skip |=
2635                                 validate_flags("vkCreateGraphicsPipelines",
2636                                                ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
2637                                                              ParameterName::IndexVector{i, attachmentIndex}),
2638                                                "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
2639                                                pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
2640                                                kOptionalFlags, "VUID-VkPipelineColorBlendAttachmentState-colorWriteMask-parameter");
2641                         }
2642                     }
2643 
2644                     if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
2645                         skip |= LogError(device, "VUID-VkPipelineColorBlendStateCreateInfo-sType-sType",
2646                                          "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
2647                                          "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
2648                                          i);
2649                     }
2650 
2651                     // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
2652                     if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
2653                         skip |= validate_ranged_enum(
2654                             "vkCreateGraphicsPipelines",
2655                             ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
2656                             AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp,
2657                             "VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00607");
2658                     }
2659                 }
2660             }
2661 
2662             if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
2663                 if (pCreateInfos[i].basePipelineIndex != -1) {
2664                     if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
2665                         skip |=
2666                             LogError(device, "VUID-VkGraphicsPipelineCreateInfo-flags-00724",
2667                                      "vkCreateGraphicsPipelines parameter, pCreateInfos[%u]->basePipelineHandle, must be "
2668                                      "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
2669                                      "and pCreateInfos->basePipelineIndex is not -1.",
2670                                      i);
2671                     }
2672                 }
2673 
2674                 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
2675                     if (pCreateInfos[i].basePipelineIndex != -1) {
2676                         skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-flags-00725",
2677                                          "vkCreateGraphicsPipelines parameter, pCreateInfos[%u]->basePipelineIndex, must be -1 if "
2678                                          "pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and "
2679                                          "pCreateInfos->basePipelineHandle is not VK_NULL_HANDLE.",
2680                                          i);
2681                     }
2682                 } else {
2683                     if (static_cast<uint32_t>(pCreateInfos[i].basePipelineIndex) >= createInfoCount) {
2684                         skip |=
2685                             LogError(device, "VUID-VkGraphicsPipelineCreateInfo-flags-00723",
2686                                      "vkCreateGraphicsPipelines parameter pCreateInfos[%u]->basePipelineIndex (%d) must be a valid"
2687                                      "index into the pCreateInfos array, of size %d.",
2688                                      i, pCreateInfos[i].basePipelineIndex, createInfoCount);
2689                     }
2690                 }
2691             }
2692 
2693             if ((pCreateInfos[i].flags & VK_PIPELINE_CREATE_DISPATCH_BASE) != 0) {
2694                 skip |= LogError(
2695                     device, "VUID-VkGraphicsPipelineCreateInfo-flags-00764",
2696                     "vkCreateGraphicsPipelines parameter pCreateInfos[%u]->flags must not contain VK_PIPELINE_CREATE_DISPATCH_BASE",
2697                     i);
2698             }
2699 
2700             if (pCreateInfos[i].pRasterizationState) {
2701                 if (!device_extensions.vk_nv_fill_rectangle) {
2702                     if (pCreateInfos[i].pRasterizationState->polygonMode == VK_POLYGON_MODE_FILL_RECTANGLE_NV) {
2703                         skip |=
2704                             LogError(device, "VUID-VkPipelineRasterizationStateCreateInfo-polygonMode-01414",
2705                                      "vkCreateGraphicsPipelines parameter, VkPolygonMode "
2706                                      "pCreateInfos->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_FILL_RECTANGLE_NV "
2707                                      "if the extension VK_NV_fill_rectangle is not enabled.");
2708                     } else if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
2709                                (physical_device_features.fillModeNonSolid == false)) {
2710                         skip |= LogError(device, "VUID-VkPipelineRasterizationStateCreateInfo-polygonMode-01413",
2711                                          "vkCreateGraphicsPipelines parameter, VkPolygonMode "
2712                                          "pCreateInfos[%u]->pRasterizationState->polygonMode cannot be VK_POLYGON_MODE_POINT or "
2713                                          "VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.",
2714                                          i);
2715                     }
2716                 } else {
2717                     if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
2718                         (pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL_RECTANGLE_NV) &&
2719                         (physical_device_features.fillModeNonSolid == false)) {
2720                         skip |=
2721                             LogError(device, "VUID-VkPipelineRasterizationStateCreateInfo-polygonMode-01507",
2722                                      "vkCreateGraphicsPipelines parameter, VkPolygonMode "
2723                                      "pCreateInfos[%u]->pRasterizationState->polygonMode must be VK_POLYGON_MODE_FILL or "
2724                                      "VK_POLYGON_MODE_FILL_RECTANGLE_NV if VkPhysicalDeviceFeatures->fillModeNonSolid is false.",
2725                                      i);
2726                     }
2727                 }
2728 
2729                 if (!has_dynamic_line_width && !physical_device_features.wideLines &&
2730                     (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
2731                     skip |= LogError(device, "VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-00749",
2732                                      "The line width state is static (pCreateInfos[%" PRIu32
2733                                      "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
2734                                      "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
2735                                      "].pRasterizationState->lineWidth (=%f) is not 1.0.",
2736                                      i, i, pCreateInfos[i].pRasterizationState->lineWidth);
2737                 }
2738             }
2739         }
2740     }
2741 
2742     return skip;
2743 }
2744 
manual_PreCallValidateCreateComputePipelines(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkComputePipelineCreateInfo * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const2745 bool StatelessValidation::manual_PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache,
2746                                                                        uint32_t createInfoCount,
2747                                                                        const VkComputePipelineCreateInfo *pCreateInfos,
2748                                                                        const VkAllocationCallbacks *pAllocator,
2749                                                                        VkPipeline *pPipelines) const {
2750     bool skip = false;
2751     for (uint32_t i = 0; i < createInfoCount; i++) {
2752         skip |= validate_string("vkCreateComputePipelines",
2753                                 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
2754                                 "VUID-VkPipelineShaderStageCreateInfo-pName-parameter", pCreateInfos[i].stage.pName);
2755         auto feedback_struct = lvl_find_in_chain<VkPipelineCreationFeedbackCreateInfoEXT>(pCreateInfos[i].pNext);
2756         if ((feedback_struct != nullptr) && (feedback_struct->pipelineStageCreationFeedbackCount != 1)) {
2757             skip |=
2758                 LogError(device, "VUID-VkPipelineCreationFeedbackCreateInfoEXT-pipelineStageCreationFeedbackCount-02669",
2759                          "vkCreateComputePipelines(): in pCreateInfo[%" PRIu32
2760                          "], VkPipelineCreationFeedbackEXT::pipelineStageCreationFeedbackCount must equal 1, found %" PRIu32 ".",
2761                          i, feedback_struct->pipelineStageCreationFeedbackCount);
2762         }
2763 
2764         // Make sure compute stage is selected
2765         if (pCreateInfos[i].stage.stage != VK_SHADER_STAGE_COMPUTE_BIT) {
2766             skip |= LogError(device, "VUID-VkComputePipelineCreateInfo-stage-00701",
2767                              "vkCreateComputePipelines(): the pCreateInfo[%u].stage.stage (%s) is not VK_SHADER_STAGE_COMPUTE_BIT",
2768                              i, string_VkShaderStageFlagBits(pCreateInfos[i].stage.stage));
2769         }
2770     }
2771     return skip;
2772 }
2773 
manual_PreCallValidateCreateSampler(VkDevice device,const VkSamplerCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSampler * pSampler) const2774 bool StatelessValidation::manual_PreCallValidateCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2775                                                               const VkAllocationCallbacks *pAllocator, VkSampler *pSampler) const {
2776     bool skip = false;
2777 
2778     if (pCreateInfo != nullptr) {
2779         const auto &features = physical_device_features;
2780         const auto &limits = device_limits;
2781 
2782         if (pCreateInfo->anisotropyEnable == VK_TRUE) {
2783             if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
2784                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-anisotropyEnable-01071",
2785                                  "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found.",
2786                                  "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
2787                                  "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy);
2788             }
2789 
2790             // Anistropy cannot be enabled in sampler unless enabled as a feature
2791             if (features.samplerAnisotropy == VK_FALSE) {
2792                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-anisotropyEnable-01070",
2793                                  "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE.",
2794                                  "pCreateInfo->anisotropyEnable");
2795             }
2796         }
2797 
2798         if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
2799             if (pCreateInfo->minFilter != pCreateInfo->magFilter) {
2800                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072",
2801                                  "vkCreateSampler(): when pCreateInfo->unnormalizedCoordinates is VK_TRUE, "
2802                                  "pCreateInfo->minFilter (%s) and pCreateInfo->magFilter (%s) must be equal.",
2803                                  string_VkFilter(pCreateInfo->minFilter), string_VkFilter(pCreateInfo->magFilter));
2804             }
2805             if (pCreateInfo->mipmapMode != VK_SAMPLER_MIPMAP_MODE_NEAREST) {
2806                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01073",
2807                                  "vkCreateSampler(): when pCreateInfo->unnormalizedCoordinates is VK_TRUE, "
2808                                  "pCreateInfo->mipmapMode (%s) must be VK_SAMPLER_MIPMAP_MODE_NEAREST.",
2809                                  string_VkSamplerMipmapMode(pCreateInfo->mipmapMode));
2810             }
2811             if (pCreateInfo->minLod != 0.0f || pCreateInfo->maxLod != 0.0f) {
2812                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074",
2813                                  "vkCreateSampler(): when pCreateInfo->unnormalizedCoordinates is VK_TRUE, "
2814                                  "pCreateInfo->minLod (%f) and pCreateInfo->maxLod (%f) must both be zero.",
2815                                  pCreateInfo->minLod, pCreateInfo->maxLod);
2816             }
2817             if ((pCreateInfo->addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE &&
2818                  pCreateInfo->addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2819                 (pCreateInfo->addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE &&
2820                  pCreateInfo->addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2821                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075",
2822                                  "vkCreateSampler(): when pCreateInfo->unnormalizedCoordinates is VK_TRUE, "
2823                                  "pCreateInfo->addressModeU (%s) and pCreateInfo->addressModeV (%s) must both be "
2824                                  "VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE or VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER.",
2825                                  string_VkSamplerAddressMode(pCreateInfo->addressModeU),
2826                                  string_VkSamplerAddressMode(pCreateInfo->addressModeV));
2827             }
2828             if (pCreateInfo->anisotropyEnable == VK_TRUE) {
2829                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076",
2830                                  "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates must "
2831                                  "not both be VK_TRUE.");
2832             }
2833             if (pCreateInfo->compareEnable == VK_TRUE) {
2834                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01077",
2835                                  "vkCreateSampler(): pCreateInfo->compareEnable and pCreateInfo->unnormalizedCoordinates must "
2836                                  "not both be VK_TRUE.");
2837             }
2838         }
2839 
2840         // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
2841         if (pCreateInfo->compareEnable == VK_TRUE) {
2842             skip |= validate_ranged_enum("vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp", AllVkCompareOpEnums,
2843                                          pCreateInfo->compareOp, "VUID-VkSamplerCreateInfo-compareEnable-01080");
2844             const auto *sampler_reduction = lvl_find_in_chain<VkSamplerReductionModeCreateInfo>(pCreateInfo->pNext);
2845             if (sampler_reduction != nullptr) {
2846                 if (sampler_reduction->reductionMode != VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE) {
2847                     skip |= LogError(
2848                         device, "VUID-VkSamplerCreateInfo-compareEnable-01423",
2849                         "copmareEnable is true so the sampler reduction mode must be VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE.");
2850                 }
2851             }
2852         }
2853 
2854         // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
2855         // valid VkBorderColor value
2856         if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2857             (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
2858             (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
2859             skip |= validate_ranged_enum("vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor", AllVkBorderColorEnums,
2860                                          pCreateInfo->borderColor, "VUID-VkSamplerCreateInfo-addressModeU-01078");
2861         }
2862 
2863         // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
2864         // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
2865         if (!device_extensions.vk_khr_sampler_mirror_clamp_to_edge &&
2866             ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2867              (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
2868              (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
2869             skip |=
2870                 LogError(device, "VUID-VkSamplerCreateInfo-addressModeU-01079",
2871                          "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
2872                          "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled.");
2873         }
2874 
2875         // Checks for the IMG cubic filtering extension
2876         if (device_extensions.vk_img_filter_cubic) {
2877             if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
2878                 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
2879                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-magFilter-01081",
2880                                  "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter "
2881                                  "are VK_FILTER_CUBIC_IMG.");
2882             }
2883         }
2884 
2885         // Check for valid Lod range
2886         if (pCreateInfo->minLod > pCreateInfo->maxLod) {
2887             skip |=
2888                 LogError(device, "VUID-VkSamplerCreateInfo-maxLod-01973",
2889                          "vkCreateSampler(): minLod (%f) is greater than maxLod (%f)", pCreateInfo->minLod, pCreateInfo->maxLod);
2890         }
2891 
2892         // Check mipLodBias to device limit
2893         if (pCreateInfo->mipLodBias > limits.maxSamplerLodBias) {
2894             skip |= LogError(device, "VUID-VkSamplerCreateInfo-mipLodBias-01069",
2895                              "vkCreateSampler(): mipLodBias (%f) is greater than VkPhysicalDeviceLimits::maxSamplerLodBias (%f)",
2896                              pCreateInfo->mipLodBias, limits.maxSamplerLodBias);
2897         }
2898 
2899         const auto *sampler_conversion = lvl_find_in_chain<VkSamplerYcbcrConversionInfo>(pCreateInfo->pNext);
2900         if (sampler_conversion != nullptr) {
2901             if ((pCreateInfo->addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) ||
2902                 (pCreateInfo->addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) ||
2903                 (pCreateInfo->addressModeW != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) ||
2904                 (pCreateInfo->anisotropyEnable != VK_FALSE) || (pCreateInfo->unnormalizedCoordinates != VK_FALSE)) {
2905                 skip |= LogError(
2906                     device, "VUID-VkSamplerCreateInfo-addressModeU-01646",
2907                     "vkCreateSampler():  SamplerYCbCrConversion is enabled: "
2908                     "addressModeU (%s), addressModeV (%s), addressModeW (%s) must be CLAMP_TO_EDGE, and anisotropyEnable (%s) "
2909                     "and unnormalizedCoordinates (%s) must be VK_FALSE.",
2910                     string_VkSamplerAddressMode(pCreateInfo->addressModeU), string_VkSamplerAddressMode(pCreateInfo->addressModeV),
2911                     string_VkSamplerAddressMode(pCreateInfo->addressModeW), pCreateInfo->anisotropyEnable ? "VK_TRUE" : "VK_FALSE",
2912                     pCreateInfo->unnormalizedCoordinates ? "VK_TRUE" : "VK_FALSE");
2913             }
2914         }
2915 
2916         if (pCreateInfo->flags & VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT) {
2917             if (pCreateInfo->minFilter != pCreateInfo->magFilter) {
2918                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02574",
2919                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2920                                  "pCreateInfo->minFilter (%s) and pCreateInfo->magFilter (%s) must be equal.",
2921                                  string_VkFilter(pCreateInfo->minFilter), string_VkFilter(pCreateInfo->magFilter));
2922             }
2923             if (pCreateInfo->mipmapMode != VK_SAMPLER_MIPMAP_MODE_NEAREST) {
2924                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02575",
2925                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2926                                  "pCreateInfo->mipmapMode (%s) must be VK_SAMPLER_MIPMAP_MODE_NEAREST.",
2927                                  string_VkSamplerMipmapMode(pCreateInfo->mipmapMode));
2928             }
2929             if (pCreateInfo->minLod != 0.0 || pCreateInfo->maxLod != 0.0) {
2930                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02576",
2931                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2932                                  "pCreateInfo->minLod (%f) and pCreateInfo->maxLod (%f) must be zero.",
2933                                  pCreateInfo->minLod, pCreateInfo->maxLod);
2934             }
2935             if (((pCreateInfo->addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) &&
2936                  (pCreateInfo->addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) ||
2937                 ((pCreateInfo->addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) &&
2938                  (pCreateInfo->addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER))) {
2939                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02577",
2940                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2941                                  "pCreateInfo->addressModeU (%s) and pCreateInfo->addressModeV (%s) must be "
2942                                  "VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE or VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER",
2943                                  string_VkSamplerAddressMode(pCreateInfo->addressModeU),
2944                                  string_VkSamplerAddressMode(pCreateInfo->addressModeV));
2945             }
2946             if (pCreateInfo->anisotropyEnable) {
2947                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02578",
2948                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2949                                  "pCreateInfo->anisotropyEnable must be VK_FALSE");
2950             }
2951             if (pCreateInfo->compareEnable) {
2952                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02579",
2953                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2954                                  "pCreateInfo->compareEnable must be VK_FALSE");
2955             }
2956             if (pCreateInfo->unnormalizedCoordinates) {
2957                 skip |= LogError(device, "VUID-VkSamplerCreateInfo-flags-02580",
2958                                  "vkCreateSampler(): when flags includes VK_SAMPLER_CREATE_SUBSAMPLED_BIT_EXT, "
2959                                  "pCreateInfo->unnormalizedCoordinates must be VK_FALSE");
2960             }
2961         }
2962     }
2963 
2964     if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2965         pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2966         if (!device_extensions.vk_ext_custom_border_color) {
2967             skip |= LogError(device, kVUID_PVError_ExtensionNotEnabled,
2968                              "VkSamplerCreateInfo->borderColor is %s but %s is not enabled.\n",
2969                              string_VkBorderColor(pCreateInfo->borderColor), VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
2970         }
2971         auto custom_create_info = lvl_find_in_chain<VkSamplerCustomBorderColorCreateInfoEXT>(pCreateInfo->pNext);
2972         if (!custom_create_info) {
2973             skip |=
2974                 LogError(device, "VUID-VkSamplerCreateInfo-borderColor-04011",
2975                          "VkSamplerCreateInfo->borderColor is set to %s but there is no VkSamplerCustomBorderColorCreateInfoEXT "
2976                          "struct in pNext chain.\n",
2977                          string_VkBorderColor(pCreateInfo->borderColor));
2978         } else {
2979             if ((custom_create_info->format != VK_FORMAT_UNDEFINED) &&
2980                 ((pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT && !FormatIsSampledInt(custom_create_info->format)) ||
2981                  (pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT &&
2982                   !FormatIsSampledFloat(custom_create_info->format)))) {
2983                 skip |= LogError(device, "VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-04013",
2984                                  "VkSamplerCreateInfo->borderColor is %s but VkSamplerCustomBorderColorCreateInfoEXT.format = %s "
2985                                  "whose type does not match\n",
2986                                  string_VkBorderColor(pCreateInfo->borderColor), string_VkFormat(custom_create_info->format));
2987                 ;
2988             }
2989         }
2990     }
2991 
2992     return skip;
2993 }
2994 
manual_PreCallValidateCreateDescriptorSetLayout(VkDevice device,const VkDescriptorSetLayoutCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorSetLayout * pSetLayout) const2995 bool StatelessValidation::manual_PreCallValidateCreateDescriptorSetLayout(VkDevice device,
2996                                                                           const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2997                                                                           const VkAllocationCallbacks *pAllocator,
2998                                                                           VkDescriptorSetLayout *pSetLayout) const {
2999     bool skip = false;
3000 
3001     // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
3002     if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
3003         for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
3004             if (pCreateInfo->pBindings[i].descriptorCount != 0) {
3005                 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
3006                      (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
3007                     (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
3008                     for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
3009                          ++descriptor_index) {
3010                         if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
3011                             skip |= LogError(device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-00282",
3012                                              "vkCreateDescriptorSetLayout: required parameter "
3013                                              "pCreateInfo->pBindings[%d].pImmutableSamplers[%d] specified as VK_NULL_HANDLE",
3014                                              i, descriptor_index);
3015                         }
3016                     }
3017                 }
3018 
3019                 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
3020                 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
3021                     ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
3022                     skip |= LogError(device, "VUID-VkDescriptorSetLayoutBinding-descriptorCount-00283",
3023                                      "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
3024                                      "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits "
3025                                      "values.",
3026                                      i, i);
3027                 }
3028 
3029                 if ((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) &&
3030                     (pCreateInfo->pBindings[i].stageFlags != 0) &&
3031                     (pCreateInfo->pBindings[i].stageFlags != VK_SHADER_STAGE_FRAGMENT_BIT)) {
3032                     skip |=
3033                         LogError(device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-01510",
3034                                  "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0 and "
3035                                  "descriptorType is VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT then pCreateInfo->pBindings[%d].stageFlags "
3036                                  "must be 0 or VK_SHADER_STAGE_FRAGMENT_BIT but is currently %s",
3037                                  i, i, string_VkShaderStageFlags(pCreateInfo->pBindings[i].stageFlags).c_str());
3038                 }
3039             }
3040         }
3041     }
3042     return skip;
3043 }
3044 
manual_PreCallValidateFreeDescriptorSets(VkDevice device,VkDescriptorPool descriptorPool,uint32_t descriptorSetCount,const VkDescriptorSet * pDescriptorSets) const3045 bool StatelessValidation::manual_PreCallValidateFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool,
3046                                                                    uint32_t descriptorSetCount,
3047                                                                    const VkDescriptorSet *pDescriptorSets) const {
3048     // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
3049     // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
3050     // validate_array()
3051     return validate_array("vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount, &pDescriptorSets,
3052                           true, true, kVUIDUndefined, kVUIDUndefined);
3053 }
3054 
validate_WriteDescriptorSet(const char * vkCallingFunction,const uint32_t descriptorWriteCount,const VkWriteDescriptorSet * pDescriptorWrites,const bool validateDstSet) const3055 bool StatelessValidation::validate_WriteDescriptorSet(const char *vkCallingFunction, const uint32_t descriptorWriteCount,
3056                                                       const VkWriteDescriptorSet *pDescriptorWrites,
3057                                                       const bool validateDstSet) const {
3058     bool skip = false;
3059 
3060     if (pDescriptorWrites != NULL) {
3061         for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
3062             // descriptorCount must be greater than 0
3063             if (pDescriptorWrites[i].descriptorCount == 0) {
3064                 skip |=
3065                     LogError(device, "VUID-VkWriteDescriptorSet-descriptorCount-arraylength",
3066                              "%s(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0.", vkCallingFunction, i);
3067             }
3068 
3069             // If called from vkCmdPushDescriptorSetKHR, the dstSet member is ignored.
3070             if (validateDstSet) {
3071                 // dstSet must be a valid VkDescriptorSet handle
3072                 skip |= validate_required_handle(vkCallingFunction,
3073                                                  ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
3074                                                  pDescriptorWrites[i].dstSet);
3075             }
3076 
3077             if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
3078                 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
3079                 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
3080                 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
3081                 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
3082                 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
3083                 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
3084                 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures.
3085                 // Valid imageView handles are checked in ObjectLifetimes::ValidateDescriptorWrite.
3086                 if (pDescriptorWrites[i].pImageInfo == nullptr) {
3087                     skip |= LogError(device, "VUID-VkWriteDescriptorSet-descriptorType-00322",
3088                                      "%s(): if pDescriptorWrites[%d].descriptorType is "
3089                                      "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
3090                                      "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
3091                                      "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL.",
3092                                      vkCallingFunction, i, i);
3093                 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
3094                     // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
3095                     // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageLayout
3096                     // member of any given element of pImageInfo must be a valid VkImageLayout
3097                     for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
3098                          ++descriptor_index) {
3099                         skip |= validate_ranged_enum(vkCallingFunction,
3100                                                      ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
3101                                                                    ParameterName::IndexVector{i, descriptor_index}),
3102                                                      "VkImageLayout", AllVkImageLayoutEnums,
3103                                                      pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout, kVUIDUndefined);
3104                     }
3105                 }
3106             } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
3107                        (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
3108                        (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
3109                        (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3110                 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
3111                 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
3112                 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
3113                 // Valid buffer handles are checked in ObjectLifetimes::ValidateDescriptorWrite.
3114                 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
3115                     skip |= LogError(device, "VUID-VkWriteDescriptorSet-descriptorType-00324",
3116                                      "%s(): if pDescriptorWrites[%d].descriptorType is "
3117                                      "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
3118                                      "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
3119                                      "pDescriptorWrites[%d].pBufferInfo must not be NULL.",
3120                                      vkCallingFunction, i, i);
3121                 } else {
3122                     const auto *robustness2_features =
3123                         lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
3124                     if (robustness2_features && robustness2_features->nullDescriptor) {
3125                         for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount;
3126                              ++descriptorIndex) {
3127                             if (pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer == VK_NULL_HANDLE &&
3128                                 (pDescriptorWrites[i].pBufferInfo[descriptorIndex].offset != 0 ||
3129                                  pDescriptorWrites[i].pBufferInfo[descriptorIndex].range != VK_WHOLE_SIZE)) {
3130                                 skip |= LogError(device, "VUID-VkDescriptorBufferInfo-buffer-02999",
3131                                                  "%s(): if pDescriptorWrites[%d].buffer is VK_NULL_HANDLE, "
3132                                                  "offset (%" PRIu64 ") must be zero and range (%" PRIu64 ") must be VK_WHOLE_SIZE.",
3133                                                  vkCallingFunction, i, pDescriptorWrites[i].pBufferInfo[descriptorIndex].offset,
3134                                                  pDescriptorWrites[i].pBufferInfo[descriptorIndex].range);
3135                             }
3136                         }
3137                     }
3138                 }
3139             } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
3140                        (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
3141                 // Valid bufferView handles are checked in ObjectLifetimes::ValidateDescriptorWrite.
3142             }
3143 
3144             if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
3145                 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
3146                 VkDeviceSize uniformAlignment = device_limits.minUniformBufferOffsetAlignment;
3147                 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
3148                     if (pDescriptorWrites[i].pBufferInfo != NULL) {
3149                         if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
3150                             skip |=
3151                                 LogError(device, "VUID-VkWriteDescriptorSet-descriptorType-00327",
3152                                          "%s(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
3153                                          ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ".",
3154                                          vkCallingFunction, i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
3155                         }
3156                     }
3157                 }
3158             } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
3159                        (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
3160                 VkDeviceSize storageAlignment = device_limits.minStorageBufferOffsetAlignment;
3161                 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
3162                     if (pDescriptorWrites[i].pBufferInfo != NULL) {
3163                         if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
3164                             skip |=
3165                                 LogError(device, "VUID-VkWriteDescriptorSet-descriptorType-00328",
3166                                          "%s(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
3167                                          ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ".",
3168                                          vkCallingFunction, i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
3169                         }
3170                     }
3171                 }
3172             }
3173             // pNext chain must be either NULL or a pointer to a valid instance of VkWriteDescriptorSetAccelerationStructureKHR
3174             // or VkWriteDescriptorSetInlineUniformBlockEX
3175             if (pDescriptorWrites[i].pNext) {
3176                 if (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) {
3177                     const auto *pnext_struct =
3178                         lvl_find_in_chain<VkWriteDescriptorSetAccelerationStructureKHR>(pDescriptorWrites[i].pNext);
3179                     if (!pnext_struct || (pnext_struct->accelerationStructureCount != pDescriptorWrites[i].descriptorCount)) {
3180                         skip |= LogError(device, "VUID-VkWriteDescriptorSet-descriptorType-02382",
3181                                          "%s(): If descriptorType is VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, the pNext"
3182                                          "chain must include a VkWriteDescriptorSetAccelerationStructureKHR structure whose "
3183                                          "accelerationStructureCount %d member equals descriptorCount %d.",
3184                                          vkCallingFunction, pnext_struct ? pnext_struct->accelerationStructureCount : -1,
3185                                          pDescriptorWrites[i].descriptorCount);
3186                     }
3187                     // further checks only if we have right structtype
3188                     if (pnext_struct) {
3189                         if (pnext_struct->accelerationStructureCount != pDescriptorWrites[i].descriptorCount) {
3190                             skip |= LogError(
3191                                 device, "VUID-VkWriteDescriptorSetAccelerationStructureKHR-accelerationStructureCount-02236",
3192                                 "%s(): accelerationStructureCount %d must be equal to descriptorCount %d in the extended structure "
3193                                 ".",
3194                                 vkCallingFunction, pnext_struct->accelerationStructureCount, pDescriptorWrites[i].descriptorCount);
3195                         }
3196                         if (pnext_struct->accelerationStructureCount == 0) {
3197                             skip |= LogError(
3198                                 device, "VUID-VkWriteDescriptorSetAccelerationStructureKHR-accelerationStructureCount-arraylength",
3199                                 "%s(): accelerationStructureCount must be greater than 0 .");
3200                         }
3201                     }
3202                 }
3203             }
3204         }
3205     }
3206     return skip;
3207 }
3208 
manual_PreCallValidateUpdateDescriptorSets(VkDevice device,uint32_t descriptorWriteCount,const VkWriteDescriptorSet * pDescriptorWrites,uint32_t descriptorCopyCount,const VkCopyDescriptorSet * pDescriptorCopies) const3209 bool StatelessValidation::manual_PreCallValidateUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
3210                                                                      const VkWriteDescriptorSet *pDescriptorWrites,
3211                                                                      uint32_t descriptorCopyCount,
3212                                                                      const VkCopyDescriptorSet *pDescriptorCopies) const {
3213     return validate_WriteDescriptorSet("vkUpdateDescriptorSets", descriptorWriteCount, pDescriptorWrites);
3214 }
3215 
manual_PreCallValidateCreateRenderPass(VkDevice device,const VkRenderPassCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const3216 bool StatelessValidation::manual_PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3217                                                                  const VkAllocationCallbacks *pAllocator,
3218                                                                  VkRenderPass *pRenderPass) const {
3219     return CreateRenderPassGeneric(device, pCreateInfo, pAllocator, pRenderPass, RENDER_PASS_VERSION_1);
3220 }
3221 
manual_PreCallValidateCreateRenderPass2(VkDevice device,const VkRenderPassCreateInfo2 * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const3222 bool StatelessValidation::manual_PreCallValidateCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
3223                                                                   const VkAllocationCallbacks *pAllocator,
3224                                                                   VkRenderPass *pRenderPass) const {
3225     return CreateRenderPassGeneric(device, pCreateInfo, pAllocator, pRenderPass, RENDER_PASS_VERSION_2);
3226 }
3227 
manual_PreCallValidateCreateRenderPass2KHR(VkDevice device,const VkRenderPassCreateInfo2KHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass) const3228 bool StatelessValidation::manual_PreCallValidateCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
3229                                                                      const VkAllocationCallbacks *pAllocator,
3230                                                                      VkRenderPass *pRenderPass) const {
3231     return CreateRenderPassGeneric(device, pCreateInfo, pAllocator, pRenderPass, RENDER_PASS_VERSION_2);
3232 }
3233 
manual_PreCallValidateFreeCommandBuffers(VkDevice device,VkCommandPool commandPool,uint32_t commandBufferCount,const VkCommandBuffer * pCommandBuffers) const3234 bool StatelessValidation::manual_PreCallValidateFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
3235                                                                    uint32_t commandBufferCount,
3236                                                                    const VkCommandBuffer *pCommandBuffers) const {
3237     bool skip = false;
3238 
3239     // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
3240     // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
3241     // validate_array()
3242     skip |= validate_array("vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount, &pCommandBuffers,
3243                            true, true, kVUIDUndefined, kVUIDUndefined);
3244     return skip;
3245 }
3246 
manual_PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer,const VkCommandBufferBeginInfo * pBeginInfo) const3247 bool StatelessValidation::manual_PreCallValidateBeginCommandBuffer(VkCommandBuffer commandBuffer,
3248                                                                    const VkCommandBufferBeginInfo *pBeginInfo) const {
3249     bool skip = false;
3250 
3251     // VkCommandBufferInheritanceInfo validation, due to a 'noautovalidity' of pBeginInfo->pInheritanceInfo in vkBeginCommandBuffer
3252     const char *cmd_name = "vkBeginCommandBuffer";
3253     const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
3254 
3255     // Implicit VUs
3256     // validate only sType here; pointer has to be validated in core_validation
3257     const bool kNotRequired = false;
3258     const char *kNoVUID = nullptr;
3259     skip |= validate_struct_type(cmd_name, "pBeginInfo->pInheritanceInfo", "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO",
3260                                  pInfo, VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, kNotRequired, kNoVUID,
3261                                  "VUID-VkCommandBufferInheritanceInfo-sType-sType");
3262 
3263     if (pInfo) {
3264         const VkStructureType allowed_structs_VkCommandBufferInheritanceInfo[] = {
3265             VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_CONDITIONAL_RENDERING_INFO_EXT};
3266         skip |= validate_struct_pnext(
3267             cmd_name, "pBeginInfo->pInheritanceInfo->pNext", "VkCommandBufferInheritanceConditionalRenderingInfoEXT", pInfo->pNext,
3268             ARRAY_SIZE(allowed_structs_VkCommandBufferInheritanceInfo), allowed_structs_VkCommandBufferInheritanceInfo,
3269             GeneratedVulkanHeaderVersion, "VUID-VkCommandBufferInheritanceInfo-pNext-pNext",
3270             "VUID-VkCommandBufferInheritanceInfo-sType-unique");
3271 
3272         skip |= validate_bool32(cmd_name, "pBeginInfo->pInheritanceInfo->occlusionQueryEnable", pInfo->occlusionQueryEnable);
3273 
3274         // Explicit VUs
3275         if (!physical_device_features.inheritedQueries && pInfo->occlusionQueryEnable == VK_TRUE) {
3276             skip |= LogError(
3277                 commandBuffer, "VUID-VkCommandBufferInheritanceInfo-occlusionQueryEnable-00056",
3278                 "%s: Inherited queries feature is disabled, but pBeginInfo->pInheritanceInfo->occlusionQueryEnable is VK_TRUE.",
3279                 cmd_name);
3280         }
3281 
3282         if (physical_device_features.inheritedQueries) {
3283             skip |= validate_flags(cmd_name, "pBeginInfo->pInheritanceInfo->queryFlags", "VkQueryControlFlagBits",
3284                                    AllVkQueryControlFlagBits, pInfo->queryFlags, kOptionalFlags,
3285                                    "VUID-VkCommandBufferInheritanceInfo-queryFlags-00057");
3286         } else {  // !inheritedQueries
3287             skip |= validate_reserved_flags(cmd_name, "pBeginInfo->pInheritanceInfo->queryFlags", pInfo->queryFlags,
3288                                             "VUID-VkCommandBufferInheritanceInfo-queryFlags-02788");
3289         }
3290 
3291         if (physical_device_features.pipelineStatisticsQuery) {
3292             skip |= validate_flags(cmd_name, "pBeginInfo->pInheritanceInfo->pipelineStatistics", "VkQueryPipelineStatisticFlagBits",
3293                                    AllVkQueryPipelineStatisticFlagBits, pInfo->pipelineStatistics, kOptionalFlags,
3294                                    "VUID-VkCommandBufferInheritanceInfo-pipelineStatistics-02789");
3295         } else {  // !pipelineStatisticsQuery
3296             skip |= validate_reserved_flags(cmd_name, "pBeginInfo->pInheritanceInfo->pipelineStatistics", pInfo->pipelineStatistics,
3297                                             "VUID-VkCommandBufferInheritanceInfo-pipelineStatistics-00058");
3298         }
3299 
3300         const auto *conditional_rendering = lvl_find_in_chain<VkCommandBufferInheritanceConditionalRenderingInfoEXT>(pInfo->pNext);
3301         if (conditional_rendering) {
3302             const auto *cr_features = lvl_find_in_chain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(device_createinfo_pnext);
3303             const auto inherited_conditional_rendering = cr_features && cr_features->inheritedConditionalRendering;
3304             if (!inherited_conditional_rendering && conditional_rendering->conditionalRenderingEnable == VK_TRUE) {
3305                 skip |= LogError(
3306                     commandBuffer, "VUID-VkCommandBufferInheritanceConditionalRenderingInfoEXT-conditionalRenderingEnable-01977",
3307                     "vkBeginCommandBuffer: Inherited conditional rendering is disabled, but "
3308                     "pBeginInfo->pInheritanceInfo->pNext<VkCommandBufferInheritanceConditionalRenderingInfoEXT> is VK_TRUE.");
3309             }
3310         }
3311     }
3312 
3313     return skip;
3314 }
3315 
manual_PreCallValidateCmdSetViewport(VkCommandBuffer commandBuffer,uint32_t firstViewport,uint32_t viewportCount,const VkViewport * pViewports) const3316 bool StatelessValidation::manual_PreCallValidateCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
3317                                                                uint32_t viewportCount, const VkViewport *pViewports) const {
3318     bool skip = false;
3319 
3320     if (!physical_device_features.multiViewport) {
3321         if (firstViewport != 0) {
3322             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewport-firstViewport-01224",
3323                              "vkCmdSetViewport: The multiViewport feature is disabled, but firstViewport (=%" PRIu32 ") is not 0.",
3324                              firstViewport);
3325         }
3326         if (viewportCount > 1) {
3327             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewport-viewportCount-01225",
3328                              "vkCmdSetViewport: The multiViewport feature is disabled, but viewportCount (=%" PRIu32 ") is not 1.",
3329                              viewportCount);
3330         }
3331     } else {  // multiViewport enabled
3332         const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
3333         if (sum > device_limits.maxViewports) {
3334             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewport-firstViewport-01223",
3335                              "vkCmdSetViewport: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
3336                              ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
3337                              firstViewport, viewportCount, sum, device_limits.maxViewports);
3338         }
3339     }
3340 
3341     if (pViewports) {
3342         for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
3343             const auto &viewport = pViewports[viewport_i];  // will crash on invalid ptr
3344             const char *fn_name = "vkCmdSetViewport";
3345             skip |= manual_PreCallValidateViewport(
3346                 viewport, fn_name, ParameterName("pViewports[%i]", ParameterName::IndexVector{viewport_i}), commandBuffer);
3347         }
3348     }
3349 
3350     return skip;
3351 }
3352 
manual_PreCallValidateCmdSetScissor(VkCommandBuffer commandBuffer,uint32_t firstScissor,uint32_t scissorCount,const VkRect2D * pScissors) const3353 bool StatelessValidation::manual_PreCallValidateCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor,
3354                                                               uint32_t scissorCount, const VkRect2D *pScissors) const {
3355     bool skip = false;
3356 
3357     if (!physical_device_features.multiViewport) {
3358         if (firstScissor != 0) {
3359             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-firstScissor-00593",
3360                              "vkCmdSetScissor: The multiViewport feature is disabled, but firstScissor (=%" PRIu32 ") is not 0.",
3361                              firstScissor);
3362         }
3363         if (scissorCount > 1) {
3364             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-scissorCount-00594",
3365                              "vkCmdSetScissor: The multiViewport feature is disabled, but scissorCount (=%" PRIu32 ") is not 1.",
3366                              scissorCount);
3367         }
3368     } else {  // multiViewport enabled
3369         const uint64_t sum = static_cast<uint64_t>(firstScissor) + static_cast<uint64_t>(scissorCount);
3370         if (sum > device_limits.maxViewports) {
3371             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-firstScissor-00592",
3372                              "vkCmdSetScissor: firstScissor + scissorCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
3373                              ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
3374                              firstScissor, scissorCount, sum, device_limits.maxViewports);
3375         }
3376     }
3377 
3378     if (pScissors) {
3379         for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
3380             const auto &scissor = pScissors[scissor_i];  // will crash on invalid ptr
3381 
3382             if (scissor.offset.x < 0) {
3383                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-x-00595",
3384                                  "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative.", scissor_i,
3385                                  scissor.offset.x);
3386             }
3387 
3388             if (scissor.offset.y < 0) {
3389                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-x-00595",
3390                                  "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative.", scissor_i,
3391                                  scissor.offset.y);
3392             }
3393 
3394             const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
3395             if (x_sum > INT32_MAX) {
3396                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-offset-00596",
3397                                  "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
3398                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
3399                                  scissor.offset.x, scissor.extent.width, x_sum, scissor_i);
3400             }
3401 
3402             const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
3403             if (y_sum > INT32_MAX) {
3404                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissor-offset-00597",
3405                                  "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
3406                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
3407                                  scissor.offset.y, scissor.extent.height, y_sum, scissor_i);
3408             }
3409         }
3410     }
3411 
3412     return skip;
3413 }
3414 
manual_PreCallValidateCmdSetLineWidth(VkCommandBuffer commandBuffer,float lineWidth) const3415 bool StatelessValidation::manual_PreCallValidateCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) const {
3416     bool skip = false;
3417 
3418     if (!physical_device_features.wideLines && (lineWidth != 1.0f)) {
3419         skip |= LogError(commandBuffer, "VUID-vkCmdSetLineWidth-lineWidth-00788",
3420                          "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0.", lineWidth);
3421     }
3422 
3423     return skip;
3424 }
3425 
manual_PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,uint32_t count,uint32_t stride) const3426 bool StatelessValidation::manual_PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3427                                                                 uint32_t count, uint32_t stride) const {
3428     bool skip = false;
3429 
3430     if (!physical_device_features.multiDrawIndirect && ((count > 1))) {
3431         skip |= LogError(device, "VUID-vkCmdDrawIndirect-drawCount-02718",
3432                          "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
3433     }
3434     return skip;
3435 }
3436 
manual_PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,uint32_t count,uint32_t stride) const3437 bool StatelessValidation::manual_PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3438                                                                        VkDeviceSize offset, uint32_t count, uint32_t stride) const {
3439     bool skip = false;
3440     if (!physical_device_features.multiDrawIndirect && ((count > 1))) {
3441         skip |=
3442             LogError(device, "VUID-vkCmdDrawIndexedIndirect-drawCount-02718",
3443                      "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
3444     }
3445     return skip;
3446 }
3447 
ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer,VkDeviceSize offset,VkDeviceSize countBufferOffset,bool khr) const3448 bool StatelessValidation::ValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkDeviceSize offset,
3449                                                        VkDeviceSize countBufferOffset, bool khr) const {
3450     bool skip = false;
3451     const char *apiName = khr ? "vkCmdDrawIndirectCountKHR()" : "vkCmdDrawIndirectCount()";
3452     if (offset & 3) {
3453         skip |= LogError(commandBuffer, "VUID-vkCmdDrawIndirectCount-offset-02710",
3454                          "%s: parameter, VkDeviceSize offset (0x%" PRIxLEAST64 "), is not a multiple of 4.", apiName, offset);
3455     }
3456 
3457     if (countBufferOffset & 3) {
3458         skip |= LogError(commandBuffer, "VUID-vkCmdDrawIndirectCount-countBufferOffset-02716",
3459                          "%s: parameter, VkDeviceSize countBufferOffset (0x%" PRIxLEAST64 "), is not a multiple of 4.", apiName,
3460                          countBufferOffset);
3461     }
3462     return skip;
3463 }
3464 
manual_PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkBuffer countBuffer,VkDeviceSize countBufferOffset,uint32_t maxDrawCount,uint32_t stride) const3465 bool StatelessValidation::manual_PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
3466                                                                      VkDeviceSize offset, VkBuffer countBuffer,
3467                                                                      VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3468                                                                      uint32_t stride) const {
3469     return ValidateCmdDrawIndirectCount(commandBuffer, offset, countBufferOffset, false);
3470 }
3471 
manual_PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkBuffer countBuffer,VkDeviceSize countBufferOffset,uint32_t maxDrawCount,uint32_t stride) const3472 bool StatelessValidation::manual_PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3473                                                                         VkDeviceSize offset, VkBuffer countBuffer,
3474                                                                         VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3475                                                                         uint32_t stride) const {
3476     return ValidateCmdDrawIndirectCount(commandBuffer, offset, countBufferOffset, true);
3477 }
3478 
ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer,VkDeviceSize offset,VkDeviceSize countBufferOffset,bool khr) const3479 bool StatelessValidation::ValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkDeviceSize offset,
3480                                                               VkDeviceSize countBufferOffset, bool khr) const {
3481     bool skip = false;
3482     const char *apiName = khr ? "vkCmdDrawIndexedIndirectCountKHR()" : "vkCmdDrawIndexedIndirectCount()";
3483     if (offset & 3) {
3484         skip |= LogError(commandBuffer, "VUID-vkCmdDrawIndexedIndirectCount-offset-02710",
3485                          "%s: parameter, VkDeviceSize offset (0x%" PRIxLEAST64 "), is not a multiple of 4.", apiName, offset);
3486     }
3487 
3488     if (countBufferOffset & 3) {
3489         skip |= LogError(commandBuffer, "VUID-vkCmdDrawIndexedIndirectCount-countBufferOffset-02716",
3490                          "%s: parameter, VkDeviceSize countBufferOffset (0x%" PRIxLEAST64 "), is not a multiple of 4.", apiName,
3491                          countBufferOffset);
3492     }
3493     return skip;
3494 }
3495 
manual_PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkBuffer countBuffer,VkDeviceSize countBufferOffset,uint32_t maxDrawCount,uint32_t stride) const3496 bool StatelessValidation::manual_PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
3497                                                                             VkDeviceSize offset, VkBuffer countBuffer,
3498                                                                             VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3499                                                                             uint32_t stride) const {
3500     return ValidateCmdDrawIndexedIndirectCount(commandBuffer, offset, countBufferOffset, false);
3501 }
3502 
manual_PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkBuffer countBuffer,VkDeviceSize countBufferOffset,uint32_t maxDrawCount,uint32_t stride) const3503 bool StatelessValidation::manual_PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3504                                                                                VkDeviceSize offset, VkBuffer countBuffer,
3505                                                                                VkDeviceSize countBufferOffset,
3506                                                                                uint32_t maxDrawCount, uint32_t stride) const {
3507     return ValidateCmdDrawIndexedIndirectCount(commandBuffer, offset, countBufferOffset, true);
3508 }
3509 
manual_PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer,uint32_t attachmentCount,const VkClearAttachment * pAttachments,uint32_t rectCount,const VkClearRect * pRects) const3510 bool StatelessValidation::manual_PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
3511                                                                     const VkClearAttachment *pAttachments, uint32_t rectCount,
3512                                                                     const VkClearRect *pRects) const {
3513     bool skip = false;
3514     for (uint32_t rect = 0; rect < rectCount; rect++) {
3515         if (pRects[rect].layerCount == 0) {
3516             skip |= LogError(commandBuffer, "VUID-vkCmdClearAttachments-layerCount-01934",
3517                              "CmdClearAttachments(): pRects[%d].layerCount is zero.", rect);
3518         }
3519         if (pRects[rect].rect.extent.width == 0) {
3520             skip |= LogError(commandBuffer, "VUID-vkCmdClearAttachments-rect-02682",
3521                              "CmdClearAttachments(): pRects[%d].rect.extent.width is zero.", rect);
3522         }
3523         if (pRects[rect].rect.extent.height == 0) {
3524             skip |= LogError(commandBuffer, "VUID-vkCmdClearAttachments-rect-02683",
3525                              "CmdClearAttachments(): pRects[%d].rect.extent.height is zero.", rect);
3526         }
3527     }
3528     return skip;
3529 }
3530 
ValidateGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkImageFormatProperties2 * pImageFormatProperties,const char * apiName) const3531 bool StatelessValidation::ValidateGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,
3532                                                                           const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
3533                                                                           VkImageFormatProperties2 *pImageFormatProperties,
3534                                                                           const char *apiName) const {
3535     bool skip = false;
3536 
3537     if (pImageFormatInfo != nullptr) {
3538         const auto image_stencil_struct = lvl_find_in_chain<VkImageStencilUsageCreateInfoEXT>(pImageFormatInfo->pNext);
3539         if (image_stencil_struct != nullptr) {
3540             if ((image_stencil_struct->stencilUsage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0) {
3541                 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
3542                 // No flags other than the legal attachment bits may be set
3543                 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
3544                 if ((image_stencil_struct->stencilUsage & ~legal_flags) != 0) {
3545                     skip |= LogError(physicalDevice, "VUID-VkImageStencilUsageCreateInfo-stencilUsage-02539",
3546                                      "%s(): in pNext chain, VkImageStencilUsageCreateInfo::stencilUsage "
3547                                      "includes VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, it must not include bits other than "
3548                                      "VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT",
3549                                      apiName);
3550                 }
3551             }
3552         }
3553     }
3554 
3555     return skip;
3556 }
3557 
manual_PreCallValidateGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkImageFormatProperties2 * pImageFormatProperties) const3558 bool StatelessValidation::manual_PreCallValidateGetPhysicalDeviceImageFormatProperties2(
3559     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
3560     VkImageFormatProperties2 *pImageFormatProperties) const {
3561     return ValidateGetPhysicalDeviceImageFormatProperties2(physicalDevice, pImageFormatInfo, pImageFormatProperties,
3562                                                            "vkGetPhysicalDeviceImageFormatProperties2");
3563 }
3564 
manual_PreCallValidateGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice physicalDevice,const VkPhysicalDeviceImageFormatInfo2 * pImageFormatInfo,VkImageFormatProperties2 * pImageFormatProperties) const3565 bool StatelessValidation::manual_PreCallValidateGetPhysicalDeviceImageFormatProperties2KHR(
3566     VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
3567     VkImageFormatProperties2 *pImageFormatProperties) const {
3568     return ValidateGetPhysicalDeviceImageFormatProperties2(physicalDevice, pImageFormatInfo, pImageFormatProperties,
3569                                                            "vkGetPhysicalDeviceImageFormatProperties2KHR");
3570 }
3571 
manual_PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer,VkBuffer srcBuffer,VkBuffer dstBuffer,uint32_t regionCount,const VkBufferCopy * pRegions) const3572 bool StatelessValidation::manual_PreCallValidateCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
3573                                                               uint32_t regionCount, const VkBufferCopy *pRegions) const {
3574     bool skip = false;
3575 
3576     if (pRegions != nullptr) {
3577         for (uint32_t i = 0; i < regionCount; i++) {
3578             if (pRegions[i].size == 0) {
3579                 skip |= LogError(device, "VUID-VkBufferCopy-size-01988",
3580                                  "vkCmdCopyBuffer() pRegions[%u].size must be greater than zero", i);
3581             }
3582         }
3583     }
3584     return skip;
3585 }
3586 
manual_PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,const VkCopyBufferInfo2KHR * pCopyBufferInfo) const3587 bool StatelessValidation::manual_PreCallValidateCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
3588                                                                   const VkCopyBufferInfo2KHR *pCopyBufferInfo) const {
3589     bool skip = false;
3590 
3591     if (pCopyBufferInfo->pRegions != nullptr) {
3592         for (uint32_t i = 0; i < pCopyBufferInfo->regionCount; i++) {
3593             if (pCopyBufferInfo->pRegions[i].size == 0) {
3594                 skip |= LogError(device, "VUID-VkBufferCopy2KHR-size-01988",
3595                                  "vkCmdCopyBuffer2KHR() pCopyBufferInfo->pRegions[%u].size must be greater than zero", i);
3596             }
3597         }
3598     }
3599     return skip;
3600 }
3601 
manual_PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer,VkBuffer dstBuffer,VkDeviceSize dstOffset,VkDeviceSize dataSize,const void * pData) const3602 bool StatelessValidation::manual_PreCallValidateCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
3603                                                                 VkDeviceSize dstOffset, VkDeviceSize dataSize,
3604                                                                 const void *pData) const {
3605     bool skip = false;
3606 
3607     if (dstOffset & 3) {
3608         skip |= LogError(device, "VUID-vkCmdUpdateBuffer-dstOffset-00036",
3609                          "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4.",
3610                          dstOffset);
3611     }
3612 
3613     if ((dataSize <= 0) || (dataSize > 65536)) {
3614         skip |= LogError(device, "VUID-vkCmdUpdateBuffer-dataSize-00037",
3615                          "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
3616                          "), must be greater than zero and less than or equal to 65536.",
3617                          dataSize);
3618     } else if (dataSize & 3) {
3619         skip |= LogError(device, "VUID-vkCmdUpdateBuffer-dataSize-00038",
3620                          "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4.",
3621                          dataSize);
3622     }
3623     return skip;
3624 }
3625 
manual_PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer,VkBuffer dstBuffer,VkDeviceSize dstOffset,VkDeviceSize size,uint32_t data) const3626 bool StatelessValidation::manual_PreCallValidateCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
3627                                                               VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) const {
3628     bool skip = false;
3629 
3630     if (dstOffset & 3) {
3631         skip |= LogError(device, "VUID-vkCmdFillBuffer-dstOffset-00025",
3632                          "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4.",
3633                          dstOffset);
3634     }
3635 
3636     if (size != VK_WHOLE_SIZE) {
3637         if (size <= 0) {
3638             skip |=
3639                 LogError(device, "VUID-vkCmdFillBuffer-size-00026",
3640                          "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero.", size);
3641         } else if (size & 3) {
3642             skip |= LogError(device, "VUID-vkCmdFillBuffer-size-00028",
3643                              "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4.", size);
3644         }
3645     }
3646     return skip;
3647 }
3648 
manual_PreCallValidateCreateSwapchainKHR(VkDevice device,const VkSwapchainCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSwapchainKHR * pSwapchain) const3649 bool StatelessValidation::manual_PreCallValidateCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3650                                                                    const VkAllocationCallbacks *pAllocator,
3651                                                                    VkSwapchainKHR *pSwapchain) const {
3652     bool skip = false;
3653 
3654     if (pCreateInfo != nullptr) {
3655         // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
3656         if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
3657             // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
3658             if (pCreateInfo->queueFamilyIndexCount <= 1) {
3659                 skip |= LogError(device, "VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01278",
3660                                  "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
3661                                  "pCreateInfo->queueFamilyIndexCount must be greater than 1.");
3662             }
3663 
3664             // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
3665             // queueFamilyIndexCount uint32_t values
3666             if (pCreateInfo->pQueueFamilyIndices == nullptr) {
3667                 skip |= LogError(device, "VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01277",
3668                                  "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
3669                                  "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
3670                                  "pCreateInfo->queueFamilyIndexCount uint32_t values.");
3671             }
3672         }
3673 
3674         skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers",
3675                                         "VUID-VkSwapchainCreateInfoKHR-imageArrayLayers-01275", "vkCreateSwapchainKHR");
3676     }
3677 
3678     return skip;
3679 }
3680 
manual_PreCallValidateQueuePresentKHR(VkQueue queue,const VkPresentInfoKHR * pPresentInfo) const3681 bool StatelessValidation::manual_PreCallValidateQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) const {
3682     bool skip = false;
3683 
3684     if (pPresentInfo && pPresentInfo->pNext) {
3685         const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
3686         if (present_regions) {
3687             // TODO: This and all other pNext extension dependencies should be added to code-generation
3688             skip |= require_device_extension(IsExtEnabled(device_extensions.vk_khr_incremental_present), "vkQueuePresentKHR",
3689                                              VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
3690             if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
3691                 skip |= LogError(device, "VUID-VkPresentRegionsKHR-swapchainCount-01260",
3692                                  "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i but VkPresentRegionsKHR "
3693                                  "extension swapchainCount is %i. These values must be equal.",
3694                                  pPresentInfo->swapchainCount, present_regions->swapchainCount);
3695             }
3696             skip |= validate_struct_pnext("QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL, present_regions->pNext, 0, NULL,
3697                                           GeneratedVulkanHeaderVersion, "VUID-VkPresentInfoKHR-pNext-pNext",
3698                                           "VUID-VkPresentInfoKHR-sType-unique");
3699             skip |= validate_array("QueuePresentKHR", "pCreateInfo->pNext->swapchainCount", "pCreateInfo->pNext->pRegions",
3700                                    present_regions->swapchainCount, &present_regions->pRegions, true, false, kVUIDUndefined,
3701                                    kVUIDUndefined);
3702             for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
3703                 skip |= validate_array("QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
3704                                        "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
3705                                        &present_regions->pRegions[i].pRectangles, true, false, kVUIDUndefined, kVUIDUndefined);
3706             }
3707         }
3708     }
3709 
3710     return skip;
3711 }
3712 
3713 #ifdef VK_USE_PLATFORM_WIN32_KHR
manual_PreCallValidateCreateWin32SurfaceKHR(VkInstance instance,const VkWin32SurfaceCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSurfaceKHR * pSurface) const3714 bool StatelessValidation::manual_PreCallValidateCreateWin32SurfaceKHR(VkInstance instance,
3715                                                                       const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3716                                                                       const VkAllocationCallbacks *pAllocator,
3717                                                                       VkSurfaceKHR *pSurface) const {
3718     bool skip = false;
3719 
3720     if (pCreateInfo->hwnd == nullptr) {
3721         skip |= LogError(device, "VUID-VkWin32SurfaceCreateInfoKHR-hwnd-01308",
3722                          "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL.");
3723     }
3724 
3725     return skip;
3726 }
3727 #endif  // VK_USE_PLATFORM_WIN32_KHR
3728 
manual_PreCallValidateCreateDescriptorPool(VkDevice device,const VkDescriptorPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkDescriptorPool * pDescriptorPool) const3729 bool StatelessValidation::manual_PreCallValidateCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
3730                                                                      const VkAllocationCallbacks *pAllocator,
3731                                                                      VkDescriptorPool *pDescriptorPool) const {
3732     bool skip = false;
3733 
3734     if (pCreateInfo) {
3735         if (pCreateInfo->maxSets <= 0) {
3736             skip |= LogError(device, "VUID-VkDescriptorPoolCreateInfo-maxSets-00301",
3737                              "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0.");
3738         }
3739 
3740         if (pCreateInfo->pPoolSizes) {
3741             for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
3742                 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
3743                     skip |= LogError(
3744                         device, "VUID-VkDescriptorPoolSize-descriptorCount-00302",
3745                         "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0.", i);
3746                 }
3747                 if (pCreateInfo->pPoolSizes[i].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT &&
3748                     (pCreateInfo->pPoolSizes[i].descriptorCount % 4) != 0) {
3749                     skip |= LogError(device, "VUID-VkDescriptorPoolSize-type-02218",
3750                                      "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32
3751                                      "].type is VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT "
3752                                      " and pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not a multiple of 4.",
3753                                      i, i);
3754                 }
3755             }
3756         }
3757     }
3758 
3759     return skip;
3760 }
3761 
manual_PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer,uint32_t groupCountX,uint32_t groupCountY,uint32_t groupCountZ) const3762 bool StatelessValidation::manual_PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX,
3763                                                             uint32_t groupCountY, uint32_t groupCountZ) const {
3764     bool skip = false;
3765 
3766     if (groupCountX > device_limits.maxComputeWorkGroupCount[0]) {
3767         skip |=
3768             LogError(commandBuffer, "VUID-vkCmdDispatch-groupCountX-00386",
3769                      "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").",
3770                      groupCountX, device_limits.maxComputeWorkGroupCount[0]);
3771     }
3772 
3773     if (groupCountY > device_limits.maxComputeWorkGroupCount[1]) {
3774         skip |=
3775             LogError(commandBuffer, "VUID-vkCmdDispatch-groupCountY-00387",
3776                      "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").",
3777                      groupCountY, device_limits.maxComputeWorkGroupCount[1]);
3778     }
3779 
3780     if (groupCountZ > device_limits.maxComputeWorkGroupCount[2]) {
3781         skip |=
3782             LogError(commandBuffer, "VUID-vkCmdDispatch-groupCountZ-00388",
3783                      "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").",
3784                      groupCountZ, device_limits.maxComputeWorkGroupCount[2]);
3785     }
3786 
3787     return skip;
3788 }
3789 
manual_PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset) const3790 bool StatelessValidation::manual_PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3791                                                                     VkDeviceSize offset) const {
3792     bool skip = false;
3793 
3794     if ((offset % 4) != 0) {
3795         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchIndirect-offset-02710",
3796                          "vkCmdDispatchIndirect(): offset (%" PRIu64 ") must be a multiple of 4.", offset);
3797     }
3798     return skip;
3799 }
3800 
manual_PreCallValidateCmdDispatchBaseKHR(VkCommandBuffer commandBuffer,uint32_t baseGroupX,uint32_t baseGroupY,uint32_t baseGroupZ,uint32_t groupCountX,uint32_t groupCountY,uint32_t groupCountZ) const3801 bool StatelessValidation::manual_PreCallValidateCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX,
3802                                                                    uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX,
3803                                                                    uint32_t groupCountY, uint32_t groupCountZ) const {
3804     bool skip = false;
3805 
3806     // Paired if {} else if {} tests used to avoid any possible uint underflow
3807     uint32_t limit = device_limits.maxComputeWorkGroupCount[0];
3808     if (baseGroupX >= limit) {
3809         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-baseGroupX-00421",
3810                          "vkCmdDispatch(): baseGroupX (%" PRIu32
3811                          ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").",
3812                          baseGroupX, limit);
3813     } else if (groupCountX > (limit - baseGroupX)) {
3814         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-groupCountX-00424",
3815                          "vkCmdDispatchBaseKHR(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
3816                          ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").",
3817                          baseGroupX, groupCountX, limit);
3818     }
3819 
3820     limit = device_limits.maxComputeWorkGroupCount[1];
3821     if (baseGroupY >= limit) {
3822         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-baseGroupX-00422",
3823                          "vkCmdDispatch(): baseGroupY (%" PRIu32
3824                          ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").",
3825                          baseGroupY, limit);
3826     } else if (groupCountY > (limit - baseGroupY)) {
3827         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-groupCountY-00425",
3828                          "vkCmdDispatchBaseKHR(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
3829                          ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").",
3830                          baseGroupY, groupCountY, limit);
3831     }
3832 
3833     limit = device_limits.maxComputeWorkGroupCount[2];
3834     if (baseGroupZ >= limit) {
3835         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-baseGroupZ-00423",
3836                          "vkCmdDispatch(): baseGroupZ (%" PRIu32
3837                          ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").",
3838                          baseGroupZ, limit);
3839     } else if (groupCountZ > (limit - baseGroupZ)) {
3840         skip |= LogError(commandBuffer, "VUID-vkCmdDispatchBase-groupCountZ-00426",
3841                          "vkCmdDispatchBaseKHR(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
3842                          ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").",
3843                          baseGroupZ, groupCountZ, limit);
3844     }
3845 
3846     return skip;
3847 }
3848 
manual_PreCallValidateCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,VkPipelineBindPoint pipelineBindPoint,VkPipelineLayout layout,uint32_t set,uint32_t descriptorWriteCount,const VkWriteDescriptorSet * pDescriptorWrites) const3849 bool StatelessValidation::manual_PreCallValidateCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
3850                                                                         VkPipelineBindPoint pipelineBindPoint,
3851                                                                         VkPipelineLayout layout, uint32_t set,
3852                                                                         uint32_t descriptorWriteCount,
3853                                                                         const VkWriteDescriptorSet *pDescriptorWrites) const {
3854     return validate_WriteDescriptorSet("vkCmdPushDescriptorSetKHR", descriptorWriteCount, pDescriptorWrites, false);
3855 }
3856 
manual_PreCallValidateCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer,uint32_t firstExclusiveScissor,uint32_t exclusiveScissorCount,const VkRect2D * pExclusiveScissors) const3857 bool StatelessValidation::manual_PreCallValidateCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer,
3858                                                                          uint32_t firstExclusiveScissor,
3859                                                                          uint32_t exclusiveScissorCount,
3860                                                                          const VkRect2D *pExclusiveScissors) const {
3861     bool skip = false;
3862 
3863     if (!physical_device_features.multiViewport) {
3864         if (firstExclusiveScissor != 0) {
3865             skip |=
3866                 LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-firstExclusiveScissor-02035",
3867                          "vkCmdSetExclusiveScissorNV: The multiViewport feature is disabled, but firstExclusiveScissor (=%" PRIu32
3868                          ") is not 0.",
3869                          firstExclusiveScissor);
3870         }
3871         if (exclusiveScissorCount > 1) {
3872             skip |=
3873                 LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-exclusiveScissorCount-02036",
3874                          "vkCmdSetExclusiveScissorNV: The multiViewport feature is disabled, but exclusiveScissorCount (=%" PRIu32
3875                          ") is not 1.",
3876                          exclusiveScissorCount);
3877         }
3878     } else {  // multiViewport enabled
3879         const uint64_t sum = static_cast<uint64_t>(firstExclusiveScissor) + static_cast<uint64_t>(exclusiveScissorCount);
3880         if (sum > device_limits.maxViewports) {
3881             skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-firstExclusiveScissor-02034",
3882                              "vkCmdSetExclusiveScissorNV: firstExclusiveScissor + exclusiveScissorCount (=%" PRIu32 " + %" PRIu32
3883                              " = %" PRIu64 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
3884                              firstExclusiveScissor, exclusiveScissorCount, sum, device_limits.maxViewports);
3885         }
3886     }
3887 
3888     if (firstExclusiveScissor >= device_limits.maxViewports) {
3889         skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-firstExclusiveScissor-02033",
3890                          "vkCmdSetExclusiveScissorNV: firstExclusiveScissor (=%" PRIu32
3891                          ") must be less than maxViewports (=%" PRIu32 ").",
3892                          firstExclusiveScissor, device_limits.maxViewports);
3893     }
3894 
3895     if (pExclusiveScissors) {
3896         for (uint32_t scissor_i = 0; scissor_i < exclusiveScissorCount; ++scissor_i) {
3897             const auto &scissor = pExclusiveScissors[scissor_i];  // will crash on invalid ptr
3898 
3899             if (scissor.offset.x < 0) {
3900                 skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-x-02037",
3901                                  "vkCmdSetExclusiveScissorNV: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative.",
3902                                  scissor_i, scissor.offset.x);
3903             }
3904 
3905             if (scissor.offset.y < 0) {
3906                 skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-x-02037",
3907                                  "vkCmdSetExclusiveScissorNV: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative.",
3908                                  scissor_i, scissor.offset.y);
3909             }
3910 
3911             const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
3912             if (x_sum > INT32_MAX) {
3913                 skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-offset-02038",
3914                                  "vkCmdSetExclusiveScissorNV: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
3915                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
3916                                  scissor.offset.x, scissor.extent.width, x_sum, scissor_i);
3917             }
3918 
3919             const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
3920             if (y_sum > INT32_MAX) {
3921                 skip |= LogError(commandBuffer, "VUID-vkCmdSetExclusiveScissorNV-offset-02039",
3922                                  "vkCmdSetExclusiveScissorNV: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
3923                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
3924                                  scissor.offset.y, scissor.extent.height, y_sum, scissor_i);
3925             }
3926         }
3927     }
3928 
3929     return skip;
3930 }
3931 
manual_PreCallValidateCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer,uint32_t firstViewport,uint32_t viewportCount,const VkViewportWScalingNV * pViewportWScalings) const3932 bool StatelessValidation::manual_PreCallValidateCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
3933                                                                          uint32_t viewportCount,
3934                                                                          const VkViewportWScalingNV *pViewportWScalings) const {
3935     bool skip = false;
3936     if (firstViewport >= device_limits.maxViewports) {
3937         skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportWScalingNV-firstViewport-01323",
3938                          "vkCmdSetViewportWScalingNV: firstViewport (=%" PRIu32 ") must be less than maxViewports (=%" PRIu32 ").",
3939                          firstViewport, device_limits.maxViewports);
3940     } else {
3941         const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
3942         if ((sum < 1) || (sum > device_limits.maxViewports)) {
3943             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportWScalingNV-firstViewport-01324",
3944                              "vkCmdSetViewportWScalingNV: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32 " = %" PRIu64
3945                              ") must be between 1 and VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "), inculsive.",
3946                              firstViewport, viewportCount, sum, device_limits.maxViewports);
3947         }
3948     }
3949 
3950     return skip;
3951 }
3952 
manual_PreCallValidateCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer,uint32_t firstViewport,uint32_t viewportCount,const VkShadingRatePaletteNV * pShadingRatePalettes) const3953 bool StatelessValidation::manual_PreCallValidateCmdSetViewportShadingRatePaletteNV(
3954     VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
3955     const VkShadingRatePaletteNV *pShadingRatePalettes) const {
3956     bool skip = false;
3957 
3958     if (!physical_device_features.multiViewport) {
3959         if (firstViewport != 0) {
3960             skip |=
3961                 LogError(commandBuffer, "VUID-vkCmdSetViewportShadingRatePaletteNV-firstViewport-02068",
3962                          "vkCmdSetViewportShadingRatePaletteNV: The multiViewport feature is disabled, but firstViewport (=%" PRIu32
3963                          ") is not 0.",
3964                          firstViewport);
3965         }
3966         if (viewportCount > 1) {
3967             skip |=
3968                 LogError(commandBuffer, "VUID-vkCmdSetViewportShadingRatePaletteNV-viewportCount-02069",
3969                          "vkCmdSetViewportShadingRatePaletteNV: The multiViewport feature is disabled, but viewportCount (=%" PRIu32
3970                          ") is not 1.",
3971                          viewportCount);
3972         }
3973     }
3974 
3975     if (firstViewport >= device_limits.maxViewports) {
3976         skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportShadingRatePaletteNV-firstViewport-02066",
3977                          "vkCmdSetViewportShadingRatePaletteNV: firstViewport (=%" PRIu32
3978                          ") must be less than maxViewports (=%" PRIu32 ").",
3979                          firstViewport, device_limits.maxViewports);
3980     }
3981 
3982     const uint64_t sum = static_cast<uint64_t>(firstViewport) + static_cast<uint64_t>(viewportCount);
3983     if (sum > device_limits.maxViewports) {
3984         skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportShadingRatePaletteNV-firstViewport-02067",
3985                          "vkCmdSetViewportShadingRatePaletteNV: firstViewport + viewportCount (=%" PRIu32 " + %" PRIu32
3986                          " = %" PRIu64 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
3987                          firstViewport, viewportCount, sum, device_limits.maxViewports);
3988     }
3989 
3990     return skip;
3991 }
3992 
manual_PreCallValidateCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,VkCoarseSampleOrderTypeNV sampleOrderType,uint32_t customSampleOrderCount,const VkCoarseSampleOrderCustomNV * pCustomSampleOrders) const3993 bool StatelessValidation::manual_PreCallValidateCmdSetCoarseSampleOrderNV(
3994     VkCommandBuffer commandBuffer, VkCoarseSampleOrderTypeNV sampleOrderType, uint32_t customSampleOrderCount,
3995     const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) const {
3996     bool skip = false;
3997 
3998     if (sampleOrderType != VK_COARSE_SAMPLE_ORDER_TYPE_CUSTOM_NV && customSampleOrderCount != 0) {
3999         skip |= LogError(commandBuffer, "VUID-vkCmdSetCoarseSampleOrderNV-sampleOrderType-02081",
4000                          "vkCmdSetCoarseSampleOrderNV: If sampleOrderType is not VK_COARSE_SAMPLE_ORDER_TYPE_CUSTOM_NV, "
4001                          "customSampleOrderCount must be 0.");
4002     }
4003 
4004     for (uint32_t order_i = 0; order_i < customSampleOrderCount; ++order_i) {
4005         skip |= ValidateCoarseSampleOrderCustomNV(&pCustomSampleOrders[order_i]);
4006     }
4007 
4008     return skip;
4009 }
4010 
manual_PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer,uint32_t taskCount,uint32_t firstTask) const4011 bool StatelessValidation::manual_PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4012                                                                    uint32_t firstTask) const {
4013     bool skip = false;
4014 
4015     if (taskCount > phys_dev_ext_props.mesh_shader_props.maxDrawMeshTasksCount) {
4016         skip |= LogError(
4017             commandBuffer, "VUID-vkCmdDrawMeshTasksNV-taskCount-02119",
4018             "vkCmdDrawMeshTasksNV() parameter, uint32_t taskCount (0x%" PRIxLEAST32
4019             "), must be less than or equal to VkPhysicalDeviceMeshShaderPropertiesNV::maxDrawMeshTasksCount (0x%" PRIxLEAST32 ").",
4020             taskCount, phys_dev_ext_props.mesh_shader_props.maxDrawMeshTasksCount);
4021     }
4022 
4023     return skip;
4024 }
4025 
manual_PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,uint32_t drawCount,uint32_t stride) const4026 bool StatelessValidation::manual_PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4027                                                                            VkDeviceSize offset, uint32_t drawCount,
4028                                                                            uint32_t stride) const {
4029     bool skip = false;
4030     static const int condition_multiples = 0b0011;
4031     if (offset & condition_multiples) {
4032         skip |= LogError(
4033             commandBuffer, "VUID-vkCmdDrawMeshTasksIndirectNV-offset-02710",
4034             "vkCmdDrawMeshTasksIndirectNV() parameter, VkDeviceSize offset (0x%" PRIxLEAST64 "), is not a multiple of 4.", offset);
4035     }
4036     if (drawCount > 1 && ((stride & condition_multiples) || stride < sizeof(VkDrawMeshTasksIndirectCommandNV))) {
4037         skip |= LogError(commandBuffer, "VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02146",
4038                          "vkCmdDrawMeshTasksIndirectNV() parameter, uint32_t stride (0x%" PRIxLEAST32
4039                          "), is not a multiple of 4 or smaller than sizeof (VkDrawMeshTasksIndirectCommandNV).",
4040                          stride);
4041     }
4042     if (!physical_device_features.multiDrawIndirect && ((drawCount > 1))) {
4043         skip |= LogError(
4044             commandBuffer, "VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02718",
4045             "vkCmdDrawMeshTasksIndirectNV(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", drawCount);
4046     }
4047 
4048     return skip;
4049 }
4050 
manual_PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkBuffer countBuffer,VkDeviceSize countBufferOffset,uint32_t maxDrawCount,uint32_t stride) const4051 bool StatelessValidation::manual_PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4052                                                                                 VkDeviceSize offset, VkBuffer countBuffer,
4053                                                                                 VkDeviceSize countBufferOffset,
4054                                                                                 uint32_t maxDrawCount, uint32_t stride) const {
4055     bool skip = false;
4056 
4057     if (offset & 3) {
4058         skip |= LogError(commandBuffer, "VUID-vkCmdDrawMeshTasksIndirectCountNV-offset-02710",
4059                          "vkCmdDrawMeshTasksIndirectCountNV() parameter, VkDeviceSize offset (0x%" PRIxLEAST64
4060                          "), is not a multiple of 4.",
4061                          offset);
4062     }
4063 
4064     if (countBufferOffset & 3) {
4065         skip |= LogError(commandBuffer, "VUID-vkCmdDrawMeshTasksIndirectCountNV-countBufferOffset-02716",
4066                          "vkCmdDrawMeshTasksIndirectCountNV() parameter, VkDeviceSize countBufferOffset (0x%" PRIxLEAST64
4067                          "), is not a multiple of 4.",
4068                          countBufferOffset);
4069     }
4070 
4071     return skip;
4072 }
4073 
manual_PreCallValidateCreateQueryPool(VkDevice device,const VkQueryPoolCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkQueryPool * pQueryPool) const4074 bool StatelessValidation::manual_PreCallValidateCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
4075                                                                 const VkAllocationCallbacks *pAllocator,
4076                                                                 VkQueryPool *pQueryPool) const {
4077     bool skip = false;
4078 
4079     // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
4080     if (pCreateInfo != nullptr) {
4081         // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
4082         // VkQueryPipelineStatisticFlagBits values
4083         if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
4084             ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
4085             skip |= LogError(device, "VUID-VkQueryPoolCreateInfo-queryType-00792",
4086                              "vkCreateQueryPool(): if pCreateInfo->queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, "
4087                              "pCreateInfo->pipelineStatistics must be a valid combination of VkQueryPipelineStatisticFlagBits "
4088                              "values.");
4089         }
4090         if (pCreateInfo->queryCount == 0) {
4091             skip |= LogError(device, "VUID-VkQueryPoolCreateInfo-queryCount-02763",
4092                              "vkCreateQueryPool(): queryCount must be greater than zero.");
4093         }
4094     }
4095     return skip;
4096 }
4097 
manual_PreCallValidateEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,const char * pLayerName,uint32_t * pPropertyCount,VkExtensionProperties * pProperties) const4098 bool StatelessValidation::manual_PreCallValidateEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
4099                                                                                    const char *pLayerName, uint32_t *pPropertyCount,
4100                                                                                    VkExtensionProperties *pProperties) const {
4101     return validate_array("vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties", pPropertyCount, &pProperties,
4102                           true, false, false, kVUIDUndefined, "VUID-vkEnumerateDeviceExtensionProperties-pProperties-parameter");
4103 }
4104 
PostCallRecordCreateRenderPass(VkDevice device,const VkRenderPassCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass,VkResult result)4105 void StatelessValidation::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
4106                                                          const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4107                                                          VkResult result) {
4108     if (result != VK_SUCCESS) return;
4109     RecordRenderPass(*pRenderPass, pCreateInfo);
4110 }
4111 
PostCallRecordCreateRenderPass2KHR(VkDevice device,const VkRenderPassCreateInfo2KHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkRenderPass * pRenderPass,VkResult result)4112 void StatelessValidation::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2KHR *pCreateInfo,
4113                                                              const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4114                                                              VkResult result) {
4115     // Track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
4116     if (result != VK_SUCCESS) return;
4117     RecordRenderPass(*pRenderPass, pCreateInfo);
4118 }
4119 
PostCallRecordDestroyRenderPass(VkDevice device,VkRenderPass renderPass,const VkAllocationCallbacks * pAllocator)4120 void StatelessValidation::PostCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
4121                                                           const VkAllocationCallbacks *pAllocator) {
4122     // Track the state necessary for checking vkCreateGraphicsPipeline (subpass usage of depth and color attachments)
4123     std::unique_lock<std::mutex> lock(renderpass_map_mutex);
4124     renderpasses_states.erase(renderPass);
4125 }
4126 
manual_PreCallValidateAllocateMemory(VkDevice device,const VkMemoryAllocateInfo * pAllocateInfo,const VkAllocationCallbacks * pAllocator,VkDeviceMemory * pMemory) const4127 bool StatelessValidation::manual_PreCallValidateAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
4128                                                                const VkAllocationCallbacks *pAllocator,
4129                                                                VkDeviceMemory *pMemory) const {
4130     bool skip = false;
4131 
4132     if (pAllocateInfo) {
4133         auto chained_prio_struct = lvl_find_in_chain<VkMemoryPriorityAllocateInfoEXT>(pAllocateInfo->pNext);
4134         if (chained_prio_struct && (chained_prio_struct->priority < 0.0f || chained_prio_struct->priority > 1.0f)) {
4135             skip |= LogError(device, "VUID-VkMemoryPriorityAllocateInfoEXT-priority-02602",
4136                              "priority (=%f) must be between `0` and `1`, inclusive.", chained_prio_struct->priority);
4137         }
4138 
4139         VkMemoryAllocateFlags flags = 0;
4140         auto flags_info = lvl_find_in_chain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext);
4141         if (flags_info) {
4142             flags = flags_info->flags;
4143         }
4144 
4145         auto opaque_alloc_info = lvl_find_in_chain<VkMemoryOpaqueCaptureAddressAllocateInfoKHR>(pAllocateInfo->pNext);
4146         if (opaque_alloc_info && opaque_alloc_info->opaqueCaptureAddress != 0) {
4147             if (!(flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR)) {
4148                 skip |= LogError(device, "VUID-VkMemoryAllocateInfo-opaqueCaptureAddress-03329",
4149                                  "If opaqueCaptureAddress is non-zero, VkMemoryAllocateFlagsInfo::flags must include "
4150                                  "VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR.");
4151             }
4152 
4153 #ifdef VK_USE_PLATFORM_WIN32_KHR
4154             auto import_memory_win32_handle = lvl_find_in_chain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext);
4155 #endif
4156             auto import_memory_fd = lvl_find_in_chain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext);
4157             auto import_memory_host_pointer = lvl_find_in_chain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext);
4158 #ifdef VK_USE_PLATFORM_ANDROID_KHR
4159             auto import_memory_ahb = lvl_find_in_chain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext);
4160 #endif
4161 
4162             if (import_memory_host_pointer) {
4163                 skip |= LogError(
4164                     device, "VUID-VkMemoryAllocateInfo-pNext-03332",
4165                     "If the pNext chain includes a VkImportMemoryHostPointerInfoEXT structure, opaqueCaptureAddress must be zero.");
4166             }
4167             if (
4168 #ifdef VK_USE_PLATFORM_WIN32_KHR
4169                 (import_memory_win32_handle && import_memory_win32_handle->handleType) ||
4170 #endif
4171                 (import_memory_fd && import_memory_fd->handleType) ||
4172 #ifdef VK_USE_PLATFORM_ANDROID_KHR
4173                 (import_memory_ahb && import_memory_ahb->buffer) ||
4174 #endif
4175                 (import_memory_host_pointer && import_memory_host_pointer->handleType)) {
4176                 skip |= LogError(device, "VUID-VkMemoryAllocateInfo-opaqueCaptureAddress-03333",
4177                                  "If the parameters define an import operation, opaqueCaptureAddress must be zero.");
4178             }
4179         }
4180 
4181         if (flags) {
4182             VkBool32 capture_replay = false;
4183             VkBool32 buffer_device_address = false;
4184             const auto *vulkan_12_features = lvl_find_in_chain<VkPhysicalDeviceVulkan12Features>(device_createinfo_pnext);
4185             if (vulkan_12_features) {
4186                 capture_replay = vulkan_12_features->bufferDeviceAddressCaptureReplay;
4187                 buffer_device_address = vulkan_12_features->bufferDeviceAddress;
4188             } else {
4189                 const auto *bda_features =
4190                     lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeaturesKHR>(device_createinfo_pnext);
4191                 if (bda_features) {
4192                     capture_replay = bda_features->bufferDeviceAddressCaptureReplay;
4193                     buffer_device_address = bda_features->bufferDeviceAddress;
4194                 }
4195             }
4196             if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR) && !capture_replay) {
4197                 skip |= LogError(device, "VUID-VkMemoryAllocateInfo-flags-03330",
4198                                  "If VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_CAPTURE_REPLAY_BIT_KHR is set, "
4199                                  "bufferDeviceAddressCaptureReplay must be enabled.");
4200             }
4201             if ((flags & VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR) && !buffer_device_address) {
4202                 skip |= LogError(device, "VUID-VkMemoryAllocateInfo-flags-03331",
4203                                  "If VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR is set, bufferDeviceAddress must be enabled.");
4204             }
4205         }
4206     }
4207     return skip;
4208 }
4209 
ValidateGeometryTrianglesNV(const VkGeometryTrianglesNV & triangles,VkAccelerationStructureNV object_handle,const char * func_name) const4210 bool StatelessValidation::ValidateGeometryTrianglesNV(const VkGeometryTrianglesNV &triangles,
4211                                                       VkAccelerationStructureNV object_handle, const char *func_name) const {
4212     bool skip = false;
4213 
4214     if (triangles.vertexFormat != VK_FORMAT_R32G32B32_SFLOAT && triangles.vertexFormat != VK_FORMAT_R16G16B16_SFLOAT &&
4215         triangles.vertexFormat != VK_FORMAT_R16G16B16_SNORM && triangles.vertexFormat != VK_FORMAT_R32G32_SFLOAT &&
4216         triangles.vertexFormat != VK_FORMAT_R16G16_SFLOAT && triangles.vertexFormat != VK_FORMAT_R16G16_SNORM) {
4217         skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-vertexFormat-02430", "%s", func_name);
4218     } else {
4219         uint32_t vertex_component_size = 0;
4220         if (triangles.vertexFormat == VK_FORMAT_R32G32B32_SFLOAT || triangles.vertexFormat == VK_FORMAT_R32G32_SFLOAT) {
4221             vertex_component_size = 4;
4222         } else if (triangles.vertexFormat == VK_FORMAT_R16G16B16_SFLOAT || triangles.vertexFormat == VK_FORMAT_R16G16B16_SNORM ||
4223                    triangles.vertexFormat == VK_FORMAT_R16G16_SFLOAT || triangles.vertexFormat == VK_FORMAT_R16G16_SNORM) {
4224             vertex_component_size = 2;
4225         }
4226         if (vertex_component_size > 0 && SafeModulo(triangles.vertexOffset, vertex_component_size) != 0) {
4227             skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-vertexOffset-02429", "%s", func_name);
4228         }
4229     }
4230 
4231     if (triangles.indexType != VK_INDEX_TYPE_UINT32 && triangles.indexType != VK_INDEX_TYPE_UINT16 &&
4232         triangles.indexType != VK_INDEX_TYPE_NONE_NV) {
4233         skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-indexType-02433", "%s", func_name);
4234     } else {
4235         uint32_t index_element_size = 0;
4236         if (triangles.indexType == VK_INDEX_TYPE_UINT32) {
4237             index_element_size = 4;
4238         } else if (triangles.indexType == VK_INDEX_TYPE_UINT16) {
4239             index_element_size = 2;
4240         }
4241         if (index_element_size > 0 && SafeModulo(triangles.indexOffset, index_element_size) != 0) {
4242             skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-indexOffset-02432", "%s", func_name);
4243         }
4244     }
4245     if (triangles.indexType == VK_INDEX_TYPE_NONE_NV) {
4246         if (triangles.indexCount != 0) {
4247             skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-indexCount-02436", "%s", func_name);
4248         }
4249         if (triangles.indexData != VK_NULL_HANDLE) {
4250             skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-indexData-02434", "%s", func_name);
4251         }
4252     }
4253 
4254     if (SafeModulo(triangles.transformOffset, 16) != 0) {
4255         skip |= LogError(object_handle, "VUID-VkGeometryTrianglesNV-transformOffset-02438", "%s", func_name);
4256     }
4257 
4258     return skip;
4259 }
4260 
ValidateGeometryAABBNV(const VkGeometryAABBNV & aabbs,VkAccelerationStructureNV object_handle,const char * func_name) const4261 bool StatelessValidation::ValidateGeometryAABBNV(const VkGeometryAABBNV &aabbs, VkAccelerationStructureNV object_handle,
4262                                                  const char *func_name) const {
4263     bool skip = false;
4264 
4265     if (SafeModulo(aabbs.offset, 8) != 0) {
4266         skip |= LogError(object_handle, "VUID-VkGeometryAABBNV-offset-02440", "%s", func_name);
4267     }
4268     if (SafeModulo(aabbs.stride, 8) != 0) {
4269         skip |= LogError(object_handle, "VUID-VkGeometryAABBNV-stride-02441", "%s", func_name);
4270     }
4271 
4272     return skip;
4273 }
4274 
ValidateGeometryNV(const VkGeometryNV & geometry,VkAccelerationStructureNV object_handle,const char * func_name) const4275 bool StatelessValidation::ValidateGeometryNV(const VkGeometryNV &geometry, VkAccelerationStructureNV object_handle,
4276                                              const char *func_name) const {
4277     bool skip = false;
4278     if (geometry.geometryType == VK_GEOMETRY_TYPE_TRIANGLES_NV) {
4279         skip = ValidateGeometryTrianglesNV(geometry.geometry.triangles, object_handle, func_name);
4280     } else if (geometry.geometryType == VK_GEOMETRY_TYPE_AABBS_NV) {
4281         skip = ValidateGeometryAABBNV(geometry.geometry.aabbs, object_handle, func_name);
4282     }
4283     return skip;
4284 }
4285 
ValidateAccelerationStructureInfoNV(const VkAccelerationStructureInfoNV & info,VkAccelerationStructureNV object_handle,const char * func_name,bool is_cmd) const4286 bool StatelessValidation::ValidateAccelerationStructureInfoNV(const VkAccelerationStructureInfoNV &info,
4287                                                               VkAccelerationStructureNV object_handle, const char *func_name,
4288                                                               bool is_cmd) const {
4289     bool skip = false;
4290     if (info.type == VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV && info.geometryCount != 0) {
4291         skip |= LogError(object_handle, "VUID-VkAccelerationStructureInfoNV-type-02425",
4292                          "VkAccelerationStructureInfoNV: If type is VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV then "
4293                          "geometryCount must be 0.");
4294     }
4295     if (info.type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV && info.instanceCount != 0) {
4296         skip |= LogError(object_handle, "VUID-VkAccelerationStructureInfoNV-type-02426",
4297                          "VkAccelerationStructureInfoNV: If type is VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV then "
4298                          "instanceCount must be 0.");
4299     }
4300     if (info.flags & VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_NV &&
4301         info.flags & VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_NV) {
4302         skip |= LogError(object_handle, "VUID-VkAccelerationStructureInfoNV-flags-02592",
4303                          "VkAccelerationStructureInfoNV: If flags has the VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_NV"
4304                          "bit set, then it must not have the VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_NV bit set.");
4305     }
4306     if (info.geometryCount > phys_dev_ext_props.ray_tracing_propsNV.maxGeometryCount) {
4307         skip |= LogError(object_handle,
4308                          is_cmd ? "VUID-vkCmdBuildAccelerationStructureNV-geometryCount-02241"
4309                                 : "VUID-VkAccelerationStructureInfoNV-geometryCount-02422",
4310                          "VkAccelerationStructureInfoNV: geometryCount must be less than or equal to "
4311                          "VkPhysicalDeviceRayTracingPropertiesNV::maxGeometryCount.");
4312     }
4313     if (info.instanceCount > phys_dev_ext_props.ray_tracing_propsNV.maxInstanceCount) {
4314         skip |= LogError(object_handle, "VUID-VkAccelerationStructureInfoNV-instanceCount-02423",
4315                          "VkAccelerationStructureInfoNV: instanceCount must be less than or equal to "
4316                          "VkPhysicalDeviceRayTracingPropertiesNV::maxInstanceCount.");
4317     }
4318     if (info.type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV && info.geometryCount > 0) {
4319         uint64_t total_triangle_count = 0;
4320         for (uint32_t i = 0; i < info.geometryCount; i++) {
4321             const VkGeometryNV &geometry = info.pGeometries[i];
4322 
4323             skip |= ValidateGeometryNV(geometry, object_handle, func_name);
4324 
4325             if (geometry.geometryType != VK_GEOMETRY_TYPE_TRIANGLES_NV) {
4326                 continue;
4327             }
4328             total_triangle_count += geometry.geometry.triangles.indexCount / 3;
4329         }
4330         if (total_triangle_count > phys_dev_ext_props.ray_tracing_propsNV.maxTriangleCount) {
4331             skip |= LogError(object_handle, "VUID-VkAccelerationStructureInfoNV-maxTriangleCount-02424",
4332                              "VkAccelerationStructureInfoNV: The total number of triangles in all geometries must be less than "
4333                              "or equal to VkPhysicalDeviceRayTracingPropertiesNV::maxTriangleCount.");
4334         }
4335     }
4336     if (info.type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV && info.geometryCount > 1) {
4337         const VkGeometryTypeNV first_geometry_type = info.pGeometries[0].geometryType;
4338         for (uint32_t i = 1; i < info.geometryCount; i++) {
4339             const VkGeometryNV &geometry = info.pGeometries[i];
4340             if (geometry.geometryType != first_geometry_type) {
4341                 skip |= LogError(device, "VUID-VkAccelerationStructureInfoNV-type-02786",
4342                                  "VkAccelerationStructureInfoNV: info.pGeometries[%d].geometryType does not match "
4343                                  "info.pGeometries[0].geometryType.",
4344                                  i);
4345             }
4346         }
4347     }
4348     for (uint32_t geometry_index = 0; geometry_index < info.geometryCount; ++geometry_index) {
4349         if (!(info.pGeometries[geometry_index].geometryType == VK_GEOMETRY_TYPE_TRIANGLES_NV ||
4350               info.pGeometries[geometry_index].geometryType == VK_GEOMETRY_TYPE_AABBS_NV)) {
4351             skip |= LogError(device, "VUID-VkGeometryNV-geometryType-03503",
4352                              "VkGeometryNV: geometryType must be VK_GEOMETRY_TYPE_TRIANGLES_NV"
4353                              "or VK_GEOMETRY_TYPE_AABBS_NV.");
4354         }
4355     }
4356     skip |=
4357         validate_flags(func_name, "info.flags", "VkBuildAccelerationStructureFlagBitsNV", AllVkBuildAccelerationStructureFlagBitsNV,
4358                        info.flags, kOptionalFlags, "VUID-VkAccelerationStructureInfoNV-flags-parameter");
4359     return skip;
4360 }
4361 
manual_PreCallValidateCreateAccelerationStructureNV(VkDevice device,const VkAccelerationStructureCreateInfoNV * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkAccelerationStructureNV * pAccelerationStructure) const4362 bool StatelessValidation::manual_PreCallValidateCreateAccelerationStructureNV(
4363     VkDevice device, const VkAccelerationStructureCreateInfoNV *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4364     VkAccelerationStructureNV *pAccelerationStructure) const {
4365     bool skip = false;
4366     if (pCreateInfo) {
4367         if ((pCreateInfo->compactedSize != 0) &&
4368             ((pCreateInfo->info.geometryCount != 0) || (pCreateInfo->info.instanceCount != 0))) {
4369             skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoNV-compactedSize-02421",
4370                              "vkCreateAccelerationStructureNV(): pCreateInfo->compactedSize nonzero (%" PRIu64
4371                              ") with info.geometryCount (%" PRIu32 ") or info.instanceCount (%" PRIu32 ") nonzero.",
4372                              pCreateInfo->compactedSize, pCreateInfo->info.geometryCount, pCreateInfo->info.instanceCount);
4373         }
4374 
4375         skip |= ValidateAccelerationStructureInfoNV(pCreateInfo->info, VkAccelerationStructureNV(0),
4376                                                     "vkCreateAccelerationStructureNV()", false);
4377     }
4378     return skip;
4379 }
4380 
manual_PreCallValidateCmdBuildAccelerationStructureNV(VkCommandBuffer commandBuffer,const VkAccelerationStructureInfoNV * pInfo,VkBuffer instanceData,VkDeviceSize instanceOffset,VkBool32 update,VkAccelerationStructureNV dst,VkAccelerationStructureNV src,VkBuffer scratch,VkDeviceSize scratchOffset) const4381 bool StatelessValidation::manual_PreCallValidateCmdBuildAccelerationStructureNV(VkCommandBuffer commandBuffer,
4382                                                                                 const VkAccelerationStructureInfoNV *pInfo,
4383                                                                                 VkBuffer instanceData, VkDeviceSize instanceOffset,
4384                                                                                 VkBool32 update, VkAccelerationStructureNV dst,
4385                                                                                 VkAccelerationStructureNV src, VkBuffer scratch,
4386                                                                                 VkDeviceSize scratchOffset) const {
4387     bool skip = false;
4388 
4389     if (pInfo != nullptr) {
4390         skip |= ValidateAccelerationStructureInfoNV(*pInfo, dst, "vkCmdBuildAccelerationStructureNV()", true);
4391     }
4392 
4393     return skip;
4394 }
4395 
manual_PreCallValidateCreateAccelerationStructureKHR(VkDevice device,const VkAccelerationStructureCreateInfoKHR * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkAccelerationStructureKHR * pAccelerationStructure) const4396 bool StatelessValidation::manual_PreCallValidateCreateAccelerationStructureKHR(
4397     VkDevice device, const VkAccelerationStructureCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
4398     VkAccelerationStructureKHR *pAccelerationStructure) const {
4399     bool skip = false;
4400 
4401     if (pCreateInfo) {
4402         for (uint32_t i = 0; i < pCreateInfo->maxGeometryCount; ++i) {
4403             if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR && pCreateInfo->compactedSize == 0) {
4404                 if (pCreateInfo->pGeometryInfos[i].geometryType != VK_GEOMETRY_TYPE_INSTANCES_KHR) {
4405                     skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03496",
4406                                      "VkAccelerationStructureCreateInfoKHR: Top-level acceleration structure "
4407                                      "pGeometryInfos[%d].geometryType must be VK_GEOMETRY_TYPE_INSTANCES_KHR",
4408                                      i);
4409                 }
4410             }
4411 
4412             if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR && pCreateInfo->compactedSize == 0) {
4413                 if (pCreateInfo->pGeometryInfos[i].geometryType == VK_GEOMETRY_TYPE_INSTANCES_KHR) {
4414                     skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03497",
4415                                      "VkAccelerationStructureCreateInfoKHR: Bottom-level acceleration structure "
4416                                      "pGeometryInfos[%d].geometryType must not be VK_GEOMETRY_TYPE_INSTANCES_KHR",
4417                                      i);
4418                 }
4419             }
4420             if (pCreateInfo->pGeometryInfos[i].geometryType == VK_GEOMETRY_TYPE_TRIANGLES_KHR) {
4421                 if (!(pCreateInfo->pGeometryInfos[i].indexType == VK_INDEX_TYPE_UINT16 ||
4422                       pCreateInfo->pGeometryInfos[i].indexType == VK_INDEX_TYPE_UINT32 ||
4423                       pCreateInfo->pGeometryInfos[i].indexType == VK_INDEX_TYPE_NONE_KHR)) {
4424                     skip |= LogError(
4425                         device, "VUID-VkAccelerationStructureCreateGeometryTypeInfoKHR-geometryType-03502",
4426                         "VkAccelerationStructureCreateInfoKHR: If geometryType is VK_GEOMETRY_TYPE_TRIANGLES_KHR, indexType"
4427                         "must be VK_INDEX_TYPE_UINT16, VK_INDEX_TYPE_UINT32, or VK_INDEX_TYPE_NONE_KHR.");
4428                 }
4429             }
4430             if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR) {
4431                 if (pCreateInfo->pGeometryInfos[i].maxPrimitiveCount > phys_dev_ext_props.ray_tracing_propsKHR.maxInstanceCount) {
4432                     skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03492",
4433                                      "VkAccelerationStructureCreateInfoKHR: If type is VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR"
4434                                      "then pGeometryInfos->maxPrimitiveCount %d  must be less than or equal to "
4435                                      "VkPhysicalDeviceRayTracingPropertiesKHR::maxInstanceCount %d.",
4436                                      pCreateInfo->pGeometryInfos[i].maxPrimitiveCount,
4437                                      phys_dev_ext_props.ray_tracing_propsKHR.maxInstanceCount);
4438                 }
4439             }
4440         }
4441 
4442         if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR && pCreateInfo->compactedSize == 0 &&
4443             pCreateInfo->maxGeometryCount != 1) {
4444             skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03495",
4445                              "VkAccelerationStructureCreateInfoKHR: If type is VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR"
4446                              "and compactedSize is 0, maxGeometryCount must be 1.");
4447         }
4448         // or VUID-VkAccelerationStructureCreateInfoKHR-compactedSize-03490
4449         if (pCreateInfo->compactedSize == 0 && pCreateInfo->maxGeometryCount == 0) {
4450             skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-compactedSize-02993",
4451                              "VkAccelerationStructureCreateInfoKHR: If compactedSize is 0 then maxGeometryCount must not be 0.");
4452         }
4453 
4454         if (pCreateInfo->flags & VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR &&
4455             pCreateInfo->flags & VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_KHR) {
4456             skip |= LogError(
4457                 device, "VUID-VkAccelerationStructureCreateInfoKHR-flags-03499",
4458                 "VkAccelerationStructureCreateInfoKHR: If flags has the VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR"
4459                 "bit set, then it must not have the VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_BUILD_BIT_KHR bit set.");
4460         }
4461 
4462         if (pCreateInfo->compactedSize != 0 && pCreateInfo->maxGeometryCount != 0) {
4463             skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-compactedSize-03490",
4464                              "VkAccelerationStructureCreateInfoKHR: pCreateInfo->compactedSize nonzero (%" PRIu64
4465                              ") with maxGeometryCount (%" PRIu32 ") nonzero.",
4466                              pCreateInfo->compactedSize, pCreateInfo->maxGeometryCount);
4467         }
4468 
4469         if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV && pCreateInfo->maxGeometryCount > 1) {
4470             const VkGeometryTypeKHR first_geometry_type = pCreateInfo->pGeometryInfos[0].geometryType;
4471             for (uint32_t i = 1; i < pCreateInfo->maxGeometryCount; i++) {
4472                 const VkGeometryTypeKHR geometry_type = pCreateInfo->pGeometryInfos[i].geometryType;
4473                 if (geometry_type != first_geometry_type) {
4474                     skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03498",
4475                                      "VkAccelerationStructureCreateInfoKHR: pGeometryInfos[%d].geometryType does not match "
4476                                      "pGeometryInfos[0].geometryType.",
4477                                      i);
4478                 }
4479             }
4480         }
4481         if (pCreateInfo->type == VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR &&
4482             (pCreateInfo->maxGeometryCount > phys_dev_ext_props.ray_tracing_propsKHR.maxGeometryCount)) {
4483             skip |= LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-type-03491",
4484                              "VkAccelerationStructureCreateInfoKHR: If type is VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR"
4485                              "then maxGeometryCount %d must be less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR "
4486                              "maxGeometryCount %d.",
4487                              pCreateInfo->maxGeometryCount, phys_dev_ext_props.ray_tracing_propsKHR.maxGeometryCount);
4488         }
4489     }
4490     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
4491     if (!raytracing_features || raytracing_features->rayTracingAccelerationStructureCaptureReplay == VK_FALSE) {
4492         if (pCreateInfo->deviceAddress != 0) {
4493             skip |=
4494                 LogError(device, "VUID-VkAccelerationStructureCreateInfoKHR-deviceAddress-03500",
4495                          "VkAccelerationStructureCreateInfoKHR: If deviceAddress is not 0, "
4496                          "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingAccelerationStructureCaptureReplay must be VK_TRUE.");
4497         }
4498     }
4499     if (!raytracing_features || !(raytracing_features->rayQuery == VK_TRUE || raytracing_features->rayTracing == VK_TRUE)) {
4500         skip |= LogError(device, "VUID-vkCreateAccelerationStructureKHR-rayTracing-03487",
4501                          "vkCreateAccelerationStructureKHR: The rayTracing or rayQuery feature must be enabled.");
4502     }
4503     return skip;
4504 }
4505 
manual_PreCallValidateGetAccelerationStructureHandleNV(VkDevice device,VkAccelerationStructureNV accelerationStructure,size_t dataSize,void * pData) const4506 bool StatelessValidation::manual_PreCallValidateGetAccelerationStructureHandleNV(VkDevice device,
4507                                                                                  VkAccelerationStructureNV accelerationStructure,
4508                                                                                  size_t dataSize, void *pData) const {
4509     bool skip = false;
4510     if (dataSize < 8) {
4511         skip = LogError(accelerationStructure, "VUID-vkGetAccelerationStructureHandleNV-dataSize-02240",
4512                         "vkGetAccelerationStructureHandleNV(): dataSize must be greater than or equal to 8.");
4513     }
4514     return skip;
4515 }
4516 
manual_PreCallValidateCreateRayTracingPipelinesNV(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkRayTracingPipelineCreateInfoNV * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const4517 bool StatelessValidation::manual_PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
4518                                                                             uint32_t createInfoCount,
4519                                                                             const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
4520                                                                             const VkAllocationCallbacks *pAllocator,
4521                                                                             VkPipeline *pPipelines) const {
4522     bool skip = false;
4523 
4524     for (uint32_t i = 0; i < createInfoCount; i++) {
4525         auto feedback_struct = lvl_find_in_chain<VkPipelineCreationFeedbackCreateInfoEXT>(pCreateInfos[i].pNext);
4526         if ((feedback_struct != nullptr) && (feedback_struct->pipelineStageCreationFeedbackCount != pCreateInfos[i].stageCount)) {
4527             skip |= LogError(device, "VUID-VkPipelineCreationFeedbackCreateInfoEXT-pipelineStageCreationFeedbackCount-02969",
4528                              "vkCreateRayTracingPipelinesNV(): in pCreateInfo[%" PRIu32
4529                              "], VkPipelineCreationFeedbackEXT::pipelineStageCreationFeedbackCount"
4530                              "(=%" PRIu32 ") must equal VkRayTracingPipelineCreateInfoNV::stageCount(=%" PRIu32 ").",
4531                              i, feedback_struct->pipelineStageCreationFeedbackCount, pCreateInfos[i].stageCount);
4532         }
4533 
4534         const auto *pipeline_cache_contol_features =
4535             lvl_find_in_chain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(device_createinfo_pnext);
4536         if (!pipeline_cache_contol_features || pipeline_cache_contol_features->pipelineCreationCacheControl == VK_FALSE) {
4537             if (pCreateInfos[i].flags & (VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT |
4538                                          VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT)) {
4539                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-pipelineCreationCacheControl-02905",
4540                                  "vkCreateRayTracingPipelinesNV(): If the pipelineCreationCacheControl feature is not enabled,"
4541                                  "flags must not include VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT or"
4542                                  "VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT.");
4543             }
4544         }
4545 
4546         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV) {
4547             skip |=
4548                 LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-02904",
4549                          "vkCreateRayTracingPipelinesNV(): flags must not include VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV.");
4550         }
4551         if ((pCreateInfos[i].flags & VK_PIPELINE_CREATE_DEFER_COMPILE_BIT_NV) &&
4552             (pCreateInfos[i].flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT)) {
4553             skip |=
4554                 LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-02957",
4555                          "vkCreateRayTracingPipelinesNV(): flags must not include both VK_PIPELINE_CREATE_DEFER_COMPILE_BIT_NV and"
4556                          "VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT at the same time.");
4557         }
4558         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
4559             if (pCreateInfos[i].basePipelineIndex != -1) {
4560                 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
4561                     skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03423",
4562                                      "vkCreateRayTracingPipelinesNV parameter, pCreateInfos->basePipelineHandle, must be "
4563                                      "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
4564                                      "and pCreateInfos->basePipelineIndex is not -1.");
4565                 }
4566                 if (pCreateInfos[i].basePipelineIndex > (int32_t)(i)) {
4567                     skip |=
4568                         LogError(device, "VUID-vkCreateRayTracingPipelinesNV-flags-03415",
4569                                  "vkCreateRayTracingPipelinesNV: If the flags member of any element of pCreateInfos contains the"
4570                                  "VK_PIPELINE_CREATE_DERIVATIVE_BIT flag, and the basePipelineIndex member of that same element"
4571                                  "is not -1, basePipelineIndex must be less than the index into pCreateInfos that corresponds to "
4572                                  "that element.");
4573                 }
4574             }
4575             if (pCreateInfos[i].basePipelineHandle == VK_NULL_HANDLE) {
4576                 if (static_cast<uint32_t>(pCreateInfos[i].basePipelineIndex) >= createInfoCount) {
4577                     skip |=
4578                         LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03422",
4579                                  "vkCreateRayTracingPipelinesNV if flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT and"
4580                                  "basePipelineHandle is VK_NULL_HANDLE, basePipelineIndex must be a valid index into the calling"
4581                                  "commands pCreateInfos parameter.");
4582                 }
4583             } else {
4584                 if (pCreateInfos[i].basePipelineIndex != -1) {
4585                     skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03424",
4586                                      "vkCreateRayTracingPipelinesNV if flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT and"
4587                                      "basePipelineHandle is not VK_NULL_HANDLE, basePipelineIndex must be -1.");
4588                 }
4589             }
4590         }
4591         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) {
4592             skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03456",
4593                              "vkCreateRayTracingPipelinesNV: flags must not include VK_PIPELINE_CREATE_LIBRARY_BIT_KHR.");
4594         }
4595         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR) {
4596             skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03458",
4597                              "vkCreateRayTracingPipelinesNV: flags must not include "
4598                              "VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR.");
4599         }
4600         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR) {
4601             skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03459",
4602                              "vkCreateRayTracingPipelinesNV: flags must not include "
4603                              "VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR.");
4604         }
4605         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR) {
4606             skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03460",
4607                              "vkCreateRayTracingPipelinesNV: flags must not include "
4608                              "VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR.");
4609         }
4610         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR) {
4611             skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03461",
4612                              "vkCreateRayTracingPipelinesNV: flags must not include "
4613                              "VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR.");
4614         }
4615         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR) {
4616             skip |= LogError(
4617                 device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03462",
4618                 "vkCreateRayTracingPipelinesNV: flags must not include VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR.");
4619         }
4620         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR) {
4621             skip |= LogError(
4622                 device, "VUID-VkRayTracingPipelineCreateInfoNV-flags-03463",
4623                 "vkCreateRayTracingPipelinesNV: flags must not include VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR .");
4624         }
4625     }
4626 
4627     return skip;
4628 }
4629 
manual_PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device,VkPipelineCache pipelineCache,uint32_t createInfoCount,const VkRayTracingPipelineCreateInfoKHR * pCreateInfos,const VkAllocationCallbacks * pAllocator,VkPipeline * pPipelines) const4630 bool StatelessValidation::manual_PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkPipelineCache pipelineCache,
4631                                                                              uint32_t createInfoCount,
4632                                                                              const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
4633                                                                              const VkAllocationCallbacks *pAllocator,
4634                                                                              VkPipeline *pPipelines) const {
4635     bool skip = false;
4636     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
4637     if (!raytracing_features || raytracing_features->rayTracing == VK_FALSE) {
4638         skip |= LogError(device, "VUID-vkCreateRayTracingPipelinesKHR-rayTracing-03455",
4639                          "vkCreateRayTracingPipelinesKHR(): The rayTracing feature must be enabled.");
4640     }
4641     for (uint32_t i = 0; i < createInfoCount; i++) {
4642         auto feedback_struct = lvl_find_in_chain<VkPipelineCreationFeedbackCreateInfoEXT>(pCreateInfos[i].pNext);
4643         if ((feedback_struct != nullptr) && (feedback_struct->pipelineStageCreationFeedbackCount != pCreateInfos[i].stageCount)) {
4644             skip |= LogError(device, "VUID-VkPipelineCreationFeedbackCreateInfoEXT-pipelineStageCreationFeedbackCount-02670",
4645                              "vkCreateRayTracingPipelinesKHR(): in pCreateInfo[%" PRIu32
4646                              "], VkPipelineCreationFeedbackEXT::pipelineStageCreationFeedbackCount"
4647                              "(=%" PRIu32 ") must equal VkRayTracingPipelineCreateInfoKHR::stageCount(=%" PRIu32 ").",
4648                              i, feedback_struct->pipelineStageCreationFeedbackCount, pCreateInfos[i].stageCount);
4649         }
4650         const auto *pipeline_cache_contol_features =
4651             lvl_find_in_chain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(device_createinfo_pnext);
4652         if (!pipeline_cache_contol_features || pipeline_cache_contol_features->pipelineCreationCacheControl == VK_FALSE) {
4653             if (pCreateInfos[i].flags & (VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT |
4654                                          VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT)) {
4655                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-pipelineCreationCacheControl-02905",
4656                                  "vkCreateRayTracingPipelinesKHR(): If the pipelineCreationCacheControl feature is not enabled,"
4657                                  "flags must not include VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT_EXT or"
4658                                  "VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT.");
4659             }
4660         }
4661         if (!raytracing_features || raytracing_features->rayTracingPrimitiveCulling == VK_FALSE) {
4662             if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR) {
4663                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-rayTracingPrimitiveCulling-03472",
4664                                  "vkCreateRayTracingPipelinesKHR(): If the rayTracingPrimitiveCulling feature is not enabled,"
4665                                  "flags must not include VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR.");
4666             }
4667             if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR) {
4668                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-rayTracingPrimitiveCulling-03473",
4669                                  "vkCreateRayTracingPipelinesKHR(): If the rayTracingPrimitiveCulling feature is not enabled,"
4670                                  "flags must not include VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR .");
4671             }
4672         }
4673 
4674         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV) {
4675             skip |=
4676                 LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-02904",
4677                          "vkCreateRayTracingPipelinesKHR(): flags must not include VK_PIPELINE_CREATE_INDIRECT_BINDABLE_BIT_NV.");
4678         }
4679         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) {
4680             if (pCreateInfos[i].pLibraryInterface == NULL)
4681                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03465",
4682                                  "If flags includes VK_PIPELINE_CREATE_LIBRARY_BIT_KHR, pLibraryInterface must not be NULL.");
4683         }
4684         for (uint32_t group_index = 0; group_index < pCreateInfos[i].groupCount; ++group_index) {
4685             if ((pCreateInfos[i].pGroups[group_index].type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR) ||
4686                 (pCreateInfos[i].pGroups[group_index].type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR)) {
4687                 if ((pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR) &&
4688                     (pCreateInfos[i].pGroups[group_index].anyHitShader == VK_SHADER_UNUSED_KHR)) {
4689                     skip |= LogError(
4690                         device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03470",
4691                         "If flags includes VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR,"
4692                         "for any element of pGroups with a type of VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR"
4693                         "or VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR, the anyHitShader of that element "
4694                         "must not be VK_SHADER_UNUSED_KHR");
4695                 }
4696                 if ((pCreateInfos[i].flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR) &&
4697                     (pCreateInfos[i].pGroups[group_index].closestHitShader == VK_SHADER_UNUSED_KHR)) {
4698                     skip |= LogError(
4699                         device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03471",
4700                         "If flags includes VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR,"
4701                         "for any element of pGroups with a type of VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR"
4702                         "or VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_KHR, the closestHitShader of that "
4703                         "element must not be VK_SHADER_UNUSED_KHR");
4704                 }
4705             }
4706         }
4707         if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
4708             if (pCreateInfos[i].basePipelineIndex != -1) {
4709                 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
4710                     skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03423",
4711                                      "vkCreateRayTracingPipelinesKHR parameter, pCreateInfos->basePipelineHandle, must be "
4712                                      "VK_NULL_HANDLE if pCreateInfos->flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag "
4713                                      "and pCreateInfos->basePipelineIndex is not -1.");
4714                 }
4715                 if (pCreateInfos[i].basePipelineIndex > (int32_t)i) {
4716                     skip |=
4717                         LogError(device, "VUID-vkCreateRayTracingPipelinesKHR-flags-03415",
4718                                  "vkCreateRayTracingPipelinesKHR: If the flags member of any element of pCreateInfos contains the"
4719                                  "VK_PIPELINE_CREATE_DERIVATIVE_BIT flag, and the basePipelineIndex member of that same element is"
4720                                  "not -1, basePipelineIndex must be less than the index into pCreateInfos that corresponds to that "
4721                                  "element.");
4722                 }
4723             }
4724             if (pCreateInfos[i].basePipelineHandle == VK_NULL_HANDLE) {
4725                 if (static_cast<uint32_t>(pCreateInfos[i].basePipelineIndex) >= createInfoCount) {
4726                     skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03422",
4727                                      "vkCreateRayTracingPipelinesKHR if flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT and"
4728                                      "basePipelineHandle is VK_NULL_HANDLE, basePipelineIndex (%d) must be a valid into the calling"
4729                                      "commands pCreateInfos parameter %d.",
4730                                      pCreateInfos[i].basePipelineIndex, createInfoCount);
4731                 }
4732             } else {
4733                 if (pCreateInfos[i].basePipelineIndex != -1) {
4734                     skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03424",
4735                                      "vkCreateRayTracingPipelinesKHR if flags contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT and"
4736                                      "basePipelineHandle is not VK_NULL_HANDLE, basePipelineIndex must be -1.");
4737                 }
4738             }
4739         }
4740         if (pCreateInfos[i].libraries.libraryCount == 0) {
4741             if (pCreateInfos[i].stageCount == 0) {
4742                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-libraries-02958",
4743                                  "If libraries.libraryCount is zero, then stageCount must not be zero .");
4744             }
4745             if (pCreateInfos[i].groupCount == 0) {
4746                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-libraries-02959",
4747                                  "If libraries.libraryCount is zero, then groupCount must not be zero .");
4748             }
4749         } else {
4750             if (pCreateInfos[i].pLibraryInterface == NULL) {
4751                 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-libraryCount-03466",
4752                                  "If the libraryCount member of libraries is greater than 0, pLibraryInterface must not be NULL.");
4753             }
4754         }
4755     }
4756 
4757     return skip;
4758 }
4759 
4760 #ifdef VK_USE_PLATFORM_WIN32_KHR
PreCallValidateGetDeviceGroupSurfacePresentModes2EXT(VkDevice device,const VkPhysicalDeviceSurfaceInfo2KHR * pSurfaceInfo,VkDeviceGroupPresentModeFlagsKHR * pModes) const4761 bool StatelessValidation::PreCallValidateGetDeviceGroupSurfacePresentModes2EXT(VkDevice device,
4762                                                                                const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
4763                                                                                VkDeviceGroupPresentModeFlagsKHR *pModes) const {
4764     bool skip = false;
4765     if (!device_extensions.vk_khr_swapchain)
4766         skip |= OutputExtensionError("vkGetDeviceGroupSurfacePresentModes2EXT", VK_KHR_SWAPCHAIN_EXTENSION_NAME);
4767     if (!device_extensions.vk_khr_get_surface_capabilities_2)
4768         skip |= OutputExtensionError("vkGetDeviceGroupSurfacePresentModes2EXT", VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
4769     if (!device_extensions.vk_khr_surface)
4770         skip |= OutputExtensionError("vkGetDeviceGroupSurfacePresentModes2EXT", VK_KHR_SURFACE_EXTENSION_NAME);
4771     if (!device_extensions.vk_khr_get_physical_device_properties_2)
4772         skip |=
4773             OutputExtensionError("vkGetDeviceGroupSurfacePresentModes2EXT", VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
4774     if (!device_extensions.vk_ext_full_screen_exclusive)
4775         skip |= OutputExtensionError("vkGetDeviceGroupSurfacePresentModes2EXT", VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME);
4776     skip |= validate_struct_type(
4777         "vkGetDeviceGroupSurfacePresentModes2EXT", "pSurfaceInfo", "VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR",
4778         pSurfaceInfo, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, true,
4779         "VUID-vkGetDeviceGroupSurfacePresentModes2EXT-pSurfaceInfo-parameter", "VUID-VkPhysicalDeviceSurfaceInfo2KHR-sType-sType");
4780     if (pSurfaceInfo != NULL) {
4781         const VkStructureType allowed_structs_VkPhysicalDeviceSurfaceInfo2KHR[] = {
4782             VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT,
4783             VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT};
4784 
4785         skip |= validate_struct_pnext("vkGetDeviceGroupSurfacePresentModes2EXT", "pSurfaceInfo->pNext",
4786                                       "VkSurfaceFullScreenExclusiveInfoEXT, VkSurfaceFullScreenExclusiveWin32InfoEXT",
4787                                       pSurfaceInfo->pNext, ARRAY_SIZE(allowed_structs_VkPhysicalDeviceSurfaceInfo2KHR),
4788                                       allowed_structs_VkPhysicalDeviceSurfaceInfo2KHR, GeneratedVulkanHeaderVersion,
4789                                       "VUID-VkPhysicalDeviceSurfaceInfo2KHR-pNext-pNext",
4790                                       "VUID-VkPhysicalDeviceSurfaceInfo2KHR-sType-unique");
4791 
4792         skip |= validate_required_handle("vkGetDeviceGroupSurfacePresentModes2EXT", "pSurfaceInfo->surface", pSurfaceInfo->surface);
4793     }
4794     return skip;
4795 }
4796 #endif
4797 
manual_PreCallValidateCreateFramebuffer(VkDevice device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer) const4798 bool StatelessValidation::manual_PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
4799                                                                   const VkAllocationCallbacks *pAllocator,
4800                                                                   VkFramebuffer *pFramebuffer) const {
4801     // Validation for pAttachments which is excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
4802     bool skip = false;
4803     if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT_KHR) == 0) {
4804         skip |= validate_array("vkCreateFramebuffer", "attachmentCount", "pAttachments", pCreateInfo->attachmentCount,
4805                                &pCreateInfo->pAttachments, false, true, kVUIDUndefined, kVUIDUndefined);
4806     }
4807     return skip;
4808 }
4809 
manual_PreCallValidateCmdSetLineStippleEXT(VkCommandBuffer commandBuffer,uint32_t lineStippleFactor,uint16_t lineStipplePattern) const4810 bool StatelessValidation::manual_PreCallValidateCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
4811                                                                      uint16_t lineStipplePattern) const {
4812     bool skip = false;
4813 
4814     if (lineStippleFactor < 1 || lineStippleFactor > 256) {
4815         skip |= LogError(commandBuffer, "VUID-vkCmdSetLineStippleEXT-lineStippleFactor-02776",
4816                          "vkCmdSetLineStippleEXT::lineStippleFactor=%d is not in [1,256].", lineStippleFactor);
4817     }
4818 
4819     return skip;
4820 }
4821 
manual_PreCallValidateCmdBindIndexBuffer(VkCommandBuffer commandBuffer,VkBuffer buffer,VkDeviceSize offset,VkIndexType indexType) const4822 bool StatelessValidation::manual_PreCallValidateCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer,
4823                                                                    VkDeviceSize offset, VkIndexType indexType) const {
4824     bool skip = false;
4825 
4826     if (indexType == VK_INDEX_TYPE_NONE_NV) {
4827         skip |= LogError(commandBuffer, "VUID-vkCmdBindIndexBuffer-indexType-02507",
4828                          "vkCmdBindIndexBuffer() indexType must not be VK_INDEX_TYPE_NONE_NV.");
4829     }
4830 
4831     const auto *index_type_uint8_features = lvl_find_in_chain<VkPhysicalDeviceIndexTypeUint8FeaturesEXT>(device_createinfo_pnext);
4832     if (indexType == VK_INDEX_TYPE_UINT8_EXT && (!index_type_uint8_features || !index_type_uint8_features->indexTypeUint8)) {
4833         skip |= LogError(commandBuffer, "VUID-vkCmdBindIndexBuffer-indexType-02765",
4834                          "vkCmdBindIndexBuffer() indexType is VK_INDEX_TYPE_UINT8_EXT but indexTypeUint8 feature is not enabled.");
4835     }
4836 
4837     return skip;
4838 }
4839 
manual_PreCallValidateCmdBindVertexBuffers(VkCommandBuffer commandBuffer,uint32_t firstBinding,uint32_t bindingCount,const VkBuffer * pBuffers,const VkDeviceSize * pOffsets) const4840 bool StatelessValidation::manual_PreCallValidateCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4841                                                                      uint32_t bindingCount, const VkBuffer *pBuffers,
4842                                                                      const VkDeviceSize *pOffsets) const {
4843     bool skip = false;
4844     if (firstBinding > device_limits.maxVertexInputBindings) {
4845         skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers-firstBinding-00624",
4846                          "vkCmdBindVertexBuffers() firstBinding (%u) must be less than maxVertexInputBindings (%u)", firstBinding,
4847                          device_limits.maxVertexInputBindings);
4848     } else if ((firstBinding + bindingCount) > device_limits.maxVertexInputBindings) {
4849         skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers-firstBinding-00625",
4850                          "vkCmdBindVertexBuffers() sum of firstBinding (%u) and bindingCount (%u) must be less than "
4851                          "maxVertexInputBindings (%u)",
4852                          firstBinding, bindingCount, device_limits.maxVertexInputBindings);
4853     }
4854 
4855     for (uint32_t i = 0; i < bindingCount; ++i) {
4856         if (pBuffers[i] == VK_NULL_HANDLE) {
4857             const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
4858             if (!(robustness2_features && robustness2_features->nullDescriptor)) {
4859                 skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers-pBuffers-04001",
4860                                  "vkCmdBindVertexBuffers() required parameter pBuffers[%d] specified as VK_NULL_HANDLE", i);
4861             } else {
4862                 if (pOffsets[i] != 0) {
4863                     skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers-pBuffers-04002",
4864                                      "vkCmdBindVertexBuffers() pBuffers[%d] is VK_NULL_HANDLE, but pOffsets[%d] is not 0", i, i);
4865                 }
4866             }
4867         }
4868     }
4869 
4870     return skip;
4871 }
4872 
manual_PreCallValidateSetDebugUtilsObjectNameEXT(VkDevice device,const VkDebugUtilsObjectNameInfoEXT * pNameInfo) const4873 bool StatelessValidation::manual_PreCallValidateSetDebugUtilsObjectNameEXT(VkDevice device,
4874                                                                            const VkDebugUtilsObjectNameInfoEXT *pNameInfo) const {
4875     bool skip = false;
4876     if (pNameInfo->objectType == VK_OBJECT_TYPE_UNKNOWN) {
4877         skip |= LogError(device, "VUID-VkDebugUtilsObjectNameInfoEXT-objectType-02589",
4878                          "vkSetDebugUtilsObjectNameEXT() pNameInfo->objectType cannot be VK_OBJECT_TYPE_UNKNOWN.");
4879     }
4880     return skip;
4881 }
4882 
manual_PreCallValidateSetDebugUtilsObjectTagEXT(VkDevice device,const VkDebugUtilsObjectTagInfoEXT * pTagInfo) const4883 bool StatelessValidation::manual_PreCallValidateSetDebugUtilsObjectTagEXT(VkDevice device,
4884                                                                           const VkDebugUtilsObjectTagInfoEXT *pTagInfo) const {
4885     bool skip = false;
4886     if (pTagInfo->objectType == VK_OBJECT_TYPE_UNKNOWN) {
4887         skip |= LogError(device, "VUID-VkDebugUtilsObjectTagInfoEXT-objectType-01908",
4888                          "vkSetDebugUtilsObjectTagEXT() pTagInfo->objectType cannot be VK_OBJECT_TYPE_UNKNOWN.");
4889     }
4890     return skip;
4891 }
4892 
manual_PreCallValidateAcquireNextImageKHR(VkDevice device,VkSwapchainKHR swapchain,uint64_t timeout,VkSemaphore semaphore,VkFence fence,uint32_t * pImageIndex) const4893 bool StatelessValidation::manual_PreCallValidateAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
4894                                                                     VkSemaphore semaphore, VkFence fence,
4895                                                                     uint32_t *pImageIndex) const {
4896     bool skip = false;
4897 
4898     if (semaphore == VK_NULL_HANDLE && fence == VK_NULL_HANDLE) {
4899         skip |= LogError(swapchain, "VUID-vkAcquireNextImageKHR-semaphore-01780",
4900                          "vkAcquireNextImageKHR: semaphore and fence are both VK_NULL_HANDLE.");
4901     }
4902 
4903     return skip;
4904 }
4905 
manual_PreCallValidateAcquireNextImage2KHR(VkDevice device,const VkAcquireNextImageInfoKHR * pAcquireInfo,uint32_t * pImageIndex) const4906 bool StatelessValidation::manual_PreCallValidateAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
4907                                                                      uint32_t *pImageIndex) const {
4908     bool skip = false;
4909 
4910     if (pAcquireInfo->semaphore == VK_NULL_HANDLE && pAcquireInfo->fence == VK_NULL_HANDLE) {
4911         skip |= LogError(pAcquireInfo->swapchain, "VUID-VkAcquireNextImageInfoKHR-semaphore-01782",
4912                          "vkAcquireNextImage2KHR: pAcquireInfo->semaphore and pAcquireInfo->fence are both VK_NULL_HANDLE.");
4913     }
4914 
4915     return skip;
4916 }
4917 
manual_PreCallValidateCmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer,uint32_t firstBinding,uint32_t bindingCount,const VkBuffer * pBuffers,const VkDeviceSize * pOffsets,const VkDeviceSize * pSizes) const4918 bool StatelessValidation::manual_PreCallValidateCmdBindTransformFeedbackBuffersEXT(VkCommandBuffer commandBuffer,
4919                                                                                    uint32_t firstBinding, uint32_t bindingCount,
4920                                                                                    const VkBuffer *pBuffers,
4921                                                                                    const VkDeviceSize *pOffsets,
4922                                                                                    const VkDeviceSize *pSizes) const {
4923     bool skip = false;
4924 
4925     char const *const cmd_name = "CmdBindTransformFeedbackBuffersEXT";
4926     for (uint32_t i = 0; i < bindingCount; ++i) {
4927         if (pOffsets[i] & 3) {
4928             skip |= LogError(commandBuffer, "VUID-vkCmdBindTransformFeedbackBuffersEXT-pOffsets-02359",
4929                              "%s: pOffsets[%" PRIu32 "](0x%" PRIxLEAST64 ") is not a multiple of 4.", cmd_name, i, pOffsets[i]);
4930         }
4931     }
4932 
4933     if (firstBinding >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
4934         skip |= LogError(commandBuffer, "VUID-vkCmdBindTransformFeedbackBuffersEXT-firstBinding-02356",
4935                          "%s: The firstBinding(%" PRIu32
4936                          ") index is greater than or equal to "
4937                          "VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
4938                          cmd_name, firstBinding, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
4939     }
4940 
4941     if (firstBinding + bindingCount > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
4942         skip |=
4943             LogError(commandBuffer, "VUID-vkCmdBindTransformFeedbackBuffersEXT-firstBinding-02357",
4944                      "%s: The sum of firstBinding(%" PRIu32 ") and bindCount(%" PRIu32
4945                      ") is greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
4946                      cmd_name, firstBinding, bindingCount, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
4947     }
4948 
4949     for (uint32_t i = 0; i < bindingCount; ++i) {
4950         // pSizes is optional and may be nullptr.
4951         if (pSizes != nullptr) {
4952             if (pSizes[i] != VK_WHOLE_SIZE &&
4953                 pSizes[i] > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferSize) {
4954                 skip |= LogError(commandBuffer, "VUID-vkCmdBindTransformFeedbackBuffersEXT-pSize-02361",
4955                                  "%s: pSizes[%" PRIu32 "] (0x%" PRIxLEAST64
4956                                  ") is not VK_WHOLE_SIZE and is greater than "
4957                                  "VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBufferSize.",
4958                                  cmd_name, i, pSizes[i]);
4959             }
4960         }
4961     }
4962 
4963     return skip;
4964 }
4965 
manual_PreCallValidateCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer,uint32_t firstCounterBuffer,uint32_t counterBufferCount,const VkBuffer * pCounterBuffers,const VkDeviceSize * pCounterBufferOffsets) const4966 bool StatelessValidation::manual_PreCallValidateCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer,
4967                                                                              uint32_t firstCounterBuffer,
4968                                                                              uint32_t counterBufferCount,
4969                                                                              const VkBuffer *pCounterBuffers,
4970                                                                              const VkDeviceSize *pCounterBufferOffsets) const {
4971     bool skip = false;
4972 
4973     char const *const cmd_name = "CmdBeginTransformFeedbackEXT";
4974     if (firstCounterBuffer >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
4975         skip |= LogError(commandBuffer, "VUID-vkCmdBeginTransformFeedbackEXT-firstCounterBuffer-02368",
4976                          "%s: The firstCounterBuffer(%" PRIu32
4977                          ") index is greater than or equal to "
4978                          "VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
4979                          cmd_name, firstCounterBuffer, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
4980     }
4981 
4982     if (firstCounterBuffer + counterBufferCount > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
4983         skip |=
4984             LogError(commandBuffer, "VUID-vkCmdBeginTransformFeedbackEXT-firstCounterBuffer-02369",
4985                      "%s: The sum of firstCounterBuffer(%" PRIu32 ") and counterBufferCount(%" PRIu32
4986                      ") is greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
4987                      cmd_name, firstCounterBuffer, counterBufferCount,
4988                      phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
4989     }
4990 
4991     return skip;
4992 }
4993 
manual_PreCallValidateCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer,uint32_t firstCounterBuffer,uint32_t counterBufferCount,const VkBuffer * pCounterBuffers,const VkDeviceSize * pCounterBufferOffsets) const4994 bool StatelessValidation::manual_PreCallValidateCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer,
4995                                                                            uint32_t firstCounterBuffer, uint32_t counterBufferCount,
4996                                                                            const VkBuffer *pCounterBuffers,
4997                                                                            const VkDeviceSize *pCounterBufferOffsets) const {
4998     bool skip = false;
4999 
5000     char const *const cmd_name = "CmdEndTransformFeedbackEXT";
5001     if (firstCounterBuffer >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
5002         skip |= LogError(commandBuffer, "VUID-vkCmdEndTransformFeedbackEXT-firstCounterBuffer-02376",
5003                          "%s: The firstCounterBuffer(%" PRIu32
5004                          ") index is greater than or equal to "
5005                          "VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
5006                          cmd_name, firstCounterBuffer, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
5007     }
5008 
5009     if (firstCounterBuffer + counterBufferCount > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers) {
5010         skip |=
5011             LogError(commandBuffer, "VUID-vkCmdEndTransformFeedbackEXT-firstCounterBuffer-02377",
5012                      "%s: The sum of firstCounterBuffer(%" PRIu32 ") and counterBufferCount(%" PRIu32
5013                      ") is greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBuffers(%" PRIu32 ").",
5014                      cmd_name, firstCounterBuffer, counterBufferCount,
5015                      phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBuffers);
5016     }
5017 
5018     return skip;
5019 }
5020 
manual_PreCallValidateCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer,uint32_t instanceCount,uint32_t firstInstance,VkBuffer counterBuffer,VkDeviceSize counterBufferOffset,uint32_t counterOffset,uint32_t vertexStride) const5021 bool StatelessValidation::manual_PreCallValidateCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount,
5022                                                                             uint32_t firstInstance, VkBuffer counterBuffer,
5023                                                                             VkDeviceSize counterBufferOffset,
5024                                                                             uint32_t counterOffset, uint32_t vertexStride) const {
5025     bool skip = false;
5026 
5027     if ((vertexStride <= 0) || (vertexStride > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride)) {
5028         skip |= LogError(
5029             counterBuffer, "VUID-vkCmdDrawIndirectByteCountEXT-vertexStride-02289",
5030             "vkCmdDrawIndirectByteCountEXT: vertexStride (%d) must be between 0 and maxTransformFeedbackBufferDataStride (%d).",
5031             vertexStride, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride);
5032     }
5033 
5034     if ((counterOffset % 4) != 0) {
5035         // TODO - Update when header are updated
5036         skip |= LogError(commandBuffer, "UNASSIGNED-vkCmdDrawIndirectByteCountEXT-offset",
5037                          "vkCmdDrawIndirectByteCountEXT(): offset (%" PRIu64 ") must be a multiple of 4.", counterOffset);
5038     }
5039 
5040     return skip;
5041 }
5042 
ValidateCreateSamplerYcbcrConversion(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion,const char * apiName) const5043 bool StatelessValidation::ValidateCreateSamplerYcbcrConversion(VkDevice device,
5044                                                                const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
5045                                                                const VkAllocationCallbacks *pAllocator,
5046                                                                VkSamplerYcbcrConversion *pYcbcrConversion,
5047                                                                const char *apiName) const {
5048     bool skip = false;
5049 
5050     // Check samplerYcbcrConversion feature is set
5051     const auto *ycbcr_features = lvl_find_in_chain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(device_createinfo_pnext);
5052     if ((ycbcr_features == nullptr) || (ycbcr_features->samplerYcbcrConversion == VK_FALSE)) {
5053         const auto *vulkan_11_features = lvl_find_in_chain<VkPhysicalDeviceVulkan11Features>(device_createinfo_pnext);
5054         if ((vulkan_11_features == nullptr) || (vulkan_11_features->samplerYcbcrConversion == VK_FALSE)) {
5055             skip |= LogError(device, "VUID-vkCreateSamplerYcbcrConversion-None-01648",
5056                              "%s: samplerYcbcrConversion must be enabled.", apiName);
5057         }
5058     }
5059 
5060 #ifdef VK_USE_PLATFORM_ANDROID_KHR
5061     const VkExternalFormatANDROID *pExternalFormatANDROID = lvl_find_in_chain<VkExternalFormatANDROID>(pCreateInfo);
5062     const bool isExternalFormat = pExternalFormatANDROID != nullptr && pExternalFormatANDROID->externalFormat != 0;
5063 #else
5064     const bool isExternalFormat = false;
5065 #endif
5066 
5067     const VkFormat format = pCreateInfo->format;
5068 
5069     // If there is a VkExternalFormatANDROID with externalFormat != 0, the value of components is ignored.
5070     if (!isExternalFormat) {
5071         const VkComponentMapping components = pCreateInfo->components;
5072         // XChroma Subsampled is same as "the format has a _422 or _420 suffix" from spec
5073         if (FormatIsXChromaSubsampled(format) == true) {
5074             if ((components.g != VK_COMPONENT_SWIZZLE_G) && (components.g != VK_COMPONENT_SWIZZLE_IDENTITY)) {
5075                 skip |=
5076                     LogError(device, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02581",
5077                              "%s: When using a XChroma subsampled format (%s) the components.g needs to be VK_COMPONENT_SWIZZLE_G "
5078                              "or VK_COMPONENT_SWIZZLE_IDENTITY, but is %s.",
5079                              apiName, string_VkFormat(format), string_VkComponentSwizzle(components.g));
5080             }
5081 
5082             if ((components.a != VK_COMPONENT_SWIZZLE_A) && (components.a != VK_COMPONENT_SWIZZLE_IDENTITY) &&
5083                 (components.a != VK_COMPONENT_SWIZZLE_ONE) && (components.a != VK_COMPONENT_SWIZZLE_ZERO)) {
5084                 skip |= LogError(
5085                     device, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02582",
5086                     "%s: When using a XChroma subsampled format (%s) the components.a needs to be VK_COMPONENT_SWIZZLE_A or "
5087                     "VK_COMPONENT_SWIZZLE_IDENTITY or VK_COMPONENT_SWIZZLE_ONE or VK_COMPONENT_SWIZZLE_ZERO, but is %s.",
5088                     apiName, string_VkFormat(format), string_VkComponentSwizzle(components.a));
5089             }
5090 
5091             if ((components.r != VK_COMPONENT_SWIZZLE_R) && (components.r != VK_COMPONENT_SWIZZLE_IDENTITY) &&
5092                 (components.r != VK_COMPONENT_SWIZZLE_B)) {
5093                 skip |=
5094                     LogError(device, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02583",
5095                              "%s: When using a XChroma subsampled format (%s) the components.r needs to be VK_COMPONENT_SWIZZLE_R "
5096                              "or VK_COMPONENT_SWIZZLE_IDENTITY or VK_COMPONENT_SWIZZLE_B, but is %s.",
5097                              apiName, string_VkFormat(format), string_VkComponentSwizzle(components.r));
5098             }
5099 
5100             if ((components.b != VK_COMPONENT_SWIZZLE_B) && (components.b != VK_COMPONENT_SWIZZLE_IDENTITY) &&
5101                 (components.b != VK_COMPONENT_SWIZZLE_R)) {
5102                 skip |=
5103                     LogError(device, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02584",
5104                              "%s: When using a XChroma subsampled format (%s) the components.b needs to be VK_COMPONENT_SWIZZLE_B "
5105                              "or VK_COMPONENT_SWIZZLE_IDENTITY or VK_COMPONENT_SWIZZLE_R, but is %s.",
5106                              apiName, string_VkFormat(format), string_VkComponentSwizzle(components.b));
5107             }
5108 
5109             // If one is identity, both need to be
5110             const bool rIdentity = ((components.r == VK_COMPONENT_SWIZZLE_R) || (components.r == VK_COMPONENT_SWIZZLE_IDENTITY));
5111             const bool bIdentity = ((components.b == VK_COMPONENT_SWIZZLE_B) || (components.b == VK_COMPONENT_SWIZZLE_IDENTITY));
5112             if ((rIdentity != bIdentity) && ((rIdentity == true) || (bIdentity == true))) {
5113                 skip |=
5114                     LogError(device, "VUID-VkSamplerYcbcrConversionCreateInfo-components-02585",
5115                              "%s: When using a XChroma subsampled format (%s) if either the components.r (%s) or components.b (%s) "
5116                              "are an identity swizzle, then both need to be an identity swizzle.",
5117                              apiName, string_VkFormat(format), string_VkComponentSwizzle(components.r),
5118                              string_VkComponentSwizzle(components.b));
5119             }
5120         }
5121 
5122         if (pCreateInfo->ycbcrModel != VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY) {
5123             // Checks same VU multiple ways in order to give a more useful error message
5124             const char *vuid = "VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrModel-01655";
5125             if ((components.r == VK_COMPONENT_SWIZZLE_ONE) || (components.r == VK_COMPONENT_SWIZZLE_ZERO) ||
5126                 (components.g == VK_COMPONENT_SWIZZLE_ONE) || (components.g == VK_COMPONENT_SWIZZLE_ZERO) ||
5127                 (components.b == VK_COMPONENT_SWIZZLE_ONE) || (components.b == VK_COMPONENT_SWIZZLE_ZERO)) {
5128                 skip |= LogError(
5129                     device, vuid,
5130                     "%s: The ycbcrModel is not VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY so components.r (%s), "
5131                     "components.g (%s), nor components.b (%s) can't be VK_COMPONENT_SWIZZLE_ZERO or VK_COMPONENT_SWIZZLE_ONE.",
5132                     apiName, string_VkComponentSwizzle(components.r), string_VkComponentSwizzle(components.g),
5133                     string_VkComponentSwizzle(components.b));
5134             }
5135 
5136             // "must not correspond to a channel which contains zero or one as a consequence of conversion to RGBA"
5137             // 4 channel format = no issue
5138             // 3 = no [a]
5139             // 2 = no [b,a]
5140             // 1 = no [g,b,a]
5141             // depth/stencil = no [g,b,a] (shouldn't ever occur, but no VU preventing it)
5142             const uint32_t channels = (FormatIsDepthOrStencil(format) == true) ? 1 : FormatChannelCount(format);
5143 
5144             if ((channels < 4) && ((components.r == VK_COMPONENT_SWIZZLE_A) || (components.g == VK_COMPONENT_SWIZZLE_A) ||
5145                                    (components.b == VK_COMPONENT_SWIZZLE_A))) {
5146                 skip |= LogError(device, vuid,
5147                                  "%s: The ycbcrModel is not VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY so components.r (%s), "
5148                                  "components.g (%s), or components.b (%s) can't be VK_COMPONENT_SWIZZLE_A.",
5149                                  apiName, string_VkComponentSwizzle(components.r), string_VkComponentSwizzle(components.g),
5150                                  string_VkComponentSwizzle(components.b));
5151             } else if ((channels < 3) &&
5152                        ((components.r == VK_COMPONENT_SWIZZLE_B) || (components.g == VK_COMPONENT_SWIZZLE_B) ||
5153                         (components.b == VK_COMPONENT_SWIZZLE_B) || (components.b == VK_COMPONENT_SWIZZLE_IDENTITY))) {
5154                 skip |= LogError(device, vuid,
5155                                  "%s: The ycbcrModel is not VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY so components.r (%s), "
5156                                  "components.g (%s), or components.b (%s) can't be VK_COMPONENT_SWIZZLE_B "
5157                                  "(components.b also can't be VK_COMPONENT_SWIZZLE_IDENTITY).",
5158                                  apiName, string_VkComponentSwizzle(components.r), string_VkComponentSwizzle(components.g),
5159                                  string_VkComponentSwizzle(components.b));
5160             } else if ((channels < 2) &&
5161                        ((components.r == VK_COMPONENT_SWIZZLE_G) || (components.g == VK_COMPONENT_SWIZZLE_G) ||
5162                         (components.g == VK_COMPONENT_SWIZZLE_IDENTITY) || (components.b == VK_COMPONENT_SWIZZLE_G))) {
5163                 skip |= LogError(device, vuid,
5164                                  "%s: The ycbcrModel is not VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY so components.r (%s), "
5165                                  "components.g (%s), or components.b (%s) can't be VK_COMPONENT_SWIZZLE_G "
5166                                  "(components.g also can't be VK_COMPONENT_SWIZZLE_IDENTITY).",
5167                                  apiName, string_VkComponentSwizzle(components.r), string_VkComponentSwizzle(components.g),
5168                                  string_VkComponentSwizzle(components.b));
5169             }
5170         }
5171     }
5172 
5173     return skip;
5174 }
5175 
manual_PreCallValidateCreateSamplerYcbcrConversion(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion) const5176 bool StatelessValidation::manual_PreCallValidateCreateSamplerYcbcrConversion(VkDevice device,
5177                                                                              const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
5178                                                                              const VkAllocationCallbacks *pAllocator,
5179                                                                              VkSamplerYcbcrConversion *pYcbcrConversion) const {
5180     return ValidateCreateSamplerYcbcrConversion(device, pCreateInfo, pAllocator, pYcbcrConversion,
5181                                                 "vkCreateSamplerYcbcrConversion");
5182 }
5183 
manual_PreCallValidateCreateSamplerYcbcrConversionKHR(VkDevice device,const VkSamplerYcbcrConversionCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkSamplerYcbcrConversion * pYcbcrConversion) const5184 bool StatelessValidation::manual_PreCallValidateCreateSamplerYcbcrConversionKHR(
5185     VkDevice device, const VkSamplerYcbcrConversionCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
5186     VkSamplerYcbcrConversion *pYcbcrConversion) const {
5187     return ValidateCreateSamplerYcbcrConversion(device, pCreateInfo, pAllocator, pYcbcrConversion,
5188                                                 "vkCreateSamplerYcbcrConversionKHR");
5189 }
5190 
manual_PreCallValidateImportSemaphoreFdKHR(VkDevice device,const VkImportSemaphoreFdInfoKHR * pImportSemaphoreFdInfo) const5191 bool StatelessValidation::manual_PreCallValidateImportSemaphoreFdKHR(
5192     VkDevice device, const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo) const {
5193     bool skip = false;
5194     VkExternalSemaphoreHandleTypeFlags supported_handle_types =
5195         VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT | VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
5196 
5197     if (0 == (pImportSemaphoreFdInfo->handleType & supported_handle_types)) {
5198         skip |= LogError(device, "VUID-VkImportSemaphoreFdInfoKHR-handleType-01143",
5199                          "vkImportSemaphoreFdKHR() to semaphore %s handleType %s is not one of the supported handleTypes (%s).",
5200                          report_data->FormatHandle(pImportSemaphoreFdInfo->semaphore).c_str(),
5201                          string_VkExternalSemaphoreHandleTypeFlagBits(pImportSemaphoreFdInfo->handleType),
5202                          string_VkExternalSemaphoreHandleTypeFlags(supported_handle_types).c_str());
5203     }
5204     return skip;
5205 }
5206 
manual_PreCallValidateCopyAccelerationStructureToMemoryKHR(VkDevice device,const VkCopyAccelerationStructureToMemoryInfoKHR * pInfo) const5207 bool StatelessValidation::manual_PreCallValidateCopyAccelerationStructureToMemoryKHR(
5208     VkDevice device, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) const {
5209     bool skip = false;
5210     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5211     if (!raytracing_features || raytracing_features->rayTracingHostAccelerationStructureCommands == VK_FALSE) {
5212         skip |=
5213             LogError(device, "", "VUID-vkCopyAccelerationStructureToMemoryKHR-rayTracingHostAccelerationStructureCommands-03447",
5214                      "vkCopyAccelerationStructureToMemoryKHR: the "
5215                      "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingHostAccelerationStructureCommands feature must be enabled.");
5216     }
5217     if (pInfo->mode != VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR) {
5218         skip |= LogError(device, "VUID-VkCopyAccelerationStructureToMemoryInfoKHR-mode-03412",
5219                          "vkCopyAccelerationStructureToMemoryKHR: mode must be VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR.");
5220     }
5221     return skip;
5222 }
5223 
manual_PreCallValidateCmdCopyAccelerationStructureToMemoryKHR(VkCommandBuffer commandBuffer,const VkCopyAccelerationStructureToMemoryInfoKHR * pInfo) const5224 bool StatelessValidation::manual_PreCallValidateCmdCopyAccelerationStructureToMemoryKHR(
5225     VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) const {
5226     bool skip = false;
5227     if (pInfo->mode != VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR) {
5228         skip |=  // to update VUID to VkCmdCopyAccelerationStructureToMemoryInfoKHR after spec update
5229             LogError(commandBuffer, "VUID-VkCopyAccelerationStructureToMemoryInfoKHR-mode-03412",
5230                      "vkCmdCopyAccelerationStructureToMemoryKHR: mode must be VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR.");
5231     }
5232     const auto *pnext_struct = lvl_find_in_chain<VkDeferredOperationInfoKHR>(pInfo->pNext);
5233     if (pnext_struct) {
5234         skip |= LogError(
5235             commandBuffer, "VUID-vkCmdCopyAccelerationStructureToMemoryKHR-pNext-03560",
5236             "vkCmdCopyAccelerationStructureToMemoryKHR: The VkDeferredOperationInfoKHR structure must not be included in the"
5237             "pNext chain of the VkCopyAccelerationStructureToMemoryInfoKHR structure.");
5238     }
5239     return skip;
5240 }
5241 
ValidateCopyAccelerationStructureInfoKHR(const VkCopyAccelerationStructureInfoKHR * pInfo,const char * api_name) const5242 bool StatelessValidation::ValidateCopyAccelerationStructureInfoKHR(const VkCopyAccelerationStructureInfoKHR *pInfo,
5243                                                                    const char *api_name) const {
5244     bool skip = false;
5245     if (!(pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR ||
5246           pInfo->mode == VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR)) {
5247         skip |= LogError(device, "VUID-VkCopyAccelerationStructureInfoKHR-mode-03410",
5248                          "(%s): mode must be VK_COPY_ACCELERATION_STRUCTURE_MODE_COMPACT_KHR"
5249                          "or VK_COPY_ACCELERATION_STRUCTURE_MODE_CLONE_KHR.",
5250                          api_name);
5251     }
5252     return skip;
5253 }
5254 
manual_PreCallValidateCopyAccelerationStructureKHR(VkDevice device,const VkCopyAccelerationStructureInfoKHR * pInfo) const5255 bool StatelessValidation::manual_PreCallValidateCopyAccelerationStructureKHR(
5256     VkDevice device, const VkCopyAccelerationStructureInfoKHR *pInfo) const {
5257     bool skip = false;
5258     skip |= ValidateCopyAccelerationStructureInfoKHR(pInfo, "vkCopyAccelerationStructureKHR()");
5259     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5260     if (!raytracing_features || raytracing_features->rayTracingHostAccelerationStructureCommands == VK_FALSE) {
5261         skip |= LogError(
5262             device, "VUID-vkCopyAccelerationStructureKHR-rayTracingHostAccelerationStructureCommands-03441",
5263             "vkCopyAccelerationStructureKHR(): the "
5264             "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingHostAccelerationStructureCommands feature must be enabled .");
5265     }
5266     return skip;
5267 }
5268 
manual_PreCallValidateCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,const VkCopyAccelerationStructureInfoKHR * pInfo) const5269 bool StatelessValidation::manual_PreCallValidateCmdCopyAccelerationStructureKHR(
5270     VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureInfoKHR *pInfo) const {
5271     bool skip = false;
5272     const auto *pnext_struct = lvl_find_in_chain<VkDeferredOperationInfoKHR>(pInfo->pNext);
5273     if (pnext_struct) {
5274         skip |= LogError(device, "VUID-vkCmdCopyAccelerationStructureKHR-pNext-03557",
5275                          "vkCmdCopyAccelerationStructureKHR(): The VkDeferredOperationInfoKHR structure must not be included in "
5276                          "the pNext chain of the VkCopyAccelerationStructureInfoKHR structure.");
5277     }
5278     skip |= ValidateCopyAccelerationStructureInfoKHR(pInfo, "vkCmdCopyAccelerationStructureKHR()");
5279     return skip;
5280 }
5281 
ValidateCopyMemoryToAccelerationStructureInfoKHR(const VkCopyMemoryToAccelerationStructureInfoKHR * pInfo,const char * api_name,bool is_cmd) const5282 bool StatelessValidation::ValidateCopyMemoryToAccelerationStructureInfoKHR(const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo,
5283                                                                            const char *api_name, bool is_cmd) const {
5284     bool skip = false;
5285     if (pInfo->mode != VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR) {
5286         skip |= LogError(device,
5287                          is_cmd ? "VUID-vkCmdCopyMemoryToAccelerationStructureKHR-mode-03413"
5288                                 : "VUID-VkCopyMemoryToAccelerationStructureInfoKHR-mode-03413",
5289                          "(%s): mode must be VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR.", api_name);
5290     }
5291     return skip;
5292 }
5293 
manual_PreCallValidateCopyMemoryToAccelerationStructureKHR(VkDevice device,const VkCopyMemoryToAccelerationStructureInfoKHR * pInfo) const5294 bool StatelessValidation::manual_PreCallValidateCopyMemoryToAccelerationStructureKHR(
5295     VkDevice device, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) const {
5296     bool skip = false;
5297     skip |= ValidateCopyMemoryToAccelerationStructureInfoKHR(pInfo, "vkCopyMemoryToAccelerationStructureKHR()", true);
5298     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5299     if (!raytracing_features || raytracing_features->rayTracingHostAccelerationStructureCommands == VK_FALSE) {
5300         skip |=
5301             LogError(device, "VUID-vkCopyMemoryToAccelerationStructureKHR-rayTracingHostAccelerationStructureCommands-03444",
5302                      "vkCopyMemoryToAccelerationStructureKHR() :the "
5303                      "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingHostAccelerationStructureCommands feature must be enabled.");
5304     }
5305     return skip;
5306 }
5307 
manual_PreCallValidateCmdCopyMemoryToAccelerationStructureKHR(VkCommandBuffer commandBuffer,const VkCopyMemoryToAccelerationStructureInfoKHR * pInfo) const5308 bool StatelessValidation::manual_PreCallValidateCmdCopyMemoryToAccelerationStructureKHR(
5309     VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) const {
5310     bool skip = false;
5311     const auto *pnext_struct = lvl_find_in_chain<VkDeferredOperationInfoKHR>(pInfo->pNext);
5312     if (pnext_struct) {
5313         skip |= LogError(device, "VUID-vkCmdCopyMemoryToAccelerationStructureKHR-pNext-03564",
5314                          "vkCmdCopyMemoryToAccelerationStructureKHR: The VkDeferredOperationInfoKHR structure must"
5315                          "not be included in the pNext chain of the VkCopyMemoryToAccelerationStructureInfoKHR structure.");
5316     }
5317     skip |= ValidateCopyMemoryToAccelerationStructureInfoKHR(pInfo, "vkCmdCopyMemoryToAccelerationStructureKHR()", false);
5318     return skip;
5319 }
manual_PreCallValidateCmdWriteAccelerationStructuresPropertiesKHR(VkCommandBuffer commandBuffer,uint32_t accelerationStructureCount,const VkAccelerationStructureKHR * pAccelerationStructures,VkQueryType queryType,VkQueryPool queryPool,uint32_t firstQuery) const5320 bool StatelessValidation::manual_PreCallValidateCmdWriteAccelerationStructuresPropertiesKHR(
5321     VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
5322     VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) const {
5323     bool skip = false;
5324     if (!(queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR ||
5325           queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR)) {
5326         skip |= LogError(device, "VUID-vkCmdWriteAccelerationStructuresPropertiesKHR-queryType-03432",
5327                          "vkCmdWriteAccelerationStructuresPropertiesKHR: queryType must be "
5328                          "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR or "
5329                          "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR.");
5330     }
5331     return skip;
5332 }
manual_PreCallValidateWriteAccelerationStructuresPropertiesKHR(VkDevice device,uint32_t accelerationStructureCount,const VkAccelerationStructureKHR * pAccelerationStructures,VkQueryType queryType,size_t dataSize,void * pData,size_t stride) const5333 bool StatelessValidation::manual_PreCallValidateWriteAccelerationStructuresPropertiesKHR(
5334     VkDevice device, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
5335     VkQueryType queryType, size_t dataSize, void *pData, size_t stride) const {
5336     bool skip = false;
5337     if (dataSize < accelerationStructureCount * stride) {
5338         skip |= LogError(device, "VUID-vkWriteAccelerationStructuresPropertiesKHR-dataSize-03452",
5339                          "vkWriteAccelerationStructuresPropertiesKHR: dataSize (%zu) must be greater than or equal to "
5340                          "accelerationStructureCount (%d) *stride(%zu).",
5341                          dataSize, accelerationStructureCount, stride);
5342     }
5343     if (!(queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR ||
5344           queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR)) {
5345         skip |= LogError(device, "VUID-vkWriteAccelerationStructuresPropertiesKHR-queryType-03432",
5346                          "vkWriteAccelerationStructuresPropertiesKHR: queryType must be "
5347                          "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR or "
5348                          "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR.");
5349     }
5350     if (queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR) {
5351         if (SafeModulo(stride, sizeof(VkDeviceSize)) != 0) {
5352             skip |= LogError(device, "VUID-vkWriteAccelerationStructuresPropertiesKHR-queryType-03448",
5353                              "vkWriteAccelerationStructuresPropertiesKHR: If queryType is "
5354                              "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR,"
5355                              "then stride (%zu) must be a multiple of the size of VkDeviceSize",
5356                              stride);
5357         }
5358     }
5359     if (queryType == VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR) {
5360         if (SafeModulo(stride, sizeof(VkDeviceSize)) != 0) {
5361             skip |= LogError(device, "VUID-vkWriteAccelerationStructuresPropertiesKHR-queryType-03450",
5362                              "vkWriteAccelerationStructuresPropertiesKHR: If queryType is "
5363                              "VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR,"
5364                              "then stride (%zu) must be a multiple of the size of VkDeviceSize",
5365                              stride);
5366         }
5367     }
5368     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5369     if (!raytracing_features || raytracing_features->rayTracingHostAccelerationStructureCommands == VK_FALSE) {
5370         skip |=
5371             LogError(device, "VUID-vkWriteAccelerationStructuresPropertiesKHR-rayTracingHostAccelerationStructureCommands-03454",
5372                      "vkWriteAccelerationStructuresPropertiesKHR: the "
5373                      "vkPhysicalDeviceRayTracingFeaturesKHR::rayTracingHostAccelerationStructureCommands"
5374                      "feature must be enabled ");
5375     }
5376     return skip;
5377 }
manual_PreCallValidateGetRayTracingCaptureReplayShaderGroupHandlesKHR(VkDevice device,VkPipeline pipeline,uint32_t firstGroup,uint32_t groupCount,size_t dataSize,void * pData) const5378 bool StatelessValidation::manual_PreCallValidateGetRayTracingCaptureReplayShaderGroupHandlesKHR(
5379     VkDevice device, VkPipeline pipeline, uint32_t firstGroup, uint32_t groupCount, size_t dataSize, void *pData) const {
5380     bool skip = false;
5381     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5382     if (!raytracing_features || raytracing_features->rayTracingShaderGroupHandleCaptureReplay == VK_FALSE) {
5383         skip |= LogError(device,
5384                          "VUID-vkGetRayTracingCaptureReplayShaderGroupHandlesKHR-rayTracingShaderGroupHandleCaptureReplay-03485",
5385                          "vkGetRayTracingCaptureReplayShaderGroupHandlesKHR: "
5386                          "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingShaderGroupHandleCaptureReplay"
5387                          "must be enabled to call this function.");
5388     }
5389     return skip;
5390 }
5391 
manual_PreCallValidateCmdTraceRaysKHR(VkCommandBuffer commandBuffer,const VkStridedBufferRegionKHR * pRaygenShaderBindingTable,const VkStridedBufferRegionKHR * pMissShaderBindingTable,const VkStridedBufferRegionKHR * pHitShaderBindingTable,const VkStridedBufferRegionKHR * pCallableShaderBindingTable,uint32_t width,uint32_t height,uint32_t depth) const5392 bool StatelessValidation::manual_PreCallValidateCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
5393                                                                 const VkStridedBufferRegionKHR *pRaygenShaderBindingTable,
5394                                                                 const VkStridedBufferRegionKHR *pMissShaderBindingTable,
5395                                                                 const VkStridedBufferRegionKHR *pHitShaderBindingTable,
5396                                                                 const VkStridedBufferRegionKHR *pCallableShaderBindingTable,
5397                                                                 uint32_t width, uint32_t height, uint32_t depth) const {
5398     bool skip = false;
5399     if (SafeModulo(pCallableShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5400         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-offset-04038",
5401                          "vkCmdTraceRaysKHR: The offset member of pCallableShaderBindingTable"
5402                          "must be a multiple of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5403     }
5404     if (SafeModulo(pCallableShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5405         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04040",
5406                          "vkCmdTraceRaysKHR: The stride member of pCallableShaderBindingTable must be a multiple"
5407                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5408     }
5409     if (pCallableShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5410         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04041",
5411                          "vkCmdTraceRaysKHR: The stride member of pCallableShaderBindingTable must be"
5412                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5413     }
5414     // hitShader
5415     if (SafeModulo(pHitShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5416         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-offset-04032",
5417                          "vkCmdTraceRaysKHR: The offset member of pHitShaderBindingTable must be a multiple"
5418                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5419     }
5420     if (SafeModulo(pHitShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5421         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04034",
5422                          "vkCmdTraceRaysKHR: The stride member of pHitShaderBindingTable must be a multiple"
5423                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5424     }
5425     if (pHitShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5426         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04035",
5427                          "vkCmdTraceRaysKHR: The stride member of pHitShaderBindingTable must be"
5428                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5429     }
5430 
5431     // missShader
5432     if (SafeModulo(pMissShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5433         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-offset-04026",
5434                          "vkCmdTraceRaysKHR: The offset member of pMissShaderBindingTable must be a multiple"
5435                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5436     }
5437     if (SafeModulo(pMissShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5438         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04028",
5439                          "vkCmdTraceRaysKHR: The stride member of pMissShaderBindingTable must be a multiple"
5440                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5441     }
5442     if (pMissShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5443         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-stride-04029",
5444                          "vkCmdTraceRaysKHR: The stride member of pMissShaderBindingTable must be"
5445                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5446     }
5447 
5448     // raygenShader
5449     if (SafeModulo(pRaygenShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5450         skip |= LogError(device, "VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-04021",
5451                          "vkCmdTraceRaysKHR: pRayGenShaderBindingTable->offset must be a multiple"
5452                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5453     }
5454     return skip;
5455 }
5456 
manual_PreCallValidateCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,const VkStridedBufferRegionKHR * pRaygenShaderBindingTable,const VkStridedBufferRegionKHR * pMissShaderBindingTable,const VkStridedBufferRegionKHR * pHitShaderBindingTable,const VkStridedBufferRegionKHR * pCallableShaderBindingTable,VkBuffer buffer,VkDeviceSize offset) const5457 bool StatelessValidation::manual_PreCallValidateCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
5458                                                                         const VkStridedBufferRegionKHR *pRaygenShaderBindingTable,
5459                                                                         const VkStridedBufferRegionKHR *pMissShaderBindingTable,
5460                                                                         const VkStridedBufferRegionKHR *pHitShaderBindingTable,
5461                                                                         const VkStridedBufferRegionKHR *pCallableShaderBindingTable,
5462                                                                         VkBuffer buffer, VkDeviceSize offset) const {
5463     bool skip = false;
5464     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5465     if (!raytracing_features || raytracing_features->rayTracingIndirectTraceRays == VK_FALSE) {
5466         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-rayTracingIndirectTraceRays-03518",
5467                          "vkCmdTraceRaysIndirectKHR: the VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingIndirectTraceRays "
5468                          "feature must be enabled.");
5469     }
5470     if (SafeModulo(pCallableShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5471         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-offset-04038",
5472                          "vkCmdTraceRaysIndirectKHR: The offset member of pCallableShaderBindingTable"
5473                          "must be a multiple of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5474     }
5475     if (SafeModulo(pCallableShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5476         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04040",
5477                          "vkCmdTraceRaysIndirectKHR: The stride member of pCallableShaderBindingTable must be a multiple"
5478                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5479     }
5480     if (pCallableShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5481         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04041",
5482                          "vkCmdTraceRaysIndirectKHR: The stride member of pCallableShaderBindingTable must be"
5483                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5484     }
5485     // hitShader
5486     if (SafeModulo(pHitShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5487         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-offset-04032",
5488                          "vkCmdTraceRaysIndirectKHR: The offset member of pHitShaderBindingTable must be a multiple"
5489                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5490     }
5491     if (SafeModulo(pHitShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5492         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04034",
5493                          "vkCmdTraceRaysIndirectKHR: The stride member of pHitShaderBindingTable must be a multiple"
5494                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5495     }
5496     if (pHitShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5497         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04035",
5498                          "vkCmdTraceRaysIndirectKHR: The stride member of pHitShaderBindingTable must be"
5499                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5500     }
5501 
5502     // missShader
5503     if (SafeModulo(pMissShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5504         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-offset-04026",
5505                          "vkCmdTraceRaysIndirectKHR: The offset member of pMissShaderBindingTable must be a multiple"
5506                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5507     }
5508     if (SafeModulo(pMissShaderBindingTable->stride, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupHandleSize) != 0) {
5509         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04028",
5510                          "vkCmdTraceRaysIndirectKHR: The stride member of pMissShaderBindingTable must be a multiple"
5511                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupHandleSize.");
5512     }
5513     if (pMissShaderBindingTable->stride > phys_dev_ext_props.ray_tracing_propsKHR.maxShaderGroupStride) {
5514         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-stride-04029",
5515                          "vkCmdTraceRaysIndirectKHR: The stride member of pMissShaderBindingTable must be"
5516                          "less than or equal to VkPhysicalDeviceRayTracingPropertiesKHR::maxShaderGroupStride.");
5517     }
5518 
5519     // raygenShader
5520     if (SafeModulo(pRaygenShaderBindingTable->offset, phys_dev_ext_props.ray_tracing_propsKHR.shaderGroupBaseAlignment) != 0) {
5521         skip |= LogError(device, "VUID-vkCmdTraceRaysIndirectKHR-pRayGenShaderBindingTable-04021",
5522                          "vkCmdTraceRaysIndirectKHR: pRayGenShaderBindingTable->offset must be a multiple"
5523                          "of VkPhysicalDeviceRayTracingPropertiesKHR::shaderGroupBaseAlignment.");
5524     }
5525     return skip;
5526 }
manual_PreCallValidateCmdTraceRaysNV(VkCommandBuffer commandBuffer,VkBuffer raygenShaderBindingTableBuffer,VkDeviceSize raygenShaderBindingOffset,VkBuffer missShaderBindingTableBuffer,VkDeviceSize missShaderBindingOffset,VkDeviceSize missShaderBindingStride,VkBuffer hitShaderBindingTableBuffer,VkDeviceSize hitShaderBindingOffset,VkDeviceSize hitShaderBindingStride,VkBuffer callableShaderBindingTableBuffer,VkDeviceSize callableShaderBindingOffset,VkDeviceSize callableShaderBindingStride,uint32_t width,uint32_t height,uint32_t depth) const5527 bool StatelessValidation::manual_PreCallValidateCmdTraceRaysNV(
5528     VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer, VkDeviceSize raygenShaderBindingOffset,
5529     VkBuffer missShaderBindingTableBuffer, VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
5530     VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset, VkDeviceSize hitShaderBindingStride,
5531     VkBuffer callableShaderBindingTableBuffer, VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
5532     uint32_t width, uint32_t height, uint32_t depth) const {
5533     bool skip = false;
5534     if (SafeModulo(callableShaderBindingOffset, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupBaseAlignment) != 0) {
5535         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-callableShaderBindingOffset-02462",
5536                          "vkCmdTraceRaysNV: callableShaderBindingOffset must be a multiple of "
5537                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
5538     }
5539     if (SafeModulo(callableShaderBindingStride, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupHandleSize) != 0) {
5540         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02465",
5541                          "vkCmdTraceRaysNV: callableShaderBindingStride must be a multiple of "
5542                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
5543     }
5544     if (callableShaderBindingStride > phys_dev_ext_props.ray_tracing_propsNV.maxShaderGroupStride) {
5545         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02468",
5546                          "vkCmdTraceRaysNV: callableShaderBindingStride must be less than or equal to "
5547                          "VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride. ");
5548     }
5549 
5550     // hitShader
5551     if (SafeModulo(hitShaderBindingOffset, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupBaseAlignment) != 0) {
5552         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-hitShaderBindingOffset-02460",
5553                          "vkCmdTraceRaysNV: hitShaderBindingOffset must be a multiple of "
5554                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
5555     }
5556     if (SafeModulo(hitShaderBindingStride, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupHandleSize) != 0) {
5557         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02464",
5558                          "vkCmdTraceRaysNV: hitShaderBindingStride must be a multiple of "
5559                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
5560     }
5561     if (hitShaderBindingStride > phys_dev_ext_props.ray_tracing_propsNV.maxShaderGroupStride) {
5562         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02467",
5563                          "vkCmdTraceRaysNV: hitShaderBindingStride must be less than or equal to "
5564                          "VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride.");
5565     }
5566 
5567     // missShader
5568     if (SafeModulo(missShaderBindingOffset, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupBaseAlignment) != 0) {
5569         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-missShaderBindingOffset-02458",
5570                          "vkCmdTraceRaysNV: missShaderBindingOffset must be a multiple of "
5571                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
5572     }
5573     if (SafeModulo(missShaderBindingStride, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupHandleSize) != 0) {
5574         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-missShaderBindingStride-02463",
5575                          "vkCmdTraceRaysNV: missShaderBindingStride must be a multiple of "
5576                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
5577     }
5578     if (missShaderBindingStride > phys_dev_ext_props.ray_tracing_propsNV.maxShaderGroupStride) {
5579         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-missShaderBindingStride-02466",
5580                          "vkCmdTraceRaysNV: missShaderBindingStride must be less than or equal to "
5581                          "VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride.");
5582     }
5583 
5584     // raygenShader
5585     if (SafeModulo(raygenShaderBindingOffset, phys_dev_ext_props.ray_tracing_propsNV.shaderGroupBaseAlignment) != 0) {
5586         skip |= LogError(device, "VUID-vkCmdTraceRaysNV-raygenShaderBindingOffset-02456",
5587                          "vkCmdTraceRaysNV: raygenShaderBindingOffset must be a multiple of "
5588                          "VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
5589     }
5590     if (width > device_limits.maxComputeWorkGroupCount[0]) {
5591         skip |=
5592             LogError(device, "VUID-vkCmdTraceRaysNV-width-02469",
5593                      "vkCmdTraceRaysNV: width must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[o].");
5594     }
5595     if (height > device_limits.maxComputeWorkGroupCount[1]) {
5596         skip |=
5597             LogError(device, "VUID-vkCmdTraceRaysNV-height-02470",
5598                      "vkCmdTraceRaysNV: height must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1].");
5599     }
5600     if (depth > device_limits.maxComputeWorkGroupCount[2]) {
5601         skip |=
5602             LogError(device, "VUID-vkCmdTraceRaysNV-depth-02471",
5603                      "vkCmdTraceRaysNV: depth must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2].");
5604     }
5605     return skip;
5606 }
5607 
manual_PreCallValidateCmdBuildAccelerationStructureIndirectKHR(VkCommandBuffer commandBuffer,const VkAccelerationStructureBuildGeometryInfoKHR * pInfo,VkBuffer indirectBuffer,VkDeviceSize indirectOffset,uint32_t indirectStride) const5608 bool StatelessValidation::manual_PreCallValidateCmdBuildAccelerationStructureIndirectKHR(
5609     VkCommandBuffer commandBuffer, const VkAccelerationStructureBuildGeometryInfoKHR *pInfo, VkBuffer indirectBuffer,
5610     VkDeviceSize indirectOffset, uint32_t indirectStride) const {
5611     bool skip = false;
5612     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5613     if (!raytracing_features || raytracing_features->rayTracingIndirectAccelerationStructureBuild == VK_FALSE) {
5614         skip |= LogError(
5615             device, "VUID-vkCmdBuildAccelerationStructureIndirectKHR-rayTracingIndirectAccelerationStructureBuild-03535",
5616             "vkCmdBuildAccelerationStructureIndirectKHR: The "
5617             "VkPhysicalDeviceRayTracingFeaturesKHR::rayTracingIndirectAccelerationStructureBuild feature must be enabled.");
5618     }
5619     const auto *pnext_struct = lvl_find_in_chain<VkDeferredOperationInfoKHR>(pInfo->pNext);
5620     if (pnext_struct) {
5621         skip |=
5622             LogError(device, "VUID-vkCmdBuildAccelerationStructureIndirectKHR-pNext-03536",
5623                      "vkCmdBuildAccelerationStructureIndirectKHR: The VkDeferredOperationInfoKHR structure must not be included in "
5624                      "the pNext chain of any of the provided VkAccelerationStructureBuildGeometryInfoKHR structures.");
5625     }
5626     return false;
5627 }
5628 
manual_PreCallValidateGetDeviceAccelerationStructureCompatibilityKHR(VkDevice device,const VkAccelerationStructureVersionKHR * version) const5629 bool StatelessValidation::manual_PreCallValidateGetDeviceAccelerationStructureCompatibilityKHR(
5630     VkDevice device, const VkAccelerationStructureVersionKHR *version) const {
5631     bool skip = false;
5632     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5633     if (!raytracing_features || !(raytracing_features->rayQuery || raytracing_features->rayTracing)) {
5634         skip |= LogError(device, "VUID-vkGetDeviceAccelerationStructureCompatibilityKHR-rayTracing-03565",
5635                          "vkGetDeviceAccelerationStructureCompatibilityKHR: The rayTracing or rayQuery feature must be enabled.");
5636     }
5637     return skip;
5638 }
5639 
manual_PreCallValidateBuildAccelerationStructureKHR(VkDevice device,uint32_t infoCount,const VkAccelerationStructureBuildGeometryInfoKHR * pInfos,const VkAccelerationStructureBuildOffsetInfoKHR * const * ppOffsetInfos) const5640 bool StatelessValidation::manual_PreCallValidateBuildAccelerationStructureKHR(
5641     VkDevice device, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
5642     const VkAccelerationStructureBuildOffsetInfoKHR *const *ppOffsetInfos) const {
5643     bool skip = false;
5644     const auto *raytracing_features = lvl_find_in_chain<VkPhysicalDeviceRayTracingFeaturesKHR>(device_createinfo_pnext);
5645     if (!raytracing_features || raytracing_features->rayTracingHostAccelerationStructureCommands == VK_FALSE) {
5646         skip |= LogError(device, "VUID-vkBuildAccelerationStructureKHR-rayTracingHostAccelerationStructureCommands-03439",
5647                          "vkBuildAccelerationStructureKHR: The "
5648                          "vkPhysicalDeviceRayTracingFeaturesKHR::rayTracingHostAccelerationStructureCommands"
5649                          "feature must be enabled .");
5650     }
5651     return skip;
5652 }
manual_PreCallValidateCmdBuildAccelerationStructureKHR(VkCommandBuffer commandBuffer,uint32_t infoCount,const VkAccelerationStructureBuildGeometryInfoKHR * pInfos,const VkAccelerationStructureBuildOffsetInfoKHR * const * ppOffsetInfos) const5653 bool StatelessValidation::manual_PreCallValidateCmdBuildAccelerationStructureKHR(
5654     VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
5655     const VkAccelerationStructureBuildOffsetInfoKHR *const *ppOffsetInfos) const {
5656     bool skip = false;
5657     for (uint32_t i = 0; i < infoCount; ++i) {
5658         const auto *pnext_struct = lvl_find_in_chain<VkDeferredOperationInfoKHR>(pInfos->pNext);
5659         if (pnext_struct) {
5660             skip |=
5661                 LogError(commandBuffer, "VUID-vkCmdBuildAccelerationStructureKHR-pNext-03532",
5662                          "vkCmdBuildAccelerationStructureKHR: The VkDeferredOperationInfoKHR structure must not be included in the"
5663                          "pNext chain of any of the provided VkAccelerationStructureBuildGeometryInfoKHR structures.");
5664         }
5665     }
5666     return skip;
5667 }
5668 
manual_PreCallValidateCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer,uint32_t viewportCount,const VkViewport * pViewports) const5669 bool StatelessValidation::manual_PreCallValidateCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
5670                                                                            const VkViewport *pViewports) const {
5671     bool skip = false;
5672 
5673     if (!physical_device_features.multiViewport) {
5674         if (viewportCount != 1) {
5675             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportWithCountEXT-viewportCount-03395",
5676                              "vkCmdSetViewportWithCountEXT: The multiViewport feature is disabled, but viewportCount (=%" PRIu32
5677                              ") is not 1.",
5678                              viewportCount);
5679         }
5680     } else {  // multiViewport enabled
5681         if (viewportCount < 1 || viewportCount > device_limits.maxViewports) {
5682             skip |= LogError(commandBuffer, "VUID-vkCmdSetViewportWithCountEXT-viewportCount-03394",
5683                              "vkCmdSetViewportWithCountEXT:  viewportCount (=%" PRIu32
5684                              ") must "
5685                              "not be greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
5686                              viewportCount, device_limits.maxViewports);
5687         }
5688     }
5689 
5690     if (pViewports) {
5691         for (uint32_t viewport_i = 0; viewport_i < viewportCount; ++viewport_i) {
5692             const auto &viewport = pViewports[viewport_i];  // will crash on invalid ptr
5693             const char *fn_name = "vkCmdSetViewportWithCountEXT";
5694             skip |= manual_PreCallValidateViewport(
5695                 viewport, fn_name, ParameterName("pViewports[%i]", ParameterName::IndexVector{viewport_i}), commandBuffer);
5696         }
5697     }
5698 
5699     return skip;
5700 }
5701 
manual_PreCallValidateCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer,uint32_t scissorCount,const VkRect2D * pScissors) const5702 bool StatelessValidation::manual_PreCallValidateCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
5703                                                                           const VkRect2D *pScissors) const {
5704     bool skip = false;
5705 
5706     if (!physical_device_features.multiViewport) {
5707         if (scissorCount != 1) {
5708             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-scissorCount-03398",
5709                              "vkCmdSetScissorWithCountEXT: scissorCount (=%" PRIu32
5710                              ") must "
5711                              "be 1 when the multiViewport feature is disabled.",
5712                              scissorCount);
5713         }
5714     } else {  // multiViewport enabled
5715         if (scissorCount == 0) {
5716             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-scissorCount-03397",
5717                              "vkCmdSetScissorWithCountEXT: scissorCount (=%" PRIu32
5718                              ") must "
5719                              "be great than zero.",
5720                              scissorCount);
5721         } else if (scissorCount > device_limits.maxViewports) {
5722             skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-scissorCount-03397",
5723                              "vkCmdSetScissorWithCountEXT: scissorCount (=%" PRIu32
5724                              ") must "
5725                              "not be greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 ").",
5726                              scissorCount, device_limits.maxViewports);
5727         }
5728     }
5729 
5730     if (pScissors) {
5731         for (uint32_t scissor_i = 0; scissor_i < scissorCount; ++scissor_i) {
5732             const auto &scissor = pScissors[scissor_i];  // will crash on invalid ptr
5733 
5734             if (scissor.offset.x < 0) {
5735                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-x-03399",
5736                                  "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.x (=%" PRIi32 ") is negative.", scissor_i,
5737                                  scissor.offset.x);
5738             }
5739 
5740             if (scissor.offset.y < 0) {
5741                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-x-03399",
5742                                  "vkCmdSetScissor: pScissors[%" PRIu32 "].offset.y (=%" PRIi32 ") is negative.", scissor_i,
5743                                  scissor.offset.y);
5744             }
5745 
5746             const int64_t x_sum = static_cast<int64_t>(scissor.offset.x) + static_cast<int64_t>(scissor.extent.width);
5747             if (x_sum > INT32_MAX) {
5748                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-offset-03400",
5749                                  "vkCmdSetScissor: offset.x + extent.width (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
5750                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
5751                                  scissor.offset.x, scissor.extent.width, x_sum, scissor_i);
5752             }
5753 
5754             const int64_t y_sum = static_cast<int64_t>(scissor.offset.y) + static_cast<int64_t>(scissor.extent.height);
5755             if (y_sum > INT32_MAX) {
5756                 skip |= LogError(commandBuffer, "VUID-vkCmdSetScissorWithCountEXT-offset-03401",
5757                                  "vkCmdSetScissor: offset.y + extent.height (=%" PRIi32 " + %" PRIu32 " = %" PRIi64
5758                                  ") of pScissors[%" PRIu32 "] will overflow int32_t.",
5759                                  scissor.offset.y, scissor.extent.height, y_sum, scissor_i);
5760             }
5761         }
5762     }
5763 
5764     return skip;
5765 }
5766 
manual_PreCallValidateCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer,uint32_t firstBinding,uint32_t bindingCount,const VkBuffer * pBuffers,const VkDeviceSize * pOffsets,const VkDeviceSize * pSizes,const VkDeviceSize * pStrides) const5767 bool StatelessValidation::manual_PreCallValidateCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
5768                                                                          uint32_t bindingCount, const VkBuffer *pBuffers,
5769                                                                          const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
5770                                                                          const VkDeviceSize *pStrides) const {
5771     bool skip = false;
5772     if (firstBinding >= device_limits.maxVertexInputBindings) {
5773         skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers2EXT-firstBinding-03355",
5774                          "vkCmdBindVertexBuffers2EXT() firstBinding (%u) must be less than maxVertexInputBindings (%u)",
5775                          firstBinding, device_limits.maxVertexInputBindings);
5776     } else if ((firstBinding + bindingCount) > device_limits.maxVertexInputBindings) {
5777         skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers2EXT-firstBinding-03356",
5778                          "vkCmdBindVertexBuffers2EXT() sum of firstBinding (%u) and bindingCount (%u) must be less than "
5779                          "maxVertexInputBindings (%u)",
5780                          firstBinding, bindingCount, device_limits.maxVertexInputBindings);
5781     }
5782 
5783     for (uint32_t i = 0; i < bindingCount; ++i) {
5784         if (pBuffers[i] == VK_NULL_HANDLE) {
5785             const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(device_createinfo_pnext);
5786             if (!(robustness2_features && robustness2_features->nullDescriptor)) {
5787                 skip |= LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers2EXT-pBuffers-04111",
5788                                  "vkCmdBindVertexBuffers2EXT() required parameter pBuffers[%d] specified as VK_NULL_HANDLE", i);
5789             } else {
5790                 if (pOffsets[i] != 0) {
5791                     skip |=
5792                         LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers2EXT-pBuffers-04112",
5793                                  "vkCmdBindVertexBuffers2EXT() pBuffers[%d] is VK_NULL_HANDLE, but pOffsets[%d] is not 0", i, i);
5794                 }
5795             }
5796         }
5797         if (pStrides) {
5798             if (pStrides[i] > device_limits.maxVertexInputBindingStride) {
5799                 skip |=
5800                     LogError(commandBuffer, "VUID-vkCmdBindVertexBuffers2EXT-pStrides-03362",
5801                              "vkCmdBindVertexBuffers2EXT() pStrides[%d] (%u) must be less than maxVertexInputBindingStride (%u)", i,
5802                              pStrides[i], device_limits.maxVertexInputBindingStride);
5803             }
5804         }
5805     }
5806 
5807     return skip;
5808 }
5809