GPU: read single-plane depth textures into guest buffers #3004

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/3006 into main
andrewpozdnakov7-jpg commented 2026-11-26 03:15:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T03:15:22Z.


The guest CopyTextureRegion readback path discards copies from any depth resource. Allow whole, single-sampled D16 and D32 subresources with a compatible single-plane footprint. The depth case checks the source subresource, the destination origin and the whole-subresource rule before recording the copy. It uses the existing pitched row transfer into the guest buffer. CopyTextureRegion requirements

Verification

  • Native inbox and Agility WARP both read the cleared 0.25 and 0.75 depths from D32_FLOAT, R32_TYPELESS, D16_UNORM and R16_TYPELESS, using the corresponding DSV and GetCopyableFootprints.
  • The same guest list test on main leaves all four depth buffers entirely at the sentinel value. The patch returns both exact rows for all four formats and preserves the buffer padding. The original RGBA8 clipped-region control also passes.
  • Focused default and Agility WARP tests passed, including the diagnostics run with VICTORY_D3D12_DEBUG=1. Full GPU diagnostics passed (246 tests, one ignored), with both strict Clippy builds and asset policy.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6618714290 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T03:15:22Z. --- The guest CopyTextureRegion readback path discards copies from any depth resource. Allow whole, single-sampled D16 and D32 subresources with a compatible single-plane footprint. The depth case checks the source subresource, the destination origin and the whole-subresource rule before recording the copy. It uses the existing pitched row transfer into the guest buffer. [CopyTextureRegion requirements](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copytextureregion) ## Verification - Native inbox and Agility WARP both read the cleared 0.25 and 0.75 depths from D32_FLOAT, R32_TYPELESS, D16_UNORM and R16_TYPELESS, using the corresponding DSV and GetCopyableFootprints. - The same guest list test on main leaves all four depth buffers entirely at the sentinel value. The patch returns both exact rows for all four formats and preserves the buffer padding. The original RGBA8 clipped-region control also passes. - Focused default and Agility WARP tests passed, including the diagnostics run with VICTORY_D3D12_DEBUG=1. Full GPU diagnostics passed (246 tests, one ignored), with both strict Clippy builds and asset policy. AI-assisted with Codex.
fuzeofficlal commented 2026-11-26 04:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:24:50Z.

Review: APPROVED


Code review on 7a11b213 (static source inspection; no runtime GPU execution):

  • crates/victory-gpu/src/list.rs:846-869 cleanly opens single-plane depth readbacks (R32 family 39 and R16 family 53) for whole single-sampled subresources with matching family, box = None, at = [0, 0, 0], and valid subresource index, with unit coverage across D32_FLOAT, R32_TYPELESS, D16_UNORM, and R16_TYPELESS.
  • Non-blocking note: as with the pre-existing color path at list.rs:843, read_back checks dst.footprint.row_pitch.is_multiple_of(256) but does not check that row_pitch is at least the unpadded row width (e.g. a 65×2 D32_FLOAT footprint with RowPitch = 256 < 260 bytes would still be forwarded to CopyTextureRegion). Fine to keep scoped here or tighten in a follow-up alongside color readbacks.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068143245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006#pullrequestreview-6068143245). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:24:50Z. **Review:** APPROVED --- Code review on `7a11b213` (static source inspection; no runtime GPU execution): - `crates/victory-gpu/src/list.rs:846-869` cleanly opens single-plane depth readbacks (`R32` family `39` and `R16` family `53`) for whole single-sampled subresources with matching family, `box = None`, `at = [0, 0, 0]`, and valid subresource index, with unit coverage across `D32_FLOAT`, `R32_TYPELESS`, `D16_UNORM`, and `R16_TYPELESS`. - Non-blocking note: as with the pre-existing color path at `list.rs:843`, `read_back` checks `dst.footprint.row_pitch.is_multiple_of(256)` but does not check that `row_pitch` is at least the unpadded row width (e.g. a 65×2 `D32_FLOAT` footprint with `RowPitch = 256` < `260` bytes would still be forwarded to `CopyTextureRegion`). Fine to keep scoped here or tighten in a follow-up alongside color readbacks.
steven-seagull27 commented 2026-11-26 04:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T03:28:34Z.


Independent RTX 5080 and Windows built-in WARP readback on 7a11b21: 12,024/12,024 depth texels matched on each adapter, alongside the original clipped RGBA8 and depth cases. The new fixture uses D32_FLOAT, R32_TYPELESS, D16_UNORM and R16_TYPELESS. Each resource has two array slices and three mips (131×9, 65×4, 32×2).

I filled each mip/slice with two distinct native DSV clears, then read all six through the guest command list in reverse order. Destination footprints begin at separate aligned offsets, have 256 extra bytes of row pitch, and end exactly after the final row's payload. All pitch and alignment padding retained its sentinel. On parent 63bcca4, all four depth formats failed the new check on both adapters. As a sensitivity check, deliberately taking each mip from the first array slice failed at subresource 3 (slice 1, mip 0) in all four formats on both adapters.

The test-only commit 18fce85 applies on your PR. Run cargo test --locked -p victory-gpu --features diagnostics --lib depth_mips_and_array_slices -- --nocapture, and repeat with VICTORY_D3D12_WARP=1 for the software pass. Both adapters ran with VICTORY_D3D12_DEBUG=1.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181751654 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006#issuecomment-7181751654). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T03:28:34Z. --- Independent RTX 5080 and Windows built-in WARP readback on `7a11b21`: **12,024/12,024 depth texels matched on each adapter**, alongside the original clipped RGBA8 and depth cases. The new fixture uses D32_FLOAT, R32_TYPELESS, D16_UNORM and R16_TYPELESS. Each resource has two array slices and three mips (131×9, 65×4, 32×2). I filled each mip/slice with two distinct native DSV clears, then read all six through the guest command list in reverse order. Destination footprints begin at separate aligned offsets, have 256 extra bytes of row pitch, and end exactly after the final row's payload. All pitch and alignment padding retained its sentinel. On parent `63bcca4`, all four depth formats failed the new check on both adapters. As a sensitivity check, deliberately taking each mip from the first array slice failed at subresource 3 (slice 1, mip 0) in all four formats on both adapters. The [test-only commit `18fce85`](https://github.com/steven-seagull27/VIctory/commit/18fce85f46fb000ac35367b60c35a824c37ea067) applies on your PR. Run `cargo test --locked -p victory-gpu --features diagnostics --lib depth_mips_and_array_slices -- --nocapture`, and repeat with `VICTORY_D3D12_WARP=1` for the software pass. Both adapters ran with `VICTORY_D3D12_DEBUG=1`.
kotekompotek commented 2026-11-26 05:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:40:25Z.

Review: APPROVED


LGTM — single-plane depth readback gated correctly: only families 39|53 (R32/R16 depth), same family required on the dst footprint, whole single-sampled subresource only (no offset, no box, index < mips*array). Test matrix covers RGBA8 + the four depth formats.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068634149 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006#pullrequestreview-6068634149). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:40:25Z. **Review:** APPROVED --- LGTM — single-plane depth readback gated correctly: only families 39|53 (R32/R16 depth), same family required on the dst footprint, whole single-sampled subresource only (no offset, no box, index < mips*array). Test matrix covers RGBA8 + the four depth formats.
Marvisak commented 2026-11-26 07:01:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:16:17Z.


Automated triage for the maintainers.

Thanks, the test is now tidy. In crates/victory-gpu/src/resource.rs the branch diff only adds a separate depth test, and the RGBA8 test is untouched. The list.rs::read_back checks are unchanged and still look consistent with the D3D12 copy rules.

As you say, the main point is still open. In main, refusing to read back a depth texture is a deliberate shortcut until a title is seen doing it. Lifting it needs evidence that GTA VI reads a depth texture back into a buffer, for example the "texture to buffer copy refused: a depth or stencil texture" warning firing in a diagnostics run. It also needs confirmation that the console's layout for these formats matches the host's single-plane rows on this path. With that, this would be a good candidate.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184263376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006#issuecomment-7184263376). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:16:17Z. --- <!-- victory-triage v1 head=34c28df456662659ced476726f9630052883b2c7 verdict=needs-work at=2026-11-26T07:19:53Z --> Automated triage for the maintainers. Thanks, the test is now tidy. In `crates/victory-gpu/src/resource.rs` the branch diff only adds a separate depth test, and the RGBA8 test is untouched. The `list.rs::read_back` checks are unchanged and still look consistent with the D3D12 copy rules. As you say, the main point is still open. In `main`, refusing to read back a depth texture is a deliberate shortcut until a title is seen doing it. Lifting it needs evidence that GTA VI reads a depth texture back into a buffer, for example the "texture to buffer copy refused: a depth or stencil texture" warning firing in a diagnostics run. It also needs confirmation that the console's layout for these formats matches the host's single-plane rows on this path. With that, this would be a good candidate. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-26 07:01:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T06:41:01Z.


Commit 34c28df restores the existing RGBA8 test verbatim and adds a separate synthetic test for D16 and D32, including their typeless counterparts. In the full branch diff, resource.rs now only adds the depth test.

With that fixture on 63bcca43, all four destination buffers stay untouched. The same fixture with the fix returns the exact depth texels and preserves every padding byte. The original RGBA8 test passes. App-local WARP GPU suite 247 passed and 1 ignored. Strict GPU Clippy passed in both modes, and asset policy passed.

The evidence here is for the synthetic guest copy and the host D3D12 layout. The requested title usage and console layout confirmation are still open.

Please retain the Git author when moving the test. If it is folded into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184675736 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3006#issuecomment-7184675736). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T06:41:01Z. --- [Commit 34c28df](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/34c28df456662659ced476726f9630052883b2c7) restores the existing RGBA8 test verbatim and adds a separate synthetic test for D16 and D32, including their typeless counterparts. In the full branch diff, `resource.rs` now only adds the depth test. With that fixture on `63bcca43`, all four destination buffers stay untouched. The same fixture with the fix returns the exact depth texels and preserves every padding byte. The original RGBA8 test passes. App-local WARP GPU suite 247 passed and 1 ignored. Strict GPU Clippy passed in both modes, and asset policy passed. The evidence here is for the synthetic guest copy and the host D3D12 layout. The requested title usage and console layout confirmation are still open. Please retain the Git author when moving the test. If it is folded into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
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/3006:upstream-pr/3006'
git switch 'upstream-pr/3006'

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