perf(shader): bound image table keys from findLSB, induction and unsigned clamps #17863

Merged
edubox merged 4 commits from upstream-pr/17863 into main 2026-11-14 04:20:36 +00:00
edubox commented 2026-11-09 18:42:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-09T18:42:26Z.


What

Bound image-table key enumeration when the key expression is a findLSB/findMSB of a 32-bit mask, a bounded induction value, or an unsigned clamp.

FindILsb32 and FindUMsb32 can only produce 0..31 for a valid table key; their no-bit sentinel (0xffffffff) is outside every table domain, so capping those keys at 31 keeps the same outside-snapshot behavior while avoiding the 65536-key fallback. IAdd32/Phi upper bounds and ReadFirstLane unwrapping let MatchKeyDomain discover scalar key domains in the same expressions.

UMin32 and UMax32 bound the key through an unsigned clamp: UMin32(x, n) can only return at most n, so the enumeration stops at n + 1 keys even when the rest of the expression is an unbounded product or induction. This is what bounds Planet Zoo's tables, whose key is min(i * 0xb0, 0x5fff): the key goes from the 65536-key fallback to 24576 keys.

This is generic: any shader whose image-table index is a bitmask LSB, a bounded induction value or an unsigned clamp benefits, not only one title.

Tested

  • Linux 7.3.1-1-cachyos, NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08.
  • agc_shader_memory_tests: passed, including a new v_min_u32 clamp case that enumerates exactly 65 of 128 records.
  • agc_driver_image_table_tests: passed.
  • agc_driver_image_table_reuse_tests: passed.
  • tools/check_conventions.py --base origin/main: passed.
  • tools/pr_overlap.py --branch perf/image-table-key-bounds --jobs 32: no overlap with open pull requests.
  • God of War image-table profile: many tables went from 65536 keys to 32 keys; in the loaded phase the observed image-table CPU time dropped from about 6.9 s to about 1.2 s per 10 s on the development run. This was not a formal main-vs-PR A/B on the same save.
  • Planet Zoo PPSA18026 (Cobra engine): image-table keys went from the 65536-key fallback to 24576 keys and the [capture] plan-lookup-plus-materialize stage dropped from about 8-11 s to about 0.7-1.2 s per 10 s window; table snapshots began to be reused (hundreds per window). Warm-run steady presents rose from about 88 to about 110-200 per 10 s in the later phase. Development run, not a formal same-save A/B.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08, Linux 7.3.1-1-cachyos
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5229207913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17863). Originally posted by [edubox](https://github.com/edubox) on 2026-11-09T18:42:26Z. --- ### What Bound image-table key enumeration when the key expression is a `findLSB`/`findMSB` of a 32-bit mask, a bounded induction value, or an unsigned clamp. `FindILsb32` and `FindUMsb32` can only produce `0..31` for a valid table key; their no-bit sentinel (`0xffffffff`) is outside every table domain, so capping those keys at 31 keeps the same outside-snapshot behavior while avoiding the 65536-key fallback. `IAdd32`/`Phi` upper bounds and `ReadFirstLane` unwrapping let `MatchKeyDomain` discover scalar key domains in the same expressions. `UMin32` and `UMax32` bound the key through an unsigned clamp: `UMin32(x, n)` can only return at most `n`, so the enumeration stops at `n + 1` keys even when the rest of the expression is an unbounded product or induction. This is what bounds Planet Zoo's tables, whose key is `min(i * 0xb0, 0x5fff)`: the key goes from the 65536-key fallback to 24576 keys. This is generic: any shader whose image-table index is a bitmask LSB, a bounded induction value or an unsigned clamp benefits, not only one title. ### Tested - Linux 7.3.1-1-cachyos, NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08. - `agc_shader_memory_tests`: passed, including a new `v_min_u32` clamp case that enumerates exactly 65 of 128 records. - `agc_driver_image_table_tests`: passed. - `agc_driver_image_table_reuse_tests`: passed. - `tools/check_conventions.py --base origin/main`: passed. - `tools/pr_overlap.py --branch perf/image-table-key-bounds --jobs 32`: no overlap with open pull requests. - God of War image-table profile: many tables went from 65536 keys to 32 keys; in the loaded phase the observed image-table CPU time dropped from about 6.9 s to about 1.2 s per 10 s on the development run. This was not a formal main-vs-PR A/B on the same save. - Planet Zoo PPSA18026 (Cobra engine): image-table keys went from the 65536-key fallback to 24576 keys and the `[capture]` plan-lookup-plus-materialize stage dropped from about 8-11 s to about 0.7-1.2 s per 10 s window; table snapshots began to be reused (hundreds per window). Warm-run steady presents rose from about 88 to about 110-200 per 10 s in the later phase. Development run, not a formal same-save A/B. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 615.78.08, Linux 7.3.1-1-cachyos - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!17863
No description provided.