Repository navigation
D3D12.X: copy a GPU-written title texture back into the title's memory - #2678
joeypercia wants to merge 1 commit into
Conversation
luckyteagirl
left a comment
There was a problem hiding this comment.
Could the download retain its readback buffer, command allocator, and source until the submitted copy is known complete, including on a wait error? ExecuteCommandLists has already queued the copy when wait(dev, queue)? runs. That helper can fail creating/signaling the fence or time out after 10 seconds; the early return then drops rb and alloc while the queue may still execute the copy. A healthy but stalled queue can exceed that budget and resume later. Creating the fence before submission covers one failure point, but signal/wait failures still need a lifetime policy for in-flight objects. Microsoft's D3D12 synchronization guidance says the application tracks how long GPU work needs resources and uses fences before reuse or destruction. Exact-head source review at 033c725442f6534e9938a7c82e41c4279d445127; no live GPU timeout reproduction. AI-assisted review with Codex.
033c725 to
bbc97e2
Compare
|
Thanks, yes. When the wait fails, |
luckyteagirl
left a comment
There was a problem hiding this comment.
download() promises every D3D12 subresource, but n = MipLevels * arrays omits the native format's plane count. D3D12 counts MipLevels * ArraySize * PlaneCount (Microsoft's resource descriptor helper); the current footprint and copy loop can return Ok containing only plane 0 for a two-plane resource when states.len() == 1. With a state per real subresource, it instead rejects the valid state count. Could this query D3D12_FEATURE_FORMAT_INFO.PlaneCount and either copy all planes or explicitly reject formats with more than one plane before recording commands? A two-plane format fixture would catch a silent partial readback. I did not find a production caller for title_textures::read_back yet, so this is a helper contract issue rather than a measured retail regression.
Exact-head source review of bbc97e2584f575be83b5e07e1f4a5db51001046c; no GPU readback was run. AI-assisted review with Codex.
bbc97e2 to
077f887
Compare
|
Thanks, also right. |
|
Ran the texture read-back tests at Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
What this adds: the author tested an Ada RTX 4070 Ti and an RDNA2 iGPU; this is a Blackwell wave32 part, and no third-party report exists in the thread yet. Not tested: a title actually calling AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. Update (26/11, head moved to The GPU read-back test still runs on the real RTX 5070 Ti and passes. |
|
Tested on the Linux/Wine lane, full standard env (AMD rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT 20 GB, Arch kernel 7.2.15, Mesa 26.2.5 RADV, wine-11.0 Proton, rustc 1.94.0; |
|
Linux/RADV verification of Tested
The same three existing tests fail on both revisions: Each new test was also run alone with
Test-only diagnostic
Not tested
AI use
|
|
One API-contract edge case before this helper is reused: Could AI-assisted. |
077f887 to
a598134
Compare
|
Thanks, @thehollowedone. |
luckyteagirl
left a comment
There was a problem hiding this comment.
At head a59813423a7f10c44fd3702e7caed0c017e441ab, write_subresources takes old = title_bytes(va, len), clones it to mem, spends time retiling, then reads old again for each page diff (title_textures.rs:1506-1524). For an all-readable range, title_bytes returns a borrowed slice into title memory after a readability check (:1459-1464). If another title thread decommits/unmaps a page after that check, either the clone or the later diff read can fault before write_writable reaches its guarded WriteProcessMemory path. The new helper's comment promises that unmapped pages fail rather than fault, but this borrowed snapshot does not provide that guarantee. Could the diff baseline use an owned read_committed(va, len) snapshot (the existing page-safe copy helper) or another mapping-lifetime guard? A concurrent decommit test between snapshot and diff would cover it.
This is an exact-head source review of the helper, which is not yet called in production until the follow-up PR. I did not run a concurrent-decommit reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) traced the new readback path; I checked the borrowed title_bytes and diff loop before posting.
A title texture that the GPU writes is not copied back to the title's memory, so a title that reads it on the CPU gets stale bytes (xcl-dev#2663). The ocean of the newer retail title is such a case: its height maps are written by compute and sampled by the physics on the CPU. This adds the read-back, not yet called: - texture::download copies every subresource of a resource out to linear rows (the reverse of texture::upload). - title_textures::write_subresources tiles them into the console layout (Chain::tile_level / tile_volume) and writes the pages that change, on committed, writable pages only (the reverse of subresources). - title_textures::read_back does both for a registered title texture, on XCL's upload queue. When to call it (a CPU read of a GPU-written texture) is the next part. Part of xcl-dev#2663. Assisted-by: Claude Code (Claude Opus 5.5)
|
Right, thanks. The baseline is now an owned copy from New test The race itself, an unmap between the check and the read, isn't reproduced by a test. That test decommits before the call, so it doesn't fail with the borrowed view either. In |
a598134 to
cfed80c
Compare
|
Re-verified the texture read-back tests at Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
Not tested: a title actually calling AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. |
… GPU writeback (port upstream xcl-dev#2470 + xcl-dev#2558 + xcl-dev#2678) (cherry picked from commit f78556f9601c01eac0e05e43532047658d085701)
|
Independent Windows/NVIDIA check of head
One source-level gap remains in the new page-safe baseline. The existing Suggested one-line diff@@ unsafe fn read_committed(at: usize, len: usize) -> Vec<u8> {
if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(at, len)) {
- std::ptr::copy_nonoverlapping(at as *const u8, out.as_mut_ptr(), len);
+ copy_committed_region(at, out.as_mut_ptr(), len);
return out;
}In a separate local copy with only that line changed, AI use: Codex (GPT-6.2 Sol) reviewed the source, made the local trial change, ran the tests, and drafted this report; Codex (GPT-6.2 Astra) independently checked the page-protection path. |
|
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2678 at Setup
Targeted RTX 4060 release unit tests (
|
RTX 5070 timeout and recovery in texture downloadOn PR #2678, head One test passed in 10.47 s. A local test-only overlay uploaded a 4 × 4 R8_UNORM texture, inserted the queue wait, and checked the recovery. It used the Windows default adapter, independently identified as the RTX 5070. The first download returned an error and exposed no data to the caller. This exercised one timeout with the caller holding its texture reference, followed by a successful retry. Long-running memory use after repeated timeouts and retail behavior remain unmeasured. AI use: OpenAI Codex prepared the local probe, ran it and wrote this report. |
|
Tested: Clean Not tested: Coherent UMA PAGE_NOACCESS, production game callers, full suite and retail smoke. AI use: T3 Code / Codex ( |
Part 1 of #2663. A title texture the GPU writes is never copied back to the title's memory, so a title that reads it on the CPU gets stale bytes. This adds the read-back, but nothing calls it yet. The next part decides when to call it: a CPU read of a GPU-written texture.
What is in it (one commit)
crates/xcl/src/gpu/texture.rs:downloadcopies every subresource of a resource out to linear rows on a queue and waits. It's the reverse ofupload: barriers from the given states toCOPY_SOURCEand back.crates/xcl/src/hle/d3d12x/title_textures.rs:write_subresourcestiles them into the console layout with the existingChain::tile_level/tile_volume. It's the reverse ofsubresources. It writes only the 4 KiB pages that change, and only committed, writable ones, throughWriteProcessMemory, so a page unmapped meanwhile fails instead of faulting.read_back(res)does both for a registered title texture on XCL's upload queue, holding its own reference to the resource meanwhile. It is#[allow(dead_code)]until part 2 calls it.written_subresources_read_back_as_the_same_texels(CPU) covers 2D with mips and slices, 3D, BC7 and a 4×4 texture, all in tiled layouts. Written texels detile back to the same subresources, bytes past the texture stay as they were, a second write with nothing changed writes 0 bytes, and subresources of the wrong size or number are refused.read_back_writes_what_the_gpu_holds_into_the_title_memory(GPU) covers 2D RGBA8 with 3 mips and 2 slices, 3D 40×24×6 with 3 mips, and BC7 256×256 with 9 mips. A copy into a registered texture is the GPU write.read_backthen makes the title's memory detile to exactly those texels. The page after the texture is untouched, a second read-back writes nothing, and a read-only page of the texture is left alone while the others are written.texture::wait),downloadkeeps the readback buffer, the allocator, the list and a reference to the texture rather than releasing them under a copy that may still run (luckyteagirl's review).texture::uploadhas the same early return on a wait error and isn't changed here.downloadrefuses a format of more than one plane (depth and stencil, video), checked withD3D12_FEATURE_FORMAT_INFObefore anything is recorded, rather than reading back plane 0 alone (luckyteagirl's second review). The GPU test checks that aD24_UNORM_S8_UINTtexture is refused; without the check it reads back plane 0 and the test fails.write_subresourcescompares against an owned copy of the title's memory (read_committed, page by page throughReadProcessMemory), not a borrowed view of it. A page the title unmaps meanwhile reads as zeros and isn't written (luckyteagirl's third review). Testwritten_subresources_skip_a_page_the_title_unmapped: a texture with one decommitted page gets the other pages' texels, and that page stays unmapped. The race itself, an unmap between the check and the read, isn't reproduced by a test.downloadrefuses a multisampled texture the same way, since a copy of one needs a destination with as many samples (thehollowedone). The GPU test checks that a 4-sample RGBA8 render target is refused.Tested
XCL_ADAPTER=Radeon. Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.8.2502.11. Debug builds for the tests, release for the runs.cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4oncfed80cf:gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, which fails the same way onmainon this iGPU (DXIL fuzz tests: fuzz_validate_and_gpu_1 fails on AMD (seed 722 and others, RDNA2-4), so the default suite is red there #2115).... ok), not skipped.SKIPPEDon both:heap_window_out_of_memory_falls_back_to_the_switch_form,uploads_start_from_each_subresources_state, the title under the debug layer, and the GPU / shader cases the adapter can't run (wave64 on the RTX 4070 Ti, mesh shaders on RDNA2).Regression run
RTX 4070 Ti (driver 621.40), release builds, 60 s each,
scripts/smoke.ps1 -Game <folder> -Title retail-titleon the newer retail title, one after the other with the same settings. The runs stay on the menus, and nothing calls the new code yet, so this is a regression check only. Both ran with the NVIDIA shader-heap profile (#2590, 1 GiB) installed on this machine since 2026-11-25.mainb49be183(this PR's base) and this PR's head (no uncommitted changes):main:
PR:
Not tested
vram::placeplacements and aren't registered intitle_textures, soread_backdoesn't reach them yet. Part 2 has to keep their console description to read them back.download: no test makes the wait fail.read_backassumes the writing work is done; part 2 waits for it.registerrefuses those).AI use