GPU, Formats: lock-free resource::current fast path, zero-alloc memory_key, zero-COM shared_texture stat, and cached ID3D12Device10 #2210

Closed
RVZO6 wants to merge 1 commit from upstream-pr/2212 into main
RVZO6 commented 2026-11-25 08:00:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T08:00:14Z.


Per-draw/dispatch texture validation and shared-texture registration currently hit several avoidable CPU bottlenecks:

  1. resource::current() acquires the global MEMORY mutex and hashes/looks up the texture's memory key on every draw/view check, even though the vast majority of textures are never replaced.
  2. resource::memory_key() constructs a full victory_formats::texture::Texture layout (allocating mip/subresource tables) only to validate swizzle parameters.
  3. shared_texture() issues a GetResourceAllocationInfo COM call while holding the global MEMORY mutex even though t.bytes is already stored.
  4. Host::make_texture() queries ID3D12Device10 via cast() on every texture creation instead of caching it once on Host.

Claimed on #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155570873).

The change

  • crates/victory-formats/src/texture.rs:
    • Extract shared Layout::validate_desc and Texture::validate_swizzle validation helpers (avoiding full layout/subresource allocation) and add exhaustive equivalence test validate_swizzle_matches_texture_new.
  • crates/victory-gpu/src/resource.rs:
    • Add a monotonic replaced: AtomicBool flag on HostTexture, set with Release ordering whenever a live MEMORY entry is replaced in shared_texture(). resource::current() checks replaced.load(Acquire) first and returns true lock-free on the common unreplaced path, falling back to MEMORY once replaced (preserving exact semantics if the replacement later drops).
    • Use Texture::validate_swizzle() in resource::memory_key() instead of building a full Texture layout.
    • Replace the GetResourceAllocationInfo COM call under the MEMORY lock in shared_texture() with t.bytes.
    • Add tests memory_key_matches_texture_layout and replaced_flag_fast_path_and_fallback_state_machine.
  • crates/victory-gpu/src/host.rs:
    • Cache device10: Option<ID3D12Device10> once on Host in create() and reuse it in make_texture().

Not a duplicate of

No open PR or CLAIMS.md entry adds the lock-free replaced fast path in resource::current(), extracts Texture::validate_swizzle() for memory_key(), removes GetResourceAllocationInfo under the MEMORY lock, or caches ID3D12Device10 on Host. (#2187 addresses readable-texture sharing policy for shader-denied textures and is orthogonal.)

Tested

  • Fork windows-latest MSVC + Windows WARP SM 6.6 CI run 45570823602 (Clippy clean, Clippy, diagnostics build clean, Tests: 731 passed; 0 failed; 10 ignored, victory-formats: 39 passed; 0 failed; 5 ignored, victory-gpu: 153 passed; 0 failed; 2 ignored + 1 passed, xtask: 6 passed; 0 failed):
    • texture::tests::validate_swizzle_matches_texture_new ... ok
    • resource::tests::memory_key_matches_texture_layout ... ok
    • resource::tests::replaced_flag_fast_path_and_fallback_state_machine ... ok

Not run: the title; any hardware GPU. The title was not used in these tests.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599931755 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2212). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T08:00:14Z. --- Per-draw/dispatch texture validation and shared-texture registration currently hit several avoidable CPU bottlenecks: 1. `resource::current()` acquires the global `MEMORY` mutex and hashes/looks up the texture's memory key on every draw/view check, even though the vast majority of textures are never replaced. 2. `resource::memory_key()` constructs a full `victory_formats::texture::Texture` layout (allocating mip/subresource tables) only to validate swizzle parameters. 3. `shared_texture()` issues a `GetResourceAllocationInfo` COM call while holding the global `MEMORY` mutex even though `t.bytes` is already stored. 4. `Host::make_texture()` queries `ID3D12Device10` via `cast()` on every texture creation instead of caching it once on `Host`. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155570873`). ## The change - `crates/victory-formats/src/texture.rs`: - Extract shared `Layout::validate_desc` and `Texture::validate_swizzle` validation helpers (avoiding full layout/subresource allocation) and add exhaustive equivalence test `validate_swizzle_matches_texture_new`. - `crates/victory-gpu/src/resource.rs`: - Add a monotonic `replaced: AtomicBool` flag on `HostTexture`, set with `Release` ordering whenever a live `MEMORY` entry is replaced in `shared_texture()`. `resource::current()` checks `replaced.load(Acquire)` first and returns `true` lock-free on the common unreplaced path, falling back to `MEMORY` once replaced (preserving exact semantics if the replacement later drops). - Use `Texture::validate_swizzle()` in `resource::memory_key()` instead of building a full `Texture` layout. - Replace the `GetResourceAllocationInfo` COM call under the `MEMORY` lock in `shared_texture()` with `t.bytes`. - Add tests `memory_key_matches_texture_layout` and `replaced_flag_fast_path_and_fallback_state_machine`. - `crates/victory-gpu/src/host.rs`: - Cache `device10: Option<ID3D12Device10>` once on `Host` in `create()` and reuse it in `make_texture()`. ## Not a duplicate of No open PR or `CLAIMS.md` entry adds the lock-free `replaced` fast path in `resource::current()`, extracts `Texture::validate_swizzle()` for `memory_key()`, removes `GetResourceAllocationInfo` under the `MEMORY` lock, or caches `ID3D12Device10` on `Host`. (`#2187` addresses readable-texture sharing policy for shader-denied textures and is orthogonal.) ## Tested - Fork `windows-latest` MSVC + Windows WARP SM 6.6 CI run [`45570823602`](https://github.com/RVZO6/VIctory/actions/runs/45570823602) (`Clippy` clean, `Clippy, diagnostics build` clean, `Tests`: **`731 passed; 0 failed; 10 ignored`**, `victory-formats`: **`39 passed; 0 failed; 5 ignored`**, `victory-gpu`: **`153 passed; 0 failed; 2 ignored`** + `1 passed`, `xtask`: **`6 passed; 0 failed`**): - `texture::tests::validate_swizzle_matches_texture_new ... ok` - `resource::tests::memory_key_matches_texture_layout ... ok` - `resource::tests::replaced_flag_fast_path_and_fallback_state_machine ... ok` **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
DenRakEiw commented 2026-11-25 08:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:03:26Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib resource::tests:: — 12 passed, 0 failed on RTX 5090
  • cargo clippy -p victory-gpu -p victory-formats --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean lock-free resource::current fast path, zero-alloc memory_key, zero-COM shared_texture stat, and cached ID3D12Device10. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053840206 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2212#pullrequestreview-6053840206). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:03:26Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib resource::tests::` — **12 passed, 0 failed** on RTX 5090 - `cargo clippy -p victory-gpu -p victory-formats --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean lock-free `resource::current` fast path, zero-alloc `memory_key`, zero-COM `shared_texture` stat, and cached `ID3D12Device10`. Looks great. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 09:05:44 +00:00 (Migrated from github.com)

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

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-formats --locked.

39 passed / 0 failed. resource::current lock-free fast path, zero-alloc... — lock-free resource lookup; mixed gpu+formats, formats side green (39 passed / 5 ignored).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054007525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2212#pullrequestreview-6054007525). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:17:48Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-formats --locked`. 39 passed / 0 failed. resource::current lock-free fast path, zero-alloc... — lock-free resource lookup; mixed gpu+formats, formats side green (39 passed / 5 ignored).
Marvisak commented 2026-11-25 14:07:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:29:18Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163848627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2212#issuecomment-7163848627). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:29:18Z. --- <!-- victory-triage v1 head=a3559bf0e6e96e7cef3f24adabe5c0d4a534d496 verdict=needs-rebase at=2026-11-25T16:14:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/resource.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 18:01:52 +00:00
RVZO6 commented 2026-11-25 18:02:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T17:13:54Z.


Closing to keep the queue clean: resource.rs moved significantly on 13f91ca (69d1e8e, 11e9a54, 56f75f8) and I do not have a title run to supply the GPU/CPU profile triage asked for.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169199561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2212#issuecomment-7169199561). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:13:54Z. --- Closing to keep the queue clean: `resource.rs` moved significantly on `13f91ca` (`69d1e8e`, `11e9a54`, `56f75f8`) and I do not have a title run to supply the GPU/CPU profile triage asked for.

Pull request closed

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!2210
No description provided.