GPU: a draw's texture read takes its host copy once, and its flags without asking the driver #3256
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3258"
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 Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T14:48:50Z.
Part of #2586 (the per-call cost of list methods on the title's threads). Local optimization, no architecture change, same behaviour.
The problem
Every texture a draw or dispatch reads through a descriptor table goes through
draw::readable. For one texture it:resource::host_resource(for the upload check),texture::upload→is_host_written→resource::host_copy, andlist::ensure_state→HostList::transition→resource::host_copy. Each lookup takes the resource'shostmutex and clones anArc(host_resourcealso AddRefs/Releases the COM texture). Title threads drawing with the same textures all take the same per-resource mutexes.texture::title_written(GetDesc), thenhost::legal_stateinHostList::transitionandhost::legal_stateagain inlist::ensure_state. The flags never change after the texture is made.The per-call benchmark below has an indexed draw that reads six textures. On main,
list::ensure_statewith the state unchanged costs 70 ns and the whole texture path about 1.9 µs of a 2.7 µs draw.The change
HostTexturekeeps its resource flags (flags), read once inHostTexture::new, which already calledGetDesc.HostTexture::legal(state)andHostTexture::title_written()give the same answers ashost::legal_stateandtexture::title_written, without callingGetDesc.HostList::transition_held(copy, wanted)andlist::ensure_held_state(list, copy, state)move a host copy the caller already holds.transitionandensure_statelook the copy up once and call them, so every other caller gets the same result.texture::upload_copy(list, resource, copy)does whatuploaddoes, for a copy the caller holds. The diagnostics-only "keeps what the host copied" note moved into a shared helper, unchanged.readablelooks up the copy once and uses it for both the upload and the state move. A texture evicted between the old lookups could give the upload and the barrier two different host textures. With one lookup that can't happen.Tests
Two new tests in
draw::tests:a_host_textures_kept_flags_give_what_its_description_does: for five kinds of host texture (plain, render target, unordered access, depth, depth + deny shader resource), the kept flags matchGetDesc.legal()matcheslegal_statefor every state bit and the common combinations, andtitle_written()matchestexture::title_written.a_texture_read_uploads_once_and_moves_as_a_read_by_resource: reading a title-written texture, moving it to copy source by resource, then reading it twice more gives exactly the barriers a read by resource gives: none on first use, then SR→copy source→SR. The list records its upload once. A texture the host wrote is not uploaded.Runs:
--features diagnostics,VICTORY_D3D12_WARP=1, serial)63bcca4The RTX failures are
descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views(the NVIDIA heap cap, #1835).memory_tests::heap_direct_texture_reads_mark_their_heap_indexwas skipped on NVIDIA because it access-violates on main too. Intel also failsa_texture_written_in_one_format_reads_in_another_through_a_placed_viewon main.cargo clippy -p victory-gpu --all-targetspasses with-D warnings, with and without--all-features. rustfmt is clean on the changed lines.Measured
Method: an
#[ignore]d test,pipeline::list_bench(branchperf/list-call-benchon my fork, one commit on top of main, not part of this PR). It calls each list method through the list's method table on a host device. The title buffers are in write-watched memory, the view heap is a shader-visible title heap, and the pipelines' translations read root views, root constants and a six-texture table the way the title's do. Their host code reads nothing, so any root signature accepts it, and the CPU work per call is the same. Each row is the best of 5 × 20,000 calls. Lists are reset every 2,000 calls. Each build's test binary was run 7 times, interleaved in random order with the other builds, and the table gives the median. RTX 4060 Laptop GPU, Core i7-14650HX, Windows 11, release profile, machine otherwise idle.DrawIndexedInstanced, nothing changedDispatch(table: texture + UAV buffer, root CBV)ExecuteIndirect, one indexed drawlist::ensure_state, state unchangedOn one thread the saving adds to the other PRs' savings: about 600 ns per six-texture draw in every combination.
With five threads recording at once, the shared locks set the time:
HostHeap::made,descriptor::VIEWS,TEXTURES_AT) more often, and those locks get more contended;So this PR should merge with or after #2821, not alone after #1978.
What this does not show
Request: could someone with the game run an A/B of the frame line's list-call time (or #3224's counters) on main and on this branch, in the same spot in the world?
Overlap
transition_copy/ensure_copy_state) for its use-after-free fix. Both PRs touch the same lines inHostList::transitionandlist::ensure_state. Whichever merges second should use the other's helper. I'll rebase onto it if #3245 lands first. This PR merges cleanly with #1978, #2102, #2821, #3061, #3215, #3238, #3254 and #3184.AI use: Claude Code (Claude Opus 5.5) wrote the change, the tests and the benchmark, ran the measurements and drafted this description.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:12:06Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
desc.Flagsonce onHostTextureat construction avoids repeatedID3D12Resource::GetDesc()calls across transitions/uploads, and passing the held&Arc<HostTexture>throughtransition_held/ensure_held_stateavoids redundanthost_copylookups while keeping the host texture pinned across the whole draw read.cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 22 passed, 0 failed (includinga_host_textures_kept_flags_give_what_its_description_doesanda_texture_read_uploads_once_and_moves_as_a_read_by_resource).cargo test -p victory-gpu --lib texture:: -- --test-threads=1(RTX 5090): 2 passed, 0 failed.cargo test -p victory-gpu --lib resource:: -- --test-threads=1(RTX 5090): 18 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:48:39Z.
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:cargo test -p victory-gpu --lib: 233 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.The two new tests are
a_host_textures_kept_flags_give_what_its_description_doesanda_texture_read_uploads_once_and_moves_as_a_read_by_resource; both pass. Synthetic only. AI-assisted.Imported from Marvisak/VIctory. Originally posted by z395977743-svg on 2026-11-27T01:46:54Z.
I tested a partial downstream port of
723d6d5con an RX 7900 XTX 24 GB, Ryzen 5 5600X, 32 GB, Win10 build 19045, driver32.0.32029.2010. Base was avatarmanz014d52dewith the same Agility 1.620.2 and keyboard/mouse compatibility changes in both executables. This adapts the single-draw reuse for eligible full-resolution texture copies. The downstream alias, depth-twin and low-mip promotion paths were preserved. There was no cross-draw cache.Series X, 2560×1440 internal → 3840×2160 output, warmed pipelines, RT and frame generation off. For each run I copied the same save, skipped the opening scene, sampled the prison window, moved backward twice and sampled the door. Here are the engine's real FPS:
At the door, the first difference was +1.22 FPS and the reversed comparison was +0.01 FPS. Using only the constants and journal ports as a separate single-pass check gave 15.84/14.19 FPS (window/door) on baseline and 16.00/14.12 with the adaptation. I could play through to the cell interaction prompt, all six runs exited 0, and a focused test on the real D3D12 adapter passed for upload, repeated reads and resource-state transitions. This is encouraging for compatibility on this path, but does not demonstrate a repeatable game-FPS increase on this machine or measure the complete PR on Marvisak main.
See the full overnight report, per-run configuration and measurements.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.