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

Author: Lionel Landwerlin <[email protected]>
Date:   Thu Oct  5 17:09:54 2023 +0300

anv: reduce working temporary memory for BVH builds

Part of the memory allocated (private) is a temporary working buffer
for the GRL kernels. Once the build operation is done, the buffer
becomes unused.

Rather than allocate a new buffer each time, reuse the current last
allocated one if its size fits the next build operation.

Signed-off-by: Lionel Landwerlin <[email protected]>
Reviewed-by: Tapani Pälli <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25570>

---

 src/intel/vulkan/anv_private.h                 |  3 +++
 src/intel/vulkan/genX_acceleration_structure.c | 25 +++++++++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index d5292d2bddc..319f04373ad 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -3367,6 +3367,9 @@ struct anv_cmd_ray_tracing_state {
       struct anv_bo *bo;
       struct brw_rt_scratch_layout layout;
    } scratch;
+
+   struct anv_address build_priv_mem_addr;
+   size_t             build_priv_mem_size;
 };
 
 /** State required while building cmd buffer */
diff --git a/src/intel/vulkan/genX_acceleration_structure.c 
b/src/intel/vulkan/genX_acceleration_structure.c
index ab9bae65953..f43221846b1 100644
--- a/src/intel/vulkan/genX_acceleration_structure.c
+++ b/src/intel/vulkan/genX_acceleration_structure.c
@@ -742,13 +742,26 @@ cmd_build_acceleration_structures(
    private_mem_binnedsah_offset = private_mem_total;
    private_mem_total += align_private_size(private_mem_binnedsah_size);
 
-   /* Allocate required memory */
-   struct anv_cmd_alloc private_mem_alloc =
-      anv_cmd_buffer_alloc_space(cmd_buffer, private_mem_total, 64);
-   if (private_mem_total > 0 && anv_cmd_alloc_is_empty(private_mem_alloc)) {
-      anv_batch_set_error(&cmd_buffer->batch, VK_ERROR_OUT_OF_DEVICE_MEMORY);
-      goto error;
+   /* Allocate required memory, unless we already have a suiteable buffer */
+   struct anv_cmd_alloc private_mem_alloc;
+   if (private_mem_total > cmd_buffer->state.rt.build_priv_mem_size) {
+      private_mem_alloc =
+         anv_cmd_buffer_alloc_space(cmd_buffer, private_mem_total, 64);
+      if (anv_cmd_alloc_is_empty(private_mem_alloc)) {
+         anv_batch_set_error(&cmd_buffer->batch, 
VK_ERROR_OUT_OF_DEVICE_MEMORY);
+         goto error;
+      }
+
+      cmd_buffer->state.rt.build_priv_mem_addr = private_mem_alloc.address;
+      cmd_buffer->state.rt.build_priv_mem_size = private_mem_alloc.size;
+   } else {
+      private_mem_alloc = (struct anv_cmd_alloc) {
+         .address = cmd_buffer->state.rt.build_priv_mem_addr,
+         .map     = anv_address_map(cmd_buffer->state.rt.build_priv_mem_addr),
+         .size    = cmd_buffer->state.rt.build_priv_mem_size,
+      };
    }
+
    struct anv_cmd_alloc transient_mem_alloc =
       anv_cmd_buffer_alloc_space(cmd_buffer, transient_total, 64);
    if (transient_total > 0 && anv_cmd_alloc_is_empty(transient_mem_alloc)) {

Reply via email to