shader: lower v_xad_u32 and v_log_f32 in the mesh frontend #3903

Merged
lambirou merged 2 commits from upstream-pr/3903 into main 2026-12-03 01:53:56 +00:00
lambirou commented 2026-12-03 00:35:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-03T00:35:44Z.


Problem

The 3 December work split on #3703 leaves A1 (small ALU) open: v_xad_u32 is the first refusal for 66 mesh programs, v_log_f32 for 37, and ds_swizzle_b32 for 17. The two former already have lowerings in the shared compute ALU; the native mesh frontend simply did not admit them.

Change

  • Add v_xad_u32 (VOP3 0x345) to the mesh vector list. It takes three sources and lowers to (S0 ^ S1) + S2 modulo 2^32, matching the compute frontend.
  • Add v_log_f32 (VOP1 0x27) to the same list. It evaluates DXIL Log (dx.op.unary.f32, opcode 23) through the shared float ALU.
  • Keep ds_swizzle_b32 refused for now; a general lane-swizzle exchange is a separate design.

Tests

tests/native_direct_mesh_check.py adds source-built programs:

  • v_xad_u32 v1, v0, s20, s21 with s20 = 0x0000ffff and s21 = 0x00ff0000 emits xor i32 %v0, 65535 then add i32 %xor, 16711680, exported through POS0.x. An unbound third source keeps unbound numeric SGPR s24.
  • v_log_f32 v1, v0 emits call float @dx.op.unary.f32(i32 23, ...) and exports the bitcast result.
python -B tests/native_direct_mesh_check.py out/build/release/compile_dxil.exe "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64"
mesh allocation, indexed outputs, group exchange and negative controls passed

tests/docs_links_check.py passed (258 files, 969 links).

Coverage

On the issue census, the two forms clear the first refusal for 103 of the 120 A1 programs. ds_swizzle_b32 (17) stays in the bucket and will show the next refusal. This PR does not claim a new total; the census owner can rerun the capture.

Refs #3703

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5617354795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3903). Originally posted by [lambirou](https://github.com/lambirou) on 2026-12-03T00:35:44Z. --- ## Problem The 3 December work split on #3703 leaves A1 (small ALU) open: `v_xad_u32` is the first refusal for 66 mesh programs, `v_log_f32` for 37, and `ds_swizzle_b32` for 17. The two former already have lowerings in the shared compute ALU; the native mesh frontend simply did not admit them. ## Change - Add `v_xad_u32` (VOP3 `0x345`) to the mesh vector list. It takes three sources and lowers to `(S0 ^ S1) + S2` modulo 2^32, matching the compute frontend. - Add `v_log_f32` (VOP1 `0x27`) to the same list. It evaluates DXIL Log (`dx.op.unary.f32`, opcode 23) through the shared float ALU. - Keep `ds_swizzle_b32` refused for now; a general lane-swizzle exchange is a separate design. ## Tests `tests/native_direct_mesh_check.py` adds source-built programs: - `v_xad_u32 v1, v0, s20, s21` with `s20 = 0x0000ffff` and `s21 = 0x00ff0000` emits `xor i32 %v0, 65535` then `add i32 %xor, 16711680`, exported through POS0.x. An unbound third source keeps `unbound numeric SGPR s24`. - `v_log_f32 v1, v0` emits `call float @dx.op.unary.f32(i32 23, ...)` and exports the bitcast result. ``` python -B tests/native_direct_mesh_check.py out/build/release/compile_dxil.exe "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64" mesh allocation, indexed outputs, group exchange and negative controls passed ``` `tests/docs_links_check.py` passed (258 files, 969 links). ## Coverage On the issue census, the two forms clear the first refusal for 103 of the 120 A1 programs. `ds_swizzle_b32` (17) stays in the bucket and will show the next refusal. This PR does not claim a new total; the census owner can rerun the capture. Refs #3703
lukaslw-lab commented 2026-12-03 01:20:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-03T01:20:53Z.

Review: APPROVED


Reviewed f34f450e by reading the diff; not built or run. Then ran the mesh census of #3703 on main f3ab02fee with and without this PR merged on top.

Verdict: approve. Both forms reuse existing shared rules and keep the operand gates; the census matches the claim. No MUST.

Mesh census (6,685 distinct programs, first refusal each) main f3ab02fee + #3903
translate 2,046 2,046
v_xad_u32 66 0
v_log_f32 37 0
moved to a later refusal 103

0 gained, 0 lost; no other program changed. Next refusals: v_xad_u32 → mesh SAVEEXEC then arm depends on EXEC 54, VCC branch without a whole-wave mask 8, unbound numeric SGPR s7 4; v_log_f32 → v_exp_f32 23, v_med3_f32 14.

  • SHOULD v_xad_u32 is not in alu_rules (gfx1013_compute_alu.inl), and it is not in the mesh three-source fallback either (gfx1013_direct_mesh.inl:2924-2926, next to v_add3_u32). So sources is 0 for it and uniform_result (:2947) is always false: a v_xad_u32 of wave-uniform operands is never recorded as uniform. That is safe (a missed proof, not a wrong value), but a later v_readfirstlane_b32 or scalar use of such a result will refuse. Adding it beside v_add3_u32 fixes that.
  • Checked: v_log_f32 takes the shared float rule (log2, DXIL opcode 23, gfx1013_direct_compute.inl:3976); v_xad_u32 lowers to add(xor(a, b), c) as in compute (:6071). Both stay behind the existing modifier and SDWA/DPP gates.
  • The Windows CI failure is native_mesh_entry_registers_ir, which fails on main itself (#3906, fix in #3907), not this PR.

Tests: native_direct_mesh_check.py adds v-xad-u32 (pins the xor/add pair and the POS0.x export), v-xad-unproven (refusal with an unbound source) and v-log-f32 (pins opcode 23 and the export). They reach the two new allowlist entries. CI ran native_direct_mesh at this head and it passed (run 47004569559).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6162061703 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3903#pullrequestreview-6162061703). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-03T01:20:53Z. **Review:** APPROVED --- Reviewed `f34f450e` by reading the diff; not built or run. Then ran the mesh census of #3703 on main `f3ab02fee` with and without this PR merged on top. **Verdict: approve.** Both forms reuse existing shared rules and keep the operand gates; the census matches the claim. No MUST. | Mesh census (6,685 distinct programs, first refusal each) | main `f3ab02fee` | + #3903 | |---|---:|---:| | translate | 2,046 | 2,046 | | `v_xad_u32` | 66 | 0 | | `v_log_f32` | 37 | 0 | | moved to a later refusal | | 103 | 0 gained, 0 lost; no other program changed. Next refusals: `v_xad_u32` → `mesh SAVEEXEC then arm depends on EXEC` 54, `VCC branch without a whole-wave mask` 8, `unbound numeric SGPR s7` 4; `v_log_f32` → `v_exp_f32` 23, `v_med3_f32` 14. - **SHOULD** `v_xad_u32` is not in `alu_rules` (`gfx1013_compute_alu.inl`), and it is not in the mesh three-source fallback either (`gfx1013_direct_mesh.inl:2924-2926`, next to `v_add3_u32`). So `sources` is 0 for it and `uniform_result` (`:2947`) is always false: a `v_xad_u32` of wave-uniform operands is never recorded as uniform. That is safe (a missed proof, not a wrong value), but a later `v_readfirstlane_b32` or scalar use of such a result will refuse. Adding it beside `v_add3_u32` fixes that. - Checked: `v_log_f32` takes the shared float rule (`log2`, DXIL opcode 23, `gfx1013_direct_compute.inl:3976`); `v_xad_u32` lowers to `add(xor(a, b), c)` as in compute (`:6071`). Both stay behind the existing modifier and SDWA/DPP gates. - The Windows CI failure is `native_mesh_entry_registers_ir`, which fails on main itself (#3906, fix in #3907), not this PR. Tests: `native_direct_mesh_check.py` adds `v-xad-u32` (pins the `xor`/`add` pair and the POS0.x export), `v-xad-unproven` (refusal with an unbound source) and `v-log-f32` (pins opcode 23 and the export). They reach the two new allowlist entries. CI ran `native_direct_mesh` at this head and it passed (run `47004569559`).
R0Y00 commented 2026-12-03 01:53:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T01:53:53Z.

Review: APPROVED


Independently reviewed 5774fb64. Both mesh forms use the existing ALU rules and retain the operand gates. MSVC Debug ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(native_direct_mesh|native_mesh_entry_registers_ir)$' passed 2/2. Removing only v_xad_u32 from the mesh allowlist made the first new XAD case fail with an unsupported mesh instruction at +0x24. Restored, the direct mesh fixture passed. This is an IR result and the updated baseline also passes the formerly red mesh entry case.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6162356246 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3903#pullrequestreview-6162356246). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T01:53:53Z. **Review:** APPROVED --- Independently reviewed 5774fb64. Both mesh forms use the existing ALU rules and retain the operand gates. MSVC Debug `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(native_direct_mesh|native_mesh_entry_registers_ir)$'` passed 2/2. Removing only v_xad_u32 from the mesh allowlist made the first new XAD case fail with an unsupported mesh instruction at +0x24. Restored, the direct mesh fixture passed. This is an IR result and the updated baseline also passes the formerly red mesh entry case.
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!3903
No description provided.