GPU: upload the stencil plane with guest textures #2509

Open
github-bot wants to merge 2 commits from github-bot/gh-2509 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 15:03 UTC · original
andrewpozdnakov7-jpg:codex1/stencil-upload → main · +271 −14 · 2 files · 2 commits · open

A VIctory CopyResource of a CPU-populated depth/stencil texture uploads depth but leaves stencil zero. Stage every compatible plane and use native D3D12 copy footprints. Dirty-span offsets include the start of each guest plane, so a stencil-only CPU write can refresh stencil independently. The console D16S8 layout that needs float depth conversion retains its existing upload path. D3D12 format plane count

The same WARP test submits a normal VIctory CopyResource of a 2 × 2 R32G8X24_TYPELESS texture with two mips and two array slices. It reads both planes back after the copy and after writing one stencil byte in the source.

Revision Depth Stencil on first copy Last mip and slice after CPU write
67e8ae1401 + test All values match Zero Zero
e98af1d All values match 7, 11, 13, 17 / 19 / 23, 29, 31, 37 / 41 53

Six alternating WARP runs reproduced the failure on main and passed on the updated branch. The full serial GPU suite had 199 passes and one ignore with both D3D12 debug flag settings. Strict GPU Clippy in both modes and repository policy passed. The independent RTX 5070 run covers the earlier 88067ef head. AI-assisted. Synthetic data only. RTX 5070 result

Coordination claim

Please preserve the Git author when reapplying the change. If you fold the code or test into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 15:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509) `andrewpozdnakov7-jpg:codex1/stencil-upload` → `main` · +271 −14 · 2 files · 2 commits · open A VIctory CopyResource of a CPU-populated depth/stencil texture uploads depth but leaves stencil zero. Stage every compatible plane and use native D3D12 copy footprints. Dirty-span offsets include the start of each guest plane, so a stencil-only CPU write can refresh stencil independently. The console D16S8 layout that needs float depth conversion retains its existing upload path. [D3D12 format plane count](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_feature_data_format_info) The same WARP test submits a normal VIctory CopyResource of a 2 × 2 R32G8X24_TYPELESS texture with two mips and two array slices. It reads both planes back after the copy and after writing one stencil byte in the source. | Revision | Depth | Stencil on first copy | Last mip and slice after CPU write | | --- | --- | --- | --- | | 67e8ae1401df112248aed36d0024483181b718b7 + test | All values match | Zero | Zero | | e98af1d | All values match | 7, 11, 13, 17 / 19 / 23, 29, 31, 37 / 41 | 53 | Six alternating WARP runs reproduced the failure on main and passed on the updated branch. The full serial GPU suite had 199 passes and one ignore with both D3D12 debug flag settings. Strict GPU Clippy in both modes and repository policy passed. The independent RTX 5070 run covers the earlier 88067ef head. AI-assisted. Synthetic data only. [RTX 5070 result](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2509) [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please preserve the Git author when reapplying the change. If you fold the code or test into another commit, please add this trailer. Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:49 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:29 UTC · original

Verification (Windows 11, WARP/CPU only) — head 88067ef31fd4b23c5a3c9ffbc32b65bc8d834e23

Tested: the PR head, which is origin/main 940d32f plus the PR commits (merge-base 940d32f; clean merge, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. VICTORY_D3D12_WARP=1 with --features diagnostics (the switch is only honoured with that feature, otherwise host() would take the default adapter), so the host device is WARP; no physical GPU involved.

command result
cargo test -p victory-gpu --locked --features diagnostics --lib copy_resource_uploads_depth -- --test-threads=1 1 passed, 0 failed
same test with texture.rs restored to origin/main (test kept) fails: depth plane passes, stencil plane left: [0, 0, 0, 0], right: [7, 11, 13, 17]
cargo test -p victory-gpu --locked --features diagnostics --lib -- --test-threads=1 147 passed, 0 failed, 2 ignored
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (also with --features diagnostics) clean
cargo xtask policy asset policy: 182 files ok

So the test exercises the bug: on main only plane 0 is detiled and the stencil plane reads back zero; with the PR both planes match the guest bytes.

Diff read: the subresource index is split as D3D12 orders it (mips, then array slices, then planes) via subresources_per_plane, each plane gets its own tiled[offset..offset+size] slice and its own detile, and the XOR-swizzle refusal now checks every plane. For single-plane textures planes[0].offset is 0 and the slice is the whole layout, so that path is unchanged; 3D textures keep MipLevels per plane. No findings. Caveats: the new test returns early if host() yields no device, so it only means something where a D3D12 device exists (WARP here); it covers one mip, one slice, 2x2, and not mip chains or array depth-stencil, which the index math also handles but nothing tests. WARP only; real-GPU behaviour untested.

AI use: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 15:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#issuecomment-7166929537) **Verification (Windows 11, WARP/CPU only) — head `88067ef31fd4b23c5a3c9ffbc32b65bc8d834e23`** Tested: the PR head, which is `origin/main` `940d32f` plus the PR commits (merge-base `940d32f`; clean merge, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. `VICTORY_D3D12_WARP=1` with `--features diagnostics` (the switch is only honoured with that feature, otherwise `host()` would take the default adapter), so the host device is WARP; no physical GPU involved. | command | result | |---|---| | `cargo test -p victory-gpu --locked --features diagnostics --lib copy_resource_uploads_depth -- --test-threads=1` | 1 passed, 0 failed | | same test with `texture.rs` restored to `origin/main` (test kept) | **fails**: depth plane passes, `stencil plane` `left: [0, 0, 0, 0]`, `right: [7, 11, 13, 17]` | | `cargo test -p victory-gpu --locked --features diagnostics --lib -- --test-threads=1` | 147 passed, 0 failed, 2 ignored | | `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (also with `--features diagnostics`) | clean | | `cargo xtask policy` | `asset policy: 182 files ok` | So the test exercises the bug: on main only plane 0 is detiled and the stencil plane reads back zero; with the PR both planes match the guest bytes. Diff read: the subresource index is split as D3D12 orders it (mips, then array slices, then planes) via `subresources_per_plane`, each plane gets its own `tiled[offset..offset+size]` slice and its own `detile`, and the XOR-swizzle refusal now checks every plane. For single-plane textures `planes[0].offset` is 0 and the slice is the whole layout, so that path is unchanged; 3D textures keep `MipLevels` per plane. No findings. Caveats: the new test returns early if `host()` yields no device, so it only means something where a D3D12 device exists (WARP here); it covers one mip, one slice, 2x2, and not mip chains or array depth-stencil, which the index math also handles but nothing tests. WARP only; real-GPU behaviour untested. AI use: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-25 16:06 UTC · original

Machine: RTX 5070, driver 621.24, Windows 11, Rust 1.98.1 (MSVC).
Head: 88067ef (base 940d32f). Command: cargo test -p victory-gpu --locked --features diagnostics --lib copy_resource_uploads_depth -- --test-threads=1.

  • Hardware (RTX 5070): 1 passed. Same with VICTORY_D3D12_DEBUG=1: 1 passed.
  • VICTORY_D3D12_WARP=1: 1 passed.
  • Full victory-gpu lib suite on the head, hardware: 142 passed, 2 failed (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). On 940d32f: 141 passed, 2 failed, the same two. So +1 test, no new failure.
  • Heads-up: the PR no longer merges cleanly into current main 67e8ae1 (conflicts in crates/victory-gpu/src/resource.rs and crates/victory-gpu/src/texture.rs), so a rebase is needed.
  • Not run: negative control (patch removed), and the game.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-25 16:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#issuecomment-7167602971) Machine: RTX 5070, driver 621.24, Windows 11, Rust 1.98.1 (MSVC). Head: 88067ef (base 940d32f). Command: `cargo test -p victory-gpu --locked --features diagnostics --lib copy_resource_uploads_depth -- --test-threads=1`. - Hardware (RTX 5070): 1 passed. Same with `VICTORY_D3D12_DEBUG=1`: 1 passed. - `VICTORY_D3D12_WARP=1`: 1 passed. - Full victory-gpu lib suite on the head, hardware: 142 passed, 2 failed (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). On 940d32f: 141 passed, 2 failed, the same two. So +1 test, no new failure. - Heads-up: the PR no longer merges cleanly into current main 67e8ae1 (conflicts in crates/victory-gpu/src/resource.rs and crates/victory-gpu/src/texture.rs), so a rebase is needed. - Not run: negative control (patch removed), and the game. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:16 UTC · original · edited 2026-11-25 18:31 UTC

Automated triage for the maintainers.

texture::staging / Staging::detile in crates/victory-gpu/src/texture.rs now stage every plane the host format has (D3D12_FEATURE_FORMAT_INFO.PlaneCount), not only plane 0, so a CPU-written stencil plane is uploaded too. Each plane's dirty spans are offset by the start of that plane in the guest layout.

What I checked:

  • The subresource split follows D3D12's order (mip, then array slice, then plane).
  • Each plane detiles from its own slice of the guest layout (victory_formats::texture::Texture).
  • The XOR-swizzle refusal now checks every plane.
  • Single-plane textures and the console D16S8 case, where the host format does not match the layout's element size, keep the previous single-plane path.
  • refresh_now still uses layout.size, which now covers both planes.

The new test in resource.rs reads both planes back over two mips and two slices, then again after a stencil-only CPU write. The head merges cleanly into current main, and CI passes (check). Not covered: real-GPU depth-format differences in plane 0, which this PR does not change.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 16:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#issuecomment-7167738102) · edited 2026-11-25 18:31 UTC <!-- victory-triage v1 head=e98af1db633835b9695f786e0421df46afc3fdb1 verdict=merge-candidate at=2026-11-25T18:31:08Z --> Automated triage for the maintainers. `texture::staging` / `Staging::detile` in `crates/victory-gpu/src/texture.rs` now stage every plane the host format has (`D3D12_FEATURE_FORMAT_INFO.PlaneCount`), not only plane 0, so a CPU-written stencil plane is uploaded too. Each plane's dirty spans are offset by the start of that plane in the guest layout. What I checked: - The subresource split follows D3D12's order (mip, then array slice, then plane). - Each plane detiles from its own slice of the guest layout (`victory_formats::texture::Texture`). - The XOR-swizzle refusal now checks every plane. - Single-plane textures and the console D16S8 case, where the host format does not match the layout's element size, keep the previous single-plane path. - `refresh_now` still uses `layout.size`, which now covers both planes. The new test in `resource.rs` reads both planes back over two mips and two slices, then again after a stencil-only CPU write. The head merges cleanly into current `main`, and CI passes (`check`). Not covered: real-GPU depth-format differences in plane 0, which this PR does not change. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 16:41 UTC · original

Updated for 67e8ae1401 and kept the new selective upload path. The same WARP test now covers two mips, two array slices and a CPU write to stencil only. Main reads zero from stencil. The updated branch reads all expected depth and stencil values, including 53 after replacing 41 in the last stencil subresource. Six alternating A/B runs, serial GPU 199 passed and 1 ignored in both debug flag settings, strict GPU Clippy in both modes and repository policy. Thanks for the independent test of 88067ef.

Updated commit

If you fold the change or test into another commit, please preserve the Git author or add this trailer.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#issuecomment-7168382340) Updated for 67e8ae1401df112248aed36d0024483181b718b7 and kept the new selective upload path. The same WARP test now covers two mips, two array slices and a CPU write to stencil only. Main reads zero from stencil. The updated branch reads all expected depth and stencil values, including 53 after replacing 41 in the last stencil subresource. Six alternating A/B runs, serial GPU 199 passed and 1 ignored in both debug flag settings, strict GPU Clippy in both modes and repository policy. Thanks for the independent test of 88067ef. [Updated commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/e98af1db633835b9695f786e0421df46afc3fdb1) If you fold the change or test into another commit, please preserve the Git author or add this trailer. Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:18 UTC · original · approved these changes

Looks good. Verified merged onto main (63bcca43) on an RTX 5090 and Microsoft WARP under the D3D12 Debug Layer (VICTORY_D3D12_DEBUG=1):

  • Querying D3D12_FEATURE_FORMAT_INFO for PlaneCount, guarding multi-plane staging with matching_layout (preserving console D16S8's single-plane path), mapping D3D12 subresource indices in mip -> array slice -> plane order, and resizing/offsetting per-plane dirty spans cleanly handle depth/stencil uploads and stencil-only refreshes.
  • cargo xtask policy (191 files ok) and cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) pass.
  • copy_resource_uploads_depth_and_stencil_from_guest_memory and texture::tests:: (3/3) pass on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1 with zero Debug Layer messages.
  • An additional format probe verified readback of both 24-bit depth and 8-bit stencil planes for DXGI_FORMAT_R24G8_TYPELESS (44), plus clean staging/copying of single-plane D32_FLOAT (40) and console D16S8 (118) fallback, on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1.
  • Also confirmed clean co-merge with #2341 on main.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#pullrequestreview-6078893396) · **approved these changes** Looks good. Verified merged onto `main` (`63bcca43`) on an RTX 5090 and Microsoft WARP under the D3D12 Debug Layer (`VICTORY_D3D12_DEBUG=1`): - Querying `D3D12_FEATURE_FORMAT_INFO` for `PlaneCount`, guarding multi-plane staging with `matching_layout` (preserving console `D16S8`'s single-plane path), mapping D3D12 subresource indices in mip -> array slice -> plane order, and resizing/offsetting per-plane dirty spans cleanly handle depth/stencil uploads and stencil-only refreshes. - `cargo xtask policy` (`191 files ok`) and `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) pass. - `copy_resource_uploads_depth_and_stencil_from_guest_memory` and `texture::tests::` (3/3) pass on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1` with zero Debug Layer messages. - An additional format probe verified readback of both 24-bit depth and 8-bit stencil planes for `DXGI_FORMAT_R24G8_TYPELESS` (44), plus clean staging/copying of single-plane `D32_FLOAT` (40) and console `D16S8` (118) fallback, on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1`. - Also confirmed clean co-merge with `#2341` on `main`.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:50 UTC · original · approved these changes

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

  • Uploading compatible multi-plane depth-stencil textures across all host planes (checking D3D12_FEATURE_FORMAT_INFO and matching depth element size so D16S8 stays safely on plane 0) cleanly brings stencil data from guest memory to the host texture.
  • cargo test -p victory-gpu --lib resource:: -- --test-threads=1: 19 passed, 0 failed (including copy_resource_uploads_depth_and_stencil_from_guest_memory).
  • cargo test -p victory-gpu --lib texture:: -- --test-threads=1: 2 passed, 0 failed.
  • 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).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2509#pullrequestreview-6079179248) · **approved these changes** LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Uploading compatible multi-plane depth-stencil textures across all host planes (checking `D3D12_FEATURE_FORMAT_INFO` and matching depth element size so D16S8 stays safely on plane 0) cleanly brings stencil data from guest memory to the host texture. - `cargo test -p victory-gpu --lib resource:: -- --test-threads=1`: 19 passed, 0 failed (including `copy_resource_uploads_depth_and_stencil_from_guest_memory`). - `cargo test -p victory-gpu --lib texture:: -- --test-threads=1`: 2 passed, 0 failed. - `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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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