Skip to content

D3D-240: blends into B8G8R8X8 render targets read destination alpha 1 - #1977

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
SpositoDouglas:x8-draws
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
SpositoDouglas:x8-draws

Conversation

@SpositoDouglas

Copy link
Copy Markdown
Contributor

What: a B8G8R8X8 render target has no alpha, so D3D12 blends into it with destination alpha 1. The layer's Vulkan image for it is BGRA8 (#759), so the blend factors that read destination alpha read the X byte instead. For B8G8R8X8 render targets, CreateGraphicsPipelineState now turns DST_ALPHA into ONE, ONE_MINUS_DST_ALPHA into ZERO and the colour SRC_ALPHA_SATURATE into ZERO (its alpha form is 1 in both APIs), in the colour and alpha factors alike.
Why: D3D-240 in #313 (the part #759 / D3D-87 left out); claim: #1745 (comment)

Measured on the host runtime before changing anything (RX 9060 XT with AMD's D3D12 driver, and WARP): a full-screen draw of (0.8, 0.6, 0.4, 0.3) into a 4x4 target cleared with (0.2, 0.4, 0.6, 0.25).

Blend B8G8R8A8_UNORM B8G8R8X8_UNORM, WARP and AMD
src × DEST_ALPHA src × 0.25 src
src × INV_DEST_ALPHA src × 0.75 0
src × SRC_ALPHA_SAT src × 0.3 0
dst × DEST_ALPHA dst × 0.25 dst
dst × INV_DEST_ALPHA dst × 0.75 0

B8G8R8X8_UNORM_SRGB blends the same way. What a draw leaves in the X byte differs between the two: WARP writes 0 after every draw, even with alpha out of the write mask, and AMD writes the blended alpha (computed with destination alpha 1), or 255 with alpha masked off. No view reads the X byte (#759), so the test leaves it out.

Tests:

  • d3d12_draw_test: a full-screen pass blended into B8G8R8X8_UNORM and B8G8R8A8_UNORM targets cleared to the same bytes (alpha 0.25), through the five factors above. Red, green and blue must follow the rule within one level: destination alpha 1 for B8G8R8X8, the stored 64/255 for B8G8R8A8.
  • Negative control: with the shim change reverted, the new block fails at its first B8G8R8X8 case (got B,G,R 0,38,51, channel 0 wants 204, the colour scaled by the X byte's 0.25).

Tested:

  • Windows 11 Pro 26H2 (10.0.26300.9974), AMD Radeon RX 9060 XT (RDNA4), AMD Software 26.11.2 (32.0.32029.2010, Vulkan driver 2.0.416), Vulkan 1.4.359; MSVC 19.44 (VS 2022 Build Tools), Vulkan SDK 1.4.363.0, llvm-mc 21.1.8 (conda-forge), Python 3.13.9; on 6a6704df + this PR
  • d3d12_draw_test: 3/3 runs pass, and 3/3 with LEONIDA_VK_VALIDATION=1 (0 validation errors), with the bundle-blend wait raised from 21 to 31 locally (fix(test): use monotonic fence value (31) for bundle blend pass in d3d12_draw_test #1807's change, not part of this PR). Without it, the bundle-blend check before the new block fails 2 runs in 3 on this GPU, the same on 6a6704df without this PR.
  • d3d12_clear_test (197/197 readbacks matched WARP), d3d12_descriptor_test, d3d12_uav_clear_test, d3d12_vulkan_device_test: pass, with and without LEONIDA_VK_VALIDATION=1
  • ctest --test-dir runtime\build -C RelWithDebInfo: 112/113, the same with validation. Only d3d12_compute fails, at line 515: rt::d3d12_xs::device_proxy_ref_count(device.p) == 1, as on 6a6704df without this PR (d3d12_compute_test: release the slot-67 PSO before the device reference check #1898)
  • python -I scripts\run_gpu_tests.py: 178 translated, 178 pass spirv-val; 164/173 pass and 9 skip, native wave64 and with LEONIDA_W64_EMULATE=1
  • python -m compileall -q make_game.py tools tests, python -I make_game.py --help: pass; tests/semantic: 1644 OK; pytest-based tests: 1332 passed, 14 skipped; python -I tests/test_*.py: 178/180. test_cf_ref.py and test_world_names.py fail on this Windows machine, and since this PR changes no Python file they fail on 6a6704df too

Not in this PR:

  • With IndependentBlendEnable = FALSE, a B8G8R8X8 and a B8G8R8A8 target in one PSO now get different Vulkan blend states, so a GPU without independentBlend refuses that PSO (E_NOTIMPL), as it already does for any per-target blend state.
  • Castable-format lists that cross the B8G8R8X8 and B8G8R8A8 families are still not consulted (D3D-87: B8G8R8X8 textures (BGRA8 images, views read alpha 1, no typed UAV) #759).

AI-assisted: written with Claude Code; reviewed and tested by me.
No game data, keys or decryption involved.

🤖 Generated with Claude Code

SpositoDouglas and others added 2 commits November 22, 2026 12:20
B8G8R8X8 has no alpha, and WARP and AMD's D3D12 driver blend into it with
destination alpha 1. Its Vulkan image is BGRA8, so the blend factors that
read destination alpha read the X byte instead. For B8G8R8X8 render
targets the PSO now turns DST_ALPHA into ONE, ONE_MINUS_DST_ALPHA into
ZERO and the colour SRC_ALPHA_SATURATE into ZERO, in the colour and alpha
factors alike.

d3d12_draw_test blends a full-screen pass into B8G8R8X8 and B8G8R8A8
targets cleared with alpha 0.25 through the five factors that read
destination alpha, and compares red, green and blue. The X byte is left
out: WARP writes 0 there after a draw and AMD the blended alpha, and no
view reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Say that blending into a B8G8R8X8 render target reads destination alpha
as 1, which factors the PSO rewrites, and that what a draw leaves in the
X byte is not defined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 111/113 pass. On current main three tests fail the same way on every PR I built, so they're not from this PR: d3d12_draw (bundle blend, bisected to #1660's merge, see #1902), d3d12_compute on both GPUs (line 515: device_proxy_ref_count(device.p) == 1), and d3d12_subgroup on the Intel UHD 770 (line 611: fragment_default). I'm bisecting the last two. Other Intel failures are the known d3d12_present and d3d12_m3_frame.

@ItsNotRexed
ItsNotRexed merged commit 8b310b2 into ItsNotRexed:main Nov 22, 2026
8 of 9 checks passed
@SpositoDouglas
SpositoDouglas deleted the x8-draws branch November 22, 2026 16:56
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.

4 participants