perf: a draw's texture read looks its host side up once #443
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/443"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T18:53:37Z.
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, andHostList::transitiontakes 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_copyfor the upload check,HostList::twin_use→resource::twin, andlist::ensure_state→HostList::transition→host_copyagain. Each lookup (resource::hosted) takes the texture'smademutex, reads the clock and clones twoArcs; title threads (or, withVICTORY_THIN=1, our translating threads) drawing with the same textures queue on the same per-texture mutexes.ensure_statealso asks the driver for the texture's description (legal_state→GetDesc) for each barrier it records.The change
resource::host_sidereturns the host copy and the twin from one lookup.HostList::transition_held,list::ensure_held_stateandHostList::twin_use_heldwork on a copy the caller holds.transition,ensure_stateandtwin_uselook the copy up once and call them, so every other caller gets the same answer.ensure_held_statetakes the legal state fromtransition_heldinstead ofGetDesc.readablelooks 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::twinhad no other caller and is gone.readablereturns early when the texture has no host side. That skips nothing that did anything before:resource::hosted(this, true)gives None only for a buffer or a texture the host refused to make (refused, never cleared), so main's latertwin_use,ensure_state→transitionand debughost_resourcefound nothing either and recorded nothing. TheTESTED_DEPTHnote (a view reads the depth target the draw only tests) doesn't need the host side, so it comes before the lookup and is made as on main. The diagnostics debug line uses the copy already in hand.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 %).DrawIndexedInstanced, six textures, nothing changedDispatch(table: texture + UAV buffer)ExecuteIndirect, 1 indexed drawAbout 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_oncecounts the host-side lookups (HOSTED_ASKED, test-only) of a draw's read: one. Withreadableput back ontwin_useandensure_state(main's path) it counts three and fails. It also checks the read still moves and uploads the texture as before.On main
a4453083(with #444),cargo test -p victory-gpu --lib, one thread:VICTORY_D3D12_ADAPTER=Intel)--features diagnostics)The Intel failure (
anisotropic_heap_sampler_reads_the_requested_mip) and the WARP one (timeline::report::tests::real_waits_are_recorded_with_who_ended_them) are the same as on main. Clippy (--all-targets, with and withoutdiagnostics): no new warnings.cargo xtask policyok, ruff (W605,F,E9) clean. The measurements above were taken onb6d86cf8, before #444 merged.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
Rebased onto main
a4453083, which already has #433 and #444; it applied without conflicts.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
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T20:21:53Z.
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).
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T20:46:08Z.
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 branchperf/texture-read-once-combinedfor when it returns.AI use: Claude Code (Claude Opus 5.5).
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T23:48:34Z.
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 onperf/texture-read-once-neptune.AI use: Claude Code (Claude Opus 5.5).
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T13:37:46Z.
Rebased onto main
fa6b209eafter #433 (the only conflict: both add a testmodline at the top ofdraw.rs; both kept). Nothing on main touched the texture-read path. Tests:a_texture_read_looks_its_host_side_up_oncefails without the change (3 lookups per read) and passes with it; victory-gpu lib suite, one thread: RTX 457 passed, Intel 456 passed + 1 failed (anisotropic_heap_sampler_reads_the_requested_mip, which fails the same way on main);cargo xtask policyok; clippy no new warnings vs main; ruff clean.AI use: Claude Code (Claude Opus 5.5).
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T15:49:13Z.
The red CI is not from this PR: the only failing test is
run::tests::big_pools_come_after_the_tuned_set_and_before_quality_and_overridesincrates/anyxboxx(8 vs 6 landing threads on the 24-CPU runner), fixed on main by3cc19ade. Please rebase on current main (it now includes #444, which reworkedresource.rs) and rerundraw::texture_read_tests: yourHOSTED_ASKEDcount hookshosted(), which #444 touched. One question for the description:readable()now returns early when the texture has no host side, which also skips the state transition and the debug block, not only the upload. Is that intended?Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T16:35:37Z.
Rebased onto main
a4453083(with #444 and3cc19ade) and force-pushed. It rebased cleanly. Point by point:1.
draw::texture_read_testsafter #444.HOSTED_ASKEDstill counts inresource::hosted, which #444 did not move. #444's reads that skip the lock (host_written_mark,staged_first,alias_of's kept answer) don't take the texture'smadelock, so they don't count as lookups. No othermade.lock()site is onreadable's path; the remaining ones are inwant_level,host_waits,copy_state, the sweep and the census. I reran the test on the rebased head:readableput back onhost_copy+twin_use+ensure_state(main's path), on the same base: it fails withleft: 3, right: 1("lookups of the texture's host side in a read").2. Your question:
readablereturns early without a host side. Is that intended? Yes. For everything that needs the host side it is the same as before, becauseresource::hosted(this, true)returning None is final:hostedreturns None in only two cases:r.desc.dimension == BUFFER);refused). It is set when the creation fails (let Some(texture) = texture else { r.host.refused.store(true, …); return None }) and never cleared. A first failed creation sets it, so the next call returns None too.readable, main's three later lookups find nothing as well, and none of them records anything:host_copy→ no upload;twin_use→twin→hosted→ returnsfalsebefore touchingtwins;ensure_state→HostList::transition→host_copy(resource)?→ no barrier and no entry in the list'sstates;host_resource→hosted→ None, so no line is logged.hostedcall for it returns None too. Debug-layer state is untouched either way, because nothing reached the D3D12 list.TESTED_DEPTHnote. It records that a view reads the depth target the draw only tests. Its only reader is the depth target's ownensure_stateinState::prepare_for(DEPTH_READ | SHADER_RESOURCEinstead ofDEPTH_READ), and for a texture without a host side that does nothing either. So skipping it changed nothing. To make the early return skip only what needs the host side, without relying on that argument, a second commit (f8d69d37) moves the note above the lookup. The note is now made exactly as on main whatever the texture has. The diagnostics-only debug line now uses the copy already in hand instead of a fourthhostedcall.3. Reruns on the rebased head (
f8d69d37),cargo test -p victory-gpu --lib, one thread:a4453083VICTORY_D3D12_ADAPTER=Intel)--features diagnostics)anisotropic_heap_sampler_reads_the_requested_mipand the WARP one istimeline::report::tests::real_waits_are_recorded_with_who_ended_them. Both fail the same way on main.texture::read_marks_tests(#444) passes on this branch.--all-targets, with and withoutdiagnostics) has no new warnings against main.cargo xtask policypasses (296 files), ruff (W605,F,E9) andtest_readme_syncare clean, and the CI build step passes (cargo release workspace build, runtime CMake, TomBox DLLs).The description has the same answer under "The change".
AI use: Claude Code (Claude Opus 5.5).