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

Author: Konstantin Seurer <[email protected]>
Date:   Thu Jan 19 21:39:59 2023 +0100

radv/bvh: Replace is_final_tree with bvh_offset

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

---

 src/amd/vulkan/bvh/bvh.h                 |  8 ++++----
 src/amd/vulkan/bvh/encode.comp           | 18 +++++++++---------
 src/amd/vulkan/bvh/lbvh_generate_ir.comp |  2 +-
 src/amd/vulkan/bvh/ploc_internal.comp    |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/amd/vulkan/bvh/bvh.h b/src/amd/vulkan/bvh/bvh.h
index eb7f4d7da8d..0778db2af9f 100644
--- a/src/amd/vulkan/bvh/bvh.h
+++ b/src/amd/vulkan/bvh/bvh.h
@@ -109,13 +109,13 @@ struct radv_ir_node {
    float cost;
 };
 
-#define FINAL_TREE_PRESENT 0
-#define FINAL_TREE_NOT_PRESENT 1
-#define FINAL_TREE_UNKNOWN 2
+#define RADV_UNKNOWN_BVH_OFFSET 0xFFFFFFFF
+#define RADV_NULL_BVH_OFFSET    0xFFFFFFFE
+
 struct radv_ir_box_node {
    radv_ir_node base;
    uint32_t children[2];
-   uint32_t in_final_tree;
+   uint32_t bvh_offset;
 };
 
 struct radv_ir_aabb_node {
diff --git a/src/amd/vulkan/bvh/encode.comp b/src/amd/vulkan/bvh/encode.comp
index ad559c888b8..714b51f1cf8 100644
--- a/src/amd/vulkan/bvh/encode.comp
+++ b/src/amd/vulkan/bvh/encode.comp
@@ -161,12 +161,12 @@ main()
    uint32_t node_id = pack_node_id(dst_node_offset, radv_bvh_node_box32);
 
    for (;;) {
-      /* Make changes to the current node's in_final_tree value visible. */
+      /* Make changes to the current node's BVH offset value visible. */
       memoryBarrier(gl_ScopeDevice, gl_StorageSemanticsBuffer,
                     gl_SemanticsAcquireRelease | gl_SemanticsMakeAvailable | 
gl_SemanticsMakeVisible);
 
-      uint32_t in_final_tree = node_id == RADV_BVH_ROOT_NODE ? 
FINAL_TREE_PRESENT : DEREF(src_node).in_final_tree;
-      if (in_final_tree == FINAL_TREE_UNKNOWN)
+      uint32_t bvh_offset = node_id == RADV_BVH_ROOT_NODE ? 
id_to_offset(RADV_BVH_ROOT_NODE) : DEREF(src_node).bvh_offset;
+      if (bvh_offset == RADV_UNKNOWN_BVH_OFFSET)
          continue;
 
       uint32_t found_child_count = 0;
@@ -221,8 +221,8 @@ main()
                children[collapsed_child_index] = children[found_child_count];
             }
 
-            if (in_final_tree == FINAL_TREE_PRESENT)
-               DEREF(child_node).in_final_tree = FINAL_TREE_NOT_PRESENT;
+            if (bvh_offset != RADV_NULL_BVH_OFFSET)
+               DEREF(child_node).bvh_offset = RADV_NULL_BVH_OFFSET;
          } else
             break;
       }
@@ -237,9 +237,9 @@ main()
             uint32_t child_index = offset_in_internal_nodes / 
SIZEOF(radv_ir_box_node);
             dst_offset = dst_internal_offset + child_index * 
SIZEOF(radv_bvh_box32_node);
 
-            if (in_final_tree == FINAL_TREE_PRESENT) {
+            if (bvh_offset != RADV_NULL_BVH_OFFSET) {
                REF(radv_ir_box_node) child_node = 
REF(radv_ir_box_node)OFFSET(args.intermediate_bvh, offset);
-               DEREF(child_node).in_final_tree = FINAL_TREE_PRESENT;
+               DEREF(child_node).bvh_offset = dst_offset;
             }
          } else {
             uint32_t child_index = offset / intermediate_leaf_node_size;
@@ -255,7 +255,7 @@ main()
 
          uint32_t child_id = pack_node_id(dst_offset, 
ir_type_to_bvh_type(type));
          children[i] = child_id;
-         if (in_final_tree == FINAL_TREE_PRESENT)
+         if (bvh_offset != RADV_NULL_BVH_OFFSET)
             set_parent(child_id, node_id);
       }
 
@@ -266,7 +266,7 @@ main()
             }
       }
 
-      /* Make changes to the children's in_final_tree value available to the 
other invocations. */
+      /* Make changes to the children's BVH offset value available to the 
other invocations. */
       memoryBarrier(gl_ScopeDevice, gl_StorageSemanticsBuffer,
                     gl_SemanticsAcquireRelease | gl_SemanticsMakeAvailable | 
gl_SemanticsMakeVisible);
 
diff --git a/src/amd/vulkan/bvh/lbvh_generate_ir.comp 
b/src/amd/vulkan/bvh/lbvh_generate_ir.comp
index e800cad2753..520a242a0a3 100644
--- a/src/amd/vulkan/bvh/lbvh_generate_ir.comp
+++ b/src/amd/vulkan/bvh/lbvh_generate_ir.comp
@@ -117,7 +117,7 @@ main(void)
       radv_ir_box_node node_value;
 
       node_value.base.aabb = bounds;
-      node_value.in_final_tree = FINAL_TREE_UNKNOWN;
+      node_value.bvh_offset = RADV_UNKNOWN_BVH_OFFSET;
       node_value.children = children;
 
       DEREF(node) = node_value;
diff --git a/src/amd/vulkan/bvh/ploc_internal.comp 
b/src/amd/vulkan/bvh/ploc_internal.comp
index 41ede73953c..d51706ed06d 100644
--- a/src/amd/vulkan/bvh/ploc_internal.comp
+++ b/src/amd/vulkan/bvh/ploc_internal.comp
@@ -137,7 +137,7 @@ push_node(uint32_t children[2])
 #if EXTENDED_SAH
    DEREF(dst_node).base.cost = cost * 0.5 + BVH_LEVEL_COST;
 #endif
-   DEREF(dst_node).in_final_tree = FINAL_TREE_UNKNOWN;
+   DEREF(dst_node).bvh_offset = RADV_UNKNOWN_BVH_OFFSET;
    return dst_id;
 }
 

Reply via email to