Skip to content

rdna2spirv: s_bfm_b64 in wave32 code is 64-bit data, not a lane mask - #6809

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
FIocker:fix/wave32-s-bfm-b64
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
FIocker:fix/wave32-s-bfm-b64

Conversation

@FIocker

@FIocker FIocker commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #5781 (comment).

Problem

958 compute programs of the pipeline library (docs/shader_library.md) have a kind-0 dispatch state that says wave32 (word 4 bit 20), and 905 of them use *_saveexec_b32. translate() refuses all of them with "FSPX wave32 dispatch state contradicts wave64 code". In every one, the only wave64 marker is s_bfm_b64.

They use s_bfm_b64 to build an S# in place:

s_bfm_b64 s[88:89], 2, 54
s_mov_b64 s[90:91], 0x18500000
image_sample ... s[88:91]

3,342 of the 3,475 uses are 2, 54; the rest are 1, 63, 32, 8, 32, 32 and 32, 0.

Dropping the check alone would be wrong. The translator always treats s_bfm_b64 as a per-lane mask, so each invocation would hold 0 or ~0 in the sampler words, and the module would still pass spirv-val.

Change

A 32-lane wave has no 64-bit lane masks, so in wave32 code:

  • Translation: D = ((1 << (S0 & 63)) - 1) << (S1 & 63) goes to the SGPR pair as data, through mov64, so the S# words stay known constants and the literal-sampler path still sees them. A run-time operand is Unsupported; none occurs.
  • Mask tracking: lane_masks.step and analyse take wave64 (default True, so other callers are unchanged) and leave the result as data in wave32.
  • FSPX wave32 check: it no longer counts s_bfm_b64. Every other marker still refuses, and the FSSM header checks and the no-header heuristic are unchanged.

Wave64 behaviour is unchanged.

Effect (counts only)

The 958 programs, disassembled with llvm-mc 23.1.5 for gfx1013:

main 561b65a8 this PR
translate and pass spirv-val 0 203
refused by the FSPX wave32 check 958 0

Most of the rest stop at the next problem: 585 at "v_cmp destination", which is v_cmp_*_e64 vcc_hi in wave32 code. That keeps a 32-bit lane mask in vcc_hi, which the translator models only as half of wave64 vcc; it is a separate change. The others are a lit(...) operand (68, #6808), "mask destination" (59), and s_load with a vcc base (38).

Tests (CPU, no game data)

  • tests/semantic/test_wave32_bfm64_data.py (new) uses the FSPX sidecar with wave32: true, the real case:

    • the value in every invocation for nine (size, offset) pairs, including size 0, size 64 and mod-64 wrap;
    • the folded sampler word in an image_sample;
    • s_bfm_b64 no longer refused, while another wave64 marker still is;
    • a run-time operand refused;
    • lane_masks.step with and without wave64.

    The value cases fail on main.

  • Related suites pass: test_lane_masks, test_salu_bfm64_add_i32, test_wave64_halves, test_wave64_halves_soundness, test_fspx_rules, test_salu_diff and test_crosslane_fuzz. That is 288 passed, 2 skipped.

  • With rdna2spirv: write the compute thread-group SGPR (TG_SIZE_EN) #6446, shader_ir: read LLVM 23's lit(V) operand as the constant V #6808 (lit(V)) and this one merged locally: tests/semantic, tests/test_lane_masks.py and tests/test_shader_ir.py give 6,210 passed, 1 skipped, 1 xfailed, no failures.

docs/design.md: the "Wave64 handling" row.

Not GPU-verified. AI-assisted (Claude Code). Windows 11, Python 3.12, no GPU used.

🤖 Generated with Claude Code

958 compute programs of the pipeline library (docs/shader_library.md) have a
kind-0 dispatch state that says wave32, and 905 of them use *_saveexec_b32. The
translator refused all of them with "FSPX wave32 dispatch state contradicts
wave64 code", and in every one the only wave64 marker is s_bfm_b64. They use it
to build an S# in place: s_bfm_b64 s[88:89], 2, 54 and s_mov_b64 s[90:91],
0x18500000, then image_sample with s[88:91] as the sampler (3,342 of the 3,475
are `2, 54`; the rest are `1, 63`, `32, 8`, `32, 32` and `32, 0`).

A 32-lane wave has no 64-bit lane masks, so there:
* translate: D = ((1 << (S0 & 63)) - 1) << (S1 & 63) goes to the SGPR pair as
  data, through mov64, so the S# words stay known constants (literal samplers).
  A run-time operand is Unsupported (none is seen).
* lane_masks.step/analyse take wave64 (default True, so other callers are
  unchanged) and leave the result data in wave32. Without that it was a
  per-lane mask, which read a sampler word as 0 or ~0.
* The FSPX wave32 check doesn't count s_bfm_b64. Every other marker still
  refuses, and the FSSM checks and the no-header heuristic are unchanged.

tests/semantic/test_wave32_bfm64_data.py runs the value in every invocation for
nine (size, offset) pairs, the constant sampler word, and the refusals. Its
value cases fail without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mortify7612

Copy link
Copy Markdown

Checked 53414165 merged onto main 1cc6e3c1 (clean) on Linux (Debian 12, Python 3.12) with an AMD Radeon RX 9060 XT (RDNA4), RADV Mesa 25.0.7: tests/semantic/test_wave32_bfm64_data.py 6 passed (9 subtests). The full run_gpu_tests.py gives 241/241 translated and valid, 218/235 passed, 17 skipped, none failed, the same as main. Note that all .spv files the suite builds are byte-identical to main's, so no GPU fixture reaches wave32 s_bfm_b64 as data yet: this change has CPU coverage only. AI-assisted (Claude Code).

@fromthemoonx

Copy link
Copy Markdown

Tested 5341416 merged onto main b4adb75 on NVIDIA GeForce RTX 3060 12 GB (Ampere), driver 610.88, Windows 11 Pro 26300, MSVC (VS 2022 Build Tools), llvm-mc 23.1.6, runtime built with scripts\build_runtime.ps1: pass.

  • py -3.12 -I scripts\run_gpu_tests.py (whole suite, native): 188/237 passed, 48 skipped, 1 failed. The one failure is ms_wave_info_s3 (frame left at the clear value, (-1,-1,-1,-1)), which fails the same way on plain main on this PC and is the known ms_wave_info_s3 intermittently fails on RX 7900 XT / RADV NAVI31 (pass rate 100% -> 2.5%, same binaries) #6172 failure (deterministic on NVIDIA there too), so it is not from this PR. cs_wm_bfm64 is skipped here (no 64-wide compute subgroup).
  • py -3.12 -m unittest discover -s tests\semantic -p test_wave32_bfm64_data.py: 6 tests, OK. py -3.12 -I tests\test_lane_masks.py: OK.

Adds an NVIDIA/Windows run to the RDNA4/RADV one above. No game files. AI-assisted (Claude).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

In tools/rdna2spirv.py, wave32 s_bfm_b64 with constant operands now emits mov64 of ((1 << (S0 & 63)) - 1) << (S1 & 63); run-time operands raise Unsupported. translate() tracks the marker set so s_bfm_b64 no longer contradicts an FSPX wave32 dispatch state. tools/lane_masks.py:step()/analyse() take a wave64 flag and leave the result as data in wave32. New test_wave32_bfm64_data.py and a docs/design.md row cover the rule.

Why merge

Unblocks 958 pipeline-library wave32 compute programs that were wrongly refused as "wave64 code", and produces the constant sampler words actually used to build their S# in place rather than per-lane masks. Direct static-recompilation coverage gain.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

In tools/rdna2spirv.py, wave32 s_bfm_b64 with constant operands now emits mov64 of ((1 << (S0 & 63)) - 1) << (S1 & 63); run-time operands raise Unsupported. translate() tracks the marker set so s_bfm_b64 no longer contradicts an FSPX wave32 dispatch state. tools/lane_masks.py:step()/analyse() take a wave64 flag and leave the result as data in wave32. New test_wave32_bfm64_data.py and a docs/design.md row cover the rule.

Why merge

Unblocks 958 pipeline-library wave32 compute programs that were wrongly refused as "wave64 code", and produces the constant sampler words actually used to build their S# in place rather than per-lane masks. Direct static-recompilation coverage gain.

Verdict: Approve

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.

4 participants