Skip to content

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

Open
KainanP wants to merge 1 commit into
LooperSalty:mainfrom
KainanP:perf/texture-read-once
Open

KainanP wants to merge 1 commit into
LooperSalty:mainfrom
KainanP:perf/texture-read-once

Conversation

@KainanP

@KainanP KainanP commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Re-ported onto the Vice-Tay base (#454), on main b6d86cf, 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 added a commit to KainanP/AnyXboxX that referenced this pull request Nov 26, 2026
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 three times: resource::host_copy for the upload check,
HostList::twin_use -> resource::twin, and HostList::transition ->
host_copy again. Each lookup (resource::hosted) takes the texture's
`made` mutex, reads the clock and clones two Arcs; title threads that
draw with the same textures queue on the same per-texture mutexes.

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 also takes the
legal state from transition_held instead of asking the driver
(GetDesc) again for each barrier. readable looks the texture up once
for the upload, the twin and the state. resource::twin had no other
caller and is gone.

The commands recorded are the same. The texture's kept flags (the other
half of Marvisak/VIctory#3258) are already in this base.

Source: port of Marvisak/VIctory#3258 (KainanP), first ported as
LooperSalty#443 onto the previous base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KainanP
KainanP force-pushed the perf/texture-read-once branch from 73b7eaf to b4984d6 Compare November 26, 2026 20:21
@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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
KainanP force-pushed the perf/texture-read-once branch from b4984d6 to 2e0986b Compare November 26, 2026 20:45
@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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).

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 three times: resource::host_copy for the upload check,
HostList::twin_use -> resource::twin, and HostList::transition ->
host_copy again. Each lookup (resource::hosted) takes the texture's
`made` mutex, reads the clock and clones two Arcs; title threads that
draw with the same textures queue on the same per-texture mutexes.

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 also takes the
legal state from transition_held instead of asking the driver
(GetDesc) again for each barrier. readable looks the texture up once
for the upload, the twin and the state. resource::twin had no other
caller and is gone.

The commands recorded are the same. The texture's kept flags (the other
half of Marvisak/VIctory#3258) are already in this base.

Source: port of Marvisak/VIctory#3258 (KainanP), first ported as
LooperSalty#443 onto the Neptune base;
this is its port onto the Vice-Tay base (LooperSalty#454).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KainanP
KainanP force-pushed the perf/texture-read-once branch from 2e0986b to 946b2de Compare November 26, 2026 23:47
@KainanP KainanP changed the title perf: a draw's texture read looks its host copy up once, its flags kept perf: a draw's texture read looks its host side up once Nov 26, 2026
@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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 b6d86cf (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).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant