Repository navigation
d3d12: dual-source blending reads SV_Target1 at Location 0, Index 1 (RT-DUAL-SOURCE-BLEND) - #1703
Conversation
…(RT-SLOT57-BLEND-STATE) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ry (RT-SLOT57-BLEND-STATE) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…PSOs (RT-SLOT57-BLEND-STATE) A library pipeline enables MAX on an R8_UINT target; the colour block bypasses blending there, and D3D12 refuses the PSO. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…with blending off on its stand-in targets (RT-SLOT57-BLEND-STATE) On devices without renderable B4G4R4A4, the Vulkan layer refuses blending on the RGBA8 stand-in (E_NOTIMPL). Turn blending off on those targets, then on every target, before leaving the pipeline to the PC description path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…RT-DUAL-SOURCE-BLEND) A PSO whose blend state uses a SRC1 factor gets its fragment module's Location 1 colour output moved to Location 0 with Index 1, as Vulkan takes the second source. Slot 57 native PSOs now map the SRC1 factors of state blob A. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts (RT-DUAL-SOURCE-BLEND) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kawaii-shakal
left a comment
There was a problem hiding this comment.
Review (read-only, not run): one likely bug in the lazy path.
Lazy pipelines lose the dual-source remap. PipelineState remaps the fragment module (dual_source::remap(stage.words)) at creation. But graphics pipelines are lazy by default (lazy_graphics_pipelines(), off only with LEONIDA_LAZY_PIPELINES=0). When a lazy pipeline is first drawn, build() gets its SPIR-V again through stage_words(), and stage_words() replays rgba4::quantize (rgba4_mask_), link_f16_halves and depth24_patch_fragment, but not the dual-source remap. With the default settings a dual-source pipeline is therefore built with SV_Target1 still at Location 1 and SRC1 blend factors, which is invalid in Vulkan (the second source has to come from Location 0, Index 1). The blend reads an undefined second source, or a driver refuses the pipeline.
Suggested fix: keep a dual_source_ flag next to rgba4_mask_ and apply leonida::dual_source::remap(words[i]) to the fragment stage (source.slot == 2) in stage_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 CreateGraphicsPipelineState path does.
Checked and fine: spirv() returns a copy, so the in-place remap does not leak into other pipelines that share the pixel shader. dualSrcBlend is already required and enabled on main (d3d12_vulkan_device.cpp ~7705 and ~16450).
AI-assisted review (Claude Code, Claude Opus 5.5).
…raw test (RT-DUAL-SOURCE-BLEND review) A lazy graphics pipeline (the default) makes its stage words again in build() through stage_words(), which replayed the B4G4R4A4 quantisation but not the Location 0 / Index 1 remap. Both now go through rewrite_fragment(), the same at creation and in a lazy build. d3d12_translated_draw_test --dual-source draws ps_m15_dual (ps_m15 plus a constant SV_Target1) with ONE + SRC1_COLOR / SRC1_ALPHA, lazy and at creation: every covered pixel is exact. Without the lazy fix, NVIDIA still draws the right colours but LEONIDA_VK_VALIDATION=1 reports 3 errors. Found by kawaii-shakal's review of ProjectLeonida#1703. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@kawaii-shakal thanks, that was a real bug. Fixed in
The slot 57 factory goes through the same PC AI-assisted. |
|
Tested
AI-assisted testing (non-developer tester). |
… ps_m15 (RT-DUAL-SOURCE-BLEND review) The generic pixel-shader harness picked up the new fixture and lost the device on an RTX 4060: it has no second colour target and no SRC1 blend. d3d12_translated_draw_test --dual-source owns that draw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@potatoe0100 thanks, good catch. AI-assisted. |
|
Tested The new draw tests pass on AMD. Whole I did not run One thing that is still there: the slot 57 blend fallback fires on any 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
left a comment
There was a problem hiding this comment.
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. Head 188207a (it carries #1671's commits; branch point main 3f81d46, not merged with current main 237deb6).
ctest -R "native_pso|dual_source|translated_draw|xs_proxy_mock|xbox_native_base_draw": 15/15 passed, including dual_source_fragment, native_pso_blend, and the GPU draws d3d12_translated_draw, xbox_native_base_draw, d3d12_dual_source_draw and d3d12_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).
…d-in (RT-SLOT57-BLEND-STATE review) adrianmjim's review: the blend fallback ran on any E_NOTIMPL, which also stands for refusals unrelated to blending (stream_unsupported, mesh limits, FullyCovered, and ProjectLeonida#1703's dual-source refusal). Such a pipeline was retried with blending off, logged as a blend refusal, and, if the retry succeeded, drew without the blend the title asked for. Now only a pipeline with a blended B4G4R4A4 target is retried, with blending off on those targets alone (without_stand_in_blend, its own header), and the line is printed only when that retry succeeds. The "every target" step is gone: no real boot used it (RTX 4070 Laptop and kawaii-shakal's RTX 5070 Ti only ever logged the B4G4R4A4 step). native_pso_fallback_test covers the decision. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # docs/fspx.md
|
@adrianmjim thanks for the AMD run, and you're right about the fallback. Fixed in #1671 (
On AI-assisted. |
|
Merged. Thank you, @OreoFR, and thanks to @kawaii-shakal, @potatoe0100 and @adrianmjim for the findings and to @MoonEyes for the independent pass.
AI-assisted (Claude Code, Claude Opus 5.5). |
Conflicts: the blend fallback of ProjectLeonida#1671/ProjectLeonida#1703 for B4G4R4A4 stand-ins moves into the build() that ProjectLeonida#1592 split out, so it runs for both stage sources; the translated draw test keeps --native-fspx and --dual-source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: RT-DUAL-SOURCE-BLEND (#1608 (comment))
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: d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) #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+ d3d12_xs: make a D16S8 depth texture without UAV when the depth provider refuses it (RT-D16S8-UAV-NVIDIA-FALLBACK) #1558 + d3d12: compile a submission's pipelines on worker threads (RT-PIPELINE-COMPILE-WORKERS) #1547 + d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) #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 d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) #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