startup: carry partial colour export masks to the pipeline write mask #2051

Merged
mumba17 merged 2 commits from upstream-pr/2058 into main 2026-11-25 00:11:51 +00:00
mumba17 commented 2026-11-24 23:45:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-24T23:45:01Z.


Closes the open deliverable of #1674 (the issue was auto-closed by the SMEM off commit; the compressed-export part was still refused). Claimed in https://github.com/R0Y00/Xbox2Windows/issues/1674#issuecomment-7142375992.

Problem

A colour export leaves its off channels unwritten, so the render target keeps what it held there. gfx2hlsl refused the compressed form (exp mrt0 v0, v0, off, off done compr vm). It also lowered uncompressed off channels as 0.0 into a full float4. Every target keeps D3D12_COLOR_WRITE_ENABLE_ALL (CB_TARGET_MASK is not located), so substituting zero overwrites channels the console shader leaves alone. #1693 was closed for this reason.

Change

One behaviour: the channels an export writes now reach the pipeline write mask.

  • tools/startup/gfx2hlsl.py:
    • Each mrtN export records its written channels: bit c is set when channel c is not off.
    • The manifest gets wmask <target> 0x<mask> for any target that is not fully written. Full masks write no line, so existing manifests are unchanged.
    • A compressed export lowers when it writes whole binary16 pairs: 0–1 (0x3), 2–3 (0xC) or both.
  • src/startup_stubs/export_write_mask.h (new):
    • Parses wmask lines. It refuses a target above 7, a mask of 0 or above 0xF, any other form, and a second line for the same target. A refused line rejects the manifest.
    • apply_export_write_masks() ANDs each mask into the target's RenderTargetWriteMask. A shared blend state (IndependentBlendEnable FALSE) is first expanded to eight equal entries.
  • src/startup_stubs/d3d12_draw.inl: reads the line and applies the masks in pipeline_for() after the console blend state.
  • Older runtimes: they ignore an unknown manifest line, so a new manifest still loads there, without the mask.

Refusals kept

These match pixel_aot (#398, #434):

  • a compressed en: mask that is not a whole pair (it fell through the export regex before, with an AttributeError);
  • an export of no channel;
  • two exports of one target with different masks (one PSO mask cannot represent them);
  • a packed integer compressed export;
  • a partial compressed export to a vertex output.

Not in this slice, as #1674 states: the value a partially written channel should take.

Overlap

#2034 lowers the same compressed off form by exporting zero without a mask. That is the form #1674 describes as unsafe. With this PR the zeros are still emitted, but the write mask keeps them out of the target.

Tests

Test What it checks Control (must fail)
startup_gfx2hlsl_export_mask Synthetic EXP encodings (documented layout, not cache bytes) through decode() and a full translation with the recorded startup_flat_param vertex stage: disassembly forms, lowered HLSL and wmask lines for both pairs, both pairs, uncompressed partial, two targets, and every refusal above. --mutate drop-mask drops the manifest lines: 4 mask checks fail.
startup_export_write_mask Without a device: accepted and refused line forms, duplicate targets, no-mask no-op, shared-state expansion, and AND with an existing mask (0x9 & 0x3 = 0x1). --mutate shared-blend skips the expansion.
startup_export_write_mask_{warp,hardware} A parsed wmask line applied to an opaque PSO. A constant source drawn over a cleared RGBA32F target. Masks 0x3, 0xC, 0x5, 0x8: unwritten channels keep the cleared value, written channels take the source, exactly. startup_export_write_mask_unmasked_* draws without the mask; all 4 cases must differ.

The hardware readback for 0x3 is 0.75 0.5 1 0.0625: the source 0.75 0.5, and the cleared 1 0.0625.

ctest --preset release --no-tests=error -R "^startup_(gfx2hlsl_)?export_(write_)?mask"

Environment: main at 06cdc47d, Windows 11 build 26300, MSVC 14.44 Release, RTX 3090 (driver 32.0.16.1664) and WARP.

  • New tests: 8/8 pass with the controls failing as required.
  • Related: 46 related translator, blend and refusal-census tests pass.
  • Full suite: the full non-hardware suite is running; result to follow in a comment

Real cache: in a local startup cache, 16 refused pipeline requests stopped at this export. With this change they pass it. They then stop at a separate problem in how their two stages are ordered, which I will report separately; this PR does not change that.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593740343 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2058). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-24T23:45:01Z. --- Closes the open deliverable of #1674 (the issue was auto-closed by the SMEM `off` commit; the compressed-export part was still refused). Claimed in https://github.com/R0Y00/Xbox2Windows/issues/1674#issuecomment-7142375992. ## Problem A colour export leaves its `off` channels unwritten, so the render target keeps what it held there. `gfx2hlsl` refused the compressed form (`exp mrt0 v0, v0, off, off done compr vm`). It also lowered uncompressed `off` channels as `0.0` into a full `float4`. Every target keeps `D3D12_COLOR_WRITE_ENABLE_ALL` (`CB_TARGET_MASK` is not located), so substituting zero overwrites channels the console shader leaves alone. #1693 was closed for this reason. ## Change One behaviour: the channels an export writes now reach the pipeline write mask. - **`tools/startup/gfx2hlsl.py`:** - Each `mrtN` export records its written channels: bit c is set when channel c is not `off`. - The manifest gets `wmask <target> 0x<mask>` for any target that is not fully written. Full masks write no line, so existing manifests are unchanged. - A compressed export lowers when it writes whole binary16 pairs: 0–1 (`0x3`), 2–3 (`0xC`) or both. - **`src/startup_stubs/export_write_mask.h` (new):** - Parses `wmask` lines. It refuses a target above 7, a mask of 0 or above `0xF`, any other form, and a second line for the same target. A refused line rejects the manifest. - `apply_export_write_masks()` ANDs each mask into the target's `RenderTargetWriteMask`. A shared blend state (`IndependentBlendEnable` FALSE) is first expanded to eight equal entries. - **`src/startup_stubs/d3d12_draw.inl`:** reads the line and applies the masks in `pipeline_for()` after the console blend state. - **Older runtimes:** they ignore an unknown manifest line, so a new manifest still loads there, without the mask. ### Refusals kept These match `pixel_aot` (#398, #434): - a compressed `en:` mask that is not a whole pair (it fell through the export regex before, with an `AttributeError`); - an export of no channel; - two exports of one target with different masks (one PSO mask cannot represent them); - a packed integer compressed export; - a partial compressed export to a vertex output. Not in this slice, as #1674 states: the value a partially written channel should take. ### Overlap #2034 lowers the same compressed `off` form by exporting zero without a mask. That is the form #1674 describes as unsafe. With this PR the zeros are still emitted, but the write mask keeps them out of the target. ## Tests | Test | What it checks | Control (must fail) | |---|---|---| | `startup_gfx2hlsl_export_mask` | Synthetic EXP encodings (documented layout, not cache bytes) through `decode()` and a full translation with the recorded `startup_flat_param` vertex stage: disassembly forms, lowered HLSL and `wmask` lines for both pairs, both pairs, uncompressed partial, two targets, and every refusal above. | `--mutate drop-mask` drops the manifest lines: 4 mask checks fail. | | `startup_export_write_mask` | Without a device: accepted and refused line forms, duplicate targets, no-mask no-op, shared-state expansion, and AND with an existing mask (`0x9 & 0x3 = 0x1`). | `--mutate shared-blend` skips the expansion. | | `startup_export_write_mask_{warp,hardware}` | A parsed `wmask` line applied to an opaque PSO. A constant source drawn over a cleared RGBA32F target. Masks `0x3`, `0xC`, `0x5`, `0x8`: unwritten channels keep the cleared value, written channels take the source, exactly. | `startup_export_write_mask_unmasked_*` draws without the mask; all 4 cases must differ. | The hardware readback for `0x3` is `0.75 0.5 1 0.0625`: the source `0.75 0.5`, and the cleared `1 0.0625`. ``` ctest --preset release --no-tests=error -R "^startup_(gfx2hlsl_)?export_(write_)?mask" ``` **Environment:** `main` at `06cdc47d`, Windows 11 build 26300, MSVC 14.44 Release, RTX 3090 (driver 32.0.16.1664) and WARP. - **New tests:** 8/8 pass with the controls failing as required. - **Related:** 46 related translator, blend and refusal-census tests pass. - **Full suite:** the full non-hardware suite is running; result to follow in a comment **Real cache:** in a local startup cache, 16 refused pipeline requests stopped at this export. With this change they pass it. They then stop at a separate problem in how their two stages are ordered, which I will report separately; this PR does not change that. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 01:01:22 +00:00
mumba17 commented 2026-11-25 01:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-24T23:45:37Z.


Full non-hardware suite on 03dee932 (this branch on main 06cdc47d), Windows 11 26300, MSVC 14.44 Release: ctest --preset release -E _hardware -j 8 -> 942/942 passed (454 s). The new _hardware write-mask tests pass on the RTX 3090 as listed above.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147763288 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2058#issuecomment-7147763288). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-24T23:45:37Z. --- Full non-hardware suite on `03dee932` (this branch on `main` `06cdc47d`), Windows 11 26300, MSVC 14.44 Release: `ctest --preset release -E _hardware -j 8` -> **942/942 passed** (454 s). The new `_hardware` write-mask tests pass on the RTX 3090 as listed above. AI-assisted (Claude Code).
R0Y00 commented 2026-11-25 01:02:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:07:17Z.


I pushed three fixes for the production path. Both cache writers now use revision 7, so the pre-fix zero-filled manifests cannot win the lookup. The reader rejects signed, oversized and malformed mask tokens. The pipeline preserves a legal shared logic operation when the masks agree, and refuses incompatible per-target masks before desktop PSO creation. Windows Release passed all 14 selected blend and export checks, including hardware and WARP pixel readback and the unmasked controls. The separate RTX 3090 startup report used a local slot 148 stand-in.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148165460 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2058#issuecomment-7148165460). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T00:07:17Z. --- I pushed three fixes for the production path. Both cache writers now use revision 7, so the pre-fix zero-filled manifests cannot win the lookup. The reader rejects signed, oversized and malformed mask tokens. The pipeline preserves a legal shared logic operation when the masks agree, and refuses incompatible per-target masks before desktop PSO creation. Windows Release passed all 14 selected blend and export checks, including hardware and WARP pixel readback and the unmasked controls. The separate RTX 3090 startup report used a local slot 148 stand-in.
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!2051
No description provided.