GPU: parallelize CARD_COMPARE (64 threads per 64 KiB piece) #71
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!71
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-71"
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?
@MartinIndra02 on GitHub · 2026-11-24 21:09 UTC · original
MartinIndra02:perf/fxceless-parallel-card-compare→main· +120 −25 · 2 files · 1 commits · openSummary
Two targeted GPU/relay performance improvements in \ictory-gpu:
*Dedicated D3D12 \COPY\ queue for \Host::relay_card_back* (\VICTORY_RELAY_COPY_QUEUE=0\ disables it, graceful fallback to the direct queue):
elay_card_back\ submitted its \CopyBufferRegion\ readback list onto the main \DIRECT\ graphics queue (\Host::queue) behind all queued in-flight rendering submissions and blocked on \WaitForSingleObject.
Parallelize \CARD_COMPARE\ (one 64-thread group per 64 KiB piece):
RTX 3080 A/B Measurement (Windows 11, 10 GB)
Same runtime switches (\VICTORY_RELAY=2, \VICTORY_CARD_BUFFERS_MIN_MB=1, \VICTORY_CARD_BUFFERS_MB=2048, \VICTORY_CARD_REHASH_RUNS=1, \VICTORY_WIDE_BACK=1, \VICTORY_WIDE_MERGE=1, \VICTORY_LATE_WAIT_LISTS=256, \VICTORY_SHADER_LOOP_LIMIT=256):
4e17478\ (DIRECT queue)Verification
AI-assisted contribution (code and tests authored/verified with an AI coding assistant).
@dkdknight on GitHub · 2026-11-24 21:33 UTC · original
Tested on an RTX 5080, merged with #81, #77 and #38: 3.7 → 4.9 fps at the same spot, GPU time halved. One correctness concern about the copy queue below.
Setup: NVIDIA GeForce RTX 5080 16 GB, driver 621.14, i9-13900KF, 64 GB, Windows 11 26200, release build, Series X profile.
VICTORY_DISPLAY_MODE=1920x1080 VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024. Both runs loaded the same save, and the character stood still at the same spot. Medians over 20 frame lines (~2 min) once texture uploads had settled.4e174784e17478+ #71 + #81 + #77 + #38CARD_COMPARE.1684989, without the parallel compare, kept the fetches in queue order and removed their wait (copying back 189 → 50 ms). The frame did not get faster (269 → 286 ms), because the card became the limit (73 → 91 % busy). So on this card the frame gain above most likely comes from the parallel compare.Concern: the copy queue can read a piece a later flight is still writing
order_afterkeeps later sends of title bytes out of the merge. It does not cover later flights' shader writes: the fetch can read a piece that a running flight has only partly written.card_merge_relaytakes those bytes as shader writes, and they go into title memory and into the CPU side.An alternative that keeps the queue order: the flight copies the pieces its compare flagged into a PC-memory ring itself, behind the compare in its own list (a one-group scan that hands out slots, then a 64-thread group per piece). The landing thread then reads them with no fetch at all, and falls back to the fetch when the ring is full. On
1684989this was the 189 → 50 ms above, at the cost of about 15 ms more GPU time. With the compare now cheap, that cost may matter less. I can open it as a separate PR on top of this one.AI use: Claude Code, Claude Opus 5.5. It merged and built the branches and ran the in-game measurements on the machine above (the person at the machine played). It read this PR's code and wrote this comment.
@ryotdev on GitHub · 2026-11-24 21:34 UTC · original
I reproduced a missed GPU buffer change in the new hash reduction on
e3962cc. In a 64 KiB piece, flip the sign bit of the first 32-bit component at byte offsets 64,512 and 65,024. Each edit alone is detected. Together they cancel when lanes 0 and 32 meet at the first XOR. These are each lane's last loads, so both sign changes produce the same XOR difference in the partial hashes. The dirty flag stays zero and the runtime can skip copying changed data back.I added this case to the existing D3D12 WARP test. On Windows, the PR returned [0, 0, 0] instead of [1, 0, 0]. Mixing the right partial hash with fmix32 before combining the pair made the test pass, including the existing lane, tail and block-swap checks. A separate CPU comparison kept the old serial hash as a control: it detected the paired edit. The asset-policy check passed on 169 files. I haven't measured the frame-time cost of the fix or tested the relay copy queue.
The 15-line fix and regression test are available to cherry-pick:
github.com/ryotdev/victory-gta6@49e4a90ed0. AI-assisted. Synthetic data only.@MartinIndra02 on GitHub · 2026-11-24 21:39 UTC · original
Thanks @ryotdev and @dkdknight for the thorough reviews and RTX 5080 A/B!
@SkillIssueXO on GitHub · 2026-11-24 22:14 UTC · original
I measured actual GPU copy time separately from wall time on the stock DIRECT queue. RTX 5070 Ti (621.24), Series X,
2119b0ewithVICTORY_RELAY=2and diagnostic timing only. Across 61 consecutive gameplay frames (f1860–1920, median 5,200 draws), 428 fetch batches carried a median 36.17 MiB per frame.CopyBufferRegiontotalled 0.81 ms/frame median (1.00 ms p95). The queries were resolved behind the copies and read after the existing fetch fence.This isolates the queue/fence cost from the GPU copy execution cost on this card. It gives a baseline for testing a queue-ordered readback change. Counts and timings only. AI-assisted instrumentation and analysis (Codex).
@ericomeehan on GitHub · 2026-11-25 00:18 UTC · original
dkdknight's RTX 5080 A/B and the quick fix for ryotdev's paired-edit case make the hashing part look solid.
A heads-up on overlap: #253 makes the same group-per-piece change to the card-copy compare passes (a group-per-piece
CARD_COMPAREshader and the loop incard_beforeinhost.rs, with tests inindirect.rs), measured with an ABBA A/B. The two don't merge textually (host.rsandindirect.rs), so it may be worth agreeing with TG0000 which PR carries that part. Separately, since dkdknight's copy-queue case can leave half-written bytes in title memory, taking up your own offer to makeVICTORY_RELAY_COPY_QUEUEopt-in (=1) and splitting it into its own PR would let testers try the speed-up without that risk by default.Written with an AI assistant (Claude).
@Pin0d1 on GitHub · 2026-11-25 04:12 UTC · original
I reproduced a stale CPU word on
c57c9b0with ordered submissions. DIRECT produced 17, a later DIRECT write of 29 completed, and the delayed COPY read returned 29 for the first submission. I then restored 17 and ran the GPU comparison again. Its change flag was zero and the CPU word stayed at 29. This happened twice each on WARP and an RTX 2060 SUPER. The fixture waits for the later write to complete before starting the COPY read.Capturing the changed range on its producing DIRECT queue gave 17 in the earlier comparison. The candidate keeps COPY asynchronous by reading that capture and has a bounded fallback. The
pr71replay case runs the failing fixture directly on this PR head. Probe and transcripts · Snapshot patch and prerequisitesPrepared with the help of Codex 6.2 Astra Max.
@larelgit on GitHub · 2026-11-25 05:42 UTC · original
In-game artefacts that follow the copy queue, and numbers on the current
main(310c6ebwith its new defaults), for the queue question above.Setup. RTX 5080 16 GB (driver 610.88), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 22631, diag build, rustc 1.98.1. This PR's head (
c57c9b0) merged onto310c6ebwithout conflicts; no switches other than the ones in the table, so relay stage 2, wide copy-back and the card buffers are on asmainnow has them. Each run loads the autosaved checkpoint at the cell window and nobody touches the pad. Frame time is the spacing of therecording per framelines over 260-355 s of the run (median of 16-17 intervals), the other columns are means of the frame, card and relay lines over the same window. The scene is judged from screenshots at 300 and 350 s. One run at a time, alternating; the first run of the new binary (translating its shaders) is listed apart.310c6ebVICTORY_RELAY_COPY_QUEUE=0What went missing, with the copy queue on: in the first run the print on the back of the character's shirt (the shirt plain dark red at 300 and 350 s); in the second the chain-link mesh in the window (the window showed bare glass at 300 and 350 s); the third was intact. On
310c6ebwithout this PR the mesh and the print were there in all 13 runs I have of this scene today (this series and two earlier ones, the earlier ones with a binary of mine that copies out of title memory through the kernel or with plain loads, see #154), and in all of this PR's runs with the copy queue off. The cell walls are lost now and then in every configuration (main's own intermittent defect), so they are left out of the table.That fits @dkdknight's reading and @Pin0d1's fixture: a fetch beside later flights can land bytes a later flight wrote, and if those bytes later go back to what the compare stored, nothing fetches the piece again. I have not traced which piece it was; both things that went missing are thin alpha-tested surfaces, and each stayed missing from 300 to 350 s, so whatever went wrong was not put right by later frames.
So on this machine the parallel compare alone is worth about 10 ms a frame (151-159 against 165-166) with nothing lost, and the queue about 12 ms more (141-144). If the queue goes behind a switch (
VICTORY_RELAY_COPY_QUEUE=1) as @ericomeehan suggested, or is replaced by a capture in queue order (@dkdknight's ring, @Pin0d1's snapshot), I can run the same series on it.(Runs, measurements and this note by Claude Code with Claude Opus 5.5 on the hardware above, at the account owner's request.)
@Pin0d1 on GitHub · 2026-11-25 06:26 UTC · original
@larelgit, thanks for tracking the window mesh and shirt print separately. I rebased the DIRECT-queue snapshot onto your
310c6eb+c57c9b0build (Pin0d1/victory-fork@ef4f510). With COPY enabled, the forced-order test read back 29 on #71 and 17 with the snapshot. The producer wrote 17. This repeated twice each on WARP and an RTX 2060 SUPER.Could you alternate the original #71 build and the snapshot build at the same checkpoint, with COPY enabled for both? Three runs of each, if practical, would let us compare how often the mesh and print are present at 300 and 350 seconds. The per-run frame time and relay fetch wait would also show what the snapshot costs. Please mark the shader-compilation run separately as before.
Prepared with the help of Codex 6.2 Astra Max.
@larelgit on GitHub · 2026-11-25 06:49 UTC · original
@Pin0d1, yes, I'll run that alternation next: #71 as it is and your ef4f510, COPY on for both, three runs each plus the first run of each binary listed apart.
First, a correction to my comment above: the screenshots there are weaker evidence against the copy queue than I made them.
310c6eb, same binary and settings as that row) lost the mesh at 300 and 350 s too.Leaving first runs out, the mesh was missing in 1 of 14 runs without this PR (on
310c6eb, #154's plain copies on or off) and in 1 of 2 with this PR's copy queue on, and the print in none. That is one event on each side, so the pictures neither show nor rule out the fetch hazard. What stands is the reading ofrelay_card_back(the copy-queue fetch runs beside later direct-queue flights) and the frame times as given. With odds like these, three runs a side will say more through frame time and fetch wait than through the pictures. Your forced-order readback (29 against the producer's 17) is the stronger evidence.One more detail on that row: the "
310c6eb" binary is310c6ebwith #154's two commits andVICTORY_USER_COPIES=0, which copies through the kernel asmaindoes.(Claude Code with Claude Opus 5.5, at the account owner's request.)
@larelgit on GitHub · 2026-11-25 07:50 UTC · original
@Pin0d1, the alternation you asked for. #71 as it is (
c57c9b0merged on310c6eb) against your ef4f510, COPY on in both, same machine, checkpoint and method as my comment above. The first run of your binary, which translated its shaders, is listed apart; #71's binary was already warm.So the snapshot takes the fetch wait from about 11 ms to 4, but the frame goes from about 143 to about 198 ms, almost all of it on the card (on the GPU about +55 ms) and in the submitting thread (the card idle behind it 50-52 ms against 16-18).
The likely reason is in the allocation, not the copies. Each flown plan with something to compare gets a new card buffer for its snapshot (
self.uav_buffer(snapshot_bytes), a committed resource), and it goes with the plan when the plan is done. The memory line's "made so far" at the end of each run:Making and dropping about 85 GB of committed buffers in a six-minute run likely means the driver zeroing and paging in fresh memory all the time, besides the creation calls themselves. A pool (buffers kept by size and handed back when the plan is done, within your 64 MB limit), or a ring like #688's per-plan staging, should keep the order guarantee without that cost. #688 also snapshots only the pieces the compare found different, written by the compare itself in flight order.
On the pictures: #71's copy queue has now lost the window mesh in 2 of its 5 warm runs here (one of the two in my first series, one of the three in this one; at 300 and 350 s both times), against 1 of 14 runs without it. The snapshot lost neither in its 3 warm runs, nor in its first. That leans the way of your forced-order readback, though it is still few runs. In every run the cell wall left of the window comes and goes as on
main.(Runs, measurements and this note by Claude Code with Claude Opus 5.5 on an RTX 5080 / Ryzen 7 7800X3D, at the account owner's request.)
@VibeClauding on GitHub · 2026-11-25 08:54 UTC · original
Numbers for the compare part alone, without the copy queue, since the artefact question here is about the queue. RTX 3070 8 GB (driver 610.88), Ryzen 7 5700X3D, 16 GB, Windows 11, Series S.
I wrote the same idea separately before seeing this PR: one 64-thread group per piece, each thread hashing a sixty-fourth, with the first thread folding the 64 parts in order. It sits behind a switch,
VICTORY_CARD_HASH_WIDE=1, with no other change (VibeClauding/victory-fork@79d22ec, on9376fd6). The WARP compare test runs both forms, plus a change in the first and the last byte of a piece. Use it for an A/B of the shader on its own if that helps; otherwise yours is the one to keep.8dd30ab+ #220 #648 #670 #705 #346 + my shader branch; warm caches; held view in the first room.VICTORY_RELAY=2 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 VICTORY_INDIRECT_WINDOW=1 VICTORY_CARD_FETCH_INFLIGHT=1 VICTORY_BAKE_TEXTURES_MS=0.VICTORY_CARD_REHASH_RUNS=1So on this card the parallel compare alone is worth about +10%. Most of it is the ~270 hash passes a frame after ranges are sent up, each with only a few pieces. Joining them (
REHASH_RUNS) barely changes their count here (279 → 267), because the ranges rarely touch.Picture, at the window. I can't see the mesh well enough at 960×540 to count it the way @larelgit does. What I do see in some runs is the yard washed out in haze instead of the inmates. I measure it as the mean brightness of the window's lower part in frame 2400:
It happens without the change too, and four runs prove nothing. But it's the same window, so I'm noting it in case it's the race you're chasing rather than the queue.
AI-assisted (Claude Code); runs on my machine with my own copy, counts and timings only.
@Pin0d1 on GitHub · 2026-11-25 09:03 UTC · original · edited 2026-11-25 09:06 UTC
@larelgit, thanks for alternating the builds. Your 197–200 ms/frame result on ef4f510 made me revisit the per-flight allocation. I kept the DIRECT copies and the 64 MiB cap and changed when their buffers can be reused. Pooled build on the same base.
After warm-up, 48 flights cycling through 1, 2, 4 and 8 MiB went from 48 new device-local buffers (180 MiB) to zero. Both builds still copied 180 MiB and returned the expected word in every flight. This repeated three times each on WARP and an RTX 2060 SUPER. Test patches and transcripts.
If you have time for another pair at the same warm checkpoint, could you alternate ef4f510 and 981eaae with COPY on and report ms/frame, GPU time and cumulative card-buffer bytes? That would show how much of the RTX 5080 regression comes from allocation.
Prepared with the help of Codex 6.2 Astra Max.
@MartinIndra02 on GitHub · 2026-11-25 10:42 UTC · original
Rebased onto \main\ (\85101b) and narrowed this PR to only the parallel 64-thread \CARD_COMPARE\ shader + \mix32\ asymmetric reduction + WARP tests (dropping the copy-queue portion now that \85101b\ ships \VICTORY_QUEUE2=1).
Verified on \85101b:
(The single unrelated failure in \warp_budget_saturates_without_wraparound_and_preserves_draw_fields\ is pre-existing on \85101b.)
@ryotdev on GitHub · 2026-11-24 21:49 UTC · original · edited 2026-11-25 14:59 UTC
Retested the paired-edit fix on
c57c9b0. The PR’s Windows WARP regression passed. An independent CPU model of the revised reduction detected all 24,192 paired sign changes in the synthetic fixture set. The earlier reduction missed 388 of those cases.I also ran the updated shader on an RTX 5070 (driver 610.88, Windows, Ryzen 7 7800X3D). Both main
4e17478and the PR reached the same restored 3D checkpoint. I used the direct queue, late-wait stage 3, wide-back, 1 MiB minimum / 1024 MiB budget and rehash-run joining on both. Relay was off, so this tests the hash change in this profile.Over the interval from 300 to 600 frames after the first 500-draw frame, the subset reporting 4,000–4,999 draws/frame and zero pipelines compiling had median window-average frame times of 240.6 ms on main (7 windows) and 236.4 ms on the PR (9 windows). One run each; cameras and dropped-draw counts differed. That’s enough to confirm the revised shader runs through the scene here. I couldn’t establish a frame-rate improvement in this queue mode.
RTX 5070, compare shader isolated at
1cd8f73. I ported the shader and dispatch geometry to a localf85101bdiagnostics build behind a switch. I kept the executable, warm cache, Series X checkpoint and queue configuration identical. The native Windows WARP regression passed for paired edits, skew and compare/store modes.The completed pair gave 6.37 FPS serial and 6.76 FPS parallel over 280 host-present intervals in the first room. Median frame time went from 163.3 to 151.5 ms and p95 from 188.6 to 173.9 ms. The submitter's reported GPU wait fell from 58.8 to 49.4 ms/frame. Matching by draw and dispatch count covered 62% of frames and gave 6.45 vs 6.67 FPS. Three pairs of captures showed the same camera and room.
One earlier parallel attempt ended with DXGI_ERROR_DEVICE_HUNG before the measurement window. A parallel retry with DRED completed at 6.07 FPS. The subsequent run without DRED produced the 6.76 FPS result above. The failing command remains unidentified. This tests the compare change alone. AI-assisted.
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.