startup: check the cb_blend decoder without a device #1680
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1687"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:05:11Z.
Refs #1149.
Change
src/startup_stubs/cb_blend.hdecodes aCB_BLENDn_CONTROLword and aCB_TARGET_MASKnibble into aD3D12_RENDER_TARGET_BLEND_DESC. It refuses, with a reason, the forms D3D12 cannot express (BOTH_SRC_ALPHA/BOTH_INV_SRC_ALPHA, constant alpha without alpha blend factor support, unknown factors and combine functions, MIN/MAX with factors other than ONE).state_block_blend.huses it for slot 57 pipelines and passes the reason on to the log.Three tests reach the header without a hardware adapter today:
startup_cb_blend_warp(offscreen_check --startup-cb-blend) runs a decoder table and then 18 WARP draws compared with a CPU model. The table puts all 21 factor values in the colour source slot only. The destination and alpha slots get only the values used by a few fixed words.startup_cb_blend_swapped_warpis the same run with source and destination exchanged, as its negative control.startup_state_block_blenddecodes the four words measured on #1216 and one refused word.The device run needs a D3D12 device. Only the colour source slot sees the whole factor table, and no case checks a refusal reason. 15 of 23 single-point mutants of the header left all three tests passing (table below). One of them leaves a colour factor such as
SRC_COLORin its colour spelling inDestBlendAlpha. D3D12 accepts only the alpha spelling in that field, so a classic multiply blend (ZERO,SRC_COLOR) would produce a blend state D3D12 rejects. The existing draws cannot catch it because none of them has a colour factor in the destination alpha slot.This PR adds
tests/startup_cb_blend_check.cpp, a device-free check registered next to the existing cb_blend block inCMakeLists.txt:SEPARATE_ALPHA_BLENDclear) in the source and in the destination field, with refused values in every alpha fieldcontrol_wordagainst four words written out by hand (one with a distinct value in each field, one with every field overfull); raw0x74331291decoded with and without alpha blend factor support--mutate dest-alpha-colourexpects the colour spelling inDestBlendAlpha. It is registered asstartup_cb_blend_decode_dest_alpha_controlwithWILL_FAIL(24 of 526 cases fail).docs/startup-runtime.md: the cb_blend paragraph now names the device-free check and its control. No existing test or case is changed.Mutation probe
I applied each mutant to
cb_blend.halone, rebuiltoffscreen_check,startup_state_block_blend_checkandstartup_cb_blend_check, and ran the four tests. Then I reverted it. "Before" is the three existing tests; "after" addsstartup_cb_blend_decode.BOTH_INV_SRC_ALPHA(12) reported as an unknown factorDestBlendAlphawithout the alpha formSrcBlendAlphawithout the alpha formALPHA_DESTBLENDread as [27:24]COLOR_DESTBLENDread as [11:8]ALPHA_SRCBLENDread as [19:16]ALPHA_COMB_FCNread as [22:21]INV_SRC1_COLORisSRC1_ALPHAcontrol_wordkeeps 4 bits ofALPHA_DESTBLEND> 0x1FSRC1_COLORCONSTANT_ALPHAreason only for 19INV_DEST_COLORdroppedM14 survived the WARP draws even though the "constant alpha" draw uses
ONE_MINUS_CONSTANT_ALPHA(20) as the destination factor. Read as [11:8], 20 becomes 4 (SRC_ALPHA), and with the draw's constant alpha 0.25 and source alpha 0.75 both factors are 0.75, so the result is the same.Not pinned: when more than one slot is refused, the reason names the first in the order colour source, colour destination, alpha source, alpha destination. That order looks like an implementation detail, so the new check puts only one bad value in each word. It also does not pin the factor fields of an unblended (
ENABLEclear) target beyondSrcBlend; D3D12 ignores them.Verification
Base
c864f138(main) plus commit3c684a32,devpreset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. No_hardwaretest was run.tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --checkpassed.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:07Z.
Review: COMMENTED
Verified at commit
3c684a32dc0745f74f54fbc13d45f4eaff01f76b:CMakeLists.txtregistration (startup_cb_blend_check,startup_cb_blend_decode, andstartup_cb_blend_decode_dest_alpha_controlwithWILL_FAIL TRUE). Zero production code changes, zero weakened assertions, no temporary files or subprocesses, clean-room/title-neutral.git diff --check origin/main...HEAD— cleanpython3 tests/docs_links_check.py— self-test passed, 16 Markdown files, 350 linkspython3 tests/bidi_controls_check.py— self-test passed, 1278 files, no bidirectional controls--preset dev):cmake --build --preset dev --target startup_cb_blend_check startup_stream_consumer -- -j 6(3.94s)ctest --preset dev -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure— 2/2 passed (0.09s)/O2(--preset release):cmake --build --preset release --target startup_cb_blend_check startup_stream_consumer -- -j 6(1.77s)ctest --preset release -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure— 2/2 passed (0.12s)--preset dev, patchedsrc/startup_stubs/cb_blend.h):alpha_form()ond.DestBlendAlpha(d.DestBlendAlpha = dst_a;):ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failureFAILED as expected (24 of 526 FAILEDacross separate and shared destination alpha slots).dst_a != D3D12_BLEND_ONEin the alphaMIN / MAXguard:ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failureFAILED as expected (6 of 526 FAILEDon alphaMIN/MAXwith non-ONEdestination factors).AI-assisted; commands listed were executed locally.