[PR #1703] [MERGED] d3d12: dual-source blending reads SV_Target1 at Location 0, Index 1 (RT-DUAL-SOURCE-BLEND) #1717

Closed
opened 2026-11-26 21:18:43 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1703
Author: @OreoFR
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: rt-dual-source-blend


📝 Commits (10+)

  • 70d3517 d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE)
  • 2f44380 docs: state blob A's colour-target registers, measured over the library (RT-SLOT57-BLEND-STATE)
  • 4e7b764 d3d12_xs: integer render targets keep blending off in slot 57 native PSOs (RT-SLOT57-BLEND-STATE)
  • f557637 d3d12_xs: a native PSO whose blend state the device refuses is built with blending off on its stand-in targets (RT-SLOT57-BLEND-STATE)
  • 81f33de docs: the stand-in-target fallback of RT-SLOT57-BLEND-STATE
  • d763845 d3d12: dual-source blending reads SV_Target1 at Location 0, Index 1 (RT-DUAL-SOURCE-BLEND)
  • 0000242 runtime: register dual_source_fragment_test away from the slot 57 tests (RT-DUAL-SOURCE-BLEND)
  • 1943a92 d3d12: lazy pipelines keep the dual-source remap, and a dual-source draw test (RT-DUAL-SOURCE-BLEND review)
  • 188207a run_gpu_tests: ps_m15_dual is run by d3d12_translated_draw_test, like ps_m15 (RT-DUAL-SOURCE-BLEND review)
  • 668d65b d3d12_xs: slot 57 retries only a pipeline that blends a B4G4R4A4 stand-in (RT-SLOT57-BLEND-STATE review)

📊 Changes

14 files changed (+752 additions, -17 deletions)

View changed files

📝 docs/fspx.md (+47 -2)
📝 runtime/CMakeLists.txt (+18 -3)
📝 runtime/shims/d3d12_vulkan_device.cpp (+44 -3)
📝 runtime/shims/d3d12_xs_native_pso.h (+66 -2)
➕ runtime/shims/d3d12_xs_native_pso_fallback.h (+25 -0)
➕ runtime/src/dual_source_fragment.h (+59 -0)
📝 runtime/src/native_pso.h (+122 -1)
📝 runtime/test/d3d12_translated_draw_test.cpp (+34 -5)
➕ runtime/test/dual_source_fragment_test.cpp (+82 -0)
➕ runtime/test/native_pso_blend_test.cpp (+148 -0)
➕ runtime/test/native_pso_fallback_test.cpp (+73 -0)
➕ runtime/test/shaders/ps_m15_dual.asm (+31 -0)
📝 runtime/test/vk_test_device.h (+1 -0)
📝 scripts/run_gpu_tests.py (+2 -1)

📄 Description

Claimed in the coordination issue as: RT-DUAL-SOURCE-BLEND (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157103042)

Depends on: #1671, #1592

This builds on #1671: its commits are the first five here and drop out once it merges. Like #1671, it has a one-line #include conflict with #1592. It merges cleanly with #1691, which is also stacked on #1671. The real-boot test also used #1558 and #1547 to get past the landing screen on NVIDIA; this change doesn't need them.

What and why

D3D12 dual-source blending takes the second source from the pixel shader's SV_Target1. The translator declares SV_Target1 as the colour output at Location 1, which is right for two render targets. But Vulkan takes the second blend source from Location 0, Index 1 (VK_BLEND_FACTOR_SRC1_*, dualSrcBlend). So no PSO that blends with a SRC1 factor could be built correctly. #1671 therefore keeps the 1,937 slot 57 records that blend this way (CB_BLEND0 0xf1010f01: colour ONE/SRC1_COLOR, alpha ONE/SRC1_ALPHA, plus a few INV_SRC1 forms) on blending off.

  • runtime/src/dual_source_fragment.h (standard library only), dual_source::remap:
    • moves the fragment module's non-builtin Output at Location 1 to Location 0 and adds OpDecorate ... Index 1 next to it;
    • refuses, leaving the words unchanged, a module that has no such output, has an output at Location 2 or above (Vulkan has one dual-source attachment), or already carries an Index.
  • runtime/shims/d3d12_vulkan_device.cpp: when an enabled target's blend uses D3D12_BLEND_(INV_)SRC1_COLOR/ALPHA, the fragment module is remapped at pipeline creation, beside the existing B4G4R4A4 output rewrite. A refused module refuses the PSO through stream_unsupported, as today. This applies to every graphics PSO, not only slot 57 ones.
  • runtime/src/native_pso.h: #1671's blend mapping now takes the SRC1 factors (SRC1_COLOR / INV_SRC1_COLOR read as their alpha forms in the alpha factors). Only the BOTH_* factors and an unknown COMB_FCN stay refused.
  • runtime/test/dual_source_fragment_test.cpp (portable): hand-built word streams test the rewrite and each refusal. The input at Location 1 and the FragDepth builtin are left alone. native_pso_blend_test covers the SRC1 mappings. The layout note in docs/fspx.md is updated.

Tested

  • The game's own shaders. The 1,937 dual-source records use 1,457 distinct pixel shaders. All of them have their second colour output at Location 1 and nothing past it:

    • 1,378 have a module in the #1592 graphics census; each one, rewritten as above, passes spirv-val --target-env vulkan1.3;
    • the other 79 have no module because the translator refuses them for other reasons (v_interp_p2_f16 and similar).

    Aggregate counts only.

  • Real boot, retail 1.0.2.1, native Windows, with LEONIDA_VK_VALIDATION=1. Build: main + #1558 + #1547 + #1671 + this branch, fresh first-run profile, factory on.

    • The slot 57 dual-source pipelines, which the title creates at startup, are built with their decoded SRC1 blend: the "keeps blending off (CB_BLEND0 f1010f01)" lines are gone.
    • No pipeline is refused and the device isn't lost. The validation layer reported no pipeline or shader error; its one message is an unrelated, existing VUID-VkImageViewCreateInfo-image-12397 (a BC7 view of an RGBA16F image).
    • The first-run pages draw as with #1671.
    • These pipelines draw 3D content, so their visual effect can't be seen before a world frame.
  • ctest on Windows: dual_source_fragment, native_pso_blend, d3d12_pso_validation, xs_proxy_mock and xbox_native_base_draw pass.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 591.59 (32.0.15.9159), Windows 11

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase). It's stacked on #1671, as stated above.
  • 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. (Not a translator change: the rewrite happens at pipeline creation; the measurement is in docs/fspx.md.)

🤖 Generated with Claude Code


🔄 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/1703 **Author:** [@OreoFR](https://github.com/OreoFR) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `rt-dual-source-blend` --- ### 📝 Commits (10+) - [`70d3517`](https://github.com/ubiquitarianism/leonida/commit/70d351788924726089efac6344da8a49f8e45d39) d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) - [`2f44380`](https://github.com/ubiquitarianism/leonida/commit/2f44380590e9471cb44b15818ad2c2c422a2af21) docs: state blob A's colour-target registers, measured over the library (RT-SLOT57-BLEND-STATE) - [`4e7b764`](https://github.com/ubiquitarianism/leonida/commit/4e7b764dbc04fbd5343fb6c99224a8b0bec9ae9c) d3d12_xs: integer render targets keep blending off in slot 57 native PSOs (RT-SLOT57-BLEND-STATE) - [`f557637`](https://github.com/ubiquitarianism/leonida/commit/f5576377d1b2052277b406d2299c3a2692137173) d3d12_xs: a native PSO whose blend state the device refuses is built with blending off on its stand-in targets (RT-SLOT57-BLEND-STATE) - [`81f33de`](https://github.com/ubiquitarianism/leonida/commit/81f33de1cd307ac7cd7365724c55d27999888629) docs: the stand-in-target fallback of RT-SLOT57-BLEND-STATE - [`d763845`](https://github.com/ubiquitarianism/leonida/commit/d763845349ec7f36669f4b2bfa67e40576b88c8a) d3d12: dual-source blending reads SV_Target1 at Location 0, Index 1 (RT-DUAL-SOURCE-BLEND) - [`0000242`](https://github.com/ubiquitarianism/leonida/commit/0000242d8d1c44accedbe1a0ffc0ed1bb1c65687) runtime: register dual_source_fragment_test away from the slot 57 tests (RT-DUAL-SOURCE-BLEND) - [`1943a92`](https://github.com/ubiquitarianism/leonida/commit/1943a92f7be008f8f6873439425bc4ebcca4b578) d3d12: lazy pipelines keep the dual-source remap, and a dual-source draw test (RT-DUAL-SOURCE-BLEND review) - [`188207a`](https://github.com/ubiquitarianism/leonida/commit/188207a9d4df1d73a954bdf4d9471a6eed829d89) run_gpu_tests: ps_m15_dual is run by d3d12_translated_draw_test, like ps_m15 (RT-DUAL-SOURCE-BLEND review) - [`668d65b`](https://github.com/ubiquitarianism/leonida/commit/668d65b4b9cb74586176edb97a9379231153e4ff) d3d12_xs: slot 57 retries only a pipeline that blends a B4G4R4A4 stand-in (RT-SLOT57-BLEND-STATE review) ### 📊 Changes **14 files changed** (+752 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/fspx.md` (+47 -2) 📝 `runtime/CMakeLists.txt` (+18 -3) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+44 -3) 📝 `runtime/shims/d3d12_xs_native_pso.h` (+66 -2) ➕ `runtime/shims/d3d12_xs_native_pso_fallback.h` (+25 -0) ➕ `runtime/src/dual_source_fragment.h` (+59 -0) 📝 `runtime/src/native_pso.h` (+122 -1) 📝 `runtime/test/d3d12_translated_draw_test.cpp` (+34 -5) ➕ `runtime/test/dual_source_fragment_test.cpp` (+82 -0) ➕ `runtime/test/native_pso_blend_test.cpp` (+148 -0) ➕ `runtime/test/native_pso_fallback_test.cpp` (+73 -0) ➕ `runtime/test/shaders/ps_m15_dual.asm` (+31 -0) 📝 `runtime/test/vk_test_device.h` (+1 -0) 📝 `scripts/run_gpu_tests.py` (+2 -1) </details> ### 📄 Description Claimed in the coordination issue as: RT-DUAL-SOURCE-BLEND (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157103042) Depends on: #1671, #1592 This builds on #1671: its commits are the first five here and drop out once it merges. Like #1671, it has a one-line `#include` conflict with #1592. It merges cleanly with #1691, which is also stacked on #1671. The real-boot test also used #1558 and #1547 to get past the landing screen on NVIDIA; this change doesn't need them. ### What and why D3D12 dual-source blending takes the second source from the pixel shader's `SV_Target1`. The translator declares `SV_Target1` as the colour output at `Location 1`, which is right for two render targets. But Vulkan takes the second blend source from `Location 0, Index 1` (`VK_BLEND_FACTOR_SRC1_*`, `dualSrcBlend`). So no PSO that blends with a `SRC1` factor could be built correctly. #1671 therefore keeps the 1,937 slot 57 records that blend this way (`CB_BLEND0 0xf1010f01`: colour `ONE`/`SRC1_COLOR`, alpha `ONE`/`SRC1_ALPHA`, plus a few `INV_SRC1` forms) on blending off. - **`runtime/src/dual_source_fragment.h`** (standard library only), `dual_source::remap`: - moves the fragment module's non-builtin `Output` at `Location 1` to `Location 0` and adds `OpDecorate ... Index 1` next to it; - refuses, leaving the words unchanged, a module that has no such output, has an output at `Location 2` or above (Vulkan has one dual-source attachment), or already carries an `Index`. - **`runtime/shims/d3d12_vulkan_device.cpp`:** when an enabled target's blend uses `D3D12_BLEND_(INV_)SRC1_COLOR/ALPHA`, the fragment module is remapped at pipeline creation, beside the existing `B4G4R4A4` output rewrite. A refused module refuses the PSO through `stream_unsupported`, as today. This applies to every graphics PSO, not only slot 57 ones. - **`runtime/src/native_pso.h`:** #1671's blend mapping now takes the `SRC1` factors (`SRC1_COLOR` / `INV_SRC1_COLOR` read as their alpha forms in the alpha factors). Only the `BOTH_*` factors and an unknown `COMB_FCN` stay refused. - **`runtime/test/dual_source_fragment_test.cpp`** (portable): hand-built word streams test the rewrite and each refusal. The input at `Location 1` and the `FragDepth` builtin are left alone. `native_pso_blend_test` covers the `SRC1` mappings. The layout note in `docs/fspx.md` is updated. ### Tested - **The game's own shaders.** The 1,937 dual-source records use 1,457 distinct pixel shaders. All of them have their second colour output at `Location 1` and nothing past it: - 1,378 have a module in the #1592 graphics census; each one, rewritten as above, passes `spirv-val --target-env vulkan1.3`; - the other 79 have no module because the translator refuses them for other reasons (`v_interp_p2_f16` and similar). Aggregate counts only. - **Real boot, retail 1.0.2.1, native Windows,** with `LEONIDA_VK_VALIDATION=1`. Build: `main` + #1558 + #1547 + #1671 + this branch, fresh first-run profile, factory on. - The slot 57 dual-source pipelines, which the title creates at startup, are built with their decoded `SRC1` blend: the "keeps blending off (CB_BLEND0 f1010f01)" lines are gone. - No pipeline is refused and the device isn't lost. The validation layer reported no pipeline or shader error; its one message is an unrelated, existing `VUID-VkImageViewCreateInfo-image-12397` (a BC7 view of an RGBA16F image). - The first-run pages draw as with #1671. - These pipelines draw 3D content, so their visual effect can't be seen before a world frame. - **ctest on Windows:** `dual_source_fragment`, `native_pso_blend`, `d3d12_pso_validation`, `xs_proxy_mock` and `xbox_native_base_draw` pass. GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 591.59 (32.0.15.9159), Windows 11 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). It's stacked on #1671, as stated above. - [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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not a translator change: the rewrite happens at pipeline creation; the measurement is in `docs/fspx.md`.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:18:43 +01:00
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#1717
No description provided.