Repository navigation
Conversation
…thout asking the driver Every texture a draw reads through a table went through `readable`, which looked the title texture's host copy up three times (the upload check, the upload, the state move), each through the resource's lock, and asked the driver for the texture's description three times (`title_written`, then `legal_state` in `HostList::transition` and again in `list::ensure_state`) for flags that never change. - `HostTexture` keeps its resource flags, read once when it is made; `HostTexture::legal` and `HostTexture::title_written` answer from them what `host::legal_state` and `texture::title_written` ask GetDesc for. - `HostList::transition_held` and `list::ensure_held_state` move a host copy the caller holds; `transition` and `ensure_state` look it up and use them, so their answers are the same. - `texture::upload_copy` is `upload` for a copy the caller holds. - `readable` takes the copy once for the upload and the state move. Same moves, same uploads: two tests, one comparing the kept flags' answers with the driver's for five kinds of texture and every state bit, one checking the moves and the single upload a list records for reads of a title-written texture, and that a texture the host wrote is not uploaded. Measured with an #[ignore]d per-call benchmark (Marvisak#2586; RTX 4060 Laptop, release, median of 7 interleaved runs): an indexed draw reading six textures through a table 2713 -> 2047 ns; `list::ensure_state` with the state unchanged 70 -> 35 ns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 26, 2026
[Upstream PR #3254] Count evictable HostTextures and skip empty per-frame census
vanya890/VIctory#95
Closed
Dukestar69
approved these changes
Nov 26, 2026
Dukestar69
left a comment
There was a problem hiding this comment.
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
- Caching
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).
vanya890
added a commit
to vanya890/VIctory
that referenced
this pull request
Nov 26, 2026
Adapt upstream Marvisak#3258 to the fork's Marvisak#3245 pinned-copy helpers. Cache immutable resource flags, use one retained HostTexture for upload/staging/state, and add flag parity and repeated-read regression coverage.
This was referenced Nov 26, 2026
This was referenced Nov 26, 2026
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)The 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 GPU: return pinned HostTexture from alias_source to avoid source Release UAF #3245 lands first. This PR merges cleanly with GPU: no texture layouts or name copies per draw for unchanged answers #1978, GPU: per-list and per-submission sets hash with FxHash, not SipHash #2102, GPU: title threads recording lists no longer wait on descriptor and buffer-copy locks #2821, GPU: a draw's table entries are looked up once #3061, GPU: a read slot is resolved once, not twice #3215, GPU: a draw reads the swizzle it already has, and the release frame line costs nothing #3238, GPU: the per-frame eviction pass is counted, and its census reads a flag instead of GetDesc per texture #3254 and GPU: list calls can translate on worker threads (VICTORY_DEFER_LISTS, opt-in) #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