startup: lower v_add_nc_i32 and v_sub_nc_i32 in gfx2hlsl #3043

Merged
R0D4X merged 1 commit from upstream-pr/3043 into main 2026-11-27 11:48:47 +00:00
R0D4X commented 2026-11-27 10:35:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-27T10:35:26Z.


What this changes

  • Lowers gfx1013 VOP3A v_add_nc_i32 (0x37f) and v_sub_nc_i32 (0x376) in tools/startup/gfx2hlsl.py:
    • Unclamped: wrapping 32-bit a + b / a - b with align4 propagation.
    • With clamp: signed 32-bit saturating add/sub to [-2^31, 2^31 - 1] via on-demand HLSL helpers (add_sat_i32 / sub_sat_i32), clearing align4.
  • Adds UNIFORM_VALU tracking for both unclamped and clamped forms, refuses _e32 spellings, unsupported modifiers, lane masks, and bad arity/operands, and rejects neg/abs or nonzero unused src2 bits in check_encoding().

Tests added

  • tests/startup_gfx2hlsl_v_add_sub_nc_i32_check.py: synthetic VOP3A decode via G.decode(), 400-case evaluation directly against the emitted HLSL expressions and helpers, selective helper emission, EXEC masking, align4 & uniformity checks, encoding & Stage refusals, unlowered controls, and FXC ps_5_1 + DXC ps_6_0 offscreen readback draws with negative controls.
  • Registered in tests/cmake/startup_gfx2hlsl_v_add_sub_nc_i32.cmake and tests/checks/python-linux/startup_gfx2hlsl_v_add_sub_nc_i32.txt.

Verification

Commit: deb96d16 on Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + DXC 1.9.2602.17, D3D12 debug layer enabled (debug_errors=0 debug_warnings=0):

  • ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_add_sub_nc_i32|^startup_tools_lint$': 4/4 passed, 0 skipped
    • WARP (Microsoft Basic Render Driver, 1414:008c, driver 10.0.26100.9818): pass
    • Hardware (NVIDIA GeForce RTX 5080, 10de:2c02, driver 32.0.16.2124): pass
  • ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_add_sub_nc_i32': 3/3 passed, 0 skipped
  • Repo/neighbor checks (docs_links_check.py, bidi_controls_check.py, startup_gfx2hlsl_handler_arity_check.py, startup_gfx2hlsl_refusals_check.py, startup_gfx2hlsl_add_sub_co_check.py, git diff --check): all passed.

Scope: Covers synthetic v_add_nc_i32 / v_sub_nc_i32 fixtures in the offline gfx2hlsl translator and offscreen D3D12 draw harness; does not establish full-title startup or runtime execution.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5525163402 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3043). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-27T10:35:26Z. --- ## What this changes - Lowers gfx1013 VOP3A `v_add_nc_i32` (`0x37f`) and `v_sub_nc_i32` (`0x376`) in `tools/startup/gfx2hlsl.py`: - Unclamped: wrapping 32-bit `a + b` / `a - b` with `align4` propagation. - With `clamp`: signed 32-bit saturating add/sub to `[-2^31, 2^31 - 1]` via on-demand HLSL helpers (`add_sat_i32` / `sub_sat_i32`), clearing `align4`. - Adds `UNIFORM_VALU` tracking for both unclamped and clamped forms, refuses `_e32` spellings, unsupported modifiers, lane masks, and bad arity/operands, and rejects `neg`/`abs` or nonzero unused `src2` bits in `check_encoding()`. ## Tests added - `tests/startup_gfx2hlsl_v_add_sub_nc_i32_check.py`: synthetic VOP3A decode via `G.decode()`, 400-case evaluation directly against the emitted HLSL expressions and helpers, selective helper emission, `EXEC` masking, `align4` & uniformity checks, encoding & `Stage` refusals, unlowered controls, and FXC `ps_5_1` + DXC `ps_6_0` offscreen readback draws with negative controls. - Registered in `tests/cmake/startup_gfx2hlsl_v_add_sub_nc_i32.cmake` and `tests/checks/python-linux/startup_gfx2hlsl_v_add_sub_nc_i32.txt`. ## Verification Commit: `deb96d16` on Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, FXC + DXC `1.9.2602.17`, D3D12 debug layer enabled (`debug_errors=0 debug_warnings=0`): - `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_v_add_sub_nc_i32|^startup_tools_lint$'`: 4/4 passed, 0 skipped - WARP (`Microsoft Basic Render Driver`, `1414:008c`, driver `10.0.26100.9818`): pass - Hardware (`NVIDIA GeForce RTX 5080`, `10de:2c02`, driver `32.0.16.2124`): pass - `ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_v_add_sub_nc_i32'`: 3/3 passed, 0 skipped - Repo/neighbor checks (`docs_links_check.py`, `bidi_controls_check.py`, `startup_gfx2hlsl_handler_arity_check.py`, `startup_gfx2hlsl_refusals_check.py`, `startup_gfx2hlsl_add_sub_co_check.py`, `git diff --check`): all passed. *Scope:* Covers synthetic `v_add_nc_i32` / `v_sub_nc_i32` fixtures in the offline `gfx2hlsl` translator and offscreen D3D12 draw harness; does not establish full-title startup or runtime execution.
R0Y00 commented 2026-11-27 11:46:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:46:58Z.

Review: APPROVED


Reviewed deb96d16 in integration tree 45a311bc on main 1c879506 with the preceding packed-integer PRs in the tested merge order where applicable. python -B tests/startup_gfx2hlsl_v_add_sub_nc_i32_check.py passed. Its draw <dxc> <offscreen_check> <warp|hardware> <fxc> invocation passed on WARP and RTX with both Debug and Release /O2 renderers, reusing builds of the unchanged renderer sources. Wrapping, signed clamp at both overflow boundaries, and the bad-operand controls matched. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled. Hosted Windows, Linux Python and gfx1013 checks passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6087651685 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3043#pullrequestreview-6087651685). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T11:46:58Z. **Review:** APPROVED --- Reviewed `deb96d16` in integration tree `45a311bc` on `main` `1c879506` with the preceding packed-integer PRs in the tested merge order where applicable. `python -B tests/startup_gfx2hlsl_v_add_sub_nc_i32_check.py` passed. Its `draw <dxc> <offscreen_check> <warp|hardware> <fxc>` invocation passed on WARP and RTX with both Debug and Release /O2 renderers, reusing builds of the unchanged renderer sources. Wrapping, signed clamp at both overflow boundaries, and the bad-operand controls matched. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled. Hosted Windows, Linux Python and gfx1013 checks 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!3043
No description provided.