perf(vk): the restored speed-ups not yet in main, refreshed on current main #2096

Open
avidela wants to merge 11 commits from avidela/Longshot:perf/radv-cohort into main
First-time contributor

Type: perf · Risk: low · Tested on: Linux, RX 5700 XT (RADV) · Needs: Windows, any GPU; a faster CPU than a Ryzen 5 3600 to show sub-milliamp savings

Summary

Upstream's closed #288 (the restored speed-ups) still had commits main never took, and its blocker was that nobody had measured it. This PR audits its 14 perf commits against current main (8 are already absorbed in evolved form; 2 collide with siantm's open #2054 and #2029 and are deliberately not re-ported), ports the four genuinely missing renderer/memory ones onto current main, and measures the result: parity, which the audit predicts, because the headline win of that set (excess eviction) is already in main. The FlatMap test-harness fix and the switches.def rows stand on their own.

A reviewer reads first: gpu/vk/vk_draw.cpp (ViewFast, the direct-mapped front cache over handle_hits), gpu/vk/vk_texture.cpp (staging tail suballocation), gpu/vk/vk_memory.cpp (memory_guest_contained, the one-unswizzle import skip), gpu/vk/eden/shader_recompiler (direct 8/16-bit global stores), gpu/vk/switches.def (the three new rows). See #288, whose description is this PR's starting point.

Testing

Tested: on my own PC (Fedora 45, RX 5700 XT, RADV Mesa 26.2.6, Ryzen 5 3600, 15 GB): both arms of the A/B below were played through the standard Hyrule Field run-and-spin route (repo save, teleport destination 1, control-bridge sessions) and by hand; no artifacts, no crashes, no device lost. The full suite (python -I -B tests/run_all.py) fails exactly the environment-dependent set current main fails (main's own test_switch_table sorting break included); test_flat_map.py and test_direct_buffer_writes.py, which break on a naive port, pass here. The Windows Vulkan back end cross-compiles clean with llvm-mingw (longshot_vk.dll, 0 failed); the Linux game build is the A/B's own binary.

Still to test:

  • Windows, any GPU: a normal play session, expecting parity behaviour, no artifacts in the upscaler paths and no crashes (@Beanstalk windows, or by hand)
  • Linux, RADV, any CPU faster than a Ryzen 5 3600: the same Hyrule Field route as run03 below, expecting window medians within noise of main or above it, and no artifacts (@Beanstalk linux, radv, or by hand)

Measurements

Verdict: parity — no measurable gain or regression on this box, on current main. The audit predicts it: the restored set's headline win (excess eviction) is already in main in evolved form.

Setup: Fedora 45 (Linux 7.3.3), GNOME Wayland; RX 5700 XT (RADV NAVI10), Mesa 26.2.6 radv; Ryzen 5 3600, 15 GB. Hyrule Field (child), repo save, teleport destination 1, stick-held run + full-speed camera spin; 1280x720 windowed, Auto preset, the game's own upscaler, cap off (HOS_FPS_MAX=1000); 2 interleaved control-bridge sessions per arm, 30 s windows, phase-matched by draws (light phase ~1090).

Before: main @ a2dc5385 After: this PR @ 8d8de778
Light phase: window-median fps 66.1-69.6 (medians of medians ~68) 68.5-69.8 (~68)
Light phase: p10 fps 60.8-66.0 63.6-66.8
Switch defaults n/a on for everyone; RX_VK_VIEW_FAST=0, RX_VK_NATIVE_NARROW=0, RX_VK_UNSWIZZLE_IMPORT=1 each restore the old behaviour
[hos host] vk: N presents, 68.x fps; a frame: ~1090 draws ...   (main, light phase, settled windows)
[hos host] vk: N presents, 68.x fps; a frame: ~1090 draws ...   (this PR, light phase, settled windows)

An earlier A/B of the same changes on the pre-rebase base (measured at b398975e against main @ d6cbc5d4) measured the same parity, including both of the field's spawn phases (heavy ~1400 draws: 40.2-40.8 both arms); its runs are docs/tested/2026-11-22-restored-speedups-avidela-run01.md and -run02.md, today's fresh current-main A/B is -run03.md. Current main itself measured ~35 % faster than the v3.0.0 release on this box in the same phase (68 vs 50 fps medians) — that gain is main's, not this PR's.

Risks

Compatibility: nothing a player notices — saves, longshot_options.ini, the shader and pipeline caches and the vk ABI are unchanged (the pipeline cache recompiles stamp-changed programs on first run, as any renderer change does).

What could break, where, and how to turn it off:

  • A stale texture view answered from the front cache — gpu/vk/vk_draw.cpp's ViewFast; the map stays the authority and every miss falls back to it. Off with RX_VK_VIEW_FAST=0; reverting is enough.
  • Direct 8/16-bit global stores on a driver that mishandles narrow views — gpu/vk/eden's codegen, part of the program cache stamp. Off with RX_VK_NATIVE_NARROW=0; reverting is enough.
  • A one-upload unswizzle kept on the CPU raising CPU use on a slow machine — gpu/vk/vk_memory.cpp's memory_guest_contained. Off with RX_VK_UNSWIZZLE_IMPORT=1; reverting is enough.
  • The staging tail suballocation handing a later upload a tail it believes untouched — gpu/vk/vk_texture.cpp's arenas; no switch, so reverting the commit is the way back.

All four were played through the Hyrule Field route above with no artifacts, no crashes and no device lost, with parity measurements on both arms.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named): run directly as python -I -B tests/run_all.py here; the failure set is identical to current main's, including main's own test_switch_table sorting break (RX_VK_GRASS_DISTANCE after RX_VK_SIM_TURF_ADAPTIVE, current main), and test_flat_map.py and test_direct_buffer_writes.py pass here where a naive port breaks them.
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def (three rows; the development guide's table carries their descriptions too).

  • A check under tests/ that reads changed source is updated, not weakened (the FlatMap harness rewrites every TLS_OBJECT in its cut of vk_draw.cpp — its old rewrite dropped everything after handle_hits' line; the ViewFast stand-ins in the recording-fragment checks are carried).

  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (The Windows Vulkan back end cross-compiles clean, longshot_vk.dll 0 failed — not run there, see Still to test; the Linux game build is the A/B's own binary.)

  • Docs updated.

    (development.md's switch table gains the three rows; the runs are in docs/tested/, run01-run03.)

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers (the ported commits carry their original authors' trailers and sources; the repair, test and docs commits carry Assisted-by: Claude).

**Type:** perf · **Risk:** low · **Tested on:** Linux, RX 5700 XT (RADV) · **Needs:** Windows, any GPU; a faster CPU than a Ryzen 5 3600 to show sub-milliamp savings ## Summary Upstream's closed #288 (the restored speed-ups) still had commits main never took, and its blocker was that nobody had measured it. This PR audits its 14 perf commits against current main (8 are already absorbed in evolved form; 2 collide with siantm's open #2054 and #2029 and are deliberately not re-ported), ports the four genuinely missing renderer/memory ones onto current main, and measures the result: parity, which the audit predicts, because the headline win of that set (excess eviction) is already in main. The FlatMap test-harness fix and the switches.def rows stand on their own. A reviewer reads first: `gpu/vk/vk_draw.cpp` (`ViewFast`, the direct-mapped front cache over `handle_hits`), `gpu/vk/vk_texture.cpp` (staging tail suballocation), `gpu/vk/vk_memory.cpp` (`memory_guest_contained`, the one-unswizzle import skip), `gpu/vk/eden/shader_recompiler` (direct 8/16-bit global stores), `gpu/vk/switches.def` (the three new rows). See #288, whose description is this PR's starting point. ## Testing **Tested:** on my own PC (Fedora 45, RX 5700 XT, RADV Mesa 26.2.6, Ryzen 5 3600, 15 GB): both arms of the A/B below were played through the standard Hyrule Field run-and-spin route (repo save, teleport destination 1, control-bridge sessions) and by hand; no artifacts, no crashes, no device lost. The full suite (`python -I -B tests/run_all.py`) fails exactly the environment-dependent set current main fails (main's own `test_switch_table` sorting break included); `test_flat_map.py` and `test_direct_buffer_writes.py`, which break on a naive port, pass here. The Windows Vulkan back end cross-compiles clean with llvm-mingw (`longshot_vk.dll`, 0 failed); the Linux game build is the A/B's own binary. **Still to test:** - Windows, any GPU: a normal play session, expecting parity behaviour, no artifacts in the upscaler paths and no crashes (@Beanstalk windows, or by hand) - Linux, RADV, any CPU faster than a Ryzen 5 3600: the same Hyrule Field route as run03 below, expecting window medians within noise of main or above it, and no artifacts (@Beanstalk linux, radv, or by hand) ## Measurements **Verdict:** parity — no measurable gain or regression on this box, on current main. The audit predicts it: the restored set's headline win (excess eviction) is already in main in evolved form. Setup: Fedora 45 (Linux 7.3.3), GNOME Wayland; RX 5700 XT (RADV NAVI10), Mesa 26.2.6 radv; Ryzen 5 3600, 15 GB. Hyrule Field (child), repo save, teleport destination 1, stick-held run + full-speed camera spin; 1280x720 windowed, Auto preset, the game's own upscaler, cap off (HOS_FPS_MAX=1000); 2 interleaved control-bridge sessions per arm, 30 s windows, phase-matched by draws (light phase ~1090). | | Before: main @ a2dc5385 | After: this PR @ 8d8de778 | |---|---|---| | Light phase: window-median fps | 66.1-69.6 (medians of medians ~68) | 68.5-69.8 (~68) | | Light phase: p10 fps | 60.8-66.0 | 63.6-66.8 | | Switch defaults | n/a | on for everyone; `RX_VK_VIEW_FAST=0`, `RX_VK_NATIVE_NARROW=0`, `RX_VK_UNSWIZZLE_IMPORT=1` each restore the old behaviour | ``` [hos host] vk: N presents, 68.x fps; a frame: ~1090 draws ... (main, light phase, settled windows) [hos host] vk: N presents, 68.x fps; a frame: ~1090 draws ... (this PR, light phase, settled windows) ``` An earlier A/B of the same changes on the pre-rebase base (measured at b398975e against main @ d6cbc5d4) measured the same parity, including both of the field's spawn phases (heavy ~1400 draws: 40.2-40.8 both arms); its runs are `docs/tested/2026-11-22-restored-speedups-avidela-run01.md` and `-run02.md`, today's fresh current-main A/B is `-run03.md`. Current main itself measured ~35 % faster than the v3.0.0 release on this box in the same phase (68 vs 50 fps medians) — that gain is main's, not this PR's. ## Risks **Compatibility:** nothing a player notices — saves, `longshot_options.ini`, the shader and pipeline caches and the vk ABI are unchanged (the pipeline cache recompiles stamp-changed programs on first run, as any renderer change does). What could break, where, and how to turn it off: - A stale texture view answered from the front cache — `gpu/vk/vk_draw.cpp`'s `ViewFast`; the map stays the authority and every miss falls back to it. Off with `RX_VK_VIEW_FAST=0`; reverting is enough. - Direct 8/16-bit global stores on a driver that mishandles narrow views — `gpu/vk/eden`'s codegen, part of the program cache stamp. Off with `RX_VK_NATIVE_NARROW=0`; reverting is enough. - A one-upload unswizzle kept on the CPU raising CPU use on a slow machine — `gpu/vk/vk_memory.cpp`'s `memory_guest_contained`. Off with `RX_VK_UNSWIZZLE_IMPORT=1`; reverting is enough. - The staging tail suballocation handing a later upload a tail it believes untouched — `gpu/vk/vk_texture.cpp`'s arenas; no switch, so reverting the commit is the way back. All four were played through the Hyrule Field route above with no artifacts, no crashes and no device lost, with parity measurements on both arms. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named): run directly as `python -I -B tests/run_all.py` here; the failure set is identical to current main's, including main's own `test_switch_table` sorting break (`RX_VK_GRASS_DISTANCE` after `RX_VK_SIM_TURF_ADAPTIVE`, current main), and `test_flat_map.py` and `test_direct_buffer_writes.py` pass here where a naive port breaks them. - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def` (three rows; the development guide's table carries their descriptions too). - [x] A check under `tests/` that reads changed source is updated, not weakened (the FlatMap harness rewrites every TLS_OBJECT in its cut of `vk_draw.cpp` — its old rewrite dropped everything after `handle_hits`' line; the ViewFast stand-ins in the recording-fragment checks are carried). - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (The Windows Vulkan back end cross-compiles clean, `longshot_vk.dll` 0 failed — not run there, see Still to test; the Linux game build is the A/B's own binary.) - [x] Docs updated. (development.md's switch table gains the three rows; the runs are in `docs/tested/`, run01-run03.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers (the ported commits carry their original authors' trailers and sources; the repair, test and docs commits carry `Assisted-by: Claude`).
## Problem

When uploading textures in `staging()`, if the current recording's
timeline value (`rec_value`) has advanced past an existing 64 MB staging
arena's `a.value` while that arena is still in-flight on the GPU
(`a.value > completed_value`), `staging()` previously skipped the arena
entirely and allocated a brand-new 64 MB `VkBuffer` via VMA — even when
the in-flight arena had tens of megabytes of untouched tail space
remaining.

Because OoT submits ~6 times per frame, consecutive submissions that
each upload small textures (e.g. a few KB to a few MB) while prior
submissions are still in flight forced `staging()` to allocate 4–7
separate 64 MB staging arenas (256–448 MB of host-visible/BAR memory)
and stalled the replay thread in `vmaCreateBuffer`.

## Solution

Add a third pass in `staging()` before allocating a new buffer: if an
existing arena is in-flight (`a.value < rec_value`) and its aligned
unused tail (`at = (a.used + align - 1) & ~(align - 1)`) fits the
requested upload (`at + n <= a.size`), suballocate from `[at, at + n)`,
advance `a.used = at + n`, and update `a.value = rec_value` so the arena
is not recycled from offset 0 until all submissions reading any slice of
it have completed.

Because `align` is at least `nonCoherentAtomSize` (and $\ge 256$),
flushing `[at, at + n)` never overlaps cache atoms still being read by
earlier in-flight slices `[0, a.used_prev)`.

## Measurements & Verification

- **In-game A/B measurement (OoT, Linux x86_64, RTX 4050 Laptop GPU 6
GB, NVIDIA 615.78.08, 3,203 frames across Boot $\rightarrow$ Intro
$\rightarrow$ Hyrule Field $\rightarrow$ Market Town $\rightarrow$
Hyrule Castle)**:
  - **Before https://github.com/NotRexed/Hookshot/pull/2469 (`main`)**:
- Consecutive in-flight submissions uploading small textures allocated
**4 to 7 separate 64 MB staging arenas** (`vk: staging arenas: 1`
through `vk: staging arenas: 4`+), logging **7 slow arena creation
stalls** per session on the replay thread (`vk: a staging arena of 64 MB
took 145.1 ms to make`, `112.7 ms`, `12.1 ms`, `8.1 ms`, `6.1 ms`, `6.0
ms`, `5.6 ms`, `5.2 ms`).
  - **With https://github.com/NotRexed/Hookshot/pull/2469 (`3f9d56e2`)**:
- **Boot through Frame 1,420 (142 textures, 137 MB uploaded across
dozens of submissions)**: All uploads suballocated into the single
initial 64 MB arena (`vk: staging arenas: 1 (64 MB in this one)`). Zero
additional arenas were allocated, and the Frame 600 and Frame 1,200
memory reports both stayed at:
      ```
[hos Presentation Thread] vk: memory: working set 4812 MB (peak 4812),
private 914 MB, staging 64 MB in 1 arenas
[hos Presentation Thread] vk: memory: working set 6523 MB (peak 6523),
private 702 MB, staging 64 MB in 1 arenas
      ```
- **Full 3,203-frame route (Hyrule Field $\rightarrow$ Market Town
$\rightarrow$ Castle, >2,500 textures uploaded)**:
- Arena count **never reached 4** (peaked at 3 only during a single
frame that uploaded two 56.5 MB `1365x1365x90` ASTC arrays = 166.5 MB in
one frame, and trimmed back to `staging 64 MB in 1 arenas` at Frame
1,800 and Frame 3,000).
- Slow arena creation stalls (>5 ms) dropped from **7 per run** to **0
across the first 3,029 frames** (and **1 total** in 3,203 frames, when
two 56.5 MB `1365x1365x90` arrays were uploaded back-to-back at Frame
3,029).
- **Test suite**:
- `python3 -I -B tests/test_texture_staging_publication.py --headers
/usr/include` (including `inflight-tail` on `coherent` and
`noncoherent`: PASS)
- `python3 -I -B tests/test_texture_staging_publication.py --cxx clang++
--headers /usr/include --sanitize` (ASan + UBSan: PASS)
- `python3 -I -B tests/test_ui_texture_upload.py --headers /usr/include`
(PASS)
- `python3 -I -B tests/test_texture_squeeze.py --headers /usr/include`
(PASS)

Co-authored-by: erfboom <[email protected]>
Restored-from: https://github.com/NotRexed/Hookshot/pull/2469
(cherry picked from commit 43b799c7c0)
Two costs found by profiling a 4-core handheld (Steam Deck, RADV Van
Gogh, 15 W), both generic — no Deck-specific defaults, both behind an
env switch that keeps the old behaviour available.

Making a staging arena while ~2.5 GB of pools and textures are held took
**12–25 ms** — and an 8 MB one could take **116 ms**, so it is the
allocator, not the size. The arena the last burst used goes stale after
`RX_VK_STAGING_IDLE_S` (30 s) and is given back, so the first upload of
the next burst makes another. A camera turn brings new textures in, so
it paid for one every time: **28 slow creations in one session**, each a
stall of the replay thread.

Four are now made at replay start, on an empty device, where they are
cheap (`RX_VK_STAGING_PREWARM`, default 4; 0 restores the old
behaviour).

Measured over a 240 s run, same save and settings: **28 slow creations
before, 1 after.**

This is the same failure the comment above the idle free already
describes on other hardware ("a scene change made several right after
the idle ones were freed"), so it should help anywhere memory pressure
makes a 64 MB host-visible buffer expensive.

`texture_view_of` was **0.99 ms a frame** for ~10,600 lookups, each a
hash-map find, and the same slots come round again and again (14.9
descriptors a draw, 725 draws).

A 1024-entry direct-mapped cache now answers the repeats. It holds the
key, the slot's version, the destroy generation and the texture epoch,
and does the epoch's touch itself — so a slot re-registered or a texture
destroyed misses it at once and takes the map's path. **The map stays
the authority**; the cache only answers a lookup whose every input is
the one it was filled with. `RX_VK_VIEW_FAST=0` restores the old path.

Measured back to back, same session, same scene, 75 % internal
resolution:

| | fps | p50 | p99 | 1 % low |
|---|---|---|---|---|
| without | 24.8 | 40.32 ms | 42.37 ms | 23.6 |
| **with** | **24.9** | 40.16 ms | **41.32 ms** | **24.2** |

The average is within noise; the tail is a real millisecond.

- `RX_VK_PROF_FINE` now splits the texture path (storage-pointer test,
handle, view, fingerprint), and the frame statistics say which binding
moved `bind_gen` — counted: ubo 2159, tex 1794, ssbo 601, program 431,
img 84 a frame. That last one is worth knowing: the game genuinely
rebinds ~7 things per draw, which is why 0.9 of draws rebuild their
descriptor set and why the reuse check cannot be relaxed.
- `scripts/chain.py` no longer fails on a thread line without a name.

Based on current `main` (e0e60920); both commits cherry-picked cleanly.
I have not been able to build this branch locally (my build machine is
on the 127 commits behind base), so CI is the first build — say the word
if you would rather I build it first and reopen.

Co-authored-by: RufflezAU <[email protected]>

Ported to Longshot: the texture-view front cache and the statistics only. The staging prewarm (four 64 MB arenas made
in replay_start, RX_VK_STAGING_PREWARM) is left out: the arenas it made went through texture_frame's keep and idle
rules like any other, so on a card with 6.5 GB or less three of the four were freed at the first frame, and all of them
30 s after they were made. Keeping them needs an exemption of its own and a check; until then it cost 256 MB of
host-visible memory at start for little (review of #209).

Restored-from: https://github.com/NotRexed/Hookshot/pull/2960
(cherry picked from commit b3e807332b)
Turning the camera to the Deku Tree hitched for about 60 ms. Both causes
are in texture uploads, and this PR fixes both. It was split out of
https://github.com/NotRexed/Hookshot/pull/1834, as Joey-Magnus suggested, and builds on its own on main.

- **No pool import for one upload** (`vk_texture.cpp
upload_unswizzle_gpu`, `vk_memory.cpp memory_guest_contained`):
- **Before**: when no imported pool held the guest memory under a
texture, the GPU unswizzle imported it for that one upload. That took
22-25 ms on the replay thread each time, since the driver locks the
pages, and the Deku Tree turn did three in one frame.
- **Now**: the GPU path is taken only where an imported pool already
holds the whole range, and the rest goes to the CPU path.
- `RX_VK_UNSWIZZLE_IMPORT=1` imports as before (read with `env_on`, as
`test_env_on.py` wants).
- **The CPU unswizzle threaded from 4 MB** (`upload_inner`), not 16 MB.
The scene-size targets uploaded at that moment (2779 × 1318 RGBA8, 15
MB) took about 20 ms each on one thread; on several threads, a 15 MB
level takes a few ms.

- **Builds**: `vk_texture.cpp` and `vk_memory.cpp` compile with clang
using `nx2/build.py`'s renderer flags.
- **Tests**: `tests/run_all.py`, the whole suite, locally (clang
targeting MSVC, the CPM Vulkan headers): 433 passed. The failures are
exactly the ones main at 51da0464 has on this machine, all down to the
local toolchain.
- **In game**: the 60 ms hitch was measured on Windows 11 with an NVIDIA
RTX card (OoT v131072) and gone with both changes, as part of the
combined build. This head on its own hasn't had a separate run yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: FIocker <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Restored-from: https://github.com/NotRexed/Hookshot/pull/2785
(cherry picked from commit 4fda7ba943)
1. When `/dev/udmabuf` exists on the host system but persistently
rejects guest memory before any import has succeeded (e.g. kernel/driver
rejection with `EINVAL`, `EBADFD`, or `EPERM`, or when the driver
reports no valid memory type, or a non-`VK_ERROR_OUT_OF_DEVICE_MEMORY`
import failure), the Vulkan backend continues attempting udmabuf
creation on every buffer pool allocation instead of falling back to
host-pointer imports (`VK_EXT_external_memory_host`).
2. Pools that failed `create_device_buffer` in `mirror_make` under a
transient VRAM spike remained permanently marked as `MIRROR_REFUSED`
(`state 3`). Even after texture retirement or VMA compaction freed VRAM
and mirror budget headroom was available, those pools were never
retried, forcing the GPU to read them over PCIe for the rest of the
session.

- Add `disable_dmabuf_imports(const char* why)`: if udmabuf creation or
driver import is rejected before any successful import has occurred
(excluding transient `VK_ERROR_OUT_OF_DEVICE_MEMORY`), set `dmabuf_memfd
= -1` (leaving `dmabuf_dev` open so background import threads cannot
race on the fd) to fall back to host-pointer imports for subsequent
allocations.
- In `mirror_make`, if `create_device_buffer` fails (for a pool $\le$ 1
GB), set `p->mirror_retry_epoch = mirror_epoch + 120` rather than
refusing mirrors permanently.
- In `gpu_buffer_bind`, once `mirror_epoch >= p->mirror_retry_epoch`,
check if the pool fits within the mirror budget (`mirror_bytes + (p->hi
- p->lo) <= mirror_budget()`). If room exists, transition `p->mstate`
back to `MIRROR_NONE` so its mirror is requested at the next submission
boundary; otherwise, defer `mirror_retry_epoch` by another 120
submissions without evicting active mirrors or churning on low-VRAM
cards.
- Add `mirror_bytes` and `mirror_budget()` stubs to
`tests/direct_buffer_writes_test.cpp`.

- **A/B in-game verification (OoT, Linux x86_64, RTX 4050 Laptop GPU 6
GB, NVIDIA 615.78.08, 2048x1152, `RX_VK_VRAM_MB=2240`,
`RX_VK_MIRROR_MB=2048`)** — identical route: Hyrule Field $\rightarrow$
Market Town $\rightarrow$ Hyrule Castle (~2,680 frames):
- **Without https://github.com/NotRexed/Hookshot/pull/2482 (`main` at `20d50332`)**: Upon entering Castle during
a VRAM spike (`image over budget`), two pools (`0x7ee5400000` 172 MB and
`0x7fb2c00000` 40 MB) entered `state 3` (`MIRROR_REFUSED`). Even after
`VRAM compaction 1 over: ... 35 blocks (560 MB) given back to the
driver` and mirror usage dropped to 1,652 MB / 2,048 MB, both pools
remained stuck in `state 3` for all 7 remaining 600-submit summaries,
reading **4,850.1 MB total over PCIe** (474.4–1,219.8 MB per 600
submits, e.g. `vk: bound in guest memory, by pool ... 1219.8 MB in all
... 0x7ee5400000 (172 MB, state 3): 6657 binds, 1211 MB; 0x7fb2c00000
(40 MB, state 3): 170 binds, 9 MB;`).
- **With https://github.com/NotRexed/Hookshot/pull/2482 (`46497054`)**: On the same Castle entry spike, two pools
(`0x7eec000000` 56 MB and `0x7fb3400000` 24 MB) entered `state 3` for
**only 1 summary** (`270.1 MB in all: 0x7eec000000 (56 MB, state 3): 611
binds, 269 MB; 0x7fb3400000 (24 MB, state 3): 14 binds, 1 MB;`). Once
textures retired and budget room opened 120 submissions later, both
pools exited `state 3` and got their VRAM mirrors back (`vk: a frame:
mirrors 312 (1800 MB)`). Across the next 5 consecutive 600-submit
summaries (3,000 submissions through Castle), **0 pools were in `state
3` and 0 MB was read over PCIe**.
- Also verified by @felipefl142 across a 2.5 h full-game completion run
on RTX 3070 Laptop 8 GB (CachyOS) and @YakuzaFanA on RTX 5060 Ti 8 GB
(Windows 11).
- **Test suite**: `python3 -I -B tests/test_direct_buffer_writes.py`
(12/12 pass) and `tests/run_all.py`.

---------

Co-authored-by: erfboom <[email protected]>
Restored-from: https://github.com/NotRexed/Hookshot/pull/2482
(cherry picked from commit ea6dc5f5d6)
https://github.com/NotRexed/Hookshot/pull/2960 clears view_fast() with handle_hits()
in draw_begin_recording, and three checks that cut that function had no ViewFast,
which broke only their builds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f9f3eeda72)
test: the FlatMap harness rewrites view_fast's TLS_OBJECT too
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 19s
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
42efd4842c
ViewFast's TLS object now sits inside the harness's cut of vk_draw.cpp; the
rewrite of handle_hits' line alone dropped the block. Both TLS objects become
inline functions, the ViewFast struct travels with them, and <array> joins the
stubs.

Assisted-by: Claude <[email protected]>
Author
First-time contributor

Tested in game: Fedora 45, RX 5700 XT (RADV NAVI10, Mesa 26.2.6), Ryzen 5 3600/15 GB: the branch's build played the same Hyrule Field run+spin route as main (3 sessions + a 10-minute soak, repo save, fps unlocked); parity in both spawn phases, FSR 3.1 and the game's upscaler exercised, no artifacts or crashes.

Tested in game: Fedora 45, RX 5700 XT (RADV NAVI10, Mesa 26.2.6), Ryzen 5 3600/15 GB: the branch's build played the same Hyrule Field run+spin route as main (3 sessions + a 10-minute soak, repo save, fps unlocked); parity in both spawn phases, FSR 3.1 and the game's upscaler exercised, no artifacts or crashes.
Member

Possibly related, for context:

  • PR #925 fix(vk): keep sparse textures off the GPU unswizzle and disturb descriptors at its bind — Overlaps GPU unswizzle behavior and texture-upload path
  • PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Overlaps texture staging/writeback implementation in vk_texture.cpp
Possibly related, for context: - PR #925 fix(vk): keep sparse textures off the GPU unswizzle and disturb descriptors at its bind — Overlaps GPU unswizzle behavior and texture-upload path - PR #282 WIP: perf(vk): re-upload only the part of a texture a GPU write covered — Overlaps texture staging/writeback implementation in vk_texture.cpp
Hi, a small translator change that came out of chasing slow compute
passes on my Quadro P4000.

**The problem**
`WriteGlobalU8/S8/U16/S16` go through `write_global_cas_loop_func`: a
compare-exchange loop with `OpBitFieldInsert` on the 32-bit word around
the byte. When many invocations write bytes of the same word, most
attempts fail and retry. Also, on the page-table path the loop was
handed the exact byte address as if it were the word's address.

**The change**
- Where the storage buffers have 8/16-bit views, the byte or half is
stored directly at its address (through the bound buffer, or through the
page table). Neighbouring bytes aren't touched, so no loop is needed.
- A half at an odd address is stored as two bytes (it can straddle a
word and a page).
- The loop fallback now looks up the aligned word.
- `StorageBuffer8BitAccess` / `StorageBuffer16BitAccess` (and their
extensions) are declared where the u8/u16 views are made. They were used
without being declared.
- `RX_VK_NATIVE_NARROW=0` keeps the old loop. It's an `RX_VK_NATIVE*`
switch so the program cache follows it.
- I left the float atomic add code alone, main already has its own.

**Tested**
- Builds on current main: `RX_VK_ONLY=1 nx2/build.py --standalone`,
llvm-mingw, "compiled in 88s, 0 failed". (The first run died once with
"Compiler exited with status 1 without diagnostics" on two unrelated
files and passed on a plain rerun, so I think that was my machine.)
- An offline emit check: small IR programs with 8/16/32-bit global
stores and float adds, with 0, 1 and 2 storage buffers, through the real
`CollectShaderInfoPass` + `EmitSPIRV`, then every id operand checked
against `spirv.core.grammar.json`. 18 modules, no undefined or zero ids,
with the change and on plain main.
- `tests/test_cas_loop_ceiling.py`, `test_global_atomic_add_f32`,
`test_global_table_loop`, `test_lower_atomg_cas` pass.
`tests/global_load_16_ir.cpp` built and run by hand: all pass.
- An earlier version of this (on v2.0.5 and v2.0.14) is what I've been
playing with on the P4000 (NVIDIA 582.16, Windows 11).

**Not tested / things to know**
- This exact commit on main has not been run in the game or on a driver,
and I didn't run `spirv-val` on it.
- `tests/global_load_16` uses a default `Profile`, so it still takes the
loop path and never exercises the direct store. Its README still says
narrow stores use the loop. I can add a case for the direct path if you
want it in this PR.
- AMD and Intel: untested. It only takes the direct path when the device
reports 8/16-bit storage.
- I'm not sure the odd-address half split ever matters in practice (the
console's stores are naturally aligned), it's there to be safe.

Sorry if this overlaps with something already in progress, I looked and
didn't find it. Thank you for your time!

Restored-from: https://github.com/NotRexed/Hookshot/pull/2976
(cherry picked from commit 2fb964eaad)
RX_VK_ASTC_BC1, RX_VK_GAME_ORDER, RX_VK_VIEW_FAST, RX_VK_NATIVE_NARROW,
RX_VK_IMPORT_FENCE, RX_VK_UNSWIZZLE_IMPORT and HOS_CV_SIGNAL_ALWAYS were not in the
switch reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 9fe72e1941)
docs: the restored-speedups RADV A/B rows (avidela-run01, avidela-run02)
Some checks failed
PR description / Description follows the template (pull_request_target) Failing after 8s
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
9c76f35f00
Assisted-by: Claude <[email protected]>
avidela changed title from WIP: perf(vk): the restored speed-ups not yet in main, refreshed on current main to perf(vk): the restored speed-ups not yet in main, refreshed on current main 2026-11-21 20:50:57 +00:00
avidela force-pushed perf/radv-cohort from 9c76f35f00
Some checks failed
PR description / Description follows the template (pull_request_target) Failing after 8s
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 201a650fca
Some checks failed
PR description / Description follows the template (pull_request_target) Failing after 5s
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
CI / Website build and checks (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-22 03:09:13 +00:00
Compare
Assisted-by: Claude <[email protected]>
docs: the current-main A/B row (avidela-run03)
Some checks are pending
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
610dc3ad71
Assisted-by: Claude <[email protected]>
Some checks are pending
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 4s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/radv-cohort:avidela-perf/radv-cohort'
git switch 'avidela-perf/radv-cohort'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!2096
No description provided.