startup: decode colour-blend registers into a desktop blend state #1226

Manually merged
github merged 2 commits from gh-pr/1226/head into gh-pr/1226/base 2026-11-26 22:50:27 +00:00
Owner

@⁠Jess-Doit on GitHub · 2026-11-24 04:25 UTC · original
Jess-Doit:startup/cb-blend-decode → main · +521 −0 · 7 files · 2 commits · merged 2026-11-24 04:41 UTC

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.h is a pure, header-only decoder. It turns CB_BLENDn_CONTROL and the render target's CB_TARGET_MASK nibble into D3D12_RENDER_TARGET_BLEND_DESC. The field layout and the BlendOp / CombFunc enums come from Mesa's src/amd/registers/gfx10.json. For these two registers they're identical to gfx103.json.

  • Factors: 17 of the 21 map directly. CONSTANT_ALPHA / ONE_MINUS_CONSTANT_ALPHA map to D3D12_BLEND_(INV_)ALPHA_FACTOR when D3D12_OPTIONS13::AlphaBlendFactorSupported is set.
  • Alpha slots: a colour factor becomes its alpha form (SRC_COLOR → SRC_ALPHA, DST_COLOR → DEST_ALPHA, SRC1_COLOR → SRC1_ALPHA, and so on). This applies when given explicitly and when SEPARATE_ALPHA_BLEND = 0 reuses the colour fields. D3D12 accepts only the alpha forms there.
  • Combine functions: DST_PLUS_SRC, SRC_MINUS_DST, MIN, MAX and DST_MINUS_SRC map to ADD, SUBTRACT, MIN, MAX and REV_SUBTRACT.
  • ENABLE clear: the target is unblended and only the write mask is kept.
  • Refused, with a reason, so the caller keeps today's opaque pipeline instead of guessing:
    • BOTH_SRC_ALPHA / BOTH_INV_SRC_ALPHA;
    • constant alpha without alpha-factor support;
    • unknown factors or functions;
    • a mask wider than four bits;
    • MIN/MAX with factors other than ONE.

Assumptions:

  • MIN/MAX: D3D12 ignores the factors of MIN/MAX. The hardware is taken to apply them, which is why RADV forces both to ONE for min/max. So only ONE/ONE is treated as equivalent.
  • Write mask: the mask nibble is taken in R, G, B, A order, as for an unswapped colour format.
  • DISABLE_ROP3: not interpreted (logic ops are a separate state).

Fixture

offscreen_check --startup-cb-blend (tests/startup_cb_blend.cpp) does two things:

  1. Decoder table. It checks:

    • every factor value 0–20, with and without alpha-factor support;
    • the seven alpha forms, both separate and shared;
    • all eight combine-function values (5 accepted, 3 refused);
    • the MIN/MAX refusals;
    • ENABLE clear with odd field values;
    • the five-bit mask refusal.
  2. Draws. 18 register words, built from those field definitions, cover:

    • straight and premultiplied alpha;
    • straight colour with premultiplied alpha;
    • additive, modulate, subtract and reverse subtract;
    • min/max, constant colour, SRC_ALPHA_SATURATE and inverse destination;
    • a colour-only write mask, blend disabled with an R+A mask, and constant alpha;
    • the four words reported in #1216 from captured state blocks: 0xE5040504, 0xE5010504, 0xE5010501 and 0xE1000104, 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_FLOAT target 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 keeps SRC_ALPHA and INV_SRC_ALPHA apart.

--startup-cb-blend-swapped is the negative control. It exchanges SrcBlend/DestBlend (and the alpha pair) after decoding, and must disagree with the model.

Verification

Tested f7ec1944 (on 4919b51a) on Windows 10 22H2 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.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.

. .\tools\dev.ps1
$env:XBOX2WINDOWS_ADAPTER = '1060'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset
    cmake --build --preset $preset --target offscreen_check -j 2
    ctest --preset $preset --no-tests=error -R '^startup_cb_blend' -V
}

Debug and Release each passed 4/4 (startup_cb_blend_{hardware,warp}, startup_cb_blend_swapped_{hardware,warp}).

  • Normal runs: 17 of 18 draw cases were drawn, with 0 mismatches.
  • Swapped control: 13 of 17 differed from the model, including straight alpha, the colour-only mask case and all four observed words. The four that can't show a swap are the ONE/ONE forms (additive, subtract, min/max) and the disabled case.
  • Skipped case: constant alpha, on both adapters, because neither reports AlphaBlendFactorSupported on this Windows 10 runtime. Its decode path is covered by the table checks.

AI-assisted (Claude Code).

**@⁠Jess-Doit** on GitHub · 2026-11-24 04:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1226) `Jess-Doit:startup/cb-blend-decode` → `main` · +521 −0 · 7 files · 2 commits · merged 2026-11-24 04:41 UTC ## 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.h` is a pure, header-only decoder. It turns `CB_BLENDn_CONTROL` and the render target's `CB_TARGET_MASK` nibble into `D3D12_RENDER_TARGET_BLEND_DESC`. The field layout and the `BlendOp` / `CombFunc` enums come from Mesa's `src/amd/registers/gfx10.json`. For these two registers they're identical to `gfx103.json`. - **Factors:** 17 of the 21 map directly. `CONSTANT_ALPHA` / `ONE_MINUS_CONSTANT_ALPHA` map to `D3D12_BLEND_(INV_)ALPHA_FACTOR` when `D3D12_OPTIONS13::AlphaBlendFactorSupported` is set. - **Alpha slots:** a colour factor becomes its alpha form (`SRC_COLOR` → `SRC_ALPHA`, `DST_COLOR` → `DEST_ALPHA`, `SRC1_COLOR` → `SRC1_ALPHA`, and so on). This applies when given explicitly and when `SEPARATE_ALPHA_BLEND = 0` reuses the colour fields. D3D12 accepts only the alpha forms there. - **Combine functions:** `DST_PLUS_SRC`, `SRC_MINUS_DST`, `MIN`, `MAX` and `DST_MINUS_SRC` map to `ADD`, `SUBTRACT`, `MIN`, `MAX` and `REV_SUBTRACT`. - **`ENABLE` clear:** the target is unblended and only the write mask is kept. - **Refused, with a reason, so the caller keeps today's opaque pipeline instead of guessing:** - `BOTH_SRC_ALPHA` / `BOTH_INV_SRC_ALPHA`; - constant alpha without alpha-factor support; - unknown factors or functions; - a mask wider than four bits; - MIN/MAX with factors other than ONE. **Assumptions:** - **MIN/MAX:** D3D12 ignores the factors of MIN/MAX. The hardware is taken to apply them, which is why RADV forces both to ONE for min/max. So only ONE/ONE is treated as equivalent. - **Write mask:** the mask nibble is taken in R, G, B, A order, as for an unswapped colour format. - **`DISABLE_ROP3`:** not interpreted (logic ops are a separate state). ## Fixture `offscreen_check --startup-cb-blend` (`tests/startup_cb_blend.cpp`) does two things: 1. **Decoder table.** It checks: - every factor value 0–20, with and without alpha-factor support; - the seven alpha forms, both separate and shared; - all eight combine-function values (5 accepted, 3 refused); - the MIN/MAX refusals; - `ENABLE` clear with odd field values; - the five-bit mask refusal. 2. **Draws.** 18 register words, built from those field definitions, cover: - straight and premultiplied alpha; - straight colour with premultiplied alpha; - additive, modulate, subtract and reverse subtract; - min/max, constant colour, `SRC_ALPHA_SATURATE` and inverse destination; - a colour-only write mask, blend disabled with an R+A mask, and constant alpha; - the four words reported in #1216 from captured state blocks: `0xE5040504`, `0xE5010504`, `0xE5010501` and `0xE1000104`, 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_FLOAT` target 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 keeps `SRC_ALPHA` and `INV_SRC_ALPHA` apart. `--startup-cb-blend-swapped` is the negative control. It exchanges `SrcBlend`/`DestBlend` (and the alpha pair) after decoding, and must disagree with the model. ## Verification Tested `f7ec1944` (on `4919b51a`) on Windows 10 22H2 `19045.6456` with a GTX 1060 6 GB (`10de:1c03`, driver `32.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. ```powershell . .\tools\dev.ps1 $env:XBOX2WINDOWS_ADAPTER = '1060' foreach ($preset in 'dev', 'release') { cmake --preset $preset cmake --build --preset $preset --target offscreen_check -j 2 ctest --preset $preset --no-tests=error -R '^startup_cb_blend' -V } ``` Debug and Release each passed 4/4 (`startup_cb_blend_{hardware,warp}`, `startup_cb_blend_swapped_{hardware,warp}`). - **Normal runs:** 17 of 18 draw cases were drawn, with 0 mismatches. - **Swapped control:** 13 of 17 differed from the model, including straight alpha, the colour-only mask case and all four observed words. The four that can't show a swap are the ONE/ONE forms (additive, subtract, min/max) and the disabled case. - **Skipped case:** constant alpha, on both adapters, because neither reports `AlphaBlendFactorSupported` on this Windows 10 runtime. Its decode path is covered by the table checks. AI-assisted (Claude Code).
src/startup_stubs/cb_blend.h turns CB_BLENDn_CONTROL and a CB_TARGET_MASK nibble into
D3D12_RENDER_TARGET_BLEND_DESC, using the field layout and enums of Mesa's gfx10 register
definitions. Colour factors in alpha slots become their alpha forms; forms D3D12 can't express
(BOTH_SRC_ALPHA, constant alpha without alpha-factor support, MIN/MAX with non-ONE factors,
unknown values) are refused with a reason. The draw path doesn't call it yet: where the registers
sit in the captured state block is still unmeasured.

offscreen_check --startup-cb-blend checks the decoder table and draws each form over a cleared
float target, comparing with a CPU model of the register fields; --startup-cb-blend-swapped
exchanges source and destination factors and must disagree.

Refs #1216.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#1216 reports four CB_BLENDn_CONTROL values from captured state blocks (0xE5040504, 0xE5010504,
0xE5010501, 0xE1000104, with ENABLE, SEPARATE_ALPHA_BLEND and bit 31 set). The decoder table now
checks their exact translation and that bit 31 does not change it, and the draw compares each with
the register model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:50:26 +00:00
github manually merged commit f7ec194453 into gh-pr/1226/base 2026-11-26 22:50:27 +00:00
Author
Owner

@⁠denn0x on GitHub · 2026-11-24 04:36 UTC · original

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, driver 32.0.32015.7029) and WARP (1414:008c).

cmake -S . -B out/build/check -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build out/build/check --target offscreen_check
ctest --no-tests=error -R '^startup_cb_blend' -V

4/4 passed: startup_cb_blend_{hardware,warp} and startup_cb_blend_swapped_{hardware,warp}. Debug layer: 0 errors and 0 warnings on all four.

  • Normal runs: drawn=14 skipped=0 mismatches=0 on 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).
  • Swapped control: drawn=14 mismatches=10 on 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_ALPHA fallback.

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

**@⁠denn0x** on GitHub · 2026-11-24 04:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1226#issuecomment-7122169842) 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`, driver `32.0.32015.7029`) and WARP (`1414:008c`). ``` cmake -S . -B out/build/check -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build out/build/check --target offscreen_check ctest --no-tests=error -R '^startup_cb_blend' -V ``` 4/4 passed: `startup_cb_blend_{hardware,warp}` and `startup_cb_blend_swapped_{hardware,warp}`. Debug layer: 0 errors and 0 warnings on all four. - **Normal runs:** `drawn=14 skipped=0 mismatches=0` on 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`). - **Swapped control:** `drawn=14 mismatches=10` on 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_ALPHA` fallback. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 04:38 UTC · original · reviewed

Reviewed commit 27780101 on Linux (x86_64, Python 3.12 with iced-x86 and pefile). 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: decodes CB_BLENDn_CONTROL + 4-bit CB_TARGET_MASK into a per-target D3D12_RENDER_TARGET_BLEND_DESC:
    • Maps 17 BlendOp factors directly, gates CONSTANT_ALPHA / ONE_MINUS_CONSTANT_ALPHA on alpha_factor_supported (D3D12_OPTIONS13::AlphaBlendFactorSupported), and refuses BOTH_SRC_ALPHA / BOTH_INV_SRC_ALPHA (11, 12) and unknown factors.
    • Converts colour factors (SRC_COLOR, DST_COLOR, SRC1_COLOR and inverses) to their *_ALPHA equivalents for SrcBlendAlpha / DestBlendAlpha, both when SEPARATE_ALPHA_BLEND = 1 and when SEPARATE_ALPHA_BLEND = 0 reuses colour fields; BLEND_FACTOR / INV_BLEND_FACTOR remain valid in alpha slots.
    • Maps CombFunc 0–4 (ADD, SUBTRACT, MIN, MAX, REV_SUBTRACT), refuses 5–7, refuses MIN/MAX with factors other than ONE, refuses target_mask > 0xF, and preserves RenderTargetWriteMask with BlendEnable = FALSE when ENABLE is clear.
    • Note: decode() targets a single render target; setting D3D12_BLEND_DESC::IndependentBlendEnable when wiring multiple targets remains the caller's responsibility.
  • docs/startup-runtime.md is title-neutral and accurately states that the draw path does not call cb_blend.h yet.

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 failed
  • git diff --check HEAD~1..HEAD: passed
**@⁠tedin7** on GitHub · 2026-11-24 04:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1226#pullrequestreview-6033725562) · **reviewed** Reviewed commit `27780101` on Linux (`x86_64`, Python 3.12 with `iced-x86` and `pefile`). 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`: decodes `CB_BLENDn_CONTROL` + 4-bit `CB_TARGET_MASK` into a per-target `D3D12_RENDER_TARGET_BLEND_DESC`: - Maps 17 `BlendOp` factors directly, gates `CONSTANT_ALPHA` / `ONE_MINUS_CONSTANT_ALPHA` on `alpha_factor_supported` (`D3D12_OPTIONS13::AlphaBlendFactorSupported`), and refuses `BOTH_SRC_ALPHA` / `BOTH_INV_SRC_ALPHA` (11, 12) and unknown factors. - Converts colour factors (`SRC_COLOR`, `DST_COLOR`, `SRC1_COLOR` and inverses) to their `*_ALPHA` equivalents for `SrcBlendAlpha` / `DestBlendAlpha`, both when `SEPARATE_ALPHA_BLEND = 1` and when `SEPARATE_ALPHA_BLEND = 0` reuses colour fields; `BLEND_FACTOR` / `INV_BLEND_FACTOR` remain valid in alpha slots. - Maps `CombFunc` 0–4 (`ADD`, `SUBTRACT`, `MIN`, `MAX`, `REV_SUBTRACT`), refuses 5–7, refuses `MIN`/`MAX` with factors other than `ONE`, refuses `target_mask > 0xF`, and preserves `RenderTargetWriteMask` with `BlendEnable = FALSE` when `ENABLE` is clear. - Note: `decode()` targets a single render target; setting `D3D12_BLEND_DESC::IndependentBlendEnable` when wiring multiple targets remains the caller's responsibility. - `docs/startup-runtime.md` is title-neutral and accurately states that the draw path does not call `cb_blend.h` yet. ### 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 failed - `git diff --check HEAD~1..HEAD`: passed
This discussion has been locked. Commenting is limited to contributors.
No description provided.