WIP: perf(vk): cache Task/Mesh c2/c0 banks by stage gen and pointer_table per stage #2339

Draft
GrimVisage wants to merge 1 commit from GrimVisage/Longshot:perf/task-mesh-bank-cache into main
Contributor

Summary

Task and mesh stages (NVN2 stages 6 & 7) currently bypass tex_gen/ssbo_gen bank caching in uniform_range() and fall back to s.bind_gen, causing their c2 and c0 driver banks to refill whenever any uniform buffer is bound (nearly every draw). In addition, pointer_table() keeps a single thread_local slot across stages, so Task (stage 6) and Mesh (stage 7) evict each other on every draw.

This WIP PR:

  1. Keys Task/Mesh c2 on s.tex_gen[bank_stage] (safe: driver_bank_fill for bank == 2 only reads s.tex, s.img, s.samp) and Task/Mesh c0 when n <= 0x880 on s.ssbo_gen[bank_stage] (safe: only reads s.ssbo). Task/Mesh c0 past 0x880 (which includes pointer_table) and compute c0 (stage 5) stay on s.bind_gen.
  2. Makes pointer_table()'s thread_local cache per-stage (PointerCache cache[kNvnStages]) keyed on (s.bind_gen, memory_capture_view(), &s), stopping Task/Mesh stage eviction while invalidating whenever submitted memory captures change.
  3. Updates tests/test_bank_gen.py to enforce both invariants.

Files to read first:

  • gpu/vk/vk_draw.cpp (uniform_range)
  • gpu/vk/vk_bank.cpp (pointer_table)
  • tests/test_bank_gen.py

See #1285.

Testing

Tested:

  • Compiled longshot_vk.so cleanly on Fedora 45 Linux (scripts/dev.py vk).
  • python3 -I -B tests/test_bank_gen.py: PASS.
  • pre-commit (including ruff) on all 3 changed files: PASS.

Still to test:

  • Dedicated paired A/B benchmark (main vs this PR alone) on Linux AMD RX 9070 XT with RX_VK_MESH_FALLBACK=0 (castle-gate and kokiri-forest) to measure isolated FPS/CPU impact before marking ready (by hand).
  • Tier 1 Windows/Linux native mesh smoke test (@Beanstalk build and run native mesh smoke test).

Measurements

WIP: dedicated main-vs-PR paired A/B benchmark pending before marking ready for review.

Risks

  • Low risk: c2 and c0 (n <= 0x880) only depend on s.tex/s.img/s.samp and s.ssbo respectively (enforced by tests/test_bank_gen.py); c0 past 0x880 keeps s.bind_gen invalidation, and pointer_table() adds memory_capture_view() to its cache key.
  • A revert restores main's behavior cleanly.

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).
  • 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 check under tests/ that reads changed source is updated, not weakened.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

Assisted-by: Antigravity
Co-Authored-By: Antigravity [email protected]

## Summary Task and mesh stages (NVN2 stages 6 & 7) currently bypass `tex_gen`/`ssbo_gen` bank caching in `uniform_range()` and fall back to `s.bind_gen`, causing their `c2` and `c0` driver banks to refill whenever any uniform buffer is bound (nearly every draw). In addition, `pointer_table()` keeps a single `thread_local` slot across stages, so Task (stage 6) and Mesh (stage 7) evict each other on every draw. This WIP PR: 1. Keys Task/Mesh `c2` on `s.tex_gen[bank_stage]` (safe: `driver_bank_fill` for `bank == 2` only reads `s.tex`, `s.img`, `s.samp`) and Task/Mesh `c0` when `n <= 0x880` on `s.ssbo_gen[bank_stage]` (safe: only reads `s.ssbo`). Task/Mesh `c0` past `0x880` (which includes `pointer_table`) and compute `c0` (stage 5) stay on `s.bind_gen`. 2. Makes `pointer_table()`'s `thread_local` cache per-stage (`PointerCache cache[kNvnStages]`) keyed on `(s.bind_gen, memory_capture_view(), &s)`, stopping Task/Mesh stage eviction while invalidating whenever submitted memory captures change. 3. Updates `tests/test_bank_gen.py` to enforce both invariants. **Files to read first:** - `gpu/vk/vk_draw.cpp` (`uniform_range`) - `gpu/vk/vk_bank.cpp` (`pointer_table`) - `tests/test_bank_gen.py` See #1285. ## Testing **Tested:** - Compiled `longshot_vk.so` cleanly on Fedora 45 Linux (`scripts/dev.py vk`). - `python3 -I -B tests/test_bank_gen.py`: PASS. - `pre-commit` (including `ruff`) on all 3 changed files: PASS. **Still to test:** - Dedicated paired A/B benchmark (`main` vs this PR alone) on Linux AMD RX 9070 XT with `RX_VK_MESH_FALLBACK=0` (`castle-gate` and `kokiri-forest`) to measure isolated FPS/CPU impact before marking ready (by hand). - Tier 1 Windows/Linux native mesh smoke test (`@Beanstalk build and run native mesh smoke test`). ## Measurements WIP: dedicated `main`-vs-PR paired A/B benchmark pending before marking ready for review. ## Risks - Low risk: `c2` and `c0` (`n <= 0x880`) only depend on `s.tex`/`s.img`/`s.samp` and `s.ssbo` respectively (enforced by `tests/test_bank_gen.py`); `c0` past `0x880` keeps `s.bind_gen` invalidation, and `pointer_table()` adds `memory_capture_view()` to its cache key. - A revert restores `main`'s behavior cleanly. ## Checklist ### Ready for review - [x] 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). - [ ] 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 check under `tests/` that reads changed source is updated, not weakened. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. Assisted-by: Antigravity Co-Authored-By: Antigravity <[email protected]>
perf(vk): cache Task/Mesh c2/c0 banks by stage gen and pointer_table per stage
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 / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
752645b79f
Key Task/Mesh (NVN2 stages 6 and 7) c2 driver banks on s.tex_gen[stage]
and c0 banks (when n <= 0x880) on s.ssbo_gen[stage], keeping compute c0
(stage 5) and Task/Mesh c0 past 0x880 (pointer_table) on s.bind_gen.
Cache pointer_table() per stage keyed on (s.bind_gen, memory_capture_view(),
&s) so Task and Mesh stages do not evict each other within the same draw.
Update tests/test_bank_gen.py to enforce both invariants.

Assisted-by: Antigravity
Co-Authored-By: Antigravity <[email protected]>
Author
Contributor

Tested in game: WIP: compiled longshot_vk.so cleanly on Fedora 45 Linux (RX 9070 XT, RADV Mesa 26.3.1) and passed test_bank_gen.py + test_tls_objects.py; dedicated solo main-vs-PR in-game A/B pending before marking ready.

Tested in game: WIP: compiled longshot_vk.so cleanly on Fedora 45 Linux (RX 9070 XT, RADV Mesa 26.3.1) and passed test_bank_gen.py + test_tls_objects.py; dedicated solo main-vs-PR in-game A/B pending before marking ready.
Member

Possibly related, for context:

  • PR #2291 WIP: perf(shaders): native task and mesh stages read global memory through the guest page table — Open native Task/Mesh stage work; overlapping renderer code and stage behavior
  • PR #794 WIP: perf(vk): a stage's descriptors are kept across draws in a recording part while what they were resolved from stands — Earlier descriptor-retention caching in Vulkan draw path; similar cache invalidation concern
  • PR #2103 perf(shaders): global loads through the guest page table, a cold shader preparation 3.5x faster — Merged page-table work includes Task/Mesh fallback stage behavior; relevant cache context
Possibly related, for context: - PR #2291 WIP: perf(shaders): native task and mesh stages read global memory through the guest page table — Open native Task/Mesh stage work; overlapping renderer code and stage behavior - PR #794 WIP: perf(vk): a stage's descriptors are kept across draws in a recording part while what they were resolved from stands — Earlier descriptor-retention caching in Vulkan draw path; similar cache invalidation concern - PR #2103 perf(shaders): global loads through the guest page table, a cold shader preparation 3.5x faster — Merged page-table work includes Task/Mesh fallback stage behavior; relevant cache context
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 / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
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/task-mesh-bank-cache:GrimVisage-perf/task-mesh-bank-cache'
git switch 'GrimVisage-perf/task-mesh-bank-cache'
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!2339
No description provided.