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

Merged
Jess-Doit merged 2 commits from upstream-pr/1226 into main 2026-11-24 04:41:19 +00:00
Jess-Doit commented 2026-11-24 04:25:20 +00:00 (Migrated from github.com)

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.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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574590233 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1226). Originally posted by [Jess-Doit](https://github.com/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.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).
upstream-sync closed this pull request 2026-11-24 06:47:05 +00:00
tedin7 commented 2026-11-24 06:47:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:38:49Z.

Review: COMMENTED


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
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033725562 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1226#pullrequestreview-6033725562). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:38:49Z. **Review:** COMMENTED --- 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
denn0x commented 2026-11-24 06:50:20 +00:00 (Migrated from github.com)

Imported 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, 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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122169842 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1226#issuecomment-7122169842). Originally posted by [denn0x](https://github.com/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`, 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).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1219
No description provided.