GPU: copy depth twins directly instead of through a scratch #2737

Open
github-bot wants to merge 1 commit from github-bot/gh-2737 into main AGit
Owner

@⁠Therecalloftheonion on GitHub · 2026-11-25 19:23 UTC · original
Therecalloftheonion:pr/depth-twin-direct → main · +271 −43 · 1 files · 1 commits · open

What

Subresources of one format family copy straight between a depth texture and its writable twin instead of through a scratch buffer. D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped. The scratch remains for converted 16-bit planes and is created only when a route needs conversion.

Why

GPU memory: a twin otherwise allocates a full scratch buffer on top of the twin texture. A D32 twin now takes one texture instead of two, and a depth-stencil texture's stencil plane (same format family) no longer goes through the scratch.

Testing

  • New hardware test a_d32_twin_copies_directly_and_takes_no_scratch: creates a D32 depth texture and its twin, uploads known texels, performs the real depth-to-color copy, reads it back, checks every texel, and checks the device was not removed. Passes on the RX 6700 XT.
  • cargo test -p victory-gpu --lib: 196 passed.

Not tested on NVIDIA; the direct copy relies on DXGI format-family compatibility, as the D3D12 copy rules allow.

**@⁠Therecalloftheonion** on GitHub · 2026-11-25 19:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737) `Therecalloftheonion:pr/depth-twin-direct` → `main` · +271 −43 · 1 files · 1 commits · open ## What Subresources of one format family copy straight between a depth texture and its writable twin instead of through a scratch buffer. D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped. The scratch remains for converted 16-bit planes and is created only when a route needs conversion. ## Why GPU memory: a twin otherwise allocates a full scratch buffer on top of the twin texture. A D32 twin now takes one texture instead of two, and a depth-stencil texture's stencil plane (same format family) no longer goes through the scratch. ## Testing - New hardware test `a_d32_twin_copies_directly_and_takes_no_scratch`: creates a D32 depth texture and its twin, uploads known texels, performs the real depth-to-color copy, reads it back, checks every texel, and checks the device was not removed. Passes on the RX 6700 XT. - `cargo test -p victory-gpu --lib`: 196 passed. Not tested on NVIDIA; the direct copy relies on DXGI format-family compatibility, as the D3D12 copy rules allow.
A depth twin copied every subresource through a scratch buffer, so a D32 twin needed a full extra texture or two. Subresources of one format family now copy straight between the depth texture and the twin; the scratch is made only for converted 16-bit planes and only when one is needed. D32 twins now exist at all: the previous exact-format check rejected them, so shader writes to D32 depth were dropped.

Add a hardware test that copies a D32 depth texture into its twin, reads it back, and checks every texel and the device state. On the RX 6700 XT the copy is accepted and the texels match; WARP is not the only path exercised.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:05 +00:00
Author
Owner

@⁠passerbyyhx on GitHub · 2026-11-25 19:59 UTC · original

On a35eb773, twin::tests::a_d32_twin_copies_directly_and_takes_no_scratch passed on a GeForce RTX 4090 Laptop GPU (driver 621.14, Windows 11, Rust 1.98.1 MSVC). I ran the unmodified PR head first, then repeated the test with a diagnostic print after the final assertions to confirm it reached readback. The D3D12 device LUID resolved to the NVIDIA adapter. All 16 texels of the generated 4×4 D32 texture matched after the depth-to-color copy. The test recorded one direct copy and no scratch buffer. Both runs used the synthetic fixture and no game files.

cargo test --locked --offline -p victory-gpu --lib twin::tests::a_d32_twin_copies_directly_and_takes_no_scratch -- --exact --test-threads=1 --nocapture

Test run and summary assisted by Codex.

**@⁠passerbyyhx** on GitHub · 2026-11-25 19:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737#issuecomment-7173042099) On `a35eb773`, `twin::tests::a_d32_twin_copies_directly_and_takes_no_scratch` passed on a GeForce RTX 4090 Laptop GPU (driver 621.14, Windows 11, Rust 1.98.1 MSVC). I ran the unmodified PR head first, then repeated the test with a diagnostic print after the final assertions to confirm it reached readback. The D3D12 device LUID resolved to the NVIDIA adapter. All 16 texels of the generated 4×4 D32 texture matched after the depth-to-color copy. The test recorded one direct copy and no scratch buffer. Both runs used the synthetic fixture and no game files. `cargo test --locked --offline -p victory-gpu --lib twin::tests::a_d32_twin_copies_directly_and_takes_no_scratch -- --exact --test-threads=1 --nocapture` Test run and summary assisted by Codex.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:06 UTC · original

Good win: same-family subresources (D32's R32 plane, D24S8's pieces) now copy texture-to-texture with no scratch - a D32 twin drops a full texture of GPU memory. The scratch is only allocated when a route actually converts (at > 0), and the copy loop splits direct routes from converted ones cleanly. The 'whole subresource for depth-stencil' comment matches D3D12's restriction.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737#issuecomment-7173198091) Good win: same-family subresources (D32's R32 plane, D24S8's pieces) now copy texture-to-texture with no scratch - a D32 twin drops a full texture of GPU memory. The scratch is only allocated when a route actually converts (at > 0), and the copy loop splits direct routes from converted ones cleanly. The 'whole subresource for depth-stencil' comment matches D3D12's restriction.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:10 UTC · original

Reviewed and verified a35eb773 (merged cleanly onto main 13f91ca) on Windows 11 (RTX 5090 + WARP).

Code review

  • Relaxing same in twin.rs:173 to resource::family(df[d].Footprint.Format) == resource::family(td.Format) cleanly enables zero-scratch direct CopyTextureRegion (whole-subresource, multi-mip/array safe) for D32_FLOAT/R32_TYPELESS, D16_UNORM, and the R8_TYPELESS stencil plane of R32G8X24_TYPELESS, while keeping the smaller scratch + compute conversion only for the 16-bit converted depth plane (118..=120) and returning true for list.need_rebind() only when compute conversion runs.
  • Note on MSAA depth textures (synergy with #2173): #2737 does not guard dd.SampleDesc.Count > 1 before calling CreateCommittedResource with ALLOW_UNORDERED_ACCESS (which D3D12 rejects for multisampled resources). On the flip side, #2173 guards MSAA and typed D16/D32 but still allocates a scratch buffer for same-family copies. git merge-tree between #2737 and #2173 (as well as #485 and #559) is completely conflict-free, so the two compose cleanly.

Verification (Windows 11, RTX 5090 + WARP)

  • RTX 5090 (--features diagnostics): twin::tests 3/3 passed (including a_d32_twin_copies_directly_and_takes_no_scratch), draw::tests --test-threads=1 11/11 passed.
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics --lib -- --test-threads=1): 199 passed, 0 failed, 1 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default & --features diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737#issuecomment-7173280136) Reviewed and verified `a35eb773` (merged cleanly onto `main` `13f91ca`) on Windows 11 (RTX 5090 + WARP). ### Code review - Relaxing `same` in `twin.rs:173` to `resource::family(df[d].Footprint.Format) == resource::family(td.Format)` cleanly enables zero-scratch direct `CopyTextureRegion` (whole-subresource, multi-mip/array safe) for `D32_FLOAT`/`R32_TYPELESS`, `D16_UNORM`, and the `R8_TYPELESS` stencil plane of `R32G8X24_TYPELESS`, while keeping the smaller scratch + compute conversion only for the 16-bit converted depth plane (`118..=120`) and returning `true` for `list.need_rebind()` only when compute conversion runs. - **Note on MSAA depth textures (synergy with `#2173`)**: `#2737` does not guard `dd.SampleDesc.Count > 1` before calling `CreateCommittedResource` with `ALLOW_UNORDERED_ACCESS` (which D3D12 rejects for multisampled resources). On the flip side, `#2173` guards MSAA and typed D16/D32 but still allocates a scratch buffer for same-family copies. `git merge-tree` between `#2737` and `#2173` (as well as `#485` and `#559`) is completely conflict-free, so the two compose cleanly. ### Verification (Windows 11, RTX 5090 + WARP) - **RTX 5090 (`--features diagnostics`)**: `twin::tests` **3/3 passed** (including `a_d32_twin_copies_directly_and_takes_no_scratch`), `draw::tests --test-threads=1` **11/11 passed**. - **WARP (`VICTORY_D3D12_WARP=1`, `--features diagnostics --lib -- --test-threads=1`)**: **199 passed, 0 failed, 1 ignored**. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default & `--features diagnostics`): **0 warnings**; `cargo xtask policy`: **184 files ok**.
Author
Owner

@⁠passerbyyhx on GitHub · 2026-11-25 20:18 UTC · original

I ran the two branches together on a GeForce RTX 4090 Laptop GPU (driver 621.14). Merging #2173 at cdd11bd2 into a35eb773 gave tree 017a5f2d88135b5740feeac8dbb7989338b250ac without conflicts. The original D32 direct-copy and typed-depth tests both passed. A second run with test-only prints confirmed the adapter by LUID and recorded the readbacks.

  • Single-sample D32: all 16 texels matched after one direct copy, with no scratch buffer.
  • Typed depth round-trip at three sampled coordinates: D16 read 0.2500038 and wrote back 0xbfff. D32 read 0.25 and wrote back 0x3f400000 (0.75).
  • 4× MSAA: the request returned no twin and no writable view. The D3D12 debug info queue held zero messages immediately before and after the request.

Both synthetic fixtures ran with diagnostics in the same build. No game files were used. Test run and summary assisted by Codex.

**@⁠passerbyyhx** on GitHub · 2026-11-25 20:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737#issuecomment-7173468997) I ran the two branches together on a GeForce RTX 4090 Laptop GPU (driver 621.14). Merging #2173 at `cdd11bd2` into `a35eb773` gave tree `017a5f2d88135b5740feeac8dbb7989338b250ac` without conflicts. The original D32 direct-copy and typed-depth tests both passed. A second run with test-only prints confirmed the adapter by LUID and recorded the readbacks. - Single-sample D32: all 16 texels matched after one direct copy, with no scratch buffer. - Typed depth round-trip at three sampled coordinates: D16 read `0.2500038` and wrote back `0xbfff`. D32 read `0.25` and wrote back `0x3f400000` (`0.75`). - 4× MSAA: the request returned no twin and no writable view. The D3D12 debug info queue held zero messages immediately before and after the request. Both synthetic fixtures ran with diagnostics in the same build. No game files were used. Test run and summary assisted by Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:22 UTC · original

Automated triage for the maintainers.

This PR conflicts with the current main in crates/victory-gpu/src/twin.rs, which has changed since the PR's base. It will be reviewed once it is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2737#issuecomment-7177477695) <!-- victory-triage v1 head=a35eb773771d06fa13693e0ba87325964255ccc0 verdict=needs-rebase at=2026-11-25T23:22:35Z --> Automated triage for the maintainers. This PR conflicts with the current `main` in `crates/victory-gpu/src/twin.rs`, which has changed since the PR's base. It will be reviewed once it is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/twin.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2737/head:github-bot/gh-2737'
git switch 'github-bot/gh-2737'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2737'
git switch 'github-bot/gh-2737'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2737'
git switch 'github-bot/gh-2737'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2737'
git switch 'main'
git merge --squash 'github-bot/gh-2737'
git switch 'main'
git merge --ff-only 'github-bot/gh-2737'
git switch 'main'
git merge 'github-bot/gh-2737'
git push origin 'main'
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!2737
No description provided.