runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback #2038

Merged
leonida/mandy
quietfold merged 1 commit from fix/rt-native-pso-fallback-independent-blend into main 2026-11-28 17:53:13 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 18:44:59 +00:00

Coordination item: RT-NATIVE-PSO-FALLBACK-INDEPENDENT-BLEND (claimed on #1608).

Why

In D3D12, when D3D12_BLEND_DESC::IndependentBlendEnable == FALSE, RenderTarget[0] governs every active render target (0..NumRenderTargets-1) and RenderTarget[1..7] are ignored (typically left zero-initialized by the title).

rt::d3d12_xs::native_pipeline_detail::without_stand_in_blend() in runtime/shims/d3d12_xs_native_pso_fallback.h previously inspected RenderTarget[i].BlendEnable directly and then set IndependentBlendEnable = TRUE without replicating RenderTarget[0] into RenderTarget[1..7], causing three bugs whenever IndependentBlendEnable == FALSE:

  1. Silently zeroed non-B4G4R4A4 targets (broken rendering): if slot 0 is B4G4R4A4_UNORM and slot 1 is R8G8B8A8_UNORM with RenderTarget[1] zero-initialized, flipping IndependentBlendEnable = TRUE leaves slot 1 with BlendEnable = FALSE and RenderTargetWriteMask = 0 (masking out all colour writes to slot 1).
  2. Missed fallback retry (permanent E_NOTIMPL): if slot 0 is R8G8B8A8_UNORM and slot 1 is B4G4R4A4_UNORM with RenderTarget[0].BlendEnable = TRUE and RenderTarget[1] zero-initialized, slot 1 is effectively blended by D3D12 rules, yet without_stand_in_blend() saw RenderTarget[1].BlendEnable == FALSE and returned false.
  3. Spurious retry on stale RenderTarget[1..7]: if RenderTarget[0].BlendEnable == FALSE and ignored RenderTarget[1].BlendEnable == TRUE on a B4G4R4A4_UNORM target, it falsely triggered the fallback even though blending was off.

Changes

  • runtime/shims/d3d12_xs_native_pso_fallback.h: check effective blend (RenderTarget[independent ? i : 0].BlendEnable), replicate RenderTarget[0] to RenderTarget[1..7] before setting IndependentBlendEnable = TRUE when !independent, and then turn off BlendEnable only on active DXGI_FORMAT_B4G4R4A4_UNORM targets.
  • runtime/test/native_pso_fallback_test.cpp: add 4 regression cases covering all three IndependentBlendEnable == FALSE bugs plus distinct per-target write-mask preservation when IndependentBlendEnable == TRUE.

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind).
  • GPUs tested: none (CPU-only unit tests on macOS arm64 using minimal local d3d12.h blend/PSO struct stubs; Windows CTest builds against real Windows SDK headers).
  • Compiled and ran runtime/test/native_pso_fallback_test.cpp directly with clang++ -std=c++20 -Wall -Wextra -Werror:
    • ASan+UBSan (-O1 -g -fsanitize=address,undefined): native_pso_fallback: ok.
    • TSan (-O1 -g -fsanitize=thread): native_pso_fallback: ok.
    • Release (-O2): native_pso_fallback: ok.
  • Negative control against main's d3d12_xs_native_pso_fallback.h: fails all 3 new IndependentBlendEnable == FALSE regression tests (exit 1).
  • python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_native_pso_fallback.h runtime/test/native_pso_fallback_test.cpp: clean.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
Coordination item: `RT-NATIVE-PSO-FALLBACK-INDEPENDENT-BLEND` (claimed on #1608). ### Why In D3D12, when `D3D12_BLEND_DESC::IndependentBlendEnable == FALSE`, `RenderTarget[0]` governs every active render target (`0..NumRenderTargets-1`) and `RenderTarget[1..7]` are ignored (typically left zero-initialized by the title). `rt::d3d12_xs::native_pipeline_detail::without_stand_in_blend()` in `runtime/shims/d3d12_xs_native_pso_fallback.h` previously inspected `RenderTarget[i].BlendEnable` directly and then set `IndependentBlendEnable = TRUE` without replicating `RenderTarget[0]` into `RenderTarget[1..7]`, causing three bugs whenever `IndependentBlendEnable == FALSE`: 1. **Silently zeroed non-B4G4R4A4 targets (broken rendering):** if slot 0 is `B4G4R4A4_UNORM` and slot 1 is `R8G8B8A8_UNORM` with `RenderTarget[1]` zero-initialized, flipping `IndependentBlendEnable = TRUE` leaves slot 1 with `BlendEnable = FALSE` and `RenderTargetWriteMask = 0` (masking out all colour writes to slot 1). 2. **Missed fallback retry (permanent `E_NOTIMPL`):** if slot 0 is `R8G8B8A8_UNORM` and slot 1 is `B4G4R4A4_UNORM` with `RenderTarget[0].BlendEnable = TRUE` and `RenderTarget[1]` zero-initialized, slot 1 is effectively blended by D3D12 rules, yet `without_stand_in_blend()` saw `RenderTarget[1].BlendEnable == FALSE` and returned `false`. 3. **Spurious retry on stale `RenderTarget[1..7]`:** if `RenderTarget[0].BlendEnable == FALSE` and ignored `RenderTarget[1].BlendEnable == TRUE` on a `B4G4R4A4_UNORM` target, it falsely triggered the fallback even though blending was off. ### Changes - `runtime/shims/d3d12_xs_native_pso_fallback.h`: check effective blend (`RenderTarget[independent ? i : 0].BlendEnable`), replicate `RenderTarget[0]` to `RenderTarget[1..7]` before setting `IndependentBlendEnable = TRUE` when `!independent`, and then turn off `BlendEnable` only on active `DXGI_FORMAT_B4G4R4A4_UNORM` targets. - `runtime/test/native_pso_fallback_test.cpp`: add 4 regression cases covering all three `IndependentBlendEnable == FALSE` bugs plus distinct per-target write-mask preservation when `IndependentBlendEnable == TRUE`. ### Verification - AI-assisted: yes (Antigravity agent by Google DeepMind). - GPUs tested: none (CPU-only unit tests on macOS arm64 using minimal local `d3d12.h` blend/PSO struct stubs; Windows CTest builds against real Windows SDK headers). - Compiled and ran `runtime/test/native_pso_fallback_test.cpp` directly with `clang++ -std=c++20 -Wall -Wextra -Werror`: - ASan+UBSan (`-O1 -g -fsanitize=address,undefined`): `native_pso_fallback: ok`. - TSan (`-O1 -g -fsanitize=thread`): `native_pso_fallback: ok`. - Release (`-O2`): `native_pso_fallback: ok`. - Negative control against `main`'s `d3d12_xs_native_pso_fallback.h`: fails all 3 new `IndependentBlendEnable == FALSE` regression tests (exit 1). - `python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_native_pso_fallback.h runtime/test/native_pso_fallback_test.cpp`: clean. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK.
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 18:45:12 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
ERROR890 commented 2026-11-26 19:14:01 +00:00

Review note from a duplicate pull request I opened before I found this one (#2368, now closed):

The layer's refusal at the stand-in checks both fields:

const auto& blend = desc.BlendState.RenderTarget[desc.BlendState.IndependentBlendEnable ? i : 0];
if (blend.BlendEnable || blend.LogicOpEnable) return E_NOTIMPL;

so a stand-in target whose blend is a logic op (BlendEnable = FALSE, LogicOpEnable = TRUE) is refused as well, and without_stand_in_blend should treat it as the stand-in's refusal and clear it:

const D3D12_RENDER_TARGET_BLEND_DESC& entry = blend.RenderTarget[blend.IndependentBlendEnable ? i : 0];
if (entry.BlendEnable || entry.LogicOpEnable) changed = true;
...
rewritten.RenderTarget[i].BlendEnable = FALSE;
rewritten.RenderTarget[i].LogicOpEnable = FALSE;

A test case that pins it: IndependentBlendEnable = FALSE, RenderTarget[0].BlendEnable = FALSE, RenderTarget[0].LogicOpEnable = TRUE, RTVFormats = {B4G4R4A4_UNORM, R8G8B8A8_UNORM}. Expect true, the logic op cleared on the stand-in, and RenderTarget[1] keeping the state it inherited from RenderTarget[0] (a logic op, since BlendEnable was false). Without the LogicOpEnable clause the helper returns false and the pipeline stays missing.

There is a branch with exactly that on it, fix/native-pso-standin-blend in ERROR890/leonida, if it is useful; take it or ignore it. Everything else here looks right to me.

Review note from a duplicate pull request I opened before I found this one (#2368, now closed): The layer's refusal at the stand-in checks both fields: ```cpp const auto& blend = desc.BlendState.RenderTarget[desc.BlendState.IndependentBlendEnable ? i : 0]; if (blend.BlendEnable || blend.LogicOpEnable) return E_NOTIMPL; ``` so a stand-in target whose blend is a **logic op** (`BlendEnable = FALSE`, `LogicOpEnable = TRUE`) is refused as well, and `without_stand_in_blend` should treat it as the stand-in's refusal and clear it: ```cpp const D3D12_RENDER_TARGET_BLEND_DESC& entry = blend.RenderTarget[blend.IndependentBlendEnable ? i : 0]; if (entry.BlendEnable || entry.LogicOpEnable) changed = true; ... rewritten.RenderTarget[i].BlendEnable = FALSE; rewritten.RenderTarget[i].LogicOpEnable = FALSE; ``` A test case that pins it: `IndependentBlendEnable = FALSE`, `RenderTarget[0].BlendEnable = FALSE`, `RenderTarget[0].LogicOpEnable = TRUE`, `RTVFormats = {B4G4R4A4_UNORM, R8G8B8A8_UNORM}`. Expect `true`, the logic op cleared on the stand-in, and `RenderTarget[1]` keeping the state it inherited from `RenderTarget[0]` (a logic op, since `BlendEnable` was false). Without the `LogicOpEnable` clause the helper returns false and the pipeline stays missing. There is a branch with exactly that on it, `fix/native-pso-standin-blend` in ERROR890/leonida, if it is useful; take it or ignore it. Everything else here looks right to me.
zmasi commented 2026-11-28 11:35:32 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main 4a54aedcb + 52d768a0d (claim #2570#issuecomment-7238618828):

  • Line-by-line diff audit: Clean (runtime/shims/d3d12_xs_native_pso_fallback.h, runtime/test/native_pso_fallback_test.cpp); evaluates effective target blend via RenderTarget[independent ? i : 0] and replicates RenderTarget[0] across RenderTarget[1..7] before setting IndependentBlendEnable = TRUE when IndependentBlendEnable == FALSE, preserving non-B4G4R4A4 blend state and write masks while ignoring stale RenderTarget[1..7] entries when RenderTarget[0].BlendEnable == FALSE. check_no_game_data.py clean.
  • Red (4a54aedcb + PR test): native_pso_fallback_test.exe fails (rc=1, 6 failures on IndependentBlendEnable == FALSE shared blend / stale RenderTarget[1].BlendEnable).
  • Green (4a54aedcb + 52d768a0d merge): Merges cleanly (rc=0), compiles with 0 /W4 warnings, and native_pso_fallback_test.exe passes (native_pso_fallback: ok, rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `4a54aedcb` + `52d768a0d` (claim `#2570#issuecomment-7238618828`): - **Line-by-line diff audit**: Clean (`runtime/shims/d3d12_xs_native_pso_fallback.h`, `runtime/test/native_pso_fallback_test.cpp`); evaluates effective target blend via `RenderTarget[independent ? i : 0]` and replicates `RenderTarget[0]` across `RenderTarget[1..7]` before setting `IndependentBlendEnable = TRUE` when `IndependentBlendEnable == FALSE`, preserving non-`B4G4R4A4` blend state and write masks while ignoring stale `RenderTarget[1..7]` entries when `RenderTarget[0].BlendEnable == FALSE`. `check_no_game_data.py` clean. - **Red (`4a54aedcb` + PR test)**: `native_pso_fallback_test.exe` fails (`rc=1`, 6 failures on `IndependentBlendEnable == FALSE` shared blend / stale `RenderTarget[1].BlendEnable`). - **Green (`4a54aedcb` + `52d768a0d` merge)**: Merges cleanly (`rc=0`), compiles with `0` `/W4` warnings, and `native_pso_fallback_test.exe` passes (`native_pso_fallback: ok`, `rc=0`). AI-assisted.
MoonEyes commented 2026-11-28 17:53:10 +00:00

Red/green: On main native_pso_fallback_test fails 6 checks (with IndependentBlendEnable=FALSE the stand-in fallback reads stale RenderTarget[1..7] instead of RenderTarget[0]), and with the PR ctest -R "^native_pso_fallback$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

Red/green: On main native_pso_fallback_test fails 6 checks (with IndependentBlendEnable=FALSE the stand-in fallback reads stale RenderTarget[1..7] instead of RenderTarget[0]), and with the PR ctest -R "^native_pso_fallback$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:58:42 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head 52d768a0d; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: ctest -R ^native_pso_fallback$
  • Red on main: 6 failures (slot 1 inherits RenderTarget[0]'s blend when IndependentBlendEnable=FALSE)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `52d768a0d`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `ctest -R ^native_pso_fallback$` - Red on main: 6 failures (slot 1 inherits RenderTarget[0]'s blend when IndependentBlendEnable=FALSE) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.