d3d12_xs: the stand-in blend fallback reads the blend state D3D12 applies #2368

Closed
github-bot wants to merge 2 commits from github-bot/gh-2368 into main AGit
Owner

@⁠ERROR890 on GitHub · 2026-11-26 16:11 UTC · original
ERROR890:fix/native-pso-standin-blend → main · +94 −7 · 2 files · 2 commits · closed without merging

Claimed in the coordination issue as: NATIVE-PSO-STANDIN-BLEND
(#1608)

Depends on: none.

Fixes: none.

What and why

without_stand_in_blend (runtime/shims/d3d12_xs_native_pso_fallback.h) decides whether a graphics pipeline is
retried with blending off on its B4G4R4A4 stand-in targets. It read BlendState.RenderTarget[i] for the target's own
index, but D3D12 only gives every target its own entry when IndependentBlendEnable is TRUE; with it FALSE,
RenderTarget[0] describes all of them and the rest are ignored. Two consequences:

  • a pipeline that does blend a stand-in target at index > 0 was never retried, because the ignored entry usually
    says no blend, so the pipeline stayed missing;
  • a pipeline that does not blend one could be retried because an ignored entry said it did.

The rewrite had the matching problem: it set IndependentBlendEnable = TRUE to turn blending off on the stand-in
alone, without first giving the other targets the state they inherited from RenderTarget[0], so turning the flag on
made each of them read its own (usually zeroed) entry and silently stop blending.

What changes:

  • the entry that applies to a target is RenderTarget[IndependentBlendEnable ? i : 0], and a target whose blend is a
    logic op counts too, since the layer's refusal tests BlendEnable || LogicOpEnable;
  • when the flag has to go on, RenderTarget[0] is copied into all eight entries first, and only then are blending and
    logic ops turned off on the stand-in targets;
  • independent blending on input behaves as before: only the stand-in target changes.

native_pso_fallback_test gains the cases: the stand-in at index > 0 under non-independent blending; the ignored
entry that must not cause a retry; the inherited state every other target keeps once the flag goes on; the independent
case where only the stand-in changes; and a stand-in whose blend is a logic op. The existing four cases still pass.

Testing

Built native_pso_fallback_test with MSVC 19.44 (Windows SDK 10.0.26100) on Windows 11 26H2, Ninja build.
With this change:  native_pso_fallback: ok  (exit 0)
On main:           7 assertions fail (the new cases), exit 1.
ctest -R "native_pso_fallback|native_pso_blend|native_pso_depth|pso_stream|process_cmdline" --output-on-failure:
100% tests passed, 0 tests failed out of 5.
Synthetic descriptor fixtures only. AI-assisted.

GPUs tested: n/a. This is a pure decision-logic change in a header plus its unit test; no Vulkan device, no D3D12
object and no game files are involved.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator
    change in this pull request.)
**@⁠ERROR890** on GitHub · 2026-11-26 16:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2368) `ERROR890:fix/native-pso-standin-blend` → `main` · +94 −7 · 2 files · 2 commits · closed without merging Claimed in the coordination issue as: NATIVE-PSO-STANDIN-BLEND (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) Depends on: none. Fixes: none. ### What and why `without_stand_in_blend` (`runtime/shims/d3d12_xs_native_pso_fallback.h`) decides whether a graphics pipeline is retried with blending off on its B4G4R4A4 stand-in targets. It read `BlendState.RenderTarget[i]` for the target's own index, but D3D12 only gives every target its own entry when `IndependentBlendEnable` is TRUE; with it FALSE, `RenderTarget[0]` describes all of them and the rest are ignored. Two consequences: - a pipeline that **does** blend a stand-in target at index > 0 was never retried, because the ignored entry usually says no blend, so the pipeline stayed missing; - a pipeline that does **not** blend one could be retried because an ignored entry said it did. The rewrite had the matching problem: it set `IndependentBlendEnable = TRUE` to turn blending off on the stand-in alone, without first giving the other targets the state they inherited from `RenderTarget[0]`, so turning the flag on made each of them read its own (usually zeroed) entry and silently stop blending. What changes: - the entry that applies to a target is `RenderTarget[IndependentBlendEnable ? i : 0]`, and a target whose blend is a logic op counts too, since the layer's refusal tests `BlendEnable || LogicOpEnable`; - when the flag has to go on, `RenderTarget[0]` is copied into all eight entries first, and only then are blending and logic ops turned off on the stand-in targets; - independent blending on input behaves as before: only the stand-in target changes. `native_pso_fallback_test` gains the cases: the stand-in at index > 0 under non-independent blending; the ignored entry that must not cause a retry; the inherited state every other target keeps once the flag goes on; the independent case where only the stand-in changes; and a stand-in whose blend is a logic op. The existing four cases still pass. ### Testing ``` Built native_pso_fallback_test with MSVC 19.44 (Windows SDK 10.0.26100) on Windows 11 26H2, Ninja build. With this change: native_pso_fallback: ok (exit 0) On main: 7 assertions fail (the new cases), exit 1. ctest -R "native_pso_fallback|native_pso_blend|native_pso_depth|pso_stream|process_cmdline" --output-on-failure: 100% tests passed, 0 tests failed out of 5. Synthetic descriptor fixtures only. AI-assisted. ``` GPUs tested: n/a. This is a pure decision-logic change in a header plus its unit test; no Vulkan device, no D3D12 object and no game files are involved. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change in this pull request.)
`without_stand_in_blend` decides whether a graphics pipeline is retried with blending off on its B4G4R4A4 stand-in
targets, and it read `BlendState.RenderTarget[i]` for the target's own index. D3D12 only gives every target its own
entry when `IndependentBlendEnable` is TRUE; with it FALSE, `RenderTarget[0]` describes all of them and the others are
ignored. So a pipeline that blends a stand-in target at index > 0 was never retried (the ignored entry usually says
no blend), and a pipeline that does not blend one could be retried because an ignored entry said it did.

The rewrite had the matching problem: it set `IndependentBlendEnable = TRUE` to turn blending off on the stand-in
alone, without first giving the other targets the state they inherited from `RenderTarget[0]`. Turning the flag on
made each of them read its own (usually zeroed) entry, so those targets silently stopped blending.

Read the entry that applies to each target, and when the flag has to go on, copy `RenderTarget[0]` into all eight
entries first and then turn blending and logic ops off on the stand-in targets only. Logic ops count as blending
here because the layer's refusal tests both.

`native_pso_fallback_test` covers the three shapes: the stand-in at index > 0 under non-independent blending, the
ignored entry that must not cause a retry, the inherited state every other target keeps once the flag goes on, the
independent case where only the stand-in changes, and a stand-in target whose blend is a logic op.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:12:08 +00:00
github-bot closed this pull request 2026-11-26 19:36:08 +00:00
Author
Owner

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

Closing as a duplicate of #2038 ("runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback"), which was opened first, covers the same three cases in the same two files, and has a more thorough write-up. Per CONTRIBUTING.md, the earlier pull request is the one that lands; mine adds nothing that #2038 does not already do in the read and the rewrite.

One gap in #2038 that is worth folding in (posted there as a review note): the layer's refusal tests blend.BlendEnable || blend.LogicOpEnable, so a stand-in target whose blend is a logic op is refused too, and without_stand_in_blend has to look for LogicOpEnable as well when it decides whether the refusal was the stand-in's, and turn it off on the stand-in target. My branch did that, along with the existing four cases:

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;

with a test case where RenderTarget[0] has BlendEnable = FALSE, LogicOpEnable = TRUE on a B4G4R4A4 target: without_stand_in_blend must return true, clear the logic op on the stand-in, and leave the inherited state on the target that is not a stand-in. Feel free to take it from branch fix/native-pso-standin-blend in this fork if that is easier.

Thanks for the prior art — I missed it when checking the open pull requests before writing mine.

No further work is planned on this branch.

**@⁠ERROR890** on GitHub · 2026-11-26 19:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2368#issuecomment-7201344447) Closing as a duplicate of #2038 ("runtime: respect IndependentBlendEnable=FALSE in B4G4R4A4 stand-in blend fallback"), which was opened first, covers the same three cases in the same two files, and has a more thorough write-up. Per CONTRIBUTING.md, the earlier pull request is the one that lands; mine adds nothing that #2038 does not already do in the read and the rewrite. One gap in #2038 that is worth folding in (posted there as a review note): the layer's refusal tests `blend.BlendEnable || blend.LogicOpEnable`, so a stand-in target whose blend is a logic op is refused too, and `without_stand_in_blend` has to look for `LogicOpEnable` as well when it decides whether the refusal was the stand-in's, and turn it off on the stand-in target. My branch did that, along with the existing four cases: ```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; ``` with a test case where `RenderTarget[0]` has `BlendEnable = FALSE, LogicOpEnable = TRUE` on a `B4G4R4A4` target: `without_stand_in_blend` must return true, clear the logic op on the stand-in, and leave the inherited state on the target that is not a stand-in. Feel free to take it from branch `fix/native-pso-standin-blend` in this fork if that is easier. Thanks for the prior art — I missed it when checking the open pull requests before writing mine. No further work is planned on this branch.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.