Skip to content

Commit

Permalink
safestruct: Add VkPipelineCreatInfoKHR workaround
Browse files Browse the repository at this point in the history
Pipeline create info structs can appear in the VkPipelineCreatInfoKHR
pNext chain even though they don't extend that structure in the
traditional sense.
  • Loading branch information
mikes-lunarg committed Sep 2, 2024
1 parent 0b4fedc commit 0317424
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scripts/generators/safe_struct_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
24 changes: 24 additions & 0 deletions src/vulkan/vk_safe_struct_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const VkShaderModuleCreateInfo *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
safe_pNext = new safe_VkComputePipelineCreateInfo(reinterpret_cast<const VkComputePipelineCreateInfo *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
safe_pNext = new safe_VkGraphicsPipelineCreateInfo(reinterpret_cast<const VkGraphicsPipelineCreateInfo *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO:
safe_pNext = new safe_VkPipelineLayoutCreateInfo(reinterpret_cast<const VkPipelineLayoutCreateInfo *>(pNext), copy_state, false);
break;
Expand Down Expand Up @@ -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<const VkPhysicalDeviceShaderEnqueuePropertiesAMDX *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_EXECUTION_GRAPH_PIPELINE_CREATE_INFO_AMDX:
safe_pNext = new safe_VkExecutionGraphPipelineCreateInfoAMDX(reinterpret_cast<const VkExecutionGraphPipelineCreateInfoAMDX *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NODE_CREATE_INFO_AMDX:
safe_pNext = new safe_VkPipelineShaderStageNodeCreateInfoAMDX(reinterpret_cast<const VkPipelineShaderStageNodeCreateInfoAMDX *>(pNext), copy_state, false);
break;
Expand Down Expand Up @@ -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<const VkPhysicalDeviceAccelerationStructurePropertiesKHR *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR:
safe_pNext = new safe_VkRayTracingPipelineCreateInfoKHR(reinterpret_cast<const VkRayTracingPipelineCreateInfoKHR *>(pNext), copy_state, false);
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR:
safe_pNext = new safe_VkPhysicalDeviceRayTracingPipelineFeaturesKHR(reinterpret_cast<const VkPhysicalDeviceRayTracingPipelineFeaturesKHR *>(pNext), copy_state, false);
break;
Expand Down Expand Up @@ -1913,6 +1925,12 @@ void FreePnextChain(const void *pNext) {
case VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO:
delete reinterpret_cast<safe_VkShaderModuleCreateInfo *>(header);
break;
case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
delete reinterpret_cast<safe_VkComputePipelineCreateInfo *>(header);
break;
case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
delete reinterpret_cast<safe_VkGraphicsPipelineCreateInfo *>(header);
break;
case VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO:
delete reinterpret_cast<safe_VkPipelineLayoutCreateInfo *>(header);
break;
Expand Down Expand Up @@ -2790,6 +2808,9 @@ void FreePnextChain(const void *pNext) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ENQUEUE_PROPERTIES_AMDX:
delete reinterpret_cast<safe_VkPhysicalDeviceShaderEnqueuePropertiesAMDX *>(header);
break;
case VK_STRUCTURE_TYPE_EXECUTION_GRAPH_PIPELINE_CREATE_INFO_AMDX:
delete reinterpret_cast<safe_VkExecutionGraphPipelineCreateInfoAMDX *>(header);
break;
case VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NODE_CREATE_INFO_AMDX:
delete reinterpret_cast<safe_VkPipelineShaderStageNodeCreateInfoAMDX *>(header);
break;
Expand Down Expand Up @@ -3702,6 +3723,9 @@ void FreePnextChain(const void *pNext) {
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR:
delete reinterpret_cast<safe_VkPhysicalDeviceAccelerationStructurePropertiesKHR *>(header);
break;
case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR:
delete reinterpret_cast<safe_VkRayTracingPipelineCreateInfoKHR *>(header);
break;
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR:
delete reinterpret_cast<safe_VkPhysicalDeviceRayTracingPipelineFeaturesKHR *>(header);
break;
Expand Down

0 comments on commit 0317424

Please sign in to comment.