Repository navigation
GPU: parallelize CARD_COMPARE (64 threads per 64 KiB piece) - #71
MartinIndra02 wants to merge 1 commit into
Conversation
|
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.
Concern: the copy queue can read a piece a later flight is still writing
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 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. |
|
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: ryotdev@49e4a90 . AI-assisted. Synthetic data only. |
|
Thanks @ryotdev and @dkdknight for the thorough reviews and RTX 5080 A/B!
|
|
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 4e17478 and 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 local f85101b diagnostics 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. |
|
I measured actual GPU copy time separately from wall time on the stock DIRECT queue. RTX 5070 Ti (621.24), Series X,
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). |
…ompare across 64 threads
…OMPARE_PARALLEL VICTORY_PERMLANE=0 refuses v_permlane16/x16 as before (default on). VICTORY_CARD_COMPARE_PARALLEL=0 uses the original one-thread-per-piece CARD_COMPARE_SERIAL (default on = parallel group reduction). The COPY queue already has VICTORY_RELAY_COPY_QUEUE. Verified intertwined: geometry/models/ lighting load properly, 230-240ms; fetch wait 86->6ms, copy-back 186->34ms, GPU 172->140ms; refusals 21->9 (permlane hash a929109552ce1e84 now translates).
|
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 Written with an AI assistant (Claude). |
|
I reproduced a stale CPU word on 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 Prepared with the help of Codex 6.2 Astra Max. |
|
In-game artefacts that follow the copy queue, and numbers on the current 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 onto 310c6eb without conflicts; no switches other than the ones in the table, so relay stage 2, wide copy-back and the card buffers are on as
What 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 310c6eb without 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 ( 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 ( (Runs, measurements and this note by Claude Code with Claude Opus 5.5 on the hardware above, at the account owner's request.) |
|
@larelgit, thanks for tracking the window mesh and shirt print separately. I rebased the DIRECT-queue snapshot onto your 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. |
|
@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.
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 of One more detail on that row: the "310c6eb" binary is 310c6eb with #154's two commits and (Claude Code with Claude Opus 5.5, at the account owner's request.) |
|
@Pin0d1, the alternation you asked for. #71 as it is (c57c9b0 merged on 310c6eb) 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 (
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 (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.) |
|
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,
So 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 ( 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. |
|
@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. |
c57c9b0 to
1cd8f73
Compare
|
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:
|
Summary
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):
Verification
AI-assisted contribution (code and tests authored/verified with an AI coding assistant).