GPU: non-stream graphics PSOs, stream subobjects 25..=28, texture-to-buffer readbacks, and sRGB view preservation #301

Open
wbkepler wants to merge 2 commits from upstream-pr/301 into main
wbkepler commented 2026-11-24 02:09:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T02:09:58Z.


Summary

Improves host D3D12 pipeline state capture, texture-to-buffer readbacks, and sRGB view fidelity across victory-gpu:

  • Non-stream graphics PSOs (pipeline.rs):
    • Captures full GraphicsState from D3D12_GRAPHICS_PIPELINE_STATE_DESC in pipeline::create_graphics instead of passing None.
  • Stream subobjects 25..=28 (pipeline.rs):
    • Sizes and parses standard D3D12 stream subobjects 25 (PC MS), 26 (DEPTH_STENCIL2), 27 (RASTERIZER1), and 28 (RASTERIZER2) with compile-time size assertions and stream bounds checks.
  • Texture-to-buffer readbacks (list.rs):
    • Implements texture-to-buffer CopyTextureRegion readbacks into the destination buffer's Shadow copy with 512-byte placement alignment checks, shadow.refresh + shadow.gpu_writes, and copy-back to title memory.
  • sRGB view preservation (descriptor.rs, descriptor/host.rs, resource.rs, texture.rs, capture.rs):
    • Expands SRGB to all 7 UNORM/sRGB pairs (R8G8B8A8, B8G8R8A8, B8G8R8X8, BC1, BC2, BC3, BC7) and backs sRGB-castable host textures with typeless family formats so _SRGB SRVs/RTVs preserve sRGB conversion while UAVs map to linear UNORM.
    • Synthesizes dimension-aware default SRV/UAV/RTV/DSV descs (1D/2D/3D/Array/MSAA) for null/UNKNOWN descriptors and passes concrete formats to GetCopyableFootprints.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (including live D3D12 readback, PSO, and 2D/Array/MSAA sRGB view tests)
  • cargo xtask policy — passed (151 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573007711 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T02:09:58Z. --- ## Summary Improves host D3D12 pipeline state capture, texture-to-buffer readbacks, and sRGB view fidelity across `victory-gpu`: - **Non-stream graphics PSOs (`pipeline.rs`)**: - Captures full `GraphicsState` from `D3D12_GRAPHICS_PIPELINE_STATE_DESC` in `pipeline::create_graphics` instead of passing `None`. - **Stream subobjects `25..=28` (`pipeline.rs`)**: - Sizes and parses standard D3D12 stream subobjects 25 (`PC MS`), 26 (`DEPTH_STENCIL2`), 27 (`RASTERIZER1`), and 28 (`RASTERIZER2`) with compile-time size assertions and stream bounds checks. - **Texture-to-buffer readbacks (`list.rs`)**: - Implements texture-to-buffer `CopyTextureRegion` readbacks into the destination buffer's `Shadow` copy with 512-byte placement alignment checks, `shadow.refresh` + `shadow.gpu_writes`, and copy-back to title memory. - **sRGB view preservation (`descriptor.rs`, `descriptor/host.rs`, `resource.rs`, `texture.rs`, `capture.rs`)**: - Expands `SRGB` to all 7 UNORM/sRGB pairs (`R8G8B8A8`, `B8G8R8A8`, `B8G8R8X8`, `BC1`, `BC2`, `BC3`, `BC7`) and backs sRGB-castable host textures with typeless family formats so `_SRGB` SRVs/RTVs preserve sRGB conversion while UAVs map to linear UNORM. - Synthesizes dimension-aware default SRV/UAV/RTV/DSV descs (`1D`/`2D`/`3D`/`Array`/`MSAA`) for null/`UNKNOWN` descriptors and passes concrete formats to `GetCopyableFootprints`. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (including live D3D12 readback, PSO, and 2D/Array/MSAA sRGB view tests) - `cargo xtask policy` — passed (151 files ok)
r4tedx commented 2026-11-24 06:55:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-24T03:30:05Z.


Review note on subobject 26 (DEPTH_STENCIL_DESC2), built on main d2a4bae (tests pass on an RTX 5070). The description is narrowed to the plain D3D12_DEPTH_STENCIL_DESC:

StencilReadMask: d.FrontFace.StencilReadMask,
StencilWriteMask: d.FrontFace.StencilWriteMask,

Two things are lost on the way:

  1. DESC2 has separate read and write masks per face; the back face's masks are dropped and the front face's used for both.
  2. DepthBoundsTestEnable is dropped, as it is for kind 21 on main.

The test uses a zeroed description, so neither shows. Creating the host pipeline from a stream with the DEPTH_STENCIL2 subobject as given would keep both.

For (2) there is an open PR, #158, which keeps the flag for kind 21, creates the pipeline from a stream when it is set, and forwards OMSetDepthBounds. The two touch the same GraphicsState: merged together the build fails with E0063 (the new initializer here lacks depth_bounds), so whichever lands second needs the field carried through kind 26 as well.

From reading and synthetic tests only; I have no copy of the title.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121156929 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7121156929). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-24T03:30:05Z. --- Review note on subobject 26 (`DEPTH_STENCIL_DESC2`), built on `main` `d2a4bae` (tests pass on an RTX 5070). The description is narrowed to the plain `D3D12_DEPTH_STENCIL_DESC`: ```rust StencilReadMask: d.FrontFace.StencilReadMask, StencilWriteMask: d.FrontFace.StencilWriteMask, ``` Two things are lost on the way: 1. `DESC2` has separate read and write masks per face; the back face's masks are dropped and the front face's used for both. 2. `DepthBoundsTestEnable` is dropped, as it is for kind 21 on `main`. The test uses a zeroed description, so neither shows. Creating the host pipeline from a stream with the `DEPTH_STENCIL2` subobject as given would keep both. For (2) there is an open PR, #158, which keeps the flag for kind 21, creates the pipeline from a stream when it is set, and forwards `OMSetDepthBounds`. The two touch the same `GraphicsState`: merged together the build fails with `E0063` (the new initializer here lacks `depth_bounds`), so whichever lands second needs the field carried through kind 26 as well. From reading and synthetic tests only; I have no copy of the title.
wbkepler commented 2026-11-24 06:55:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T03:42:31Z.


Thanks @r4tedx, good catch. Fixed in 1af4624:

  • Kind 26 now keeps the D3D12_DEPTH_STENCIL_DESC2 as given in GraphicsState (a later kind 11/21 clears it). When stencil is on and the back-face read/write masks differ from the front ones, the host pipeline is created from a pipeline-state stream with the DEPTH_STENCIL2 subobject, if the device reports IndependentFrontAndBackStencilRefMaskSupported (OPTIONS14, probed once). Otherwise it falls back to the front masks with a once-logged warning. Equal masks keep the plain description, which is exact in that case.
  • Mesh pipelines use the same stream builder (a small subobject writer) in place of the fixed struct.
  • DepthBoundsTestEnable is kept in the captured state but still cleared for the host pipeline, as for kind 21, marked as a shortcut:. Bounds aren't forwarded here, and I've left that to #158. Whichever of the two lands second will need to carry #158's depth_bounds through kind 26 and set the flag in the stream path.
  • Two new tests use a non-zeroed description with distinct front and back masks. One checks the back masks survive and a later kind 11 replaces them. The other checks equal masks stay plain and the stream subobject layout is byte-exact.

Gate: clippy clean for the changed code, cargo test --workspace passes, cargo xtask policy ok. cargo fmt --check already reports diffs in these files on main, and this change adds none.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121345787 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7121345787). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T03:42:31Z. --- Thanks @r4tedx, good catch. Fixed in 1af4624: - Kind 26 now keeps the `D3D12_DEPTH_STENCIL_DESC2` as given in `GraphicsState` (a later kind 11/21 clears it). When stencil is on and the back-face read/write masks differ from the front ones, the host pipeline is created from a pipeline-state stream with the `DEPTH_STENCIL2` subobject, if the device reports `IndependentFrontAndBackStencilRefMaskSupported` (OPTIONS14, probed once). Otherwise it falls back to the front masks with a once-logged warning. Equal masks keep the plain description, which is exact in that case. - Mesh pipelines use the same stream builder (a small subobject writer) in place of the fixed struct. - `DepthBoundsTestEnable` is kept in the captured state but still cleared for the host pipeline, as for kind 21, marked as a `shortcut:`. Bounds aren't forwarded here, and I've left that to #158. Whichever of the two lands second will need to carry #158's `depth_bounds` through kind 26 and set the flag in the stream path. - Two new tests use a non-zeroed description with distinct front and back masks. One checks the back masks survive and a later kind 11 replaces them. The other checks equal masks stay plain and the stream subobject layout is byte-exact. Gate: clippy clean for the changed code, `cargo test --workspace` passes, `cargo xtask policy` ok. `cargo fmt --check` already reports diffs in these files on `main`, and this change adds none.
fuzeofficlal commented 2026-11-24 06:56:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T06:24:25Z.


I tested a default DSV on a synthetic 4×4 D32_FLOAT texture with 4× MSAA and typeless host backing. The test uses the ordinary DSV creation and clear path, then resolves and reads back depth. An explicit TEXTURE2DMS DSV was the positive control.

On d2a4bae, the default descriptor selected TEXTURE2D, and D3D12 rejected it at view creation on both RTX 5090 and WARP. The explicit control passed. On 1af4624, both the default and explicit views selected TEXTURE2DMS. Both adapters read back all 16 depth texels as 0.25, with zero D3D12 debug errors. This covers the non-array default D32 depth-view path.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123899667 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7123899667). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T06:24:25Z. --- I tested a default DSV on a synthetic 4×4 D32_FLOAT texture with 4× MSAA and typeless host backing. The test uses the ordinary DSV creation and clear path, then resolves and reads back depth. An explicit `TEXTURE2DMS` DSV was the positive control. On `d2a4bae`, the default descriptor selected `TEXTURE2D`, and D3D12 rejected it at view creation on both RTX 5090 and WARP. The explicit control passed. On `1af4624`, both the default and explicit views selected `TEXTURE2DMS`. Both adapters read back all 16 depth texels as `0.25`, with zero D3D12 debug errors. This covers the non-array default D32 depth-view path.
SamuelReeder commented 2026-11-24 18:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SamuelReeder on 2026-11-24T17:32:48Z.


In make, a null-description or format-0 SRV on a typeless host texture takes view_format. Depth textures are typeless on the host too, so a D32_FLOAT one gets a D32_FLOAT SRV, and fits accepts it as the same family. I did not run this branch, but on main ffe310e creating that SRV explicitly on WARP removed the device (0x887A0001); the null-description form is refused there today. Limiting the fill-in to non-depth formats, or mapping to the readable one (R32_FLOAT), would avoid it. I read only the view code. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139356267 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7139356267). Originally posted by [SamuelReeder](https://github.com/SamuelReeder) on 2026-11-24T17:32:48Z. --- In `make`, a null-description or format-0 SRV on a typeless host texture takes `view_format`. Depth textures are typeless on the host too, so a `D32_FLOAT` one gets a `D32_FLOAT` SRV, and `fits` accepts it as the same family. I did not run this branch, but on `main` ffe310e creating that SRV explicitly on WARP removed the device (0x887A0001); the null-description form is refused there today. Limiting the fill-in to non-depth formats, or mapping to the readable one (`R32_FLOAT`), would avoid it. I read only the view code. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 01:07:48 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/pipeline.rs, crates/victory-gpu/src/pipeline/host.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148514283 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7148514283). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:34Z. --- <!-- victory-triage v1 head=1af462451537270dc9b0d508fb5e70bf535622be verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/pipeline.rs`, `crates/victory-gpu/src/pipeline/host.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
r4tedx commented 2026-11-25 08:06:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-25T07:42:43Z.


One interaction to settle before either lands, from reading 1af4624 beside #158.

In pipeline/host.rs this PR sets DepthBoundsTestEnable: false with the comment "bounds are not forwarded yet; carry it through when they are". #158 is the PR that forwards them: with it the depth bounds test reaches the host, on adapters that support it. It is on main 940d32f and merges cleanly.

So whichever of the two goes in second has one line to change: if #158 is in first, this should carry the title's value through instead of clearing it; if this is in first, #158's rebase does the same. Otherwise the test is dropped again for every pipeline that takes this path, as it is on main today.

Nothing was run for this comment; I read both diffs.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156166243 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/301#issuecomment-7156166243). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-25T07:42:43Z. --- One interaction to settle before either lands, from reading `1af4624` beside #158. In `pipeline/host.rs` this PR sets `DepthBoundsTestEnable: false` with the comment "bounds are not forwarded yet; carry it through when they are". #158 is the PR that forwards them: with it the depth bounds test reaches the host, on adapters that support it. It is on `main` `940d32f` and merges cleanly. So whichever of the two goes in second has one line to change: if #158 is in first, this should carry the title's value through instead of clearing it; if this is in first, #158's rebase does the same. Otherwise the test is dropped again for every pipeline that takes this path, as it is on `main` today. Nothing was run for this comment; I read both diffs. AI-assisted (Claude Code).
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/301:upstream-pr/301'
git switch 'upstream-pr/301'

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