A texture that once received a GPU copy ignores later writes to its memory #758
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#758
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Conrage on GitHub · 2026-11-24 09:38 UTC · original
crates/victory-gpu/src/texture.rs:109-113: once a texture is inHOST_WRITTEN,upload()always returns early.CopyResource,CopyTextureRegionand resolves add textures to that set (list.rs:454,550,634), and it is cleared only when the resource is dropped (resource.rs:976). If the title later writes that texture's memory (for example by streaming new mips), the host copy keeps the old contents.Suggestion: record the write-watch point when the host copy happens. If the title's memory changes after that, detile it again.
AI use: found and written with Claude from reading the code at
8e79c80; not run on hardware.@DrDarkDK on GitHub · 2026-11-24 09:51 UTC · original
Reproduced on
8e79c80with a synthetic 64×1 RGBA8 texture on native Windows 11, using both an RTX 4070 Ti (driver 621.01) and WARP.The initial title-memory upload read back correctly. After
CopyResource, a second upload attempt with unchanged title memory correctly preserved the GPU-copied pixels. After writing new pixels to the title memory and calling the same upload path again, both adapters still read back the GPU-copied[68, 85, 102, 255]instead of the new[119, 136, 153, 255].The test is
resource::tests::title_texture_write_after_gpu_copy_reaches_the_host. It uses a real D3D12 copy and readback with generated pixels. No game files used. AI-assisted test implementation and verification.@BastienRodz on GitHub · 2026-11-24 09:57 UTC · original
I'm working on this, along the lines suggested: record the write-watch asking when the host copy is recorded, and in
upload()leave the host-written state once a page of the texture's memory is written after it, so the next upload detiles title memory again. Memory without a write watch keeps the host's contents, as today. PR creation is limited to collaborators, so the fix will go on a branch of my fork, linked here, once it's tested. No game data used.AI-assisted (Claude Code, Gemini).
@AndyLatimer on GitHub · 2026-11-24 10:03 UTC · original
Branch ready on fork (PR creation is currently collaborators-only): https://github.com/AndyLatimer/VIctory/tree/fix/gpu-host-written-texture-refresh (commit
d5344a8, based on8e79c80).Covers both memory paths in
crates/victory-gpu/src/texture.rs:MEM_WRITE_WATCH): records thewatch::writesasking number athost_written()so writes before the GPU copy do not falsely invalidate it, while any write after it clears the entry and resumes detiling.host::copy_mapped(64 KiB chunks) athost_written()and clears the entry once the content hash changes (or pages become committed).Stickyin O(1) without watch/hash overhead.upload()checks!list.first_use(...)first so a host-written texture sampled multiple times in one command list is checked at most once per list, and clears entries with compare-and-remove against concurrenthost_written()updates.Verified on Windows 11 (
rustc 1.98.1) with synthetic GPU + WARP readback tests (host_written_watched_texture_uploads_after_title_write,host_written_unwatched_texture_uploads_after_title_write,host_written_render_target_stays_sticky_until_forgotten):cargo test -p victory-gpu(hardware GPU): 53 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --features diagnostics(hardware GPU): 56 passed, 0 failed, 1 ignoredVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics(WARP): 56 passed, 0 failed, 1 ignoredcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): 0 warningscargo check -p victory --features diagnostics,rustfmt --edition 2024 --check crates/victory-gpu/src/texture.rs,cargo xtask policy(153 files ok): cleanNo game data or console SDK used. AI-assisted (Google Antigravity).
@BastienRodz on GitHub · 2026-11-24 10:12 UTC · original
A fix, on a branch of my fork since PR creation is limited to collaborators:
https://github.com/BastienRodz/VIctory/commits/gpu/texture-write-after-host-copy (
7a2ea90)The branch is based on
c7a5f49, just before the CI commit (my token can't push a branch that contains.github/workflows). It merges cleanly into the currentmain. The change is three files invictory-gpu:texture.rs, plus test helpers inresource.rsandwatch.rs.What
HOST_WRITTENnow keeps, per texture, the write-watch asking current when the host copy (CopyResource,CopyTextureRegion, resolve) was recorded.upload()asks the journal (watch::writes) for the texture's memory. If a page was written after that asking, the texture leaves the host-written state and its staging cursor is reset, so the upload detiles title memory again. A later host copy makes it host-written again.shortcut:note).host_writtenruns when the copy is recorded, not when it executes. A title write between recording and submission gets a later asking, so the next upload takes the title's contents.Tested
Linux, cross-built with
cargo xwinforx86_64-pc-windows-msvc, run under Wine 10. GPU tests ran on vkd3d-proton 3.1 over lavapipe (a real D3D12 device).cargo xwin test -p victory-gpu: 53 passed (plain Wine). On vkd3d-proton: 52 passed and 1 failed, the environment-onlya_rejected_blob_gives_an_empty_library, which also fails onmainthere.written_since_detects_pages_written_after_asking: the rule itself.host_written_yields_after_write_in_watched_memory: a write before the copy keeps host ownership; a write after it ends it; a new copy takes it again; unwatched memory keeps it.title_write_after_host_copy_reaches_the_host_texture, the same shape as the repro above, run on the device: a 64x1 RGBA8 title texture in write-watched memory gets its initial upload, then a realCopyResource. The copied pixels are kept while nothing writes, and after a title write the next upload reads back the new pixels.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features, as the CI runs it: clean. No new rustfmt diffs.cargo xtask policy: ok.Not run: the title, and native Windows. @DrDarkDK, if your
title_texture_write_after_gpu_copy_reaches_the_hosttest is on a branch, it would be a good independent check against this one.No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and tested with Claude Code.
@AndyLatimer on GitHub · 2026-11-24 10:08 UTC · original · edited 2026-11-24 10:18 UTC
Withdrawn. The branch in the comment above,
AndyLatimer:fix/gpu-host-written-texture-refresh(d5344a8), does the same for write-watched memory and also covers memory that is not watched (physical-page views, where streamed texture data lands). That is the one to use.To measure in game: in unwatched memory it reads and hashes the whole texture at each host copy, and at each list that samples it while it keeps the host's contents.
@DrDarkDK on GitHub · 2026-11-24 10:19 UTC · original
Ran the same synthetic
CopyResourceand pixel readback fixture against all three revisions on native Windows 11, with both RTX 4070 Ti and WARP. The fixture checks that VIctory recognizes the watched and unwatched allocations as intended.7a2ea90c0eb07dd5344a8Both adapters gave the same results. The initial upload and unchanged-memory controls passed in every case. The unwatched failures occurred only after the later title-memory write, as expected for the write-watch-only branches.
Synthetic tests only. AI-assisted test setup and reporting.
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 10:21 UTC · original
Fixed in commit
github.com/LAKSHYA-cmd-tech/VIctory@223efb297b(branch ix/texture-host-written-streaming-invalidation): we record the watch asking tick when host GPU writes a resource. On subsequent uploads, if title memory writes occurred after that tick, the entry is invalidated from HOST_WRITTEN allowing newly streamed mips to be staged and uploaded.@MichaelSmithAI on GitHub · 2026-11-24 10:27 UTC · original
On
d5344a8, the executed-copy / later CPU write test passed here on an RTX 4090 through Wine/vkd3d. We also found a separate recording-order case with a 4×4 RGBA8 texture backed by ordinary CPU memory.Both arms upload the original pixels, write new pixels in CPU memory, then do the same upload and readback. With no intervening recording, the new pixels reach the host (first byte 80). If we record and close a buffer-to-texture copy and release its command list without submitting it, the same readback returns the old pixels (first byte 16). The discarded copy never executes. The fixture calls the normal command-list entry point and changes only test code. Paired regression on d5344a8
The recording path calls
host_writtenwhile building the list. This case is worth keeping alongside the existing executed-copy control when deciding when a texture becomes GPU-owned. We haven’t measured how often the game discards such recordings. AI-assisted testing on synthetic input.@BastienRodz on GitHub · 2026-11-24 11:16 UTC · original
Update: the branch (https://github.com/BastienRodz/VIctory/commits/gpu/texture-write-after-host-copy) is now on current
main(ffe310e, commitb3bc426). The upstream CI's checks pass on GitHub'swindows-latest(clippy-D warningswith and without--all-features, thencargo test --workspace --locked): https://github.com/BastienRodz/VIctory/actions/runs/45382122283.victory-gputhere: 53 passed, 0 failed.AI-assisted (Claude Code).
@AndyLatimer on GitHub · 2026-11-24 11:17 UTC · original
Thanks @DrDarkDK for verifying both watched and unwatched paths across the branches, and thanks @MichaelSmithAI for catching the discarded-recording bug on
d5344a8!Fixed on
AndyLatimer:fix/gpu-host-written-texture-refreshin commitgithub.com/AndyLatimer/VIctory@eb1b8d4(merges cleanly ontomainffe310e):texture::host_written(list, resource)now markslist.first_use(key)locally (so a laterupload()inside the same command list still does not clobber the GPU copy), and defers updating the globalHOST_WRITTENmap ontoHostListuntilHost::executeactually runs that list.texture::forget, so releasing a texture before submitting a recorded list neither touches freed memory nor leaves a staleHOST_WRITTENentry on a reused address.unsubmitted_texture_copy_does_not_suppress_title_upload), same-list copy-then-upload (same_list_upload_after_copy_keeps_gpu_copy), and release-before-submit (released_texture_pending_host_write_is_ignored_on_submit).Verified on Windows 11 (
rustc 1.98.1):cargo test -p victory-gpu(hardware GPU): 56 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --features diagnostics(hardware GPU andVICTORY_D3D12_WARP=1): 59 passed, 0 failed, 1 ignoredcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics),cargo check -p victory --features diagnostics,rustfmt --edition 2024 --check crates/victory-gpu/src/texture.rs,cargo xtask policy(153 files ok): cleanSynthetic tests only (no game data). AI-assisted (Google Antigravity).
@MichaelSmithAI on GitHub · 2026-11-24 11:30 UTC · original · edited 2026-11-24 11:37 UTC
We verified the reset, discarded-list and release controls from
eb1b8d4on our Wine texture stack. Combining it with #641 also exposed a separate case in the unwatched-memory snapshot.Melissa reserved two 64 KiB tiles, committed the first, and edited a byte in that resident tile. On the combined baseline, the second tile being uncommitted made
hash_unwatchedreturnNonefor the entire texture, so there was no snapshot with which to detect the edit. Reusing #641’s resident-range reader gives a stable snapshot before the edit, a changed digest after it, and another change when the second tile becomes resident. The digest includes the offsets of the readable ranges.All 11 focused texture tests passed on Win64 under Wine/GE 3.2. The new regression measures snapshot behavior; the resulting pixels and any effect in-game remain unmeasured. This comparison includes the #641 dependency. Patch and regression test
Separate submissions on exact
eb1b8d4. Donald tested a fully resident 4×4 RGBA8 texture on an RTX 4090 with Wine and vkd3d-proton 3.2. In both runs he submitted the writer, verified the GPU pixels, then submitted the reader. Recording the reader after the writer executed preserved every expected pixel (first byte0x70). Recording the same reader before the writer executed restored the old CPU pattern (first byte0x10). The discard/reset, same-list and release controls all passed in the same binary. This isolates the upload decision made while recording the reader. The test uses synthetic pixels and two separate submissions. Regression fixture on the author’s commit@Marvisak on GitHub · 2026-11-25 03:50 UTC · original
Automated triage for the maintainers.
Confirmed on current
main. Incrates/victory-gpu/src/texture.rs,uploadreturns early for any texture inHOST_WRITTEN(is_host_written), and its own comment marks this as a shortcut: a texture the host copied into keeps the host's contents even if the title later writes its memory. DrDarkDK's synthetic readback reproduces it on an RTX 4070 Ti and on WARP.Open PRs linked to this issue: #1210 and #1547. #1934 also moves
host_writtento submission time, which covers the discarded-recording and recording-order cases MichaelSmithAI found. The fork branches here (BastienRodz, AndyLatimer, LAKSHYA-cmd-tech) aren't PRs. Pull requests are open to everyone, so please compare with those PRs before opening another. Per DrDarkDK's table, a fix needs to cover unwatched memory as well as write-watched memory.Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 12:45 UTC · original
Rechecked the submitted
CopyResourcecase on63bcca43with app-local Agility 1.620.2 and WARP 1.0.22. I used a synthetic 4×4 RGBA8 texture in write-watched title memory and read all 16 texels through a compute shader after separate submissions.CopyResourcefrom it made the destination read blue in all 16 texels.This reproduces the reported behavior on that revision. The flag set at submission still suppresses uploads after the later watched CPU write. Submission-order change
f68442fThe
victory-gpudiagnostics suite, including the temporary checks, had 249 passed, 0 failed and 1 ignored. This run used synthetic data and the software adapter. AI-assisted with Codex.