GPU: upload dirty title textures in HostList::prelude #80

Open
github-bot wants to merge 1 commit from github-bot/gh-80 into main AGit
Owner

@⁠adritoyalser on GitHub · 2026-11-24 21:18 UTC · original
adritoyalser:fix/prelude-texture-upload → main · +302 −111 · 2 files · 1 commits · open

Problem

exture::upload previously decided whether to record CopyTextureRegion at command-list recording time by checking staging.uploaded && !staging.dirty, before Staging::refresh runs at submission:
  1. Stale host texture for a full submission after CPU updates: once a title-written texture became clean (either after an unchanged submission, or after a multi-list submission where Batch::texture_due skipped the second
    efresh while the second defer_host cleared dirty), the next CPU write was detiled into the staging buffer at submission without a recorded CopyTextureRegion, so the GPU sampled stale texels until a subsequent use.
  2. Redundant copy on the next unchanged submission: because defer_host cleared dirty before Step::Texture ran
    efresh (which set dirty = true again), the next submission recorded and executed an extra CopyTextureRegion even when nothing had changed.

Fix

  • Move the CopyTextureRegion for title-written textures into HostList::prelude(), which runs immediately after
    un_deferred() has refreshed staging buffers for the submission.
  • Staging::take_upload() atomically checks and clears (!uploaded || dirty) at prelude time, so unchanged textures still skip the GPU copy (and barrier transitions) while changed textures upload on the same submission.
  • Add two D3D12 regression tests in crates/victory-gpu/src/texture.rs:
    • _changed_texture_uploads_on_the_same_submission
    • wo_lists_in_one_submission_do_not_drop_the_next_upload

Verification

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings — clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings — clean
  • cargo test -p victory-gpu --locked — 112 passed, 0 failed (also verified --features diagnostics)
  • cargo test -p xtask --locked — 4 passed, 0 failed
**@⁠adritoyalser** on GitHub · 2026-11-24 21:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/80) `adritoyalser:fix/prelude-texture-upload` → `main` · +302 −111 · 2 files · 1 commits · open ### Problem exture::upload previously decided whether to record CopyTextureRegion at command-list recording time by checking staging.uploaded && !staging.dirty, before Staging::refresh runs at submission: 1. **Stale host texture for a full submission after CPU updates:** once a title-written texture became clean (either after an unchanged submission, or after a multi-list submission where Batch::texture_due skipped the second efresh while the second defer_host cleared dirty), the next CPU write was detiled into the staging buffer at submission without a recorded CopyTextureRegion, so the GPU sampled stale texels until a subsequent use. 2. **Redundant copy on the next unchanged submission:** because defer_host cleared dirty before Step::Texture ran efresh (which set dirty = true again), the next submission recorded and executed an extra CopyTextureRegion even when nothing had changed. ### Fix - Move the CopyTextureRegion for title-written textures into HostList::prelude(), which runs immediately after un_deferred() has refreshed staging buffers for the submission. - Staging::take_upload() atomically checks and clears (!uploaded || dirty) at prelude time, so unchanged textures still skip the GPU copy (and barrier transitions) while changed textures upload on the **same** submission. - Add two D3D12 regression tests in crates/victory-gpu/src/texture.rs: - _changed_texture_uploads_on_the_same_submission - wo_lists_in_one_submission_do_not_drop_the_next_upload ### Verification - cargo clippy -p victory-gpu --all-targets --locked -- -D warnings — clean - cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings — clean - cargo test -p victory-gpu --locked — 112 passed, 0 failed (also verified --features diagnostics) - cargo test -p xtask --locked — 4 passed, 0 failed
texture::upload previously checked Staging::dirty at command-list recording time, before Staging::refresh ran at submission. Once a title-written texture became clean (after an unchanged submission, or after a multi-list submission where Batch::texture_due skipped the second refresh while the second defer_host cleared dirty), the next CPU update skipped CopyTextureRegion and sampled stale host texels until a subsequent use; conversely, a changed texture left dirty=true after submission and forced a redundant GPU copy on the next unchanged submission.

Move CopyTextureRegion into HostList::prelude() right after run_deferred() refreshes staging buffers, so unchanged textures skip GPU copies and changed ones upload on the same submission. Add two D3D12 regression tests covering both cases.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:35:49 +00:00
github-bot referenced this pull request from a commit 2026-11-26 03:40:07 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 21:37 UTC · original

Independent test run on commit 231b835 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 498 passed, 0 failed, 7 ignored (victory-gpu: 112 passed, 0 failed, 1 ignored; victory-shader: 210 passed, 0 failed, 2 ignored)
  • Not tested: live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 21:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7145172724) Independent test run on commit `231b835` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 498 passed, 0 failed, 7 ignored (`victory-gpu`: 112 passed, 0 failed, 1 ignored; `victory-shader`: 210 passed, 0 failed, 2 ignored) - **Not tested:** live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-24 22:57 UTC · original

I tested this on Linux (RTX 4080, Proton Experimental) against the startup flicker from #39. The tree was 1684989 with #63 and upstream's #1524 applied.

The measure is a count of presented frames that repeat a frame from up to six frames back while differing from the frame just before. Each run is 30 s, with every second frame captured from 100 to 600:

Build Returns
#63 alone 12 to 13
#63 and this PR 0
#63, with the record-time skip in texture::upload switched off locally so the copy is always recorded 0

With #63 alone, every repeat that is left has the same cause. The title draws one Bink slot in two frames in a row. The second refresh finds it unchanged and clears dirty. One cycle later, the next list that uses that slot skips the copy, although its own refresh has already detiled the new picture into staging, so the screen shows the previous cycle's picture. In the run I looked at, each exact repeat comes four frames after such a break in the ring order. This PR records the copy after the refresh, and that removes them.

There is also something in the world, from one run of each build, so take it as a lead. In the prison cell, with the skip switched off, the left wall, the window frame and the posters all render. With the skip on, the left wall is missing (the horizon shows through it) and the posters come out in blocks. With this PR the window frame renders, but the left wall is still missing and the main character's shirt is dark. A changed texture may have a second way to miss its copy that this PR doesn't cover. I haven't found it yet. #168 also reports walls missing in the first room.

Thanks to @⁠adritoyalser for the fix, to @⁠arminkhaleghirod for tracing the flicker to the texture guard in #39 and #63, and to @⁠fxceless for the fork.

**@⁠brunofgmag** on GitHub · 2026-11-24 22:57 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7146838511) I tested this on Linux (RTX 4080, Proton Experimental) against the startup flicker from #39. The tree was 1684989 with #63 and upstream's #1524 applied. The measure is a count of presented frames that repeat a frame from up to six frames back while differing from the frame just before. Each run is 30 s, with every second frame captured from 100 to 600: | Build | Returns | |---|---| | #63 alone | 12 to 13 | | #63 and this PR | 0 | | #63, with the record-time skip in `texture::upload` switched off locally so the copy is always recorded | 0 | With #63 alone, every repeat that is left has the same cause. The title draws one Bink slot in two frames in a row. The second refresh finds it unchanged and clears `dirty`. One cycle later, the next list that uses that slot skips the copy, although its own refresh has already detiled the new picture into staging, so the screen shows the previous cycle's picture. In the run I looked at, each exact repeat comes four frames after such a break in the ring order. This PR records the copy after the refresh, and that removes them. There is also something in the world, from one run of each build, so take it as a lead. In the prison cell, with the skip switched off, the left wall, the window frame and the posters all render. With the skip on, the left wall is missing (the horizon shows through it) and the posters come out in blocks. With this PR the window frame renders, but the left wall is still missing and the main character's shirt is dark. A changed texture may have a second way to miss its copy that this PR doesn't cover. I haven't found it yet. #168 also reports walls missing in the first room. Thanks to @⁠adritoyalser for the fix, to @⁠arminkhaleghirod for tracing the flicker to the texture guard in #39 and #63, and to @⁠fxceless for the fork.
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-24 23:46 UTC · original

A follow-up on the walls, with five runs in the same spot (the prison cell window, nobody touching the pad) on the same tree as before (1684989 with #63 and upstream #1524).

The cell's left wall shows up in both runs of the old path with the record-time skip switched off, so every list records its own copy. One run used stock Proton's wineserver and one a patched one. With this PR the wall is missing in all three runs: plain, with VICTORY_RELAY=2, and with a local switch that makes take_upload always return true. The last one rules out the dirty bookkeeping. Even with a copy in every prelude, the wall stays missing.

So something else in the move to HostList::prelude loses it. Two things I noticed but did not test:

  • In submit, each list's prelude() runs inside the loop over runs, and batch.flush() runs after the loop. A refresh that the batch holds back is not done yet when take_upload reads dirty.
  • The prelude moves an uploaded texture to COPY_DEST and back to its real state, and the list's own barriers are built from copy.state. I could not tell whether that still matches what the copy left behind.

The always-copy switch also showed that this PR misses some changes the old path caught: the character's shirt print and the window frame's lighting came back with it. It cost about 2.5 % per frame here (253 ms to 260 ms median with VICTORY_RELAY=2). So always recording the copy is a cheap fallback if the cause takes a while to find.

The PR does fix the flicker. Thanks again to @⁠adritoyalser.

**@⁠brunofgmag** on GitHub · 2026-11-24 23:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7147780456) A follow-up on the walls, with five runs in the same spot (the prison cell window, nobody touching the pad) on the same tree as before (1684989 with #63 and upstream #1524). The cell's left wall shows up in both runs of the old path with the record-time skip switched off, so every list records its own copy. One run used stock Proton's wineserver and one a patched one. With this PR the wall is missing in all three runs: plain, with `VICTORY_RELAY=2`, and with a local switch that makes `take_upload` always return true. The last one rules out the `dirty` bookkeeping. Even with a copy in every prelude, the wall stays missing. So something else in the move to `HostList::prelude` loses it. Two things I noticed but did not test: - In `submit`, each list's `prelude()` runs inside the loop over `runs`, and `batch.flush()` runs after the loop. A refresh that the batch holds back is not done yet when `take_upload` reads `dirty`. - The prelude moves an uploaded texture to `COPY_DEST` and back to its real state, and the list's own barriers are built from `copy.state`. I could not tell whether that still matches what the copy left behind. The always-copy switch also showed that this PR misses some changes the old path caught: the character's shirt print and the window frame's lighting came back with it. It cost about 2.5 % per frame here (253 ms to 260 ms median with `VICTORY_RELAY=2`). So always recording the copy is a cheap fallback if the cause takes a while to find. The PR does fix the flicker. Thanks again to @⁠adritoyalser.
Author
Owner

@⁠adritoyalser on GitHub · 2026-11-24 23:51 UTC · original

Thanks for the 5-run follow-up @⁠brunofgmag — forcing take_upload() to always return true is a super useful data point because it isolates the wall difference from the dirty bookkeeping.

I double-checked both points in the code:

  • batch.flush() vs prelude(): Step::Texture(staging) runs synchronously inside HostList::run_deferred() (right before list.prelude()), not inside batch.flush() (which only batches buffer Step::Refresh ranges). So staging.refresh() has already run for that list when take_upload() checks dirty.
  • Resource states in prelude(): for each uploaded texture, prelude() transitions real -> COPY_DEST in to_copy, records CopyTextureRegion, and then transitions COPY_DEST -> *first (storing *last in copy.state), or COPY_DEST -> real if the list has no states entry for it. That matches what list.list expects at entry.

That leaves two narrower differences between "always copy in list.list" and "always copy in list.prelude()":

  1. Separate command list vs inline: in the prelude path, CopyTextureRegion + COPY_DEST -> SHADER_RESOURCE run in a separate preceding command list before list.list rather than inline right before the draw/copy that uses the texture.
  2. In-flight staging writes under VICTORY_RELAY=2: if a subsequent submission refreshes the same Staging buffer while an earlier prelude's CopyTextureRegion is still in flight on the GPU, the staging buffer can be overwritten mid-copy (tracked separately in #141).

Happy to investigate further or adjust the approach if you spot anything in the logs/captures or if the maintainer prefers a different trade-off here.

**@⁠adritoyalser** on GitHub · 2026-11-24 23:51 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7147877905) Thanks for the 5-run follow-up @⁠brunofgmag — forcing `take_upload()` to always return `true` is a super useful data point because it isolates the wall difference from the `dirty` bookkeeping. I double-checked both points in the code: - **`batch.flush()` vs `prelude()`:** `Step::Texture(staging)` runs synchronously inside `HostList::run_deferred()` (right before `list.prelude()`), not inside `batch.flush()` (which only batches buffer `Step::Refresh` ranges). So `staging.refresh()` has already run for that list when `take_upload()` checks `dirty`. - **Resource states in `prelude()`:** for each uploaded texture, `prelude()` transitions `real -> COPY_DEST` in `to_copy`, records `CopyTextureRegion`, and then transitions `COPY_DEST -> *first` (storing `*last` in `copy.state`), or `COPY_DEST -> real` if the list has no `states` entry for it. That matches what `list.list` expects at entry. That leaves two narrower differences between "always copy in `list.list`" and "always copy in `list.prelude()`": 1. **Separate command list vs inline:** in the prelude path, `CopyTextureRegion` + `COPY_DEST -> SHADER_RESOURCE` run in a separate preceding command list before `list.list` rather than inline right before the draw/copy that uses the texture. 2. **In-flight staging writes under `VICTORY_RELAY=2`:** if a subsequent submission refreshes the same `Staging` buffer while an earlier prelude's `CopyTextureRegion` is still in flight on the GPU, the staging buffer can be overwritten mid-copy (tracked separately in #141). Happy to investigate further or adjust the approach if you spot anything in the logs/captures or if the maintainer prefers a different trade-off here.
Author
Owner

@⁠ericomeehan on GitHub · 2026-11-25 00:15 UTC · original

brunofgmag's flicker counts on #39 make a strong case for moving the uploads into prelude().

A heads-up on overlap: #272 changes the same record-time block in texture.rs (the two don't merge textually). With it, a submission counts as reading a texture's staging buffer only when it recorded a real CopyTextureRegion (defer_texture(staging, uploads) and note_upload_fence after the submission's signal), so a later detile waits for that submission only when the contents changed. With the copy moved into prelude(), that marking would need to move there too (set where take_upload() returns true), or detiles under VICTORY_LATE_WAIT/VICTORY_RELAY could again overwrite staging that a submission still in flight copies from. Whichever lands second will need to carry that over; a rebase on #272, or comparing notes with fffluffy-dev, might be the easiest route.

Written with an AI assistant (Claude).

**@⁠ericomeehan** on GitHub · 2026-11-25 00:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7148319619) brunofgmag's flicker counts on #39 make a strong case for moving the uploads into `prelude()`. A heads-up on overlap: #272 changes the same record-time block in `texture.rs` (the two don't merge textually). With it, a submission counts as reading a texture's staging buffer only when it recorded a real `CopyTextureRegion` (`defer_texture(staging, uploads)` and `note_upload_fence` after the submission's signal), so a later detile waits for that submission only when the contents changed. With the copy moved into `prelude()`, that marking would need to move there too (set where `take_upload()` returns true), or detiles under `VICTORY_LATE_WAIT`/`VICTORY_RELAY` could again overwrite staging that a submission still in flight copies from. Whichever lands second will need to carry that over; a rebase on #272, or comparing notes with fffluffy-dev, might be the easiest route. Written with an AI assistant (Claude).
Author
Owner

@⁠brunofgmag on GitHub · 2026-11-25 00:23 UTC · original

Thanks for checking both points, @⁠adritoyalser. I added a local switch at the end of upload() and ran it again at the same spot with nobody touching the pad. Each run lasts 200 s on an RTX 4080 with Proton Experimental. Both textures that go missing here, the cell's left wall and the window's chain-link fence, show up again once the copy is back in list.list. They come back for different reasons, though.

Tree A is the one from before: 1684989 with #63, upstream #1524 and this PR. Tree B is 2119b0e with this PR, #343, #256, #95, #231, #257 and #187.

What upload() does besides deferring the prelude copy Tree Relay Fence Left wall
nothing (this PR as is) A, B off, 2 missing missing (4 runs)
ensure_state(list, resource, COPY_DEST) only, no copy in the list A off there missing, plus orange streaks on the frame
ensure_state + record_copy(&list.list, texture), prelude copy kept A off there there
the same, with the prelude copy skipped (the old path) A off there there
ensure_state + record_copy, prelude copy kept B off there there
ensure_state + record_copy, with or without the prelude copy B 2 there missing

The wall reading is the mean brightness of the frame's left strip in the last captured frames. It is 3 to 60 where the wall is drawn and 140 to 240 where the sky shows through.

So the fence needs only the list to know the texture's state. That points at the prelude's barriers for a texture the list has no states entry for, even though the sequence reads right in the code. The wall needs the copy itself to sit at the first-use point inside the list. A prelude copy, even one made on every submission, does not bring it back. My guess, which I have not checked, is that the list writes that texture on the card before it samples it (a clear or a copy into it), and the old in-list copy overwrote that with the title's contents. The prelude copy runs first and loses to it.

The relay is a separate problem. With stage 2 the wall is missing even with the copy in the list, so it is not this PR's doing. It may be the in-flight staging overwrite from your point 2 (#141, #272). In tree B the relay is the default through #187, so I'll note it there.

**@⁠brunofgmag** on GitHub · 2026-11-25 00:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7148461568) Thanks for checking both points, @⁠adritoyalser. I added a local switch at the end of `upload()` and ran it again at the same spot with nobody touching the pad. Each run lasts 200 s on an RTX 4080 with Proton Experimental. Both textures that go missing here, the cell's left wall and the window's chain-link fence, show up again once the copy is back in `list.list`. They come back for different reasons, though. Tree A is the one from before: 1684989 with #63, upstream #1524 and this PR. Tree B is `2119b0e` with this PR, #343, #256, #95, #231, #257 and #187. | What `upload()` does besides deferring the prelude copy | Tree | Relay | Fence | Left wall | |---|---|---|---|---| | nothing (this PR as is) | A, B | off, 2 | missing | missing (4 runs) | | `ensure_state(list, resource, COPY_DEST)` only, no copy in the list | A | off | there | missing, plus orange streaks on the frame | | `ensure_state` + `record_copy(&list.list, texture)`, prelude copy kept | A | off | there | there | | the same, with the prelude copy skipped (the old path) | A | off | there | there | | `ensure_state` + `record_copy`, prelude copy kept | B | off | there | there | | `ensure_state` + `record_copy`, with or without the prelude copy | B | 2 | there | missing | The wall reading is the mean brightness of the frame's left strip in the last captured frames. It is 3 to 60 where the wall is drawn and 140 to 240 where the sky shows through. So the fence needs only the list to know the texture's state. That points at the prelude's barriers for a texture the list has no `states` entry for, even though the sequence reads right in the code. The wall needs the copy itself to sit at the first-use point inside the list. A prelude copy, even one made on every submission, does not bring it back. My guess, which I have not checked, is that the list writes that texture on the card before it samples it (a clear or a copy into it), and the old in-list copy overwrote that with the title's contents. The prelude copy runs first and loses to it. The relay is a separate problem. With stage 2 the wall is missing even with the copy in the list, so it is not this PR's doing. It may be the in-flight staging overwrite from your point 2 (#141, #272). In tree B the relay is the default through #187, so I'll note it there.
Author
Owner

@⁠adritoyalser on GitHub · 2026-11-25 01:29 UTC · original

Thanks for that ablation table @⁠brunofgmag — that isolates both pieces cleanly:

  1. Fence (ensure_state(..., COPY_DEST) only): recording COPY_DEST in list.list forces an inline COPY_DEST -> SHADER_RESOURCE barrier inside list.list rather than only in prelude(), which points at a prelude-only barrier interaction (possibly with vkd3d-proton or a state mismatch when a texture enters list.list already transitioned).
  2. Left wall (record_copy inline in list.list): needing the copy itself at the first-use point inside list.list (and not before the list in prelude()) strongly supports your hypothesis that an earlier command in list.list touches the texture before the first sampling draw.

And good catch separating the RELAY=2 wall loss — I just updated #141 so it only waits on actual detile() overwrites of real in-flight uploads (avoiding the settle overhead @⁠tycosnh measured there).

**@⁠adritoyalser** on GitHub · 2026-11-25 01:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/80#issuecomment-7149613554) Thanks for that ablation table @⁠brunofgmag — that isolates both pieces cleanly: 1. **Fence (`ensure_state(..., COPY_DEST)` only):** recording `COPY_DEST` in `list.list` forces an inline `COPY_DEST -> SHADER_RESOURCE` barrier inside `list.list` rather than only in `prelude()`, which points at a prelude-only barrier interaction (possibly with `vkd3d-proton` or a state mismatch when a texture enters `list.list` already transitioned). 2. **Left wall (`record_copy` inline in `list.list`):** needing the copy itself at the first-use point inside `list.list` (and not before the list in `prelude()`) strongly supports your hypothesis that an earlier command in `list.list` touches the texture before the first sampling draw. And good catch separating the `RELAY=2` wall loss — I just updated #141 so it only waits on actual `detile()` overwrites of real in-flight uploads (avoiding the settle overhead @⁠tycosnh measured there).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/80/head:github-bot/gh-80'
git switch 'github-bot/gh-80'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-80'
git switch 'github-bot/gh-80'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-80'
git switch 'github-bot/gh-80'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-80'
git switch 'main'
git merge --squash 'github-bot/gh-80'
git switch 'main'
git merge --ff-only 'github-bot/gh-80'
git switch 'main'
git merge 'github-bot/gh-80'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.