Skip to content

D3D12.X: discard newly backed placed and reserved targets (#940) - #1342

Open
eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/940-discard-fresh-targets
Open

eizispark wants to merge 1 commit into
xcl-dev:mainfrom
eizispark:fix/940-discard-fresh-targets

Conversation

@eizispark

@eizispark eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

D3D12 resources created with CreatePlacedResource or CreateReservedResource and ALLOW_RENDER_TARGET or ALLOW_DEPTH_STENCIL start uninitialized; transitioning or using them before a DiscardResource, Clear*View, or Copy* triggers debug-layer error 1422 (RENDER_TARGET_OR_DEPTH_STENCIL_RESOURCENOTINITIALIZED, #940) and leaves target compression metadata uninitialized. Placements that alias existing live or < 2 s idle memory at the same title address (vram::Arenas reusing an arena or vram::Pages sharing any existing 64 KiB page) must keep earlier GPU writes intact and must not be discarded.

Part of #940 (handles message 1422 on newly backed placed and reserved render targets and depth-stencil buffers; messages 538 and 824 remain separate).

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: return a fresh flag from Arenas::take (true only when a new arena heap is created) and Pages::bind (true only when none of the target's tiles reused an existing pages or extra_pages entry). When a freshly backed placement carries ALLOW_DEPTH_STENCIL or ALLOW_RENDER_TARGET, synchronously submit DiscardResource on a per-device internal direct queue inside title_textures::own_work (after waiting on the Pages tile-mapping fence for reserved placements), transitioning to DEPTH_WRITE or RENDER_TARGET and restoring the initial state before place returns.
  • crates/xcl/src/hle/d3d12x/vram.rs (tests): add fresh_targets_need_discard_once_and_aliased_arenas_do_not (unit test for Arenas::take freshness across live, < 2 s idle, and swept arenas plus discard_target_state) and fresh_placed_and_reserved_targets_discard_without_wiping_aliases (GPU test verifying fresh arena D32S8 and fresh reserved R8G8B8A8_UNORM targets discard once, preserve non-target initial states across the discard, and do not discard or overwrite pixels when aliased at the same title address).

Tested

  • Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (driver 32.0.32015.16001), rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 961 passed, 0 failed, 43 ignored, 8 SKIPPED lines (6 per-lane f16 subcases in gpu::recomp::lower_dxil::tests::{f16_programs_on_the_gpu, f32_programs_on_the_gpu}, shaders::tests::pso_measurement_compiles_an_exact_synthetic_record requiring Windows Developer Mode, and heap_window_out_of_memory_falls_back_to_the_switch_form; the 2 optional d3d12SDKLayers.dll tests return early because Windows Graphics Tools is not installed on this host).
  • cargo test -p xcl --lib hle::d3d12x::vram -- --test-threads=4 and cargo test -p xcl --lib hle::d3d12x::vram -- --test-threads=1: fresh_placed_and_reserved_targets_discard_without_wiping_aliases failed before wiring discard_fresh (discards() stayed 0); 12 passed, 0 failed, 1 ignored after wiring it.

Regression run

main:

xcl-smoke v1
commit: 4e3515eed124b9f4779f5ef4e2b54adf97da936a
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1676 (PresentX 1676)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14731 MB

PR head:

xcl-smoke v1
commit: bb12dd71c686ca39c8c4fdcc07b4dd0facf87b43
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1670 (PresentX 1670)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14865 MB

Not tested

  • Live D3D12 debug-layer (d3d12SDKLayers.dll) message count check on a retail run on this host (Windows Graphics Tools is not installed locally).
  • Intel GPUs, Windows 10, wave32-only adapters, and XCL_SAMPLE_* sample-data tests.

AI use

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet: the new test fails on both GPUs here, on its expected clear colour. Tested exact head 39c1824 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 708 passed, 1 failed, 21 ignored in the xcl lib, so cargo stops before the other test binaries. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • Failed: fresh_placed_and_reserved_targets_discard_without_wiping_aliases (vram.rs:1222), 3 of 3 runs on its own too: left: [64, 127, 191, 255], right: [64, 128, 191, 255]. The other checks in that test (discard counts, the aliased depth/stencil keeping 0.375 / 0x3C) passed before it.
  • The render target is cleared to [0.25, 0.5, 0.75, 1.0] as R8G8B8A8_UNORM, and 0.5 × 255 = 127.5 is exactly halfway between two bytes. Both drivers here give 127, and D3D's float-to-UNORM conversion has a tolerance, so 128 isn't guaranteed. Clearing to a value off the halfway point (or allowing ±1 per channel) would make the check portable.
  • The new tests ran and passed: fresh_targets_need_discard_once_and_aliased_arenas_do_not.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: the same single failure with the same bytes ([64, 127, 191, 255]), 708 passed.

Not tested

  • The test binaries after the xcl lib, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux, on a retail title.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1371 (PresentX 1371)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 39c18245a55e5f3e550c7b9efe4d97d9b4755c88
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1359 (PresentX 1359)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The last main run: 1338 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head; native Windows; AMD.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@Mischief8713

Copy link
Copy Markdown

GPU run of 39c1824 on Windows (NVIDIA GTX 1660 Ti, Turing): fresh_placed_and_reserved_targets_discard_without_wiping_aliases fails with 127 where 128 is expected

Tested

  • NVIDIA GeForce GTX 1660 Ti 6 GB (Turing, driver 32.0.16.2114), Ryzen 5 2600X, Windows 11 (10.0.26300), rustc 1.100.0, debug build
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64)
  • main at 930e8b4 on the same machine: lib 707 passed, 0 failed, 21 ignored; e2e 3 passed
  • The head contains current main (930e8b4).
  • lib: 708 passed, 1 failed, 21 ignored. The failure is hle::d3d12x::vram::tests::fresh_placed_and_reserved_targets_discard_without_wiping_aliases at vram.rs:1222: left [64, 127, 191, 255], right [64, 128, 191, 255].
  • The failing check is the tiled render target cleared to [0.25, 0.5, 0.75, 1.0]. 0.5 times 255 is 127.5, an exact tie, and this driver converts it to 127. The other three channels match.

What this adds: the same 127 versus 128 is already reported on an RTX 5070 Ti and a Radeon iGPU. A third driver family on a different architecture shows it, which points at the test comparing an exact tie, not at a driver bug. A clear value that is not a tie (for example 0.502) or a tolerance of one would make the test independent of the driver's tie-breaking. I have not run that change.

Not tested

  • No retail title and no scripts/smoke.ps1 run, so no regression run
  • AMD GPUs; only Turing was run here
  • No change was tried to see whether the test passes with a non-tie clear value

AI use

  • Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.

@eizispark
eizispark force-pushed the fix/940-discard-fresh-targets branch from 39c1824 to ebdbae3 Compare November 24, 2026 15:57
@eizispark

Copy link
Copy Markdown
Author

Thanks @futurepro62 for running with the D3D12 debug layer enabled and catching the 0.5 * 255 = 127.5 halfway tie on RTX 5070 Ti and the 9800X3D RDNA2 iGPU, and thanks @JoaoPauluu for the Linux/Wine NVIDIA regression run.

Updated fresh_placed_and_reserved_targets_discard_without_wiping_aliases to clear the R8G8B8A8_UNORM target to [0.2, 0.4, 0.6, 1.0] ([51, 102, 153, 255], exact integers on every adapter), rebased onto main as ebdbae3, and refreshed the PR description with new workspace test and 60 s xcl-smoke results on ebdbae3.

AI use: Antigravity (Gemini 4 Carbon)

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@futurepro62

Copy link
Copy Markdown

Retest of the new head ebdbae3: passes on both GPUs. The new clear colour [0.2, 0.4, 0.6, 1.0] maps to exact bytes (51, 102, 153), so no channel lands on a rounding tie any more.

  • RTX 5070 Ti (driver 616.64), XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored.
  • AMD Radeon iGPU of the 9800X3D (RDNA2), XCL_ADAPTER=radeon, same command: 753 passed, 0 failed, 41 ignored, nothing skipped.
  • fresh_placed_and_reserved_targets_discard_without_wiping_aliases is ok on both. Last time it failed on both with [64, 127, 191, 255].

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this comment. I checked it before posting.

D3D12 placed and reserved resources created with ALLOW_RENDER_TARGET or
ALLOW_DEPTH_STENCIL start uninitialized; using or transitioning them
before a DiscardResource, Clear*View, or Copy* triggers debug-layer
error 1422 (RENDER_TARGET_OR_DEPTH_STENCIL_RESOURCENOTINITIALIZED) and
leaves target compression metadata uninitialized.

Track whether a placement in vram::Pages::bind or vram::Arenas::take
allocated exclusively fresh backing rather than sharing existing live or
idle pages or an existing arena. When a render-target or depth-stencil
placement is freshly backed, synchronously submit DiscardResource on an
internal direct queue (after waiting on the tile-mapping fence for
reserved placements) while preserving the resource's initial state and
leaving aliased placements untouched.

Part of xcl-dev#940.

Assisted-by: Antigravity (Google DeepMind, Gemini 4 Carbon)
@eizispark
eizispark force-pushed the fix/940-discard-fresh-targets branch from ebdbae3 to bb12dd7 Compare November 24, 2026 21:36
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.

5 participants