GPU: no texture layouts or name copies per draw for unchanged answers #1976

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/1978 into main
0xkn0wh3r3 commented 2026-11-25 02:15:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T02:15:04Z.


The problem

Two lookups that run on every draw did expensive work even when the answer did not need it. Both run under a global lock, so the cost adds to every draw.

  • resource::alias_source runs for every placed view a draw reads. It built the placed texture's full console layout (texture_layout, a mip chain of vectors) under the global TEXTURES_AT lock, and only then looked at the other textures at its address. Most placed views have no texture the GPU writes at that address, so the layout was usually built for nothing.
  • memory::note_use runs on every draw that reads title memory. It copied the pipeline's name into a new String each time, under the process-wide stats lock, even when that name was counted already.

The fix

  • resource::alias_source now does the cheap tests first: another resource, written by the GPU, whose host texture is made (and is not this one's). It builds the layout only once such a texture is found. The answer is the same in every case.
  • memory::note_use looks the name up first and only copies it when it is new, so the name is copied once per frame instead of once per draw.

Testing

  • cargo test -p victory-gpu on an RTX 5070 Ti (driver 621.24): all pass except descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way on main (the NVIDIA 1,000,000-descriptor heap cap, #1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.

Not covered

Not measured in a game run (no game data here). The answers are the same by construction.

Rebased onto 13f91ca

  • Upstream now makes host textures on first use, so the cheap test checks that the other texture's host texture has been made (made). Before, it checked for a host texture of its own. The code of both changes is otherwise the same.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5483833341 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T02:15:04Z. --- ## The problem Two lookups that run on every draw did expensive work even when the answer did not need it. Both run under a global lock, so the cost adds to every draw. - `resource::alias_source` runs for every placed view a draw reads. It built the placed texture's full console layout (`texture_layout`, a mip chain of vectors) under the global `TEXTURES_AT` lock, and only then looked at the other textures at its address. Most placed views have no texture the GPU writes at that address, so the layout was usually built for nothing. - `memory::note_use` runs on every draw that reads title memory. It copied the pipeline's name into a new `String` each time, under the process-wide stats lock, even when that name was counted already. ## The fix - `resource::alias_source` now does the cheap tests first: another resource, written by the GPU, whose host texture is made (and is not this one's). It builds the layout only once such a texture is found. The answer is the same in every case. - `memory::note_use` looks the name up first and only copies it when it is new, so the name is copied once per frame instead of once per draw. ## Testing - `cargo test -p victory-gpu` on an RTX 5070 Ti (driver 621.24): all pass except `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, which fail the same way on `main` (the NVIDIA 1,000,000-descriptor heap cap, #1835). - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. ## Not covered Not measured in a game run (no game data here). The answers are the same by construction. ### Rebased onto 13f91ca - Upstream now makes host textures on first use, so the cheap test checks that the other texture's host texture has been made (`made`). Before, it checked for a host texture of its own. The code of both changes is otherwise the same.
catminou4 commented 2026-11-25 02:48:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:48:38Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

No per-draw texture layouts/name copies when answers are unchanged — draw-call CPU overhead reduction; caching must be keyed on everything that affects the layout. Windows perf validation needed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051086793 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#pullrequestreview-6051086793). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:48:38Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. No per-draw texture layouts/name copies when answers are unchanged — draw-call CPU overhead reduction; caching must be keyed on everything that affects the layout. Windows perf validation needed.
DesertGamer commented 2026-11-25 03:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-25T02:17:09Z.


VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150533676 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#issuecomment-7150533676). Originally posted by [DesertGamer](https://github.com/DesertGamer) on 2026-11-25T02:17:09Z. --- ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
0xkn0wh3r3 commented 2026-11-25 07:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:35:32Z.


@catminou4: nothing is cached here. Both changes compute the same answers as before, only in a cheaper order. alias_source runs its cheap checks first (another resource, written by the GPU, a host texture of its own), and builds the texture layout only for a candidate that passes them. note_use looks the pipeline name up before copying it, rather than copying it every draw. Nothing is kept from one draw to the next, so no cache key is involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154951716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#issuecomment-7154951716). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T06:35:32Z. --- @catminou4: nothing is cached here. Both changes compute the same answers as before, only in a cheaper order. `alias_source` runs its cheap checks first (another resource, written by the GPU, a host texture of its own), and builds the texture layout only for a candidate that passes them. `note_use` looks the pipeline name up before copying it, rather than copying it every draw. Nothing is kept from one draw to the next, so no cache key is involved.
Marvisak commented 2026-11-25 09:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:23:46Z.


Automated triage for the maintainers.

Merge candidate (re-checked on bc51d6f). This push is a rebase, and the code matches what was reviewed before. In resource::alias_source (crates/victory-gpu/src/resource.rs), the cheap tests come first: another resource, GPU-written, with a different made host texture. The placed texture's layout (bytes/texture_layout) is built only when such a candidate exists. The result is still the first matching candidate in the same order, and None in the same cases as main. memory::note_use copies a pipeline name only when it is not in Stats::uses yet.

Neither change alters any answer. The gain is unmeasured in a game run, but it removes per-draw work done under global locks.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156972745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#issuecomment-7156972745). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:23:46Z. --- <!-- victory-triage v1 head=bc51d6f65eaed28e61d9e91d55f3a5cdf714fdf2 verdict=merge-candidate at=2026-11-26T01:20:17Z --> Automated triage for the maintainers. **Merge candidate (re-checked on `bc51d6f`).** This push is a rebase, and the code matches what was reviewed before. In `resource::alias_source` (`crates/victory-gpu/src/resource.rs`), the cheap tests come first: another resource, GPU-written, with a different made host texture. The placed texture's layout (`bytes`/`texture_layout`) is built only when such a candidate exists. The result is still the first matching candidate in the same order, and `None` in the same cases as `main`. `memory::note_use` copies a pipeline name only when it is not in `Stats::uses` yet. Neither change alters any answer. The gain is unmeasured in a game run, but it removes per-draw work done under global locks. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
KainanP commented 2026-11-26 15:02:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T14:50:05Z.


Measured with a per-call list benchmark on main 63bcca4, with this PR merged on top (RTX 4060 Laptop, release build, median of 7 interleaved runs; method and full table in https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7195391455):

  • resource::alias_source for a texture with nothing else at its address: 120 → 14 ns
  • indexed draw reading six textures through a table: 2713 → 2046 ns
  • the same draws recorded by 5 threads at once: 10526 → 6664 ns per draw per thread

#3238 makes the same alias_source change and gets the same number. It also adds a linear-scan refreshed set, which costs more over a long list (see the linked comment), so this version looks like the one to take.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195397477 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#issuecomment-7195397477). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T14:50:05Z. --- Measured with a per-call list benchmark on main 63bcca4, with this PR merged on top (RTX 4060 Laptop, release build, median of 7 interleaved runs; method and full table in https://github.com/Marvisak/VIctory/issues/2586#issuecomment-7195391455): - `resource::alias_source` for a texture with nothing else at its address: 120 → 14 ns - indexed draw reading six textures through a table: 2713 → 2046 ns - the same draws recorded by 5 threads at once: 10526 → 6664 ns per draw per thread #3238 makes the same `alias_source` change and gets the same number. It also adds a linear-scan refreshed set, which costs more over a long list (see the linked comment), so this version looks like the one to take. _AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this comment._
fuzeofficlal commented 2026-11-26 15:04:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:04:42Z.

Review: APPROVED


Reviewed crates/victory-gpu/src/memory.rs and crates/victory-gpu/src/resource.rs at bc51d6f6 merged onto origin/main (63bcca43) and verified on RTX 5090 and WARP (VICTORY_D3D12_WARP=1) with VICTORY_D3D12_DEBUG=1.

Code & equivalence audit

  • resource::alias_source (resource.rs:1792-1822): purely reorders predicates with no cross-draw caching (so no invalidation hazards). Filtering r != placed, a.desc.flags & WRITTEN != 0, and distinct made(a)/made(b) Arcs first (resource.rs:1808-1819), then written.peek()? (resource.rs:1819) before computing bytes(&b.desc)? (resource.rs:1820) and written.find(...) (resource.rs:1821), preserves exact return values and match order in every case while skipping texture_layout builds under TEXTURES_AT when no writable alias exists. made(a) drops its lock before made(b) locks, so there is no nested locking.
  • memory::note_use (memory.rs:285-292): checks s.uses.get_mut(pipeline) (memory.rs:286) first and only allocates pipeline.to_owned() on first insertion per frame.
  • Merge note: expect a small textual conflict with open #3245 in alias_source (both are semantically composable).

Verification

  • cargo run -p xtask -- policy: 191 files ok.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean.
  • memory:: resource:: draw:: texture:: with VICTORY_D3D12_DEBUG=1: 47/47 passed on RTX 5090 (skipping the pre-existing NVIDIA 1M-cap lists_share_a_table_and_copies_keep_their_views) and 48/48 passed on WARP (--features diagnostics, zero skips), plus a repeated note_use counting check.
<!-- greyfinch-sync:Marvisak/VIctory:review:6076419585 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#pullrequestreview-6076419585). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T15:04:42Z. **Review:** APPROVED --- Reviewed `crates/victory-gpu/src/memory.rs` and `crates/victory-gpu/src/resource.rs` at `bc51d6f6` merged onto `origin/main` (`63bcca43`) and verified on RTX 5090 and WARP (`VICTORY_D3D12_WARP=1`) with `VICTORY_D3D12_DEBUG=1`. ### Code & equivalence audit - **`resource::alias_source` (`resource.rs:1792-1822`)**: purely reorders predicates with no cross-draw caching (so no invalidation hazards). Filtering `r != placed`, `a.desc.flags & WRITTEN != 0`, and distinct `made(a)`/`made(b)` `Arc`s first (`resource.rs:1808-1819`), then `written.peek()?` (`resource.rs:1819`) before computing `bytes(&b.desc)?` (`resource.rs:1820`) and `written.find(...)` (`resource.rs:1821`), preserves exact return values and match order in every case while skipping `texture_layout` builds under `TEXTURES_AT` when no writable alias exists. `made(a)` drops its lock before `made(b)` locks, so there is no nested locking. - **`memory::note_use` (`memory.rs:285-292`)**: checks `s.uses.get_mut(pipeline)` (`memory.rs:286`) first and only allocates `pipeline.to_owned()` on first insertion per frame. - Merge note: expect a small textual conflict with open `#3245` in `alias_source` (both are semantically composable). ### Verification - `cargo run -p xtask -- policy`: 191 files ok. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean. - `memory:: resource:: draw:: texture::` with `VICTORY_D3D12_DEBUG=1`: **47/47 passed** on RTX 5090 (skipping the pre-existing NVIDIA 1M-cap `lists_share_a_table_and_copies_keep_their_views`) and **48/48 passed** on WARP (`--features diagnostics`, zero skips), plus a repeated `note_use` counting check.
Dukestar69 commented 2026-11-26 23:09:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:09:57Z.

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Avoiding redundant texture layout recomputations and name copies per draw when unchanged cleanly reduces per-draw CPU overhead.
  • cargo test -p victory-gpu --lib resource:: -- --test-threads=1: all passed.
  • 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6081364849 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1978#pullrequestreview-6081364849). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T23:09:57Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Avoiding redundant texture layout recomputations and name copies per draw when unchanged cleanly reduces per-draw CPU overhead. - `cargo test -p victory-gpu --lib resource:: -- --test-threads=1`: all passed. - `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).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1978:upstream-pr/1978'
git switch 'upstream-pr/1978'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1978'
git switch 'upstream-pr/1978'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1978'
git switch 'upstream-pr/1978'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1978'
git switch 'main'
git merge --squash 'upstream-pr/1978'
git switch 'main'
git merge --ff-only 'upstream-pr/1978'
git switch 'main'
git merge 'upstream-pr/1978'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1976
No description provided.