Skip to content

d3d12: an integer render target bypasses its blender (D3D-INTEGER-TARGET-BLEND-BYPASS) - #2023

Open
BubsMcgee wants to merge 1 commit into
ProjectLeonida:mainfrom
BubsMcgee:fix/integer-target-blend-bypass
Open

BubsMcgee wants to merge 1 commit into
ProjectLeonida:mainfrom
BubsMcgee:fix/integer-target-blend-bypass

Conversation

@BubsMcgee

Copy link
Copy Markdown
Contributor

Ports the first concrete gap from DexNom/VIctory (source-only Rust runtime,
GPL-3.0-or-later), commit ddb7332, reimplemented for this Vulkan layer.

What

  • A render target whose format is integer no longer gets blendEnable = VK_TRUE. The layer clears the enable for
    that target only, keeps its colorWriteMask (and every other target's state), and no longer counts it as a
    dual-source consumer.
  • The console's native state keeps CB_BLENDn regardless of the format, and D3D12Xbox bypasses the blender on
    integer surfaces. PC D3D12 rejects that state at pipeline creation, and Vulkan requires
    blendEnable = VK_FALSE (VUID-VkPipelineColorBlendAttachmentState-blendEnable-04727), so forwarding it could
    only fail the pipeline — the failed-CreatePipelineState class reported on RADV in AMD/RADV + 8 GB: boot ends at 54 s with a null write at game+0x2215c35, with or without the shader library #1915.

Test

  • d3d12_pso_validation_test §3b creates a layer-only pipeline with an R8G8B8A8_UINT target, blending enabled
    and a red write mask. PC D3D12 rejects the same state, so it is deliberately not in the parity set.
  • Windows 11, RTX 3080 Ti, driver 616.64: PASS (61 layer checks, 100 host comparisons), with the plain run and
    with LEONIDA_VK_VALIDATION=1.

Attribution

Adapted from DexNom/VIctory ddb7332 (GPL-3.0-or-later), "Restore 40 shader variants and repair integer-target
blending"; noted in the code comment. AI-assisted.

Claimed as D3D-INTEGER-TARGET-BLEND-BYPASS in the coordination issue.

@BubsMcgee

Copy link
Copy Markdown
Contributor Author

Ready for review: integer-target blending bypass (no blend state on integer RTVs, dual-source excluded for integer targets), from DexNom/VIctory ddb7332. New layer-only PSO test added; d3d12_pso_validation_test is 61/61 layer checks and 100/100 host comparisons plain and with LEONIDA_VK_VALIDATION=1 on an RTX 3080 Ti (616.64). Mergeable; the red status is the repo-wide checks backlog.

@Tauwni

Tauwni commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Tested for RT-STATE-AUDIT-PIPELINE on a Mac: Apple M3, macOS 26.5.1, Wine 11.0 (WineHQ macOS build, its MoltenVK 1.4.1), clang-cl/lld-link 23.1.6 cross build. Merged onto main 2859d0c9b, no game files.

  • With this PR: d3d12_pso_validation, d3d12_draw, d3d12_depth24_draw, d3d12_bundle and gfx10_descriptors pass. Same as main, no regression.
  • This PR's d3d12_pso_validation_test.cpp alone on main, without the fix: the test fails. So it is a test that fails on main and passes with the change (MEASURED, 1 run each).

GPUs tested: Apple M3 (profile S), MoltenVK 1.4.1 under Wine.

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

@Tauwni

Tauwni commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

CORRECTION to my comment above (#2023 (comment)).

Wrong line: "This PR's d3d12_pso_validation_test.cpp alone on main, without the fix: the test fails. So it is a test that fails on main and passes with the change."

What I measured since (2 runs each, Apple M3, Wine 11.0 with its MoltenVK 1.4.1, main 2859d0c9b):

  • With this PR's test file on main, the test prints PASS (60 layer checks, 0 host comparisons), so its §3b check passes there. On this driver, creating the pipeline with blending on an R8G8B8A8_UINT target succeeds, so §3b doesn't catch the bug on MoltenVK. Only the validation layer would. (60, not 61: the LogicOp XOR case skips because this MoltenVK has no logicOp.)
  • The "failure" was ctest's timeout: the process hangs at exit after printing PASS. It does that with and without this PR, so it's a Wine-on-Mac exit hang, not this change.

So on a Mac under Wine, this test neither fails on main nor shows the fix. Your RTX 3080 Ti run and RADV remain the evidence for it. What still holds: no regression with the PR in the other four tests.

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

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed and tested merged onto main (493867366) on Windows 11 + NVIDIA GeForce RTX 5070 12 GB (MSVC 19.44, Ninja Release).

  • integer_color_format() covers all 21 D3D12 integer render-target formats (including R10G10B10A2_UINT), and both the dual_source check and blends[i].blendEnable clear blending for integer targets while preserving colorWriteMask, satisfying VUID-VkPipelineColorBlendAttachmentState-blendEnable-04727.
  • Built and ran d3d12_pso_validation_test: the new case 3b (gfx: integer target bypasses blending) passed on RTX 5070. (Note: the later pre-existing parity check at line 460 gfx: Flags=DYNAMIC_DEPTH_BIAS fails on this host because Windows 11 inbox D3D12 without the Agility SDK returns E_INVALIDARG for DYNAMIC_DEPTH_BIAS, unrelated to this PR.)

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (Windows 11, driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
AI-assisted (Antigravity, Gemini).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Verified the integer-target bypass on physical gfx906 (RADV Mesa 26.0.8, Linux Wine 11.0), main aa918e5d9 versus 8536bcb4e merged into it. The stock red-only UINT case can return S_OK before a Vulkan pipeline exists in lazy mode. At actual pipeline creation, main emitted blendEnable=1 for a non-blendable integer attachment; the merge emitted 0 and kept the red-only write mask. The test intercepted and corrected main’s invalid enable before forwarding. Its pixels are therefore a control, not evidence that unmodified main draws correctly.

On the merge, both fenced 4 × 3 draws changed only the six covered red channels and preserved the other channels and pixels. Normalized blending and a mixed integer/UNORM render-target pair also produced the expected output. No validation errors or synchronization hazards in the submitted runs. The SRC1 control did log warnings: output type mismatch on main, unused fragment output on the merge.

Remaining feature-off case: with dualSrcBlend explicitly disabled, main refused the integer SRC1 case before Vulkan. The merge disabled blending but still supplied SRC1_COLOR and SRC1_ALPHA in the pipeline description. The test withheld that creation before the driver: the feature-off restrictions on those factors (VUIDs 00608–00611) still apply. Use non-SRC1 factors for the bypassed attachment and keep this as a distinct control.

AI-assisted.

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

TAKEN by OreoFR (Windows, RTX 4070 8 GB)

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR — NO RED (the new check passes on main too)

  • Base: main c22a0a7 + this PR (head 8536bcb) merged with --no-ff
  • Red (main + only this PR's test): d3d12_pso_validation passes on main, also with LEONIDA_VK_VALIDATION=1 (PASS (61 layer checks ...), no VUID-04727 reported): on this driver main's layer already returns S_OK for an R8G8B8A8_UINT target with blending on, and the check only reads the HRESULT.
  • Green (merge): d3d12_pso_validation passes; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p4 = main + d3d12: an integer render target bypasses its blender (D3D-INTEGER-TARGET-BLEND-BYPASS) #2023 + present: write each LEONIDA_CAPTURE file by the present it captures, so the last frame is kept (RT-CAPTURE-LAST-FRAME) #2090 (no shared files): 505 tests, new failures vs main: none from this PR (vk_presenter_sparse_capture fails in this package because of present: write each LEONIDA_CAPTURE file by the present it captures, so the last frame is kept (RT-CAPTURE-LAST-FRAME) #2090, see there; xmem_no_write_watch, xmem_write_watch, d3d12_multithread and d3d12_queue_wait_timeout pass when re-run alone; main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present)
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty) in package p4; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32)
  • Diff read: no bug. integer_color_format lists the DXGI UINT/SINT colour formats, the blend enable is cleared for them (the write mask is kept), and they no longer turn on dual-source blending. The GPL-3.0-or-later attribution to DexNom/VIctory matches this repository's GPL-3.0 licence. The test would show the fix if it also checked the created pipeline's blendEnable or counted validation errors.
  • Other runs: Consistent with zmasi's gfx906 run, Tauwni's corrected Mac run and lixonik's approval.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

@fiestorra

Copy link
Copy Markdown
Contributor

Heads-up from a negative control: the new case 3b in this branch passes with main's shim too, so it does not detect the change it accompanies.

1. It applies and builds. merge-tree clean onto main 012b79a67; d3d12_pso_validation_test builds.

2. With the branch its test passes:

ctest -R '^d3d12_pso_validation'
100% tests passed, 0 tests failed out of 1

3. The control - revert only runtime/shims/d3d12_vulkan_device.cpp, keep the test:

git checkout origin/main -- runtime/shims/d3d12_vulkan_device.cpp
cmake --build … --target d3d12_pso_validation_test
ctest -R '^d3d12_pso_validation'
100% tests passed, 0 tests failed out of 1      <- still green

4. Why, and it is visible in the new case itself. Case 3b builds a graphics pipeline with RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UINT, blending enabled and a RED write mask, then asserts:

const HRESULT hr = create_graphics(layer_dev.p, desc);
if (hr != S_OK) { … "FAIL [gfx: integer target bypasses blending]" … return 1; }
++checked;

The only thing it asserts is that creation succeeds. The change in the shim is about what state the layer emits - forcing blendEnable = VK_FALSE for integer colour targets because VUID-VkPipelineColorBlendAttachmentState-blendEnable-04727 requires it. Creation succeeds on main too, so the case cannot fail in the way it exists to catch.

What would detect it: inspect the created pipeline's blend state (or the Vulkan side of it) and assert blendEnable == VK_FALSE and that RenderTargetWriteMask survived as RED. The comment above the case already says "the target's write mask must survive" - the assertion just is not there.

What I am not saying: that the change is wrong. The shim's rule is the correct one for Vulkan; what is missing is a test that fails when the rule is not applied. I did not edit the test - that is the author's call, and a stranger rewriting an assertion would be guessing at what they meant to check.

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change and re-run. 19 controls so far: 13 bite, 4 do not, 2 are compile-level only. This is the fourth that does not bite, and the first where the new case exists but asserts the wrong thing rather than nothing.

Written with an AI assistant.

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.

6 participants