Skip to content

d3d12: enable OPTIONS13 AlphaBlendFactorSupported and validate blend/logic-op state - #8043

Open
Sakura-Byte wants to merge 1 commit into
ItsNotRexed:mainfrom
Sakura-Byte:feat/d3d12-alpha-blend-factor-cap
Open

Sakura-Byte wants to merge 1 commit into
ItsNotRexed:mainfrom
Sakura-Byte:feat/d3d12-alpha-blend-factor-cap

Conversation

@Sakura-Byte

Copy link
Copy Markdown

Claimed in the coordination issue as: #7804 (comment)

Depends on: none

What and why

  • runtime/shims/d3d12_vulkan_device.cpp:
    • Sets D3D12_FEATURE_DATA_D3D12_OPTIONS13::AlphaBlendFactorSupported = TRUE (the layer already maps D3D12_BLEND_ALPHA_FACTOR / D3D12_BLEND_INV_ALPHA_FACTOR to Vulkan 1.0 core VK_BLEND_FACTOR_CONSTANT_ALPHA / VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA).
    • Replaces the unvalidated blend_factor / blend_op fallbacks with map_blend_factor, map_blend_op, and convert_blend_attachment: validates active RenderTarget entries (0 or 0..7 when IndependentBlendEnable) in CreateGraphicsPipelineState when BlendEnable or LogicOpEnable is set, returning E_INVALIDARG on out-of-range/gap D3D12_BLEND values (0, 12, 13, >21), *_COLOR factors on SrcBlendAlpha/DestBlendAlpha, invalid D3D12_BLEND_OP, BlendEnable && LogicOpEnable, IndependentBlendEnable && LogicOpEnable, and out-of-range LogicOp, while keeping valid Vulkan defaults when BlendEnable == FALSE.
  • runtime/test/d3d12_vulkan_device_test.cpp: updates compare_feature_options to assert OPTIONS13::AlphaBlendFactorSupported == TRUE alongside the existing host parity comparison.
  • runtime/test/d3d12_state_sweep_test.cpp: adds D3D12_BLEND_ALPHA_FACTOR / D3D12_BLEND_INV_ALPHA_FACTOR cases, disabled-blend invalid-factor acceptance, and 13 invalid-blend host-parity cases comparing exact refusal HRESULT (mine.pso != reference.pso).
  • runtime/test/d3d12_draw_test.cpp: adds Vulkan-side checks for OPTIONS13::AlphaBlendFactorSupported, invalid blend refusal cases, and D3D12_BLEND_ALPHA_FACTOR / D3D12_BLEND_INV_ALPHA_FACTOR draw parity (OMSetBlendFactor({0.1f, 0.2f, 0.3f, 0.4f}) and nullptr -> 1.0f) on B8G8R8A8_UNORM and B8G8R8X8_UNORM.

Tested

Windows 11, MSVC 2022 (19.44.35228.0), Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5090 D / driver 621.14. Synthetic inputs only; no game data.

  • Compliance: python -I scripts/check_no_game_data.py on all 4 changed files exited 0; git diff --check clean; 0 CRLF bytes across all 4 changed files.
  • Build: cmake --build runtime/build --config RelWithDebInfo -j 8 (-DLEONIDA_REQUIRE_VULKAN=ON) -> 665/665 targets built, exit 0.
  • Isolated & LEONIDA_VK_VALIDATION=1 runs:
    • d3d12_state_sweep_test.exe (LEONIDA_VK_VALIDATION=1): 601 cases compared with NVIDIA GeForce RTX 5090 D, 0 differ; 0 skipped, exit 0.
    • d3d12_draw_test.exe (LEONIDA_VK_VALIDATION=1): ALPHA_FACTOR: OPTIONS13, validation and B8G8R8A8/B8G8R8X8 colour/alpha factor blends matched, exit 0.
    • Sequential d3d12_state_sweep, d3d12_draw, d3d12_bindless_churn, d3d12_bindless_churn_validated: 4/4 passed.
    • d3d12_vulkan_device_test.exe: CheckFeatureSupport options (NVIDIA GeForce RTX 5090 D): 46 feature queries compared (0 host-unsupported skipped), 0 mismatches passed (still exits 1 later on the pre-existing upstream/main line 6574: tiles == 1 check).
  • Full ctest -j 4: 268/272 passed (11 skipped, 1 disabled; 3 pre-existing upstream/main failures d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_depth_resolve, plus one parallel temp-dir race #238 which passed standalone).
  • Negative controls (with the runtime/shims/d3d12_vulkan_device.cpp fix temporarily reverted):
    • d3d12_vulkan_device_test.exe failed OPTIONS13 mismatch (1 mismatches).
    • d3d12_state_sweep_test.exe failed all 13 invalid-blend parity cases (601 cases compared with NVIDIA GeForce RTX 5090 D, 13 differ; 0 skipped, exit 1).
    • d3d12_draw_test.exe failed options13.AlphaBlendFactorSupported == TRUE (line 862), exit 1.

AI-assisted: yes

Checklist

  • 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. (n/a: no translator change)

@byPreaZy

Copy link
Copy Markdown

Tested 1223c42 on Windows 11, MSVC 2022 BuildTools, AMD RX 9060 XT (driver 32.0.32015.7029), RelWithDebInfo/Ninja.

Built and ran the three touched test binaries:

  • d3d12_state_sweep_test: 601 cases vs the AMD host, 0 differ, 0 skipped.
  • d3d12_draw_test: all pixel comparisons matched, including the XOR logic-op and full-screen no-vertex-input cases.
  • d3d12_vulkan_device_test: one failure, line 6574: tiles == 1, which is the known slot-78 proxy routing bug (TEST-1649, d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 still open, not in this base). Everything else in the log matched, including all resolve/format/feature comparisons.

Code read of convert_blend_attachment: the *_COLOR-on-alpha rejection matches the D3D12 E_INVALIDARG rule, the BlendEnable=FALSE path keeps valid Vulkan defaults the way the runtime ignores the fields, and LogicOpEnable correctly requires !BlendEnable && !IndependentBlendEnable && LogicOp <= OR_INVERTED. Two behaviour notes, neither blocking:

  • With IndependentBlendEnable=TRUE all 8 RenderTarget[] entries are validated regardless of NumRenderTargets; zeroed unused entries still pass, so only genuinely malformed tails are refused. Slightly stricter than reading only NumRenderTargets entries, probably fine.
  • The LogicOp range check now runs even when NumRenderTargets==0 (previously gated on desc.NumRenderTargets &&); a PSO with no render targets but LogicOpEnable set is refused where before it passed. Worth a one-line confirmation that the host runtime does the same.

AI-assisted review and test; no game files.

@Sakura-Byte

Sakura-Byte commented Nov 23, 2026 •

Copy link
Copy Markdown
Author

Thanks @byPreaZy for testing on AMD RX 9060 XT and checking those two edge cases!

Confirmed both against Windows 11 host d3d12core.dll (NVIDIA GeForce RTX 5090 D hardware and WARP) — both already match convert_blend_attachment, so no code change is needed:

  1. IndependentBlendEnable = TRUE beyond NumRenderTargets: host D3D12 validates all 8 RenderTarget[0..7] slots regardless of NumRenderTargets:

    • IndependentBlendEnable = TRUE, NumRenderTargets = 1, RT[1].BlendEnable = TRUE, RT[1].SrcBlend = 0 -> E_INVALIDARG (0x80070057, HW & WARP)
    • IndependentBlendEnable = TRUE, NumRenderTargets = 1, RT[7].BlendEnable = TRUE, RT[7].SrcBlend = 0 -> E_INVALIDARG (0x80070057, HW & WARP)
    • IndependentBlendEnable = TRUE, NumRenderTargets = 0, RT[1].BlendEnable = TRUE, RT[1].SrcBlend = 0 -> E_INVALIDARG (0x80070057, HW & WARP)
  2. LogicOpEnable / LogicOp with NumRenderTargets == 0: host D3D12 validates RT[0] even when NumRenderTargets == 0:

    • NumRenderTargets = 0, RT[0].LogicOpEnable = TRUE, LogicOp = D3D12_LOGIC_OP_XOR -> S_OK (0x00000000, HW & WARP)
    • NumRenderTargets = 0, RT[0].LogicOpEnable = TRUE, LogicOp = 99 -> E_INVALIDARG (0x80070057, HW & WARP)
    • NumRenderTargets = 0, RT[0].BlendEnable = TRUE, RT[0].LogicOpEnable = TRUE -> E_INVALIDARG (0x80070057, HW & WARP)

AI-assisted; synthetic probe only.

@LooperSalty

Copy link
Copy Markdown

Tested 1223c426 on Windows 11 26300, RTX 4070 SUPER (driver 610.88), MSVC RelWithDebInfo: pass

AI-assisted (Claude Code).

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.

3 participants