perf(gpu): split UAVs out of State::scan cache and reuse descriptor::view_of #510

Manually merged
github merged 1 commit from github-bot/gh-510 into main 2026-12-05 17:30:16 +00:00 AGit
Owner

@⁠Not4Eric on GitHub · 2026-12-04 20:24 UTC · original
Not4Eric:perf/draw-split-uav-scan-cache → main · +64 −33 · 1 files · 1 commits · merged 2026-12-05 17:28 UTC

What this does

Precomputes each TableGroup's UAV descriptor indices in TablePlan, allowing draw::State::scan to cache descriptor tables that contain UAVs (when picked.is_empty() and list.epoch() did not advance during the scan) and re-scan only the UAV slots on subsequent cache hits instead of re-scanning the entire descriptor table. Also replaces redundant descriptor::view(at) lookups with descriptor::view_of(words[1], words[2]) using the already-read record words and reuses the looked-up View instead of querying VIEWS twice.

Checks

  • N/A: pure performance optimization preserving identical UAV barrier/readability tracking and descriptor-table scan output.
  • N/A: no switches added, changed, or removed.
  • No unrelated cleanup: diff is limited to TableGroup/TablePlan and State::scan in crates/victory-gpu/src/draw.rs.
  • N/A: existing draw:: unit tests pass; no prior behavioural bug existed for a failing-before unit test.
  • Checked open PR queue: independent of #445 and of perf/records-skip-touch-batch-stats.
  • cargo xtask policy passed (359 files ok); no fork-only files, configs, or build outputs.

Verified

  • cargo xtask policy — 359 files ok
  • PKG=victory-gpu ./build.sh test --lib -- draw:: --test-threads=1 (Proton Wine on Linux, RX 9070 XT) — 7 passed; 0 failed; 1 ignored, 0 warnings
  • Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton); not benchmarked in isolation.

Cost

One small Vec<u32> (uavs) per TableGroup in TablePlan; 0 new warnings.

AI-assisted: yes

**@⁠Not4Eric** on GitHub · 2026-12-04 20:24 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/510) `Not4Eric:perf/draw-split-uav-scan-cache` → `main` · +64 −33 · 1 files · 1 commits · merged 2026-12-05 17:28 UTC ## What this does Precomputes each `TableGroup`'s UAV descriptor indices in `TablePlan`, allowing `draw::State::scan` to cache descriptor tables that contain UAVs (when `picked.is_empty()` and `list.epoch()` did not advance during the scan) and re-scan only the UAV slots on subsequent cache hits instead of re-scanning the entire descriptor table. Also replaces redundant `descriptor::view(at)` lookups with `descriptor::view_of(words[1], words[2])` using the already-read record words and reuses the looked-up `View` instead of querying `VIEWS` twice. ## Checks - N/A: pure performance optimization preserving identical UAV barrier/readability tracking and descriptor-table scan output. - N/A: no switches added, changed, or removed. - [x] No unrelated cleanup: diff is limited to `TableGroup`/`TablePlan` and `State::scan` in `crates/victory-gpu/src/draw.rs`. - N/A: existing `draw::` unit tests pass; no prior behavioural bug existed for a failing-before unit test. - [x] Checked open PR queue: independent of #445 and of `perf/records-skip-touch-batch-stats`. - [x] `cargo xtask policy` passed (`359 files ok`); no fork-only files, configs, or build outputs. ## Verified - `cargo xtask policy` — `359 files ok` - `PKG=victory-gpu ./build.sh test --lib -- draw:: --test-threads=1` (Proton Wine on Linux, RX 9070 XT) — `7 passed; 0 failed; 1 ignored`, 0 warnings - Also exercised in gameplay on GTA 6 Series S (Ryzen 5 7600X, RX 9070 XT, CachyOS + Proton); not benchmarked in isolation. ## Cost One small `Vec<u32>` (`uavs`) per `TableGroup` in `TablePlan`; 0 new warnings. AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 20:27:34 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-04 21:53 UTC · original

Checked 62df21f on native Windows (one NVIDIA desktop card plus WARP, didn't run the game), against current main.

Tests come out the same on both sides. draw:: is 7 passed, 1 ignored. The full victory-gpu lib has the same failures on main and on the PR (the two indirect host_list tests and the two pipeline library tests that fail natively, plus the flaky watch test). The device subset with diagnostics matches too, under WARP and on the NVIDIA card with the debug layer. Clippy with and without diagnostics adds nothing in draw.rs. Keep in mind that no test in the tree reaches State::scan, so the passing draw:: tests don't cover this change.

To see the cache itself I wrote a throwaway test (not pushed). It scans one table of two fake buffer records (SRV + UAV) five times with a different direct each call. The records point at no view, so this only checks the caching, not barriers or tracking. On main that table is never cached and each call returns the direct it was given. On the PR the second call hits and returns the first call's offset (7 instead of 9). After changed_something() it misses and caches again. When I rewrote the UAV record in place without an epoch bump, the rescan read the new record but the call still returned the old offset and skipped the SRV slot.

On invalidation, the hit is as safe as SRV-only tables already are on main, no more. The epoch moves on state changes (host.rs:5229 for transitions, 5340 for twins, defer_copy and friends), never on descriptor writes, and the key is just table address + group + STORES + tested depth. So on a hit the SRV slots of a UAV table now skip c.touch and the fresh re-mirror check (draw.rs:2841, 2843/2848), which main still did for them on every draw. Depth twin UAVs bump the epoch every time (|| colour at host.rs:5340), so those tables never get cached. Texture UAVs get cached whenever the scan doesn't need a transition, and buffer UAVs don't bump at all, so that's where the saving is.

The one case I'd look at is when the offset is a copy. On the aside path (draw.rs:2703 and 2723) scan gets a fresh copy of the table as direct on every draw, and beside snapshots the table bytes at call time. The same goes for the copy made for uncovered buffers. On main a UAV table always used the fresh copy. With the PR a hit returns the copy from the first scan of the epoch, while the UAV-only rescan reads the live table. If the title rewrites a UAV descriptor in place within the epoch, the barriers and write tracking follow the new view but the shader writes through the old copy. SRV-only tables already work like this on main, but for UAVs it's the write side that drifts. A cheap guard would be to take the UAV hit only when the cached offset is the plain direct one.

Smaller things

  • has_uav (draw.rs:38, 79) is now only written, never read.
  • uavs is built after the first-declaration dedup (draw.rs:89), so a descriptor declared SRV first and UAV second no longer marks the table as having UAVs. Main's scan used the SRV kind there anyway, so the output doesn't change, it just gets cached now.
  • counts[0] (SCANNED) is still incremented on UAV-only hits (draw.rs:2788), so that stat won't show the saving.
  • view_of(words[1], words[2]) matches view(at) once the VIEW_TAG check has passed, and one snapshot of the record is better than two reads.

Nothing blocking from me apart from the copy question.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-04 21:53 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/510#issuecomment-7425270001) Checked 62df21f on native Windows (one NVIDIA desktop card plus WARP, didn't run the game), against current main. Tests come out the same on both sides. `draw::` is 7 passed, 1 ignored. The full victory-gpu lib has the same failures on main and on the PR (the two indirect host_list tests and the two pipeline library tests that fail natively, plus the flaky watch test). The device subset with diagnostics matches too, under WARP and on the NVIDIA card with the debug layer. Clippy with and without diagnostics adds nothing in draw.rs. Keep in mind that no test in the tree reaches `State::scan`, so the passing `draw::` tests don't cover this change. To see the cache itself I wrote a throwaway test (not pushed). It scans one table of two fake buffer records (SRV + UAV) five times with a different `direct` each call. The records point at no view, so this only checks the caching, not barriers or tracking. On main that table is never cached and each call returns the `direct` it was given. On the PR the second call hits and returns the first call's offset (7 instead of 9). After `changed_something()` it misses and caches again. When I rewrote the UAV record in place without an epoch bump, the rescan read the new record but the call still returned the old offset and skipped the SRV slot. On invalidation, the hit is as safe as SRV-only tables already are on main, no more. The epoch moves on state changes (host.rs:5229 for transitions, 5340 for twins, defer_copy and friends), never on descriptor writes, and the key is just table address + group + STORES + tested depth. So on a hit the SRV slots of a UAV table now skip `c.touch` and the `fresh` re-mirror check (draw.rs:2841, 2843/2848), which main still did for them on every draw. Depth twin UAVs bump the epoch every time (`|| colour` at host.rs:5340), so those tables never get cached. Texture UAVs get cached whenever the scan doesn't need a transition, and buffer UAVs don't bump at all, so that's where the saving is. The one case I'd look at is when the offset is a copy. On the aside path (draw.rs:2703 and 2723) `scan` gets a fresh copy of the table as `direct` on every draw, and `beside` snapshots the table bytes at call time. The same goes for the copy made for uncovered buffers. On main a UAV table always used the fresh copy. With the PR a hit returns the copy from the first scan of the epoch, while the UAV-only rescan reads the live table. If the title rewrites a UAV descriptor in place within the epoch, the barriers and write tracking follow the new view but the shader writes through the old copy. SRV-only tables already work like this on main, but for UAVs it's the write side that drifts. A cheap guard would be to take the UAV hit only when the cached offset is the plain direct one. Smaller things - `has_uav` (draw.rs:38, 79) is now only written, never read. - `uavs` is built after the first-declaration dedup (draw.rs:89), so a descriptor declared SRV first and UAV second no longer marks the table as having UAVs. Main's scan used the SRV kind there anyway, so the output doesn't change, it just gets cached now. - `counts[0]` (SCANNED) is still incremented on UAV-only hits (draw.rs:2788), so that stat won't show the saving. - `view_of(words[1], words[2])` matches `view(at)` once the VIEW_TAG check has passed, and one snapshot of the record is better than two reads. Nothing blocking from me apart from the copy question. AI-assisted: yes
github-bot force-pushed github-bot/gh-510 from 62df21fa44 to 0952e48a89 2026-12-05 00:05:47 +00:00 Compare
Author
Owner

@⁠Not4Eric on GitHub · 2026-12-05 00:00 UTC · original

Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this

Pushed updates addressing your review:

  • Passed is_direct into State::scan so UAV tables are only read/stored in self.scanned when using the live direct table (neither aside/beside nor uncovered copies), preventing stale copied UAV tables from drifting on in-place descriptor updates.
  • Removed the unused has_uav field from TableGroup.
  • Guarded self.counts[0] += 1 with !uav_only so UAV-only re-scans aren't counted as full scans.
**@⁠Not4Eric** on GitHub · 2026-12-05 00:00 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/510#issuecomment-7427749666) Thank you so much for helping, I'm not the best at this and I'm heavily relying on AI to even do this Pushed updates addressing your review: - Passed `is_direct` into `State::scan` so UAV tables are only read/stored in `self.scanned` when using the live direct table (neither `aside`/`beside` nor `uncovered` copies), preventing stale copied UAV tables from drifting on in-place descriptor updates. - Removed the unused `has_uav` field from `TableGroup`. - Guarded `self.counts[0] += 1` with `!uav_only` so UAV-only re-scans aren't counted as full scans.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 00:48 UTC · original

Re-checked 0952e48 on native Windows (didn't run the game).

The copy issue is fixed. is_direct is false on both copy paths (draw.rs:2703, 2727) and true only for the plain direct table (2741), UAV tables only hit with it set (2780) and are only stored from a direct scan with nothing uncovered (2921). So a cached UAV offset is always the current direct one. My throwaway probe agrees, copies never cache or hit for a UAV table, a direct hit returns the direct offset, and a UAV record rewritten in place is no longer stale. has_uav is gone and UAV-only hits no longer bump counts[0] (2794).

Full victory-gpu lib is 352 passed / 5 failed, the same known native failures as before, and clippy with and without diagnostics shows nothing new.

Looks good to me.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 00:48 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/510#issuecomment-7428648120) Re-checked 0952e48 on native Windows (didn't run the game). The copy issue is fixed. `is_direct` is false on both copy paths (draw.rs:2703, 2727) and true only for the plain direct table (2741), UAV tables only hit with it set (2780) and are only stored from a direct scan with nothing uncovered (2921). So a cached UAV offset is always the current direct one. My throwaway probe agrees, copies never cache or hit for a UAV table, a direct hit returns the direct offset, and a UAV record rewritten in place is no longer stale. `has_uav` is gone and UAV-only hits no longer bump `counts[0]` (2794). Full victory-gpu lib is 352 passed / 5 failed, the same known native failures as before, and clippy with and without diagnostics shows nothing new. Looks good to me. AI-assisted: yes
github manually merged commit 412b0697a8 into main 2026-12-05 17:30:15 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.