Skip to content

D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap - #3349

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/shared-heap-null-window-uavs
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/shared-heap-null-window-uavs

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Write the shared view heap's out-of-layout null raw buffer UAVs (MEM_NULL_LOAD and MEM_NULL_STORE) after fill_nulls in console_heap::shared_heap (crates/xcl/src/hle/d3d12x/console_heap.rs), so fill_nulls no longer overwrites those two RWByteAddressBuffer null UAV slots with Texture2D null SRV/UAV descriptors.

What is in it

  • crates/xcl/src/hle/d3d12x/console_heap.rs:
    • Move null_window_views(dev, cpu, inc) after the fill_nulls(dev, cpu, inc, MEM_HEAP_BASE, cap, at) pass in shared_heap. Previously null_window_views ran first and fill_nulls immediately overwrote MEM_NULL_LOAD (even index 20) with a Texture2D null SRV and MEM_NULL_STORE (odd index 21) with a Texture2D null UAV, causing descriptor-type mismatches whenever XCL_HEAP_WINDOWS=1 shaders redirected out-of-layout memory loads/stores to those slots (set_window_views only writes MEM_HEAP_BASE..MEM_NULL_LOAD).
    • Add child-isolated WARP + D3D12 debug-layer + GPU-based validation (ID3D12Debug1::SetEnableGPUBasedValidation(true)) test hle::d3d12x::console_heap::tests::shared_heap_preserves_null_window_raw_uavs that initializes shared_heap, dispatches a Direct DXIL SM 6.6 compute shader accessing ResourceDescriptorHeap[MEM_NULL_LOAD] and ResourceDescriptorHeap[MEM_NULL_STORE] as RWByteAddressBuffer, verifies readback (0 ^ 0xA5A5_5A5A), and asserts 0 D3D12 debug/GBV errors.

Tested

  • Targeted console_heap tests (cargo test -p xcl --lib -j 4 -- hle::d3d12x::console_heap:: and cargo test -p xcl --test console_heap_contract -j 4):
    • Before the fix: shared_heap_preserves_null_window_raw_uavs failed 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_UAV and [id=941] UAV Dimension Expected: D3D12_UAV_DIMENSION_BUFFER, UAV Dimension In Descriptor: D3D12_UAV_DIMENSION_TEXTURE2D, Descriptor Heap Index: [21]).
    • After the fix: 26 passed; 0 failed (0.27s) in hle::d3d12x::console_heap:: (including shared_heap_preserves_null_window_raw_uavs with 0 GBV errors and 0xA5A5_5A5A readback) and 9 passed; 0 failed (0.01s) in console_heap_contract.
  • Full workspace test suite on Windows 11 Pro (rustc 1.99.0, RTX 5070 Ti driver 32.0.16.1074, DXC 1.9.2609.5):
    • Command: cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::
    • Result: 2610 passed; 0 failed; 49 ignored (128.2s).
    • SKIPPED: 26 runtime SKIPPED lines (21 wave64-only checks on this wave32 RTX 5070 Ti, 3 wave32 per-lane #1426 op refusals, 2 heap-windows opt-in checks).

Regression run
Baseline (main ancestor f0e8fdd5c3942ddd399d5ee11384c8595c5aacff) and this PR (5dc64ea70b240d48ee0da31b1deff64ae1260710), 150 s on RTX 5070 Ti:

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 5dc64ea70b240d48ee0da31b1deff64ae1260710
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 4154 (PresentX 4154)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17074 MB

Not tested

  • AMD RDNA hardware, macOS/Linux hosts, and set_window_views slot expansion past windows.len().max(MAX_WINDOWS) (left untouched for #3096).

AI use

  • Drafted, verified, and tested with an AI coding assistant; all code, tests, and regression runs were reviewed and validated locally.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 5dc64ea
merge: 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_heap writes the raw null UAVs (~503) and then fill_nulls(MEM_HEAP_BASE..cap) (~511) writes Texture2D nulls over descriptors 20 and 21. Those slots are never handed out (next starts at 22) and are outside every range that release, drain or resource_gone refill, so writing them once at creation is enough. By default slots 20/21 now hold raw buffer null UAVs instead of Texture2D nulls; only XCL_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 calls skip_test; open #3486 says it depends on this PR.
performance: 60 s smoke of a retail title, main d0832e6 vs 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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -511,6 +510,9 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool {
fill_nulls(dev, cpu, inc, crate::gpu::recomp::MEM_HEAP_BASE, cap, at);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for slots 20/21 looks right, but fill_nulls still 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_views only rewrites windows.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). Starting fill_nulls at MEM_NULL_STORE + 1 (where Global.next starts), and having null_window_views write raw null UAVs for all of MEM_HEAP_BASE..=MEM_NULL_STORE once, would fix the whole region.

});
// Written after `fill_nulls` so the two out-of-layout raw buffer null UAVs at
// `MEM_NULL_LOAD` and `MEM_NULL_STORE` are not overwritten with Texture2D null SRV/UAVs.
null_window_views(dev, cpu, inc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants