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

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3297 into main
Kalmarv commented 2026-11-29 06:23:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T06:23:00Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5548235212 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T06:23:00Z. --- 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.
andrewDoing commented 2026-11-29 06:41:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T06:41:10Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7252005720 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297#issuecomment-7252005720). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T06:41:10Z. --- 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 commented 2026-11-29 14:58:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:58:50Z.


Review (head 5cd9be1c, 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.)

<!-- greyfinch-sync:ivall/xcl:comment:7257724808 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297#issuecomment-7257724808). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T14:58:50Z. --- Review (head 5cd9be1c, 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 commented 2026-12-01 21:42:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:42:13Z.

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

@@ -3708,6 +3721,8 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void,
                 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 {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4761413027 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297#discussion_r4761413027). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T21:42:13Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3724 ~~~~diff @@ -3708,6 +3721,8 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void, 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 { ~~~~ --- 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.
bmjask commented 2026-12-01 21:42:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:42:13Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6140669904 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297#pullrequestreview-6140669904). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T21:42:13Z. **Review:** COMMENTED --- 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._
Kalmarv commented 2026-12-02 19:39:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:01Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7356507074 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3297#issuecomment-7356507074). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T19:39:01Z. --- Closing: conflicts in `real.rs`, overlaps #3547 (#1607 D267), and review flagged undefined `ClearUnorderedAccessView` behaviour.

Pull request closed

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!3297
No description provided.