GPU: upload a host-copied texture again once the title writes its memory #1210
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!1210
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1210"
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?
@powplusplus on GitHub · 2026-11-24 16:26 UTC · original
powplusplus:gpu/host-written-reupload→main· +194 −28 · 3 files · 1 commits · openFixes #758.
Once a texture received a GPU copy or resolve,
upload()skipped it until the resource was released, so later title writes to its memory (streamed mips, for example) never reached the host copy.host_writtennow records where the memory stood at the copy: the write-watch asking for watched memory, a content hash for physical-page views.upload()keeps the host contents only while the memory is unchanged since then. Render targets, depth and UAV textures are not tracked, sinceupload()never runs for them.Tested:
cargo test -p victory-gpu: two new tests, one for write-watched memory and one for hashed memory@Zipettte on GitHub · 2026-11-24 18:00 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
fd59489:cargo test -p victory-gpupasses, 52 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@wwwwwwww3333333 on GitHub · 2026-11-24 20:18 UTC · original
With
--test-threads=1, a main test fails with this PR:watch::tests::written_pages_are_reported_to_every_asker, atassert!(before.is_empty())(watch.rs:307). That gives 51 passed, 1 failed. main alone passes all 50 the same way.Setup: head
fd59489on mainffe310e(clean merge), Windows 11, RX 6750 XT, Rust 1.98.1 MSVC,cargo test -p victory-gpu --lib -- --test-threads=1. @Zipettte's 52/52 ran with the default parallel threads, so the order and the addresses differ there.What I think happens, from the source:
host_written_clears_after_write_watched_memory_is_written(texture::tests, which runs before watch::tests in a sequential run) allocates one write-watched 64 KiB page and writes to it.still_host_writtenthen callswatch::writes, which records that page in the globalJOURNAL.written.writtenonly ever grows.VirtualAllocgets the same address back. So the firstwriteson it already lists that page, andbefore.is_empty()fails.Ways out, smallest first:
beforeinstead of requiring it to be empty.watchdrop journal entries for a range when the title frees it. In the emulator, the same stale entry makes a reallocated buffer look written once, which costs one extra copy rather than a wrong result.Unit tests only, no game files. AI-assisted (Claude found it in a batch run and traced it in the source; I ran the tests on my machine).
@wbkepler on GitHub · 2026-11-24 20:48 UTC · original
I compared this with #1547, which fixes the same issue. This PR is the more complete fix:
w > asked, as in #1547.HostWrite::Hashed. Perwatch.rs's header, that is where the texture pool lives, so it is the streamed case from #758. #1547 leaves views host-written for good.These points apply to both PRs:
host_writtenruns when the copy or resolve is recorded (list.rscopy_resource/copy_texture_region/resolve). A CPU write to the texture's memory between recording and submission therefore counts as "after the copy". A sampler recorded later in the same frame then re-uploads title bytes over the copy, although on the console the GPU copy runs after submission and wins. Taking the snapshot at submission (inrun_deferred) matches hardware ordering.texture.rs:119). The journal works in 64 KiBwatch::PAGEunits. A texture that shares a 64 KiB page with data the title writes on the CPU is reported as rewritten even when its own bytes didn't change; small 256 B or 4 KiB swizzled textures sub-allocated next to per-frame data are the likely case.upload()then detiles the pre-copy title bytes over the GPU copy result. For a texture that gets a GPU copy every frame, that means stale content every frame plus a re-upload. The staging refresh upstream has the same granularity, but there a false positive only re-detiles identical bytes. The hash helper is already here: treat the watch result as "maybe changed" and confirm it against a hash of the texture's bytes taken inhost_written.texture.rs:121-127).still_host_writtenhashes the whole texture once for every list that samples it, on the recording thread. That comes on top of the hash inhost_writtenfor every copy and the staging refresh's hash once per submission. A large GPU-copied texture in view memory that many lists sample gets hashed in full many times per frame. Doing the check once per submission, next tobatch.texture_due, would bound it.Render targets, depth and UAV textures are not affected in either PR, because
upload()never runs for them.Interaction with #230 (
gpu/skip-clean-texture-uploads, ours):HOST_WRITTENwithHostTexture::host_written: AtomicBool. AStep::TextureHostWriteinrun_deferredsets it at submission, andStep::Texturechecks it again at submission; that is also where #230 records the staging-to-texture copy, and only whenstaging.refresh()reports dirty.Step::Texturecheck (fixing point 3).Last(asked/hash) must be reset as well, because after a host copy the host texture no longer matches what staging last detiled. Otherwise, on the hashed path, title memory that returns to the bytes staging last held reads as clean and no upload is recorded. We'll handle that side in #230 if this lands first.AI-assisted review (Claude Code); checked on Windows 11 / RTX 5090.
@Marvisak on GitHub · 2026-11-25 01:18 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/texture.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
fd5948937bto60f6d1a575@andrewpozdnakov7-jpg on GitHub · 2026-11-26 13:07 UTC · original
@powplusplus I ran the same two-mip RGBA8 regression on
63bcca43and your exact60f6d1a. A submittedCopyResourcemade both mips green. Then a CPU write replaced all four texels in mip 1 with blue and left the backing bytes for mip 0 red. A later compute dispatch read both mips.63bcca4360f6d1aThree runs per revision on app-local Agility 1.620.2/WARP 1.0.22 gave the same values for both write-watched and untracked allocations. The ordinary diagnostics suite on the PR tree passed with 249 tests and 2 ignored, and strict GPU Clippy passed with all features. This is synthetic D3D12 evidence. A title capture would establish whether this combination occurs in the game.
The opt-in regression is one test-only commit on your head. It checks that mip 1 takes the CPU update while mip 0 keeps the GPU copy. Could you check whether the fix can retain the host contents for untouched subresources?
If you reuse the test, please retain its Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit. AI-assisted with Codex.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 16:40 UTC · original
@powplusplus I tested a subresource follow-up
8595658directly above60f6d1aand the earlier regression commit. It takes the CPU baseline at the original submission point, compares logical texels per subresource when the CPU bytes change, and uploads only the changed subresources. A mip tail can share a tile, so a hash of the whole tile alone cannot identify which mip to replace. The host copy stays resident until every mip and slice has received CPU data.The updated
issue758_cpu_mip_write_keeps_the_other_gpu_mipfixture failed three times on the PR control, at the first mip-1 update. The candidate passed all three fresh runs. Each run checked linear and 4 KiB swizzled layouts (both mips in the same tile), on watched and untracked allocations. It also checks a same-page write outside the texture, two CPU updates to one mip, the copy count, and eviction followed by recreation once both mips are CPU-backed. App-local Agility 1.620.2/WARP 1.0.22 diagnostics suite: 248 passed with the runtime identity test, 0 failed, 1 ignored. Strict GPU Clippy passed with default and all features. Policy passed.Could you review this approach and check it against a title capture? The logical baseline adds CPU detiling when a host copy is recorded for submission and when its title bytes actually change. I have synthetic correctness results and no title timings for that path.
If you reuse the commits, please retain their Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding them into another commit. AI-assisted with Codex.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 17:35 UTC · original
I also checked the selective mip candidate with #3288's shared texture view refresh. The bindless conflict has a tested resolution. The original four replacement-view tests passed, and partial CPU mip updates still preserve GPU-written mip contents across the linear and packed cases. Combined WARP results and branch. AI-assisted with Codex.
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.