GPU: a submission's texture checks run several at a time (VICTORY_WIDE_TEXTURES=1) #768
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!768
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-768"
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?
@KyleS98 on GitHub · 2026-11-25 07:04 UTC · original
KyleS98:perf/wide-texture-refresh→main· +203 −3 · 3 files · 8 commits · openWhile the world streams in, a submission checks hundreds of textures one after another on the submitting thread. Each one is read, hashed whole and, if it changed, detiled into its staging buffer. On the opening cutscene and the first world minutes, that's the frame line's "textures" at 100–1,400 ms per frame (250–930 MB), so the cutscene plays at 0.3–2 fps.
Change (opt-in,
VICTORY_WIDE_TEXTURES=1)Batch::textures_due) instead of being run inline.shadow::wide_run).Batch::texture_due), so no two threads check the same one. Read buffers are per-thread, and the remap guard is a shared lock.Measurements
RTX 3090 Ti + Ryzen, Windows 11, diag build of this branch on
8dd30ab, retail title, Series X profile. One launch per configuration, average over the frames between the first world frame and the steady state:VICTORY_WIDE_TEXTURES=1VICTORY_TEXTURE_NO_WAIT=1VICTORY_TEXTURE_NO_WAITaddresses, and the two complement each other: together the slow phase runs at about twice the default frame rate.cargo test -p victory-gpu --lib batch: 4 passed (1 ignored benchmark).cargo clippy -p victory-gpu --all-targets: no new warnings.If these numbers hold on other machines, both switches look like candidates to turn on by default. I've left that to you.
AI-assisted (Claude Code, Claude Opus 5.5). No game data attached.
🤖 Generated with Claude Code
@SkillIssueXO on GitHub · 2026-11-25 13:15 UTC · original
I reviewed
19546ddon0b0074ewith Claude while preparing a Series X test. There is a submission-order dependency whenVICTORY_LEVELS_ON_DEMAND=1andVICTORY_WIDE_TEXTURES=1.The texture upload path queues
defer_texture(staging)followed by a host closure that passesstaging.detiledtoOnDemand::uploaded. That mask determines which mip tiles to back before the recorded texture copies run.Step::Hostexecutes immediately, so with the queued refresh it can see the prior mask or zero. The later flush can detile the newly available levels after the tile-backing decision has already been made.Flushing pending texture refreshes before
Step::Hostpreserves that dependency and keeps buffer refresh ordering intact. I have staged this change locally. This finding is from source review. A matched runtime comparison is pending. No game data attached.@grosterr on GitHub · 2026-11-25 13:25 UTC · original
Bug report with a fix:
VICTORY_WIDE_TEXTURES=1together withVICTORY_LEVELS_ON_DEMAND=1leaves some textures black or stale, because a queued texture check runs after the host step that maps its tiles.Setup: RTX 3060 12 GB (driver 621.40), Ryzen 7 5700X, 32 GB, Windows 11, release build. Tree: #770's stack
d034ac1(which carries this PR) + maina253706. AI-assisted (Claude Code); the runs and observations are mine.A/B, same save, prologue bedroom:
LEVELS_ON_DEMAND=1 EARLY_TEXTURES_MS=40 TEXTURE_NO_WAIT=1 WIDE_TEXTURES=1WIDE_TEXTURESVICTORY_STAGING_POOL=0did not change F0's picture, so the staging pool is not involved.Cause. For a texture with levels on demand,
texture::uploadrecords two steps in a row (texture.rs, end ofupload; line 704 on this PR's head):list.defer_texture(staging.clone())→Step::Texture: the check that detiles into the staging buffer (and records which levels it holds);list.defer_host(...)→Step::Host: maps the tiles for those levels (on_demand.uploaded(...)with the levels just detiled).With this PR,
run_deferredno longer refreshes onStep::Texturebut pushes it tobatch.textures_due, which is drained at the next flush (beforeStep::Run, before copies, at the end).Step::Hostdoes not flush. So step 2 runs before step 1: it sees no detiled levels or those of an earlier check, the tiles are not mapped (or mapped for the wrong levels), and the list'sCopyTextureRegioninto unmapped tiles is dropped by the card.Fix (in
HostList::run_deferred): drain the queue before a host step, which gives the same order as without the switch:fn run_steps(steps: &[Step], batch: &mut Batch, wide: bool), withrun_deferredcalling it withwide_textures().queued_textures_refresh_before_host_stepdoes the following:texture::uploadfollowed by a host step that reads the texture-refresh byte counter;wide = true;wide_runbranch).WIDE_TEXTURESnothing changes: the queue is always empty then.I have it as a commit with the test and can open it as a PR against this branch or against main, whichever you prefer. F0x (10 minutes): no device loss; steady 330 ms a frame (3.0 fps, p90 380 ms) on this card, against 380 ms (p90 479 ms) for F0 with the broken textures.
@tikD1337 on GitHub · 2026-11-25 13:41 UTC · original
We tried an almost identical change before seeing this PR (texture refreshes due in a row queued and run on
shadow::wide_run, wall-clock accounting), and on our machine it measured worse and showed artifacts. Sharing in case it helps, with the caveats below.Setup: RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600 (6 cores / 12 threads), 32 GB, Windows 11. Base
2119b0e+a803c87, plus a local patch of ours that hashed recently changed view-memory textures every frame, with 9 pipeline workers. Release build, warm cache,VICTORY_RELAY=2 VICTORY_WIDE_REFRESH=1. Opening cutscene, one launch per configuration, medians over frames with more than 1000 draws:With the switch on, the player saw texture artifacts that did not appear without it: a character's face turning black, hair drawn in the wrong place, a building missing near the end of the cutscene.
Caveats: an older base than yours, our own texture-hash patch on top (its "hash every check while recently changed" rule may interact with the queueing), and a 6-core CPU that was also running 9 pipeline workers. We did not find the cause. The write-watch journal is a global mutex, so per-thread state is not it. The texture MB per frame rising 2.5× suggests more textures were re-read with the switch on. It might be worth checking that metric on your side too.
@KyleS98 on GitHub · 2026-11-25 18:09 UTC · original
Thanks @grosterr and @SkillIssueXO, that's a real ordering bug and your diagnosis is right: the host step that maps the tiles ran before the queued check that records which levels it detiled.
I've pushed your fix as
4cb2bc6:run_deferreddrainstextures_duebefore aStep::Host, so withVICTORY_WIDE_TEXTURES=1the steps run in recorded order, as they do without the switch. I didn't take therun_stepssplit or the test. @grosterr, if you'd like your test in, a PR againstperf/wide-texture-refreshis welcome and I'll merge it.Checked on an RTX 3090 Ti with your F0 switches (
LEVELS_ON_DEMAND=1 EARLY_TEXTURES_MS=40 TEXTURE_NO_WAIT=1 WIDE_TEXTURES=1), Series X profile, warm cache, one 7-minute run from boot into the cell:@tikD1337, thanks for the numbers. Your setup differs in ways that matter here (a per-frame texture-hash patch of your own and 9 pipeline workers on 6 cores), so I can't tell from it whether the queue itself costs time on your machine. The bug above could also explain the black face you saw. If you try again on
4cb2bc6without your hash patch, the "texture MB / frame" line with and without the switch would show whether more textures get re-read.AI-assisted (Claude Code, Claude Opus 5.5).
@Ahmet-Dedeler on GitHub · 2026-11-25 18:46 UTC · original
Numbers from a very different host, since tikD1337 saw it get worse. I tried nearly the same idea on an M5 Max under CrossOver + D3DMetal (all CPU work goes through Wine and Rosetta): one job per due texture on
shadow::wide_run, 8 workers, pending jobs flushed before every step that writes title memory. One run against a baseline run with the same switches, frame lines from 120-330 s of the opening:No visual problems in the captured frames. So on this host it takes the texture time out of the way, but the frame is limited by something else. Copy-back and GPU time went up in the same window (+152 and +46 ms median), though those are noisy with two different playthroughs and one run each.
@tikD1337 on GitHub · 2026-11-25 20:51 UTC · original
Re-tested on your head
4cb2bc6, merged ontoorigin/maind510ee4with no local patches of ours.ASYNC_SUBMIT QUEUE2 TEXTURE_NO_WAIT WIDE_REFRESH JOIN_PARTS BACK_OWN_VIEW.VICTORY_WIDE_TEXTURES=1and one without.VICTORY_LEVELS_ON_DEMANDwas never set, here or in our earlier test.Means of the frame line's readings (world readings only, more than 1,000 draws a frame); median frame from the frame log's per-frame times:
WIDE_TEXTURES=1Since
VICTORY_LEVELS_ON_DEMANDwas never on in our runs, theStep::Hostordering bug fixed in4cb2bc6cannot explain the black face we reported earlier. One run each, so treat the frame times as indicative only.@KyleS98 on GitHub · 2026-11-26 01:27 UTC · original
@grosterr your regression test is merged into this branch (
b842aa5, from your PR against my fork).queued_textures_refresh_before_host_steppasses here on the RTX 3090 Ti, and it carries therun_stepssplit it needs. Thanks for following through on it.AI-assisted (Claude Code, Claude Fable 5.2).
@KyleS98 on GitHub · 2026-11-26 07:11 UTC · original
@DoubleD17 you are right: the workers added their own time to the shared counter and the batch subtracted the excess afterwards, so a drain between the two could wrap it. @gmankab had sent the fix against my fork and it is merged here (
7521f3a): the workers only count bytes now, and the batch adds its wall-clock time once afterwide_runreturns. Nothing is subtracted any more.Also merged: @Lilith133T's regression test
host_callback_sees_the_preceding_texture_refresh(the fix it guards was already here as4cb2bc6). The branch is merged up tomain46bf535; head is4c234f4.Checked on an RTX 3090 Ti: both ordering tests pass with
VICTORY_WIDE_TEXTURES=1, and a 270 s Series S run with the switch, from boot into the prologue, ended without a crash or device loss.@tikD1337 thanks for running it again without your patches. I cannot explain the extra texture megabytes you measured in the cutscene (+47%): the queue should refresh the same textures as before, only on other threads. Until that is understood this should stay what it is, an opt-in switch, and I am not claiming a frame-time gain from it on other machines. Agreed too that the host-step ordering cannot be behind the black face you saw, since levels on demand were off in your runs.
AI-assisted (Claude Code, Claude Fable 5.2).
@DoubleD17 on GitHub · 2026-11-25 20:50 UTC · original · reviewed
The new wall-clock accounting can wrap the frame's texture-time counter. In
Batch::refresh_textures, the workers add their individual durations toPREPARING[2], and the submission later subtracts the excess after loading the sum. The presenter's meter independently drains this same atomic withswap(0). If the drain lands between the final load andfetch_sub, the latter subtracts a positive correction from the reset counter and can wrapu64. Thesaturating_subbounds the correction, while the atomic subtraction still wraps. This can corrupt thetexturesmetric used to assess this PR. Batch accounting ┬╖ Frame counter drainPlease keep the worker timing out of the shared texture-time counter and add one elapsed wall-clock contribution after
wide_runjoins. The worker jobs can still report bytes separately. This is a static review of4cb2bc6631d6691a8d511839c0ba4f99e229115a. No runtime timing was measured. Per-texture accountingAI-assisted.
@KyleS98 on GitHub · 2026-11-26 09:03 UTC · original
A correction to my comment above: the 270 s game run I cited there was made with a stale binary that did not contain this branch (several worktrees of mine share one build folder, and the last one built did not relink). The two unit tests were real. I have repeated the game run with a binary checked to be head
4c234f4(RTX 3090 Ti, Series S profile,VICTORY_WIDE_TEXTURES=1, 290 s from boot into the prologue): it ran to the end, no crash, no device loss. The Series S world is black in that run as it is on plainmainwithout #798, so this run says nothing about the picture.AI-assisted (Claude Code, Claude Fable 5.2).
@tikD1337 on GitHub · 2026-11-26 10:11 UTC · original
Re-tested your head
4c234f4(it contains main46bf535). It is a fresh build folder, and I checked that the exe is built from that commit.ASYNC_SUBMIT QUEUE2 TEXTURE_NO_WAIT WIDE_REFRESH JOIN_PARTS BACK_OWN_VIEW, nothing else, noLEVELS_ON_DEMAND.VICTORY_WIDE_TEXTURES=1and 3 without, alternating: menus, the opening cutscene, then about 40 s standing in the prison.The +47% was mostly my averaging, sorry. I had averaged the frame line's per-reading "MB/frame" over 5 s readings without weighting, so a reading of a few stalled frames counted as much as one of many fast frames. Weighted by frames (total MB over total frames):
Where the texture bytes come from. I added counters by branch of
refresh_timed(diagnostics only, one run each way):refresh_unlocked: withTEXTURE_NO_WAIT=1, a check that meets the runtime remapping reads the whole texture through the kernel, and on failure it forgets its writes. That is 25.0 MB/frame with the queue vs 20.5 without in the cutscene. In the prison the queued checks hit remap windows that the inline ones did not: 6.9 vs 0.0 MB/frame.Batch::texturesis cleared at each title write and each batch. So it is not something the queue adds.Picture. Face faults show up with the switch and without it, and are not caused by #768:
Prison frames match between the modes within run-to-run noise.
So on this machine
VICTORY_WIDE_TEXTURES=1gives a somewhat better cutscene median frame and about the same traffic. Keeping it opt-in seems right.refresh_unlocked, which reads whole textures through the kernel, is worth a look, independently of this PR.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.Merge
Merge the changes and update on Forgejo.