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

Open
github-bot wants to merge 1 commit from github-bot/gh-2038 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 18:44 UTC · original
IlyassRS3:fix/rt-native-pso-fallback-independent-blend → main · +90 −5 · 2 files · 1 commits · open

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.
**@⁠IlyassRS3** on GitHub · 2026-11-25 18:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2038) `IlyassRS3:fix/rt-native-pso-fallback-independent-blend` → `main` · +90 −5 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:15:45 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 18:45 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 18:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2038#pullrequestreview-6063120940) · **reviewed** 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.
Author
Owner

@⁠ERROR890 on GitHub · 2026-11-26 19:14 UTC · original

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.

**@⁠ERROR890** on GitHub · 2026-11-26 19:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2038#issuecomment-7201343946) 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.
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/2038/head:github-bot/gh-2038'
git switch 'github-bot/gh-2038'

Merge

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