GPU: an option to refresh a texture once every N frames #2478
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!2478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2478"
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?
@HoLa-Lee on GitHub · 2026-11-25 14:25 UTC · original
HoLa-Lee:gpu/texture-refresh-stride→main· +29 −3 · 1 files · 1 commits · openWhat this is
A world that renders at a frame a second spends most of that frame reading title memory for textures. Measured on one title and machine, on the card, with docs-level counters: 24,821 texture refreshes pulling 24.8 GB of title memory in a single frame, with none of them skipped, and 6,814 ms of the frame's 7,000 ms of texture work spent waiting for that memory. The GPU did 71-72 ms in the same frame.
VICTORY_TEXTURE_REFRESH_EVERY=<n>reads a texture once every n frames at most, round-robin by the texture's own address so the frames share the work instead of one frame taking all of it:and
refresh()returnsNone(nothing changed, keep the last upload) on the frames that are not its turn.What it buys
At
VICTORY_TEXTURE_REFRESH_EVERY=8, same scene, same captures: 145-522 ms a frame instead of 2,333-6,906 ms (0.1-0.4 fps to 1.9-6.9 fps), with the picture intact - the same frame numbers captured before and after compare.What it costs
A texture's contents can lag by up to n frames. Unset, 0 or 1: nothing changes, every frame refreshes exactly as now, so this is inert for anyone who does not ask for it. It is a switch for slow machines and for measuring what the refresh costs, not a claim that every frame should skip reads - the proper fix (refresh only what the frame reads) is a larger change in draw.rs/host.rs.
Changes since the last review (
a6d6afa)All four review points are in, in this push (
c8d6571):diagnosticsfeature, like the otherVICTORY_*switches incapture.rsandpipeline.rs. A build that ships hasdue()returningtrueunconditionally: theOnceLockand the env read do not exist there at all.refresh()intorefresh_all, beforein_parallel- a texture that is not due this frame is no longer handed to a worker thread.refresh()keeps only its own work.git diff --checkis clean and the blob starts2f 2f 21, ends0a 7d 0a.% every == 0became.is_multiple_of(every)(manual_is_multiple_of), and the parse now.filter(|&n| n > 0)s soVICTORY_TEXTURE_REFRESH_EVERY=0is "every frame" rather than something to reason about. Thanks @kotekompotek and @kais7654 - both of your points are the same two lines.Checked
cargo check -p victory-gpu(default features): okcargo check -p victory-gpu --profile diag --features diagnostics: okcargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: 0 warningscargo test -p victory-gpu --lib --profile diag --features diagnostics: 196 passed, 2 failed, 1 ignored - the 2 are the known#1744view-heap failures (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), which fail onmaintoo on this machine.The frame-time numbers above come from runs on the title (RTX 4080 SUPER,
VICTORY_FAST=1,VICTORY_TEXTURE_STAGE_MB=64), not from a test.@Marvisak on GitHub · 2026-11-25 16:16 UTC · original · edited 2026-11-25 20:21 UTC
Automated triage for the maintainers.
Merge candidate.
Staging::dueincrates/victory-gpu/src/texture.rsaddsVICTORY_TEXTURE_REFRESH_EVERY=N, adiagnostics-only switch. With it set, a texture is re-read from title memory at most once every N frames, with the frames assigned round-robin by the texture's address. Without the feature, or when the variable is unset, 0 or 1,due()returnstrueand nothing changes.All three points from the last triage are in
c8d6571:#[cfg(feature = "diagnostics")];refresh_allchecksdue()beforein_parallel, so textures that aren't due never reach a worker thread;The
0divide that kotekompotek found is handled by.filter(|&n| n > 0), and the modulo now usesis_multiple_of, as clippy 1.98 wants. Onmain,refresh_all's only caller is the bindless upload pass inbindless.rs, which only covers copies that already exist. A skipped texture keeps its last upload, and because its tracker isn't cleared, the change is picked up on its next due frame.Reply to the author: thanks, every point checks out against the code.
CI: not run. The workflow run for
c8d6571is waiting for a maintainer's approval (action_required).Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 16:53 UTC · original
The knob is sound as a diagnostic:
due()buckets textures by(address >> 16)againstframe::current(), so withEVERY=Neach texture reads at most once per N frames and the reads spread evenly — exactly what a "world at 1 fps" frame cost needs. Semantics are safe: skippingrefresh()leaves the last uploaded copy live, so the worst case is N frames of staleness, never a missing texture.Two nits: the file lost its trailing newline, and
EVERY=0parses to0→% 0panics —unwrap_or(1)doesn't catchOk(0).every <= 1handles 0/1 for the<= 1check butparseaccepts 0 → division by zero in the else branch. Clamp with.filter(|&n| n > 0)ormax(1).@kais7654 on GitHub · 2026-11-25 17:14 UTC · original
Tested on Windows 11, RTX 5070 Laptop GPU (driver 616.87) + WARP, rustc
1.98.1, --locked. The CI will fail as-is: clippy -D warnings rejects the
modulo line in crates/victory-gpu/src/texture.rs:555 with
clippy::manual_is_multiple_of (pinned clippy 1.98):
With that one line applied (not committed on my side), the branch is
green: clippy -D warnings clean with and without --all-features,
victory-gpu lib 193 passed / 2 failed (the heap-cap pair #1943 owns),
victory-shader lib 266 passed / 3 failed (the NVIDIA machine trio of
#2317). Merge into current main (
67e8ae1) is clean.@HoLa-Lee on GitHub · 2026-11-25 19:16 UTC · original
Both review comments are in, in
c8d6571:VICTORY_TEXTURE_REFRESH_EVERY=0no longer reaches the divide: the parse is.filter(|&n| n > 0).unwrap_or(1), so 0 and 1 both mean "every frame"; the trailing newline is back..is_multiple_of(every).cargo clippy -p victory-gpu --all-targets --all-features -- -D warningsis 0 warnings on 1.98.1 here, andcargo test -p victory-gpu --lib --profile diag --features diagnosticsgives 196 passed / 2 failed (the#1744view-heap pair, which fails onmainon this machine too).The switch is also behind
diagnosticsnow, and the due check runs inrefresh_allbeforein_parallel, so a texture that is not due is never handed to a thread.@DenRakEiw on GitHub · 2026-11-25 14:34 UTC · original · reviewed
Tested against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:cargo test -p victory-gpu texture::tests: 2/2 passed on RTX 5090 and WARP.cargo xtask policy: 183 files ok.cargo clippy -p victory-gpu --all-targets -- -D warnings):Fails with
clippy::manual_is_multiple_ofincrates/victory-gpu/src/texture.rs— using(crate::frame::current() + ((self.memory as usize >> 16) as u64)).is_multiple_of(every)will satisfy Rust 1.98 clippy-D warnings.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 14:57 UTC · original · reviewed
Refresh a texture once every N frames option. Note: this PR introduces a UTF-8 BOM (U+FEFF) at the start of texture.rs — the first line is rewritten with an invisible BOM byte sequence; please drop it, it is noise in every future diff of the file. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
@fuzeofficlal on GitHub · 2026-11-26 19:38 UTC · original · requested changes
Tested
c8d6571db41b66b6e553dc234a5d578d3dee215emerged ontoorigin/main(63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP,--features diagnosticswithVICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).Default builds (without
diagnostics),VICTORY_TEXTURE_REFRESH_EVERYunset /0/1,cargo xtask policy, andcargo clippy --locked -p victory-gpu --all-targets [--all-features] -- -D warningsare all clean.Blocking Issue:
Staging::due()skips the initial upload of newly created and evicted-then-remade texturesStaging::staging()(crates/victory-gpu/src/texture.rs:781-842) does not perform an initial upload —refresh_all()(L519-533) is the only path that detiles and uploads a texture's title memory into its hostID3D12Resourcefor the first time.Because
Staging::due()(L549-565) checks(crate::frame::current() + ((self.memory as usize >> 16) as u64)).is_multiple_of(every)unconditionally whenevery > 1, any newly created texture (or texture evicted byresource::evictand later recreated) whose address residue does not match the current frame is skipped on its very first frame (uploads == 0):0x00000000) for up toN - 1frames (or permanently for one-shot textures).crate::placementtexture heaps do not even start zeroed (as noted attexture.rs:640-641) and sample whatever stale texels previously occupied that heap range until their due frame arrives.Hardware Repro (
--features diagnostics,VICTORY_TEXTURE_REFRESH_EVERY=8)Created 16 brand-new committed
4x4DXGI_FORMAT_R8G8B8A8_UNORMtextures initialized with0xDEAD_BEEFin title memory, ranrefresh_all(&work)+record_upload, and read back a skipped texture on the GPU:uploaded_first_frame=0,skipped_first_frame=16;uploads(tex[0]) == 0, GPU readbackpixel[0] = 0x00000000(expected0xdeadbeef).uploaded_first_frame=4,skipped_first_frame=12;uploads(tex[1]) == 0, GPU readbackpixel[0] = 0x00000000(expected0xdeadbeef).Suggested Fix
Allow the initial upload unconditionally when
self.uploadsis still0, and only apply the every-N-frames throttle to subsequent refreshes (crates/victory-gpu/src/texture.rs:560):Verified this 1-line fix locally on both RTX 5090 and WARP (
--features diagnostics,VICTORY_TEXTURE_REFRESH_EVERY=8):uploads == 1).(frame + (memory >> 16)).is_multiple_of(8)refresh (actual_due == expected_due:6/16on RTX 5090,0/16on WARP), keeping the intended steady-state throttling while ensuring no texture is ever sampled uninitialized.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.