Skip to content

GPU: integer render targets write unblended on the host (#2775) - #2801

Open
miatson wants to merge 3 commits into
Marvisak:mainfrom
miatson:gpu-integer-target-blend
Open

miatson wants to merge 3 commits into
Marvisak:mainfrom
miatson:gpu-integer-target-blend

Conversation

@miatson

@miatson miatson commented Nov 25, 2026

Copy link
Copy Markdown

Fixes #2775.

Problem

The console blends (MIN/MAX) into integer render targets; desktop D3D12 refuses a
pipeline that enables blending on a _UINT/_SINT target. The title's blend state was
passed to the host unchanged, so pipelines like the mesh pipeline in #2775 (blending on
slot 2, R8_UINT) were refused with E_INVALIDARG and all their draws were dropped.

Change

GraphicsState::host_blend (in pipeline/host.rs) is now the blend state both host paths use
(the graphics description and the mesh pipeline stream):

  • Targets with an integer format get BlendEnable = FALSE; the others keep the title's blending.
  • If IndependentBlendEnable was off, target 0's description is first copied to every
    target and independent blending turned on, so only the integer target changes.
  • States with no blended integer target are passed on unchanged.

It reuses twin::integer (now pub(crate)) for the format check.

Trade-off

The integer target now overwrites instead of MIN/MAX-blending, as the issue suggests.
That can differ from the console's output for that target, but the pass is drawn instead
of dropped.

Tests

  • integer_targets_write_unblended: the blend state for both the independent and the
    shared description cases, and the unchanged case.
  • the_host_takes_a_pipeline_blending_into_an_integer_target: creates the pipeline on the
    host device (skipped without one). Before the change it failed locally with
    HRESULT(0x80070057), the error in the issue; it now passes.

cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean, and
cargo test --workspace --locked passes (782 passed, 0 failed) on Windows 11.

Not tested in game: I have no game data. The mesh path uses the same host_blend but
only the graphics path is covered by the device test.

Written with the help of Claude Code.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct on both semantics and mechanics: D3D12 rejects PSOs that blend into integer RTVs, while the console allows MIN/MAX there — degrading to unblended writes on only the integer slots is the right approximation. The non-independent case correctly promotes to IndependentBlendEnable (otherwise disabling RT2's blend would disable it everywhere), and twin::integer is the established format classifier. Both pipeline paths (classic + mesh stream subobject) use host_blend. Tests cover independent true/false and the no-integer passthrough. LGTM.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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

Code review (and comparison with #2790)

  • Clean, minimal diff on current main (13f91ca), keeping g.blend / g.describe() untouched via GraphicsState::host_blend() for both graphics (host.rs:647) and mesh (host.rs:752) PSO creation.
  • Correctly handles IndependentBlendEnable == FALSE (unlike #2790): inspects blend.RenderTarget[if independent { i } else { 0 }].BlendEnable across 0..count, expands [blend.RenderTarget[0]; 8] and sets IndependentBlendEnable = true when any integer target is blended, and clears BlendEnable only on the integer slots—so both (RT0 float blended, RT2 integer) and (RT0 integer blended, RT1 float) MRT combinations work without rejecting the PSO or disabling blending on float targets.
  • Reuses twin::integer covering all 21 DXGI _UINT/_SINT RTV formats. (Minor edge note: if a title ever set both BlendEnable = TRUE and LogicOpEnable = TRUE simultaneously with IndependentBlendEnable = FALSE, expanding to IndependentBlendEnable = TRUE would also need LogicOpEnable = FALSE, though that combination is already invalid in D3D12.)

Verification (Windows 11, RTX 5090 + WARP)

  • RTX 5090 (--features diagnostics --test-threads=1, pipeline::): 18/18 passed (including integer_targets_write_unblended and the_host_takes_a_pipeline_blending_into_an_integer_target for both independent = true and false).
  • WARP & RTX 5090 full victory-gpu --features diagnostics --lib -- --test-threads=1: 198 passed, 2 failed, 1 ignored (all pipeline::* pass; only the 2 pre-existing 13f91ca view-heap cap baselines fail).
  • cargo clippy --locked -p victory-gpu --features diagnostics --all-targets -- -D warnings: 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca and #2803.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent WARP/CPU verification of head 28b7278f6ddcce2bd9b7a01f6e989c2adc86534b, merged onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca (clean merge).

Environment: Windows 11 Pro 26200, WARP only (VICTORY_D3D12_WARP=1 with --features diagnostics, so host() is WARP, plus VICTORY_WARP=1), Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11.

  • cargo test -j 4 -p victory-gpu --features diagnostics:
    • The first run gave 199 passed, 1 failed, 1 ignored. The failure was memory::tests::a_submission_that_missed_leaves_the_copies_at_once ("the written page counts as changed at once"), which is the known race on main that GPU tests: assert a missed submission through readback #2805 removes, unrelated to this change.
    • Five reruns each gave 200 passed, 0 failed, 1 ignored. The baseline was 198/0/1, so there are 2 new passing tests.
  • the_host_takes_a_pipeline_blending_into_an_integer_target ran on the WARP host device.
  • Negative controls:
  • cargo clippy -p victory-gpu --all-targets -- -D warnings was clean, with and without --all-features.
  • cargo fmt --all --check: 897 hunks against 891 on the baseline. The 6 new hunks are all in pipeline/host.rs: the blended closure in host_blend, two assert!s in integer_targets_write_unblended, and the D3DCompile, D3D12_SHADER_BYTECODE and CreateRootSignature lines in the device test.

Diff review:

  • The logic looks right. The early return only applies when a blended target is an integer one, both the graphics and the mesh-stream paths use host_blend, min(8) bounds the format index, and twin::integer's list matches the DXGI _UINT/_SINT formats.
  • The only requests are the test gap and the rustfmt hunks above.
  • The mesh path isn't exercised by a test, as the description says.

Not tested: physical GPU, mesh pipeline path on a device, retail title.

AI use: Claude Code (Claude Opus 5.5)

@miatson

miatson commented Nov 25, 2026

Copy link
Copy Markdown
Author
  • The logic looks right. The early return only applies when a blended target is an integer one, both the graphics and the mesh-stream paths use host_blend, min(8) bounds the format index, and twin::integer's list matches the DXGI _UINT/_SINT formats.
  • The only requests are the test gap and the rustfmt hunks above.
  • The mesh path isn't exercised by a test, as the description says.

Not tested: physical GPU, mesh pipeline path on a device, retail title.

Both points are addressed in 100605f:

  • Test gap: with independent == false the fixture now describes only RenderTarget[0] and leaves RenderTarget[1..] at their defaults (unblended). With the [blend.RenderTarget[0]; 8] copy removed, integer_targets_write_unblended now fails at RenderTarget[1].BlendEnable; with it, both tests pass. (The device test still passes without the copy, as expected: the pipeline is valid, target 1 just loses its blending.)
  • rustfmt: the new code is formatted; pipeline/host.rs is back to main's 12 cargo fmt --check hunks, none in this change.

Re-checked on Windows 11 / RX 7900 XT: Clippy clean with and without --all-features, cargo test --workspace --locked 781 passed, 0 failed.

# Conflicts:
#	crates/victory-gpu/src/pipeline/host.rs

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The fix this PR first carried is now in main (host_blend in crates/victory-gpu/src/pipeline/host.rs, from #1152), and after merging main the diff only adds two tests: a_shared_blend_description_is_copied_to_every_target, which leaves RenderTarget[1..] at their defaults so it fails if the copy of target 0 is removed (the existing integer_targets_do_not_blend gives every entry the same blend and does not catch that), and the_host_takes_a_pipeline_blending_into_an_integer_target, which creates such a pipeline on the host device for both IndependentBlendEnable values. I checked both against main's host_blend and the default blend state; they are meaningful tests. No CI run is reported for the current head, and the title and description still describe the fix, so they would be best updated to say this is now tests only.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@steven-seagull27

Copy link
Copy Markdown

I checked the mesh dispatch from #2775 on head 36cfa002. The current head carries regression tests, and the production blend fix is already on main. With the D3D12 debug layer enabled, I dispatched a full-screen triangle through VIctory's mesh_pipeline and copied all three render targets back. This exercised the mixed formats together, with MAX blending requested by the guest.

Adapter Shared blend state Independent blend state
RTX 5080, driver 621.40 0 / 1,536 target pixels wrong 0 / 1,536 wrong
Windows WARP, 10.0.26100.10068 0 / 1,536 wrong 0 / 1,536 wrong

Counts are per run. All three repetitions on each adapter agreed. Each column includes a 16×16 full draw and a scissored draw covering 72 pixels, with the other 184 retaining their clear values. The drawn RGBA8 target read [191,192,128,255], the RGBA16F neighbor read [0.75,0.75,0.5,1], and the R8_UINT target in slot 2 changed from 201 to the shader's 17.

For a sensitivity check I locally removed just the shared-state copy for the RGBA16F neighbor. The mesh PSO still created and dispatched on both adapters. All 256 drawn pixels on that neighbor then differed in the full draw and exactly 72 differed in the scissored draw. The other targets and the independent-state cases stayed correct. That gives the shared-state regression test a concrete rendering consequence. These are synthetic mesh draws. I did not run the title.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified merged against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1) — clean and ready to merge:

  • Note that the production integer_format / host_blend changes from the first commit are already present on main (63bcca43), so merging this PR cleanly adds the two regression tests (a_shared_blend_description_is_copied_to_every_target and the_host_takes_a_pipeline_blending_into_an_integer_target), which directly validate live D3D12 PSO creation with blended integer render targets.

Local verification:

  • victory-gpu (pipeline::, draw::, VICTORY_D3D12_DEBUG=1): 45/45 passed on RTX 5090 (default) and 48/48 passed on WARP (--features diagnostics)
  • cargo clippy --all-targets -- -D warnings (default & --features diagnostics) + cargo xtask policy (191 files ok): 0 warnings

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • cargo test -p victory-gpu --lib pipeline::host::tests: 6 passed, 0 failed (including new a_shared_blend_description_is_copied_to_every_target and the_host_takes_a_pipeline_blending_into_an_integer_target).
  • 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

7 participants