WIP: perf(vk): a recording's uniform copies shared, their reads made once a draw: Castle Town's market from 54.9 to 59.5 fps on a B580 with the uniform snapshot #952

Draft
nyannoying wants to merge 3 commits from nyannoying/Longshot:perf/vk-ub-reads-once into main
Contributor

Type: perf · Risk: medium · Tested on: Windows 11, Arc B580 (the snapshot on, as #446 has it) · Needs: an Intel iGPU, any OS (the snapshot is on there by default); a Linux build

Why

On Intel GPUs the renderer copies every uniform buffer a draw binds into its own stream instead of binding the game's
memory: the uniform snapshot (RX_VK_UB_SNAPSHOT). Without it Intel's iGPUs drew objects with other objects' matrices
and painted sky over Kokiri Forest's ground; #446 turns it on for the Arc cards too. Each copy was read from the game's
memory on its own, most of them under a lock. In Castle Town's market an Arc B580 made about 10,400 copies a frame, 19 MB, of only
4,200 distinct ranges, 2.4 MB, and building the draws' descriptors took 6.1 ms of every frame on the render
thread, in a place that already waits on the CPU. With this PR a recording copies each range once and a draw reads its
copies together: the descriptors take 2.6 ms, and the market runs at 59.5 fps instead of 54.9.

What changed

A draw that binds a uniform range (address and size) an earlier draw of the same recording copied, with the same
captures in view, is given that copy instead of making its own. The copies a draw still makes are read from the game's
memory together once its descriptors are built, the memory lock taken once instead of once a copy. Within a recording
a range's contents were the same in every copy of it: RX_VK_UB_SNAP_DEDUP=2, which makes every copy all the same and
compares it with the shared one, compared 40 million in the market, Kokiri Forest and Hyrule Field and found none
different. Only the snapshot's copies change: without the snapshot none of this runs.

  • gpu/vk/vk_draw.cpp:
    • uniform_range(): the sharing. ub_snaps is a thread's table of its recording's copies by address and size (4,096
      slots, 16 probes, ub_snap_slot()); RecordingRes::ub_snap_epoch, a recording's number set in
      draw_begin_recording(), keeps another recording's copies from being given out, and memory_capture_view() a copy
      made with other captures in view. ub_snap_dedup_mode() is RX_VK_UB_SNAP_DEDUP; ub_snap_check() and
      ub_snap_count() are its check and its log line.
    • build_descriptors(): the batched reads. uniform_range() queues a copy's read (ub_reads_pending) and
      UbReadsScope makes them all when the build is over, however it ends (ub_reads_flush()).
      ub_read_batch_mode() is RX_VK_UB_READ_BATCH.
    • bind_descriptors(): with the copies shared, every uniform buffer write is pushed each draw, as every one was
      before (each draw had copies of its own, so each had changed); textures and storage buffers are still pushed only
      when changed. Left out as unchanged, the B580 drew objects with other objects' matrices: a push that carries some of a
      draw's uniform buffer writes and leaves others out reads wrong data there, as with the snapshot off (measured: adding
      the ones left out to such a push puts it right, adding them to other pushes does not; comment of 16 November).
    • The snapshot's default is #446's ub_snapshot_wanted(), which bind_descriptors() asks too; this PR has no default of
      its own.
  • gpu/vk/vk_memory.cpp, gpu/vk/vk_internal.h: memory_read_as_submitted_many() (SubmittedRead): many reads as
    memory_read_as_submitted() makes one, pools_mu taken once for those that need the captures. The one read is
    split into the part without the lock and the part with it (submitted_read_unlocked(), submitted_read_locked()),
    which both use. #977's late pages' hook (late_defer_cpu_read(), RX_VK_LATE_DEFER, where the pools have no mirror)
    is in submitted_read_locked(), so the reads made together take a late page's copy again before reading it, as one
    read does.
  • tests/test_submitted_page.py: the split read: both reads ask the per-page cache before the pool lock, without
    taking it, and copy the captures' pages under it; the answer is kept only for a page in no capture, as before.
    tests/sampler_admission_test.cpp: the two helpers bind_descriptors() now asks (no snapshot there).
    tests/test_late_defer.py: its text check finds #977's hook in submitted_read_locked(), and both reads going
    through it.
  • docs/development.md: the two switches, with the numbers and the read check's cost; docs/tested/: the 6 runs, and the 7 of the A/B with #446 (16 November).

Measurements

Verdict: faster on the Arc B580 with the snapshot on, in the market: 54.9 → 59.5 fps average (+8.4%), 1% low 37.1 → 39.8 fps, median frame time 17.45 → 16.48 ms; the replay's descriptors 6.12 → 2.64 ms a frame, the GPU time the same (12.1 ms). The picture is the same: no flash either way, and the check modes found no copy different.

Baseline: RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0 on the same build: every binding gets a copy of its own and
each copy is read on its own, exactly as on main (none of the sharing or the batching runs, and every uniform write
is pushed when changed, as before). Both columns are one build: 690d8446, this PC's game folder (main at 2b1d38c6
with my open #443, #446, #459 and #500 merged), with #761's change (now on main) and this PR's diff applied: main's
renderer (MKWVK_API_VERSION 23) doesn't load in that folder's host (22), and a new folder for main means preparing
the 38,809 shaders again. #446 is what turns the snapshot on for the B580 there; on main the B580 needs
RX_VK_UB_SNAPSHOT=1 for this PR to do anything. The runs' build had the recordings' counter (ub_snap_epochs) as a
global; this PR's head has it inside draw_begin_recording(), the same counter, for the checks that compile that
function.

Hardware: Windows 11 Pro Insider 10.0.29704, Intel Arc B580 12 GB (driver 32.0.101.9154), Core i5-13600K, 64 GB
Scene: Castle Town's market as child Link by day, standing at the entrance (the control bridge's teleport Market_Child); 1280x720 window, render 75% upscaled with Intel XeSS 2.0.2 (Ultra Quality: 960x540 → 1280x720, #459), frame generation off, V-Sync Auto, HOS_FPS_MAX=240 (not
capped)
Method: 3 interleaved pairs, each from a fresh start (on, off, off, on, on, off): 40 s after the teleport, then 40 s
measured. fps and frame times from RX_VK_FRAME_LOG (every present of the 40 s; the 1% low is the rate of the slowest
1% of frames); the render thread's time and the replay's descriptors from HOS_PROFILE=5; GPU time from the log's
GPU time line. Each cell is the median of the arm's 3 runs, the runs in brackets.
How to reproduce: python -I scripts/longshot_ctl.py launch <game folder> --env RX_VK_UB_SNAPSHOT=1 --env HOS_PROFILE=5 --env RX_VK_FRAME_LOG=frames.csv [--env RX_VK_UB_SNAP_DEDUP=0 --env RX_VK_UB_READ_BATCH=0], then longshot_ctl.py teleport Market_Child, 40 s, and 40 s measured.

Before, RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0 (every copy made and read on its own, as on main): this PR @ 8db390d8 After, the default (the copies shared, read once a draw): this PR @ 8db390d8 Δ
Average fps 54.9 (55.3, 54.9, 53.2) 59.5 (60.1, 59.5, 59.2) +8.4%
1% low 37.1 fps (38.4, 37.1, 22.4) 39.8 fps (41.2, 39.8, 37.5) +7%
Median frame time 17.45 ms (17.40, 17.45, 17.98) 16.48 ms (16.31, 16.48, 16.54) −0.97 ms
p99 frame time 24.80 ms (24.02, 24.80, 29.05) 23.12 ms (22.63, 23.12, 23.77) −1.68 ms
The render thread's jobs, a frame 15.83 ms 12.29 ms −3.54 ms
The replay's draws, a frame 9.73 ms 6.22 ms −3.51 ms
The replay's descriptors, a frame 6.12 ms 2.64 ms −3.48 ms
GPU time, a frame 12.1 ms 12.1 ms
Uniform copies given the recording's earlier copy none 59% (30.9 of 52 million since the start)

The 3.5 ms the render thread no longer spends on the descriptors gives about 1 ms of frame time: it now idles 4.1 ms a
frame (2.5 before), the frame held by the GPU's 12 ms and the game's own threads. One run without the change (UA-3) had
a stretch of slow frames (11 over 40 ms, the longest 70 ms) that pulls its 1% low to 22.4; the medians don't lean on it.

UA-2, RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0 (the median run of the three):
vk: a frame's replay time (ms): submit 15.14, present 0.09, draw 9.61, descriptors 5.99, texture lookups 0.07, uploads 0.00, pipelines 0.33, programs 0.90, commands 1.66, dispatch 1.04, memory sync 0.50, queue submit 0.58, slot wait 0.11
vk: the render thread (600 presents, 17.98 ms a frame): its jobs 15.48 ms a frame (submits 1.73, presents 0.20, others 13.55), idle 2.50
vk: GPU time 11.8 ms a frame (the longest submission 2.5 ms); 0.1 textures made a frame

UB-2, the default (the median run of the three):
vk: uniform copies (RX_VK_UB_SNAP_DEDUP=1): 30856751 of 52000000 given the recording's earlier copy of their range, 81479.3 MB not copied
vk: a frame's replay time (ms): submit 11.64, present 0.08, draw 6.29, descriptors 2.67, texture lookups 0.06, uploads 0.00, pipelines 0.33, programs 0.89, commands 1.67, dispatch 1.04, memory sync 0.50, queue submit 0.57, slot wait 0.11
vk: the render thread (600 presents, 16.59 ms a frame): its jobs 12.46 ms a frame (submits 2.72, presents 0.21, others 9.53), idle 4.12
vk: GPU time 11.9 ms a frame (the longest submission 2.5 ms); 0.0 textures made a frame

With #446's guard: Kokiri Forest and the Market (16 November)

Verdict: faster on #446's guard too, where the B580 runs it: Kokiri Forest 86.85 → 93.15 fps (+7.3%) and the Market 54.35 → 59.45 fps (+9.4%) standing, 4 and 4 interleaved sessions (the medians); the replay 6.34 → 4.85 ms a frame in Kokiri Forest and 15.43 → 11.93 ms in the Market, the GPU time the same. No dark or bright patch and no whole picture dark standing, either way.

Baseline: #446's guard on the folder's source, as in #446's The guard (its "After" column): 690d8446 + #761, #838, 64ed6a2f, #1083's commits, a local region test and #446's renderer diff of 32ab00b5..c10f1e32 as a local commit. After: that build with this PR's renderer diff as rebased onto #446 (1076e816) as a second local commit, which also carries a local switch turning the uniform re-push off (unset here). The branch's perf commit now (335c890e, on main 0cab3548, #446's merge) has the same code lines as 1076e816 but for #977's late pages' hook, which moved with the page loop into submitted_read_locked(): that hook is not in the measured builds' source, and it is off where the pools have mirrors, as on the B580; only comments changed otherwise. Both at their defaults.

Before: #446's guard alone After: with this PR Δ
Kokiri Forest fps standing (4 sessions; the median) 86.8, 86.9, 88.6, 86.5 (86.85) 93.1, 93.2, 95.1, 91.7 (93.15) +7.3%
the Market fps standing, the same sessions 54.6, 54.5, 54.2, 53.4 (54.35) 59.9, 55.6, 60.1, 59.0 (59.45) +9.4%
the replay's time a frame, Kokiri Forest / the Market (medians) 6.34 / 15.43 ms 4.85 / 11.93 ms −1.49 / −3.50 ms
the replay's descriptors a frame, Kokiri Forest / the Market 2.79 / 6.33 ms 1.21 / 2.90 ms −1.58 / −3.43 ms
GPU time a frame, Kokiri Forest / the Market 8.1 / 12.2 ms 8.2 / 12.1 ms
dark / bright patches standing (region test, both windows of the 4 sessions); whole pictures dark 0 / 0 of 16,800; 0 0 / 0 of 16,800; 0
walking, Kakariko Village / the Market fps (3 sessions; each session's 5 s windows, the median, then the sessions') not run 70.5, 62.4, 65.6 (65.6) / 53.3, 47.9, 53.3 (53.3)
walking: dark / bright patches (region test), Kakariko Village; the Market; whole pictures dark not run 4 / 5 of 7,200; 14 / 16 of 6,600; 0
device lost 0 0

Method: each session a new start of the game: Kokiri Forest, then the Market by the debug teleport, 40 s to settle and 30 s measured in each; fps from the log's 5 s vi: windows, dark and bright patches from the region test on every presented frame of the measured windows (2 or more of 16x9 regions more than 10 levels darker, or brighter, than in both neighbouring frames), the frame log on with its pictures dropped on both sides alike; 1280x720 window, the scene rendered at 960x540 and upscaled with Intel XeSS 2.0.2 (Ultra Quality), HOS_FPS_MAX=240; each session a timed job of the queue. The orders interleaved a third setup, #446 with the snapshot off and every descriptor pushed (on #446): XR XA XP, XP XA XR, XA XP XR, XR XP XA. Walking: Kakariko Village, then the Market, 40 s each, the stick held forward 150 frames, right 20, forward 90, left 45, over and over.

Flags and settings

Two new switches, both on by default where the snapshot is on (they change nothing without it).

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
RX_VK_UB_SNAP_DEDUP A draw given the recording's earlier copy of a uniform range (1), a copy for every binding (0), or a copy for every binding compared with the shared one, the differences logged (2, a check) (none: a copy for every binding) 1 59% of the copies not made in the market; with the batched reads, descriptors 6.1 → 2.6 ms a frame and +8.4% fps on a B580 Helps: Arc B580 on Windows with the snapshot (#446 or RX_VK_UB_SNAPSHOT=1). Untested: Intel iGPUs, where the snapshot is on by default; Linux On as shipped
RX_VK_UB_READ_BATCH A draw's uniform copies read together at the end of its descriptor build, the lock taken once (1), each where it is asked (0), or both, compared, the differences logged (2, a check) (none: each where it is asked) 1 The lock taken once a draw instead of once a copy; measured together with the sharing (above) As above On as shipped

Testing

Tested:

  • The game-free checks, python -I -B tests/run_all.py with the toolchain's llvm-mingw (bin and its runtime folder
    first on PATH) and Vulkan headers (RX_CPM), on this PR's head 3d43b0ee (the same files as this head, e68d8859: #446's merge, 0cab3548, has the
    tree of #446's commits that were under it) and on main 60bf15bd, the commit under #446's merge, on the same PC: 622 passed, 26 failed, 44 skipped here; 621, 25 and 44 on main. The same 25 fail on
    both (e.g. test_tested_configurations' CLI pipe on Windows line ends, and test_fsr_uniform_ownership and
    test_parallel_init_order, whose fixtures don't know FpsRtWait). The 26th, test_coverage_run, fails on this PC
    whenever no game is running (scripts/coverage/cover.py reads tasklist's German "no tasks" line as cp1252), on
    main too: run alone after the suite, it failed on both. The 44 skipped run on Linux or need tools this PC lacks
    (spirv-val, glslang). The renderer builds at 3d43b0ee (RX_VK_ONLY, llvm-mingw, 0 warnings).
    tests/test_submitted_page.py and tests/test_sampler_admission.py failed on this change before their updates
    here, and pass now. tests/test_late_defer.py (#977's) finds its hook in submitted_read_locked() now and passes
    here and on main; its text check fails with the hook taken out, with the hook after the copy, and with either read
    not calling submitted_read_locked().
  • In the game, Windows 11, Arc B580, driver 32.0.101.9154, the snapshot on: Castle Town's market, 3 runs with the
    change and 3 without (above), no device lost. The picture, walking through the market with the flash detector
    (RX_VK_FLASH=1, every frame checked for frames that go white, black or flash against the ones around them):
    no flash, no region flash, no white or black frame, with the change and without, and none in the 6
    standing runs. The checks: RX_VK_UB_SNAP_DEDUP=2 compared 40 million copies with the recording's shared one
    (the market, Kokiri Forest and Hyrule Field), none different; RX_VK_UB_READ_BATCH=2, walking through the market,
    made 1.2 million reads again at their draw's end, none different (that check reads the stream's memory back: 1.7 fps).

Not tested: Intel iGPUs, where the snapshot is on by default (no iGPU run here: a new device means preparing the
shaders again); Linux; AMD and NVIDIA with RX_VK_UB_SNAPSHOT=1. Without the snapshot (on main every GPU but Intel's,
since #446 turned it on for the Arc cards too) the change runs nothing.

Must be tested:

  • An Intel iGPU (Core Ultra, or 12th to 14th gen with Iris Xe or UHD), Windows or Linux: Kokiri Forest and Castle
    Town's market by day, a minute each, with the defaults and again with RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0,
    expecting the same picture both ways (no white blocks, no object drawn in another's place, no sky over the forest's
    ground), the log's uniform copies (RX_VK_UB_SNAP_DEDUP=1) line with the defaults, and no lower fps (by hand: a
    tester with an Intel iGPU, asked in #test-requests).
  • linux, any GPU: build the renderer (longshot_vk.so) from this branch and play the market by day for a minute with
    RX_VK_UB_SNAPSHOT=1, expecting it to build, the same picture as with RX_VK_UB_SNAP_DEDUP=0, and the log's
    uniform copies (RX_VK_UB_SNAP_DEDUP=1) line (Test Farm: @Beanstalk linux, build and the market with
    RX_VK_UB_SNAPSHOT=1)

Risks

What could break: a draw given a copy whose contents its own copy would not have had would draw with stale
uniforms: objects in the wrong place, the wrong colour or flickering. A copy is shared only within one recording, for
the same address and size, with the same captures in view (a capture published or a page stamped since makes a new
copy), and the check found no copy different in the market, Kokiri Forest and Hyrule Field. The uniform writes are pushed every draw again: a push that leaves some of a
draw's uniform buffer writes out is what the B580 draws wrong, and with all of them pushed that can't happen.
A read made at the build's end instead of where it was asked sees the same submission's captures (the check compares
both).

Turning it off: RX_VK_UB_SNAP_DEDUP=0 and RX_VK_UB_READ_BATCH=0.

Compatibility: Nothing changes: no option, cache or save format, and the renderer's interface is the same
(MKWVK_API_VERSION unchanged).

Issues

See #446

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main (0cab3548, #446's merge: this PR's three commits alone now; on 60bf15bd before it, #977's hook moved with the page loop).
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A file in docs/tested/ for each new measured run (format in docs/tested-configurations.md).
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows: built (llvm-mingw). Linux: not
    built here (no Linux toolchain on this PC); the change uses no platform API. Asked of the Test Farm (Must be tested).
  • Docs updated.

🤖 Generated with Claude Code

**Type:** perf · **Risk:** medium · **Tested on:** Windows 11, Arc B580 (the snapshot on, as #446 has it) · **Needs:** an Intel iGPU, any OS (the snapshot is on there by default); a Linux build ## Why On Intel GPUs the renderer copies every uniform buffer a draw binds into its own stream instead of binding the game's memory: the uniform snapshot (`RX_VK_UB_SNAPSHOT`). Without it Intel's iGPUs drew objects with other objects' matrices and painted sky over Kokiri Forest's ground; #446 turns it on for the Arc cards too. Each copy was read from the game's memory on its own, most of them under a lock. In Castle Town's market an Arc B580 made about 10,400 copies a frame, 19 MB, of only 4,200 distinct ranges, 2.4 MB, and building the draws' descriptors took 6.1 ms of every frame on the render thread, in a place that already waits on the CPU. With this PR a recording copies each range once and a draw reads its copies together: the descriptors take 2.6 ms, and the market runs at 59.5 fps instead of 54.9. ## What changed A draw that binds a uniform range (address and size) an earlier draw of the same recording copied, with the same captures in view, is given that copy instead of making its own. The copies a draw still makes are read from the game's memory together once its descriptors are built, the memory lock taken once instead of once a copy. Within a recording a range's contents were the same in every copy of it: `RX_VK_UB_SNAP_DEDUP=2`, which makes every copy all the same and compares it with the shared one, compared 40 million in the market, Kokiri Forest and Hyrule Field and found none different. Only the snapshot's copies change: without the snapshot none of this runs. - `gpu/vk/vk_draw.cpp`: - `uniform_range()`: the sharing. `ub_snaps` is a thread's table of its recording's copies by address and size (4,096 slots, 16 probes, `ub_snap_slot()`); `RecordingRes::ub_snap_epoch`, a recording's number set in `draw_begin_recording()`, keeps another recording's copies from being given out, and `memory_capture_view()` a copy made with other captures in view. `ub_snap_dedup_mode()` is `RX_VK_UB_SNAP_DEDUP`; `ub_snap_check()` and `ub_snap_count()` are its check and its log line. - `build_descriptors()`: the batched reads. `uniform_range()` queues a copy's read (`ub_reads_pending`) and `UbReadsScope` makes them all when the build is over, however it ends (`ub_reads_flush()`). `ub_read_batch_mode()` is `RX_VK_UB_READ_BATCH`. - `bind_descriptors()`: with the copies shared, every uniform buffer write is pushed each draw, as every one was before (each draw had copies of its own, so each had changed); textures and storage buffers are still pushed only when changed. Left out as unchanged, the B580 drew objects with other objects' matrices: a push that carries some of a draw's uniform buffer writes and leaves others out reads wrong data there, as with the snapshot off (measured: adding the ones left out to such a push puts it right, adding them to other pushes does not; comment of 16 November). - The snapshot's default is #446's `ub_snapshot_wanted()`, which `bind_descriptors()` asks too; this PR has no default of its own. - `gpu/vk/vk_memory.cpp`, `gpu/vk/vk_internal.h`: `memory_read_as_submitted_many()` (`SubmittedRead`): many reads as `memory_read_as_submitted()` makes one, `pools_mu` taken once for those that need the captures. The one read is split into the part without the lock and the part with it (`submitted_read_unlocked()`, `submitted_read_locked()`), which both use. #977's late pages' hook (`late_defer_cpu_read()`, `RX_VK_LATE_DEFER`, where the pools have no mirror) is in `submitted_read_locked()`, so the reads made together take a late page's copy again before reading it, as one read does. - `tests/test_submitted_page.py`: the split read: both reads ask the per-page cache before the pool lock, without taking it, and copy the captures' pages under it; the answer is kept only for a page in no capture, as before. `tests/sampler_admission_test.cpp`: the two helpers `bind_descriptors()` now asks (no snapshot there). `tests/test_late_defer.py`: its text check finds #977's hook in `submitted_read_locked()`, and both reads going through it. - `docs/development.md`: the two switches, with the numbers and the read check's cost; `docs/tested/`: the 6 runs, and the 7 of the A/B with #446 (16 November). ## Measurements **Verdict:** faster on the Arc B580 with the snapshot on, in the market: 54.9 → 59.5 fps average (+8.4%), 1% low 37.1 → 39.8 fps, median frame time 17.45 → 16.48 ms; the replay's descriptors 6.12 → 2.64 ms a frame, the GPU time the same (12.1 ms). The picture is the same: no flash either way, and the check modes found no copy different. Baseline: `RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0` on the same build: every binding gets a copy of its own and each copy is read on its own, exactly as on `main` (none of the sharing or the batching runs, and every uniform write is pushed when changed, as before). Both columns are one build: 690d8446, this PC's game folder (`main` at 2b1d38c6 with my open #443, #446, #459 and #500 merged), with #761's change (now on `main`) and this PR's diff applied: `main`'s renderer (`MKWVK_API_VERSION` 23) doesn't load in that folder's host (22), and a new folder for `main` means preparing the 38,809 shaders again. #446 is what turns the snapshot on for the B580 there; on `main` the B580 needs `RX_VK_UB_SNAPSHOT=1` for this PR to do anything. The runs' build had the recordings' counter (`ub_snap_epochs`) as a global; this PR's head has it inside `draw_begin_recording()`, the same counter, for the checks that compile that function. Hardware: Windows 11 Pro Insider 10.0.29704, Intel Arc B580 12 GB (driver 32.0.101.9154), Core i5-13600K, 64 GB Scene: Castle Town's market as child Link by day, standing at the entrance (the control bridge's `teleport Market_Child`); 1280x720 window, render 75% upscaled with Intel XeSS 2.0.2 (Ultra Quality: 960x540 → 1280x720, #459), frame generation off, V-Sync Auto, `HOS_FPS_MAX=240` (not capped) Method: 3 interleaved pairs, each from a fresh start (on, off, off, on, on, off): 40 s after the teleport, then 40 s measured. fps and frame times from `RX_VK_FRAME_LOG` (every present of the 40 s; the 1% low is the rate of the slowest 1% of frames); the render thread's time and the replay's descriptors from `HOS_PROFILE=5`; GPU time from the log's `GPU time` line. Each cell is the median of the arm's 3 runs, the runs in brackets. How to reproduce: `python -I scripts/longshot_ctl.py launch <game folder> --env RX_VK_UB_SNAPSHOT=1 --env HOS_PROFILE=5 --env RX_VK_FRAME_LOG=frames.csv [--env RX_VK_UB_SNAP_DEDUP=0 --env RX_VK_UB_READ_BATCH=0]`, then `longshot_ctl.py teleport Market_Child`, 40 s, and 40 s measured. | | Before, `RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0` (every copy made and read on its own, as on `main`): this PR @ 8db390d8 | After, the default (the copies shared, read once a draw): this PR @ 8db390d8 | Δ | |---|---|---|---| | Average fps | 54.9 (55.3, 54.9, 53.2) | 59.5 (60.1, 59.5, 59.2) | +8.4% | | 1% low | 37.1 fps (38.4, 37.1, 22.4) | 39.8 fps (41.2, 39.8, 37.5) | +7% | | Median frame time | 17.45 ms (17.40, 17.45, 17.98) | 16.48 ms (16.31, 16.48, 16.54) | −0.97 ms | | p99 frame time | 24.80 ms (24.02, 24.80, 29.05) | 23.12 ms (22.63, 23.12, 23.77) | −1.68 ms | | The render thread's jobs, a frame | 15.83 ms | 12.29 ms | −3.54 ms | | The replay's draws, a frame | 9.73 ms | 6.22 ms | −3.51 ms | | The replay's descriptors, a frame | 6.12 ms | 2.64 ms | −3.48 ms | | GPU time, a frame | 12.1 ms | 12.1 ms | | | Uniform copies given the recording's earlier copy | none | 59% (30.9 of 52 million since the start) | | The 3.5 ms the render thread no longer spends on the descriptors gives about 1 ms of frame time: it now idles 4.1 ms a frame (2.5 before), the frame held by the GPU's 12 ms and the game's own threads. One run without the change (UA-3) had a stretch of slow frames (11 over 40 ms, the longest 70 ms) that pulls its 1% low to 22.4; the medians don't lean on it. ``` UA-2, RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0 (the median run of the three): vk: a frame's replay time (ms): submit 15.14, present 0.09, draw 9.61, descriptors 5.99, texture lookups 0.07, uploads 0.00, pipelines 0.33, programs 0.90, commands 1.66, dispatch 1.04, memory sync 0.50, queue submit 0.58, slot wait 0.11 vk: the render thread (600 presents, 17.98 ms a frame): its jobs 15.48 ms a frame (submits 1.73, presents 0.20, others 13.55), idle 2.50 vk: GPU time 11.8 ms a frame (the longest submission 2.5 ms); 0.1 textures made a frame UB-2, the default (the median run of the three): vk: uniform copies (RX_VK_UB_SNAP_DEDUP=1): 30856751 of 52000000 given the recording's earlier copy of their range, 81479.3 MB not copied vk: a frame's replay time (ms): submit 11.64, present 0.08, draw 6.29, descriptors 2.67, texture lookups 0.06, uploads 0.00, pipelines 0.33, programs 0.89, commands 1.67, dispatch 1.04, memory sync 0.50, queue submit 0.57, slot wait 0.11 vk: the render thread (600 presents, 16.59 ms a frame): its jobs 12.46 ms a frame (submits 2.72, presents 0.21, others 9.53), idle 4.12 vk: GPU time 11.9 ms a frame (the longest submission 2.5 ms); 0.0 textures made a frame ``` ### With #446's guard: Kokiri Forest and the Market (16 November) **Verdict:** faster on #446's guard too, where the B580 runs it: Kokiri Forest 86.85 → 93.15 fps (+7.3%) and the Market 54.35 → 59.45 fps (+9.4%) standing, 4 and 4 interleaved sessions (the medians); the replay 6.34 → 4.85 ms a frame in Kokiri Forest and 15.43 → 11.93 ms in the Market, the GPU time the same. No dark or bright patch and no whole picture dark standing, either way. Baseline: #446's guard on the folder's source, as in #446's *The guard* (its "After" column): 690d8446 + #761, #838, 64ed6a2f, #1083's commits, a local region test and #446's renderer diff of 32ab00b5..c10f1e32 as a local commit. After: that build with this PR's renderer diff as rebased onto #446 (1076e816) as a second local commit, which also carries a local switch turning the uniform re-push off (unset here). The branch's perf commit now (335c890e, on `main` 0cab3548, #446's merge) has the same code lines as 1076e816 but for #977's late pages' hook, which moved with the page loop into `submitted_read_locked()`: that hook is not in the measured builds' source, and it is off where the pools have mirrors, as on the B580; only comments changed otherwise. Both at their defaults. | | Before: #446's guard alone | After: with this PR | Δ | |---|---|---|---| | Kokiri Forest fps standing (4 sessions; the median) | 86.8, 86.9, 88.6, 86.5 (86.85) | 93.1, 93.2, 95.1, 91.7 (93.15) | +7.3% | | the Market fps standing, the same sessions | 54.6, 54.5, 54.2, 53.4 (54.35) | 59.9, 55.6, 60.1, 59.0 (59.45) | +9.4% | | the replay's time a frame, Kokiri Forest / the Market (medians) | 6.34 / 15.43 ms | 4.85 / 11.93 ms | −1.49 / −3.50 ms | | the replay's descriptors a frame, Kokiri Forest / the Market | 2.79 / 6.33 ms | 1.21 / 2.90 ms | −1.58 / −3.43 ms | | GPU time a frame, Kokiri Forest / the Market | 8.1 / 12.2 ms | 8.2 / 12.1 ms | | | dark / bright patches standing (region test, both windows of the 4 sessions); whole pictures dark | 0 / 0 of 16,800; 0 | 0 / 0 of 16,800; 0 | | | walking, Kakariko Village / the Market fps (3 sessions; each session's 5 s windows, the median, then the sessions') | not run | 70.5, 62.4, 65.6 (65.6) / 53.3, 47.9, 53.3 (53.3) | | | walking: dark / bright patches (region test), Kakariko Village; the Market; whole pictures dark | not run | 4 / 5 of 7,200; 14 / 16 of 6,600; 0 | | | device lost | 0 | 0 | | Method: each session a new start of the game: Kokiri Forest, then the Market by the debug teleport, 40 s to settle and 30 s measured in each; fps from the log's 5 s `vi:` windows, dark and bright patches from the region test on every presented frame of the measured windows (2 or more of 16x9 regions more than 10 levels darker, or brighter, than in both neighbouring frames), the frame log on with its pictures dropped on both sides alike; 1280x720 window, the scene rendered at 960x540 and upscaled with Intel XeSS 2.0.2 (Ultra Quality), `HOS_FPS_MAX=240`; each session a timed job of the queue. The orders interleaved a third setup, #446 with the snapshot off and every descriptor pushed (on #446): XR XA XP, XP XA XR, XA XP XR, XR XP XA. Walking: Kakariko Village, then the Market, 40 s each, the stick held forward 150 frames, right 20, forward 90, left 45, over and over. ### Flags and settings Two new switches, both on by default where the snapshot is on (they change nothing without it). | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `RX_VK_UB_SNAP_DEDUP` | A draw given the recording's earlier copy of a uniform range (1), a copy for every binding (0), or a copy for every binding compared with the shared one, the differences logged (2, a check) | (none: a copy for every binding) | 1 | 59% of the copies not made in the market; with the batched reads, descriptors 6.1 → 2.6 ms a frame and +8.4% fps on a B580 | Helps: Arc B580 on Windows with the snapshot (#446 or `RX_VK_UB_SNAPSHOT=1`). Untested: Intel iGPUs, where the snapshot is on by default; Linux | On as shipped | | `RX_VK_UB_READ_BATCH` | A draw's uniform copies read together at the end of its descriptor build, the lock taken once (1), each where it is asked (0), or both, compared, the differences logged (2, a check) | (none: each where it is asked) | 1 | The lock taken once a draw instead of once a copy; measured together with the sharing (above) | As above | On as shipped | ## Testing **Tested:** - The game-free checks, `python -I -B tests/run_all.py` with the toolchain's llvm-mingw (`bin` and its runtime folder first on `PATH`) and Vulkan headers (`RX_CPM`), on this PR's head 3d43b0ee (the same files as this head, e68d8859: #446's merge, 0cab3548, has the tree of #446's commits that were under it) and on `main` 60bf15bd, the commit under #446's merge, on the same PC: 622 passed, 26 failed, 44 skipped here; 621, 25 and 44 on `main`. The same 25 fail on both (e.g. `test_tested_configurations`' CLI pipe on Windows line ends, and `test_fsr_uniform_ownership` and `test_parallel_init_order`, whose fixtures don't know `FpsRtWait`). The 26th, `test_coverage_run`, fails on this PC whenever no game is running (`scripts/coverage/cover.py` reads `tasklist`'s German "no tasks" line as cp1252), on `main` too: run alone after the suite, it failed on both. The 44 skipped run on Linux or need tools this PC lacks (spirv-val, glslang). The renderer builds at 3d43b0ee (`RX_VK_ONLY`, llvm-mingw, 0 warnings). `tests/test_submitted_page.py` and `tests/test_sampler_admission.py` failed on this change before their updates here, and pass now. `tests/test_late_defer.py` (#977's) finds its hook in `submitted_read_locked()` now and passes here and on `main`; its text check fails with the hook taken out, with the hook after the copy, and with either read not calling `submitted_read_locked()`. - In the game, Windows 11, Arc B580, driver 32.0.101.9154, the snapshot on: Castle Town's market, 3 runs with the change and 3 without (above), no device lost. The picture, walking through the market with the flash detector (`RX_VK_FLASH=1`, every frame checked for frames that go white, black or flash against the ones around them): no flash, no region flash, no white or black frame, with the change and without, and none in the 6 standing runs. The checks: `RX_VK_UB_SNAP_DEDUP=2` compared 40 million copies with the recording's shared one (the market, Kokiri Forest and Hyrule Field), none different; `RX_VK_UB_READ_BATCH=2`, walking through the market, made 1.2 million reads again at their draw's end, none different (that check reads the stream's memory back: 1.7 fps). **Not tested:** Intel iGPUs, where the snapshot is on by default (no iGPU run here: a new device means preparing the shaders again); Linux; AMD and NVIDIA with `RX_VK_UB_SNAPSHOT=1`. Without the snapshot (on `main` every GPU but Intel's, since #446 turned it on for the Arc cards too) the change runs nothing. **Must be tested:** - An Intel iGPU (Core Ultra, or 12th to 14th gen with Iris Xe or UHD), Windows or Linux: Kokiri Forest and Castle Town's market by day, a minute each, with the defaults and again with `RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0`, expecting the same picture both ways (no white blocks, no object drawn in another's place, no sky over the forest's ground), the log's `uniform copies (RX_VK_UB_SNAP_DEDUP=1)` line with the defaults, and no lower fps (by hand: a tester with an Intel iGPU, asked in #test-requests). - linux, any GPU: build the renderer (`longshot_vk.so`) from this branch and play the market by day for a minute with `RX_VK_UB_SNAPSHOT=1`, expecting it to build, the same picture as with `RX_VK_UB_SNAP_DEDUP=0`, and the log's `uniform copies (RX_VK_UB_SNAP_DEDUP=1)` line (Test Farm: @Beanstalk linux, build and the market with RX_VK_UB_SNAPSHOT=1) ## Risks **What could break:** a draw given a copy whose contents its own copy would not have had would draw with stale uniforms: objects in the wrong place, the wrong colour or flickering. A copy is shared only within one recording, for the same address and size, with the same captures in view (a capture published or a page stamped since makes a new copy), and the check found no copy different in the market, Kokiri Forest and Hyrule Field. The uniform writes are pushed every draw again: a push that leaves some of a draw's uniform buffer writes out is what the B580 draws wrong, and with all of them pushed that can't happen. A read made at the build's end instead of where it was asked sees the same submission's captures (the check compares both). **Turning it off:** `RX_VK_UB_SNAP_DEDUP=0` and `RX_VK_UB_READ_BATCH=0`. **Compatibility:** Nothing changes: no option, cache or save format, and the renderer's interface is the same (`MKWVK_API_VERSION` unchanged). ## Issues See #446 ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main` (0cab3548, #446's merge: this PR's three commits alone now; on 60bf15bd before it, #977's hook moved with the page loop). - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A file in `docs/tested/` for each new measured run (format in `docs/tested-configurations.md`). - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [ ] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows: built (llvm-mingw). Linux: not built here (no Linux toolchain on this PC); the change uses no platform API. Asked of the Test Farm (Must be tested). - [x] Docs updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With the uniform snapshot on (Intel GPUs without VRAM mirrors by default, the iGPUs; RX_VK_UB_SNAPSHOT=1 elsewhere, and
#446 on the Arc cards) every uniform buffer a draw binds was copied into the stream: about 10,400 copies a frame in
Castle Town's market on an Arc B580, 19 MB, of 4,200 distinct ranges (2.4 MB), each read under pools_mu on its own.
Within a recording a range's contents were the same in every copy of it (RX_VK_UB_SNAP_DEDUP=2 in the market, Kokiri
Forest and Hyrule Field: 40 million compared, none differed), so a draw binding a range an earlier draw of the recording
copied, with the same captures in view, is given that copy (RX_VK_UB_SNAP_DEDUP=0: off). The copies a draw still makes
are read together at the end of its descriptor build, pools_mu taken once (RX_VK_UB_READ_BATCH=0: off).

Shared copies make a draw's uniform buffer writes often the same as the last push's; left out of the delta push as
unchanged, the B580 drew objects with other objects' matrices. Every uniform buffer write is pushed each draw when the
copies are shared, as every one was before (each draw had copies of its own); textures and storage buffers stay delta.

Market, B580, the snapshot on, uncapped, 3 interleaved runs each: 54.9 -> 59.5 fps (median),
median frame 17.45 -> 16.48 ms; the replay's descriptors 6.12 -> 2.64 ms a frame.

The checks that compile bind_descriptors and memory_read_as_submitted know the new helpers and the split read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs: the uniform copy sharing's 6 market runs on an Arc B580 (3 with, 3 without), and its read check's cost
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
7a5e59083e
docs/tested: the runs of perf/vk-ub-reads-once's A/B. docs/development.md: RX_VK_UB_READ_BATCH=2 reads the stream's
memory back, a few frames a second (1.7 fps in the market on a B580; 1.2 million reads made again, none differed).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11, Intel Arc B580, driver 32.0.101.9154, i5-13600K, with the uniform snapshot on (as #446 sets it), render 75% with Intel XeSS: Castle Town's market as child by day, 3 runs with the change and 3 without, 54.9 to 59.5 fps and the descriptors 6.1 to 2.6 ms a frame, no device lost; walking through the market with the flash detector, the change on and off: no flash, no white or black frame; the check modes RX_VK_UB_SNAP_DEDUP=2 (40 million copies in the market, Kokiri Forest and Hyrule Field) and RX_VK_UB_READ_BATCH=2 (1.2 million reads) found no copy different.

Tested in game: Windows 11, Intel Arc B580, driver 32.0.101.9154, i5-13600K, with the uniform snapshot on (as #446 sets it), render 75% with Intel XeSS: Castle Town's market as child by day, 3 runs with the change and 3 without, 54.9 to 59.5 fps and the descriptors 6.1 to 2.6 ms a frame, no device lost; walking through the market with the flash detector, the change on and off: no flash, no white or black frame; the check modes RX_VK_UB_SNAP_DEDUP=2 (40 million copies in the market, Kokiri Forest and Hyrule Field) and RX_VK_UB_READ_BATCH=2 (1.2 million reads) found no copy different.
Author
Contributor

@Beanstalk two runs for this PR, please (it still merges cleanly onto main 0691f81c):

  1. linux, any GPU: build the renderer (longshot_vk.so) from this branch, then child Link in Castle Town's market by day, 60 s after 40 s to settle, with RX_VK_UB_SNAPSHOT=1 (the uniform snapshot this PR speeds up; off by default there), once as it is and once with RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0 (this PR's sharing and batched reads off). Expected: it builds; the log line uniform copies (RX_VK_UB_SNAP_DEDUP=1) in the first run; the same picture both ways (no object drawn with another's matrices, no white blocks), no device lost, and no lower fps in the first run.
  2. an Intel iGPU (Core Ultra, or 12th to 14th gen Iris Xe or UHD), Windows or Linux, if the farm has one: Kokiri Forest and the market by day, 60 s each, with the defaults (the snapshot is on there) and again with RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0. Expected: the same picture both ways (no sky over the forest's ground, no white blocks), the uniform copies line with the defaults, and no lower fps with them.
@Beanstalk two runs for this PR, please (it still merges cleanly onto main 0691f81c): 1. linux, any GPU: build the renderer (`longshot_vk.so`) from this branch, then child Link in Castle Town's market by day, 60 s after 40 s to settle, with `RX_VK_UB_SNAPSHOT=1` (the uniform snapshot this PR speeds up; off by default there), once as it is and once with `RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0` (this PR's sharing and batched reads off). Expected: it builds; the log line `uniform copies (RX_VK_UB_SNAP_DEDUP=1)` in the first run; the same picture both ways (no object drawn with another's matrices, no white blocks), no device lost, and no lower fps in the first run. 2. an Intel iGPU (Core Ultra, or 12th to 14th gen Iris Xe or UHD), Windows or Linux, if the farm has one: Kokiri Forest and the market by day, 60 s each, with the defaults (the snapshot is on there) and again with `RX_VK_UB_SNAP_DEDUP=0 RX_VK_UB_READ_BATCH=0`. Expected: the same picture both ways (no sky over the forest's ground, no white blocks), the `uniform copies` line with the defaults, and no lower fps with them.
Member

@nyannoying only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it. This request was for 7a5e590, and the PR has changed since (fb2f963), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@nyannoying only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it.~~ This request was for `7a5e590`, and the PR has changed since (`fb2f963`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
dyst left a comment

Nice, contained change. The sharing is keyed tightly (address, size, the recording's epoch, the capture view), the batched read reuses the same unlocked/locked halves as the single read, and with both switches at 0 the path is main's. I also checked two things that could have gone wrong, and both hold: a queued read's pointer into a stream the recording has moved off stays valid until the slot's next recording, and uniform_range is only reached from build_descriptors, so every queued read is flushed before the bind.

  1. The bind_descriptors change is a workaround with no known cause. Unchanged uniform-buffer writes are already skipped today on the same GPU: the bank cache and c1 give the same buffer and offset draw after draw. And RX_VK_UB_SNAP_DEDUP=2 can't exercise the skip, because every copy there has its own offset. So "the driver drops unchanged writes" isn't shown yet. Could you try RX_VK_PUSH_ALL=1 with the sharing on and again removed, and RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1 on the B580? If the second also fixes the wrong matrices, part of what #446's snapshot fixes on Arc is the delta push, and that changes what both PRs should do. Also, again re-pushes the banks and c1 at every draw, not only the shared copies.
  2. This conflicts with #977 in vk_memory.cpp (git merge-tree shows it). #977 adds late_defer_cpu_read to the per-page loop that this PR moves into submitted_read_locked, and tests/test_late_defer.py looks for that hook in memory_read_as_submitted's text. Whichever PR lands second should put the hook in submitted_read_locked. Otherwise the batched reads skip it on Intel iGPUs, where both are on (no mirrors).

This is a code read only: nothing was built or run.

🤖 Generated with Claude Code

Nice, contained change. The sharing is keyed tightly (address, size, the recording's epoch, the capture view), the batched read reuses the same unlocked/locked halves as the single read, and with both switches at 0 the path is main's. I also checked two things that could have gone wrong, and both hold: a queued read's pointer into a stream the recording has moved off stays valid until the slot's next recording, and `uniform_range` is only reached from `build_descriptors`, so every queued read is flushed before the bind. 1. The `bind_descriptors` change is a workaround with no known cause. Unchanged uniform-buffer writes are already skipped today on the same GPU: the bank cache and c1 give the same buffer and offset draw after draw. And `RX_VK_UB_SNAP_DEDUP=2` can't exercise the skip, because every copy there has its own offset. So "the driver drops unchanged writes" isn't shown yet. Could you try `RX_VK_PUSH_ALL=1` with the sharing on and `again` removed, and `RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1` on the B580? If the second also fixes the wrong matrices, part of what #446's snapshot fixes on Arc is the delta push, and that changes what both PRs should do. Also, `again` re-pushes the banks and c1 at every draw, not only the shared copies. 2. This conflicts with #977 in `vk_memory.cpp` (`git merge-tree` shows it). #977 adds `late_defer_cpu_read` to the per-page loop that this PR moves into `submitted_read_locked`, and `tests/test_late_defer.py` looks for that hook in `memory_read_as_submitted`'s text. Whichever PR lands second should put the hook in `submitted_read_locked`. Otherwise the batched reads skip it on Intel iGPUs, where both are on (no mirrors). This is a code read only: nothing was built or run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
@ -4329,0 +4461,4 @@
// drew objects with other objects' matrices (Castle Town's market). Before the sharing each draw had copies of its own, so
// every one of its uniform buffer writes had changed and was pushed: they still all are, the textures and storage buffers
// only when changed, as before
static const bool ub_every = ub_snapshot_on() && ub_snap_dedup_mode() == 1;
Member

Identical uniform-buffer writes are already left out of the push here on the B580: the bank cache returns {c.buf, c.at, n} and c1 returns {it->second.first, it->second.second, n} draw after draw. So this probably isn't the driver dropping every unchanged write. An A/B with RX_VK_PUSH_ALL=1 (sharing on, again removed) and one with RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1 would show whether the delta push or the shared copy is behind the wrong matrices. Also, again matches every VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER write, so banks and c1 are now pushed at every draw too.

Identical uniform-buffer writes are already left out of the push here on the B580: the bank cache returns `{c.buf, c.at, n}` and c1 returns `{it->second.first, it->second.second, n}` draw after draw. So this probably isn't the driver dropping every unchanged write. An A/B with `RX_VK_PUSH_ALL=1` (sharing on, `again` removed) and one with `RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1` would show whether the delta push or the shared copy is behind the wrong matrices. Also, `again` matches every `VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER` write, so banks and c1 are now pushed at every draw too.
@ -1337,0 +1340,4 @@
return 2;
}
/// (pools_mu held) the pages of that read a capture holds, copied over what guest memory gave: how many
int64_t submitted_read_locked(uint64_t guest, void* dst, uint64_t n) {
Member

Heads-up: #977 adds if (late_defer_any()) late_defer_cpu_read(...) inside this per-page loop (on the old memory_read_as_submitted), and the two branches conflict here. Whichever lands second should put it in this function, so memory_read_as_submitted_many gets it too, and point tests/test_late_defer.py's text check here.

Heads-up: #977 adds `if (late_defer_any()) late_defer_cpu_read(...)` inside this per-page loop (on the old `memory_read_as_submitted`), and the two branches conflict here. Whichever lands second should put it in this function, so `memory_read_as_submitted_many` gets it too, and point `tests/test_late_defer.py`'s text check here.
Author
Contributor

@dyst both runs are done on the B580: it is the delta push, and, as you suspected, not every unchanged uniform-buffer write.

Windows 11, Arc B580, driver 32.0.101.9154, render 75% with Intel XeSS (Ultra Quality); Kokiri Forest and Castle Town's market as child by day, standing, 40 s to settle and 8 s measured; two sessions of each setup, the second round in reverse order. The builds: #446's head, and this PR rebased onto it with again behind a local switch, both on the renderer my game folder runs. The picture is checked as numbers: each frame's brightness in 16x9 blocks, averaged over the window and compared with this PR's own (its two sessions differ by 0.7-0.8 on 0-255), and the region-flash count.

Setup fps, Kokiri / market GPU ms a frame, Kokiri / market Replay ms a frame in the market (descriptors) Region flashes, Kokiri / market (dark pictures) Picture off this PR's, Kokiri / market
#446 alone 87.2 / 54.0 8.2 / 12.1 15.23 (6.12) 0 / 0 (0) 0.8 / 2.9 ¹
RX_VK_UB_SNAPSHOT=0 74.7 / 53.7 10.5 / 13.4 10.12 (1.82) 742 / 32 (26) 50.2 / 75.5
RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1 91.5 / 59.6 8.1 / 12.1 10.79 (1.89) 0 / 0 (0) 0.9 / 0.6
this PR 93.2 / 59.2 8.2 / 12.0 11.92 (2.95) 0 / 0 (0) 0.8 / 0.7 ²
this PR, again removed 75.2 / 56.2 10.6 / 13.3 10.77 (2.61) 596 / 190 (4) 45.0 / 79.9
this PR, again removed, RX_VK_PUSH_ALL=1 94.7 / 59.3 8.0 / 12.1 11.80 (2.80) 0 / 0 (0) 1.2 / 0.5

Medians of the two sessions; the flashes and dark pictures summed over both (the flash lines stop at 400 a session, so the broken setups' counts are floors). ¹ In the market, #446 alone differs only in the middle of the picture (12 of 144 blocks more than 10 off, none near the edges, no flash); not looked into further. ² This PR's two sessions against each other.

(The fps of the two broken setups isn't comparable: their scene isn't the same one.)

  1. RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1 alone fixes the wrong matrices (0.9 and 0.6 off this PR's picture, no region flash). So what #446's snapshot fixes on the B580 is the delta push, not uniforms rewritten under a range bound in place: with each draw's own copies, every uniform-buffer write is new, so every one is pushed.
  2. With the sharing on and again removed, the picture breaks as with the snapshot off (sky over the forest's ground, white blocks: 45 and 80 off), and RX_VK_PUSH_ALL=1 puts it right (1.2 and 0.5 off). The shared copies hold the right bytes; leaving their writes out of the push, as unchanged, is what goes wrong.
  3. Not every unchanged uniform-buffer write, as you said: #446 alone leaves the banks and c1 out of the push when unchanged and draws right. So the B580 doesn't get every unchanged write wrong; the comment in bind_descriptors will say which ones, once that is known. What it trips on is still open. A local build now runs with the snapshot off, adding the uniform-buffer writes to one kind of push at a time: a push that carries other writes but no uniform buffer, a draw that would push nothing, or a push that already carries one. It also counts how often each kind happens. That should say what it is, and whether again needs the banks and c1. I'll add the result here.

Walking with this PR's build (Kakariko Village, then the market, 40 s each on the same path; one session each), the frames with two or more regions darker / brighter than both neighbours: this PR 0 / 0 and 6 / 6; without again 1,194 / 309 and 1,516 / 327; without again, with RX_VK_PUSH_ALL=1, 0 / 1 and 3 / 2 (out of 2,400 to 3,000 frames an area; the flash lines stop at 400 a session, so these are the region test's own totals).

On #977: noted. Whichever lands second puts late_defer_cpu_read in submitted_read_locked, so memory_read_as_submitted_many gets it too, and points tests/test_late_defer.py's text check there. If that's this PR, it goes into its rebase.

What this means for #446 and for this PR is on #446 (#446): with the snapshot off and every descriptor pushed, the B580 draws this PR's picture at this PR's fps, with no copies at all.

🤖 Generated with Claude Code

@dyst both runs are done on the B580: it is the delta push, and, as you suspected, not every unchanged uniform-buffer write. Windows 11, Arc B580, driver 32.0.101.9154, render 75% with Intel XeSS (Ultra Quality); Kokiri Forest and Castle Town's market as child by day, standing, 40 s to settle and 8 s measured; two sessions of each setup, the second round in reverse order. The builds: #446's head, and this PR rebased onto it with `again` behind a local switch, both on the renderer my game folder runs. The picture is checked as numbers: each frame's brightness in 16x9 blocks, averaged over the window and compared with this PR's own (its two sessions differ by 0.7-0.8 on 0-255), and the region-flash count. | Setup | fps, Kokiri / market | GPU ms a frame, Kokiri / market | Replay ms a frame in the market (descriptors) | Region flashes, Kokiri / market (dark pictures) | Picture off this PR's, Kokiri / market | |---|---|---|---|---|---| | #446 alone | 87.2 / 54.0 | 8.2 / 12.1 | 15.23 (6.12) | 0 / 0 (0) | 0.8 / 2.9 ¹ | | `RX_VK_UB_SNAPSHOT=0` | 74.7 / 53.7 | 10.5 / 13.4 | 10.12 (1.82) | 742 / 32 (26) | 50.2 / 75.5 | | `RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1` | 91.5 / 59.6 | 8.1 / 12.1 | 10.79 (1.89) | 0 / 0 (0) | 0.9 / 0.6 | | this PR | 93.2 / 59.2 | 8.2 / 12.0 | 11.92 (2.95) | 0 / 0 (0) | 0.8 / 0.7 ² | | this PR, `again` removed | 75.2 / 56.2 | 10.6 / 13.3 | 10.77 (2.61) | 596 / 190 (4) | 45.0 / 79.9 | | this PR, `again` removed, `RX_VK_PUSH_ALL=1` | 94.7 / 59.3 | 8.0 / 12.1 | 11.80 (2.80) | 0 / 0 (0) | 1.2 / 0.5 | Medians of the two sessions; the flashes and dark pictures summed over both (the flash lines stop at 400 a session, so the broken setups' counts are floors). ¹ In the market, #446 alone differs only in the middle of the picture (12 of 144 blocks more than 10 off, none near the edges, no flash); not looked into further. ² This PR's two sessions against each other. (The fps of the two broken setups isn't comparable: their scene isn't the same one.) 1. **`RX_VK_UB_SNAPSHOT=0 RX_VK_PUSH_ALL=1` alone fixes the wrong matrices** (0.9 and 0.6 off this PR's picture, no region flash). So what #446's snapshot fixes on the B580 is the delta push, not uniforms rewritten under a range bound in place: with each draw's own copies, every uniform-buffer write is new, so every one is pushed. 2. **With the sharing on and `again` removed, the picture breaks as with the snapshot off** (sky over the forest's ground, white blocks: 45 and 80 off), and `RX_VK_PUSH_ALL=1` puts it right (1.2 and 0.5 off). The shared copies hold the right bytes; leaving their writes out of the push, as unchanged, is what goes wrong. 3. **Not every unchanged uniform-buffer write, as you said:** #446 alone leaves the banks and c1 out of the push when unchanged and draws right. So the B580 doesn't get every unchanged write wrong; the comment in `bind_descriptors` will say which ones, once that is known. What it trips on is still open. A local build now runs with the snapshot off, adding the uniform-buffer writes to one kind of push at a time: a push that carries other writes but no uniform buffer, a draw that would push nothing, or a push that already carries one. It also counts how often each kind happens. That should say what it is, and whether `again` needs the banks and c1. I'll add the result here. Walking with this PR's build (Kakariko Village, then the market, 40 s each on the same path; one session each), the frames with two or more regions darker / brighter than both neighbours: this PR 0 / 0 and 6 / 6; without `again` 1,194 / 309 and 1,516 / 327; without `again`, with `RX_VK_PUSH_ALL=1`, 0 / 1 and 3 / 2 (out of 2,400 to 3,000 frames an area; the flash lines stop at 400 a session, so these are the region test's own totals). On #977: noted. Whichever lands second puts `late_defer_cpu_read` in `submitted_read_locked`, so `memory_read_as_submitted_many` gets it too, and points `tests/test_late_defer.py`'s text check there. If that's this PR, it goes into its rebase. What this means for #446 and for this PR is on #446 (https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/446): with the snapshot off and every descriptor pushed, the B580 draws this PR's picture at this PR's fps, with no copies at all. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Contributor

@dyst the result of the local build from point 3: the snapshot off (main's delta push), and the uniform-buffer writes the delta left out added back to one kind of push at a time. Standing as before, one session each; the build also counted the delta pushes (about 7.3 million a session).

Uniform-buffer writes added to How often (a session) Region flashes, Kokiri / market (dark pictures) Picture off this PR's, Kokiri / market
nothing (main's delta push) - 375 / 23 (15) 50.4 / 77.2
a push that carries other writes but no uniform buffer ~15,000 (0.2%) 379 / 13 (11) 48.2 / 76.8
a draw that would push nothing ~165 358 / 33 (23) 53.0 / 74.6
a push that carries a uniform-buffer write already ~7.3 million (99.8%) 0 / 0 (0) 1.2 / 0.6
all three 0 / 0 (0) 1.1 / 0.5

(The flash lines stop at 400 a session, so the broken rows' counts are floors.)

So what the B580 gets wrong is a push that carries some of a draw's uniform-buffer writes and leaves others out as unchanged: the draw then reads wrong data. Pushing the ones left out along with it puts the picture right; adding them anywhere else doesn't. again pushes every uniform-buffer write in every push, so it covers that case (it is 99.8% of the pushes anyway).

The banks and c1 still fit: with #446 alone they are left out unchanged from pushes whose other uniform-buffer writes are all new copies, and the picture is right. So it isn't every uniform buffer left out; what tells the bad ones apart is still open. I haven't tried again without the banks and c1, so I can't say it may skip them. The rebase's comment in bind_descriptors will say what is known: a push that carries one of a draw's uniform-buffer writes carries them all.

🤖 Generated with Claude Code

@dyst the result of the local build from point 3: the snapshot off (main's delta push), and the uniform-buffer writes the delta left out added back to one kind of push at a time. Standing as before, one session each; the build also counted the delta pushes (about 7.3 million a session). | Uniform-buffer writes added to | How often (a session) | Region flashes, Kokiri / market (dark pictures) | Picture off this PR's, Kokiri / market | |---|---|---|---| | nothing (main's delta push) | - | 375 / 23 (15) | 50.4 / 77.2 | | a push that carries other writes but no uniform buffer | ~15,000 (0.2%) | 379 / 13 (11) | 48.2 / 76.8 | | a draw that would push nothing | ~165 | 358 / 33 (23) | 53.0 / 74.6 | | a push that carries a uniform-buffer write already | ~7.3 million (99.8%) | 0 / 0 (0) | 1.2 / 0.6 | | all three | | 0 / 0 (0) | 1.1 / 0.5 | (The flash lines stop at 400 a session, so the broken rows' counts are floors.) So what the B580 gets wrong is a push that carries some of a draw's uniform-buffer writes and leaves others out as unchanged: the draw then reads wrong data. Pushing the ones left out along with it puts the picture right; adding them anywhere else doesn't. `again` pushes every uniform-buffer write in every push, so it covers that case (it is 99.8% of the pushes anyway). The banks and c1 still fit: with #446 alone they are left out unchanged from pushes whose other uniform-buffer writes are all new copies, and the picture is right. So it isn't every uniform buffer left out; what tells the bad ones apart is still open. I haven't tried `again` without the banks and c1, so I can't say it may skip them. The rebase's comment in `bind_descriptors` will say what is known: a push that carries one of a draw's uniform-buffer writes carries them all. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nyannoying force-pushed perf/vk-ub-reads-once from 7a5e59083e
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to fb2f963a47
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-16 15:40:26 +00:00
Compare
Author
Contributor

Pushed fb2f963a: three commits on #446's head a1c51ef2 (main 71b1edd8):

  • 020a91ef perf(vk): rebased onto #446's guard. The snapshot's decision is #446's ub_snapshot_wanted() (this PR's own ub_snapshot_on() is gone); a range the guard binds in place is bound before the sharing is asked; and the comment in bind_descriptors gives the B580's cause as measured (my comment above: a push that carries some of a draw's uniform buffer writes and leaves others out as unchanged). The RX_VK_UB_SNAP_DEDUP row says the snapshot is on by default on Intel GPUs (#446). Its code lines are those of 1076e816, the build #446's A/B ran; only comments changed since.
  • 0b5fc0dc docs: the same, with an Assisted-by: trailer.
  • fb2f963a docs(tested): one file for each run of this PR's arm in #446's A/B (4 standing sessions, 3 walks).

The description: Measurements has the A/B with #446's guard (Kokiri Forest 86.85 → 93.15 fps, the Market 54.35 → 59.45, standing, 4 and 4 sessions), and Testing the new head's checks.

Checked at fb2f963a on this PC: the renderer builds (RX_VK_ONLY, llvm-mingw, 0 warnings); run_all: 611 passed, 25 failed, 43 skipped; main 71b1edd8 609, 25 and 43, the same 25 failing.

🤖 Generated with Claude Code

Pushed fb2f963a: three commits on #446's head a1c51ef2 (main 71b1edd8): - 020a91ef perf(vk): rebased onto #446's guard. The snapshot's decision is #446's `ub_snapshot_wanted()` (this PR's own `ub_snapshot_on()` is gone); a range the guard binds in place is bound before the sharing is asked; and the comment in `bind_descriptors` gives the B580's cause as measured (my comment above: a push that carries some of a draw's uniform buffer writes and leaves others out as unchanged). The `RX_VK_UB_SNAP_DEDUP` row says the snapshot is on by default on Intel GPUs (#446). Its code lines are those of 1076e816, the build #446's A/B ran; only comments changed since. - 0b5fc0dc docs: the same, with an `Assisted-by:` trailer. - fb2f963a docs(tested): one file for each run of this PR's arm in #446's A/B (4 standing sessions, 3 walks). The description: Measurements has the A/B with #446's guard (Kokiri Forest 86.85 → 93.15 fps, the Market 54.35 → 59.45, standing, 4 and 4 sessions), and Testing the new head's checks. Checked at fb2f963a on this PC: the renderer builds (`RX_VK_ONLY`, llvm-mingw, 0 warnings); run_all: 611 passed, 25 failed, 43 skipped; main 71b1edd8 609, 25 and 43, the same 25 failing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nyannoying force-pushed perf/vk-ub-reads-once from fb2f963a47
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 3d43b0ee34
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-16 18:11:52 +00:00
Compare
Author
Contributor

Rebased onto main 60bf15bd: head 3d43b0ee.

  • The conflict @dyst foresaw: #977, now on main, put its late pages' hook (late_defer_cpu_read()) in the page loop this PR moves into submitted_read_locked(). The hook moved with the loop, so the reads made together (memory_read_as_submitted_many()) take a late page's copy again before reading it, as a read on its own does. tests/test_late_defer.py looks for the hook there now, and checks that both reads go through submitted_read_locked(). Its text check fails with the hook taken out, with the hook after the copy, and with either read not calling submitted_read_locked() (four edits, each run).
  • #446's seven commits under this PR's three were rebased with them and are unchanged. #446's own head, a1c51ef2, merges without a rebase, so it isn't pushed again.
  • The description's ub_snapshot_on() line was stale since the 15:40 push: the default is #446's ub_snapshot_wanted(). It says that now.

Checked at 3d43b0ee:

  • Built at the new head: the renderer alone (RX_VK_ONLY, llvm-mingw), 0 warnings.
  • tests/test_late_defer.py passes here and on main 60bf15bd.
  • python -I -B tests/run_all.py (llvm-mingw and the toolchain's Vulkan headers): 622 passed, 26 failed, 44 skipped here; main 60bf15bd 621, 25 and 44. The 26th is test_coverage_run, which fails on this PC whenever no game is running, on main too (run alone after the suite, it failed on both).

Why the numbers still hold, not measured again: the in-game A/B is this PR's renderer diff on and off on one build of the game folder's source (the Baseline line), and that diff changed only where #977's hook sits. The hook isn't in the measured builds' source, and on the B580 it is off (late_defer_on(): off where the pools have mirrors). Main's other changes since 71b1edd8 are in neither column.

🤖 Generated with Claude Code

Rebased onto `main` 60bf15bd: head 3d43b0ee. - The conflict @dyst foresaw: #977, now on `main`, put its late pages' hook (`late_defer_cpu_read()`) in the page loop this PR moves into `submitted_read_locked()`. The hook moved with the loop, so the reads made together (`memory_read_as_submitted_many()`) take a late page's copy again before reading it, as a read on its own does. `tests/test_late_defer.py` looks for the hook there now, and checks that both reads go through `submitted_read_locked()`. Its text check fails with the hook taken out, with the hook after the copy, and with either read not calling `submitted_read_locked()` (four edits, each run). - #446's seven commits under this PR's three were rebased with them and are unchanged. #446's own head, a1c51ef2, merges without a rebase, so it isn't pushed again. - The description's `ub_snapshot_on()` line was stale since the 15:40 push: the default is #446's `ub_snapshot_wanted()`. It says that now. Checked at 3d43b0ee: - Built at the new head: the renderer alone (`RX_VK_ONLY`, llvm-mingw), 0 warnings. - `tests/test_late_defer.py` passes here and on `main` 60bf15bd. - `python -I -B tests/run_all.py` (llvm-mingw and the toolchain's Vulkan headers): 622 passed, 26 failed, 44 skipped here; `main` 60bf15bd 621, 25 and 44. The 26th is `test_coverage_run`, which fails on this PC whenever no game is running, on `main` too (run alone after the suite, it failed on both). Why the numbers still hold, not measured again: the in-game A/B is this PR's renderer diff on and off on one build of the game folder's source (the Baseline line), and that diff changed only where #977's hook sits. The hook isn't in the measured builds' source, and on the B580 it is off (`late_defer_on()`: off where the pools have mirrors). Main's other changes since 71b1edd8 are in neither column. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nyannoying force-pushed perf/vk-ub-reads-once from 3d43b0ee34
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to e68d88597e
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Has been cancelled
2026-11-16 18:13:40 +00:00
Compare
Author
Contributor

#446 is merged (0cab3548), so this branch is now just this PR's three commits on it: head e68d8859. #446's seven commits are no longer in the diff.

The files are the same as 3d43b0ee's: #446's merge has the same tree as the #446 commits that were under this PR (git diff of the two is empty), and git diff 3d43b0ee e68d8859 is empty too. So the build and the checks in my last comment hold for this head.

The description no longer has the "Stacked on #446" note. Its Not tested line now says the snapshot is on for every Intel GPU on main.

🤖 Generated with Claude Code

#446 is merged (0cab3548), so this branch is now just this PR's three commits on it: head e68d8859. #446's seven commits are no longer in the diff. The files are the same as 3d43b0ee's: #446's merge has the same tree as the #446 commits that were under this PR (`git diff` of the two is empty), and `git diff 3d43b0ee e68d8859` is empty too. So the build and the checks in my last comment hold for this head. The description no longer has the "Stacked on #446" note. Its *Not tested* line now says the snapshot is on for every Intel GPU on `main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
futondestroyer left a comment

Reviewed current head e68d88597e8c3ffacac74afe85e034e57c06dd4c, code and posted evidence only. Request changes for the snapshot-off fallback path noted inline; not ready for merge. Nothing built, tested or launched in this review, and no source changes pushed.

The earlier review's two concerns have substantive answers in this head:

  • The late-page hook is in submitted_read_locked(), before copying the capture's bytes. Both the single and batched readers call it under pools_mu. The updated late-defer wiring check covers both callers; the author reports mutation checks removing/moving the hook and disconnecting either caller. I am not repeating the old conflict with #977, which is already merged.
  • The B580 isolation results distinguish partial uniform pushes from unchanged writes in general. The new comment correctly limits the conclusion, and both push-state implementations re-push all uniform writes when sharing is enabled with the snapshot. The empirical workaround is now explained; a driver-level cause is still not established.

The address/size/capture-view/recording-epoch key prevents reuse across recordings or capture views. Stream growth retains the old buffers/mappings, so queued destinations and memoized buffer offsets survive a move to the next stream. UbReadsScope flushes before descriptor binding on the normal descriptor-build exits. The shared locked reader retains both late-fix and late-defer handling. No renderer ABI, vendored code or generated shader changes are involved.

One scope/correctness gap remains: uniform_range() reaches the new dedup and batch code when gpu_buffer_bind() fails or returns an unaligned range even if ub_snapshot_wanted() is false. Thus this is not confined to the snapshot-on path described by the PR. The inline comment asks to preserve the old fallback path when snapshotting is off, or explicitly make the broader path safe and validate it; the existing sampler fixture stubs snapshotting off and therefore does not exercise the new sharing/re-push combination.

Evidence acknowledged, not independently rerun: Windows B580 interleaved A/Bs report +7.3% in Kokiri Forest and +9.4% in the Market with the merged snapshot guard. The author reports a warning-free Windows renderer build and baseline-compared full suites on the tree reported identical to this head, including the separately reproduced baseline test_coverage_run failure. The timing builds contain other explicitly disclosed changes and the description explains why the rebase's late-defer-hook move does not affect those B580 numbers. Standing region tests reported zero detections; the later walking runs have nonzero dark/bright region detections, so they should not be summarized as zero walking flashes or as proof of no visual regression.

Remaining readiness evidence: an Intel iGPU run with defaults versus both optimizations disabled, and a Linux renderer build plus snapshot-on Market run. These are still explicitly required in Testing. The old farm request targets 7a5e590, not this head, and is marked stale; it does not satisfy current-head coverage. Keep WIP until the outstanding coverage and applicable checklist are settled.

Overlap: #446 and #977 are already in the base. Open #1158 touches recording-stream ownership, #794 touches descriptor reuse, and #759 and #326 touch capture/memory code. They are related work, not identified duplicates; whichever lands later needs its affected lifetime/read paths checked against the merged version.

Reviewed current head `e68d88597e8c3ffacac74afe85e034e57c06dd4c`, code and posted evidence only. **Request changes for the snapshot-off fallback path noted inline; not ready for merge.** Nothing built, tested or launched in this review, and no source changes pushed. The earlier review's two concerns have substantive answers in this head: - The late-page hook is in `submitted_read_locked()`, before copying the capture's bytes. Both the single and batched readers call it under `pools_mu`. The updated late-defer wiring check covers both callers; the author reports mutation checks removing/moving the hook and disconnecting either caller. I am not repeating the old conflict with https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/977, which is already merged. - The B580 isolation results distinguish partial uniform pushes from unchanged writes in general. The new comment correctly limits the conclusion, and both push-state implementations re-push all uniform writes when sharing is enabled with the snapshot. The empirical workaround is now explained; a driver-level cause is still not established. The address/size/capture-view/recording-epoch key prevents reuse across recordings or capture views. Stream growth retains the old buffers/mappings, so queued destinations and memoized buffer offsets survive a move to the next stream. `UbReadsScope` flushes before descriptor binding on the normal descriptor-build exits. The shared locked reader retains both late-fix and late-defer handling. No renderer ABI, vendored code or generated shader changes are involved. One scope/correctness gap remains: `uniform_range()` reaches the new dedup and batch code when `gpu_buffer_bind()` fails or returns an unaligned range **even if `ub_snapshot_wanted()` is false**. Thus this is not confined to the snapshot-on path described by the PR. The inline comment asks to preserve the old fallback path when snapshotting is off, or explicitly make the broader path safe and validate it; the existing sampler fixture stubs snapshotting off and therefore does not exercise the new sharing/re-push combination. Evidence acknowledged, not independently rerun: Windows B580 interleaved A/Bs report +7.3% in Kokiri Forest and +9.4% in the Market with the merged snapshot guard. The author reports a warning-free Windows renderer build and baseline-compared full suites on the tree reported identical to this head, including the separately reproduced baseline `test_coverage_run` failure. The timing builds contain other explicitly disclosed changes and the description explains why the rebase's late-defer-hook move does not affect those B580 numbers. Standing region tests reported zero detections; the later walking runs have nonzero dark/bright region detections, so they should not be summarized as zero walking flashes or as proof of no visual regression. Remaining readiness evidence: an Intel iGPU run with defaults versus both optimizations disabled, and a Linux renderer build plus snapshot-on Market run. These are still explicitly required in Testing. The old farm request targets `7a5e590`, not this head, and is marked stale; it does not satisfy current-head coverage. Keep WIP until the outstanding coverage and applicable checklist are settled. Overlap: https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/446 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/977 are already in the base. Open https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1158 touches recording-stream ownership, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/794 touches descriptor reuse, and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/759 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/326 touch capture/memory code. They are related work, not identified duplicates; whichever lands later needs its affected lifetime/read paths checked against the merged version.
@ -3494,12 +3603,26 @@ VkDescriptorBufferInfo uniform_range(const NvnState& s, const Stage& st, uint32_
static std::atomic<int64_t> after_gpu[2][2];
if (gpu_written) after_gpu[gpu_written - 1][b && b.offset % align == 0 ? 0 : 1].fetch_add(1, std::memory_order_relaxed);
if (b && b.offset % align == 0) return {b.buffer, b.offset, n};
static const int dedup = ub_snap_dedup_mode(); // (the recording's earlier copy of the range: ub_snap_slot)
Member

[P2] Preserve the fallback path when the uniform snapshot is off. The early return immediately above only handles a successful aligned gpu_buffer_bind(). If snapshot is false and that bind fails or is unaligned, dedup still defaults to 1 here and batching defaults to 1 below: repeated fallback ranges now reuse a stream copy and their reads move to descriptor-build exit. This changes the default AMD/NVIDIA fallback path and explicit RX_VK_UB_SNAPSHOT=0 runs despite the stated snapshot-only scope. It also creates shared fallback UB writes while bind_descriptors disables its re-push safeguard via ub_snapshot_wanted() && ub_snap_dedup_mode() == 1; on the documented B580 partial-push failure path those shared writes can again be omitted. Gate both new optimizations on snapshot here, leaving the immediate per-binding read when it is false, or intentionally support the broader fallback path with matching push handling, documentation and evidence. Add a behavioral fixture for snapshot off with an unaligned/out-of-pool binding repeated across draws; the updated sampler fixture only tests the non-snapshot descriptor path without exercising these copies. This is a code-path finding, not a claimed new in-game reproduction.

[P2] Preserve the fallback path when the uniform snapshot is off. The early return immediately above only handles a successful aligned gpu_buffer_bind(). If snapshot is false and that bind fails or is unaligned, dedup still defaults to 1 here and batching defaults to 1 below: repeated fallback ranges now reuse a stream copy and their reads move to descriptor-build exit. This changes the default AMD/NVIDIA fallback path and explicit RX_VK_UB_SNAPSHOT=0 runs despite the stated snapshot-only scope. It also creates shared fallback UB writes while bind_descriptors disables its re-push safeguard via ub_snapshot_wanted() && ub_snap_dedup_mode() == 1; on the documented B580 partial-push failure path those shared writes can again be omitted. Gate both new optimizations on snapshot here, leaving the immediate per-binding read when it is false, or intentionally support the broader fallback path with matching push handling, documentation and evidence. Add a behavioral fixture for snapshot off with an unaligned/out-of-pool binding repeated across draws; the updated sampler fixture only tests the non-snapshot descriptor path without exercising these copies. This is a code-path finding, not a claimed new in-game reproduction.
Some checks failed
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Has been cancelled
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-ub-reads-once:nyannoying-perf/vk-ub-reads-once'
git switch 'nyannoying-perf/vk-ub-reads-once'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!952
No description provided.