[PR #2038] runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback #2044

Open
opened 2026-11-26 21:19:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2038
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-native-pso-fallback-independent-blend


📝 Commits (1)

  • 52d768a runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback

📊 Changes

2 files changed (+90 additions, -5 deletions)

View changed files

📝 runtime/shims/d3d12_xs_native_pso_fallback.h (+20 -5)
📝 runtime/test/native_pso_fallback_test.cpp (+70 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2038 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-native-pso-fallback-independent-blend` --- ### 📝 Commits (1) - [`52d768a`](https://github.com/ubiquitarianism/leonida/commit/52d768a0dc370128cf6e4f71adfb656ce5317c68) runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback ### 📊 Changes **2 files changed** (+90 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_xs_native_pso_fallback.h` (+20 -5) 📝 `runtime/test/native_pso_fallback_test.cpp` (+70 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2044
No description provided.