GPU: copy textures from GPU-backed buffer shadows #3338
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3338
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3338"
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?
@fuzeofficlal on GitHub · 2026-11-26 19:03 UTC · original
fuzeofficlal:fix/gpu-copy-texture-from-gpu-buffer→main· +955 −15 · 4 files · 1 commits · openSummary
CopyTextureRegion(buffer to texture) previously always allocated a temporary upload buffer and filled it from CPU title memory at submission preparation time (HostList::defer_fill). Whenever a title wrote texel data into a buffer on the GPU—through a compute/graphics shader UAV orClearUnorderedAccessViewUint/Float—and copied that buffer into a texture in the same command list or submission,CopyTextureRegionuploaded stale pre-GPU CPU memory instead of the GPU-written bytes.Changes
shadow.rs: Addshadow::existing(address, len)to look up an already-created hostShadowcopy (inBUFFERSorLOOSE) without allocating shadows for pure CPU upload buffers.resource.rs: Addresource::buffer_unordered(this)to identify buffers created withD3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.list.rs: Incopy_texture_region(buffer -> texture):shadow::find(when UAV-capable, covering out-of-order multi-threaded command list recording) orshadow::existing(for buffers inside an already-shadowed heap or window).shadow.refresh(also pinningArc<Shadow>until list reset), issue a UAV barrier so prior GPU writes are visible, and copy directly fromshadow.bufferatshadow.offset(data)when 512-byte aligned, or stage through adefault_buffer(CopyBufferRegion+COPY_DEST -> COPY_SOURCE) when the shadow offset is not 512-byte aligned.CopyBufferRegionordering.draw.rs: Track buffer copies promoted toCOPY_SOURCEinState::copy_sources(cleared onreset/cut) soclear_unorderedtransitions them fromCOPY_SOURCE -> UNORDERED_ACCESSwhen needed, and returns cleared buffer copies toCOMMONafterward without breaking prior implicit read promotions (e.g., root SRV / vertex buffer reads on the same buffer).Testing
Added 7 end-to-end D3D12 tests in
crates/victory-gpu/src/list.rs(list::tests::copy_texture_from_gpu_buffer::*) covering compute shader UAV writes at non-zero footprint offsets,ClearUnorderedAccessViewUintbefore and afterCopyTextureRegion, out-of-order multi-list recording within one submission, non-512-byte-aligned shadow offsets, mixed CPU+GPU writes withsource_boxand destination(x, y, z), root SRV +CopyTextureRegionstate compatibility on the same buffer, and pure CPU upload buffer ordering without shadow allocation. All 7 tests fail before the fix (5 GPU-write cases fail with stale CPU bytes) and pass on both hardware D3D12 and WARP withVICTORY_D3D12_DEBUG=1and zero D3D12 debug errors, along with fullvictory-gputest suites, workspaceclippy(default and--all-features), formatting checks, andxtask policy.@Dukestar69 on GitHub · 2026-11-26 19:08 UTC · original · approved these changes
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib list:: -- --test-threads=1: 11 passed, 0 failed (all 7copy_texture_from_gpu_buffer::*tests passed).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20 passed, 0 failed.cargo test -p victory-gpu --lib resource:: -- --test-threads=1: 18 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 19:16 UTC · original
WARP/CPU verification of head
5d0b0dfd(claim: #1633)Environment: Windows 11, WARP only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1),dxil.dllfrom Windows SDK 10.0.26100.0 (VICTORY_DXIL), no physical GPU, no game files.-j 4,--locked, separate target dir. Control:origin/main@63bcca43. Merge:git merge-treeagainst currentorigin/mainis clean (head is 1 commit ahead, 0 behind).63bcca435d0b0dfdcargo test -p victory-gpucargo clippy -p victory-gpu --all-targets -- -D warningsxtask policyThe 7 added tests (
copy_texture_region_*) all pass on WARP. They do not run on control: with the PR'sdraw.rs/resource.rs/shadow.rsreverted to main, the test module fails to compile (buffer_unordered,shadow::existing,note_copy_sourcemissing), so they depend on the fix. I did not review the design beyond that. Synthetic/unit tests only.AI disclosure: run by Claude Code (Claude Sonnet 5.5), coordinated by Antigravity.
@kalberts0089-hash on GitHub · 2026-11-27 10:00 UTC · original
NVIDIA test report: RTX 4070 Ti (desktop, driver 621.01), Windows 11 Pro, rustc 1.98.1. Head
5d0b0df(base main63bcca4). Claimed in #1633.Confirmed:
copy_texture_from_gpu_buffertests put on it unchanged (minus the oneshadow::existingassertion, which main can't build): 5 fail with stale bytes (for exampletexel (0, 0) got 0x0, expected 0xa0000000), and the pure-CPU and root-SRV cases pass. So #785 reproduces on this card.VICTORY_D3D12_DEBUG=1and withVICTORY_D3D12_DEBUG=1 VICTORY_D3D12_GBV=1(--features diagnostics), with no D3D12 messages.CopyTextureRegionfrom it, a second dispatch writes it again, a second copy, then the read-back, all in one list. It passes under the debug layer and GBV.cargo test -p victory-gpu --lib -- --test-threads=1: 236 passed, 2 failed, 1 ignored (main: 229 / 2 / 1). The 2 failures are the known capped-heap ones (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views) and fail the same way on main; unrelated to this PR.A design question, not something I could make fail:
clear_unorderednow transitions the buffer it clears: COPY_SOURCE to UNORDERED_ACCESS when it was a copy source (draw.rs:1095-1101), and UNORDERED_ACCESS to COMMON after every buffer clear (draw.rs:1114-1119). For a title buffer that resource is the host copy of the title's memory.315cea1says those copies are never transitioned ("common between submissions, promoted by every use, ordered by unordered-access barriers"), and #1374 was closed for bringing such transitions back. Is this case meant to be an exception, or would the copy need to go through a buffer the list owns, as that closing note suggests?Not tested:
cargo test -p victory-shader(this PR doesn't touch it), theExecuteIndirectand vertex-buffer sequences from the #1374 thread, and a title (needs the game).Synthetic tests only, no game files. AI-assisted (Claude Code).
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.