Skip to content

GPU: scan copy-back bounds in 32-byte chunks - #255

Open
gomeaw wants to merge 1 commit into
fxceless:mainfrom
gomeaw:perf/shadow-copy-back-span
Open

gomeaw wants to merge 1 commit into
fxceless:mainfrom
gomeaw:perf/shadow-copy-back-span

Conversation

@gomeaw

@gomeaw gomeaw commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Copy-back locates the first and last changed byte of each differing piece before replaying GPU writes into title memory. The RTX 5080 report in #107 measured 44–47 ms per frame for the broader copy-back stage in one cutscene.

Use fixed 32-byte equality in both searches and inspect individual bytes only in the unequal chunk or the partial tail. On Windows x64, Rust 1.98.1 emits two SSE comparisons per complete chunk. The synchronous, relay and card-local paths all use these helpers. The byte offsets passed to the merge stay the same.

Related work: #71 changes the GPU compare and readback queue. #240 reduces scratch allocation and still uses both searches. I verified that this patch merges cleanly with #240.

Measurement

Windows x64, GitHub-hosted AMD EPYC 7763, Rust 1.98.1, optimized standalone A/B of the original and patched helpers. Median of three runs, each reporting the median of nine samples over 128 synthetic pieces per iteration.

64 KiB piece Base (µs) Patch (µs)
Equal 5.94 2.70
One changed byte near the middle 6.64 4.54
One changed byte near the beginning 4.95 3.27
One changed byte near the end 5.99 3.50
Two interior changes 3.35 1.78

A 64 KiB piece differing at both ends took 0.6 ns longer. The 64-byte input with a middle change took 3.3 ns longer. The benchmark times the CPU search only. An independent RTX 5070 checkpoint A/B passed the shadow tests and reported similar copy-back time per MB with variation in streaming. The gameplay benefit remains unverified. Independent test report Windows run · Benchmark source

The bytewise regression checks cover unaligned input, equal spans, partial chunks, unequal lengths and changes on either side of chunk boundaries. Both Clippy configurations and cargo test --workspace --locked passed on the Windows x64 runner with 497 passed, 7 ignored and 0 failed. The asset policy also passed. Windows test job

AI-assisted with Codex. All benchmark and test inputs are synthetic.

Use fixed-size comparisons to skip equal bytes and retain byte-level bounds for the merge. Cover unaligned ranges, partial chunks and both directions against the byte-wise search.
@ryotdev

ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

I tested 413bab7 on Windows with an RTX 5070 (driver 610.88) and Ryzen 7 7800X3D. I ran the same 3D checkpoint once per build, with the same release settings, starting cache files and scripted inputs, and capture disabled. The only source change between the two builds was this PR. All 20 native shadow unit tests passed, including both byte-search tests.

In the shared 145–158 seconds after launch, both runs had 12 window-title samples at 4,800–5,100 draws/frame. Median reported frame time was 231.8 ms before and 223.4 ms after. The two host copy-back reports per arm averaged 35.2 ms for 70.05 MB before and 33.5 ms for 66.9 MB after, about 0.50 ms/MB in both. Streaming varied between the runs and the host frame-time reports moved in the opposite direction. This pair does not establish an end-to-end speedup or a regression. The changed byte-search functions represent only part of the copy-back timer.

AI-assisted hardware test. No game data attached.

JustDownTV pushed a commit to JustDownTV/victory-gta6 that referenced this pull request Nov 24, 2026
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
…; stores never wait for a library save; VICTORY_BVH_BUILDER=2

Hand port of PalmVIDev fxceless#255 and fxceless#249. Groundwork for turning the
ray-tracing structure builder on by default; with no switch set nothing
changes (the builder stays off).

fxceless#255, two stalls seen in a world run with the builder on (RTX 4090: one
frame frozen for 5 minutes):
- The builder made its 53 pipelines on the title's recording thread, at
  its first dispatch, under the builder lock (seconds of driver compile
  each). Now make::poll asks the workers for each one (requested line,
  ahead of early and background work) and does not wait; the builder
  does not run, none of its stages, until none is still being made, so
  all-or-none still holds.
- Pipeline workers waited in their library store behind a save, which
  holds the library alone while it serialises it (over 3 minutes for a
  7 GB library). A store that finds a save in progress is now deferred
  (at most 4096) and done after the save or at the next store; the save
  log counts them (deferred_stores).

fxceless#249: VICTORY_BVH_BUILDER=2 runs the builder while some of its programs
have no host pipeline and turns it off at the first dispatched stage
without one. The title creates every program of the builder library,
also ones its scenes never dispatch, and a few of those do not
translate, which keeps =1 off for good.

Tests: the_builder_waits_for_pipelines_being_made,
a_store_during_a_save_does_not_wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBCi8h4eymnRhdth77t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants