Skip to content

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 into
Marvisak:mainfrom
wbkepler:gpu/graphics-pso-and-readback
Open

wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:gpu/graphics-pso-and-readback

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

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)

…buffer readbacks, and sRGB view preservation

Improve host D3D12 correctness across pipeline state creation, GPU-to-CPU
texture readbacks, and sRGB view casting:

- Non-stream graphics PSOs (`pipeline.rs`, `pipeline/host.rs`):
  - Capture `GraphicsState` from `D3D12_GRAPHICS_PIPELINE_STATE_DESC` in
    `pipeline::create_graphics` (blend, sample mask, rasterizer, depth-
    stencil, owned input layout, strip cut, topology, RTV/DSV formats,
    and sample desc) instead of passing `None`.
- Stream PSO subobjects `25..=28` (`pipeline.rs`, `pipeline/host.rs`):
  - Size and parse standard D3D12 subobjects `25` (PC `MS`), `26`
    (`DEPTH_STENCIL2`), `27` (`RASTERIZER1`), and `28` (`RASTERIZER2`)
    with compile-time size assertions and explicit stream bounds checks
    (`at + size <= desc.size`) so later subobjects are not dropped.
- Texture -> buffer `CopyTextureRegion` readbacks (`list.rs`, `resource.rs`):
  - Copy from the source `HostTexture` (transitioned to `COPY_SOURCE`)
    into the destination buffer's `Shadow` copy (checking 512-byte
    placement alignment, refreshing before snapshotting, and scheduling
    `shadow.gpu_writes`) so copied texture rows land back in title memory.
- sRGB view format preservation (`resource.rs`, `descriptor.rs`,
  `descriptor/host.rs`, `texture.rs`, `capture.rs`):
  - Expand `SRGB` to all 7 sRGB/UNORM pairs (`R8G8B8A8`, `B8G8R8A8`,
    `B8G8R8X8`, `BC1`, `BC2`, `BC3`, `BC7`) and back sRGB-castable host
    textures with their typeless family format so `_SRGB` SRV/RTV views
    retain hardware sRGB conversion while UAVs map cleanly to linear UNORM.
  - Synthesize default concrete SRV/UAV/RTV view descriptions when titles
    omit the descriptor or pass `DXGI_FORMAT_UNKNOWN` on typeless host
    textures, and pass concrete non-typeless formats to `GetCopyableFootprints`
    in staging uploads and diagnostics captures.
- Add unit and live D3D12 tests covering plain graphics PSO state capture,
  subobjects `25..=28` parsing, texture-to-buffer `CopyTextureRegion`
  readbacks, and sRGB SRV/UAV/RTV view creation on typeless host textures.
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

Stream subobject 26 was narrowed to the plain depth-stencil description,
using the front face's stencil read/write masks for both faces. The
graphics state now keeps the description as given; when stencil is on and
the back 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 independent front and back stencil masks (OPTIONS14).
Otherwise the front masks are used for both, with a once-logged warning.

Mesh pipelines now share the same stream builder (a small byte-exact
subobject writer) instead of a fixed struct. The depth bounds flag is kept
in the captured state but still cleared for the host pipeline, as for
kind 21, until bounds are forwarded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wbkepler

Copy link
Copy Markdown
Contributor Author

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 GPU: the depth bounds test reaches the host #158. Whichever of the two lands second will need to carry GPU: the depth bounds test reaches the host #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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Owner

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

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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).

Steenax6 pushed a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
When a frame ended a loop, decode cut it at the loop's end subframe, set
the loop's skip (the subframes of the loop's first frame that lie before
the loop) and then took that skip out of the frame in hand: the loop's
last. So the head of the last frame was dropped instead, and the first
frame played from its start, with the audio before the loop in it. The
number of samples came out the same; the seam did not.

The pending skip is still applied to the frame in hand, and the loop's
skip is set after it, for the frame decoded next.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Source: Marvisak/VIctory 985d8d4 (Maraco91), merged upstream as PR Marvisak#194; the same fix as the loop half of fxceless/victory-fork PR Marvisak#301.

(cherry picked from commit 985d8d4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Steenax6 pushed a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
A decode step can succeed without samples: a switch from an input with
no packets to the other, or a start or loop skip that takes a whole
frame. The block writer decoded once, found fewer samples than a block,
padded the block with silence and moved the write block on: a gap of
2.7 ms in the sound for every such step. It now decodes until the block
is full or the input runs out; sixteen steps in a row without samples
(a looping stream whose skip takes all it keeps) end the pass for that
voice, so it cannot spin.

Test: blocks_are_filled_across_decode_steps_without_samples (an empty
input 0 before a six-frame input 1: 26 blocks; a start skip of a whole
frame: 22 blocks). Without the loop the first case writes 27 (checked
here).

Source: Marvisak/VIctory PR Marvisak#2444 (Texbirds), commit 413cf34, ported
onto PR Marvisak#2788's fill_block; the same fix is the pump half of
fxceless/victory-fork PR Marvisak#301 (its loop half is upstream 985d8d4, taken
earlier). Marvisak PR Marvisak#2709 (VlREX) fixes the same case by leaving the
ring for the next pass, which waits for the decoding thread to come
round again; it is not taken. Not heard in the title.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants