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

Author: Konstantin Seurer <[email protected]>
Date:   Fri Jan 20 21:51:32 2023 +0100

radv/bvh: Add a shader for filling the header

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20818>

---

 src/amd/vulkan/bvh/build_interface.h |  7 ++++
 src/amd/vulkan/bvh/header.comp       | 68 ++++++++++++++++++++++++++++++++++++
 src/amd/vulkan/bvh/meson.build       |  5 +++
 3 files changed, 80 insertions(+)

diff --git a/src/amd/vulkan/bvh/build_interface.h 
b/src/amd/vulkan/bvh/build_interface.h
index fc05f73ac61..3319e16d727 100644
--- a/src/amd/vulkan/bvh/build_interface.h
+++ b/src/amd/vulkan/bvh/build_interface.h
@@ -120,4 +120,11 @@ struct ploc_args {
    uint32_t internal_node_offset;
 };
 
+struct header_args {
+   REF(radv_ir_header) src;
+   REF(radv_accel_struct_header) dst;
+   uint32_t bvh_offset;
+   uint32_t instance_count;
+};
+
 #endif
diff --git a/src/amd/vulkan/bvh/header.comp b/src/amd/vulkan/bvh/header.comp
new file mode 100644
index 00000000000..169928b4939
--- /dev/null
+++ b/src/amd/vulkan/bvh/header.comp
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2023 Valve Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#version 460
+
+#extension GL_GOOGLE_include_directive : require
+
+#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require
+#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
+#extension GL_EXT_shader_explicit_arithmetic_types_int32 : require
+#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
+#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
+#extension GL_EXT_scalar_block_layout : require
+#extension GL_EXT_buffer_reference : require
+#extension GL_EXT_buffer_reference2 : require
+
+layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
+
+#include "build_interface.h"
+
+layout(push_constant) uniform CONSTS
+{
+   header_args args;
+};
+
+void
+main(void)
+{
+   uint32_t compacted_size = args.bvh_offset + DEREF(args.src).dst_node_offset;
+
+   uint32_t serialization_size =
+      compacted_size +
+      align(SIZEOF(radv_accel_struct_serialization_header) + SIZEOF(uint64_t) 
* args.instance_count,
+            128);
+
+   uint32_t size = serialization_size - 
SIZEOF(radv_accel_struct_serialization_header) -
+                   SIZEOF(uint64_t) * args.instance_count;
+
+   DEREF(args.dst).compacted_size = compacted_size;
+
+   DEREF(args.dst).copy_dispatch_size[0] = DIV_ROUND_UP(compacted_size, 16 * 
64);
+   DEREF(args.dst).copy_dispatch_size[1] = 1;
+   DEREF(args.dst).copy_dispatch_size[2] = 1;
+
+   DEREF(args.dst).serialization_size = serialization_size;
+
+   DEREF(args.dst).size = size;
+}
diff --git a/src/amd/vulkan/bvh/meson.build b/src/amd/vulkan/bvh/meson.build
index ba5a757a1bc..244bce3195e 100644
--- a/src/amd/vulkan/bvh/meson.build
+++ b/src/amd/vulkan/bvh/meson.build
@@ -35,6 +35,11 @@ bvh_shaders = [
     'encode_compact',
     ['COMPACT=1'],
   ],
+  [
+    'header.comp',
+    'header',
+    [],
+  ],
   [
     'lbvh_generate_ir.comp',
     'lbvh_generate_ir',

Reply via email to