Skip to content

d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) - #1671

Merged
aslan2142 merged 6 commits into
ProjectLeonida:mainfrom
OreoFR:rt-slot57-blend-state
Nov 25, 2026
Merged

aslan2142 merged 6 commits into
ProjectLeonida:mainfrom
OreoFR:rt-slot57-blend-state

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-SLOT57-BLEND-STATE (#1608 (comment))

Depends on: #1592

#1592 is a conflict only: both add an #include on the same line of runtime/shims/d3d12_xs_native_pso.h. Everything else merges, and I'll rebase onto whichever lands first. This builds on no other PR. 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

Since #939, every graphics pipeline the game creates through device slot 57 goes through the native factory (runtime/shims/d3d12_xs_native_pso.h). The factory built each PSO from a zeroed desc and set only RenderTargetWriteMask, so every target drew with blending off. The record's state blob A, which carries the blend state, was never read (native_pso.h: "blend, raster, depth, not decoded"). That is the cause of the picture regression QemmHD bisected to #939 (#939 (comment)):

  • glyphs drawn as solid blocks;
  • option arrows drawn as white squares;
  • hard-edged artwork;
  • black where a gradient is composited over.

Blob A's shared block holds context register values in the RDNA2 layout. Measured over all 5,680 distinct blobs in the 1.0.2.1 pipeline library (25,471 graphics records):

  • +0xd0..+0xec CB_BLEND0..7_CONTROL: 34 distinct values, all in-range blends.
  • +0x78 CB_TARGET_MASK: it matches blob B's targets in 17,626 records.
  • +0x7c CB_COLOR_CONTROL: ROP3 copy everywhere.
  • Mesh pipelines: the same registers, 84 bytes further on.

The counts and the layout are in docs/fspx.md, "State blob A". Aggregate counts only; no blob bytes are quoted anywhere.

  • runtime/src/native_pso.h:
    • decode_state_a_blend checks the measured shapes and the tag, then reads the registers.
    • d3d12_target_blend and d3d12_blend map them to D3D12 blend values: RDNA2 factor and COMB_FCN to D3D12_BLEND and D3D12_BLEND_OP, alpha taken from the colour fields without SEPARATE_ALPHA_BLEND, and each target's CB_TARGET_MASK nibble as its write mask.
    • plan() fills FixedState::blend.
  • runtime/shims/d3d12_xs_native_pso.h: fill_blend_state builds D3D12_BLEND_DESC from it, with IndependentBlendEnable where targets differ. Both the VS and the mesh paths use it.
  • Kept on today's defaults (blending off, all components written), logged:
    • the 1,937 records that blend with dual-source SRC1 factors, since the translator declares no second pixel-shader output;
    • any blob of another shape;
    • any target with a factor this path doesn't take.
  • Raster and depth state: not decoded here, so the factory's defaults stay. That would be a separate item.
  • runtime/test/native_pso_blend_test.cpp (portable, standard library only): synthetic blobs for both families, the shape and tag checks, the register mapping including the subtract/reverse-subtract order and the non-separate alpha case, the refused forms, and plan().

Tested

  • Real boot, retail 1.0.2.1, native Windows. 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 (needed on NVIDIA to get past the landing screen) + this branch, fresh first-run profile, factory on.
    • Before (same build without this change), the first-run pages had solid glyph blocks, square arrows, a flat minimap illustration, and a black background with hard-edged artwork on the legal screens.
    • With this change:
      • "Navigation experience", "Interface size", the legal and photosensitivity screens draw correctly: readable text, round arrow buttons, the translucent minimap frame, the purple gradient behind the legal screens with the faded building art, and the highlighted-row gradient;
      • the loading slideshow draws clean, with its blurred cross-fade.
    • The log shows the dual-source fallback for CB_BLEND0 f1010f01 pipelines, as expected.
  • ctest on Windows: native_pso_blend, 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

@QemmHD offered an A/B on a 4070 SUPER with the factory on and off; that would cover a second machine.

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. (Not a translator change; the measurement is in docs/fspx.md.)

🤖 Generated with Claude Code

OreoFR and others added 2 commits November 25, 2026 08:35
…(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>
OreoFR and others added 3 commits November 25, 2026 09:02
…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>
@OreoFR

OreoFR commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I pushed two fixes after a second real-boot run turned up one refused pipeline (slot 57 call 1 failed with 0x80070057), the first pipeline the title creates. It writes R32_FLOAT, B4G4R4A4_UNORM and R8_UINT with MAX blending on every target:

  • 4e7b764db: integer targets (UINT/SINT) keep blending off. The colour block bypasses blending there, and D3D12 refuses a PSO that asks for it.
  • f5576377d: on this RTX 4070 Laptop, B4G4R4A4 isn't renderable, so the Vulkan layer draws it into an RGBA8 stand-in and refuses blending on it (E_NOTIMPL), because the stand-in quantizes the output before blending. When the device refuses the decoded blend state, the factory turns blending off on those targets only, then on every target if it's still refused. It no longer leaves the pipeline to the PC description path, which fails on this machine.

After both fixes, the same boot has no refused slot 57 pipeline and no device loss, and the first-run pages, legal screens and slideshow still draw correctly. Blending on the RGBA8 stand-in is something the layer could allow approximately, but that's a separate decision about the layer.

#1691 (depth, stencil and raster state from the same blob, RT-SLOT57-DEPTH-RASTER) is stacked on this branch and already includes these fixes. Merging this one first leaves #1691 with only its own two commits to review. @QemmHD if you A/B, #1691's branch covers both.

AI-assisted.

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (native Windows; RTX 4070 SUPER + AMD Radeon gfx1036 iGPU, LEONIDA_VK_VALIDATION=1): builds clean (815-step rebuild); new native_pso_blend portable test passes on both GPUs. ctest over native_pso_blend|xs_proxy_mock|pso_stream|d3d12_pso_validation|d3d12_draw|d3d12_pipeline_library (15 tests): NVIDIA 14/15 — only d3d12_pipeline_library_host crashes (0xc0000409); AMD passes the PR-relevant tests, with d3d12_draw/d3d12_pso_validation failing on the iGPU's 128-byte push-constant limit and d3d12_pipeline_library skipping. All failures reproduce identically on clean origin/main (3f81d46ac) — pre-existing/environmental, not caused by this PR. Caveat: xbox_native_base_draw needs llvm-mc/spirv tools not installed here, so GPU coverage of the blend path is indirect. AI-assisted verification.

@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Real-boot A/B on native Windows 11, RTX 4070 SUPER (NVIDIA 621.24), MSVC RelWithDebInfo. The slot 57 native graphics factory is on in both arms, with LEONIDA_TITLE_WINDOWS_MB=1024 and #1558's fallback in both. Arm A = 3f81d46 (this PR's base), arm B = 81f33de (this head).

A (base) B (#1671)
CreateNativeGraphicsPipelineState ok / failed 25,450 / 0 25,450 / 0
"slot 57 call N failed" none none
CreatePipelineState failed 15 15
presents ok 2,263 2,320
distinct "unbound T#" slots by the end 6,477 344
  • Picture: 16 swapchain captures per arm, one every 150 presents.
    • In A, every layered full-screen image from the first one on is drawn opaque, with black rectangles behind each layer, and 5 of the last 6 captures are flat fills.
    • In B every capture is a normal image, and the per-capture mean colours match runs with the factory off (the pre-[integration] Windows offline boot to the first-run UI (RT-WINDOWS-FIRST-RUN-UI) #939 path) on the same images.
    • So this fixes the blending regression the factory brought, for everything this boot reaches.
  • New lines in B (worth a look, not blockers):
    • 4× "a target's blend state is not one this path builds (dual-source or unknown factor), so this pipeline keeps blending off (CB_BLEND0 f1010f01)";
    • 1× "the device refused this pipeline's blend state, so it was built with blending off on its B4G4R4A4 targets". NVIDIA doesn't support blending on that format, so that one is expected.
  • Not checked: the first pages after a fresh profile (skipped on this profile now), and anything past the load. Both arms end at the same later device loss, which is unrelated.

Thanks @OreoFR, this is the fix for what I reported on #939.

AI-assisted (Claude Code, Claude Opus 5.5).

@OreoFR

OreoFR commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@QemmHD thanks for the A/B. The 4 CB_BLEND0 f1010f01 lines are the dual-source (SRC1) pipelines: #1703, stacked on this PR, builds them with their real blend by moving the pixel shader's SV_Target1 to Location 0, Index 1. On a real boot with LEONIDA_VK_VALIDATION=1, those lines are gone and no pipeline is refused. The B4G4R4A4 line is expected on NVIDIA, as you say.

AI-assisted.

@kawaii-shakal

Copy link
Copy Markdown
Contributor

Tested on a real boot: this fixes the solid glyph blocks for us too. Menu and first-run text now renders as glyphs, on an RTX 5070 Ti (Blackwell, NVIDIA 617.42, Windows 11 Pro 26300).

AI-assisted (Claude Code, Claude Opus 5.5).

…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>
@OreoFR

OreoFR commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@kawaii-shakal thanks, a second machine and GPU family showing the glyphs instead of the solid blocks is exactly what this needed. Your log matches mine: the B4G4R4A4 step is the only fallback that fires in a real boot.

Since your run, adrianmjim pointed out in #1703 that the fallback also caught unrelated E_NOTIMPL refusals. 668d65b4b limits it to pipelines that blend a B4G4R4A4 target, which is the case your boot hit, so nothing changes for what you saw. The log line now reads "the device refused blending on this pipeline's B4G4R4A4 stand-in targets".

AI-assisted.

@aslan2142
aslan2142 merged commit 5e95fa2 into ProjectLeonida:main Nov 25, 2026
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged: this is the fix for the solid glyph blocks and the opaque, black-backed layers that every boot since #939 showed. Thank you, @OreoFR, and thanks to @QemmHD for the A/B and to @kawaii-shakal and @whoalin1 for the independent runs.

AI-assisted (Claude Code, Claude Opus 5.5).

Snooozs added a commit to Snooozs/leonida that referenced this pull request Nov 27, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants