Skip to content

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

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
lambirou:shader/mesh-a1-small-alu
Dec 3, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
lambirou:shader/mesh-a1-small-alu

Conversation

@lambirou

@lambirou lambirou commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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 lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reviewed 5774fb6. 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.

@R0Y00
R0Y00 merged commit 06251bd into R0Y00:main Dec 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants