records: descriptor lookups skip the key hash and the table row (VICTORY_RECORD_PLACES, VICTORY_RECORD_RANGES) #329

Manually merged
github merged 4 commits from github-bot/gh-329 into main 2026-12-03 17:11:28 +00:00 AGit
Owner

@⁠t-jonesy on GitHub · 2026-12-03 15:36 UTC · original
t-jonesy:upstream/records-places-ranges → main · +770 −37 · 9 files · 4 commits · merged 2026-12-03 17:11 UTC

Problem

RGP thread traces of the hot translated shaders (decoded with AMD's rocprof-trace-decoder) put waits at 47% and scalar ALU at 30% of instruction cycles. Slicing the hottest shaders' disassembly, 51–86% of their scalar ALU (37% frame-wide) is the per-wave resolution of descriptor records in the title's heap, and the s_wait_kmcnt stalls wait on its chains of dependent scalar loads:

  • Texture (record_slot): record load, key hash (~18 instructions, 6 multiplies), two cuckoo probes, compare. About 34 SALU and 3 SMEM in 2 dependent steps.
  • Raw / constant buffer (record_range + address_view): record load, table-row load, ~41–45 instructions of decode, chunk descriptor load. 3 dependent SMEM.

Changes (two switches, both off by default)

  1. VICTORY_RECORD_PLACES=1: the host writes the record's two cuckoo place offsets into words 4–5 of each 32-byte view record. They depend only on the key, so whole-record copies stay valid. Textures read them instead of hashing. =2 also covers typed buffers. That is riskier, because a 16-byte partial copy of a buffer record would leave stale places.
  2. VICTORY_RECORD_RANGES=1:
    • Constant-buffer views decode their range straight from record words 1–2. Their table row was always the zero row, so this is exact and needs no host change.
    • Other buffer views read a host-written range in words 4–7 (start, length, word 1, word 2 ^ mark). They use it only if it carries the record's own key and a valid tag; otherwise the view reads empty.
    • Either way there is no table-row load, and the dependent load depth drops by 1.
  3. Rebase fix-up: the places load is marked pure like the other records loads (#166).

With the switches on, the shader cache key changes, so shaders need translating and warming again (./run.sh shaders, then a warm). With both off, translations and the cache key are unchanged. The only host-side difference is that view records also get the two place offsets written into words 4–5 (8 bytes per view made; nothing reads them when off). Both switches are listed in docs/SETTINGS.md.

examples/isa_probe.rs (victory-shader, --features host) translates shader containers and builds a host pipeline of each, so RADV's RADV_DEBUG=asm dumps show the resulting ISA. The table below was made with it.

Results

Host ISA (RADV, GFX1201): scalar ALU in the hottest shaders, default vs PLACES=1 + RANGES=1.

shader SALU dependent SMEM depth
compute fd46520032208bed 636 → 538 5 → 4
pixel e06396004d18c51b 631 → 487 5 → 4
mesh 797816f4d7b5d9b7 415 → 380 8 → 7
mesh b1a6d299fd26d0e6 786 → 704 9 → 8

In game, alternating A/B runs of 60 s each:

off PLACES=1 PLACES=1 + RANGES=1
fps 25.3 / 25.6 25.8 / 25.9 (~+2%) 27.0 / 27.9 / 26.7 → 27.2 (+6.3%)
min fps ~25.0 ~25.0 26.3
GPU wait ~16.6 ms ~14.6 ms

There were 0 errors, and screenshots showed textures, skin and prints intact. Both switches have since stayed on in longer hands-on play with no visual problems seen.

All of these numbers come from one machine:

  • Ryzen 9 7950X3D, RX 9070 XT (RDNA4)
  • RADV / Mesa 26.3.1 with this project's patches, Linux 7.3
  • 4K with FSR 4 performance, RT on
  • a steady camera, alternating A/B runs

They were measured on a fork whose base is about 150 commits behind current main; this branch is the same change rebased. Untested on other GPUs (RDNA2/3 in particular), and not re-measured in game after the rebase.

Risk

Under RANGES, a partial copy of a raw buffer record (the first 16 bytes only) would read as an empty view rather than a wrong one. No such copy turned up in the host code, but a title doing a 16-byte memcpy of a raw-buffer record would hit it.

Testing

  • ./build.sh (release) builds.
  • victory-shader unit tests (Windows target under Wine, RADV): 408 passed, 0 failed, 4 ignored. That includes the 7 new tests for places and ranges.
  • victory-gpu unit tests: the new descriptor::tests::buffer_records_carry_their_range_when_asked passes. The full suite has 309 passed and 6 failed; the same 6 tests (indirect::tests::host_list_* and watch::*) fail on unmodified main in the same environment.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya

**@⁠t-jonesy** on GitHub · 2026-12-03 15:36 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/329) `t-jonesy:upstream/records-places-ranges` → `main` · +770 −37 · 9 files · 4 commits · merged 2026-12-03 17:11 UTC ## Problem RGP thread traces of the hot translated shaders (decoded with AMD's rocprof-trace-decoder) put waits at 47% and scalar ALU at 30% of instruction cycles. Slicing the hottest shaders' disassembly, 51–86% of their scalar ALU (37% frame-wide) is the per-wave resolution of descriptor records in the title's heap, and the `s_wait_kmcnt` stalls wait on its chains of dependent scalar loads: - Texture (`record_slot`): record load, key hash (~18 instructions, 6 multiplies), two cuckoo probes, compare. About 34 SALU and 3 SMEM in 2 dependent steps. - Raw / constant buffer (`record_range` + `address_view`): record load, table-row load, ~41–45 instructions of decode, chunk descriptor load. 3 dependent SMEM. ## Changes (two switches, both off by default) 1. **`VICTORY_RECORD_PLACES=1`**: the host writes the record's two cuckoo place offsets into words 4–5 of each 32-byte view record. They depend only on the key, so whole-record copies stay valid. Textures read them instead of hashing. `=2` also covers typed buffers. That is riskier, because a 16-byte partial copy of a buffer record would leave stale places. 2. **`VICTORY_RECORD_RANGES=1`**: - Constant-buffer views decode their range straight from record words 1–2. Their table row was always the zero row, so this is exact and needs no host change. - Other buffer views read a host-written range in words 4–7 (start, length, word 1, word 2 ^ mark). They use it only if it carries the record's own key and a valid tag; otherwise the view reads empty. - Either way there is no table-row load, and the dependent load depth drops by 1. 3. Rebase fix-up: the places load is marked pure like the other records loads (#166). With the switches on, the shader cache key changes, so shaders need translating and warming again (`./run.sh shaders`, then a warm). With both off, translations and the cache key are unchanged. The only host-side difference is that view records also get the two place offsets written into words 4–5 (8 bytes per view made; nothing reads them when off). Both switches are listed in `docs/SETTINGS.md`. `examples/isa_probe.rs` (victory-shader, `--features host`) translates shader containers and builds a host pipeline of each, so RADV's `RADV_DEBUG=asm` dumps show the resulting ISA. The table below was made with it. ## Results Host ISA (RADV, GFX1201): scalar ALU in the hottest shaders, default vs `PLACES=1` + `RANGES=1`. | shader | SALU | dependent SMEM depth | |---|---|---| | compute fd46520032208bed | 636 → 538 | 5 → 4 | | pixel e06396004d18c51b | 631 → 487 | 5 → 4 | | mesh 797816f4d7b5d9b7 | 415 → 380 | 8 → 7 | | mesh b1a6d299fd26d0e6 | 786 → 704 | 9 → 8 | In game, alternating A/B runs of 60 s each: | | off | `PLACES=1` | `PLACES=1` + `RANGES=1` | |---|---|---|---| | fps | 25.3 / 25.6 | 25.8 / 25.9 (~+2%) | 27.0 / 27.9 / 26.7 → **27.2 (+6.3%)** | | min fps | ~25.0 | ~25.0 | **26.3** | | GPU wait | ~16.6 ms | | ~14.6 ms | There were 0 errors, and screenshots showed textures, skin and prints intact. Both switches have since stayed on in longer hands-on play with no visual problems seen. All of these numbers come from **one machine**: - Ryzen 9 7950X3D, RX 9070 XT (RDNA4) - RADV / Mesa 26.3.1 with this project's patches, Linux 7.3 - 4K with FSR 4 performance, RT on - a steady camera, alternating A/B runs They were measured on a fork whose base is about 150 commits behind current `main`; this branch is the same change rebased. **Untested on other GPUs** (RDNA2/3 in particular), and not re-measured in game after the rebase. ## Risk Under `RANGES`, a partial copy of a raw buffer record (the first 16 bytes only) would read as an empty view rather than a wrong one. No such copy turned up in the host code, but a title doing a 16-byte memcpy of a raw-buffer record would hit it. ## Testing - `./build.sh` (release) builds. - victory-shader unit tests (Windows target under Wine, RADV): 408 passed, 0 failed, 4 ignored. That includes the 7 new tests for places and ranges. - victory-gpu unit tests: the new `descriptor::tests::buffer_records_carry_their_range_when_asked` passes. The full suite has 309 passed and 6 failed; the same 6 tests (`indirect::tests::host_list_*` and `watch::*`) fail on unmodified `main` in the same environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
Every texture a translated program reads through its record in the title's
heap cost, every wave, a 16-instruction scalar hash of the record's key
(six multiplies) to find the two places of the table of the views' slots
to probe. The places are a function of the key alone, so the host now
writes them into words 4 and 5 of each view record it makes (beside the
tag, key and slot hint in words 0 to 3); copies of the record keep them.

With VICTORY_RECORD_PLACES=1 shaders read the places from the record for
textures (descriptors of eight dwords, always copied whole); =2 also for
typed buffers and any other view found by its slot. Off by default: the
host writes the words either way, shaders hash as before, and the shader
cache key is unchanged unless the switch is on.

Measured on the host compiler (RADV, GFX1201) with the new isa_probe
example on translations of shaders hot in RGP captures:
compute fd46520032208bed 636 -> 572 SALU, pixel e06396004d18c51b
631 -> 550, mesh 797816f4d7b5d9b7 415 -> 401 and b1a6d299fd26d0e6
786 -> 772 (=2); one more SMEM load per texture, issued with the record's,
so no added dependent load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
A buffer a translated program reads as raw bytes through its record in the
title's heap (constant buffers among them) cost, every wave, three dependent
scalar loads before its data: the record, the row of the host's table of
ranges the record's kind picks, then the descriptor of the chunk of title
memory the range lies in; and some 40 scalar instructions between them.

With VICTORY_RECORD_RANGES=1 the table is left alone:
- a constant buffer view's record names it whole (address and size code),
  so the program decodes it from the record's own words;
- for any other buffer view (placed, by resource, ray-tracing structure)
  the host writes into words 4 to 7 of the record the range the table
  would give (start low 32 bits, length) and the key (word 1, word 2 xor a
  mark), and bits 32-39 of the start into word 3 bits 20-27 (free beside
  the slot hint and flags). A function of the key and its view, so whole
  copies of the record stay right. The program reads words 4-7 with the
  record (one x8 load) and takes them only if they hold its own key: a
  record whose second half belongs to another (a copy of its first 16
  bytes alone) reads as an empty view instead of the wrong one.
Branch-free, so it also holds in the entry block where hoisted descriptors
are resolved. Typed buffers then hash their places at any
VICTORY_RECORD_PLACES level (their record carries the range where the
places were). Off by default: the host writes the records as before and
the shader cache key is unchanged unless the switch is on.

Measured on the host compiler (RADV, GFX1201) with isa_probe, SALU and the
depth of the scalar load chain before the data (places=1 / +ranges):
compute fd46520032208bed 572 -> 538, depth 5 -> 4;
pixel e06396004d18c51b 550 -> 487, 5 -> 4;
mesh 797816f4d7b5d9b7 415 -> 380, 8 -> 7;
mesh b1a6d299fd26d0e6 786 -> 704, 9 -> 8 (=2: 401/772 -> 380/704).
SMEM 3-8 fewer per shader (the table's rows).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
On main the records loads are marked pure for CSE (#166); the load of the
places (VICTORY_RECORD_PLACES) reads the same records, so it is marked the
same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ETU6PfySRvsjk18uHFtWya
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 15:37:30 +00:00
github manually merged commit f1b024fa51 into main 2026-12-03 17:11:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.