startup: decode colour-blend registers into a desktop blend state #1219
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1226"
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 Jess-Doit on 2026-11-24T04:25:20Z.
Change
Refs #1216. This covers the register-decoding half (steps 2 and 3). Finding the registers in the captured state block (step 1) needs captures and stays open, so the draw path doesn't call the decoder yet.
src/startup_stubs/cb_blend.his a pure, header-only decoder. It turnsCB_BLENDn_CONTROLand the render target'sCB_TARGET_MASKnibble intoD3D12_RENDER_TARGET_BLEND_DESC. The field layout and theBlendOp/CombFuncenums come from Mesa'ssrc/amd/registers/gfx10.json. For these two registers they're identical togfx103.json.CONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHAmap toD3D12_BLEND_(INV_)ALPHA_FACTORwhenD3D12_OPTIONS13::AlphaBlendFactorSupportedis set.SRC_COLOR→SRC_ALPHA,DST_COLOR→DEST_ALPHA,SRC1_COLOR→SRC1_ALPHA, and so on). This applies when given explicitly and whenSEPARATE_ALPHA_BLEND = 0reuses the colour fields. D3D12 accepts only the alpha forms there.DST_PLUS_SRC,SRC_MINUS_DST,MIN,MAXandDST_MINUS_SRCmap toADD,SUBTRACT,MIN,MAXandREV_SUBTRACT.ENABLEclear: the target is unblended and only the write mask is kept.BOTH_SRC_ALPHA/BOTH_INV_SRC_ALPHA;Assumptions:
DISABLE_ROP3: not interpreted (logic ops are a separate state).Fixture
offscreen_check --startup-cb-blend(tests/startup_cb_blend.cpp) does two things:Decoder table. It checks:
ENABLEclear with odd field values;Draws. 18 register words, built from those field definitions, cover:
SRC_ALPHA_SATURATEand inverse destination;0xE5040504,0xE5010504,0xE5010501and0xE1000104, as captured with bit 31 set. The table also checks their exact translation, and that bit 31 doesn't change it.Each draws a constant source colour over a cleared
R32G32B32A32_FLOATtarget with the decoded state. The result is compared with a CPU model of the register fields:combine(src × source factor, dst × destination factor)per channel, written where the mask allows. The inputs are exact in binary32: source (0.75, 0.5, 0.25, 0.75), destination (0.25, 0.5, 1, 0.5), constant (0.5, 0.25, 0.75, 0.25). The source alpha keepsSRC_ALPHAandINV_SRC_ALPHAapart.--startup-cb-blend-swappedis the negative control. It exchangesSrcBlend/DestBlend(and the alpha pair) after decoding, and must disagree with the model.Verification
Tested
f7ec1944(on4919b51a) on Windows 10 22H219045.6456with a GTX 1060 6 GB (10de:1c03, driver32.0.15.6094) and in-box WARP (1414:008c,10.0.19041.5794). The D3D12 debug layer was enabled and reported 0 errors and 0 warnings.Debug and Release each passed 4/4 (
startup_cb_blend_{hardware,warp},startup_cb_blend_swapped_{hardware,warp}).AlphaBlendFactorSupportedon this Windows 10 runtime. Its decode path is covered by the table checks.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:38:49Z.
Review: COMMENTED
Reviewed commit
27780101on Linux (x86_64, Python 3.12 withiced-x86andpefile). Windows D3D12 build/tests (offscreen_check,ctest --preset {dev,release} --no-tests=error -R '^startup_cb_blend' -V) were not run locally.Code & Spec Audit
src/startup_stubs/cb_blend.h: decodesCB_BLENDn_CONTROL+ 4-bitCB_TARGET_MASKinto a per-targetD3D12_RENDER_TARGET_BLEND_DESC:BlendOpfactors directly, gatesCONSTANT_ALPHA/ONE_MINUS_CONSTANT_ALPHAonalpha_factor_supported(D3D12_OPTIONS13::AlphaBlendFactorSupported), and refusesBOTH_SRC_ALPHA/BOTH_INV_SRC_ALPHA(11, 12) and unknown factors.SRC_COLOR,DST_COLOR,SRC1_COLORand inverses) to their*_ALPHAequivalents forSrcBlendAlpha/DestBlendAlpha, both whenSEPARATE_ALPHA_BLEND = 1and whenSEPARATE_ALPHA_BLEND = 0reuses colour fields;BLEND_FACTOR/INV_BLEND_FACTORremain valid in alpha slots.CombFunc0–4 (ADD,SUBTRACT,MIN,MAX,REV_SUBTRACT), refuses 5–7, refusesMIN/MAXwith factors other thanONE, refusestarget_mask > 0xF, and preservesRenderTargetWriteMaskwithBlendEnable = FALSEwhenENABLEis clear.decode()targets a single render target; settingD3D12_BLEND_DESC::IndependentBlendEnablewhen wiring multiple targets remains the caller's responsibility.docs/startup-runtime.mdis title-neutral and accurately states that the draw path does not callcb_blend.hyet.Checks Run Locally (Linux)
/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (self-test passed; 16 Markdown files, 277 links)/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (self-test passed; 1037 tracked files)/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py: passed/root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py: 12/12 passed, 0 skipped, 0 failed/root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py: 10/10 passed, 0 skipped, 0 failedgit diff --check HEAD~1..HEAD: passedImported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-24T04:36:11Z.
Test report for
27780101: Windows 11 Pro build 26300, MSVC 14.50 (VS 18 Build Tools), Ninja, Release, D3D12 debug layer enabled. Adapters: AMD Radeon RX 9070 XT (1002:7550, driver32.0.32015.7029) and WARP (1414:008c).4/4 passed:
startup_cb_blend_{hardware,warp}andstartup_cb_blend_swapped_{hardware,warp}. Debug layer: 0 errors and 0 warnings on all four.drawn=14 skipped=0 mismatches=0on both adapters. That includes the constant alpha case (control=40001413): both report alpha-factor support on this Windows 11 runtime, so the path you had to skip ran here and matched the model (0.375 0.5 0.8125 0.5625).drawn=14 mismatches=10on the 9070 XT. Constant alpha is now among the cases that differ.This covers the decoder (steps 2 and 3 of #1216). I haven't checked it against captured state blocks yet. Once the registers are located (step 1), I can rerun the menu pages here and compare the result with the local
SRC_ALPHA / INV_SRC_ALPHAfallback.AI-assisted (Claude Code, Claude Opus 5.5).