d3d12: dual-source blending reads SV_Target1 at Location 0, Index 1 (RT-DUAL-SOURCE-BLEND) #1703
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1703
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1703/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@OreoFR on GitHub · 2026-11-25 08:46 UTC · original
OreoFR:rt-dual-source-blend→main· +752 −17 · 14 files · 11 commits · merged 2026-11-25 13:46 UTCClaimed in the coordination issue as: RT-DUAL-SOURCE-BLEND (#1608)
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
#includeconflict 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 declaresSV_Target1as the colour output atLocation 1, which is right for two render targets. But Vulkan takes the second blend source fromLocation 0, Index 1(VK_BLEND_FACTOR_SRC1_*,dualSrcBlend). So no PSO that blends with aSRC1factor could be built correctly. #1671 therefore keeps the 1,937 slot 57 records that blend this way (CB_BLEND0 0xf1010f01: colourONE/SRC1_COLOR, alphaONE/SRC1_ALPHA, plus a fewINV_SRC1forms) on blending off.runtime/src/dual_source_fragment.h(standard library only),dual_source::remap:OutputatLocation 1toLocation 0and addsOpDecorate ... Index 1next to it;Location 2or above (Vulkan has one dual-source attachment), or already carries anIndex.runtime/shims/d3d12_vulkan_device.cpp: when an enabled target's blend usesD3D12_BLEND_(INV_)SRC1_COLOR/ALPHA, the fragment module is remapped at pipeline creation, beside the existingB4G4R4A4output rewrite. A refused module refuses the PSO throughstream_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 theSRC1factors (SRC1_COLOR/INV_SRC1_COLORread as their alpha forms in the alpha factors). Only theBOTH_*factors and an unknownCOMB_FCNstay refused.runtime/test/dual_source_fragment_test.cpp(portable): hand-built word streams test the rewrite and each refusal. The input atLocation 1and theFragDepthbuiltin are left alone.native_pso_blend_testcovers theSRC1mappings. The layout note indocs/fspx.mdis 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 1and nothing past it:spirv-val --target-env vulkan1.3;v_interp_p2_f16and 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.SRC1blend: the "keeps blending off (CB_BLEND0 f1010f01)" lines are gone.VUID-VkImageViewCreateInfo-image-12397(a BC7 view of an RGBA16F image).ctest on Windows:
dual_source_fragment,native_pso_blend,d3d12_pso_validation,xs_proxy_mockandxbox_native_base_drawpass.GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 591.59 (32.0.15.9159), Windows 11
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase). It's stacked on #1671, as stated above.docs/design.md, with how it was confirmed. (Not a translator change: the rewrite happens at pipeline creation; the measurement is indocs/fspx.md.)🤖 Generated with Claude Code
@kawaii-shakal on GitHub · 2026-11-25 09:45 UTC · original · reviewed
Review (read-only, not run): one likely bug in the lazy path.
Lazy pipelines lose the dual-source remap.
PipelineStateremaps the fragment module (dual_source::remap(stage.words)) at creation. But graphics pipelines are lazy by default (lazy_graphics_pipelines(), off only withLEONIDA_LAZY_PIPELINES=0). When a lazy pipeline is first drawn,build()gets its SPIR-V again throughstage_words(), andstage_words()replaysrgba4::quantize(rgba4_mask_),link_f16_halvesanddepth24_patch_fragment, but not the dual-source remap. With the default settings a dual-source pipeline is therefore built withSV_Target1still atLocation 1andSRC1blend factors, which is invalid in Vulkan (the second source has to come fromLocation 0, Index 1). The blend reads an undefined second source, or a driver refuses the pipeline.Suggested fix: keep a
dual_source_flag next torgba4_mask_and applyleonida::dual_source::remap(words[i])to the fragment stage (source.slot == 2) instage_words(), failing the same way. A ctest that creates a dual-source PSO with lazy pipelines on and draws it once would catch it.If the slot 57 factory's pipelines never take the lazy path, please say so in the PR; the PC
CreateGraphicsPipelineStatepath does.Checked and fine:
spirv()returns a copy, so the in-place remap does not leak into other pipelines that share the pixel shader.dualSrcBlendis already required and enabled on main (d3d12_vulkan_device.cpp~7705 and ~16450).AI-assisted review (Claude Code, Claude Opus 5.5).
@OreoFR on GitHub · 2026-11-25 10:09 UTC · original
@kawaii-shakal thanks, that was a real bug. Fixed in
1943a92f7:rewrite_fragment(): theB4G4R4A4quantisation, then theLocation 0, Index 1remap under a newdual_source_flag. Both the creation path andstage_words()call it, so a lazybuild()makes the same words as creation, and a refusal fails the same way in both.d3d12_translated_draw_test --dual-sourcedrawsps_m15_dual.asm, which is ps_m15 plus a constantSV_Target1(0.5), withONE+SRC1_COLOR/SRC1_ALPHAover the clear colour. Every covered pixel must be exact. It runs twice, lazily (d3d12_dual_source_draw) and at creation (d3d12_dual_source_draw_eager,LEONIDA_LAZY_PIPELINES=0). The test device now enablesdualSrcBlendwhere the GPU has it, and the test exits 77 where it doesn't.ps_m15_dualcarries one more FSSM data word, because the layer finds a PSO's shader by FSSM hash and it would otherwise collide with ps_m15's.Location 1as the second source. So the colours alone don't catch it, butLEONIDA_VK_VALIDATION=1does, with 3 errors on the secondary-color-input / maxLocationrule. With the fix, it's clean and all 4,064 covered pixels are exact.The slot 57 factory goes through the same PC
CreatePipelineStatepath, so it was affected too.AI-assisted.
@potatoe0100 on GitHub · 2026-11-25 11:01 UTC · original
Tested
1943a92f7merged ontomainbcaa13dad(clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, llvm-mc 21.1.8.ctest -j 6: all pass, includingd3d12_dual_source_draw,d3d12_dual_source_draw_eager,d3d12_translated_draw,dual_source_fragmentandnative_pso_blend.run_gpu_tests.py: one new failure vsmain. The newps_m15_dual.asmis picked up by the generic pixel-shader harness, and on this GPU it ends in a lost device, every time (3 of 3):ps_m15is listed inOTHER_HARNESSinscripts/run_gpu_tests.py(run byd3d12_translated_draw_test) butps_m15_dualisn't. With"ps_m15_dual": "d3d12_translated_draw_test"added there locally, the suite is back tomain's result: 209/264 passed, 54 skipped,SKIP ps_m15_dual (run by d3d12_translated_draw_test).AI-assisted testing (non-developer tester).
@OreoFR on GitHub · 2026-11-25 11:10 UTC · original
@potatoe0100 thanks, good catch.
ps_m15_dualis now inOTHER_HARNESSnext tops_m15(188207a9d):run_gpu_tests.pystill assembles and translates it, andd3d12_translated_draw_test --dual-sourcejudges the draw. The generic pixel-shader harness has no second colour target orSRC1blend for it, which is presumably why the 4060 lost the device.tests/test_run_gpu_tests.pypasses (68 tests).AI-assisted.
@adrianmjim on GitHub · 2026-11-25 11:24 UTC · original
Tested
1943a92f7applied ontomain42537e7b6;188207a9dsince then only adds theOTHER_HARNESSentry. The test machine is AMD: Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo. No game files.The new draw tests pass on AMD.
d3d12_dual_source_draw(lazy) andd3d12_dual_source_draw_eagerboth printSV_Target1 blended as the second source (ONE + SRC1_COLOR / SRC1_ALPHA), 4064 of 4096 pixels exact. Withdual_source_fragment,native_pso_blend,d3d12_translated_draw,d3d12_pso_validation,d3d12_state_sweepandxbox_native_base_drawthat makes 8 of 8 pass, plain and withLEONIDA_VK_VALIDATION=1(validation on, no messages). So therewrite_fragment()fix works on this driver in both modes.Whole
ctest -j 6: 401 of 406 pass or skip. Three failures are the same as onmain:d3d12_texture_tiles,d3d12_clearandd3d12_geometry_views.xmemandxmem_write_watchfailed once under-j 6and pass 3 of 3 alone. They are load-sensitive and have failed like that on other trees here too.I did not run
ps_m15_dualthroughrun_gpu_tests.py. The lost device on the RTX 4060 above comes from the generic pixel harness picking it up, and188207a9d'sOTHER_HARNESSentry fixes that.One thing that is still there: the slot 57 blend fallback fires on any
E_NOTIMPL.if (hr == E_NOTIMPL && plan.state.blend)retries with blending off on B4G4R4A4 targets, and then on every target.E_NOTIMPLis also whatstream_unsupported()and a few direct returns give for refusals that have nothing to do with B4G4R4A4: rect lists without the geometryShader feature or whose geometry stage can't be generated, mesh limits, two stages reading their code base, FullyCovered. This PR's own "outputs do not fit Location 0 Index 1" refusal is caught too, and the retry then turns the SRC1 blend off.For any of those, a pipeline whose decoded blend differs from the default is retried with blending off. If the refusal had nothing to do with blending, that retry fails the same way, but the log still says "the device refused this pipeline's blend state". If it does succeed, the pipeline draws without the blending the title asked for. Checking that the refusal was the B4G4R4A4 one, for example with a distinct HRESULT or a flag set where that refusal is made, would keep the fallback to the case it is meant for.
@MoonEyes on GitHub · 2026-11-25 11:33 UTC · original · reviewed
Built and tested on Windows 11 with MSVC 19.44 (
scripts\build_runtime.ps1, incremental on the same build tree, after #1691), NVIDIA GeForce RTX 4060, driver 610.88. Head188207a9d(it carries #1671's commits; branch point main3f81d46ac, not merged with current main237deb64c).ctest -R "native_pso|dual_source|translated_draw|xs_proxy_mock|xbox_native_base_draw": 15/15 passed, includingdual_source_fragment,native_pso_blend, and the GPU drawsd3d12_translated_draw,xbox_native_base_draw,d3d12_dual_source_drawandd3d12_dual_source_draw_eager.Not checked: the dual-source result in a real world frame, which needs a world frame my setup does not reach yet.
AI-assisted: yes (Claude Code ran the build and the tests; I read the results).
@kawaii-shakal on GitHub · 2026-11-25 11:57 UTC · original
Tested as part of the #1671 + #1691 + #1703 stack (
188207a9d) onmainbcaa13dad, in a real boot on an RTX 5070 Ti (NVIDIA 617.42, Windows 11). Menu text renders as glyphs instead of solid blocks, and no pipeline is refused. Details: #1671. AI-assisted (Claude Code, Claude Opus 5.5).@OreoFR on GitHub · 2026-11-25 12:03 UTC · original
@adrianmjim thanks for the AMD run, and you're right about the fallback. Fixed in #1671 (
668d65b4b), merged into this branch (b19b00e88) and #1691 (7a769396d):B4G4R4A4target is retried, with blending off on those targets alone (without_stand_in_blend, in its own headerd3d12_xs_native_pso_fallback.h). Any otherE_NOTIMPLis returned as it is, with the blend the title asked for. That includes this PR's "does not fit Location 0 Index 1" refusal.B4G4R4A4step.native_pso_fallbacktest covers the decision: a blendedB4G4R4A4target is retried, while noB4G4R4A4target, aB4G4R4A4target that doesn't blend, or one pastNumRenderTargetsleaves the description untouched.On
main0d80bc5df+ the three PRs (RTX 4070 Laptop, NVIDIA 621.40),ctest -R "native_pso|dual_source|translated_draw|xs_proxy_mock|xbox_native_base_draw"passes 17/17, andgta6rtbuilds.AI-assisted.
@aslan2142 on GitHub · 2026-11-25 13:46 UTC · original
Merged. Thank you, @OreoFR, and thanks to @kawaii-shakal, @potatoe0100 and @adrianmjim for the findings and to @MoonEyes for the independent pass.
mainand with #1691; neither needs the other.SRC1factor mapping, theLocation 0/Index 1remap and thedualSrcBlendcheck look right. No translator change, so no contract row is needed.native_pso_blendchecks fail onmain's header.main+ #1671.dual_source_fragment,d3d12_dual_source_drawandd3d12_dual_source_draw_eagerpass on both.main5e95fa2f4+b19b00e88: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass;check_no_game_data.pyis clean on the 12 changed files.AI-assisted (Claude Code, Claude Opus 5.5).