startup: clear the lane-mask mark when gfx2hlsl overwrites an SGPR #2114

Merged
denn0x merged 1 commit from upstream-pr/2122 into main 2026-11-25 01:13:29 +00:00
denn0x commented 2026-11-25 00:53:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T00:53:50Z.


Part of #1723. Related: #2023 (item L, a lane mask derived from descriptor data, relies on the same mask tracking; this does not lower it)

Stage.masks in tools/startup/gfx2hlsl.py records the SGPRs that hold a lane mask, and a scalar logic op with a mask source is lowered as a mask op, so its result is reduced to the lane's bit. Only the generic scalar path cleared the mark on an ordinary write. After v_cmp_eq_u32_e64 s6, v0, v1 and s_buffer_load_dword s6, s[16:19], 0x0, the instruction s_or_b32 s8, s6, s7 was emitted as s8 = (s6 | s7) & 1;, which cuts the loaded word to bit 0. The stale mark would also make the lane-mask refusals, such as the one for scalar bit tests, refuse a register that no longer holds a mask (not tested here).

Now:

  • set_s clears the mark on every write, after the uniformity of the new value is judged (#1931), so the readfirstlane proof still sees a source register as it was before the write.
  • The writers of a mask (v_cmp*_e64, s_and_saveexec, s_*_wrexec, a copy of exec_lo, s_cselect_b64, the mask logic ops) mark the register again after the write.
  • s_load clears the mark on its destination registers, including the forms that only record a descriptor symbol.

New test tests/startup_gfx2hlsl_mask_overwrite_check.py, registered as startup_gfx2hlsl_mask_overwrite_controls in CMakeLists.txt, AGENTS.md and the Python job, and described in docs/experiments.md. It overwrites a compare result with s_buffer_load, s_load (through a root pointer, and of a descriptor) or s_cselect_b32, then evaluates the following OR on a buffer word. Controls: without the overwrite the OR stays a mask OR, and a compare, saveexec, wrexec, exec copy, s_cselect_b64 or class compare after a load marks the register again.

Verification (branch head 7ebe57e7 on main 246a875d, Windows 11 Pro 10.0.26300, Python 3.13):

  • python -B tests/startup_gfx2hlsl_mask_overwrite_check.py -> exit 0 (mask overwrite: loads and selects clear the mask mark; mask writers mark again). On main the same test reports FAILED: 7 check(s).
  • every tests/startup_gfx2hlsl_*_check.py (including startup_gfx2hlsl_readfirstlane_uniform_check.py), tests/startup_translator_check.py, tests/docs_links_check.py and tests/startup_tools_lint_check.py tools/startup -> 33 scripts, all exit 0.
  • git diff --check main..HEAD -> clean.
  • Not run: a DXC compile or a draw; the check evaluates the emitted HLSL text only.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594598532 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2122). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-25T00:53:50Z. --- Part of #1723. Related: #2023 (item L, a lane mask derived from descriptor data, relies on the same mask tracking; this does not lower it) `Stage.masks` in `tools/startup/gfx2hlsl.py` records the SGPRs that hold a lane mask, and a scalar logic op with a mask source is lowered as a mask op, so its result is reduced to the lane's bit. Only the generic scalar path cleared the mark on an ordinary write. After `v_cmp_eq_u32_e64 s6, v0, v1` and `s_buffer_load_dword s6, s[16:19], 0x0`, the instruction `s_or_b32 s8, s6, s7` was emitted as `s8 = (s6 | s7) & 1;`, which cuts the loaded word to bit 0. The stale mark would also make the lane-mask refusals, such as the one for scalar bit tests, refuse a register that no longer holds a mask (not tested here). Now: - `set_s` clears the mark on every write, after the uniformity of the new value is judged (#1931), so the readfirstlane proof still sees a source register as it was before the write. - The writers of a mask (`v_cmp*_e64`, `s_and_saveexec`, `s_*_wrexec`, a copy of `exec_lo`, `s_cselect_b64`, the mask logic ops) mark the register again after the write. - `s_load` clears the mark on its destination registers, including the forms that only record a descriptor symbol. New test `tests/startup_gfx2hlsl_mask_overwrite_check.py`, registered as `startup_gfx2hlsl_mask_overwrite_controls` in `CMakeLists.txt`, `AGENTS.md` and the Python job, and described in `docs/experiments.md`. It overwrites a compare result with `s_buffer_load`, `s_load` (through a root pointer, and of a descriptor) or `s_cselect_b32`, then evaluates the following OR on a buffer word. Controls: without the overwrite the OR stays a mask OR, and a compare, saveexec, wrexec, exec copy, `s_cselect_b64` or class compare after a load marks the register again. Verification (branch head `7ebe57e7` on `main` `246a875d`, Windows 11 Pro 10.0.26300, Python 3.13): - `python -B tests/startup_gfx2hlsl_mask_overwrite_check.py` -> exit 0 (`mask overwrite: loads and selects clear the mask mark; mask writers mark again`). On `main` the same test reports `FAILED: 7 check(s)`. - every `tests/startup_gfx2hlsl_*_check.py` (including `startup_gfx2hlsl_readfirstlane_uniform_check.py`), `tests/startup_translator_check.py`, `tests/docs_links_check.py` and `tests/startup_tools_lint_check.py tools/startup` -> 33 scripts, all exit 0. - `git diff --check main..HEAD` -> clean. - Not run: a DXC compile or a draw; the check evaluates the emitted HLSL text only. AI-assisted.
upstream-sync closed this pull request 2026-11-25 02:01:49 +00:00
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!2114
No description provided.