D3D12.X: copy a GPU-written title texture back into the title's memory #2678
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!2678
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2678"
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?
@joeypercia on GitHub · 2026-11-26 05:53 UTC · original
joeypercia:d3d12x-texture-readback→main· +361 −0 · 2 files · 1 commits · openPart 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 (#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
@joeypercia on GitHub · 2026-11-26 06:11 UTC · original
Thanks, yes. When the wait fails,
downloadnow keeps the readback buffer, the allocator, the list and a reference to the texture (std::mem::forget) instead of releasing them while the queued copy may still run. That'sbbc97e25. It leaks them, but only on that error path, andread_backgives up there. The wait-error path itself isn't tested; I couldn't make the wait fail in a test.texture::uploadhas the same early return and is left as it is here. The suite and the smoke run were rerun onbbc97e25, and the description has the counts. (Claude Code, Claude Opus 5.5)@luckyteagirl on GitHub · 2026-11-26 05:55 UTC · original · reviewed
Could the download retain its readback buffer, command allocator, and source until the submitted copy is known complete, including on a wait error?
ExecuteCommandListshas already queued the copy whenwait(dev, queue)?runs. That helper can fail creating/signaling the fence or time out after 10 seconds; the early return then dropsrbandallocwhile 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 at033c725442f6534e9938a7c82e41c4279d445127; no live GPU timeout reproduction. AI-assisted review with Codex.@luckyteagirl on GitHub · 2026-11-26 06:20 UTC · original · reviewed
download()promises every D3D12 subresource, butn = MipLevels * arraysomits the native format's plane count. D3D12 countsMipLevels * ArraySize * PlaneCount(Microsoft's resource descriptor helper); the current footprint and copy loop can returnOkcontaining only plane 0 for a two-plane resource whenstates.len() == 1. With a state per real subresource, it instead rejects the valid state count. Could this queryD3D12_FEATURE_FORMAT_INFO.PlaneCountand 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 fortitle_textures::read_backyet, 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.bbc97e2584to077f887619@joeypercia on GitHub · 2026-11-26 06:27 UTC · original
Thanks, also right.
downloadnow checks the format's plane count (D3D12_FEATURE_FORMAT_INFO) before it records anything, and refuses a format of more than one plane instead of returning plane 0 alone. No caller needs a depth or stencil read-back yet, andregisteralready turns render targets and depth buffers away. The GPU test now checks that aD24_UNORM_S8_UINTtexture is refused. With the check taken out, that assertion fails:downloadreturns a single plane-0 subresource. Amended into077f8876, with the suite and the smoke run rerun on it (description updated). (Claude Code, Claude Opus 5.5)@Aniseto on GitHub · 2026-11-26 06:38 UTC · original · edited 2026-11-26 07:51 UTC
Ran the texture read-back tests at
077f8876: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.
read_back_writes_what_the_gpu_holds_into_the_title_memoryran on the real adapter (backend 'real' --- NVIDIA GeForce RTX 5070 Ti) and passed, together with the CPU detiling test and the driver-cache test matched by the same filter.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
read_back(nothing does yet), UAV-written textures, the wait-error path, MSAA, depth/stencil, a paired 60 s smoke run, AMD and Intel GPUs, release profile, title data.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
a598134): the new commits add 13 lines intexture.rsandtitle_textures.rs. Re-ran the same filter ata598134:The GPU read-back test still runs on the real RTX 5070 Ti and passes.
@SlopTart on GitHub · 2026-11-26 06:50 UTC · original · edited 2026-11-26 07:02 UTC
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;
d3d12,d3d12core,dxgi,d3d11,d3d10core=n,boverrides, official DXC kit,VKD3D_CONFIG=ignore_shared_fence, threads=2), head077f8876, mergeable against mainb49be183:non-gpu suite (
--skip gpu::): 598 passed, 3 failed, 4 ignored, 733 filtered.The failure set is identical to bare main
b49be183measured on the same rig the same day (596 passed, 3 failed): gpu_promoted_uav_clear (our #2490), xma2_source_voice (#2481, vendored-FAudio gate). The third red, the sparse tile video-memory test, is a known batch flake (green solo).Zero delta from this PR; every test it adds passes inside the suite.
Not tested: gpu suite, Windows native.
Correction: an earlier version of this row reported three extra reds; those runs lacked the
d3d12,d3d12core=n,bDLL overrides and hit stub-DLL NOTIMPL artifacts. Re-ran with the standard env, artifacts gone.AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
@SzczepanGrela on GitHub · 2026-11-26 07:08 UTC · original
Linux/RADV verification of
077f8876195f6a26e0acfbe66b036e5a003c3feaagainstmainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7. The unmodified GPU fixture stops before read-back; a test-only raw-device fixture exercises the read-back and passes.Tested
26.3.1-arch3.5, Ryzen 7 7700, CachyOS7.3.0-5-cachyos, GE-Proton11-12 / Wine 11.0 Staging, vkd3d-proton8293130ebe370b1+(v3.1-1-g8293130eb-GE-Proton(dirty)+), rustc1.97.1, MinGW GCC16.2.0, release.cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-runfor both source snapshots.--nocapture --skip retail_ --test-threads=N. Filters below.XCL_ADAPTER=radeon XCL_REQUIRE_GPU=wave64 XCL_NETWORK=0 VKD3D_SHADER_CACHE_PATH=0, natived3d12,d3d12core,dxgi, noXCL_SAMPLE_*. Zero skip messages.gpu::texture::tests::hle::d3d12x::title_textures::tests::hle::d3d12x::title_textures::tests::The same three existing tests fail on both revisions:
a_placed_texture_gets_the_pages_of_a_level_with_its_texels,gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes, andplaced_title_textures_share_vram_and_preserve_pixels.Each new test was also run alone with
--exact, in three fresh processes:written_subresources_read_back_as_the_same_texels: 3/3 passed.read_back_writes_what_the_gpu_holds_into_the_title_memory: 0/3 passed. All fail attitle_textures.rs:2079, in the existingtexture::upload, with0x80070057; vkd3d-proton logsd3d12_command_list_Reset: Invalid command allocator.The firstread_backcall at line 2083 is not reached. This is a setup blockage, not a reproduced read-back failure.Test-only diagnostic
backend()/real::device_raw()initialization withagility::create_device(None, D3D_FEATURE_LEVEL_12_0)and its raw pointer. Production code and all assertions are unchanged.Not tested
scripts/smoke.ps1, UAV-written placements, cross-queue producer ordering, injected wait failures, Windows, other GPUs, or performance. The actual read-back failure path has not been reproduced.AI use
@thehollowedone on GitHub · 2026-11-26 07:26 UTC · original
One API-contract edge case before this helper is reused:
downloadaccepts a one-plane texture without checkingSampleDesc.Count, then copies each subresource into a single-sample readback buffer. Microsoft'sCopyTextureRegioncontract says copies involving a multisampled resource must cover the whole subresource and the source and destination should have matching sample counts (documentation). The current path therefore has no defined MSAA read-back behavior.Could
downloadrejectrd.SampleDesc.Count != 1before allocating or recording commands, with a focused test, unless this helper is meant to resolve to a defined single-sample representation? I have not run an MSAA case; this is a source/API-contract finding, not a retail-title result.AI-assisted.
077f887619toa59813423a@joeypercia on GitHub · 2026-11-26 07:34 UTC · original
Thanks, @thehollowedone.
downloadnow refuses a multisampled texture before it records anything, as it refuses a format of several planes. Resolving to one sample would be a different read-back, and nothing needs one. The GPU test checks that a 4-sample RGBA8 render target is refused. It's ina5981342, and the read-back tests pass on the RTX 4070 Ti and the RDNA2 iGPU. The full suite and the smoke run on it follow; I'll update the description then. (Claude Code, Claude Opus 5.5)@luckyteagirl on GitHub · 2026-11-26 08:28 UTC · original · reviewed
At head
a59813423a7f10c44fd3702e7caed0c017e441ab,write_subresourcestakesold = title_bytes(va, len), clones it tomem, spends time retiling, then readsoldagain for each page diff (title_textures.rs:1506-1524). For an all-readable range,title_bytesreturns 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 beforewrite_writablereaches its guardedWriteProcessMemorypath. 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 ownedread_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_bytesand diff loop before posting.a59813423atocfed80cff0@joeypercia on GitHub · 2026-11-26 08:29 UTC · original
Right, thanks. The baseline is now an owned copy from
read_committed, the page-safe helper (ReadProcessMemoryper page run), and the retile and the diff use that copy. A page the title unmaps meanwhile reads as zeros there, andwrite_writablethen skips it because it isn't committed.New test
written_subresources_skip_a_page_the_title_unmapped: one page of a texture's memory is decommitted. That page isn't written or committed again, and the other pages get their texels.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
cfed80cf; the suite and smoke rerun follow. (Claude Code, Claude Opus 5.5)@Aniseto on GitHub · 2026-11-26 08:45 UTC · original
Re-verified the texture read-back tests at
cfed80cfafter the head moved again (36 lines added intitle_textures.rs).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.
read_back_writes_what_the_gpu_holds_into_the_title_memorystill runs on the real adapter (backend 'real' - NVIDIA GeForce RTX 5070 Ti) and passes, along with the CPU detiling test and the driver-cache test matched by the same filter. This follows my earlier reports at077f8876anda598134; I am posting a new report rather than editing those, per the current rule.Not tested: a title actually calling
read_back, UAV-written textures, the wait-error path, MSAA, depth/stencil, a paired 60 s smoke run, AMD and Intel GPUs, release profile, title data.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.
@thehollowedone on GitHub · 2026-11-26 09:31 UTC · original
Independent Windows/NVIDIA check of head
cfed80cfagainst mainb49be183. RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC; debug tests.cargo build --offline --locked --workspace: passed.cargo test --offline --locked -p xcl --lib read_back_writes_what_the_gpu_holds_into_the_title_memory -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored; the real RTX adapter ran the GPU readback fixture.cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quiet: 1,438 passed, 0 failed, 47 ignored across 37 test executables. There were 25 GPUSKIPPEDnotices, mainly unsupported wave64 cases; they are not counted as GPU coverage. These results are for the unmodified PR head.One source-level gap remains in the new page-safe baseline.
read_committeduses a raw pointer copy whenuma.in_committed_window(va, len)is true. That predicate checks window membership, not the current page protections.kernelx::VirtualProtectcan passPAGE_NOACCESSto Windows for an interior page. The raw copy can then fault beforewrite_writablegets to skip that page. The new decommit test allocates outside the UMA window, so it does not exercise this branch.The existing
copy_committed_regionusesReadProcessMemoryand splits failed spans around inaccessible pages. Using it for the coherent-window branch avoids aVirtualQuerywalk over the large window:Suggested one-line diff
In a separate local copy with only that line changed,
written_subresourcespassed 2/0/0 and the real-GPU readback test passed 1/0/0. A regression should protect an interior page of an actual coherent UMA allocation and check neighboring pages. I did not run that protected-window case, so this is a source finding and a suggested fix, not a reproduced crash or a validated protection regression. I did not run a retail title, a paired smoke test, AMD or Intel hardware, or a readback caller in production.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.
@Decodere on GitHub · 2026-11-26 10:24 UTC · original
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2678 at
cfed80cff0cd8a06aee72d6898daf2955dcf3690(exact parentorigin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.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 RTX 4060 release unit tests (
cfed80cf)cargo test --release -p xcl --lib written_subresources_skip_a_page_the_title_unmapped -- --nocapture: 1 passed, 0 failed, 0 ignored (0.04 s, exit0).cargo test --release -p xcl --lib written_subresources_read_back_as_the_same_texels -- --nocapture: 1 passed, 0 failed, 0 ignored (0.02 s, exit0).cargo test --release -p xcl --lib read_back_writes_what_the_gpu_holds_into_the_title_memory -- --nocapture: 1 passed, 0 failed, 0 ignored (0.45 s, exit0).cargo test --release -p xcl --lib gpu::texture:: -- --test-threads=4: 15 passed, 0 failed, 0 ignored (0.62 s,0skipped, exit0).cargo test --release -p xcl --lib hle::d3d12x::title_textures:: -- --test-threads=4: 22 passed, 0 failed, 0 ignored (1.03 s,0skipped, exit0).Observations
written_subresources_skip_a_page_the_title_unmapped,written_subresources_read_back_as_the_same_texels,read_back_writes_what_the_gpu_holds_into_the_title_memory) and all 37 targetedgpu::texture::+hle::d3d12x::title_textures::tests passed cleanly in--releaseon this RTX 4060 (8 GB) host with0skips.exit: 0x0,1539frames shown,60 60 60steady-state presents per 2 s,0device removals,0crashes,14019 MBpeak commit vs parentb49be183's14018 MB/1518frames).Paired 60 s RTX 4060 smoke (
b49be183vscfed80cf)Parent
origin/main(b49be183):PR #2678 head (
cfed80cf):Limits of coverage
cfed80cf(only targetedgpu::texture::andhle::d3d12x::title_textures::release tests plus paired quiet 60 s smoke).RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.AI use
Ran the targeted release unit tests 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.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.