From 703f29874bb9ee414e1ee12487cd38c4dd31488f Mon Sep 17 00:00:00 2001 From: Kevin Chuang Date: Mon, 10 Mar 2025 10:51:19 -0700 Subject: [PATCH] intel/bvh/debug: Adapt instance leaf dumping to support 64-bit RT Adding a boolean "enable_64b_rt" in anv_accel_struct_header for the interpret.py to properly decode anv_instance_leaf Signed-off-by: Kevin Chuang Reviewed-by: Lionel Landwerlin Reviewed-by: Sagar Ghuge Part-of: --- src/intel/vulkan/bvh/anv_bvh.h | 8 ++- src/intel/vulkan/bvh/header.comp | 5 ++ src/intel/vulkan/bvh/interpret.py | 61 +++++++++++++------ .../vulkan/genX_acceleration_structure.c | 6 ++ 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/intel/vulkan/bvh/anv_bvh.h b/src/intel/vulkan/bvh/anv_bvh.h index 38dde7d1baf..de629e8e572 100644 --- a/src/intel/vulkan/bvh/anv_bvh.h +++ b/src/intel/vulkan/bvh/anv_bvh.h @@ -74,7 +74,13 @@ struct anv_accel_struct_header { uint64_t self_ptr; - uint32_t padding[42]; + /* A boolean indicating if the bvh is built with 64b_rt data structures. + * This is for INTEL_DEBUG=bvh_* to make the decision how to decode the + * dump. + */ + uint32_t enable_64b_rt; + + uint32_t padding[41]; }; /* Mixed internal node with type per child */ diff --git a/src/intel/vulkan/bvh/header.comp b/src/intel/vulkan/bvh/header.comp index fee5d70ec47..baf0b66e029 100644 --- a/src/intel/vulkan/bvh/header.comp +++ b/src/intel/vulkan/bvh/header.comp @@ -47,4 +47,9 @@ main(void) DEREF(args.dst).copy_dispatch_size[0] = DIV_ROUND_UP(compacted_size, 8 * 128); DEREF(args.dst).copy_dispatch_size[1] = 1; DEREF(args.dst).copy_dispatch_size[2] = 1; +#if GFX_VERx10 >= 300 + DEREF(args.dst).enable_64b_rt = 1; +#else + DEREF(args.dst).enable_64b_rt = 0; +#endif } diff --git a/src/intel/vulkan/bvh/interpret.py b/src/intel/vulkan/bvh/interpret.py index 77a0909efeb..ee6cc493115 100644 --- a/src/intel/vulkan/bvh/interpret.py +++ b/src/intel/vulkan/bvh/interpret.py @@ -22,6 +22,7 @@ def get_header_properties(header): 'size': header.size, 'instance_count': header.instance_count, 'self_ptr': header.self_ptr, + 'enable_64b_rt': header.enable_64b_rt, 'padding': f"{len(header.padding)} uint32_t paddings", } @@ -118,20 +119,38 @@ def get_internal_node_properties(node): 'actual_coords': actual_coords } -def get_instance_leaf_properties(node): +def get_instance_leaf_properties(node, enable_64b_rt): + if enable_64b_rt: + part0 = { + 'instanceContribution': node.part0.DW0 & 0xFFFFFF, + 'geomMask': (node.part0.DW0 >> 24) & 0xFF, + 'insFlags': node.part0.DW1 & 0xFF, + 'ComparisonMode': (node.part0.DW1 >> 8) & 0x1, + 'ComparisonValue': (node.part0.DW1 >> 9) & 0x7F, + 'pad0': (node.part0.DW1 >> 16) & 0xFF, + 'subType': (node.part0.DW1 >> 24) & 0xF, + 'pad1': (node.part0.DW1 >> 28) & 0x1, + 'DisableOpacityCull': (node.part0.DW1 >> 29) & 0x1, + 'OpaqueGeometry': (node.part0.DW1 >> 30) & 0x1, + 'IgnoreRayMultiplier': (node.part0.DW1 >> 31) & 0x1, + 'startNodePtr': node.part0.QW_startNodePtr, + } + else: + part0 = { + 'shaderIndex': node.part0.DW0 & 0xFFFFFF, + 'geomMask': (node.part0.DW0 >> 24) & 0xFF, + 'instanceContribution': node.part0.DW1 & 0xFFFFFF, + 'pad0': (node.part0.DW1 >> 24) & 0x1F, + 'DisableOpacityCull': (node.part0.DW1 >> 29) & 0x1, + 'OpaqueGeometry': (node.part0.DW1 >> 30) & 0x1, + 'pad1': (node.part0.DW1 >> 31) & 0x1, + 'startNodePtr': node.part0.QW_startNodePtr & 0xFFFFFFFFFFFF, + 'instFlags': (node.part0.QW_startNodePtr >> 48) & 0xFF, + } + return { 'part0': { - 'shaderIndex': node.part0.shader_index_and_geom_mask & 0xFFFFFF, - 'geomMask': (node.part0.shader_index_and_geom_mask >> 24) & 0xFF, - 'instanceContribution': node.part0.instance_contribution_and_geom_flags & 0xFFFFFF, - 'pad0': (node.part0.instance_contribution_and_geom_flags >> 24) & 0x1F, - 'DisableOpacityCull': (node.part0.instance_contribution_and_geom_flags >> 29) & 0x1, - 'OpaqueGeometry': (node.part0.instance_contribution_and_geom_flags >> 30) & 0x1, - 'pad1': (node.part0.instance_contribution_and_geom_flags >> 31) & 0x1, - 'startNodePtr': node.part0.start_node_ptr_and_inst_flags & 0xFFFFFFFFFFFF, - 'instFlags': (node.part0.start_node_ptr_and_inst_flags >> 48) & 0xFF, - 'ComparisonMode': (node.part0.start_node_ptr_and_inst_flags >> 56) & 0x1, - 'ComparisonValue': (node.part0.start_node_ptr_and_inst_flags >> 57) & 0x7F, + **part0, 'world2obj_vx': [node.part0.world2obj_vx_x, node.part0.world2obj_vx_y, node.part0.world2obj_vx_z], 'world2obj_vy': [node.part0.world2obj_vy_x, node.part0.world2obj_vy_y, node.part0.world2obj_vy_z], 'world2obj_vz': [node.part0.world2obj_vz_x, node.part0.world2obj_vz_y, node.part0.world2obj_vz_z], @@ -180,7 +199,8 @@ class AnvAccelStructHeader(ctypes.Structure): ('size', ctypes.c_uint64), ('instance_count', ctypes.c_uint64), ('self_ptr', ctypes.c_uint64), - ('padding', ctypes.c_uint32 * 42), + ('enable_64b_rt', ctypes.c_uint32), + ('padding', ctypes.c_uint32 * 41), ) class ChildData(ctypes.Structure): @@ -230,9 +250,9 @@ class AnvProceduralLeafNode(ctypes.Structure): class InstanceLeafPart0(ctypes.Structure): _fields_ = ( - ('shader_index_and_geom_mask', ctypes.c_uint32), - ('instance_contribution_and_geom_flags', ctypes.c_uint32), - ('start_node_ptr_and_inst_flags', ctypes.c_uint64), + ('DW0', ctypes.c_uint32), + ('DW1', ctypes.c_uint32), + ('QW_startNodePtr', ctypes.c_uint64), ('world2obj_vx_x', ctypes.c_float), ('world2obj_vx_y', ctypes.c_float), ('world2obj_vx_z', ctypes.c_float), @@ -274,6 +294,7 @@ class AnvInstanceLeaf(ctypes.Structure): class BVHInterpreter: def __init__(self, data): + self.enable_64b_rt = False; self.data = data self.nodes = [] self.relationships = {} @@ -282,7 +303,10 @@ class BVHInterpreter: def interpret_structure(self, offset, structure): size = ctypes.sizeof(structure) if(offset + size > len(self.data)): - raise ValueError("Not enought data to interpret this structure.") + raise ValueError( + f"Not enough data to interpret structure: {structure.__name__}, " + f"required {size} bytes but only {len(self.data) - offset} bytes available." + ) buffer = self.data[offset:offset + size] return structure.from_buffer_copy(buffer) @@ -290,6 +314,7 @@ class BVHInterpreter: offset = 0 # Interpret the header header = self.interpret_structure(offset, AnvAccelStructHeader) + self.enable_64b_rt = header.enable_64b_rt offset += header.rootNodeOffset # Interpret the rootNode @@ -324,7 +349,7 @@ class BVHInterpreter: node_properties = get_internal_node_properties(node) elif structure == AnvInstanceLeaf: node_type_str = "AnvInstanceLeaf" - node_properties = get_instance_leaf_properties(node) + node_properties = get_instance_leaf_properties(node, self.enable_64b_rt) elif structure == AnvQuadLeafNode: node_type_str = "AnvQuadLeafNode" node_properties = get_quad_leaf_properties(node) diff --git a/src/intel/vulkan/genX_acceleration_structure.c b/src/intel/vulkan/genX_acceleration_structure.c index 0a68f01381f..fd2ad97057b 100644 --- a/src/intel/vulkan/genX_acceleration_structure.c +++ b/src/intel/vulkan/genX_acceleration_structure.c @@ -558,6 +558,12 @@ anv_init_header(VkCommandBuffer commandBuffer, header.size = header.compacted_size; +#if GFX_VERx10 >= 300 + header.enable_64b_rt = 1; +#else + header.enable_64b_rt = 0; +#endif + size_t header_size = sizeof(struct anv_accel_struct_header) - base; assert(base % sizeof(uint32_t) == 0); assert(header_size % sizeof(uint32_t) == 0);