shader: keep only defined bits under a mesh SDWA UNUSED_PRESERVE write (Part of #3703) #3941

Merged
mumba17 merged 1 commit from upstream-pr/3941 into main 2026-12-03 15:39:33 +00:00
mumba17 commented 2026-12-03 15:19:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-03T15:19:09Z.


Part of #3703 (the half-write slice of graphics register undefined on an incoming path, left with us in https://github.com/R0Y00/Xbox2Windows/issues/3703#issuecomment-7358494917).

Problem

Since #3862, a mesh v_cvt_f16_f32 into a register that has no value on one incoming path (or was never written) defines only the low half. Programs then fill the high half with an SDWA v_cvt_f16_f32 … dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE. place_subword built that merge from read(i.dst), which needs every bit of the old register, so the write was refused with graphics register read includes undefined bits, although the two writes together define the whole register.

Change

Under graphics_half_writes (the mesh frontend), UNUSED_PRESERVE keeps the other bits only where they are defined (graphics_bits), the rule v_cvt_f16_f32 and v_fma_mixlo_f16/v_fma_mixhi_f16 already use. The result is recorded as defined in the written bits plus the kept ones. A later read that needs a kept bit with no value is still refused by read_storage. Paths without graphics_half_writes, and UNUSED_PAD/UNUSED_SEXT, are unchanged.

Tests (native_direct_mesh)

  • cvt-f16-sdwa-high-over-low: v10 has no value on one path after a widened EXEC. v_cvt_f16_f32 v10 writes the low half, the SDWA WORD_1 preserve conversion writes the high half, and a whole-word read of v10 translates. The output places the narrowed 0.5 above the narrowed 1.0 (shl … 16 or'd with and … 65535).
  • cvt-f16-sdwa-high-only: the same SDWA write with no low-half write first. A whole-word read is refused with graphics register read includes undefined bits: 266.
  • Mutation check: with the source change reverted, cvt-f16-sdwa-high-over-low fails with graphics register read includes undefined bits: 266.

Census

Our native Mesh86 capture (RTX 3090, 600 s) gives 6,685 distinct .m86 programs, each run once through compile_dxil … gfx1013-container-ms-texture-heap.

  • main adfc0d94: 2,161 translate. 5 stop at graphics register read includes undefined bits, all at this preserve write.
  • With this change: 2,163 translate, 0 lost. Of the 5, 2 translate and 3 move to unproven packed mesh signature rows (2) and unsupported packed vertex export (1). No other program's first refusal changes.

Counts only; request bytes stay local.

Checks

Windows 11 build 26300, MSVC (VS Build Tools 14.44), SDK/DXC 10.0.26100. ctest --preset pr on this commit (rebased on main 4b2c8343): 346/348 pass, native_direct_mesh included. The two local failures, native_compute_implicit_lod_controls and native_wave_virtual_derivative_controls, are the local SDK validator 1.7 vs DXIL 1.8 and fail on main too. The census above was measured on adfc0d94 and not rerun after the rebase.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5629378701 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3941). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-03T15:19:09Z. --- Part of #3703 (the half-write slice of `graphics register undefined on an incoming path`, left with us in https://github.com/R0Y00/Xbox2Windows/issues/3703#issuecomment-7358494917). ## Problem Since #3862, a mesh `v_cvt_f16_f32` into a register that has no value on one incoming path (or was never written) defines only the low half. Programs then fill the high half with an SDWA `v_cvt_f16_f32 … dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE`. `place_subword` built that merge from `read(i.dst)`, which needs every bit of the old register, so the write was refused with `graphics register read includes undefined bits`, although the two writes together define the whole register. ## Change Under `graphics_half_writes` (the mesh frontend), `UNUSED_PRESERVE` keeps the other bits only where they are defined (`graphics_bits`), the rule `v_cvt_f16_f32` and `v_fma_mixlo_f16`/`v_fma_mixhi_f16` already use. The result is recorded as defined in the written bits plus the kept ones. A later read that needs a kept bit with no value is still refused by `read_storage`. Paths without `graphics_half_writes`, and `UNUSED_PAD`/`UNUSED_SEXT`, are unchanged. ## Tests (`native_direct_mesh`) - `cvt-f16-sdwa-high-over-low`: v10 has no value on one path after a widened EXEC. `v_cvt_f16_f32 v10` writes the low half, the SDWA WORD_1 preserve conversion writes the high half, and a whole-word read of v10 translates. The output places the narrowed 0.5 above the narrowed 1.0 (`shl … 16` or'd with `and … 65535`). - `cvt-f16-sdwa-high-only`: the same SDWA write with no low-half write first. A whole-word read is refused with `graphics register read includes undefined bits: 266`. - Mutation check: with the source change reverted, `cvt-f16-sdwa-high-over-low` fails with `graphics register read includes undefined bits: 266`. ## Census Our native Mesh86 capture (RTX 3090, 600 s) gives 6,685 distinct `.m86` programs, each run once through `compile_dxil … gfx1013-container-ms-texture-heap`. - `main` `adfc0d94`: 2,161 translate. 5 stop at `graphics register read includes undefined bits`, all at this preserve write. - With this change: 2,163 translate, 0 lost. Of the 5, 2 translate and 3 move to `unproven packed mesh signature rows` (2) and `unsupported packed vertex export` (1). No other program's first refusal changes. Counts only; request bytes stay local. ## Checks Windows 11 build 26300, MSVC (VS Build Tools 14.44), SDK/DXC 10.0.26100. `ctest --preset pr` on this commit (rebased on `main` `4b2c8343`): 346/348 pass, `native_direct_mesh` included. The two local failures, `native_compute_implicit_lod_controls` and `native_wave_virtual_derivative_controls`, are the local SDK validator 1.7 vs DXIL 1.8 and fail on `main` too. The census above was measured on `adfc0d94` and not rerun after the rebase. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-12-03 15:39:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T15:39:28Z.

Review: APPROVED


Independently reviewed 432d5075. The preserve merge masks out the bits being replaced and intersects the remaining bits with the available graphics SSA definition. The missing-low-half control still refuses the whole-register read, and the existing non-mesh path retains its full-word read.

On Windows 11 with MSVC Debug I rebuilt compile_dxil and ran ctest --test-dir out/build/review --no-tests=error -R '^native_direct_mesh$' --output-on-failure (1/1 passed, no skips). Disabling only the new graphics preserve branch and rebuilding made cvt-f16-sdwa-high-over-low fail at +0x44 with “graphics register read includes undefined bits: 266”. The unmodified fixture also checks the negative case where no low half was ever defined. These verify compilation and emitted DXIL. The required Windows check passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6173060223 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3941#pullrequestreview-6173060223). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T15:39:28Z. **Review:** APPROVED --- Independently reviewed 432d5075. The preserve merge masks out the bits being replaced and intersects the remaining bits with the available graphics SSA definition. The missing-low-half control still refuses the whole-register read, and the existing non-mesh path retains its full-word read. On Windows 11 with MSVC Debug I rebuilt compile_dxil and ran ctest --test-dir out/build/review --no-tests=error -R '^native_direct_mesh$' --output-on-failure (1/1 passed, no skips). Disabling only the new graphics preserve branch and rebuilding made cvt-f16-sdwa-high-over-low fail at +0x44 with “graphics register read includes undefined bits: 266”. The unmodified fixture also checks the negative case where no low half was ever defined. These verify compilation and emitted DXIL. The required Windows check passed.
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!3941
No description provided.