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

Closed
github-bot wants to merge 1 commit from gh-pr/2212/head into gh-pr/2212/base
Owner

@⁠RVZO6 on GitHub · 2026-11-25 08:00 UTC · original
RVZO6:rvzo/resource-fast-path → main · +470 −36 · 3 files · 1 commits · closed without merging

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)

**@⁠RVZO6** on GitHub · 2026-11-25 08:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2212) `RVZO6:rvzo/resource-fast-path` → `main` · +470 −36 · 3 files · 1 commits · closed without merging 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)
- Add a monotonic `replaced: AtomicBool` flag to `HostTexture`, set with
  Release ordering whenever a live `MEMORY` entry is replaced in
  `shared_texture()`, so `resource::current()` returns `true` lock-free
  without hashing or allocating on the common unreplaced path and falls
  back to `MEMORY` once replaced (preserving semantics if the replacement
  later drops).
- Extract shared `Layout::validate_desc` / `Texture::validate_swizzle`
  validation helpers in `victory-formats` and use them 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`.
- Cache `device10: Option<ID3D12Device10>` once on `Host` in `create()`
  and reuse it in `make_texture()`.
- Add exhaustive validation-equivalence tests for `validate_swizzle()` /
  `memory_key()` and state-machine tests for the `replaced` fast path and
  fallback.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:34 +00:00
github-bot closed this pull request 2026-11-26 04:58:34 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original · edited 2026-11-25 16:03 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2212#issuecomment-7163848627) · edited 2026-11-25 16:03 UTC <!-- 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)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:13 UTC · original

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.

**@⁠RVZO6** on GitHub · 2026-11-25 17:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2212#issuecomment-7169199561) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2212
No description provided.