D3D12.X: use a valid empty BVH for unaddressable SRVs #3688

Open
jeroenhaentjens wants to merge 1 commit from upstream-pr/3688 into main
jeroenhaentjens commented 2026-12-02 11:24:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-02T11:24:19Z.


What & Why

Unaddressable non-null acceleration-structure SRVs could produce an all-zero descriptor. Translated traversal can read that descriptor as a root in memory window 0. Use a valid empty root in coherent UMA so traversal reports a miss. Extracted from #3681 after the review by Foniass.

What is in it

  • dev_create_srv_inner uses the shared empty BVH for non-null addresses outside addressable UMA and preserves explicit null SRVs in normal mode.
  • The GPU regression calls the console SRV creation hook and feeds the emitted descriptor into translated ray traversal. It checks the explicit null case too.

Tested

  • Exact head 4ede28030c87b1a36518b25f7924f7073b952ced on an Intel Core i7-9750H and NVIDIA Quadro RTX 3000 (6 GB, driver 597.06 / 32.0.15.9706). Windows 11 Pro 25H2 build 26200.9974, Rust 1.100.0 MSVC, DXC 1.9.2602.17.
  • cargo build --locked --workspace and cargo test --locked --workspace -- --test-threads=4 passed. The harnesses reported 2,910 passed, 0 failed and 51 ignored. That total includes 19 tests with 26 explicit skip entries for wave64, heap windows, GPU_UPLOAD heaps or the driver-cache control that needs Windows Developer Mode. A temporary high-performance Windows preference selected the Quadro for test executables that use the default D3D12 adapter.
  • The same test binary ran hle::d3d12x::real::srv_tests::gpu_out_of_uma_bvh_srv_returns_a_miss --exact --nocapture with XCL_D3D12_DEBUG=1. All rays missed and the Quadro reported 0 Debug Layer messages. The regression failed against the old implementation.
  • Separate cargo build --locked --release builds and matched 60-second scripts/smoke.ps1 runs on main and the exact head.

Regression run

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA Quadro RTX 3000
title: 0ba91dcb
seconds: 60
exit: 0x0
frames shown: 2883 (PresentX 2883)
presents per 2 s (last 3): 120 121 120
device removals: 0
crashes: 0
peak commit: 12995 MB
xcl-smoke v1
commit: 4ede28030c87b1a36518b25f7924f7073b952ced
gpu: NVIDIA Quadro RTX 3000
title: 0ba91dcb
seconds: 60
exit: 0x0
frames shown: 2943 (PresentX 2943)
presents per 2 s (last 3): 121 120 121
device removals: 0
crashes: 0
peak commit: 13598 MB

Not tested

AMD, Linux or gameplay past the startup/menu. The menu smoke does not establish that the specific fallback was reached in the title.

AI use

OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR draft. The author reviewed the diff and the recorded test results.

<!-- greyfinch-sync:ivall/xcl:issue:5605419077 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3688). Originally posted by [jeroenhaentjens](https://github.com/jeroenhaentjens) on 2026-12-02T11:24:19Z. --- **What & Why** Unaddressable non-null acceleration-structure SRVs could produce an all-zero descriptor. Translated traversal can read that descriptor as a root in memory window 0. Use a valid empty root in coherent UMA so traversal reports a miss. Extracted from #3681 after [the review by Foniass](https://github.com/xcl-dev/xcl/pull/3681#issuecomment-7340339243). **What is in it** - `dev_create_srv_inner` uses the shared empty BVH for non-null addresses outside addressable UMA and preserves explicit null SRVs in normal mode. - The GPU regression calls the console SRV creation hook and feeds the emitted descriptor into translated ray traversal. It checks the explicit null case too. **Tested** - Exact head `4ede28030c87b1a36518b25f7924f7073b952ced` on an Intel Core i7-9750H and NVIDIA Quadro RTX 3000 (6 GB, driver 597.06 / `32.0.15.9706`). Windows 11 Pro 25H2 build `26200.9974`, Rust `1.100.0` MSVC, DXC `1.9.2602.17`. - `cargo build --locked --workspace` and `cargo test --locked --workspace -- --test-threads=4` passed. The harnesses reported 2,910 passed, 0 failed and 51 ignored. That total includes 19 tests with 26 explicit skip entries for wave64, heap windows, GPU_UPLOAD heaps or the driver-cache control that needs Windows Developer Mode. A temporary high-performance Windows preference selected the Quadro for test executables that use the default D3D12 adapter. - The same test binary ran `hle::d3d12x::real::srv_tests::gpu_out_of_uma_bvh_srv_returns_a_miss --exact --nocapture` with `XCL_D3D12_DEBUG=1`. All rays missed and the Quadro reported 0 Debug Layer messages. The regression failed against the old implementation. - Separate `cargo build --locked --release` builds and matched 60-second `scripts/smoke.ps1` runs on `main` and the exact head. **Regression run** ``` xcl-smoke v1 commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f gpu: NVIDIA Quadro RTX 3000 title: 0ba91dcb seconds: 60 exit: 0x0 frames shown: 2883 (PresentX 2883) presents per 2 s (last 3): 120 121 120 device removals: 0 crashes: 0 peak commit: 12995 MB ``` ``` xcl-smoke v1 commit: 4ede28030c87b1a36518b25f7924f7073b952ced gpu: NVIDIA Quadro RTX 3000 title: 0ba91dcb seconds: 60 exit: 0x0 frames shown: 2943 (PresentX 2943) presents per 2 s (last 3): 121 120 121 device removals: 0 crashes: 0 peak commit: 13598 MB ``` **Not tested** AMD, Linux or gameplay past the startup/menu. The menu smoke does not establish that the specific fallback was reached in the title. **AI use** OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR draft. The author reviewed the diff and the recorded test results.
Foniass commented 2026-12-02 11:28:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T11:28:26Z.


Review (head 4ede2803, diff read, not a merge-check):

  • #3681 still carries this change. #3681 still contains 8ff1db17, with the same fallback = (empty || va != 0).then(empty_bvh) decision in dev_create_srv_inner (real.rs ~3309) and the same runner.rs sampler-heap hunk (~1604); whichever merges second conflicts in both files or applies it twice, so that commit should be dropped from #3681.

Fine: the new gpu_out_of_uma_bvh_srv_returns_a_miss calls dev_create_srv_x with a VA outside unified memory and with VA 0, so it covers the decision that #3681's test missed: it fails on main, which writes a zero descriptor there, and checks that an explicit null SRV stays zero. The shared empty BVH is allocated once from a committed window of the process-wide UMA and never freed, and the device reaches that memory through the opened heap, the driver window or the shadow copy.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7343969088 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3688#issuecomment-7343969088). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T11:28:26Z. --- Review (head 4ede2803, diff read, not a merge-check): - **#3681 still carries this change.** #3681 still contains `8ff1db17`, with the same `fallback = (empty || va != 0).then(empty_bvh)` decision in `dev_create_srv_inner` (`real.rs` ~3309) and the same `runner.rs` sampler-heap hunk (~1604); whichever merges second conflicts in both files or applies it twice, so that commit should be dropped from #3681. Fine: the new `gpu_out_of_uma_bvh_srv_returns_a_miss` calls `dev_create_srv_x` with a VA outside unified memory and with VA 0, so it covers the decision that #3681's test missed: it fails on `main`, which writes a zero descriptor there, and checks that an explicit null SRV stays zero. The shared empty BVH is allocated once from a committed window of the process-wide UMA and never freed, and the device reaches that memory through the opened heap, the driver window or the shadow copy. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
gut0to commented 2026-12-02 15:57:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T15:57:18Z.

Review: COMMENTED


AI-assisted review (model: GPT-6). I traced the out-of-UMA SRV fallback and its allocation failure path.

<!-- greyfinch-sync:ivall/xcl:review:6154386642 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3688#pullrequestreview-6154386642). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T15:57:18Z. **Review:** COMMENTED --- AI-assisted review (model: GPT-6). I traced the out-of-UMA SRV fallback and its allocation failure path.
gut0to commented 2026-12-02 15:57:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T15:57:19Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3311

@@ -3306,16 +3306,20 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const
             let w = crate::gpu::desc::bvh_words(va, true);
             return super::console_heap::write(&slot, &[w[0], w[1], w[2], w[3], 0, 0, 0, 0]);
         }
-        // (an all-zero descriptor is no empty structure: the shader reads its root at 0x30 of
-        // window 0)
-        if let Some(at) = empty.then(empty_bvh).flatten() {
+        // A zero descriptor can make the shader read its root from window 0. Give a missing
+        // non-null address the shared empty root and preserve explicit null SRVs.
+        let fallback = (empty || va != 0).then(empty_bvh).flatten();

If empty_bvh() cannot allocate its 64 KiB root, fallback is None and this function falls through to writing a zero descriptor. The comment above says a zero descriptor can make traversal read the root from window 0—the behavior this change aims to prevent. Since empty_bvh() caches Option<u64> in a OnceLock, a transient allocation failure is permanent for this process, even if UMA space becomes available later. Could this path avoid publishing a zero descriptor for a non-null out-of-UMA SRV and retry after allocation pressure clears? A failure-then-retry test would cover the case.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772376479 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3688#discussion_r4772376479). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-02T15:57:19Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3311 ~~~~diff @@ -3306,16 +3306,20 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const let w = crate::gpu::desc::bvh_words(va, true); return super::console_heap::write(&slot, &[w[0], w[1], w[2], w[3], 0, 0, 0, 0]); } - // (an all-zero descriptor is no empty structure: the shader reads its root at 0x30 of - // window 0) - if let Some(at) = empty.then(empty_bvh).flatten() { + // A zero descriptor can make the shader read its root from window 0. Give a missing + // non-null address the shared empty root and preserve explicit null SRVs. + let fallback = (empty || va != 0).then(empty_bvh).flatten(); ~~~~ --- If `empty_bvh()` cannot allocate its 64 KiB root, `fallback` is `None` and this function falls through to writing a zero descriptor. The comment above says a zero descriptor can make traversal read the root from window 0—the behavior this change aims to prevent. Since `empty_bvh()` caches `Option<u64>` in a `OnceLock`, a transient allocation failure is permanent for this process, even if UMA space becomes available later. Could this path avoid publishing a zero descriptor for a non-null out-of-UMA SRV and retry after allocation pressure clears? A failure-then-retry test would cover the case.
fromthemoonx commented 2026-12-03 01:51:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T01:51:22Z.


merge-check
base: 078358a058
head: 4ede28030c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored (base: 3006 passed, 0 failed, 52 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none in this run. In a first run the lib binary ended with 0xc0000005 after 10 of the 40 dumps of thread_dumps_while_threads_run_and_exit, before this PR's test had started. That is #3586, which is on base too (#3743 fixes it)
review: read the whole diff (4 files, +141 -10). No blocking finding.

  • Only a non-null address outside unified memory changes: it now gets the shared empty BVH where base writes a zero descriptor. Addresses in unified memory, explicit null SRVs and XCL_BVH_EMPTY=1 behave as on base.
  • empty_bvh() now runs without XCL_BVH_EMPTY, under the tracked-SRV write lock. The allocation takes only the arena's own lock and releases it before it returns, so I see no lock-order risk.
  • The new test ran on this GPU: 30 of 30 alone, 30 of 30 with srv_tests:: at --test-threads=8, and 10 of 10 with XCL_D3D12_DEBUG=1 (all rays missed, 0 messages).
  • Mutations, each fails the test: base's decision put back; the empty BVH also given to null SRVs; the empty root not written. All three fail at the checks of the descriptor and the root in memory, before the GPU part, so they do not show what the ray part alone would catch.
  • The sampler heap added in runner.rs is test support: without it the test still passes, but the debug layer reports 1 message.
  • gut0to's open point is right from reading: if the 64 KiB allocation fails once, empty_bvh() keeps None for the rest of the process and the zero descriptor is written. Base writes that descriptor every time, so it is a remaining gap and not a regression.
  • Not tested: AMD, and a retail title (none on this machine).
    performance: none expected (reasoned, not measured): one 64 KiB allocation, made the first time such an address is seen.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
<!-- greyfinch-sync:ivall/xcl:comment:7364811394 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3688#issuecomment-7364811394). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-03T01:51:22Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: 4ede28030c87b1a36518b25f7924f7073b952ced merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored (base: 3006 passed, 0 failed, 52 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none in this run. In a first run the lib binary ended with 0xc0000005 after 10 of the 40 dumps of `thread_dumps_while_threads_run_and_exit`, before this PR's test had started. That is #3586, which is on base too (#3743 fixes it) review: read the whole diff (4 files, +141 -10). No blocking finding. - Only a non-null address outside unified memory changes: it now gets the shared empty BVH where base writes a zero descriptor. Addresses in unified memory, explicit null SRVs and `XCL_BVH_EMPTY=1` behave as on base. - `empty_bvh()` now runs without `XCL_BVH_EMPTY`, under the tracked-SRV write lock. The allocation takes only the arena's own lock and releases it before it returns, so I see no lock-order risk. - The new test ran on this GPU: 30 of 30 alone, 30 of 30 with `srv_tests::` at `--test-threads=8`, and 10 of 10 with `XCL_D3D12_DEBUG=1` (all rays missed, 0 messages). - Mutations, each fails the test: base's decision put back; the empty BVH also given to null SRVs; the empty root not written. All three fail at the checks of the descriptor and the root in memory, before the GPU part, so they do not show what the ray part alone would catch. - The sampler heap added in `runner.rs` is test support: without it the test still passes, but the debug layer reports 1 message. - gut0to's open point is right from reading: if the 64 KiB allocation fails once, `empty_bvh()` keeps `None` for the rest of the process and the zero descriptor is written. Base writes that descriptor every time, so it is a remaining gap and not a regression. - Not tested: AMD, and a retail title (none on this machine). performance: none expected (reasoned, not measured): one 64 KiB allocation, made the first time such an address is seen. verdict: safe to merge hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3688:upstream-pr/3688'
git switch 'upstream-pr/3688'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3688'
git switch 'upstream-pr/3688'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3688'
git switch 'upstream-pr/3688'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3688'
git switch 'main'
git merge --squash 'upstream-pr/3688'
git switch 'main'
git merge --ff-only 'upstream-pr/3688'
git switch 'main'
git merge 'upstream-pr/3688'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3688
No description provided.