Skip to content

D3D12.X: align promoted UAV clear values, key UAV support by adapter LUID, and use device-aware footprints fallback - #2280

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1991-device-x-clear-uav-cache
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1991-device-x-clear-uav-cache

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it

Follow-up to #1988 and #1991 fixing three D3D12.X resource-creation and format-support bugs in crates/xcl/src/hle/d3d12x/device_x.rs and crates/xcl/src/hle/d3d12x/real.rs:

  1. Align optimized clear-value formats on promoted B5G6R5 / B8G8R8X8 RT+UAV textures (pc_clear_format / pc_clear_for_desc): D3D12.X: global shader-visible sampler heap, typed UAV validation, and occlusion/query VA fixes #1991 promoted B5G6R5_UNORM (85) + ALLOW_UNORDERED_ACCESS to R8G8B8A8_UNORM (28) and B8G8R8X8_UNORM (88) + ALLOW_UNORDERED_ACCESS to B8G8R8A8_UNORM (87) in pc_resource_desc, but resource creation still ran clear through pc_clear (leaving clear.Format at 85/88), causing D3D12 CreateCommittedResource/CreatePlacedResource to fail with E_INVALIDARG. Add pc_clear_format(pc_format, clear_format) and pc_clear_for_desc(clear, pc_format, buf) aligning (28, 85) => 28 and (87, 88) => 87 (while preserving native 85/88 on render-target-only resources without UAV), and wire it across create_placed_resource_x, dev_create_committed_resource_x, dev_create_placed_resource_x fallback, and own_memory_if_larger_on_the_pc.
  2. Eliminate pointer-ABA stale adapter cache in device_format_supports_uav: UAV_FORMAT_SUPPORT previously keyed by raw device as usize pointer and was never evicted on device release; reusing a freed device address on a different adapter returned stale UAV support. Key UAV_FORMAT_SUPPORT by ((luid.LowPart, luid.HighPart), format) via ID3D12Device::GetAdapterLuid() (matching TYPED_UAV_SUPPORT).
  3. Use device-aware fallback in get_copyable_footprints_x: When GetCopyableFootprints returns UINT64_MAX, retry with pc_resource_desc_for_device(this, &x) instead of pc_resource_desc(&x) (matching get_resource_allocation_info_x and create_placed_resource_x), so device-unsupported ALLOW_UNORDERED_ACCESS flags are stripped on retry.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 (8 GB, 32-lane waves, driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0, DXC 1.9.2609.5 (01b62ad4), release build.
  • Failing-first verification before the fixes: running the three new pure-CPU unit tests against pre-fix behavior failed all three (0 passed, 3 failed: pc_clear_for_desc_aligns_promoted_uav_targets_only saw 85 instead of 28, device_format_supports_uav_keys_cache_by_adapter_luid hit the stale pointer-keyed cache on pointer reuse across adapter LUIDs, and get_copyable_footprints_x_strips_device_unsupported_uav_on_retry left ALLOW_UNORDERED_ACCESS set on retry).
  • Targeted unit tests (cargo test -j 4 -p xcl --lib hle::d3d12x::device_x::tests -- --nocapture and cargo test --release -p xcl --lib hle::d3d12x::device_x::tests -- --nocapture): 14 passed, 0 failed, 0 ignored (0.21 s; all 10 existing device_x tests + 4 new tests: pc_clear_for_desc_aligns_promoted_uav_targets_only, gpu_promoted_uav_clear_values_pass_create_committed_resource verifying live RTX 4060 CreateCommittedResource fails with pc_clear and succeeds with pc_clear_for_desc for both 85->28 and 88->87 RT+UAV textures, device_format_supports_uav_keys_cache_by_adapter_luid, and get_copyable_footprints_x_strips_device_unsupported_uav_on_retry).
  • Full workspace release build and test suite (cargo build --release --workspace and cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture): 23 test binaries, 1254 passed, 0 failed, 46 ignored, plus 27 runtime SKIPPED lines (20 no wave64 on RTX 4060, 3 wave32 per-lane form refused by driver, 2 missing d3d12SDKLayers.dll / D3D12 debug layer, 1 driver shader cache toggle unavailable, 1 no heap windows).

Regression run

Baseline (origin/main 1a0bbe3a):

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1601 (PresentX 1601)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14459 MB

PR head (7fa87890):

xcl-smoke v1
commit: 7fa8789091281de67c1940fdf04e8f53e5cfe5ed
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14455 MB

Not tested

  • AMD and Intel GPUs, native wave64 hardware, the 27 runtime-skipped GPU/driver tests, and the 46 #[ignore] tests on this machine.
  • Multi-adapter live hardware switching in a single retail title process (pointer-ABA LUID caching is verified via deterministic fake-COM unit test; single-adapter RTX 4060 CreateCommittedResource and 60 s title smoke ran live).

AI use

Implemented and verified with Google Antigravity (Gemini 4 Neon). All code changes, failing-first and post-fix unit tests, full workspace release tests, and paired 60 s RTX 4060 smoke runs were reviewed and executed locally.

…LUID, and use device-aware footprints fallback

Follow-up to xcl-dev#1988 and xcl-dev#1991 fixing three D3D12.X resource/format bugs in
`crates/xcl/src/hle/d3d12x/device_x.rs` and `crates/xcl/src/hle/d3d12x/real.rs`:

1. Clear-value format mismatch on promoted B5G6R5 / B8G8R8X8 RT+UAV textures:
   xcl-dev#1991 promoted B5G6R5_UNORM (85) + UAV -> R8G8B8A8_UNORM (28) and
   B8G8R8X8_UNORM (88) + UAV -> B8G8R8A8_UNORM (87) in `pc_resource_desc`,
   but resource creation still mapped `clear.Format` via `pc_clear` (leaving
   85/88 unchanged), causing D3D12 `CreateCommittedResource`/`CreatePlacedResource`
   to fail with `E_INVALIDARG`. Add `pc_clear_format` / `pc_clear_for_desc` to
   align `(28, 85) => 28` and `(87, 88) => 87` (preserving native 85/88 on
   RT-only textures without UAV) across `create_placed_resource_x`,
   `dev_create_committed_resource_x`, `dev_create_placed_resource_x` fallback,
   and `own_memory_if_larger_on_the_pc`.
2. Pointer-ABA stale cache in `device_format_supports_uav`:
   `UAV_FORMAT_SUPPORT` keyed by raw `device as usize` pointer without eviction
   on release; reusing a freed device address on another adapter returned stale
   UAV support. Key `UAV_FORMAT_SUPPORT` by `((luid.LowPart, luid.HighPart), format)`
   via `ID3D12Device::GetAdapterLuid()` (matching `TYPED_UAV_SUPPORT`).
3. Device-unaware retry in `get_copyable_footprints_x`:
   Retry used `pc_resource_desc(&x)` instead of `pc_resource_desc_for_device(this, &x)`,
   leaving device-unsupported `ALLOW_UNORDERED_ACCESS` intact so
   `GetCopyableFootprints` still returned `UINT64_MAX`. Switch to
   `pc_resource_desc_for_device(this, &x)`.

Assisted-by: Google Antigravity (Gemini 4 Neon)
@DarkPanda69

Copy link
Copy Markdown

AMD run (listed as untested), on a machine with two GPUs (RX 9070 XT + RTX 3060), each picked with XCL_ADAPTER: the new test passes on both.

Head 7fa8789 applied on main 1a0bbe3, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4:

Each run used one adapter, so this covers the LUID-keyed UAV support per device on two different vendors, but not switching adapters inside one process.
Not tested: a title, Intel.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@Lum7nt

Lum7nt commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Independent Windows release test on clean head 7fa8789091281de67c1940fdf04e8f53e5cfe5ed: Windows 11 build 26300, Rust 1.100.0 MSVC; this machine has an RX 9070 XT (driver 32.0.32029.2010).

cargo test --offline --locked --release -p xcl --lib hle::d3d12x::device_x::tests -- --nocapture --test-threads=1

Result: 14 passed, 0 failed, 0 ignored; no SKIPPED messages, including gpu_promoted_uav_clear_values_pass_create_committed_resource. The latter uses D3D12CreateDevice(None, ...) and can fall back to WARP; this run did not log the actual device identity, so I cannot independently confirm the adapter used by that test.

Not tested: full workspace, retail title, paired smoke runs, or live switching between multiple adapters.

AI use: OpenAI Codex (GPT-6; exact variant unavailable) ran the tests and drafted this report.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Test report: AMD Radeon RX 7800 XT (RDNA3, native wave64) for head 7fa8789091281de67c1940fdf04e8f53e5cfe5ed.

Setup: RX 7800 XT, driver 32.0.31035.1003, Windows 11 Pro 10.0.26200, rustc/cargo 1.100.0, debug build, DXC 1.9.0.5512 (dxc on PATH). Detached checkout of the PR head, which includes ea088a5. I did not merge it with current main. I read the diff (device_x.rs, real.rs) before running it.

Targeted (cargo test -p xcl --lib -- uav --nocapture --test-threads=1): 15 passed, 0 failed, 0 ignored. The filter also matches existing UAV tests. The PR's four new tests all passed and none printed SKIPPED:

  • device_x::tests::pc_clear_for_desc_aligns_promoted_uav_targets_only
  • device_x::tests::gpu_promoted_uav_clear_values_pass_create_committed_resource (the GPU test, which ran here)
  • device_x::tests::device_format_supports_uav_keys_cache_by_adapter_luid
  • device_x::tests::get_copyable_footprints_x_strips_device_unsupported_uav_on_retry

Full suite (cargo test --workspace --no-fail-fast -- --test-threads=4): 1253 passed, 1 failed, 46 ignored.

  • The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, the known RDNA3 failure on main. The PR does not touch it.
  • 7 SKIPPED lines: 6 in lower_dxil::tests (f16 / f32 conversion programs refused) and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows). These are not coverage.

Not tested: retail title or scripts/smoke.ps1 (this is a runtime change, so real-title UAV clear and footprint behaviour is unchecked), NVIDIA, Intel (the LUID-keyed support cache is only exercised through a fake device here), Wine/vkd3d, this PR merged with current main.

AI use: this report was run and written by Claude Code (Claude Sonnet 5.5). I read the diff but did not change any code.

@nnonno91

Copy link
Copy Markdown

Independent Windows test of 7fa8789091281de67c1940fdf04e8f53e5cfe5ed. Real D3D12 texture creation behaved as expected on both adapters.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile.
  • Ran gpu_promoted_uav_clear_values_pass_create_committed_resource with explicit adapter selection added to the local fixture. The log identified Radeon integrated graphics and RTX 5090 in their respective runs. Each run reported 1 passed, 0 failed, 0 ignored, and no logged skips. For both B5G6R5 and B8G8R8X8, D3D12 rejected the old mismatched clear format and accepted the corrected format.
  • Also ran pc_clear_for_desc_aligns_promoted_uav_targets_only, device_format_supports_uav_keys_cache_by_adapter_luid, and get_copyable_footprints_x_strips_device_unsupported_uav_on_retry unchanged. Each reported 1 passed, 0 failed, 0 ignored, and no logged skips.

Not tested

Texture pixel readback, the parent revision, retail titles, or the full workspace suite. The adapter-selection change was temporary.

AI use

OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants