upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorzneel <14263028+zneel@users.noreply.github.com>2026-11-22 20:54:14 +0100
committerzneel <14263028+zneel@users.noreply.github.com>2026-11-22 23:30:14 +0100
commit649a26064eb56ab01f5b93ae62ac475f5542e018 (patch)
tree627220ed17b10a823461cb607e1d3204bc107b04 /runtime/src
parentc42cb873ddd985c5b91e491748266567ec9432a4 (diff)
XDXR builder: second review pass (refuse updates without ALLOW_UPDATE, rotation coverage, docs)
- xdxr_check refuses PERFORM_UPDATE without ALLOW_UPDATE (D3D12 requires it): a structure built without it may be paired, and a refit would leave its TRI1 children reading wrong vertices. - blas_paired_rotations: a grid whose triangles start at varied vertices, so pairs use all nine (TRI0, TRI1) rotations; check-build asserts it ("all_rotations"). Before, the sibling rotation kd = 1 never occurred. - BOX32 cases now say "box16": false, so a stray BOX16 is caught too. - docs/bvh.md cites the one traced BOX16-related datum (docs/xdxr.md: a bottom-level path needing MINIMIZE_MEMORY and a stream value above 10), notes that world-space BLASes only get looser boxes; README says pairing saves no memory yet and the BOX16 switch is assumed; comments rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_backend.h20
-rw-r--r--runtime/src/xdxr_build.comp4
2 files changed, 15 insertions, 9 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h
index e19fcbf4f..cea04a7bd 100644
--- a/runtime/src/vulkan_backend.h
+++ b/runtime/src/vulkan_backend.h
@@ -879,8 +879,11 @@ public:
879 if (xdxr_->loaded()) { 879 if (xdxr_->loaded()) {
880 replay_.xdxr_check = [](const BuildAccelerationStructure& b) { 880 replay_.xdxr_check = [](const BuildAccelerationStructure& b) {
881 XdxrLayout layout; 881 XdxrLayout layout;
882 // An update needs ALLOW_UPDATE (D3D12 requires it on the build and the update): a structure
883 // built without it may have paired leaves, which a refit would rewrite as wrong geometry.
882 return xdxr_inputs(b, nullptr, 0) && layout.compute(xdxr_elements(b), b.is_tlas, xdxr_box16(b)) && 884 return xdxr_inputs(b, nullptr, 0) && layout.compute(xdxr_elements(b), b.is_tlas, xdxr_box16(b)) &&
883 b.dst_va && b.scratch_va && (!b.is_tlas || !b.instance_count || b.instances_va); 885 b.dst_va && b.scratch_va && (!b.is_tlas || !b.instance_count || b.instances_va) &&
886 (!b.update || (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) != 0);
884 }; 887 };
885 replay_.xdxr_record = [this](VkCommandBuffer cb, const BuildAccelerationStructure& b) { 888 replay_.xdxr_record = [this](VkCommandBuffer cb, const BuildAccelerationStructure& b) {
886 // Every address is a console VA in the GPU address arena: the device address is heap_base + VA, 889 // Every address is a console VA in the GPU address arena: the device address is heap_base + VA,
@@ -1111,17 +1114,18 @@ public:
1111 bool xdxr_acceleration_structures() const { return xdxr_ != nullptr; } 1114 bool xdxr_acceleration_structures() const { return xdxr_ != nullptr; }
1112 1115
1113 // Whether a build's inner nodes are BOX16 (64 bytes, half boxes rounded outward) instead of BOX32: bottom-level 1116 // Whether a build's inner nodes are BOX16 (64 bytes, half boxes rounded outward) instead of BOX32: bottom-level
1114 // builds with MINIMIZE_MEMORY (VK LOW_MEMORY). The flags of an update must match its build's (D3D12), so prebuild 1117 // builds with MINIMIZE_MEMORY (VK LOW_MEMORY). A top-level build keeps BOX32: it is in world space, where half
1115 // info, the build and its refits agree. An update that breaks that rule (MINIMIZE_MEMORY on one and not the 1118 // precision would make boxes metres too large a few kilometres from the origin. The flags of an update must match
1116 // other) is refitted with the wrong layout, out of the structure's bounds: D3D12 leaves it undefined too. A top-level build keeps BOX32: it is in world space, where half precision 1119 // its build's (D3D12), so prebuild info, the build and its refits agree. WARNING: an update that breaks that rule
1117 // would make boxes metres too large a few kilometres from the origin. 1120 // (MINIMIZE_MEMORY on one and not the other) is refitted with the wrong layout and writes past the structure; it
1121 // cannot be detected when the command is recorded.
1118 static bool xdxr_box16(const BuildAccelerationStructure& b) { 1122 static bool xdxr_box16(const BuildAccelerationStructure& b) {
1119 return !b.is_tlas && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR) != 0; 1123 return !b.is_tlas && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR) != 0;
1120 } 1124 }
1121 // Whether a bottom-level build pairs sibling triangles into TRI0/TRI1 leaves: not when the structure may be 1125 // Whether a bottom-level build pairs sibling triangles into TRI0/TRI1 leaves: not when the structure may be
1122 // updated (ALLOW_UPDATE), since a refit rewrites the leaves one triangle each (D3D12 allows PERFORM_UPDATE only on 1126 // updated (ALLOW_UPDATE), since a refit rewrites the leaves one triangle each and would leave every TRI1 child
1123 // a structure built with ALLOW_UPDATE; an update of a paired one would lose every TRI1 triangle). Pairing changes neither the layout 1127 // reading wrong vertices. xdxr_check refuses an update without ALLOW_UPDATE for that reason. Pairing changes
1124 // nor the tree, so prebuild info does not depend on it. 1128 // neither the layout nor the tree, so prebuild info does not depend on it.
1125 static bool xdxr_pair(const BuildAccelerationStructure& b) { 1129 static bool xdxr_pair(const BuildAccelerationStructure& b) {
1126 return !b.is_tlas && !b.update && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) == 0; 1130 return !b.is_tlas && !b.update && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) == 0;
1127 } 1131 }
diff --git a/runtime/src/xdxr_build.comp b/runtime/src/xdxr_build.comp
index 2e017d602..70332c37a 100644
--- a/runtime/src/xdxr_build.comp
+++ b/runtime/src/xdxr_build.comp
@@ -462,7 +462,8 @@ void pair_children(uint n, out uint kids[4]) {
462 for (uint k = 0u; k < 3u; ++k) v[c][k] = leaf_vertex(e[c], k); 462 for (uint k = 0u; k < 3u; ++k) v[c][k] = leaf_vertex(e[c], k);
463 vec3 lo, hi; 463 vec3 lo, hi;
464 load_box(e[c], lo, hi); 464 load_box(e[c], lo, hi);
465 live[c] = !box_empty(lo, hi); // a triangle with a NaN vertex is inactive: never paired 465 live[c] = !box_empty(lo, hi); // inactive (NaN vertex): never paired. Conservative only: its box is empty,
466 // so a pair with it would never be traversed anyway
466 } 467 }
467 for (uint c = 0u; c < count; ++c) { 468 for (uint c = 0u; c < count; ++c) {
468 if (used[c] || !live[c]) continue; 469 if (used[c] || !live[c]) continue;
@@ -515,6 +516,7 @@ void build_node(uint n) {
515 if (child != INVALID) { 516 if (child != INVALID) {
516 uint at = ptr_unit(child) * 64u; 517 uint at = ptr_unit(child) * 64u;
517 if (ptr_is_node(child)) { 518 if (ptr_is_node(child)) {
519 // the child's own type gives its node size (it is what the structure holds, whatever the flags)
518 load_box(pc.elements + (at - pc.nodes_off) / ((child & 7u) == BOX16 ? 64u : 128u), lo, hi); 520 load_box(pc.elements + (at - pc.nodes_off) / ((child & 7u) == BOX16 ? 64u : 128u), lo, hi);
519 } else { 521 } else {
520 uint e = (at - pc.elements_off) / element_size(); 522 uint e = (at - pc.elements_off) / element_size();