startup: lower v_lerp_u8 in gfx2hlsl #2873

Manually merged
github merged 1 commit from github-bot/gh-2873 into gh-pr/2873/base 2026-11-27 05:27:24 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-26 15:30 UTC · original
R0D4X:feat/gfx2hlsl-lerp-u8 → main · +216 −1 · 4 files · 1 commits · merged 2026-11-27 05:26 UTC

Root Cause / Motivation

tools/disasm_rdna2.py already decodes VOP3A v_lerp_u8 (0x14d), but tools/startup/gfx2hlsl.py had no lowering for it in VEC_U, refusing shaders that perform unsigned per-byte averaging with rounding.

Summary

  • Translator (tools/startup/gfx2hlsl.py):
    • Add 'v_lerp_u8': (3, 'lerp_u8({0}, {1}, {2})') to VEC_U.
    • Emit uint lerp_u8(uint a, uint b, uint c) on demand in Pipeline.common() (uses_lerp_u8, absent when unused), implementing AMD RDNA 2 ISA V_LERP_U8:
      • D_i = (S0_i + S1_i + (S2_i & 1)) >> 1 for each byte lane i in 0..3 (preserving only bit 8*i of S2).
    • Add 'v_lerp_u8' to the VOP3A integer neg/abs encoding guard in check_encoding() so neg/abs bits (including inline integers) are rejected with v_lerp_u8 with neg/abs.
  • Fixture & Registration (tests/startup_gfx2hlsl_lerp_u8_check.py, tests/cmake/startup_gfx2hlsl_lerp_u8.cmake, tests/checks/python-linux/startup_gfx2hlsl_lerp_u8.txt):
    • On-demand helper presence/absence check, 600-case CPU evaluation of the exact emitted HLSL helper body, accepted operand forms (VGPR, SGPR, inline constants, literal), exec-masked emission, and pinned refusals (abs/neg on VGPR and inline constants, clamp, omod, op_sel, wrong operand counts).
    • FXC (vs_5_1/ps_5_1) and DXC (vs_6_0/ps_6_0) offscreen draws on WARP and hardware across 2 sets x 4 lanes, plus two GPU mutation controls (dropping & 1u on S2 bytes and dropping rounding bits).

Before / After

  • Before: v_lerp_u8 was rejected as unsupported by gfx2hlsl.py.
  • After: v_lerp_u8 translates via an on-demand lerp_u8 helper, passes 600 reference triples and pinned refusal controls, and matches FXC/DXC readback on WARP and hardware with 0 D3D12 debug-layer errors/warnings.

Verification

  • Commit under test: f283b7c8 (based on b505c32b)
  • Environment: 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
    • WARP: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.9818
    • Hardware: NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2124

Commands and measured results (0 failures, 0 skips):

  • Pure-Python, neighbor, link & bidi checks (git diff --check, startup_gfx2hlsl_lerp_u8_check.py, startup_gfx2hlsl_sad_check.py, startup_gfx2hlsl_sad_hi_msad_check.py, startup_gfx2hlsl_operand_count_check.py, startup_gfx2hlsl_handler_arity_check.py, startup_translator_check.py, run_checks_parallel_check.py, docs_links_check.py, bidi_controls_check.py): PASS
  • ctest --preset dev --no-tests=error -j 1 -R '^(startup_tools_lint|startup_gfx2hlsl_lerp_u8_)' -V: 4/4 passed (4.44 sec, debug_errors=0 debug_warnings=0 on WARP and RTX 5080)
  • ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_lerp_u8_' -V: 3/3 passed (3.93 sec, debug_errors=0 debug_warnings=0 on WARP and RTX 5080)
  • Live self-mutations (drop_s2_mask, drop_top_byte, drop_negabs_guard): 3/3 caught (rc=1) and reverted cleanly.

Evidence Scope

  • Verified locally: pure-Python controls, neighbor/lint/link/bidi checks, dev and release FXC & DXC offscreen draws + 2 GPU mutation controls on WARP and RTX 5080 with D3D12 debug layer enabled, and tools/disasm_rdna2.py decode of all fixture VOP3A words.

AI-assisted; source-built fixtures only.

**@⁠R0D4X** on GitHub · 2026-11-26 15:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2873) `R0D4X:feat/gfx2hlsl-lerp-u8` → `main` · +216 −1 · 4 files · 1 commits · merged 2026-11-27 05:26 UTC ## Root Cause / Motivation `tools/disasm_rdna2.py` already decodes VOP3A `v_lerp_u8` (`0x14d`), but `tools/startup/gfx2hlsl.py` had no lowering for it in `VEC_U`, refusing shaders that perform unsigned per-byte averaging with rounding. ## Summary - **Translator (`tools/startup/gfx2hlsl.py`):** - Add `'v_lerp_u8': (3, 'lerp_u8({0}, {1}, {2})')` to `VEC_U`. - Emit `uint lerp_u8(uint a, uint b, uint c)` on demand in `Pipeline.common()` (`uses_lerp_u8`, absent when unused), implementing AMD RDNA 2 ISA `V_LERP_U8`: - `D_i = (S0_i + S1_i + (S2_i & 1)) >> 1` for each byte lane `i in 0..3` (preserving only bit `8*i` of `S2`). - Add `'v_lerp_u8'` to the VOP3A integer `neg`/`abs` encoding guard in `check_encoding()` so `neg`/`abs` bits (including inline integers) are rejected with `v_lerp_u8 with neg/abs`. - **Fixture & Registration (`tests/startup_gfx2hlsl_lerp_u8_check.py`, `tests/cmake/startup_gfx2hlsl_lerp_u8.cmake`, `tests/checks/python-linux/startup_gfx2hlsl_lerp_u8.txt`):** - On-demand helper presence/absence check, 600-case CPU evaluation of the exact emitted HLSL helper body, accepted operand forms (VGPR, SGPR, inline constants, literal), `exec`-masked emission, and pinned refusals (`abs`/`neg` on VGPR and inline constants, `clamp`, `omod`, `op_sel`, wrong operand counts). - FXC (`vs_5_1`/`ps_5_1`) and DXC (`vs_6_0`/`ps_6_0`) offscreen draws on WARP and hardware across 2 sets x 4 lanes, plus two GPU mutation controls (dropping `& 1u` on `S2` bytes and dropping rounding bits). ## Before / After - **Before:** `v_lerp_u8` was rejected as unsupported by `gfx2hlsl.py`. - **After:** `v_lerp_u8` translates via an on-demand `lerp_u8` helper, passes 600 reference triples and pinned refusal controls, and matches FXC/DXC readback on WARP and hardware with 0 D3D12 debug-layer errors/warnings. ## Verification - Commit under test: `f283b7c8` (based on `b505c32b`) - Environment: 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 - WARP: `Microsoft Basic Render Driver` (`1414:008c`), driver `10.0.26100.9818` - Hardware: `NVIDIA GeForce RTX 5080` (`10de:2c02`), driver `32.0.16.2124` Commands and measured results (0 failures, 0 skips): - Pure-Python, neighbor, link & bidi checks (`git diff --check`, `startup_gfx2hlsl_lerp_u8_check.py`, `startup_gfx2hlsl_sad_check.py`, `startup_gfx2hlsl_sad_hi_msad_check.py`, `startup_gfx2hlsl_operand_count_check.py`, `startup_gfx2hlsl_handler_arity_check.py`, `startup_translator_check.py`, `run_checks_parallel_check.py`, `docs_links_check.py`, `bidi_controls_check.py`): **PASS** - `ctest --preset dev --no-tests=error -j 1 -R '^(startup_tools_lint|startup_gfx2hlsl_lerp_u8_)' -V`: **4/4 passed** (`4.44 sec`, `debug_errors=0 debug_warnings=0` on WARP and RTX 5080) - `ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_lerp_u8_' -V`: **3/3 passed** (`3.93 sec`, `debug_errors=0 debug_warnings=0` on WARP and RTX 5080) - Live self-mutations (`drop_s2_mask`, `drop_top_byte`, `drop_negabs_guard`): **3/3 caught (`rc=1`)** and reverted cleanly. ## Evidence Scope - Verified locally: pure-Python controls, neighbor/lint/link/bidi checks, `dev` and `release` FXC & DXC offscreen draws + 2 GPU mutation controls on WARP and RTX 5080 with D3D12 debug layer enabled, and `tools/disasm_rdna2.py` decode of all fixture VOP3A words. AI-assisted; source-built fixtures only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:27:33 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-26 21:01 UTC · original · reviewed

V_LERP_U8 lowering follows the same clean pattern as recent VOP3A additions (perm_b32, sad variants). The HLSL helper — lerp_u8(a, b, c) = ((a+ b+ c&1)>>1 per byte) — matches the AMD RDNA 2 ISA reference exactly: D.u[i] = (S0.u[i] + S1.u[i] + S2.u[i&1]) >> 1 for each byte lane.

The test harness is solid:

  • 600 edge-triple value evaluations (10 x 10 x 6 input sets covering boundaries, max sums, LSB patterns)
  • Two mutation checks: upper-S2-bit leak masks and dropped rounding, both verified to fail when mutated
  • Accepted operand forms (VGPR, SGPR, inline, literal) plus exec-masked guard
  • Refusals for abs/neg/clamp/omod/op_sel on all sources plus arity checks

check_encoding correctly adds v_lerp_u8 to the neg/abs refusal list shared with other VOP3A integer forms. uses_lerp_u8 follows the same boolean pattern as uses_perm_b32.

No concerns. Clean and correct.

**@⁠KelboLive** on GitHub · 2026-11-26 21:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2873#pullrequestreview-6080434006) · **reviewed** V_LERP_U8 lowering follows the same clean pattern as recent VOP3A additions (perm_b32, sad variants). The HLSL helper — lerp_u8(a, b, c) = ((a+ b+ c&1)>>1 per byte) — matches the AMD RDNA 2 ISA reference exactly: D.u[i] = (S0.u[i] + S1.u[i] + S2.u[i&1]) >> 1 for each byte lane. The test harness is solid: - 600 edge-triple value evaluations (10 x 10 x 6 input sets covering boundaries, max sums, LSB patterns) - Two mutation checks: upper-S2-bit leak masks and dropped rounding, both verified to fail when mutated - Accepted operand forms (VGPR, SGPR, inline, literal) plus exec-masked guard - Refusals for abs/neg/clamp/omod/op_sel on all sources plus arity checks check_encoding correctly adds v_lerp_u8 to the neg/abs refusal list shared with other VOP3A integer forms. uses_lerp_u8 follows the same boolean pattern as uses_perm_b32. No concerns. Clean and correct.
github-bot changed target branch from main to gh-pr/2873/base 2026-11-27 05:27:22 +00:00
github manually merged commit f283b7c82e into gh-pr/2873/base 2026-11-27 05:27:23 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 05:26 UTC · original · approved these changes

Reviewed f283b7c82e31e4f059505f215874ee88c12c1a86 in a clean integration build against main e62e3a5e. The translated helper applies each independent rounding bit without cross-byte carry, and the encoding guard rejects the invalid integer modifiers. The controls and both GPU readbacks passed. Windows 11 26200.9974, Release /O2, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Relevant release tests: startup_gfx2hlsl_lerp_u8_(controls|warp|hardware). Required Windows CI passed.

**@⁠R0Y00** on GitHub · 2026-11-27 05:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2873#pullrequestreview-6083853726) · **approved these changes** Reviewed `f283b7c82e31e4f059505f215874ee88c12c1a86` in a clean integration build against main `e62e3a5e`. The translated helper applies each independent rounding bit without cross-byte carry, and the encoding guard rejects the invalid integer modifiers. The controls and both GPU readbacks passed. Windows 11 26200.9974, Release /O2, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Relevant release tests: startup_gfx2hlsl_lerp_u8_(controls|warp|hardware). Required Windows CI passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.