Skip to content

D3D12.X: use null PC buffer UAV for shifted UMA buffers - #3297

Closed
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/uav-buf-delta-null
Closed

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/uav-buf-delta-null

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

When a console buffer was placed at a 64 KiB-aligned UMA backing address below its console address (buffer_delta(res) != 0), dev_create_srv_x already substituted a null PC buffer SRV (buf_delta_null) because PC D3D12 FirstElement cannot express the sub-buffer byte delta, while buffer_view wrote the exact UMA V# into the console descriptor slot. dev_create_uav_x did not have the matching buf_delta_null guard:

  • Passing a buffer_delta != 0 buffer (or counter buffer) to CreateUnorderedAccessView on PC created a PC UAV referencing the shifted PC resource (at the wrong element offset, or failing PC validation when the buffer size + delta did not align with StructureByteStride / NumElements), and published the non-zero resource pointer into the console slot.
  • In addition, null_uav_desc fell through for D3D12_UAV_DIMENSION_BUFFER (1) to D3D12_UAV_DIMENSION_TEXTURE2D, which did not preserve buffer dimension for null buffer UAVs.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Add an explicit D3D12_UAV_DIMENSION_BUFFER (1) arm to null_uav_desc returning a valid null buffer UAV descriptor (DXGI_FORMAT_R32_UINT, D3D12_UAV_DIMENSION_BUFFER).
    • Mirror dev_create_srv_x's buf_delta_null handling in dev_create_uav_x when ViewDimension == D3D12_UAV_DIMENSION_BUFFER and either res or counter has buffer_delta(...) != 0: create a valid null PC buffer UAV in slot.pc_uav and publish 0 (while buffer_view continues to write the exact UMA V# into the console descriptor slot).
    • Add unit + child-isolated WARP debug-layer tests in uav_buffer_delta_tests (null_uav_desc_preserves_buffer_dimension and dev_create_uav_x_buffer_delta_uses_null_pc_uav_and_writes_uma_vsharp).

Tested

  • Host: Windows 11 Pro (build 26200), AMD Ryzen 9 9950X, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9 (1.9.2609).
  • Pre-fix check: both new tests failed before the fix (null_uav_desc returned TEXTURE2D; dev_create_uav_x published the non-zero PC resource pointer instead of 0).
  • Post-fix targeted tests (cargo test -p xcl --lib -- hle::d3d12x::real::uav_buffer_delta_tests::): 2 passed, 0 failed (0.17s, D3D12 debug layer enabled, 0 debug-layer errors, exact UMA V# verified).
  • Full workspace (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: with XCL_DXC_DIR set to DXC 1.9): 2601 passed, 0 failed, 49 ignored, 9 filtered (160.8s).
  • Explicit GPU SKIPPED lines in workspace run (26 total): 21 no wave64 (RTX 5070 Ti is wave32), 3 wave32 per-lane #1426 (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), 2 no heap windows (default XCL_HEAP_WINDOWS off).
  • Release build (cargo build --release -p xcl -j 4) succeeded and passed the paired 150 s title smoke below.

Regression run

main (f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):

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

PR (5cd9be1c178887bc370f589c57b21eb7918860e5):

xcl-smoke v1
commit: 5cd9be1c178887bc370f589c57b21eb7918860e5
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1663 (PresentX 1663)
presents per 2 s (last 3): 33 31 0
device removals: 0
crashes: 0
peak commit: 32215 MB

Not tested

  • AMD or Intel GPUs (only tested on NVIDIA GeForce RTX 5070 Ti and WARP).
  • Native wave64 GPU tests (RTX 5070 Ti is wave32; 21 wave64 tests skipped).
  • uma_driver::tests:: and test_title_runs_and_game_folder_is_untouched (filtered out of the workspace test run).
  • ClearUnorderedAccessViewUint / ClearUnorderedAccessViewFloat on a buffer with a non-zero buffer_delta (tracked separately from view creation).

AI use

  • Drafted, implemented, and tested with AI assistance (Antigravity); all code changes, pre/post WARP debug-layer tests, workspace suite, and regression runs were verified locally.

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

Copy link
Copy Markdown
Contributor

Verified the translated guest buffer-store path on 5cd9be1c with an RTX 5070 (driver 616.92). In two fresh processes, the 64 lane-specific DWORDs landed at their expected addresses and all 960 surrounding or interleaved canary DWORDs kept their original address-tagged values. Both runs passed with the D3D12 debug layer enabled, once at defaults and once with XCL_DIRECT_DXIL=1.

The fixture allocated a 64 KiB-aligned block of committed coherent UMA and used the production place_at_title_address helper to place a 2 KiB guest buffer 256 bytes into it. The recorded delta was 256. Guest dev_create_uav_x created a structured view with first element 1, stride 24 and 64 records; the PC UAV resource name was zero. The test fed the guest slot's four actual V# words into a translated indexed BUFFER_STORE_DWORD and checked the first 4 KiB after fence completion. Lane i wrote at aligned block + 256 + 24 + 24*i. This checks both the placement delta and the first-element offset, including untouched bytes before the guest buffer and between records.

The dispatch used the shader test runner with the coherent window bound and the fixture supplying the four SGPRs. Guest descriptor-table loading, shifted counter resources, and the native Uint/Float clear entry points remain separate coverage questions.

AI disclosure: OpenAI Codex built and ran the fixture and drafted this report.

@Foniass

Foniass commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Review (head 5cd9be1, diff read, not a merge-check):

  • It moves the bug into the clear instead of fixing it. The PC buffer UAV of a slot is only used by ClearUnorderedAccessView. With this PR that clear goes to the PC with the slot's null view and the title's real resource (list_x::clear_uav → uav_clear_resource passes res through), which is an undefined clear. Before, it landed delta bytes low.
  • The claim that main's view fails PC validation does not hold on the real path: placed delta buffers are created with Width = delta + bytes. The new test fails before the fix only because it builds a layout that cannot happen there.

Suggested verdict: not yet.

(Review written with Claude Code, Claude Opus 5.5; both points were traced in the code.)

@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 5cd9be1c: 2 finding(s). 1 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/real.rs:3730: buf_delta_null also applies when cpu isn't a console heap slot (the return pc_uav(cpu) path), so a plain PC descriptor becomes null and no UMA V# is written anywhere to fall back on. dev_create_srv_x returns f(this, res, desc, cpu) for non-console slots before its buf_delta_null check, so this doesn't mirror the SRV fix. A delta-buffer UAV at a non-console handle (XCL-internal heap, PC-handle ClearUAV via UavClearHandles::Pc, descriptor copies) silently reads, writes or clears nothing.


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.

crate::xlog_warn!("D3D12.X: a UAV of a resource that cannot have one on the PC (a depth buffer) – a null view");
}
f(this, std::ptr::null_mut(), std::ptr::null_mut(), &null_desc, at)
} else if buf_delta_null {

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.

Once a shifted buffer's slot gets the null PC UAV, ClearUnorderedAccessViewUint/Float in list_x::clear_uav, and the CLEAR_UAV_MARKER replay in console_list.rs (~967), still pass that null descriptor to the PC together with the real resource. Clearing a UAV of a buffer placed at va & 0xFFFF != 0 (common for counters and indirect args) now sends a descriptor that doesn't match pResource. The debug layer reports an error, the buffer isn't zeroed, or a strict driver removes the device. Before this PR the clear went through a real view. These clears are listed under Not tested.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing: conflicts in real.rs, overlaps #3547 (#1607 D267), and review flagged undefined ClearUnorderedAccessView behaviour.

@Kalmarv Kalmarv closed this Dec 2, 2026
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 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants