D3D12.X: read back the swap chain buffer for the frame dump and guard readback_copy #2703
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2713"
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?
Imported from ivall/xcl. Originally posted by itsSio on 2026-11-26T08:05:49Z.
With
XCL_FRAME_DUMPset and no composited present, the frame dump read back the title's ownsrcwith a texture copy recorded at present time. XCL does not know which state the title keepssrcin, andreadback_copyrecorded the copy for any resource, buffers included. The dump now reads back the swap chain buffer XCL has just copied into (COPY_DEST -> COPY_SOURCE -> PRESENT), as the composited path already does from RENDER_TARGET, andreadback_copyrefuses what it cannot copy to a buffer: anything other than a single-sample 2D texture with a size and a footprint format, or a failedGetCopyableFootprints. Part of #499 (observation 2).What is in it
D3D12.X: read back the swap chain buffer for the frame dump and guard readback_copy(6d29dc26):crates/xcl/src/hle/d3d12x/present.rs(dump_backbufferused by both present paths;readback_possiblechecked inreadback_copy; a unit test of the checks and a GPU test on WARP that dumps a filled swap chain buffer and refuses a buffer, usingManuallyDrop::new(Some(bb.clone()))/up.clone()to avoid a COM double-Releaseon test teardown)Tested
Commit
6d29dc265b2a2cd5508b31b0da53c4ecb8e9566b, clean checkouts on each PC, debug builds for workspace tests and release builds for--releasepresent::checks and retail smoke runs.32.0.16.1088), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro build 26200, Rust 1.97.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5 (XCL_ADAPTER=NVIDIA).cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=1(×3) and-- --test-threads=4(×3): 11 passed, 0 failed on all 6 runs (exit 0).cargo build --workspace: exit 0.cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1431 passed, 0 failed, 47 ignored.SKIPPEDGPU tests: wave64 tests (no wave64 on this adapter), f16 / f16-conversion wave32 refusals (#1426),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows),pso_measurement_compiles_an_exact_synthetic_record(driver cache, Developer Mode).XCL_FRAME_DUMP=1+XCL_PRESS_A_AT=15,25,35,45,55check (release, RTX 5080, on identical runtime codeb25ae0cfvsmain08db8020): both captured genuine non-black BMPs (max=249,mean=36.6,99.8%non-dark;3258vs3306frames) with0crashes,0device removals, and0nvwgf2umx.dllfaults.32.0.16.1088), AMD Ryzen 5 5600X, 16 GB RAM, Windows 11 Pro build 26200, Rust 1.99.1 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100 DXC 1.8.2502.11 (XCL_ADAPTER=NVIDIA).cargo test --release -p xcl --lib hle::d3d12x::present::(×3--test-threads=1, ×3--test-threads=4): 11 passed, 0 failed on all 6 runs (exit 0).cargo build --workspace: exit 0.cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1431 passed, 0 failed, 47 ignored.SKIPPED: the same 26 as PC 1 plus 3 requiringd3d12SDKLayers.dll.present.rsGPU tests run on WARP.Regression run
main(b49be183, RTX 5080, release):PR (
6d29dc26, RTX 5080, release,XCL_FRAME_DUMP=1):Not tested
nvwgf2umx.dllcrash onmain(did not reproduce on RTX 5080 onmain08db8020).scripts/smoke.ps1on the RTX 2080 SUPER.AI use
Ran via Samaritan:
Releaseteardown bug in6d29dc26, independently reviewed the fix, ran the dual-PC workspace suites, 6×--releasepresent::checks, and the fresh RTX 50806d29dc26smoke run, and contributed earlier frame-dump verification.scripts/pr_check.py --local, updated this PR description, and pushed6d29dc26.Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-26T10:01:18Z.
Independent AMD RDNA4 (native wave64) verification of exact PR head
b25ae0cf3816b2538742645b755ea8cf967976fdon Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC1.9.2602.17).Tested
cargo build --workspace(debug): passed (0errors).cargo test --workspace --no-fail-fast -- --test-threads=4:1429 passed, 2 failed, 47 ignored(8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1heap_window_out_of_memory_falls_back_to_the_switch_formno heap windows, 1pso_measurement_compiles_an_exact_synthetic_recordWindows Developer Mode off).hle::d3d12x::present::frame_dump_tests::frame_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_bufferhle::d3d12x::present::frame_dump_tests::readback_needs_a_single_sample_2d_texture_with_a_footprintgpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1andfuzz_validate_and_gpu_3) are pre-existing on unmodifiedmainon this RX 9060 XT / driver32.0.31044.16.cargo build --release -p xcl+ 60 s retail-title smoke test (scripts/smoke.ps1, offline):(Compare against
mainb49be183on this machine:1603 frames, 18576 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T10:24:35Z.
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2713 at
b25ae0cf3816b2538742645b755ea8cf967976fd(parent08db8020d323bf478964fcc586152cce54959cfc,MERGEABLEagainstorigin/mainb49be183).Result:
STATUS_ACCESS_VIOLATION(0xc0000005) in the new test — COM double-Releaseon teardownRunning
hle::d3d12x::present::in--releaseon Windows 1126200(rustc 1.100.0, NVIDIA GeForce RTX 4060 8 GB, driver32.0.16.2114) hit0xc0000005(STATUS_ACCESS_VIOLATION) inside the new testframe_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer(both under--test-threads=4and deterministically isolated by--test-threads=1), while unmodifiedorigin/main(b49be183) passed 3/3 times cleanly.Reproduction on
b25ae0cfvsorigin/main(b49be183)origin/main(b49be183)cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=4: 9 passed, 0 failed, 0 ignored × 3 consecutive runs (0.03 s,0.03 s,0.02 s, exit0).#2713(b25ae0cf):cargo test --release -p xcl --lib readback_needs_a_single_sample_2d_texture_with_a_footprint -- --nocapture: 1 passed, 0 failed (0.00 s, exit0).cargo test --release -p xcl --lib frame_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer -- --nocapture: 1 passed, 0 failed (0.02 s, exit0when run standalone).cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=4: crashed 1/4 runs withexit code: 0xc0000005, STATUS_ACCESS_VIOLATION(the other 10 tests printed... ok, leaving onlyframe_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_bufferunfinished; the other 3/4 passes exited0,11/0/0).cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=1: crashed withexit code: 0xc0000005, STATUS_ACCESS_VIOLATIONdirectly onframe_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer:Root cause in
crates/xcl/src/hle/d3d12x/present.rs(b25ae0cf)In
frame_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer:1809–1815constructdst.pResourceandsrc.pResourcewithstd::mem::transmute_copy(&bb)andstd::mem::transmute_copy(&up), which copies the COM interface pointer without callingAddRef.1848–1849then call: which immediately drops both un-AddRef'd wrappers and invokesIUnknown::Release()onbbandup(updrops1 -> 0and is freed;bbdrops2 -> 1, thendumpsdrops1 -> 0freeingbb).1851),upandbbdrop a second time, callingIUnknown::Release()on freed WARPID3D12Resourceobjects -> heap-dependent UAF /STATUS_ACCESS_VIOLATION(which explains why isolated or single-run test invocations can occasionally slip through before the freed slot is reused).(Note: production code in
present_nowlines1150/1155usesManuallyDrop::new(Some(bb.clone()))/src.clone()beforeManuallyDrop::into_inner, andreadback_copylines1333–1335usestransmute_copywithout callingManuallyDrop::into_inner, so this COM double-Releaseis isolated to the new test.)Suggested fix (2 lines in the new test)
Either match
present_nowby calling.clone():or delete lines
1848–1849(let _ = ManuallyDrop::into_inner(...)) so the borrowedtransmute_copywrappers stayManuallyDropand are not released.Limits of coverage
b25ae0cfoncehle::d3d12x::present::crashed with0xc0000005; happy to re-verify unit tests + paired 60 s RTX 4060 smoke once the test teardown is fixed.AI use
Ran the release unit test reproductions and root-cause inspection with assistance from Google Antigravity (Gemini 4 Neon); all test results and exit codes were taken directly from
cargo testoutput.Imported from ivall/xcl. Originally posted by itsSio on 2026-11-26T12:08:20Z.
Thanks for catching the
--release0xc0000005teardown crash @Decodere — confirmed the test-only COM double-Releasefromstd::mem::transmute_copy+ManuallyDrop::into_innerinframe_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer.Pushed squashed commit
6d29dc265b2a2cd5508b31b0da53c4ecb8e9566breplacing bothtransmute_copycalls withManuallyDrop::new(Some(bb.clone()))/ManuallyDrop::new(Some(up.clone()))and updated the PR description with fresh dual-PC results and a6d29dc26RTX 5080 smoke block:32.0.16.1088, Ryzen 7 9800X3D, Win11 26200,rustc 1.97.0, DXC1.9.2609.5):cargo test --release -p xcl --lib hle::d3d12x::present::passed11/0across 6 runs (--test-threads=1×3,--test-threads=4×3); full workspace1431/0/47(26 SKIPPED); 60 sXCL_FRAME_DUMP=1smoke1663frames,0removals/crashes.32.0.16.1088, Ryzen 5 5600X, Win11 26200,rustc 1.99.1, WinSDK DXC1.8.2502.11):cargo test --release -p xcl --lib hle::d3d12x::present::passed11/0across 6 runs (--test-threads=1×3,--test-threads=4×3); full workspace1431/0/47(29 SKIPPED).AI use
Ran via Samaritan:
6d29dc26and ran the dual-PC release, workspace, and smoke checks.pr_check.py, pushed6d29dc26, and posted this update.Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T12:49:52Z.
Re-verification of PR #2713 at
6d29dc265b2a2cd5508b31b0da53c4ecb8e9566b(RTX 4060 8 GB / Windows 11,--release) (parent08db8020d323bf478964fcc586152cce54959cfc,MERGEABLEagainstorigin/mainb49be183).Result:
--release0xc0000005teardown crash is fixedRe-tested the exact commands that previously hit
0xc0000005(STATUS_ACCESS_VIOLATION) onb25ae0cf(both--test-threads=1and--test-threads=4), plus a quiet 60 s retail smoke:Setup
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)title: 29640639viascripts/smoke.ps1 -Seconds 60(XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)Targeted Win11 / RTX 4060 release unit tests (
6d29dc26)cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=1(3 consecutive runs): 11 passed, 0 failed, 0 ignored × 3 (0.05 s,0.05 s,0.05 s,0skipped, exit0).cargo test --release -p xcl --lib hle::d3d12x::present:: -- --test-threads=4(3 consecutive runs): 11 passed, 0 failed, 0 ignored × 3 (0.03 s,0.03 s,0.03 s,0skipped, exit0).Paired 60 s RTX 4060 smoke (
b49be183vs6d29dc26)Reference
origin/main(b49be183):PR #2713 head (
6d29dc26):Limits of coverage
6d29dc26(only 6 repeated--releasepasses ofhle::d3d12x::present::plus paired quiet 60 s default-flags smoke).XCL_FRAME_DUMP=1BMP export during the retail smoke was not enabled; swap-chain backbuffer readback and buffer refusal are covered by the WARP D3D12 unit testframe_dump_reads_the_swap_chain_buffer_after_its_copy_and_refuses_a_buffer.26200) / discrete RTX 4060 only; no AMD, Intel, or Wine/Linux run on this host.AI use
Ran the repeated release unit test passes and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from
cargo testandscripts/smoke.ps1outputs.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:34:26Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:47:13Z.
Triage (#1607) – head
6d29dc2Main still reads back the title's
srcin the uncomposited present path (present.rs,readback_copy(&p.list, src, desc)), andreadback_copyhas no guard. No open or merged PR moves the dump to the swap chain buffer or addsreadback_possible.dump_backbufferleavesbbin PRESENT on both paths, as the old barriers did. No problems found in the diff. The PR conflicts with main's newerpresent.rsand needs a rebase.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.