fix(victory-gpu): sanitize host_blend LogicOpEnable and stale RTFormats in PSO creation #447

Open
github-bot wants to merge 3 commits from github-bot/gh-447 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 18:57 UTC · original
mauroalvare:fix/victory-pso-blend-rtformats → main · +385 −16 · 1 files · 3 commits · open

Summary

Fixes two D3D12 graphics/mesh pipeline rejection bugs (CreateGraphicsPipelineState / CreatePipelineState returning E_INVALIDARG, 0x80070057) in third_party/victory/crates/victory-gpu/src/pipeline/host.rs:

  1. host_blend leaving LogicOpEnable = TRUE while promoting IndependentBlendEnable = TRUE:
    • When a pipeline had IndependentBlendEnable = false, RenderTarget[0].LogicOpEnable = true, and any integer/non-blendable render target (even a single R8_UINT target), host_blend previously set IndependentBlendEnable = true, copied RenderTarget[0] (including LogicOpEnable = true) into RenderTarget[1..8], and cleared LogicOpEnable only on slots matching integer(format).
    • That left LogicOpEnable = true on non-integer slots and unused DXGI_FORMAT_UNKNOWN slots (1..7) while IndependentBlendEnable = true, which D3D12 unconditionally rejects with E_INVALIDARG.
  2. Stale RTFormats[NumRenderTargets..8] in GraphicsState::read (subobject 15):
    • GraphicsState::read copied D3D12_RT_FORMAT_ARRAY without clamping NumRenderTargets to <= 8 or clearing unused RTFormats[NumRenderTargets..8] to DXGI_FORMAT_UNKNOWN.
    • Reused console stream structs with leftover non-zero formats past NumRenderTargets are rejected by PC D3D12 with E_INVALIDARG (and also caused host_blend to inspect inactive target slots).

What changed

  • GraphicsState::read (subobject 15) (third_party/victory/crates/victory-gpu/src/pipeline/host.rs): Clamp NumRenderTargets to <= 8, map formats via target_format(pc_format(...)) only for active targets 0..NumRenderTargets, and clear RTFormats[NumRenderTargets..8] to DXGI_FORMAT_UNKNOWN.
  • host_blend (third_party/victory/crates/victory-gpu/src/pipeline/host.rs):
    • Only promote IndependentBlendEnable = true when slot 0 has BlendEnable or LogicOpEnable active and there is a blendable active target alongside an integer/non-blendable target.
    • When all active targets are non-blendable/integer, disable BlendEnable and LogicOpEnable directly on RenderTarget[0] without enabling IndependentBlendEnable.
    • Whenever IndependentBlendEnable is true (originally or after promotion), clear LogicOpEnable = false across all 8 slots and keep unused DXGI_FORMAT_UNKNOWN slots unblended, while preserving blending on blendable targets (such as R8G8B8A8_UNORM).
  • Synthetic GPU regression tests (pipeline::host::tests in third_party/victory/crates/victory-gpu/src/pipeline/host.rs): Added three tests compiling real VS/PS shaders (D3DCompile, vs_5_1/ps_5_1), creating real D3D12 PSOs, executing draws on GPU, and checking readback pixels for:
    1. Single R8_UINT and mixed [R8G8B8A8_UNORM, R8_UINT] PSOs with LogicOpEnable = true and IndependentBlendEnable = false (verifying GPU readbacks 42, 255, and 77).
    2. Stream subobject 15 with NumRenderTargets = 1 and stale formats in RTFormats[1..3] (verifying PSO acceptance and GPU readback 255).
    3. Mixed [R8G8B8A8_UNORM, R8_UINT] with additive blending (ONE + ONE, verifying two 0.25 draws blend to ~128 on RT0 while RT1 receives unblended 9).

Reproduction and test results

  • Base commit: 91c15f2 (LooperSalty/AnyXboxX:main)
  • Hardware / environment: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2140), Rust 1.98.1.
  • All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (d3d12SDKLayers.dll) is not installed on this machine; validation checks real D3D12 CreateGraphicsPipelineState acceptance and GPU draw readbacks on both RTX 5070 Ti and WARP.

Before fix (base 91c15f2 + tests, RTX 5070 Ti)

cargo test --locked -p victory-gpu pipeline::host::tests -- --test-threads=1 --nocapture

Result: 3 passed, 2 failed:

  • host_blend_with_logic_op_and_integer_rt_creates_valid_pso_and_draws: FAILED — single R8_UINT PSO with LogicOpEnable must not be rejected: Error { code: HRESULT(0x80070057) }.
  • rt_format_array_clears_stale_formats_past_num_render_targets: FAILED — PSO with stale formats cleared past NumRenderTargets must succeed: Error { code: HRESULT(0x80070057) } (and g.targets.RTFormats[1] remained DXGI_FORMAT(62)).

After fix (synthetic tests)

Command Adapter / Mode Result
cargo test --locked -p victory-gpu pipeline:: -- --test-threads=1 --nocapture RTX 5070 Ti (default) 27 passed, 0 failed (0.46s)
VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics pipeline::host::tests -- --test-threads=1 RTX 5070 Ti (diagnostics) 5 passed, 0 failed (0.32s)
VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics pipeline::host::tests -- --test-threads=1 WARP (diagnostics) 5 passed, 0 failed (0.08s)
cargo test --locked -p victory-loader --test load_probe Smoke (hle-probe) 2 passed, 0 failed (0.13s)
cargo xtask policy (in third_party/victory) Asset policy asset policy: 215 files ok
cargo clippy --locked -p victory-gpu --tests Clippy 0 new warnings in pipeline/host.rs

AI assistance

Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code changes, synthetic GPU tests, and local RTX 5070 Ti and WARP runs were inspected and verified on this machine.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/447) `mauroalvare:fix/victory-pso-blend-rtformats` → `main` · +385 −16 · 1 files · 3 commits · open ## Summary Fixes two D3D12 graphics/mesh pipeline rejection bugs (`CreateGraphicsPipelineState` / `CreatePipelineState` returning `E_INVALIDARG`, `0x80070057`) in `third_party/victory/crates/victory-gpu/src/pipeline/host.rs`: 1. **`host_blend` leaving `LogicOpEnable = TRUE` while promoting `IndependentBlendEnable = TRUE`**: - When a pipeline had `IndependentBlendEnable = false`, `RenderTarget[0].LogicOpEnable = true`, and any integer/non-blendable render target (even a single `R8_UINT` target), `host_blend` previously set `IndependentBlendEnable = true`, copied `RenderTarget[0]` (including `LogicOpEnable = true`) into `RenderTarget[1..8]`, and cleared `LogicOpEnable` only on slots matching `integer(format)`. - That left `LogicOpEnable = true` on non-integer slots and unused `DXGI_FORMAT_UNKNOWN` slots (`1..7`) while `IndependentBlendEnable = true`, which D3D12 unconditionally rejects with `E_INVALIDARG`. 2. **Stale `RTFormats[NumRenderTargets..8]` in `GraphicsState::read` (subobject 15)**: - `GraphicsState::read` copied `D3D12_RT_FORMAT_ARRAY` without clamping `NumRenderTargets` to `<= 8` or clearing unused `RTFormats[NumRenderTargets..8]` to `DXGI_FORMAT_UNKNOWN`. - Reused console stream structs with leftover non-zero formats past `NumRenderTargets` are rejected by PC D3D12 with `E_INVALIDARG` (and also caused `host_blend` to inspect inactive target slots). ## What changed - **`GraphicsState::read` (subobject 15)** (`third_party/victory/crates/victory-gpu/src/pipeline/host.rs`): Clamp `NumRenderTargets` to `<= 8`, map formats via `target_format(pc_format(...))` only for active targets `0..NumRenderTargets`, and clear `RTFormats[NumRenderTargets..8]` to `DXGI_FORMAT_UNKNOWN`. - **`host_blend`** (`third_party/victory/crates/victory-gpu/src/pipeline/host.rs`): - Only promote `IndependentBlendEnable = true` when slot 0 has `BlendEnable` or `LogicOpEnable` active **and** there is a blendable active target alongside an integer/non-blendable target. - When all active targets are non-blendable/integer, disable `BlendEnable` and `LogicOpEnable` directly on `RenderTarget[0]` without enabling `IndependentBlendEnable`. - Whenever `IndependentBlendEnable` is `true` (originally or after promotion), clear `LogicOpEnable = false` across all 8 slots and keep unused `DXGI_FORMAT_UNKNOWN` slots unblended, while preserving blending on blendable targets (such as `R8G8B8A8_UNORM`). - **Synthetic GPU regression tests** (`pipeline::host::tests` in `third_party/victory/crates/victory-gpu/src/pipeline/host.rs`): Added three tests compiling real VS/PS shaders (`D3DCompile`, `vs_5_1`/`ps_5_1`), creating real D3D12 PSOs, executing draws on GPU, and checking readback pixels for: 1. Single `R8_UINT` and mixed `[R8G8B8A8_UNORM, R8_UINT]` PSOs with `LogicOpEnable = true` and `IndependentBlendEnable = false` (verifying GPU readbacks `42`, `255`, and `77`). 2. Stream subobject 15 with `NumRenderTargets = 1` and stale formats in `RTFormats[1..3]` (verifying PSO acceptance and GPU readback `255`). 3. Mixed `[R8G8B8A8_UNORM, R8_UINT]` with additive blending (`ONE + ONE`, verifying two `0.25` draws blend to `~128` on RT0 while RT1 receives unblended `9`). ## Reproduction and test results - **Base commit**: `91c15f2` (`LooperSalty/AnyXboxX:main`) - **Hardware / environment**: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `32.0.16.2140`), Rust `1.98.1`. - All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (`d3d12SDKLayers.dll`) is not installed on this machine; validation checks real D3D12 `CreateGraphicsPipelineState` acceptance and GPU draw readbacks on both RTX 5070 Ti and WARP. ### Before fix (base `91c15f2` + tests, RTX 5070 Ti) ```powershell cargo test --locked -p victory-gpu pipeline::host::tests -- --test-threads=1 --nocapture ``` Result: **3 passed, 2 failed**: - `host_blend_with_logic_op_and_integer_rt_creates_valid_pso_and_draws`: **FAILED** — `single R8_UINT PSO with LogicOpEnable must not be rejected: Error { code: HRESULT(0x80070057) }`. - `rt_format_array_clears_stale_formats_past_num_render_targets`: **FAILED** — `PSO with stale formats cleared past NumRenderTargets must succeed: Error { code: HRESULT(0x80070057) }` (and `g.targets.RTFormats[1]` remained `DXGI_FORMAT(62)`). ### After fix (synthetic tests) | Command | Adapter / Mode | Result | | --- | --- | --- | | `cargo test --locked -p victory-gpu pipeline:: -- --test-threads=1 --nocapture` | RTX 5070 Ti (default) | **27 passed, 0 failed** (0.46s) | | `VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics pipeline::host::tests -- --test-threads=1` | RTX 5070 Ti (`diagnostics`) | **5 passed, 0 failed** (0.32s) | | `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics pipeline::host::tests -- --test-threads=1` | WARP (`diagnostics`) | **5 passed, 0 failed** (0.08s) | | `cargo test --locked -p victory-loader --test load_probe` | Smoke (`hle-probe`) | **2 passed, 0 failed** (0.13s) | | `cargo xtask policy` (in `third_party/victory`) | Asset policy | **asset policy: 215 files ok** | | `cargo clippy --locked -p victory-gpu --tests` | Clippy | **0 new warnings in `pipeline/host.rs`** | ## AI assistance Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code changes, synthetic GPU tests, and local RTX 5070 Ti and WARP runs were inspected and verified on this machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:02:36 +00:00
github-bot force-pushed github-bot/gh-447 from 615429a652 to 854b138652 2026-11-26 19:50:49 +00:00 Compare
github-bot force-pushed github-bot/gh-447 from 854b138652 to 9b3a39ec1b 2026-11-27 00:37:45 +00:00 Compare
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 23:37 UTC · original

The Vice-Tay port is up in 9b3a39e. The PSO tests passed for mixed integer and UNORM targets, including a draw that checked the blend result. The target-count regression also passed and confirmed that unused format slots are cleared.

**@⁠mauroalvare** on GitHub · 2026-11-26 23:37 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/447#issuecomment-7205708589) The Vice-Tay port is up in `9b3a39e`. The PSO tests passed for mixed integer and UNORM targets, including a draw that checked the blend result. The target-count regression also passed and confirmed that unused format slots are cleared.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/447/head:github-bot/gh-447'
git switch 'github-bot/gh-447'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-447'
git switch 'github-bot/gh-447'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-447'
git switch 'github-bot/gh-447'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-447'
git switch 'main'
git merge --squash 'github-bot/gh-447'
git switch 'main'
git merge --ff-only 'github-bot/gh-447'
git switch 'main'
git merge 'github-bot/gh-447'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.