Skip to content

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

Open
adritoyalser wants to merge 1 commit into
fxceless:mainfrom
adritoyalser:fix/prelude-texture-upload
Open

adritoyalser wants to merge 1 commit into
fxceless:mainfrom
adritoyalser:fix/prelude-texture-upload

Conversation

@adritoyalser

Copy link
Copy Markdown

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.
@adriaespii

Copy link
Copy Markdown

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.

Korsuma added a commit to RicerBoy/DropItLikeItsHot that referenced this pull request Nov 24, 2026
… (#82), core/VRAM scaling (#49/#38/#42/#45/#47), scatter batching (#108), prelude textures (#80), and shader/UAV fixes

Integrates 15 upstream PRs orthogonal to Issue #2's default speed-switch measurements:
- GPU culling & compute cap:
  - Marvisak/VIctory#1731: real host D3D12 occlusion queries (wired into read_backs for both sync execute and async VICTORY_RELAY/LATE_WAIT flights)
  - fxceless/victory-fork#82: hardware depth-bounds test pass-through in pipelines and command lists
  - fxceless/victory-fork#66: lower default compute shader loop cap (4096 -> 256)
- CPU multicore, streaming & memory/VRAM scaling:
  - fxceless/victory-fork#49: scale shadow, pipeline (keeping VICTORY_PIPELINE_THREADS override), and DirectStorage workers with CPU cores
  - fxceless/victory-fork#38: default-on parallel host-copy refreshes on >=4 logical CPUs (VICTORY_WIDE_REFRESH=0 opts out)
  - fxceless/victory-fork#108: batch adjacent zero-page unmaps in XMemMapPhysicalPagesScatter
  - fxceless/victory-fork#67: release directly indexed buffer ranges with their heap
  - fxceless/victory-fork#42, #45, #47: auto-scale card buffers, texture staging/floor, and snapshot/scratch/list pools from VRAM and RAM
- Rendering smoothness & correctness:
  - fxceless/victory-fork#80: upload dirty title textures in HostList::prelude
  - fxceless/victory-fork#114: mirror placed unordered texture views onto host textures
  - fxceless/victory-fork#121: preserve VGPR slots observed by relative reads
  - fxceless/victory-fork#122: recompute ISG1 input usage and barycentrics flag after bitcode opt
  - fxceless/victory-fork#112: fix DXIL signature ordering for packed semantics

Verified:
- cargo xtask policy --staged: 21 files ok
- cargo clippy --workspace --all-features --lib --tests -- -D warnings: 0 warnings
- cargo test --workspace: 0 failures (140 victory-gpu incl. host occlusion query + depth-bounds tests; 226/226 victory-shader)
- Live 2560x1440 run (RTX 4080, VICTORY_RELAY=2 + VICTORY_INPLACE=1): reached 3D world (frame 1285), 77 in-place windows (364 MB, 0 refused), 0.0 ms texture remap waits, 0 crashes, 0 D3D12 errors

Fixes #10
@brunofgmag

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

@adritoyalser

Copy link
Copy Markdown
Author

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 GPU: wait before overwriting an in-flight texture staging buffer under VICTORY_LATE_WAIT/RELAY #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.

@ericomeehan

Copy link
Copy Markdown

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).

@brunofgmag

Copy link
Copy Markdown

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.

VlREX added a commit to VlREX/victory-fork that referenced this pull request Nov 25, 2026
…uploads

Credit NuraadGit (fxceless#159), ryotdev (unlocked reads), adritoyalser (fxceless#80), arminkhaleghirod (fxceless#39/fxceless#63), and brunofgmag (geometry A/B). Preserve inline placement for correctness testing. Native validation pending.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants