GPU: capture the mip selected by 2D render-target views #2754

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2756 into main
andrewpozdnakov7-jpg commented 2026-11-25 19:45:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T19:45:55Z.


Summary

Use the MipSlice from a single-sampled Texture2D render-target view when dumping its first plane. Track a resource and mip together across lists and frames, and use the selected subresource for both the copy and the readback footprint. Nonzero mips are named in the PNG filename. D3D12_TEX2D_RTV

Verification

  • The same synthetic guest command list binds and clears mip 0 to red and mip 1 to green. On 13f91ca, both captures contain only the red 4x4 base-mip PNG.
  • With the change, submission and present each also produce a green 2x2 PNG. The test decodes and checks every pixel and the PNG dimensions.
  • The targeted D3D12 WARP regression, full app-local WARP GPU library suite, strict GPU Clippy with and without diagnostics, and staged asset policy pass.

Coordination claim

Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg [email protected].

AI-assisted. Verification used synthetic textures and commands.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6612379692 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T19:45:55Z. --- ## Summary Use the MipSlice from a single-sampled Texture2D render-target view when dumping its first plane. Track a resource and mip together across lists and frames, and use the selected subresource for both the copy and the readback footprint. Nonzero mips are named in the PNG filename. [D3D12_TEX2D_RTV](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_tex2d_rtv) ## Verification - The same synthetic guest command list binds and clears mip 0 to red and mip 1 to green. On 13f91ca, both captures contain only the red 4x4 base-mip PNG. - With the change, submission and present each also produce a green 2x2 PNG. The test decodes and checks every pixel and the PNG dimensions. - The targeted D3D12 WARP regression, full app-local WARP GPU library suite, strict GPU Clippy with and without diagnostics, and staged asset policy pass. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7172579771) Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted. Verification used synthetic textures and commands.
fuzeofficlal commented 2026-11-25 20:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:03:14Z.


Reviewed and verified 2cc21c3c on Windows 11 (RTX 5090 + WARP) against main (13f91ca).

Code review

  • note_rtv restricts mip extraction strictly to Some(view) with D3D12_RTV_DIMENSION_TEXTURE2D and PlaneSlice == 0, safely falling back to mip = 0 for null RTVs, non-2D/array/MSAA/3D RTVs, non-zero planes, and depth targets (with zero overhead when diagnostics is disabled).
  • dump_one bounds-checks target.mip >= u32::from(d.MipLevels) before read_back_subresource, which passes subresource = target.mip consistently to GetCopyableFootprints (BaseOffset = 0) and CopyTextureRegion, matching f.Width/f.Height/f.RowPitch in to_rgba/save_as.
  • Minor non-blocking note: the output PNG filename (capture.rs:611-617) still embeds the top-level {d.Width}x{d.Height} alongside -mip{target.mip} even though the saved PNG dimensions are the selected mip's f.Width x f.Height.

Verification (Windows 11, RTX 5090 + WARP)

  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1: 199 passed, 0 failed, 1 ignored (including resource::tests::capture_uses_the_bound_render_target_mip).
  • RTX 5090 (--features diagnostics): capture::tests 2/2, draw::tests --test-threads=1 11/11.
  • cargo clippy -p victory-gpu --all-targets --locked (default and --features diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
  • Merge compatibility: clean git merge-tree against 13f91ca, #2680, and #2701; text conflicts with #2702 (capture.rs), #2673 (capture.rs), and #2732 (capture.rs, host.rs).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173122342 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#issuecomment-7173122342). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:03:14Z. --- Reviewed and verified `2cc21c3c` on Windows 11 (RTX 5090 + WARP) against `main` (`13f91ca`). ### Code review - `note_rtv` restricts mip extraction strictly to `Some(view)` with `D3D12_RTV_DIMENSION_TEXTURE2D` and `PlaneSlice == 0`, safely falling back to `mip = 0` for null RTVs, non-2D/array/MSAA/3D RTVs, non-zero planes, and depth targets (with zero overhead when `diagnostics` is disabled). - `dump_one` bounds-checks `target.mip >= u32::from(d.MipLevels)` before `read_back_subresource`, which passes `subresource = target.mip` consistently to `GetCopyableFootprints` (`BaseOffset = 0`) and `CopyTextureRegion`, matching `f.Width`/`f.Height`/`f.RowPitch` in `to_rgba`/`save_as`. - Minor non-blocking note: the output PNG filename (`capture.rs:611-617`) still embeds the top-level `{d.Width}x{d.Height}` alongside `-mip{target.mip}` even though the saved PNG dimensions are the selected mip's `f.Width x f.Height`. ### Verification (Windows 11, RTX 5090 + WARP) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1`: **199 passed, 0 failed, 1 ignored** (including `resource::tests::capture_uses_the_bound_render_target_mip`). - RTX 5090 (`--features diagnostics`): `capture::tests` **2/2**, `draw::tests --test-threads=1` **11/11**. - `cargo clippy -p victory-gpu --all-targets --locked` (default and `--features diagnostics`): **0 warnings**; `cargo xtask policy`: **184 files ok**. - **Merge compatibility**: clean `git merge-tree` against `13f91ca`, `#2680`, and `#2701`; text conflicts with `#2702` (`capture.rs`), `#2673` (`capture.rs`), and `#2732` (`capture.rs`, `host.rs`).
kotekompotek commented 2026-11-25 20:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:04:50Z.


Correct: restricting to D3D12_RTV_DIMENSION_TEXTURE2D (non-array, non-MS) makes subresource == MipSlice exactly, and PlaneSlice==0 keeps planar formats on the first plane. Threading Target{resource,mip} through note_texture/targets/dump keeps the bookkeeping consistent, and nonzero mips land in the filename so sequential dumps don't clobber each other.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173162287 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#issuecomment-7173162287). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:04:50Z. --- Correct: restricting to D3D12_RTV_DIMENSION_TEXTURE2D (non-array, non-MS) makes subresource == MipSlice exactly, and PlaneSlice==0 keeps planar formats on the first plane. Threading Target{resource,mip} through note_texture/targets/dump keeps the bookkeeping consistent, and nonzero mips land in the filename so sequential dumps don't clobber each other.
oni-swr commented 2026-11-25 21:03:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:16:15Z.


Independent WARP verification: PR head 2cc21c3

Environment: Windows 11, rustc/cargo 1.98.1, debug build, VICTORY_WARP=1 VICTORY_D3D12_WARP=1 (Microsoft WARP only, no physical GPU), Windows SDK 10.0.26100.0 dxil.dll 1.8.2502.11 on PATH. Tested the PR head itself (single commit directly on origin/main 13f91caee2, so identical to the merge tree). All commands cargo ... --locked.

Baseline on origin/main: test -p victory-gpu --lib: 195 passed, 0 failed, 1 ignored. --features diagnostics: 1 failure, memory::tests::a_submission_that_missed_leaves_the_copies_at_once (memory.rs:886), pre-existing and flaky on main (failed 3 of 4 repeated full runs, passes alone). clippy --all-targets --features diagnostics -D warnings: clean.

On this PR:

  • test -p victory-gpu --lib: 195 passed, 0 failed, 1 ignored.
  • test -p victory-gpu --lib --features diagnostics: 199 passed, 0 failed, 1 ignored (+1 new test, which runs on WARP and does not skip).
  • clippy --locked -p victory-gpu --all-targets --features diagnostics -- -D warnings: clean.
  • Negative control: restored draw.rs from origin/main (note_target instead of note_rtv): capture_uses_the_bound_render_target_mip fails; only 2 PNGs are produced instead of the expected 4 (mip 0 and mip 1, at submission and at present), then restored the PR file.

Review: capture targets are now keyed by (resource, mip), and the readback uses GetCopyableFootprints and CopyTextureRegion for that subresource. The mip comes only from an explicit Texture2D RTV with PlaneSlice == 0. dump_one skips a mip beyond MipLevels. Observations, none blocking: array/Texture2DArray views and the array slice are still captured as mip 0 (as before); the file name still shows the mip-0 width and height, with a -mipN suffix. The change is diagnostics-only. Without the diagnostics feature nothing in it compiles in. The test re-runs itself as a child process with env vars.

Not tested: a physical GPU, any retail title or game behavior, a release build, non-Windows targets.

AI disclosure: this verification was run by Claude Code (Claude Sonnet 5.5). No game files, dumps, shader names or retail hashes were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173422387 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#issuecomment-7173422387). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:16:15Z. --- ## Independent WARP verification: PR head `2cc21c3` **Environment:** Windows 11, rustc/cargo 1.98.1, debug build, `VICTORY_WARP=1 VICTORY_D3D12_WARP=1` (Microsoft WARP only, no physical GPU), Windows SDK 10.0.26100.0 `dxil.dll` 1.8.2502.11 on `PATH`. Tested the PR head itself (single commit directly on `origin/main` 13f91caee25f2fdf2c062be5f7a27f058e51cbca, so identical to the merge tree). All commands `cargo ... --locked`. **Baseline on origin/main:** `test -p victory-gpu --lib`: 195 passed, 0 failed, 1 ignored. `--features diagnostics`: 1 failure, `memory::tests::a_submission_that_missed_leaves_the_copies_at_once` (`memory.rs:886`), pre-existing and flaky on main (failed 3 of 4 repeated full runs, passes alone). `clippy --all-targets --features diagnostics -D warnings`: clean. **On this PR:** - `test -p victory-gpu --lib`: 195 passed, 0 failed, 1 ignored. - `test -p victory-gpu --lib --features diagnostics`: 199 passed, 0 failed, 1 ignored (+1 new test, which runs on WARP and does not skip). - `clippy --locked -p victory-gpu --all-targets --features diagnostics -- -D warnings`: clean. - **Negative control:** restored `draw.rs` from origin/main (`note_target` instead of `note_rtv`): `capture_uses_the_bound_render_target_mip` fails; only 2 PNGs are produced instead of the expected 4 (mip 0 and mip 1, at submission and at present), then restored the PR file. **Review:** capture targets are now keyed by (resource, mip), and the readback uses `GetCopyableFootprints` and `CopyTextureRegion` for that subresource. The mip comes only from an explicit Texture2D RTV with `PlaneSlice == 0`. `dump_one` skips a mip beyond `MipLevels`. Observations, none blocking: array/Texture2DArray views and the array slice are still captured as mip 0 (as before); the file name still shows the mip-0 width and height, with a `-mipN` suffix. The change is diagnostics-only. Without the `diagnostics` feature nothing in it compiles in. The test re-runs itself as a child process with env vars. **Not tested:** a physical GPU, any retail title or game behavior, a release build, non-Windows targets. AI disclosure: this verification was run by Claude Code (Claude Sonnet 5.5). No game files, dumps, shader names or retail hashes were used.
Marvisak commented 2026-11-26 00:03:32 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers. This is diagnostics only: crates/victory-gpu/src/capture.rs now keys capture targets by (resource, mip). note_rtv takes the MipSlice from a Texture2D RTV with PlaneSlice == 0, and dump_one reads that subresource back through read_back_subresource, skipping mips past MipLevels. I checked the footprint and copy subresource indices, and that the new test's 4x4/2x2 expectations match the half-size PNG output of save_as.

Update for e5f86c1: thanks, the filename nit is fixed. The only change since the last review is that dump_one names the file with the footprint's f.Width/f.Height instead of the mip-0 size, and the test now asserts the name (-4x4-f28-mip1 / -8x8-f28). Still a merge candidate; it may conflict textually with other open capture PRs (#2702, #2673, #2732). CI: check passing. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177572096 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#issuecomment-7177572096). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:26:52Z. --- <!-- victory-triage v1 head=e5f86c128ce3165830d23305169bd87d4d5a274f verdict=merge-candidate at=2026-11-26T02:17:40Z --> Automated triage for the maintainers. This is diagnostics only: `crates/victory-gpu/src/capture.rs` now keys capture targets by (resource, mip). `note_rtv` takes the MipSlice from a Texture2D RTV with `PlaneSlice == 0`, and `dump_one` reads that subresource back through `read_back_subresource`, skipping mips past `MipLevels`. I checked the footprint and copy subresource indices, and that the new test's 4x4/2x2 expectations match the half-size PNG output of `save_as`. Update for `e5f86c1`: thanks, the filename nit is fixed. The only change since the last review is that `dump_one` names the file with the footprint's `f.Width`/`f.Height` instead of the mip-0 size, and the test now asserts the name (`-4x4-f28-mip1` / `-8x8-f28`). Still a merge candidate; it may conflict textually with other open capture PRs (#2702, #2673, #2732). CI: `check` passing. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-26 00:03:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T23:38:00Z.


The capture filename now uses the selected subresource's dimensions in e5f86c128c. The same synthetic app-local WARP test failed at the old head when it expected -4x4-f28-mip1. At the updated head, all four submission and present PNGs have the expected source labels (8x8 for mip 0, 4x4 for mip 1), half-size IHDR dimensions and distinct pixels.

The full GPU suite reports 199 passed and 1 ignored. Strict GPU Clippy passed with default and all features, and the staged asset policy passed. The updated head merges cleanly with main at 63bcca43c6.

github.com/Marvisak/VIctory@e5f86c128c

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177835004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#issuecomment-7177835004). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T23:38:00Z. --- The capture filename now uses the selected subresource's dimensions in e5f86c128ce3165830d23305169bd87d4d5a274f. The same synthetic app-local WARP test failed at the old head when it expected `-4x4-f28-mip1`. At the updated head, all four submission and present PNGs have the expected source labels (8x8 for mip 0, 4x4 for mip 1), half-size IHDR dimensions and distinct pixels. The full GPU suite reports 199 passed and 1 ignored. Strict GPU Clippy passed with default and all features, and the staged asset policy passed. The updated head merges cleanly with main at 63bcca43c6a00a758510398fa43096ce7e4f7df0. https://github.com/Marvisak/VIctory/commit/e5f86c128ce3165830d23305169bd87d4d5a274f
Dukestar69 commented 2026-11-26 05:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:10:46Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • cargo test -p victory-gpu --features diagnostics --lib capture_uses_the_bound_render_target_mip: 1 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --all-targets --features diagnostics -- -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:6068439366 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#pullrequestreview-6068439366). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:10:46Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - `cargo test -p victory-gpu --features diagnostics --lib capture_uses_the_bound_render_target_mip`: **1 passed, 0 failed**. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 12:05:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:56:32Z.

Review: APPROVED


Reviewed and verified at head e5f86c12 against origin/main (63bcca43) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer):

  • Design & correctness:
    • Scoped cleanly to #[cfg(feature = "diagnostics")] (plus avoiding a duplicate record.desc() call in crates/victory-gpu/src/draw.rs:422-425).
    • note_rtv (crates/victory-gpu/src/capture.rs:293-307) restricts mip extraction to explicit D3D12_RTV_DIMENSION_TEXTURE2D views with PlaneSlice == 0, where the D3D12 subresource index equals MipSlice, while safely falling back to mip 0 for other dimensions, planes, and depth targets.
    • dump_one (capture.rs:555-617) guards target.mip >= u32::from(d.MipLevels) (capture.rs:563), passes subresource = target.mip consistently to both GetCopyableFootprints and CopyTextureRegion in read_back_subresource (capture.rs:135-205), and labels output PNGs with the selected mip's f.Width x f.Height plus -mip{N} for nonzero mips (capture.rs:611-617).
  • Verification:
    • Clean git merge-tree against origin/main (63bcca43); cargo xtask policy (184 files ok); cargo clippy -p victory-gpu --all-targets -- -D warnings clean with default features and --all-features.
    • cargo test -p victory-gpu --features diagnostics --lib resource::tests::capture_uses_the_bound_render_target_mip -- --exact --nocapture: 1/1 passed (bound-mip capture produced 4 PNGs, verifying filenames, IHDR dimensions, and decoded red/green pixels); capture::tests 2/2 passed.
    • Live child-process capture runs with VICTORY_D3D12_DEBUG=1 on both RTX 5090 and WARP (VICTORY_D3D12_WARP=1) exited cleanly with zero debug-layer errors and produced all four expected PNGs (-8x8-f28.png and -4x4-f28-mip1.png at both submission and present).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6073721560 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2756#pullrequestreview-6073721560). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T11:56:32Z. **Review:** APPROVED --- Reviewed and verified at head `e5f86c12` against `origin/main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, D3D12 Debug Layer): - **Design & correctness**: - Scoped cleanly to `#[cfg(feature = "diagnostics")]` (plus avoiding a duplicate `record.desc()` call in `crates/victory-gpu/src/draw.rs:422-425`). - `note_rtv` (`crates/victory-gpu/src/capture.rs:293-307`) restricts mip extraction to explicit `D3D12_RTV_DIMENSION_TEXTURE2D` views with `PlaneSlice == 0`, where the D3D12 subresource index equals `MipSlice`, while safely falling back to mip 0 for other dimensions, planes, and depth targets. - `dump_one` (`capture.rs:555-617`) guards `target.mip >= u32::from(d.MipLevels)` (`capture.rs:563`), passes `subresource = target.mip` consistently to both `GetCopyableFootprints` and `CopyTextureRegion` in `read_back_subresource` (`capture.rs:135-205`), and labels output PNGs with the selected mip's `f.Width x f.Height` plus `-mip{N}` for nonzero mips (`capture.rs:611-617`). - **Verification**: - Clean `git merge-tree` against `origin/main` (`63bcca43`); `cargo xtask policy` (`184 files ok`); `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean with default features and `--all-features`. - `cargo test -p victory-gpu --features diagnostics --lib resource::tests::capture_uses_the_bound_render_target_mip -- --exact --nocapture`: **1/1 passed** (`bound-mip capture produced 4 PNGs`, verifying filenames, IHDR dimensions, and decoded red/green pixels); `capture::tests` **2/2 passed**. - Live child-process capture runs with `VICTORY_D3D12_DEBUG=1` on both **RTX 5090** and **WARP** (`VICTORY_D3D12_WARP=1`) exited cleanly with zero debug-layer errors and produced all four expected PNGs (`-8x8-f28.png` and `-4x4-f28-mip1.png` at both submission and present). LGTM.
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/2756:upstream-pr/2756'
git switch 'upstream-pr/2756'

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