D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3349"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T09:57:08Z.
Write the shared view heap's out-of-layout null raw buffer UAVs (
MEM_NULL_LOADandMEM_NULL_STORE) afterfill_nullsinconsole_heap::shared_heap(crates/xcl/src/hle/d3d12x/console_heap.rs), sofill_nullsno longer overwrites those twoRWByteAddressBuffernull UAV slots withTexture2Dnull SRV/UAV descriptors.What is in it
crates/xcl/src/hle/d3d12x/console_heap.rs:null_window_views(dev, cpu, inc)after thefill_nulls(dev, cpu, inc, MEM_HEAP_BASE, cap, at)pass inshared_heap. Previouslynull_window_viewsran first andfill_nullsimmediately overwroteMEM_NULL_LOAD(even index20) with aTexture2Dnull SRV andMEM_NULL_STORE(odd index21) with aTexture2Dnull UAV, causing descriptor-type mismatches wheneverXCL_HEAP_WINDOWS=1shaders redirected out-of-layout memory loads/stores to those slots (set_window_viewsonly writesMEM_HEAP_BASE..MEM_NULL_LOAD).ID3D12Debug1::SetEnableGPUBasedValidation(true)) testhle::d3d12x::console_heap::tests::shared_heap_preserves_null_window_raw_uavsthat initializesshared_heap, dispatches a Direct DXIL SM 6.6 compute shader accessingResourceDescriptorHeap[MEM_NULL_LOAD]andResourceDescriptorHeap[MEM_NULL_STORE]asRWByteAddressBuffer, verifies readback (0 ^ 0xA5A5_5A5A), and asserts0D3D12 debug/GBV errors.Tested
console_heaptests (cargo test -p xcl --lib -j 4 -- hle::d3d12x::console_heap::andcargo test -p xcl --test console_heap_contract -j 4):shared_heap_preserves_null_window_raw_uavsfailed on WARP+GBV with two D3D12 GPU-based validation errors ([id=939]Descriptor Heap Index: [20], Descriptor Type in Heap: D3D12_DESCRIPTOR_RANGE_TYPE_SRV, Register Type: D3D12_DESCRIPTOR_RANGE_TYPE_UAVand[id=941]UAV Dimension Expected: D3D12_UAV_DIMENSION_BUFFER, UAV Dimension In Descriptor: D3D12_UAV_DIMENSION_TEXTURE2D, Descriptor Heap Index: [21]).26 passed; 0 failed(0.27s) inhle::d3d12x::console_heap::(includingshared_heap_preserves_null_window_raw_uavswith0GBV errors and0xA5A5_5A5Areadback) and9 passed; 0 failed(0.01s) inconsole_heap_contract.rustc 1.99.0, RTX 5070 Ti driver32.0.16.1074, DXC1.9.2609.5):cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::2610 passed; 0 failed; 49 ignored(128.2s).SKIPPED:26runtimeSKIPPEDlines (21wave64-only checks on this wave32 RTX 5070 Ti,3wave32 per-lane#1426op refusals,2heap-windows opt-in checks).Regression run
Baseline (
mainancestorf0e8fdd5c3942ddd399d5ee11384c8595c5aacff) and this PR (5dc64ea70b240d48ee0da31b1deff64ae1260710), 150 s on RTX 5070 Ti:Not tested
set_window_viewsslot expansion pastwindows.len().max(MAX_WINDOWS)(left untouched for#3096).AI use
Claude Opus 5.5for initial patch/GBV test;Gemini 4 Neonfor verification and PR maintenance); all code, tests, and regression runs were validated locally.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:31:03Z.
merge-check
base:
d0832e614fhead:
5dc64ea70bmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (console_heap.rs: a 3-line move plus the test). The bug is real on main:
shared_heapwrites the raw null UAVs (~503) and thenfill_nulls(MEM_HEAP_BASE..cap)(~511) writes Texture2D nulls over descriptors 20 and 21. Those slots are never handed out (nextstarts at 22) and are outside every range that release, drain orresource_gonerefill, so writing them once at creation is enough. By default slots 20/21 now hold raw buffer null UAVs instead of Texture2D nulls; onlyXCL_HEAP_WINDOWS=1(off by default) uses them, and a garbage T# index of 20 would find a UAV in an SRV slot, the same kind of risk slots 4-19 already carry with heap windows on. Findings: (1) the test catches the bug only through GPU-based validation: a null descriptor reads 0 whatever its type, so the readback (~3022) passes on main too, and without the debug layer it skips. (2) The PR's smoke numbers (4154 vs 1695 frames) aren't caused by this change: smoke doesn't turn heap windows on, and main's run had stopped presenting. (3) AI use names no tool or model. Fine: the test runs in its own child process and callsskip_test; open #3486 says it depends on this PR.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (ac66e869): 1516 -> 1652 frames shown (108 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17101 MB, 0 device removals, 0 crashes. Smoke doesn't set XCL_HEAP_WINDOWS=1, so descriptors 20/21 aren't used here.verdict: safe to merge (the test only catches the bug through GPU-based validation; the description should name the AI model)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:22:18Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 510The fix for slots 20/21 looks right, but
fill_nullsstill starts at MEM_HEAP_BASE, so it writes Texture2D null SRV/UAVs over the window slots 4..19, which are reserved for raw buffer UAVs too.set_window_viewsonly rewriteswindows.len().max(MAX_WINDOWS)slots (4 for a normal layout), so slots 8..19 keep Texture2D nulls. A heap-windows shader that reaches window k >= count (a cached PSO translated for a wider layout, or the #3096 expansion) hits the same type mismatch this PR fixes for 20/21 (GBV 939/941, undefined on hardware). Startingfill_nullsat MEM_NULL_STORE + 1 (where Global.next starts), and havingnull_window_viewswrite raw null UAVs for all of MEM_HEAP_BASE..=MEM_NULL_STORE once, would fix the whole region.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:22:18Z.
Code review location:
crates/xcl/src/hle/d3d12x/console_heap.rs; line 515Not certain about this one: with slots 20/21 holding raw buffer UAVs again, a stale or garbage T# index that lands on them reaches a raw UAV through a Texture2D access. The image guard only checks
tw0 < VIEW_HEAP_MAX_SRV, with no lower bound past the window region. A T# with word 0 = 20 indexes ResourceDescriptorHeap[20] as Texture2D and [21] as RWTexture2D and finds a 4-byte raw buffer UAV. The MEM_HEAP_BASE doc already records that a raw buffer UAV read as a texture hangs NVIDIA GPUs, and the shared_heap comment's promise that garbage T# indexes read zeros no longer holds for 4..21.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T01:22:18Z.
Review: COMMENTED
Review of
5dc64ea7: 2 finding(s). 2 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by SavageCore on 2026-12-02T04:30:47Z.
Review: COMMENTED
sorry, ignore, agent went crazy
Imported from ivall/xcl. Originally posted by Pipodi on 2026-12-02T10:48:56Z.
merge-check
base:
1c8b551475head:
5dc64ea70bmerge: clean (merge commit bfb2d5db2d578a7ab0860cd4ab4125587f2938b9)
build: cargo build --workspace -> ok (and cargo build --release -p xcl -> ok)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; failing: none. 25 SKIPPED lines (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache).
shared_heap_preserves_null_window_raw_uavsruns here (the debug layer is installed; the test turns on GPU-based validation on WARP itself, no env needed) and passes. With only the 3-line move reverted (test kept) it fails at console_heap.rs:3037 with two GBV errors: heap index 20 is an SRV where the shader has a UAV, and index 21 is a TEXTURE2D UAV where the shader expects a BUFFER UAV.review:
null_window_views(console_heap.rs:503) runs beforefill_nulls(MEM_HEAP_BASE..cap)(:511), which copies the null block over 20 (even: Texture2D null SRV) and 21 (odd: Texture2D null UAV); writing them afterfill_nulls(:515 in the merge) fixes both.shared_heapis the only caller ofnull_window_views; the otherfill_nullscallers (resource_gone:418, range release/drain :708/:768,GONEcopies :1308) only touch handed-out slots, which start atMEM_NULL_STORE + 1(:536), so 20/21 are never overwritten later. The test runner's heaps (runner.rs:1599/1891) write the same views withoutfill_nulls. Without the CPU-only null heapfill_nullsdoes not run and the order does not matter.raw_window_uav(4)is an R32_TYPELESS buffer UAV with the RAW flag, which is what the heap-window accessors bind at those indexes (RWByteAddressBufferfromResourceDescriptorHeap, emit.rs:6228); with no resource, loads read 0 and stores are dropped.okwithout coverage.performance: no cost by default: one more pair of view writes at heap creation, and slots 20/21 are only bound with heap windows on (
XCL_HEAP_WINDOWS=1, off by default). Smoke pair on the retail title, 60 s, same scripted presses on both sides, one untimed warm-up run before each: main 1611 frames, peak commit 19846 MB; merge 1594 frames (98.9 %), 19825 MB (99.9 %); 0 device removals and 0 crashes on both. The smoke runs do not set XCL_HEAP_WINDOWS=1, so they do not reach descriptors 20/21.main (base):
this PR merged into base:
verdict: safe to merge (the AI use section should still name the tool and model)
hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0; debug suite, release smoke. Claude Code, Claude Opus 5.5 (ran the merge, build, suite, revert test and smoke pair, and wrote this check).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.