d3d12: drop acceleration-structure postbuild info when LEONIDA_RT_AS=off #2413

Open
github-bot wants to merge 1 commit from github-bot/gh-2413 into main AGit
Owner

@⁠robot00f on GitHub · 2026-11-26 23:51 UTC · original
robot00f:fix/rt-as-off-postbuild → main · +145 −18 · 3 files · 1 commits · open

Claimed in the coordination issue as: RT-D3D12-AS-OFF-POSTBUILD (#1608)

What and why

LEONIDA_RT_AS=off drops acceleration-structure builds and copies in resolve_acceleration_structure_build and resolve_acceleration_structure_copy, leaving BVH buffers unbuilt for isolating device-loss regressions. However, resolve_acceleration_structure_postbuild did not check acceleration_structures_off(), so standalone EmitRaytracingAccelerationStructurePostbuildInfo calls still resolved and recorded XDXR postbuild dispatches (or KHR postbuild queries) reading unbuilt acceleration-structure memory and overwriting the destination buffer.

  • Check if (acceleration_structures_off()) return false; at the top of resolve_acceleration_structure_postbuild in runtime/shims/d3d12_vulkan_device.cpp, matching resolve_acceleration_structure_build and resolve_acceleration_structure_copy immediately above it, and update the LEONIDA_RT_AS=off diagnostic log and comment accordingly.
  • Add d3d12_dxr_validation_off (LEONIDA_RT_AS=off) in runtime/CMakeLists.txt and runtime/test/d3d12_dxr_validation_test.cpp, verifying both that all three resolve_acceleration_structure_{build,copy,postbuild} entry points return false and that GPU execution of BuildRaytracingAccelerationStructure (with inline postbuild), standalone EmitRaytracingAccelerationStructurePostbuildInfo (COMPACTED_SIZE and CURRENT_SIZE), and CopyRaytracingAccelerationStructure leaves a seeded postbuild buffer untouched while preserving D3D12 command-list argument validation.

Tested

  • ctest -R "^d3d12_dxr_validation" (d3d12_dxr_validation, d3d12_dxr_validation_khr, d3d12_dxr_validation_off): all passed (KHR skipped as expected on Pascal).
  • python -I tests/test_ctest_registration.py, python -I tests/test_text_write_line_endings.py, and python -I scripts/check_no_game_data.py: all clean.

GPUs tested: NVIDIA GeForce GTX 1050 Ti (driver 582.28, Windows 10 19045)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — D3D12 Vulkan runtime only)
**@⁠robot00f** on GitHub · 2026-11-26 23:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2413) `robot00f:fix/rt-as-off-postbuild` → `main` · +145 −18 · 3 files · 1 commits · open Claimed in the coordination issue as: RT-D3D12-AS-OFF-POSTBUILD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `LEONIDA_RT_AS=off` drops acceleration-structure builds and copies in `resolve_acceleration_structure_build` and `resolve_acceleration_structure_copy`, leaving BVH buffers unbuilt for isolating device-loss regressions. However, `resolve_acceleration_structure_postbuild` did not check `acceleration_structures_off()`, so standalone `EmitRaytracingAccelerationStructurePostbuildInfo` calls still resolved and recorded XDXR postbuild dispatches (or KHR postbuild queries) reading unbuilt acceleration-structure memory and overwriting the destination buffer. - Check `if (acceleration_structures_off()) return false;` at the top of `resolve_acceleration_structure_postbuild` in `runtime/shims/d3d12_vulkan_device.cpp`, matching `resolve_acceleration_structure_build` and `resolve_acceleration_structure_copy` immediately above it, and update the `LEONIDA_RT_AS=off` diagnostic log and comment accordingly. - Add `d3d12_dxr_validation_off` (`LEONIDA_RT_AS=off`) in `runtime/CMakeLists.txt` and `runtime/test/d3d12_dxr_validation_test.cpp`, verifying both that all three `resolve_acceleration_structure_{build,copy,postbuild}` entry points return `false` and that GPU execution of `BuildRaytracingAccelerationStructure` (with inline postbuild), standalone `EmitRaytracingAccelerationStructurePostbuildInfo` (`COMPACTED_SIZE` and `CURRENT_SIZE`), and `CopyRaytracingAccelerationStructure` leaves a seeded postbuild buffer untouched while preserving D3D12 command-list argument validation. ### Tested - `ctest -R "^d3d12_dxr_validation"` (`d3d12_dxr_validation`, `d3d12_dxr_validation_khr`, `d3d12_dxr_validation_off`): all passed (KHR skipped as expected on Pascal). - `python -I tests/test_ctest_registration.py`, `python -I tests/test_text_write_line_endings.py`, and `python -I scripts/check_no_game_data.py`: all clean. GPUs tested: NVIDIA GeForce GTX 1050 Ti (driver 582.28, Windows 10 19045) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — D3D12 Vulkan runtime only)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:35:40 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-27 00:18 UTC · original

The KHR case that skipped on Pascal ran on a physical RTX 4090. I built 673bd8304d on Windows 11, NVIDIA 616.64, and ran all three d3d12_dxr_validation variants with Vulkan validation enabled. All three passed without skips or Vulkan validation errors.

  • Default and LEONIDA_RT_AS=khr: Each ran the valid bottom-level and top-level acceleration-structure build cases through the Vulkan layer. The native D3D12 comparison also passed on the same RTX 4090.
  • LEONIDA_RT_AS=off: All four 64-bit values in the 32-byte GPU readback retained their seeded value after the inline postbuild, standalone compacted/current-size queries, and copy. The strict command-list checks also passed.
  • Separate enabled-path check: vk_xdxr_postbuild_readback read back 320 bytes of reported size, exactly the expected value, and observed one compute-to-host barrier. The KHR copy/postbuild callback test also passed; that one uses a CPU mock.

All inputs were synthetic. AI-assisted verification.

**@⁠ecox982745** on GitHub · 2026-11-27 00:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2413#issuecomment-7206347696) The KHR case that skipped on Pascal ran on a physical RTX 4090. I built `673bd8304d` on Windows 11, NVIDIA 616.64, and ran all three `d3d12_dxr_validation` variants with Vulkan validation enabled. All three passed without skips or Vulkan validation errors. - **Default and `LEONIDA_RT_AS=khr`:** Each ran the valid bottom-level and top-level acceleration-structure build cases through the Vulkan layer. The native D3D12 comparison also passed on the same RTX 4090. - **`LEONIDA_RT_AS=off`:** All four 64-bit values in the 32-byte GPU readback retained their seeded value after the inline postbuild, standalone compacted/current-size queries, and copy. The strict command-list checks also passed. - **Separate enabled-path check:** `vk_xdxr_postbuild_readback` read back 320 bytes of reported size, exactly the expected value, and observed one compute-to-host barrier. The KHR copy/postbuild callback test also passed; that one uses a CPU mock. All inputs were synthetic. AI-assisted verification.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 05:25 UTC · original · approved these changes

Approving. Checked on 673bd8304, which fast-forwards onto main.

Built d3d12_dxr_validation_test (clang-cl, cross-built) and ran the three ctest entries under Wine on llvmpipe: d3d12_dxr_validation, _khr and the new _off all pass, and the off run reaches the end of the suite ("valid prebuild, GPU BLAS+TLAS build, and all strict validation checks OK"). As a negative check I built the new test against main without the one-line change in resolve_acceleration_structure_postbuild: the off variant fails straight away at the resolve check, so the test does catch the gap.

Read the diff. All three D3D12 entry points in d3d12_com.cpp (Build's inline postbuild, Emit, Copy) go through the resolve_* functions, so the one early return covers the D3D12 path as well as the Xbox one.

One observation, not a blocker: because BuildRaytracingAccelerationStructure resolves the build before it validates the inline postbuild descs, under LEONIDA_RT_AS=off an invalid inline postbuild DestBuffer (0 or misaligned) is silently dropped instead of failing Close. You already skip those two cases in the test with a comment, and for a diagnostic switch that seems acceptable, but it might be worth a word in the doc line so nobody chases a missing E_INVALIDARG with the switch on.

**@⁠tiguan26** on GitHub · 2026-11-27 05:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2413#pullrequestreview-6083845448) · **approved these changes** Approving. Checked on 673bd8304, which fast-forwards onto main. Built `d3d12_dxr_validation_test` (clang-cl, cross-built) and ran the three ctest entries under Wine on llvmpipe: `d3d12_dxr_validation`, `_khr` and the new `_off` all pass, and the off run reaches the end of the suite ("valid prebuild, GPU BLAS+TLAS build, and all strict validation checks OK"). As a negative check I built the new test against main without the one-line change in `resolve_acceleration_structure_postbuild`: the off variant fails straight away at the resolve check, so the test does catch the gap. Read the diff. All three D3D12 entry points in `d3d12_com.cpp` (Build's inline postbuild, Emit, Copy) go through the `resolve_*` functions, so the one early return covers the D3D12 path as well as the Xbox one. One observation, not a blocker: because `BuildRaytracingAccelerationStructure` resolves the build before it validates the inline postbuild descs, under `LEONIDA_RT_AS=off` an invalid inline postbuild DestBuffer (0 or misaligned) is silently dropped instead of failing Close. You already skip those two cases in the test with a comment, and for a diagnostic switch that seems acceptable, but it might be worth a word in the doc line so nobody chases a missing E_INVALIDARG with the switch on.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2413/head:github-bot/gh-2413'
git switch 'github-bot/gh-2413'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2413'
git switch 'github-bot/gh-2413'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2413'
git switch 'github-bot/gh-2413'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2413'
git switch 'main'
git merge --squash 'github-bot/gh-2413'
git switch 'main'
git merge --ff-only 'github-bot/gh-2413'
git switch 'main'
git merge 'github-bot/gh-2413'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.