From 0f9fb8e15ff1e40a4fc0b2f7a6dfbb4fc93d1437 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Thu, 15 Sep 2022 01:30:02 +0200 Subject: [PATCH] radv: Remove aabb bounds from instance nodes. I need space ... Furthermore, this only gets used during the build, and we can eat the cost of generating the AABB a second time there. Reviewed-by: Konstantin Seurer Part-of: --- src/amd/vulkan/bvh/build_helpers.h | 28 ++++++++++++++++++++-------- src/amd/vulkan/bvh/bvh.h | 2 +- src/amd/vulkan/bvh/leaf.comp | 18 +----------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/amd/vulkan/bvh/build_helpers.h b/src/amd/vulkan/bvh/build_helpers.h index 08fc3544047..11af62be672 100644 --- a/src/amd/vulkan/bvh/build_helpers.h +++ b/src/amd/vulkan/bvh/build_helpers.h @@ -257,6 +257,25 @@ pack_node_id(uint32_t offset, uint32_t type) #define NULL_NODE_ID 0xFFFFFFFF +AABB +calculate_instance_node_bounds(radv_bvh_instance_node instance) +{ + AABB aabb; + radv_accel_struct_header header = DEREF(REF(radv_accel_struct_header)(instance.base_ptr)); + + for (uint32_t comp = 0; comp < 3; ++comp) { + aabb.min[comp] = instance.wto_matrix[3 + 4 * comp]; + aabb.max[comp] = instance.wto_matrix[3 + 4 * comp]; + for (uint32_t col = 0; col < 3; ++col) { + aabb.min[comp] += min(instance.otw_matrix[col + comp * 3] * header.aabb[0][col], + instance.otw_matrix[col + comp * 3] * header.aabb[1][col]); + aabb.max[comp] += max(instance.otw_matrix[col + comp * 3] * header.aabb[0][col], + instance.otw_matrix[col + comp * 3] * header.aabb[1][col]); + } + } + return aabb; +} + AABB calculate_node_bounds(VOID_REF bvh, uint32_t id) { @@ -292,14 +311,7 @@ calculate_node_bounds(VOID_REF bvh, uint32_t id) } case radv_bvh_node_instance: { radv_bvh_instance_node instance = DEREF(REF(radv_bvh_instance_node)(node)); - - aabb.min.x = instance.aabb[0][0]; - aabb.min.y = instance.aabb[0][1]; - aabb.min.z = instance.aabb[0][2]; - - aabb.max.x = instance.aabb[1][0]; - aabb.max.y = instance.aabb[1][1]; - aabb.max.z = instance.aabb[1][2]; + aabb = calculate_instance_node_bounds(instance); break; } case radv_bvh_node_aabb: { diff --git a/src/amd/vulkan/bvh/bvh.h b/src/amd/vulkan/bvh/bvh.h index f7d2121345e..f907feb4fc5 100644 --- a/src/amd/vulkan/bvh/bvh.h +++ b/src/amd/vulkan/bvh/bvh.h @@ -100,7 +100,7 @@ struct radv_bvh_instance_node { * post-translation of the object->world matrix so this way we can share data between both * matrices. */ float wto_matrix[12]; - float aabb[2][3]; + uint32_t reserved[6]; uint32_t instance_id; /* Object to world matrix transposed from the initial transform. Translate part is store in the diff --git a/src/amd/vulkan/bvh/leaf.comp b/src/amd/vulkan/bvh/leaf.comp index a0e86f69cef..ecb08b6770b 100644 --- a/src/amd/vulkan/bvh/leaf.comp +++ b/src/amd/vulkan/bvh/leaf.comp @@ -213,28 +213,12 @@ build_instance(inout AABB bounds, VOID_REF src_ptr, VOID_REF dst_ptr, uint32_t g DEREF(REF(radv_accel_struct_header)(instance.accelerationStructureReference)); DEREF(node).base_ptr = instance.accelerationStructureReference; - for (uint32_t comp = 0; comp < 3; ++comp) { - bounds.min[comp] = transform[3][comp]; - bounds.max[comp] = transform[3][comp]; - for (uint32_t col = 0; col < 3; ++col) { - bounds.min[comp] += min(transform[col][comp] * instance_header.aabb[0][col], - transform[col][comp] * instance_header.aabb[1][col]); - bounds.max[comp] += max(transform[col][comp] * instance_header.aabb[0][col], - transform[col][comp] * instance_header.aabb[1][col]); - } - } + bounds = calculate_instance_node_bounds(DEREF(node)); DEREF(node).custom_instance_and_mask = instance.custom_instance_and_mask; DEREF(node).sbt_offset_and_flags = instance.sbt_offset_and_flags; DEREF(node).instance_id = global_id; - DEREF(node).aabb[0][0] = bounds.min.x; - DEREF(node).aabb[0][1] = bounds.min.y; - DEREF(node).aabb[0][2] = bounds.min.z; - DEREF(node).aabb[1][0] = bounds.max.x; - DEREF(node).aabb[1][1] = bounds.max.y; - DEREF(node).aabb[1][2] = bounds.max.z; - return true; }