diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:07:14 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:07:14 -0500 |
| commit | 6df9cc0d181b6b3e2e81d6f6032940c796a73ce5 (patch) | |
| tree | 992e90f3e80ab7f2d695c5b5e455154b4473a688 /runtime/src/vulkan_backend.h | |
| parent | db9af915974318a6d9496ef6b52ab048a4ea5faa (diff) | |
| parent | c2f3eaa308a2c67a48987e772f7feea3a16b519c (diff) | |
Merge pull request #3315 from zneel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
# README.md
Diffstat (limited to 'runtime/src/vulkan_backend.h')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 99add4faf..c705bfda2 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -893,15 +893,18 @@ public: | |||
| 893 | if (xdxr_->loaded()) { | 893 | if (xdxr_->loaded()) { |
| 894 | replay_.xdxr_check = [](const BuildAccelerationStructure& b) { | 894 | replay_.xdxr_check = [](const BuildAccelerationStructure& b) { |
| 895 | XdxrLayout layout; | 895 | XdxrLayout layout; |
| 896 | return xdxr_inputs(b, nullptr, 0) && layout.compute(xdxr_elements(b), b.is_tlas) && b.dst_va && | 896 | // An update needs ALLOW_UPDATE (D3D12 requires it on the build and the update): a structure |
| 897 | b.scratch_va && (!b.is_tlas || !b.instance_count || b.instances_va); | 897 | // built without it may have paired leaves, which a refit would rewrite as wrong geometry. |
| 898 | return xdxr_inputs(b, nullptr, 0) && layout.compute(xdxr_elements(b), b.is_tlas, xdxr_box16(b)) && | ||
| 899 | b.dst_va && b.scratch_va && (!b.is_tlas || !b.instance_count || b.instances_va) && | ||
| 900 | (!b.update || (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) != 0); | ||
| 898 | }; | 901 | }; |
| 899 | replay_.xdxr_record = [this](VkCommandBuffer cb, const BuildAccelerationStructure& b) { | 902 | replay_.xdxr_record = [this](VkCommandBuffer cb, const BuildAccelerationStructure& b) { |
| 900 | // Every address is a console VA in the GPU address arena: the device address is heap_base + VA, | 903 | // Every address is a console VA in the GPU address arena: the device address is heap_base + VA, |
| 901 | // and the BLAS addresses in instance descs get the same bias. | 904 | // and the BLAS addresses in instance descs get the same bias. |
| 902 | const std::uint64_t base = replay_.heap_base; | 905 | const std::uint64_t base = replay_.heap_base; |
| 903 | XdxrLayout layout; | 906 | XdxrLayout layout; |
| 904 | layout.compute(xdxr_elements(b), b.is_tlas); | 907 | layout.compute(xdxr_elements(b), b.is_tlas, xdxr_box16(b)); |
| 905 | // PERFORM_UPDATE refits the source (the destination itself when no source is given, as D3D12 | 908 | // PERFORM_UPDATE refits the source (the destination itself when no source is given, as D3D12 |
| 906 | // allows for an in-place update); a full build otherwise. | 909 | // allows for an in-place update); a full build otherwise. |
| 907 | const std::uint64_t from = b.update ? base + (b.src_va ? b.src_va : b.dst_va) : 0; | 910 | const std::uint64_t from = b.update ? base + (b.src_va ? b.src_va : b.dst_va) : 0; |
| @@ -911,7 +914,8 @@ public: | |||
| 911 | } else { | 914 | } else { |
| 912 | std::vector<XdxrTriangles> geometries; | 915 | std::vector<XdxrTriangles> geometries; |
| 913 | xdxr_inputs(b, &geometries, base); | 916 | xdxr_inputs(b, &geometries, base); |
| 914 | xdxr_->record_blas(cb, layout, geometries, base + b.dst_va, base + b.scratch_va, from); | 917 | xdxr_->record_blas(cb, layout, geometries, base + b.dst_va, base + b.scratch_va, from, |
| 918 | xdxr_pair(b)); | ||
| 915 | } | 919 | } |
| 916 | }; | 920 | }; |
| 917 | replay_.xdxr_copy = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dst, std::uint64_t bytes) { | 921 | replay_.xdxr_copy = [this](VkCommandBuffer cb, std::uint64_t src, std::uint64_t dst, std::uint64_t bytes) { |
| @@ -1151,6 +1155,22 @@ public: | |||
| 1151 | bool ray_tracing_supported() const { return ray_tracing_ && vk.vkCmdBuildAccelerationStructuresKHR != nullptr; } | 1155 | bool ray_tracing_supported() const { return ray_tracing_ && vk.vkCmdBuildAccelerationStructuresKHR != nullptr; } |
| 1152 | bool xdxr_acceleration_structures() const { return xdxr_ != nullptr; } | 1156 | bool xdxr_acceleration_structures() const { return xdxr_ != nullptr; } |
| 1153 | 1157 | ||
| 1158 | // Whether a build's inner nodes are BOX16 (64 bytes, half boxes rounded outward) instead of BOX32: bottom-level | ||
| 1159 | // builds with MINIMIZE_MEMORY (VK LOW_MEMORY). A top-level build keeps BOX32: it is in world space, where half | ||
| 1160 | // precision would make boxes metres too large a few kilometres from the origin. The flags of an update must match | ||
| 1161 | // its build's (D3D12), so prebuild info, the build and its refits agree. WARNING: an update that breaks that rule | ||
| 1162 | // (MINIMIZE_MEMORY on one and not the other) is refitted with the wrong layout and writes past the structure; it | ||
| 1163 | // cannot be detected when the command is recorded. | ||
| 1164 | static bool xdxr_box16(const BuildAccelerationStructure& b) { | ||
| 1165 | return !b.is_tlas && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_LOW_MEMORY_BIT_KHR) != 0; | ||
| 1166 | } | ||
| 1167 | // Whether a bottom-level build pairs sibling triangles into TRI0/TRI1 leaves: not when the structure may be | ||
| 1168 | // updated (ALLOW_UPDATE), since a refit rewrites the leaves one triangle each and would leave every TRI1 child | ||
| 1169 | // reading wrong vertices. xdxr_check refuses an update without ALLOW_UPDATE for that reason. Pairing changes | ||
| 1170 | // neither the layout nor the tree, so prebuild info does not depend on it. | ||
| 1171 | static bool xdxr_pair(const BuildAccelerationStructure& b) { | ||
| 1172 | return !b.is_tlas && !b.update && (b.build_flags & VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR) == 0; | ||
| 1173 | } | ||
| 1154 | // Triangles (BLAS) or instances (TLAS) a build has: what XdxrLayout is computed from, for the build and for | 1174 | // Triangles (BLAS) or instances (TLAS) a build has: what XdxrLayout is computed from, for the build and for |
| 1155 | // GetRaytracingAccelerationStructurePrebuildInfo. | 1175 | // GetRaytracingAccelerationStructurePrebuildInfo. |
| 1156 | static std::uint32_t xdxr_elements(const BuildAccelerationStructure& b) { | 1176 | static std::uint32_t xdxr_elements(const BuildAccelerationStructure& b) { |