shader, host: cap early wave64 folding at 65 VGPRs, scope Batch::title_written_at, deduplicate texbacks, and forward put_off in split send #3524
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3524"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by Maverick0351a on 2026-11-30T00:26:52Z.
Summary
GF(2)-factored XOR texture tiling (
crates/victory-formats/src/texture.rs):xor_offsetis a linear parity map over GF(2):xor_offset(pattern, bits, x, y, z) = xor_axis(0, x) ^ xor_axis(1, y) ^ xor_axis(2, z).Layout::walk_xor, precompute column runs(x_combined, linear_x, byte_len)once per subresource (wherex_combined = (((x_t / bw) as usize) << bits) | xor_axis(pattern, bits, 0, x_t)), computetiled_rowandrow_xor = xor_axis(pattern, bits, 1, y_t) ^ xor_axis(pattern, bits, 2, z_coord)once per(z, y)row, and copy fixed-size 4/8/16/32-byte aligned chunks viacopy_runs_xor::<N, DETILE>.xor_offset(16 iterations of bit-mask, XOR, andcount_ones()) 16,384 to 65,536 times per 256x256 XOR-swizzled texture readback onvictory-relay.Skip redundant title-memory read on full-coverage texture readbacks & deduplicate per-flight readbacks (
crates/victory-gpu/src/texback.rs,crates/victory-gpu/src/host.rs):texback::land, when!same()and the texture's single mip covers 100% of[at, end)without padding or mip tail, skip readingsizebytes (256 KiB–512 KiB) from title memory intotiledbefore overwriting every byte inback.layout.tile(tiled, ...).read_backsandread_backs_flight, skip landing anytexture_backwhose(at, end)title allocation is overwritten by a latertexture_backin the same flight before any fence signal or bottom-of-pipe write.Forward
card_steps::put_off(VICTORY_LATE_FILLS=1) inHandoff/Host::send_publishedand graduate verified-clean constant pages (crates/victory-gpu/src/host.rs,crates/victory-gpu/src/host/card_steps.rs):VICTORY_CARD_STEPS_LEARN=1andVICTORY_LATE_FILLS=1are active,Taken::stepsincludesput_offsorun_deferredleaves those learned constant-buffer fills out during submission preparation.VICTORY_SUBMIT_SPLIT=1(publish == true),Host::submitpreviously returned early before callingcard_steps::put_off::send, andHost::send_publisheddid not carry or sendput_off. Carryput_offinHandoffand dispatchcard_steps::put_off::send+queue.WaitinHost::send_published(and callown.landed()insettlebeforerelease_scratch()).no_shader_wrote == true) across 8 landings directly to the parallel CPU fill batch (Step::Fill/wide_fills), avoiding hundreds of extraCopyBufferRegioncommands per frame for pure CPU constant buffers.Cap early Wave64 folding (
folded (before wave-wide)) at 65 console VGPRs (crates/victory-shader/src/emit/mod.rs):05d1c56enabledfolded (before wave-wide)ahead ofdeep skips,wave-wide branches, andlocal wavesso 44-VGPR tree-culling shaders (CS_Tree_BatchCull*) fold instead of flickering. However, applying early folding unconditionally to all Wave64 compute shaders folded 4 high-VGPR shaders past NVIDIA's 255-VGPR physical hardware register file limit per thread (2 * native.vgprs + 2 >= 260..314host VGPRs), causing massive register spilling to scratch memory and100–140 ms/frameGPU stalls (5–8 FPS) incardmeter:ptfx_CS_lightAtlas_Sprite(2561af9577c47289,129 -> 260VGPRs,95.97 ms/frameGPU time)ptfx_CS_lightAtlas_Trail(c06aa62112ffba4c,129 -> 260VGPRs)CS_TransmissionVolumetrics_Tiled_LocalLights(6f225b641c5b0708,156 -> 314VGPRs,41.13 ms/frameGPU time)CS_TransmissionVolumetricsSubmerged(926c46bab3b86bd6,129 -> 260VGPRs)folded (before wave-wide)onnative.vgprs <= FOLD_BEFORE_WIDE_MAX_VGPRS(65, i.e.<= 132host VGPRs) while keepingfolded (last resort)at the end ofemit_strictuncapped:CS_Tree_BatchCull*(44 -> 90VGPRs) andCS_DrawBatch(65 -> 132VGPRs) still fold beforewave-wide.ptfx_CS_lightAtlas_Spriteand_Traillower vialocal wavesat129VGPRs (0 barriers, 0 register spilling).CS_TransmissionVolumetrics_Tiled*(101and156VGPRs) andSubmerged(129VGPRs) lower via their dedicatedwide_by_defaultwave-wide path.1,271 / 1,271) translate cleanly.Preserve non-overlapping
Batch::texturesacrossBatch::title_written_at(dst, len)(crates/victory-gpu/src/host.rs):Batch::title_written_at(dst, len)previously clearedself.texturesunconditionally on every small bufferStep::Copy/Step::Placedand calledself.flush()whenever!self.due.is_empty(). Becauseself.textureswas wiped after every buffer copy, subsequent command lists in the same submission re-queued already-refreshed textures intoself.due, which then triggered a fullself.flush()of all buffer refreshes on the nextStep::Copy(25–31 flushes/frame).(start, end)title-memory span inBatch::textures(texture_due_at) and only refreshself.dueor invalidate entries inself.textureswhose title-memory range overlaps[dst, dst + len).Verification
cargo test -p victory-shader --lib(462 passed, 0 failed)cargo test -p victory-formats --lib texture(30 passed, 0 failed)cargo test -p victory-gpu --lib batch::(4 passed, 0 failed, includingtitle_writes_at_range_only_invalidate_overlapping_textures)victory.exe translateacross all 1,271 bound compute shaders (1271 emitted of 1271 compute programs)Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Maverick0351a on 2026-11-30T00:35:07Z.
Live Playthrough Telemetry (
GTA VI v1.0.2.1, RTX 5080 Laptop GPU, Driving Scene)Comparing
victory-nvidia-play-20261130-000314-53404.log(before) vsvictory-nvidia-play-20261130-003105-52456.log(after) in the same driving scene (~260 texture readbacks/sec of256 KiBand512 KiBtextures,7,355 draws/frame):read-backs and listsonvictory-relay: dropped from25.60-33.17 ms/framedown to5.81-7.99 ms/frame(4.4x faster, saving ~20-25 ms/frame onvictory-relay).copying backonvictory-relay: dropped from36.1-45.2 ms/framedown to17.5-23.1 ms/frame.65.1-72.2 msdown to56.2 ms.VICTORY_CARD_STEPS=2+VICTORY_CARD_STEPS_LEARN=1+VICTORY_LATE_FILLS=1withVICTORY_SUBMIT_SPLIT=1:Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Maverick0351a on 2026-11-30T02:45:31Z.
Follow-up Update (
8e374f6) — Verified-Clean Constant Page Graduation & ScopedBatch::title_written_atIn heavy outdoor city scenes (
~4,970indirect executions/frame,~7,500buffers/textures touched across21submissions/frame), we observed two follow-up bottlenecks when routinglate::writtenconstant-buffer pages throughput_off:Per-Landing
read_intoComparison Storm (20,292fills/frame compared at landing) & Unblocked 174 MB Root-UAV Constant Heap:VICTORY_CARD_STEPS_LEARN=1is active without graduating clean pages,note_flight_landedcallsread_intoon every constant-buffer fill in every flight forever (20,292.2 fills on the CPU compared at landingper frame, adding~14 ms/frameonvictory-relay).0.00 submissionsare refused,card_stepsaccepts the main render submission (5,161fills) and routes every fill from the 174 MB shader-writable constant heap throughStep::CopyBufferon the GPU (3,741.3 copies into the buffer betweenper frame) even for constant pages that have never been late-written.8e374f6): Track a per-page clean-landing counter incard_steps::late(backed by anRwLock<LateLearn>) that graduates 4 KiB pages afterCLEAN_THRESHOLD = 8consecutive verified-clean landings (late::verified_clean), skipping further landingread_intocomparisons unless a dirty write is detected. InHost::fill_is_titles, allow non-shader constant fills whose pages arecard_steps::late_verified_clean(src, src + len)and!watch::landed_lately(src, len, 600)to take the fast direct upload path instead ofcard_stepsGPU staging. Also elevatevictory-late-fillstoTHREAD_PRIORITY_HIGHESTwith a short spin beforeWaitForSingleObject.Full-Batch
Batch::title_written()Flush on Every SmallStep::Copy/Step::Placed:Batch::title_written()unconditionally calledflush_fills,flush_refreshes, andself.ahead.clear(), forcing32–46full refresh flushes per frame (23–32 ms/frame).3ab89f4/8e374f6): ScopeBatch::title_written_at(dst, len)to the written[dst, dst + len)range soflush_fillsandflush_refreshesonly run when a pending fill or refresh actually overlaps[dst, dst + len), andself.aheadonly evicts overlapping entries.Live Telemetry (
victory-nvidia-play-20261130-023708-52468.log, RTX 5080 Laptop GPU)57–67 FPSinternal (median 14.6–15.8 ms,0 over 100 ms),5–8refresh flushes/frame (2.8–5.6 ms),0.6–2.6 ms/frametotal landing time onvictory-relay.4,972indirect executions/frame,1,373mesh pipelines/frame):VICTORY_CARD_STEPS_LEARN:0.0 fills on the card and 0.0 on the CPU compared at landingafter the first 8 landings (down from20,292.2comparisons/frame),0.00 submissions waited for a learned page,2 pages learned; 27.0 fills in 7.00 submissions done when the card got to them (VICTORY_LATE_FILLS).VICTORY_CARD_STEPS=2:125.9–136.1 fills/frame(33.4 copies into the buffer between,51.8 KB) instead of5,161 fills/frame(3,741.3 copies), with0.00 submissions refused and waited(0.0–0.1 ms waiting for flights, down from69–82 ms/frame).preparing per frame, the submitting thread:33.5–41.9 ms/frame(down from151.3–171.6 ms/frame— a~3.8xspeedup in outdoor frame preparation).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by davemathews12 on 2026-11-30T05:15:04Z.
On the texture part. The
copy_runs_xorfast path looks correct:chunk_sizerequires every body run to have the same length and a column offset that is a multiple of it.tiled_rowandrow_xorare checked to be multiples of N.(tiled_row + (x_off ^ row_xor)) / N == tiled_row / N + ((x_off / N) ^ (row_xor / N)).Three suggestions:
xor_offsetitself on top ofxor_axis, andoffset()usesxor_offset. That makes the existingxor_modes_tile_where_offset_pointscompare the new code with itself. Only the golden digests (render_xor_water_*) stay independent, and they cover one mode (64KB_R_X, 4-byte). A test that pinsxor_axisto the per-bit definition would fix that: XOR of the three axis parts == parity of(x & px) ^ (y & py) ^ (z & pz)per bit, for everyXOR_PATTERNSentry. The element-by-element test from the #2543 comment would also apply here.card_steps,put_off, texback dedup) and a shader one (the wave64 VGPR cap inemit/mod.rs). Each is easier to review, bisect and revert on its own.walk_xor.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T13:31:44Z.
We ran a test of this PR on current main (
41adb551with this PR merged, headfc05a1b5), on a CPU-bound machine: seven 150 s runs among seven main runs, in two rounds (ABBA), with a preload made for each build (this PR changes the translator).CPU preparation is lower in all seven runs. Light-view seconds only (the idle camera's lighter views, about 7,500 draws a frame), each run against main's runs of its round interpolated in time:
On these views fps moves less than preparation does, as other limits take over.
The heavier view gains the most. The idle camera also spends 5 to 55 s of each run on a heavier view (about 15,000 draws a frame). There, every PR run was faster than every main run:
These are fewer seconds per run (10 to 50 s for the PR, 5 to 55 s for main), so take the size with care, but the direction held in all fourteen runs.
Threads: the relay thread was landing 37.4 ms a frame on average with this PR against 41.3 on main, and the submitting thread's refreshes took 19.7 ms against 21.0 (medians of the 5 s lines, means over the seven runs).
Picture: in round 1, two frames out of 240 had vegetation near the camera missing for one frame (palms, potted plants and a bush; the islands further away stayed), back in the next frame. Round 2 was clean (0 in 320), and main's runs in both rounds were clean too (0 in 560). We see the same one-frame gap on main about once in 4,000 frames, and about once in 600 frames on builds of other PRs from the same base (#1165), so we cannot pin it on this PR. With 2 in 560 it is worth keeping an eye on, because skipped or deduplicated readbacks could leave the culling's lists one frame stale.
Memory: no change (in the last 100 s of each run, shared 8.2 to 9.1 GB with this PR and 8.4 to 9.5 GB on main, dedicated about 10.3 GB in both).
One caveat for round 2: the PC was in use for light browsing during part of it. The order (ABBA) spreads that over both builds, and round 2 agrees with round 1.
Setup:
41adb551, against41adb551itself, each with a preload made with these settings;AI Assisted
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:51:23Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed