Mesa (main): radv: Fix the accel struct size calculation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 7 13:00:27 UTC 2022


Module: Mesa
Branch: main
Commit: b24216c52d3e06084aee9b217e336273950f1f61
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b24216c52d3e06084aee9b217e336273950f1f61

Author: Konstantin Seurer <konstantin.seurer at gmail.com>
Date:   Sun Jun  5 11:12:10 2022 +0200

radv: Fix the accel struct size calculation

Signed-off-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16874>

---

 src/amd/vulkan/radv_acceleration_structure.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/amd/vulkan/radv_acceleration_structure.c b/src/amd/vulkan/radv_acceleration_structure.c
index c8ed3eec22c..4394ead136b 100644
--- a/src/amd/vulkan/radv_acceleration_structure.c
+++ b/src/amd/vulkan/radv_acceleration_structure.c
@@ -100,16 +100,15 @@ radv_GetAccelerationStructureBuildSizesKHR(
    }
 
    uint64_t children = boxes + instances + triangles;
-   uint64_t internal_nodes = 0;
+   /* Initialize to 1 to have enought space for the root node. */
+   uint64_t internal_nodes = 1;
    while (children > 1) {
       children = DIV_ROUND_UP(children, 4);
       internal_nodes += children;
    }
 
-   /* The stray 128 is to ensure we have space for a header
-    * which we'd want to use for some metadata (like the
-    * total AABB of the BVH) */
-   uint64_t size = boxes * 128 + instances * 128 + triangles * 64 + internal_nodes * 128 + 192;
+   uint64_t size = boxes * 128 + instances * 128 + triangles * 64 + internal_nodes * 128 +
+                   ALIGN(sizeof(struct radv_accel_struct_header), 64);
 
    pSizeInfo->accelerationStructureSize = size;
 



More information about the mesa-commit mailing list