perf: a draw's texture read looks its host side up once #443

Open
github-bot wants to merge 1 commit from github-bot/gh-443 into main AGit
Owner

@⁠KainanP on GitHub · 2026-11-26 18:53 UTC · original
KainanP:perf/texture-read-once → main · +161 −30 · 5 files · 1 commits · open

Re-ported onto the Vice-Tay base (#454), on main b6d86cf8, with numbers measured there. The Neptune-base version is kept on KainanP/AnyXboxX:perf/texture-read-once-neptune, the combined-base one on perf/texture-read-once-combined.

Port of Marvisak/VIctory#3258 (mine) to this tree's draw::readable. Vice-Tay already has half of it (a host texture keeps its resource flags, and HostList::transition takes the legal state from them); the other half, one host-side lookup per texture read, is not there.

The problem

Every texture a draw or dispatch reads through a view goes through draw::readable. For one texture it looks the title texture's host side up three times: resource::host_copy for the upload check, HostList::twin_use → resource::twin, and list::ensure_state → HostList::transition → host_copy again. Each lookup (resource::hosted) takes the texture's made mutex, reads the clock and clones two Arcs; title threads (or, with VICTORY_THIN=1, our translating threads) drawing with the same textures queue on the same per-texture mutexes. ensure_state also asks the driver for the texture's description (legal_state → GetDesc) for each barrier it records.

The change

  • resource::host_side returns the host copy and the twin from one lookup.
  • HostList::transition_held, list::ensure_held_state and HostList::twin_use_held work on a copy the caller holds. transition, ensure_state and twin_use look the copy up once and call them, so every other caller gets the same answer. ensure_held_state takes the legal state from transition_held instead of GetDesc.
  • readable looks the texture up once for the upload, the twin and the state. A texture let go between the old lookups could give the upload and the barrier two different host textures; with one lookup it can't.
  • resource::twin had no other caller and is gone.

The commands recorded are the same.

Measured

The list bench of #441 (pipeline::list_bench, #[ignore]d). Each row: best of 5 × 20,000 calls; each build's test binary ran 7 times interleaved with the others, median [min–max]. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile. Quiet machine: no game running, Windows reported 0–31 % CPU load around the runs (mostly under 16 %).

ns main this PR
DrawIndexedInstanced, six textures, nothing changed 1343 [1203–1444] 1112 [1060–1159]
draw sequence, per draw, 1 thread 1340 [1284–1398] 1134 [1084–1180]
draw sequence, per draw, 5 threads at once 3267 [3097–3358] 2629 [2456–2731]
the same with placed views, 1 thread 1565 [1544–1611] 1384 [1289–1442]
the same with placed views, 5 threads 4315 [4008–4472] 3627 [3572–3664]
Dispatch (table: texture + UAV buffer) 637 [574–675] 585 [535–601]
ExecuteIndirect, 1 indexed draw 3049 [3003–3136] 2832 [2719–2873]

About 35 ns less per texture read on one thread (−15 % a draw), −20 % a draw on five threads. With #444 as well, the draw sequence on 5 threads goes 3267 → 2156 ns (placed views 4315 → 2347).

Tests

New, draw/texture_read_tests.rs: a_texture_read_looks_its_host_side_up_once counts the host-side lookups (HOSTED_ASKED, test-only) of a draw's read: one. With readable put back on twin_use and ensure_state (main's path) it counts three and fails. It also checks the read still moves and uploads the texture as before.

cargo test -p victory-gpu --release --lib, one thread: RTX 4060 Laptop 422 passed (main 421), Intel UHD (a78b, VICTORY_D3D12_ADAPTER=Intel) with #441/#444 too 428 passed (main 421), WARP (--features diagnostics, VICTORY_D3D12_WARP=1) with #441/#444 too: the same single failure as main (timeline::report::tests::real_waits_are_recorded_with_who_ended_them). Clippy (--all-targets, with and without diagnostics): only main's warning. cargo xtask policy ok, ruff clean.

What this does not show

No in-game numbers: I don't run the title here. The bench's draw reads six textures; a title draw reads from none to dozens, so the saving scales with that. Please A/B it in game (frame time, or the translating threads' time with VICTORY_THIN=1).

Overlaps

git merge-tree against the open PRs that touch third_party/victory and merge with main: only #433 conflicts (both add a test mod line at the top of draw.rs; keep both). #441 and #444 merge with this in any order (built and tested together).

AI use: Claude Code (Claude Opus 5.5) ported the change, wrote the tests, ran the measurements and drafted this description.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/443) `KainanP:perf/texture-read-once` → `main` · +161 −30 · 5 files · 1 commits · open > **Re-ported onto the Vice-Tay base (#454)**, on main b6d86cf8, with numbers measured there. The Neptune-base version is kept on [`KainanP/AnyXboxX:perf/texture-read-once-neptune`](https://github.com/KainanP/AnyXboxX/tree/perf/texture-read-once-neptune), the combined-base one on [`perf/texture-read-once-combined`](https://github.com/KainanP/AnyXboxX/tree/perf/texture-read-once-combined). Port of Marvisak/VIctory#3258 (mine) to this tree's `draw::readable`. Vice-Tay already has half of it (a host texture keeps its resource flags, and `HostList::transition` takes the legal state from them); the other half, one host-side lookup per texture read, is not there. ## The problem Every texture a draw or dispatch reads through a view goes through `draw::readable`. For one texture it looks the title texture's host side up **three** times: `resource::host_copy` for the upload check, `HostList::twin_use` → `resource::twin`, and `list::ensure_state` → `HostList::transition` → `host_copy` again. Each lookup (`resource::hosted`) takes the texture's `made` mutex, reads the clock and clones two `Arc`s; title threads (or, with `VICTORY_THIN=1`, our translating threads) drawing with the same textures queue on the same per-texture mutexes. `ensure_state` also asks the driver for the texture's description (`legal_state` → `GetDesc`) for each barrier it records. ## The change - `resource::host_side` returns the host copy and the twin from one lookup. - `HostList::transition_held`, `list::ensure_held_state` and `HostList::twin_use_held` work on a copy the caller holds. `transition`, `ensure_state` and `twin_use` look the copy up once and call them, so every other caller gets the same answer. `ensure_held_state` takes the legal state from `transition_held` instead of `GetDesc`. - `readable` looks the texture up once for the upload, the twin and the state. A texture let go between the old lookups could give the upload and the barrier two different host textures; with one lookup it can't. - `resource::twin` had no other caller and is gone. The commands recorded are the same. ## Measured The list bench of #441 (`pipeline::list_bench`, `#[ignore]`d). Each row: best of 5 × 20,000 calls; each build's test binary ran 7 times interleaved with the others, median [min–max]. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile. Quiet machine: no game running, Windows reported 0–31 % CPU load around the runs (mostly under 16 %). | ns | main | this PR | |---|---:|---:| | `DrawIndexedInstanced`, six textures, nothing changed | 1343 [1203–1444] | **1112** [1060–1159] | | draw sequence, per draw, 1 thread | 1340 [1284–1398] | **1134** [1084–1180] | | draw sequence, per draw, 5 threads at once | 3267 [3097–3358] | **2629** [2456–2731] | | the same with placed views, 1 thread | 1565 [1544–1611] | **1384** [1289–1442] | | the same with placed views, 5 threads | 4315 [4008–4472] | **3627** [3572–3664] | | `Dispatch` (table: texture + UAV buffer) | 637 [574–675] | **585** [535–601] | | `ExecuteIndirect`, 1 indexed draw | 3049 [3003–3136] | **2832** [2719–2873] | About 35 ns less per texture read on one thread (−15 % a draw), −20 % a draw on five threads. With #444 as well, the draw sequence on 5 threads goes 3267 → 2156 ns (placed views 4315 → 2347). ## Tests New, `draw/texture_read_tests.rs`: `a_texture_read_looks_its_host_side_up_once` counts the host-side lookups (`HOSTED_ASKED`, test-only) of a draw's read: one. With `readable` put back on `twin_use` and `ensure_state` (main's path) it counts three and fails. It also checks the read still moves and uploads the texture as before. `cargo test -p victory-gpu --release --lib`, one thread: RTX 4060 Laptop 422 passed (main 421), Intel UHD (a78b, `VICTORY_D3D12_ADAPTER=Intel`) with #441/#444 too 428 passed (main 421), WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`) with #441/#444 too: the same single failure as main (`timeline::report::tests::real_waits_are_recorded_with_who_ended_them`). Clippy (`--all-targets`, with and without `diagnostics`): only main's warning. `cargo xtask policy` ok, ruff clean. ## What this does not show No in-game numbers: I don't run the title here. The bench's draw reads six textures; a title draw reads from none to dozens, so the saving scales with that. **Please A/B it in game** (frame time, or the translating threads' time with `VICTORY_THIN=1`). ## Overlaps `git merge-tree` against the open PRs that touch `third_party/victory` and merge with main: only #433 conflicts (both add a test `mod` line at the top of `draw.rs`; keep both). #441 and #444 merge with this in any order (built and tested together). _AI use: Claude Code (Claude Opus 5.5) ported the change, wrote the tests, ran the measurements and drafted this description._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Every texture a draw or dispatch reads through a view goes through
draw::readable. For one texture it looked the title texture's host side
up four times (host_resource for the upload, twin_use, then
HostList::transition's host_resource and host_copy), each taking the
texture's `made` lock, reading the clock and cloning two Arcs, and asked
the driver for the texture's description three times (title_written,
then legal_state in transition and again in ensure_state). The flags
never change once the host texture is made.

- HostTexture keeps its resource flags, read once when it is made;
  HostTexture::legal and ::title_written give what legal_state and
  texture::title_written give, without GetDesc.
- resource::host_side gives the host copy and the twin from one lookup.
- HostList::transition_held, list::ensure_held_state and
  HostList::twin_use_held work on a copy the caller holds; transition,
  ensure_state and twin_use look it up once and call them, so every
  other caller gets the same result.
- readable looks the texture up once for the upload, the twin and the
  state. (A texture let go between the old lookups could give the
  upload and the barrier two different host textures; not any more.)

Same commands recorded. Tests: the kept flags match GetDesc for five
kinds of host texture and every state bit; a read moves the texture as
a read by resource does, records its upload once and skips a texture
the host wrote (this one passes on main too: same behaviour).

List bench (ignored, test PR), RTX 4060 Laptop, release, median of 7
interleaved runs: DrawIndexedInstanced reading six textures 3843 ->
2374 ns; draw sequence on 5 threads 8357 -> 6227 ns a draw (placed
views: 9538 -> 7109).

Source: Marvisak/VIctory#3258 (ported by hand: this tree's readable
also has the twin, the alias copy and the upload's first level)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:42 +00:00
github-bot force-pushed github-bot/gh-443 from 73b7eaf5bd to b4984d6156 2026-11-26 20:24:50 +00:00 Compare
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 20:21 UTC · original

Re-ported onto the combined base (#409) and force-pushed. The base already keeps the host texture's flags, so this is now only the single host-side lookup per read (it was 3). List bench of #441, median of 7 interleaved runs, RTX 4060 Laptop: draw with six textures 2133 → 1782 ns, draw sequence 1 / 5 threads 2095 / 5597 → 1747 / 4517 ns. With #444, 5 threads go 5597 → 3955. The new test counts lookups and fails on main (3 instead of 1). Description updated.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 20:21 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/443#issuecomment-7202587616) Re-ported onto the combined base (#409) and force-pushed. The base already keeps the host texture's flags, so this is now only the single host-side lookup per read (it was 3). List bench of #441, median of 7 interleaved runs, RTX 4060 Laptop: draw with six textures 2133 → 1782 ns, draw sequence 1 / 5 threads 2095 / 5597 → 1747 / 4517 ns. With #444, 5 threads go 5597 → 3955. The new test counts lookups and fails on main (3 instead of 1). Description updated. _AI use: Claude Code (Claude Opus 5.5)._
github-bot force-pushed github-bot/gh-443 from b4984d6156 to 2e0986b4eb 2026-11-26 20:50:59 +00:00 Compare
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 20:46 UTC · original

Main reverted #409 (#452), so this is back to the Neptune-base version measured in the original body, rebased onto 15024d5 (RTX: its tests pass, and the suite gives the same results as before). The combined-base port is kept on branch perf/texture-read-once-combined for when it returns.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 20:46 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/443#issuecomment-7203053050) Main reverted #409 (#452), so this is back to the Neptune-base version measured in the original body, rebased onto 15024d5 (RTX: its tests pass, and the suite gives the same results as before). The combined-base port is kept on branch [`perf/texture-read-once-combined`](https://github.com/KainanP/AnyXboxX/tree/perf/texture-read-once-combined) for when it returns. _AI use: Claude Code (Claude Opus 5.5)._
github-bot changed title from perf: a draw's texture read looks its host copy up once, its flags kept to perf: a draw's texture read looks its host side up once 2026-11-27 00:37:49 +00:00
github-bot force-pushed github-bot/gh-443 from 2e0986b4eb to 946b2de53c 2026-11-27 00:37:50 +00:00 Compare
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 23:48 UTC · original

Re-ported onto the Vice-Tay base (#454). The base already keeps a host texture's flags (half of this PR); the single host-side lookup per read was still missing, so that is what this PR does now. On b6d86cf8 (list bench of #441, quiet machine): draw sequence 1340 → 1134 ns on one thread, 3267 → 2629 ns on five (placed views 4315 → 3627); with #444, 2156 (2347). Suites on RTX, Intel UHD and WARP: same results as main. Description updated; the Neptune version is on perf/texture-read-once-neptune.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-26 23:48 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/443#issuecomment-7205879886) Re-ported onto the Vice-Tay base (#454). The base already keeps a host texture's flags (half of this PR); the single host-side lookup per read was still missing, so that is what this PR does now. On b6d86cf8 (list bench of #441, quiet machine): draw sequence 1340 → 1134 ns on one thread, 3267 → 2629 ns on five (placed views 4315 → 3627); with #444, 2156 (2347). Suites on RTX, Intel UHD and WARP: same results as main. Description updated; the Neptune version is on [`perf/texture-read-once-neptune`](https://github.com/KainanP/AnyXboxX/tree/perf/texture-read-once-neptune). _AI use: Claude Code (Claude Opus 5.5)._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 origin '+refs/pull/443/head:github-bot/gh-443'
git switch 'github-bot/gh-443'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'main'
git merge --squash 'github-bot/gh-443'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'main'
git merge 'github-bot/gh-443'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.