Skip to content

Commit

Permalink
Fix handle mapping/unwrapping for acceleration structure building (#1590
Browse files Browse the repository at this point in the history
)

Change-Id: I526eb16c866785c60aab0121dd21df2131ba6893
  • Loading branch information
marius-pelegrin-arm authored Jul 11, 2024
1 parent 6b1fc0b commit f9b6598
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 27 deletions.
55 changes: 55 additions & 0 deletions framework/decode/custom_vulkan_struct_handle_mappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,60 @@ void MapStructHandles(Decoded_VkWriteDescriptorSet* wrapper, const VulkanObjectI
}
}

void MapStructHandles(Decoded_VkAccelerationStructureGeometryKHR* wrapper,
const VulkanObjectInfoTable& object_info_table)
{
if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
{
VkAccelerationStructureGeometryKHR* value = wrapper->decoded_value;

switch (value->geometryType)
{
case VK_GEOMETRY_TYPE_TRIANGLES_KHR:
MapStructHandles(wrapper->geometry->triangles, object_info_table);
break;
case VK_GEOMETRY_TYPE_AABBS_KHR:
// No handle there so the map func doesn't exist
break;
case VK_GEOMETRY_TYPE_INSTANCES_KHR:
// No handle there so the map func doesn't exist
break;
default:
GFXRECON_LOG_WARNING("Attempting to map unknown acceleration structure geometry type");
break;
}
}
}

void MapStructHandles(Decoded_VkAccelerationStructureBuildGeometryInfoKHR* wrapper,
const VulkanObjectInfoTable& object_info_table)
{
if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
{
VkAccelerationStructureBuildGeometryInfoKHR* value = wrapper->decoded_value;

value->srcAccelerationStructure = handle_mapping::MapHandle<AccelerationStructureKHRInfo>(
wrapper->srcAccelerationStructure,
object_info_table,
&VulkanObjectInfoTable::GetAccelerationStructureKHRInfo);

value->dstAccelerationStructure = handle_mapping::MapHandle<AccelerationStructureKHRInfo>(
wrapper->dstAccelerationStructure,
object_info_table,
&VulkanObjectInfoTable::GetAccelerationStructureKHRInfo);

MapStructArrayHandles<Decoded_VkAccelerationStructureGeometryKHR>(
wrapper->pGeometries->GetMetaStructPointer(), wrapper->pGeometries->GetLength(), object_info_table);

if (wrapper->ppGeometries->GetMetaStructPointer() != nullptr)
{
for (size_t i = 0; i < wrapper->ppGeometries->GetLength(); ++i)
{
MapStructHandles(wrapper->ppGeometries->GetMetaStructPointer()[i], object_info_table);
}
}
}
}

GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)
6 changes: 6 additions & 0 deletions framework/decode/custom_vulkan_struct_handle_mappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ void MapStructHandles(VkDescriptorType type,

void MapStructHandles(Decoded_VkWriteDescriptorSet* wrapper, const VulkanObjectInfoTable& object_info_table);

void MapStructHandles(Decoded_VkAccelerationStructureGeometryKHR* wrapper,
const VulkanObjectInfoTable& object_info_table);

void MapStructHandles(Decoded_VkAccelerationStructureBuildGeometryInfoKHR* wrapper,
const VulkanObjectInfoTable& object_info_table);

GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)

Expand Down
3 changes: 3 additions & 0 deletions framework/decode/vulkan_handle_mapping_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ uint64_t MapHandle(uint64_t object, VkObjectType object_type, const VulkanObject
case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV:
return format::ToHandleId(MapHandle<IndirectCommandsLayoutNVInfo>(
object, object_info_table, &VulkanObjectInfoTable::GetIndirectCommandsLayoutNVInfo));
case VK_OBJECT_TYPE_MICROMAP_EXT:
return format::ToHandleId(
MapHandle<MicromapEXTInfo>(object, object_info_table, &VulkanObjectInfoTable::GetMicromapEXTInfo));
case VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT:
return format::ToHandleId(MapHandle<PrivateDataSlotEXTInfo>(
object, object_info_table, &VulkanObjectInfoTable::GetPrivateDataSlotInfo));
Expand Down
42 changes: 42 additions & 0 deletions framework/encode/custom_vulkan_struct_handle_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,48 @@ void UnwrapStructHandles(VkWriteDescriptorSet* value, HandleUnwrapMemory* unwrap
}
}

void UnwrapStructHandles(VkAccelerationStructureGeometryKHR* value, HandleUnwrapMemory* unwrap_memory)
{
if (value != nullptr)
{
switch (value->geometryType)
{
case VK_GEOMETRY_TYPE_TRIANGLES_KHR:
UnwrapStructHandles(&value->geometry.triangles, unwrap_memory);
break;
case VK_GEOMETRY_TYPE_AABBS_KHR:
// No handle there so the unwrap func doesn't exist
break;
case VK_GEOMETRY_TYPE_INSTANCES_KHR:
// No handle there so the unwrap func doesn't exist
break;
default:
GFXRECON_LOG_WARNING("Attempting to unwrap unknown acceleration structure geometry type");
break;
}
}
}

void UnwrapStructHandles(VkAccelerationStructureBuildGeometryInfoKHR* value, HandleUnwrapMemory* unwrap_memory)
{
if (value != nullptr)
{
value->pGeometries = UnwrapStructArrayHandles(value->pGeometries, value->geometryCount, unwrap_memory);

if ((value->ppGeometries != nullptr) && (value->geometryCount > 0))
{
auto unwrapped_structs = MakeUnwrapStructs(value->ppGeometries, value->geometryCount, unwrap_memory);

for (size_t i = 0; i < value->geometryCount; ++i)
{
unwrapped_structs[i] = UnwrapStructArrayHandles(value->ppGeometries[i], 1, unwrap_memory);
}

value->ppGeometries = unwrapped_structs;
}
}
}

GFXRECON_END_NAMESPACE(vulkan_wrappers)
GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)
4 changes: 4 additions & 0 deletions framework/encode/custom_vulkan_struct_handle_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void UnwrapStructHandles(VkDescriptorType type, VkDescriptorImageInfo* value, Ha

void UnwrapStructHandles(VkWriteDescriptorSet* value, HandleUnwrapMemory* unwrap_memory);

void UnwrapStructHandles(VkAccelerationStructureGeometryKHR* value, HandleUnwrapMemory* unwrap_memory);

void UnwrapStructHandles(VkAccelerationStructureBuildGeometryInfoKHR* value, HandleUnwrapMemory* unwrap_memory);

GFXRECON_END_NAMESPACE(vulkan_wrappers)
GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/vulkan_handle_wrapper_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ uint64_t GetWrappedId(uint64_t object, VkObjectType object_type)
case VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV:
return GetWrappedId<IndirectCommandsLayoutNVWrapper>(
format::FromHandleId<VkIndirectCommandsLayoutNV>(object));
case VK_OBJECT_TYPE_MICROMAP_EXT:
return GetWrappedId<MicromapEXTWrapper>(format::FromHandleId<VkMicromapEXT>(object));
case VK_OBJECT_TYPE_PRIVATE_DATA_SLOT_EXT:
return GetWrappedId<PrivateDataSlotEXTWrapper>(format::FromHandleId<VkPrivateDataSlotEXT>(object));
case VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def generate_feature(self):
(struct in self.structs_with_handles)
or (struct in self.GENERIC_HANDLE_STRUCTS)
or (struct in self.structs_with_map_data)
):
) and (struct not in self.STRUCT_MAPPERS_BLACKLIST):
handle_members = list()
generic_handle_members = dict()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def generate_feature(self):
(struct in self.structs_with_handles)
or (struct in self.GENERIC_HANDLE_STRUCTS)
or (struct in self.structs_with_map_data)
):
) and (struct not in self.STRUCT_MAPPERS_BLACKLIST):
body = '\n'
body += 'void MapStruct{}(Decoded_{}* wrapper, const {}ObjectInfoTable& object_info_table{});'.format(
map_type, struct, platform_type, map_table
Expand Down
12 changes: 0 additions & 12 deletions framework/generated/generated_vulkan_struct_handle_mappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,18 +1823,6 @@ void MapStructHandles(Decoded_VkAccelerationStructureGeometryTrianglesDataKHR* w
}
}

void MapStructHandles(Decoded_VkAccelerationStructureBuildGeometryInfoKHR* wrapper, const VulkanObjectInfoTable& object_info_table)
{
if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
{
VkAccelerationStructureBuildGeometryInfoKHR* value = wrapper->decoded_value;

value->srcAccelerationStructure = handle_mapping::MapHandle<AccelerationStructureKHRInfo>(wrapper->srcAccelerationStructure, object_info_table, &VulkanObjectInfoTable::GetAccelerationStructureKHRInfo);

value->dstAccelerationStructure = handle_mapping::MapHandle<AccelerationStructureKHRInfo>(wrapper->dstAccelerationStructure, object_info_table, &VulkanObjectInfoTable::GetAccelerationStructureKHRInfo);
}
}

void MapStructHandles(Decoded_VkAccelerationStructureCreateInfoKHR* wrapper, const VulkanObjectInfoTable& object_info_table)
{
if ((wrapper != nullptr) && (wrapper->decoded_value != nullptr))
Expand Down
2 changes: 0 additions & 2 deletions framework/generated/generated_vulkan_struct_handle_mappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ void MapStructHandles(Decoded_VkLatencySleepInfoNV* wrapper, const VulkanObjectI

void MapStructHandles(Decoded_VkAccelerationStructureGeometryTrianglesDataKHR* wrapper, const VulkanObjectInfoTable& object_info_table);

void MapStructHandles(Decoded_VkAccelerationStructureBuildGeometryInfoKHR* wrapper, const VulkanObjectInfoTable& object_info_table);

void MapStructHandles(Decoded_VkAccelerationStructureCreateInfoKHR* wrapper, const VulkanObjectInfoTable& object_info_table);

void MapStructHandles(Decoded_VkWriteDescriptorSetAccelerationStructureKHR* wrapper, const VulkanObjectInfoTable& object_info_table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,6 @@ void UnwrapStructHandles(VkAccelerationStructureGeometryTrianglesDataKHR* value,
}
}

void UnwrapStructHandles(VkAccelerationStructureBuildGeometryInfoKHR* value, HandleUnwrapMemory* unwrap_memory)
{
if (value != nullptr)
{
}
}

void UnwrapStructHandles(VkAccelerationStructureCreateInfoKHR* value, HandleUnwrapMemory* unwrap_memory)
{
if (value != nullptr)
Expand Down
2 changes: 0 additions & 2 deletions framework/generated/generated_vulkan_struct_handle_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ void UnwrapStructHandles(VkLatencySleepInfoNV* value, HandleUnwrapMemory* unwrap

void UnwrapStructHandles(VkAccelerationStructureGeometryTrianglesDataKHR* value, HandleUnwrapMemory* unwrap_memory);

void UnwrapStructHandles(VkAccelerationStructureBuildGeometryInfoKHR* value, HandleUnwrapMemory* unwrap_memory);

void UnwrapStructHandles(VkAccelerationStructureCreateInfoKHR* value, HandleUnwrapMemory* unwrap_memory);

void UnwrapStructHandles(VkWriteDescriptorSetAccelerationStructureKHR* value, HandleUnwrapMemory* unwrap_memory);
Expand Down
3 changes: 3 additions & 0 deletions framework/generated/vulkan_generators/base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ def __init__(
# These structures should not be processed by the code generator. They require special implementations.
self.STRUCT_BLACKLIST = []

# These structures should be ignored for handle mapping/unwrapping. They require special implementations.
self.STRUCT_MAPPERS_BLACKLIST = ['VkAccelerationStructureBuildGeometryInfoKHR']

# Platform specific basic types that have been defined extarnally to the Vulkan header.
self.PLATFORM_TYPES = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def generate_feature(self):
if (
(struct in self.structs_with_handles)
or (struct in self.GENERIC_HANDLE_STRUCTS)
):
) and (struct not in self.STRUCT_MAPPERS_BLACKLIST):
handle_members = dict()
generic_handle_members = dict()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def generate_feature(self):
if (
(struct in self.structs_with_handles)
or (struct in self.GENERIC_HANDLE_STRUCTS)
):
) and (struct not in self.STRUCT_MAPPERS_BLACKLIST):
body = '\n'
body += 'void UnwrapStructHandles({}* value, HandleUnwrapMemory* unwrap_memory);'.format(
struct
Expand Down

0 comments on commit f9b6598

Please sign in to comment.