From 87ff7b061f170a4f757ce16c1ab18b75a90e1583 Mon Sep 17 00:00:00 2001 From: Kevin Chuang Date: Tue, 25 Feb 2025 13:35:17 -0800 Subject: [PATCH] anv/bvh: Fix copy shader handling sparse buffer Fixes: 692b5fa9f22d ("anv: Add shader to copy acceleration structures") This commit fixes the future test "sparse_binding_structures" for "header_bottom_address" for ray tracing pipeline. Even on 48-bit ray tracing (Xe1/2), the software-defined part instance_leaf_part1.bvh_ptr has to be in canonical form for copy.comp to deference a bvh, which means we have to preserve the upper 16bits. This is especially relevant in cases where the acceleration structure buffer is located high, such as sparse buffer. Signed-off-by: Kevin Chuang Reviewed-by: Sagar Ghuge Part-of: --- src/intel/vulkan/bvh/anv_bvh.h | 7 ++++++- src/intel/vulkan/bvh/copy.comp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/bvh/anv_bvh.h b/src/intel/vulkan/bvh/anv_bvh.h index 2ba5c371ba5..c4efeac5b6e 100644 --- a/src/intel/vulkan/bvh/anv_bvh.h +++ b/src/intel/vulkan/bvh/anv_bvh.h @@ -252,7 +252,12 @@ struct instance_leaf_part0 { }; struct instance_leaf_part1 { - /* 48-bits pointer to BVH where start node belongs too */ + /* 48-bits pointer to BVH where start node belongs to. + * Note that this software-defined bvh_ptr has to be in canonical form for + * copy.comp to dereference, which means we have to preserve the upper 16 + * bits. For example, sparse buffer's heaps are located high, so its 63:48 + * are set to 1. + */ uint64_t bvh_ptr; /* The instanceCustomIndex in VkAccelerationStructureInstanceKHR */ diff --git a/src/intel/vulkan/bvh/copy.comp b/src/intel/vulkan/bvh/copy.comp index 070eee3307e..65856b3e85d 100644 --- a/src/intel/vulkan/bvh/copy.comp +++ b/src/intel/vulkan/bvh/copy.comp @@ -126,14 +126,14 @@ main(void) /* Indirectly access the anv_instance_leaf, and store the blas_ptrs after ser_header */ uint64_t instance_leaf_addr = DEREF(REF(uint64_t)(copy_src_addr + offset)); REF(anv_instance_leaf) instance_leaf = REF(anv_instance_leaf)(instance_leaf_addr); - uint64_t blas_ptr = DEREF(instance_leaf).part1.bvh_ptr & 0xfffffffffffful; + uint64_t blas_ptr = DEREF(instance_leaf).part1.bvh_ptr; DEREF(INDEX(uint64_t, instance_base, idx)) = blas_ptr; } else { /* ANV_COPY_MODE_DESERIALIZE */ /* Indirectly access the anv_instance_leaf, and replace the bvh_ptr with the ones after ser_header */ uint64_t instance_leaf_addr = DEREF(REF(uint64_t)(copy_dst_addr + offset)); REF(anv_instance_leaf) instance_leaf = REF(anv_instance_leaf)(instance_leaf_addr); uint64_t blas_ptr = DEREF(INDEX(uint64_t, instance_base, idx)); - DEREF(instance_leaf).part1.bvh_ptr = (blas_ptr & 0xfffffffffffful); + DEREF(instance_leaf).part1.bvh_ptr = blas_ptr; /* set the startNodePtr to blas_ptr + ANV_HEADER_SIZE */ uint64_t mask = 0x0000fffffffffffful;