GPU: a submission's texture checks run several at a time (VICTORY_WIDE_TEXTURES=1) #768
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-25T07:04:32Z.
While 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
Imported from fxceless/victory-fork. Originally posted by SkillIssueXO on 2026-11-25T13:15:59Z.
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.Imported from fxceless/victory-fork. Originally posted by grosterr on 2026-11-25T13:25:46Z.
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.
Imported from fxceless/victory-fork. Originally posted by tikD1337 on 2026-11-25T13:41:23Z.
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.
Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-25T18:09:11Z.
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).
Imported from fxceless/victory-fork. Originally posted by Ahmet-Dedeler on 2026-11-25T18:46:33Z.
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.
Imported from fxceless/victory-fork. Originally posted by DoubleD17 on 2026-11-25T20:50:42Z.
Review: COMMENTED
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.
Imported from fxceless/victory-fork. Originally posted by tikD1337 on 2026-11-25T20:51:17Z.
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.Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T01:27:58Z.
@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).
Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T07:11:04Z.
@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).
Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-26T09:03:14Z.
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).
Imported from fxceless/victory-fork. Originally posted by tikD1337 on 2026-11-26T10:11:38Z.
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.Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-26T21:16:44Z.
I tested the parallel checks on a physical RTX 5060 Laptop 8 GB with Bazzite 44, NVIDIA 615.78.08, GE-Proton11-14 and vkd3d-proton 3.2.0. The local port retained the host-callback ordering fix. Both callback-ordering tests executed on the RTX and passed.
The same 40% Series S executable and warm seed were used for both runs. The enabled log confirmed a simultaneous texture batch. The shared heavy transition into the prison doorway showed these frame-group results:
Storage activity and draw counts differed. Both runs rendered the same doorway and stopped cleanly. This single comparison did not reproduce the transition speedup reported on Windows.
Assisted by Codex (GPT-6.2-Sol High).
Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-27T00:50:49Z.
@tikD1337 @Filip722 thank you both. Taken together your runs say more than mine did, so here is how I read them.
So it helps a little where there are processors to spare and the checks are the limit, and it can hurt where they are not. That is a reason to leave it exactly as it is here: opt-in, off by default. I would not want it in anyone's default set on the strength of my card.
@tikD1337, the counters by branch of
refresh_timedare the more useful result.refresh_unlockedreading whole textures through the kernel underTEXTURE_NO_WAIT=1(25 MB a frame in your cutscene, and the 10.5 MB a frame of textures read twice in a frame in both modes) is independent of this PR, as you say, and looks like the larger thing to go after. If you put those counters up as a PR I will run them here.The face faults you list show without the switch too, on this card as well, so I agree they are not this change's.
AI-assisted (Claude Code, Claude Fable 5.2).
Imported from fxceless/victory-fork. Originally posted by tikD1337 on 2026-11-27T11:33:47Z.
@KyleS98 Opened a separate PR with the per-branch
refresh_timedcounters: https://github.com/fxceless/victory-fork/pull/1458View 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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.