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

Closed
leonida/mandy
robot00f wants to merge 0 commits from fix/rt-as-off-postbuild into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

robot00f commented 2026-11-26 23:51:55 +00:00

Claimed in the coordination issue as: RT-D3D12-AS-OFF-POSTBUILD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7205556765)

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)
Claimed in the coordination issue as: RT-D3D12-AS-OFF-POSTBUILD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7205556765) ### 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)
ecox982745 commented 2026-11-27 00:18:13 +00:00

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.

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.
tiguan26 approved these changes 2026-11-27 05:25:12 +00:00
tiguan26 left a comment

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.

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.
zmasi commented 2026-11-28 23:23:28 +00:00

#2413 | head 673bd8304d7b0c2a9c7f8fbf182441d87c02d420 (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_dxr_validation|d3d12_dxr_validation_khr|d3d12_dxr_validation_off|vk_xdxr_postbuild_readback|replay_khr_as_copy_postbuild)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: building d3d12_dxr_validation_test against main's runtime/shims/d3d12_vulkan_device.cpp fails d3d12_dxr_validation_off (LEONIDA_RT_AS=off: resolve_acceleration_structure_{build,copy,postbuild} must all drop) | green on PR+main: 5/5 CTests (d3d12_dxr_validation, d3d12_dxr_validation_khr, d3d12_dxr_validation_off — all 4 seeded 64-bit postbuild slots untouched across inline postbuild, standalone compacted/current-size queries, and copy with strict command-list validation intact, replay_khr_as_copy_postbuild, vk_xdxr_postbuild_readback — compute_to_host_barriers=1, reported_size=320, expected=320) pass in 4.91 s on RTX 3090 without skips and with 0 Khronos validation errors; test_ctest_registration.py & test_text_write_line_endings.py (10/10 OK) and check_no_game_data.py (0 violations) pass | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2413 | head 673bd8304d7b0c2a9c7f8fbf182441d87c02d420 (merged cleanly with main adfb3821a23612263c1c5b195453ed01c4c114db — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_dxr_validation|d3d12_dxr_validation_khr|d3d12_dxr_validation_off|vk_xdxr_postbuild_readback|replay_khr_as_copy_postbuild)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: building `d3d12_dxr_validation_test` against `main`'s `runtime/shims/d3d12_vulkan_device.cpp` fails `d3d12_dxr_validation_off` (`LEONIDA_RT_AS=off: resolve_acceleration_structure_{build,copy,postbuild} must all drop`) | green on PR+main: `5/5` CTests (`d3d12_dxr_validation`, `d3d12_dxr_validation_khr`, `d3d12_dxr_validation_off` — all 4 seeded 64-bit postbuild slots untouched across inline postbuild, standalone compacted/current-size queries, and copy with strict command-list validation intact, `replay_khr_as_copy_postbuild`, `vk_xdxr_postbuild_readback` — `compute_to_host_barriers=1, reported_size=320, expected=320`) pass in `4.91 s` on RTX 3090 without skips and with `0` Khronos validation errors; `test_ctest_registration.py` & `test_text_write_line_endings.py` (`10/10 OK`) and `check_no_game_data.py` (`0` violations) pass | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 reviewed 2026-11-29 04:29:06 +00:00
timbot103 left a comment
No description provided.
Static audit of `673bd8304`. No builds or GPU runs performed. - The guard in `runtime/shims/d3d12_vulkan_device.cpp:21018` drops standalone Emit after the COM argument checks and before either XDXR dispatch or KHR query replay. Build already exits before recording the build or its inline postbuild commands. Both entry points reject bundles, so `ExecuteBundle` cannot forward those calls. Inline destination address validation was already after the build resolver, as reflected in the off-mode test. See `runtime/shims/d3d12_com.cpp:1057`, `runtime/shims/d3d12_com.cpp:1152`, and `runtime/src/vulkan_replay.h:5396`. - Dropped commands leave the destination bytes at their prior values, with no zero-fill. XDXR replay writes compacted and current sizes, and KHR replay writes compacted size. Serialization was already unsupported in both Vulkan replay paths. Title-side reads, polling, and any resulting crash or loop remain unverified. See `runtime/src/vulkan_replay.h:4217`. - The runtime and test use an exact, case-sensitive match for `off`. The runtime caches the result, and the separate `khr` selector still chooses the backend. The new CTest sets `off` for its process and retains the existing skip and validation-error settings. The Windows target uses the existing MSVC CRT call, and native Linux does not compile this target. See `runtime/shims/d3d12_vulkan_device.cpp:20992`, `runtime/test/d3d12_dxr_validation_test.cpp:79`, and `runtime/CMakeLists.txt:2764`. - **[MINOR]** At `runtime/test/d3d12_dxr_validation_test.cpp:324`, the clone destination is `src_va` while the sentinel readback observes `post_buf`. A clone recorded by the COM method could therefore pass both the sentinel check and the separate resolver checks. Please assert that the recorded list contains no `CopyAccelerationStructure` command using `rt::d3d12::recorded_commands`. AI-assisted.
enlight3d commented 2026-11-29 15:17:46 +00:00

RUN #2413 (drop acceleration-structure postbuild info when LEONIDA_RT_AS=off)

  • Heads: PR head 673bd8304d7b0c2a9c7f8fbf182441d87c02d420, main bd643e46e784daf6bf3a45d09f0ec20e669c4ddb.
  • Merged locally with main (git merge --no-ff), no conflicts, nothing pushed.
  • Commands:
    • cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
    • cmake --build runtime/build -j 6 --target d3d12_dxr_validation_test vk_xdxr_postbuild_readback_test replay_khr_as_copy_postbuild_test gta6rt
    • ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_dxr_validation|d3d12_dxr_validation_khr|d3d12_dxr_validation_off|vk_xdxr_postbuild_readback|replay_khr_as_copy_postbuild)$" --output-on-failure -j1 (once as is, once with LEONIDA_VK_VALIDATION=1)
  • Red (behavioural): same d3d12_dxr_validation_test with the PR's test and CMake registration kept, runtime/shims/d3d12_vulkan_device.cpp reverted to main's version. It builds against main, so this is not a build failure. d3d12_dxr_validation and d3d12_dxr_validation_khr still pass; d3d12_dxr_validation_off fails: LEONIDA_RT_AS=off: resolve_acceleration_structure_{build,copy,postbuild} must all drop.
  • Green (PR merged into main): 5 of 5 pass, none skipped (the KHR variant runs on this GPU), both without and with LEONIDA_VK_VALIDATION=1.
  • Link: gta6rt.exe built from the merged tree has no new imports vs main (693 DLL!symbol entries, identical list, from dumpbin /imports).
  • Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.
  • Prep notes by TheGeogeo's review session.
RUN #2413 (drop acceleration-structure postbuild info when LEONIDA_RT_AS=off) - Heads: PR head `673bd8304d7b0c2a9c7f8fbf182441d87c02d420`, main `bd643e46e784daf6bf3a45d09f0ec20e669c4ddb`. - Merged locally with main (`git merge --no-ff`), no conflicts, nothing pushed. - Commands: - `cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON` - `cmake --build runtime/build -j 6 --target d3d12_dxr_validation_test vk_xdxr_postbuild_readback_test replay_khr_as_copy_postbuild_test gta6rt` - `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_dxr_validation|d3d12_dxr_validation_khr|d3d12_dxr_validation_off|vk_xdxr_postbuild_readback|replay_khr_as_copy_postbuild)$" --output-on-failure -j1` (once as is, once with `LEONIDA_VK_VALIDATION=1`) - Red (behavioural): same `d3d12_dxr_validation_test` with the PR's test and CMake registration kept, `runtime/shims/d3d12_vulkan_device.cpp` reverted to main's version. It builds against main, so this is not a build failure. `d3d12_dxr_validation` and `d3d12_dxr_validation_khr` still pass; `d3d12_dxr_validation_off` fails: `LEONIDA_RT_AS=off: resolve_acceleration_structure_{build,copy,postbuild} must all drop`. - Green (PR merged into main): 5 of 5 pass, none skipped (the KHR variant runs on this GPU), both without and with `LEONIDA_VK_VALIDATION=1`. - Link: gta6rt.exe built from the merged tree has no new imports vs main (693 DLL!symbol entries, identical list, from `dumpbin /imports`). - Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44. - Prep notes by TheGeogeo's review session.
aslan2142 commented 2026-12-01 16:44:45 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.