fix(gpu): skip converting twin copy routes when depth converter is unavailable #3360

Open
reeledMarek wants to merge 1 commit from upstream-pr/3360 into main
reeledMarek commented 2026-11-26 20:25:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T20:25:43Z.


Summary

  • When a depth twin has routes requiring 16-bit <-> 32-bit float conversion (r.depth.is_some()) and converter() returns None, Twin::copy previously skipped the compute conversion pass but still ran the second CopyTextureRegion pass from the unwritten scratch offset (r.depth or r.twin) into the destination texture, corrupting it with uninitialized scratch bytes.
  • Resolves the converter before transitioning resources or recording copies (via a testable copy_with helper), skipping routes that require conversion when no converter is available and returning false early without transitions or incrementing COPIES if no active routes remain.
  • Adds regression test copy_skips_converting_routes_when_converter_is_missing.

Verification

  • cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked
<!-- greyfinch-sync:Marvisak/VIctory:issue:5516695640 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T20:25:43Z. --- ### Summary - When a depth twin has routes requiring 16-bit <-> 32-bit float conversion (`r.depth.is_some()`) and `converter()` returns `None`, `Twin::copy` previously skipped the compute conversion pass but still ran the second `CopyTextureRegion` pass from the unwritten scratch offset (`r.depth` or `r.twin`) into the destination texture, corrupting it with uninitialized scratch bytes. - Resolves the converter before transitioning resources or recording copies (via a testable `copy_with` helper), skipping routes that require conversion when no converter is available and returning `false` early without transitions or incrementing `COPIES` if no active routes remain. - Adds regression test `copy_skips_converting_routes_when_converter_is_missing`. ### Verification - `cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `cargo test -p xtask --locked`
Dukestar69 commented 2026-11-26 20:28:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:28:07Z.

Review: APPROVED


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

  • Filtering out converting routes (and their plane barriers) when converter() is unavailable avoids copying unconverted scratch bytes into the destination texture or emitting unnecessary transitions.
  • cargo test -p victory-gpu --lib twin:: -- --test-threads=1: 3 passed, 0 failed (including copy_skips_converting_routes_when_converter_is_missing).
  • 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:6080158381 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360#pullrequestreview-6080158381). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T20:28:07Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Filtering out converting routes (and their plane barriers) when `converter()` is unavailable avoids copying unconverted scratch bytes into the destination texture or emitting unnecessary transitions. - `cargo test -p victory-gpu --lib twin:: -- --test-threads=1`: 3 passed, 0 failed (including `copy_skips_converting_routes_when_converter_is_missing`). - `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).
passerbyyhx commented 2026-11-26 21:34:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T21:34:54Z.


I exercised the mixed route when the depth converter returns None on Windows D3D12, using an RTX 4090 Laptop and Microsoft WARP. The 4×2 fixture creates the resource through the production format mapping. Console formats 118/119/120 all produced an R32 depth footprint (DXGI 39) requiring conversion from the R16 twin and an R8 stencil footprint (DXGI 60) that can copy directly.

On 66ea2630 each adapter passed 12 readback cases: three formats × two shader-resource flag settings × both copy directions. Stencil transferred, both depth surfaces retained their respective initial bytes, and each case checked all four plane payloads before and after queue completion. The fixture seeded scratch with 0xA5.

On parent 63bcca43 with only the converter-injection seam, both adapters transferred stencil but overwrote destination depth with 0xA5. This reproduced for both directions and both flag settings on format 118 (eight failing cases total). Parent readbacks for 119/120 were not needed to establish that control. This is an injected converter-unavailable condition with one mip, one slice and one sample.

Portable head fixture.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203863100 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360#issuecomment-7203863100). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-26T21:34:54Z. --- I exercised the mixed route when the depth converter returns `None` on Windows D3D12, using an RTX 4090 Laptop and Microsoft WARP. The 4×2 fixture creates the resource through the production format mapping. Console formats 118/119/120 all produced an R32 depth footprint (DXGI 39) requiring conversion from the R16 twin and an R8 stencil footprint (DXGI 60) that can copy directly. On `66ea2630` each adapter passed 12 readback cases: three formats × two shader-resource flag settings × both copy directions. Stencil transferred, both depth surfaces retained their respective initial bytes, and each case checked all four plane payloads before and after queue completion. The fixture seeded scratch with `0xA5`. On parent `63bcca43` with only the converter-injection seam, both adapters transferred stencil but overwrote destination depth with `0xA5`. This reproduced for both directions and both flag settings on format 118 (eight failing cases total). Parent readbacks for 119/120 were not needed to establish that control. This is an injected converter-unavailable condition with one mip, one slice and one sample. [Portable head fixture](https://github.com/passerbyyhx/VIctory/commit/eacb5e1db00fe98c5aeac17c65220a63f6fbcdfc). AI-assisted with Codex.
passerbyyhx commented 2026-11-26 22:01:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T22:01:03Z.


I followed up on the mixed-copy readback with both source and destination starting outside their copy states. Host depth started in DEPTH_WRITE and both twin planes in UNORDERED_ACCESS. All runs required a live D3D12 debug info queue.

On the updated fixture, each adapter (RTX 4090 Laptop and Microsoft WARP) passed all 12 combinations of console format 118/119/120, shader-resource flag and copy direction. Every copy emitted the two expected texture transitions, for the stencil twin and host texture. The depth twin stayed in UAV state. After the fence, stencil matched the source byte-for-byte, both depth payloads retained their seeds, and the copy counter advanced once. The debug queue had zero warnings and errors at list close and after GPU completion in these cases. The earlier host-initialization diagnostic was drained separately.

With the same fixture source and converter-injection seam on parent 63bcca43c6a00a758510398fa43096ce7e4f7df0, all eight format-118 controls again transferred stencil and overwrote destination depth with scratch 0xA5. The parent requested a third transition on the depth twin. Coverage is for Twin::copy_with, one mip and injected converter absence. The wrapper state machines in twin::route and HostList::prelude were outside this run.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204276332 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360#issuecomment-7204276332). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-26T22:01:03Z. --- I followed up on the mixed-copy readback with both source and destination starting outside their copy states. Host depth started in `DEPTH_WRITE` and both twin planes in `UNORDERED_ACCESS`. All runs required a live D3D12 debug info queue. On the [updated fixture](https://github.com/passerbyyhx/VIctory/commit/07e1aca5aaf94c90495a91551bcb496d3ac7f9bd), each adapter (RTX 4090 Laptop and Microsoft WARP) passed all 12 combinations of console format 118/119/120, shader-resource flag and copy direction. Every copy emitted the two expected texture transitions, for the stencil twin and host texture. The depth twin stayed in UAV state. After the fence, stencil matched the source byte-for-byte, both depth payloads retained their seeds, and the copy counter advanced once. The debug queue had zero warnings and errors at list close and after GPU completion in these cases. The earlier host-initialization diagnostic was drained separately. With the same fixture source and converter-injection seam on parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`, all eight format-118 controls again transferred stencil and overwrote destination depth with scratch `0xA5`. The parent requested a third transition on the depth twin. Coverage is for `Twin::copy_with`, one mip and injected converter absence. The wrapper state machines in `twin::route` and `HostList::prelude` were outside this run. AI-assisted with Codex.
passerbyyhx commented 2026-11-26 22:33:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T22:33:05Z.


I ran the missing-depth-converter case through both callers of Twin::copy at 66ea26305170b091bf05e27f770f8f310329066a. The same-list twin::route and the submission-time HostList::prelude each copied the two stencil mips in both directions and preserved the independently seeded host and twin depth bytes. The RTX 4090 Laptop (621.14) and Microsoft WARP returned the same data.

Each case used a single-sample format-118 texture with 4×2 and 2×1 mips. Host stencil started with 41 42 43 44 45 46 47 48 and 61 62. Twin stencil started with c1 c2 c3 c4 c5 c6 c7 c8 and e1 e2. We checked all eight plane/mip payloads before and after the copy. The route cases incremented the copy counter while recording. The prelude cases first incremented it at submission. Every case finished with exactly one copy and one injected converter miss.

The submission prelude restored the host depth texture to DEPTH_WRITE and both twin textures to UAV. The depth twin had no copy transition. Both callers left the list’s rebind flag clear. A compute pipeline and root UAV bound before routing still produced 0xc0decafe after routing without a rebind.

Each adapter had an active D3D12 info queue. All 24 recording and fenced-completion checks per adapter reported zero warnings or errors after host initialization. Both logs captured the existing sampler-heap diagnostic during initialization. This run seeded the authoritative side explicitly, used one array slice, and injected converter absence at lookup. The earlier parent comparison used the single-mip copy fixture. Earlier parent and head comparison

Synthetic test source

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204779180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360#issuecomment-7204779180). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-26T22:33:05Z. --- I ran the missing-depth-converter case through both callers of `Twin::copy` at `66ea26305170b091bf05e27f770f8f310329066a`. The same-list `twin::route` and the submission-time `HostList::prelude` each copied the two stencil mips in both directions and preserved the independently seeded host and twin depth bytes. The RTX 4090 Laptop (621.14) and Microsoft WARP returned the same data. Each case used a single-sample format-118 texture with 4×2 and 2×1 mips. Host stencil started with `41 42 43 44 45 46 47 48` and `61 62`. Twin stencil started with `c1 c2 c3 c4 c5 c6 c7 c8` and `e1 e2`. We checked all eight plane/mip payloads before and after the copy. The route cases incremented the copy counter while recording. The prelude cases first incremented it at submission. Every case finished with exactly one copy and one injected converter miss. The submission prelude restored the host depth texture to `DEPTH_WRITE` and both twin textures to UAV. The depth twin had no copy transition. Both callers left the list’s rebind flag clear. A compute pipeline and root UAV bound before routing still produced `0xc0decafe` after routing without a rebind. Each adapter had an active D3D12 info queue. All 24 recording and fenced-completion checks per adapter reported zero warnings or errors after host initialization. Both logs captured the existing sampler-heap diagnostic during initialization. This run seeded the authoritative side explicitly, used one array slice, and injected converter absence at lookup. The earlier parent comparison used the single-mip copy fixture. [Earlier parent and head comparison](https://github.com/Marvisak/VIctory/pull/3360#issuecomment-7204276332) [Synthetic test source](https://github.com/passerbyyhx/VIctory/commit/25433a44d241dee413e1e64708c33a2a66c8c218) AI-assisted with Codex.
fuzeofficlal commented 2026-11-26 23:39:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:39:52Z.

Review: APPROVED


Looks good — cleanly prevents unconverted/mismatched scratch copies when the depth converter pipeline is unavailable while preserving direct non-converting planes.

Checked crates/victory-gpu/src/twin.rs:409-493 alongside its callers in twin.rs:326 and host.rs:1961-1976:

  • When all routes require conversion and get_converter() returns None, copy_with returns false early without calling mv, recording transitions/copies, modifying scratch (stays in COMMON), or incrementing COPIES.
  • For mixed-route twins (e.g. console 16-bit depth + 8-bit stencil on R32G8X24_TYPELESS, where plane 0 converts and plane 1 is a direct copy), active skips the converting plane (so mv and prelude reverse barriers in host.rs:1961-1976 stay balanced), transitions scratch COPY_DEST -> COPY_SOURCE -> COMMON without compute dispatch, copies the stencil plane cleanly, and returns false so callers do not trigger an unnecessary compute rebind.

Verification (66ea2630):

  • cargo xtask policy and cargo clippy -p victory-gpu (default and --features diagnostics, --tests -- -D warnings): passed.
  • twin::tests:: (3/3): passed on both hardware GPU and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1, zero Debug Layer errors).
  • Live mixed-route D16S8 (R32G8X24_TYPELESS, plane 0 R16_TYPELESS converting + plane 1 R8_TYPELESS direct) probe calling copy_with(..., to_depth = true, || None): confirmed on both hardware GPU and WARP (VICTORY_D3D12_DEBUG=1) that plane 0 is never transitioned, stencil bytes (0x5a) copy accurately into depth subresource 1, converted == false, and zero Debug Layer errors occur.
<!-- greyfinch-sync:Marvisak/VIctory:review:6081563029 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3360#pullrequestreview-6081563029). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:39:52Z. **Review:** APPROVED --- Looks good — cleanly prevents unconverted/mismatched scratch copies when the depth converter pipeline is unavailable while preserving direct non-converting planes. Checked `crates/victory-gpu/src/twin.rs:409-493` alongside its callers in `twin.rs:326` and `host.rs:1961-1976`: - When all routes require conversion and `get_converter()` returns `None`, `copy_with` returns `false` early without calling `mv`, recording transitions/copies, modifying `scratch` (stays in `COMMON`), or incrementing `COPIES`. - For mixed-route twins (e.g. console 16-bit depth + 8-bit stencil on `R32G8X24_TYPELESS`, where plane 0 converts and plane 1 is a direct copy), `active` skips the converting plane (so `mv` and prelude reverse barriers in `host.rs:1961-1976` stay balanced), transitions `scratch` `COPY_DEST -> COPY_SOURCE -> COMMON` without compute dispatch, copies the stencil plane cleanly, and returns `false` so callers do not trigger an unnecessary compute rebind. Verification (`66ea2630`): - `cargo xtask policy` and `cargo clippy -p victory-gpu` (default and `--features diagnostics`, `--tests -- -D warnings`): passed. - `twin::tests::` (3/3): passed on both hardware GPU and WARP (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`, zero Debug Layer errors). - Live mixed-route `D16S8` (`R32G8X24_TYPELESS`, plane 0 `R16_TYPELESS` converting + plane 1 `R8_TYPELESS` direct) probe calling `copy_with(..., to_depth = true, || None)`: confirmed on both hardware GPU and WARP (`VICTORY_D3D12_DEBUG=1`) that plane 0 is never transitioned, stencil bytes (`0x5a`) copy accurately into depth subresource 1, `converted == false`, and zero Debug Layer errors occur.
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/3360:upstream-pr/3360'
git switch 'upstream-pr/3360'

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/3360'
git switch 'upstream-pr/3360'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3360'
git switch 'upstream-pr/3360'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3360'
git switch 'main'
git merge --squash 'upstream-pr/3360'
git switch 'main'
git merge --ff-only 'upstream-pr/3360'
git switch 'main'
git merge 'upstream-pr/3360'
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!3360
No description provided.