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