D3D12.X: discard newly backed placed and reserved targets (#940) #1342
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1342
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1342"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@eizispark on GitHub · 2026-11-24 15:00 UTC · original
eizispark:fix/940-discard-fresh-targets→main· +217 −24 · 1 files · 1 commits · openD3D12 resources created with
CreatePlacedResourceorCreateReservedResourceandALLOW_RENDER_TARGETorALLOW_DEPTH_STENCILstart uninitialized; transitioning or using them before aDiscardResource,Clear*View, orCopy*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 sidle memory at the same title address (vram::Arenasreusing an arena orvram::Pagessharing 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 afreshflag fromArenas::take(true only when a new arena heap is created) andPages::bind(true only when none of the target's tiles reused an existingpagesorextra_pagesentry). When a freshly backed placement carriesALLOW_DEPTH_STENCILorALLOW_RENDER_TARGET, synchronously submitDiscardResourceon a per-device internal direct queue insidetitle_textures::own_work(after waiting on thePagestile-mapping fence for reserved placements), transitioning toDEPTH_WRITEorRENDER_TARGETand restoring the initial state beforeplacereturns.crates/xcl/src/hle/d3d12x/vram.rs(tests): addfresh_targets_need_discard_once_and_aliased_arenas_do_not(unit test forArenas::takefreshness across live,< 2 sidle, and swept arenas plusdiscard_target_state) andfresh_placed_and_reserved_targets_discard_without_wiping_aliases(GPU test verifying fresh arenaD32S8and fresh reservedR8G8B8A8_UNORMtargets 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
32.0.32015.16001),rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release.cargo test --workspace --no-fail-fast -- --test-threads=4on the head, rebased ontomain426a5a7: 1242 passed, 3 failed –gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3andgpu::recomp::tests::gpu_image_get_resinfo_past_last_level, which fail the same way on a cleanmain426a5a7on this adapter; 46 ignored.cargo test -p xcl --lib hle::d3d12x::vram -- --test-threads=4, 3 consecutive runs: 17 passed, 0 failed, 1 ignored on each run.fresh_placed_and_reserved_targets_discard_without_wiping_aliasesfailed beforediscard_freshwas wired in:discards()stayed 0.Regression run
main:PR head:
Not tested
XCL_SAMPLE_*sample-data tests.AI use
main426a5a7(keptcanonical_vanext to the discard helpers and updated the new arena tests to the 4-fieldArenas::takeresult), and reran the suite and the smoke pair.@futurepro62 on GitHub · 2026-11-24 15:08 UTC · original
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 base930e8b4).Tested
cargo build --workspace, thenXCL_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.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.[0.25, 0.5, 0.75, 1.0]asR8G8B8A8_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.fresh_targets_need_discard_once_and_aliased_arenas_do_not.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
AI use
@JoaoPauluu on GitHub · 2026-11-24 15:28 UTC · original
A regression run under Wine on Linux, on a retail title.
Tested
x86_64-pc-windows-gnu.39c1824as it is andmain930e8b4, no uncommitted changes. Retail title 1.0.2.1,scripts/linux/smoke.sh(#257) for 60 s, no input. Nine runs in a row,mainfirst and last, other PRs in between.Regression run
main (first run):
this PR:
The last
mainrun: 1338 frames,exit: 0x0, no device removal, no crash. Under Wine,peak commitreads 0 MB, so these blocks do not check memory.Not tested
AI use
@Mischief8713 on GitHub · 2026-11-24 15:55 UTC · original
GPU run of
39c1824on Windows (NVIDIA GTX 1660 Ti, Turing):fresh_placed_and_reserved_targets_discard_without_wiping_aliasesfails with 127 where 128 is expectedTested
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64)mainat930e8b4on the same machine: lib 707 passed, 0 failed, 21 ignored;e2e3 passedmain(930e8b4).hle::d3d12x::vram::tests::fresh_placed_and_reserved_targets_discard_without_wiping_aliasesatvram.rs:1222: left[64, 127, 191, 255], right[64, 128, 191, 255].[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
scripts/smoke.ps1run, so no regression runAI use
@eizispark on GitHub · 2026-11-24 15:57 UTC · original
Thanks @futurepro62 for running with the D3D12 debug layer enabled and catching the
0.5 * 255 = 127.5halfway 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_aliasesto clear theR8G8B8A8_UNORMtarget to[0.2, 0.4, 0.6, 1.0]([51, 102, 153, 255], exact integers on every adapter), rebased ontomainasebdbae3, and refreshed the PR description with new workspace test and 60 sxcl-smokeresults onebdbae3.AI use: Antigravity (Gemini 4 Carbon)
@DavidM1911 on GitHub · 2026-11-24 16:11 UTC · original
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 on GitHub · 2026-11-24 16:51 UTC · original
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.XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored.XCL_ADAPTER=radeon, same command: 753 passed, 0 failed, 41 ignored, nothing skipped.fresh_placed_and_reserved_targets_discard_without_wiping_aliasesisokon both. Last time it failed on both with[64, 127, 191, 255].AI use
@jessenic on GitHub · 2026-11-25 09:05 UTC · original
Test report: on a retail title with the D3D12 debug layer, this PR removes the id 1422 errors (render and depth targets used before they are initialised). The title still ends at the same later device removal, which is not this PR's.
Setup: RTX 5070 Ti 16 GB (driver 610.88), Ryzen 7 9700X, 32 GB, Windows 11 Pro 26300, rustc 1.97.0, release. Retail title, Series S profile (
device_type = "lockhart"), story load with scripted A presses,XCL_D3D12_DEBUG=1.Tree: a local integration branch on
main8f5fca5with #1323, #1143, #1221, #765, #1405, #1464, #751, #684, #1110, #615, #1315/#1316, #495, #1993, #2009, #929, #1291 and a local port of #640. This PR'sbb12dd7was cherry-picked on top as70e76ee. The only conflict was with the #640 port inplace_on_pages(vram.rs): #640's two newTargetfields were kept, and so were this PR'sfresh/after_mapand its return value.0x887a0005after the intro's title card0x887a0005at the same point (#101+ 7–9 s)cargo test -p xcl --lib -- vramon this tree: 18 passed, 1 failed, 1 ignored with--test-threads=1. The failure is #640'spage_budget_one_placement_at_the_cap_evicts_one_batch(33 evictions instead of 32). It fails only when this PR'sfresh_placed_and_reserved_targets_discard_without_wiping_aliasesruns before it on the same device. It passes alone (3 of 3), and with this PR's GPU test skipped the rest pass 16/0/1. So the two PRs' tests share state on the device; it matters only if both are merged.Not tested:
mainalone; AMD; Series X; more than two runs with the PR; not ascripts/smoke.ps1regression run.AI use: Claude Code (Claude Opus 5.5) resolved the cherry-pick, ran the runs and tests on the machine above and wrote this report.
@eizispark on GitHub · 2026-11-25 11:45 UTC · original
Rebased onto
main426a5a7as4573144. Thanks @jessenic for the debug-layer run; that covers the retail check I couldn't do on this host.mainhad addedcanonical_va(mirror aliasing) in the same spot asdiscard_fresh, and both are kept.canonical_varuns beforeArenas::take/Pages::bind, so a GPU mirror view that lands on an existing arena or page counts as an alias, not as a fresh placement, and is not discarded. The new arena tests from #1990 /5a515f0were updated to the 4-fieldtake()result.On the RX 9070 XT:
vram, 3 runs × 17 passed. Full workspace: 1242 passed; the 3 failures also fail on a cleanmain426a5a7here. New smoke pair in the description: 1680 frames on main, 1677 on the PR, no removals or crashes.@DavidM1911 on GitHub · 2026-11-26 04:53 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.