From 0317424d7f9b4754041a4097d232e367dc001206 Mon Sep 17 00:00:00 2001 From: Mike Schuchardt Date: Mon, 2 Sep 2024 11:22:55 -0700 Subject: [PATCH] safestruct: Add VkPipelineCreatInfoKHR workaround Pipeline create info structs can appear in the VkPipelineCreatInfoKHR pNext chain even though they don't extend that structure in the traditional sense. --- scripts/generators/safe_struct_generator.py | 15 +++++++++++-- src/vulkan/vk_safe_struct_utils.cpp | 24 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/scripts/generators/safe_struct_generator.py b/scripts/generators/safe_struct_generator.py index e1d2bf0..f4e17bf 100644 --- a/scripts/generators/safe_struct_generator.py +++ b/scripts/generators/safe_struct_generator.py @@ -82,6 +82,17 @@ def __init__(self): ', const bool is_host, const VkAccelerationStructureBuildRangeInfoKHR *build_range_info', } + def isInPnextChain(self, struct: Struct) -> bool: + # Can appear in VkPipelineCreateInfoKHR::pNext even though it isn't listed in the xml structextends attribute + # VUID-VkPipelineCreateInfoKHR-pNext-09604 + pipeline_create_infos = [ + 'VkGraphicsPipelineCreateInfo', + 'VkExecutionGraphPipelineCreateInfoAMDX', + 'VkRayTracingPipelineCreateInfoKHR', + 'VkComputePipelineCreateInfo', + ] + return struct.extends or struct.name in pipeline_create_infos + # Determine if a structure needs a safe_struct helper function # That is, it has an sType or one of its members is a pointer def needSafeStruct(self, struct: Struct) -> bool: @@ -296,7 +307,7 @@ def generateUtil(self): } ''') guard_helper = PlatformGuardHelper() - for struct in [x for x in self.vk.structs.values() if x.extends]: + for struct in filter(self.isInPnextChain, self.vk.structs.values()): safe_name = self.convertName(struct.name) out.extend(guard_helper.add_guard(struct.protect)) out.append(f' case {struct.sType}:\n') @@ -352,7 +363,7 @@ def generateUtil(self): break; ''') - for struct in [x for x in self.vk.structs.values() if x.extends]: + for struct in filter(self.isInPnextChain, self.vk.structs.values()): safe_name = self.convertName(struct.name) out.extend(guard_helper.add_guard(struct.protect)) out.append(f' case {struct.sType}:\n') diff --git a/src/vulkan/vk_safe_struct_utils.cpp b/src/vulkan/vk_safe_struct_utils.cpp index 1fd2d9b..3550dba 100644 --- a/src/vulkan/vk_safe_struct_utils.cpp +++ b/src/vulkan/vk_safe_struct_utils.cpp @@ -60,6 +60,12 @@ void *SafePnextCopy(const void *pNext, PNextCopyState* copy_state) { case VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO: safe_pNext = new safe_VkShaderModuleCreateInfo(reinterpret_cast(pNext), copy_state, false); break; + case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: + safe_pNext = new safe_VkComputePipelineCreateInfo(reinterpret_cast(pNext), copy_state, false); + break; + case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: + safe_pNext = new safe_VkGraphicsPipelineCreateInfo(reinterpret_cast(pNext), copy_state, false); + break; case VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO: safe_pNext = new safe_VkPipelineLayoutCreateInfo(reinterpret_cast(pNext), copy_state, false); break; @@ -937,6 +943,9 @@ void *SafePnextCopy(const void *pNext, PNextCopyState* copy_state) { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ENQUEUE_PROPERTIES_AMDX: safe_pNext = new safe_VkPhysicalDeviceShaderEnqueuePropertiesAMDX(reinterpret_cast(pNext), copy_state, false); break; + case VK_STRUCTURE_TYPE_EXECUTION_GRAPH_PIPELINE_CREATE_INFO_AMDX: + safe_pNext = new safe_VkExecutionGraphPipelineCreateInfoAMDX(reinterpret_cast(pNext), copy_state, false); + break; case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NODE_CREATE_INFO_AMDX: safe_pNext = new safe_VkPipelineShaderStageNodeCreateInfoAMDX(reinterpret_cast(pNext), copy_state, false); break; @@ -1849,6 +1858,9 @@ void *SafePnextCopy(const void *pNext, PNextCopyState* copy_state) { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR: safe_pNext = new safe_VkPhysicalDeviceAccelerationStructurePropertiesKHR(reinterpret_cast(pNext), copy_state, false); break; + case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR: + safe_pNext = new safe_VkRayTracingPipelineCreateInfoKHR(reinterpret_cast(pNext), copy_state, false); + break; case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR: safe_pNext = new safe_VkPhysicalDeviceRayTracingPipelineFeaturesKHR(reinterpret_cast(pNext), copy_state, false); break; @@ -1913,6 +1925,12 @@ void FreePnextChain(const void *pNext) { case VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO: delete reinterpret_cast(header); break; + case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: + delete reinterpret_cast(header); + break; + case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: + delete reinterpret_cast(header); + break; case VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO: delete reinterpret_cast(header); break; @@ -2790,6 +2808,9 @@ void FreePnextChain(const void *pNext) { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ENQUEUE_PROPERTIES_AMDX: delete reinterpret_cast(header); break; + case VK_STRUCTURE_TYPE_EXECUTION_GRAPH_PIPELINE_CREATE_INFO_AMDX: + delete reinterpret_cast(header); + break; case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NODE_CREATE_INFO_AMDX: delete reinterpret_cast(header); break; @@ -3702,6 +3723,9 @@ void FreePnextChain(const void *pNext) { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR: delete reinterpret_cast(header); break; + case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR: + delete reinterpret_cast(header); + break; case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR: delete reinterpret_cast(header); break;