Skip to content

rdna2spirv: accept ds_swizzle_b32 with offset:0 / omitted offset (SHADER-716) - #5101

Open
kotekompotek wants to merge 1 commit into
ItsNotRexed:mainfrom
kotekompotek:work/shader-716-ds-swizzle-offset0
Open

kotekompotek wants to merge 1 commit into
ItsNotRexed:mainfrom
kotekompotek:work/shader-716-ds-swizzle-offset0

Conversation

@kotekompotek

Copy link
Copy Markdown

Implements SHADER-716:

  • In Gen.swizzle (tools/rdna2spirv.py), treat ds_swizzle_b32 with offset:0 / offset:0x0 or omitted offset: as QUAD_PERM(0, 0, 0, 0) instead of raising Unsupported("ds_swizzle pattern").
  • Non-zero raw offsets without swizzle(...) remain Unsupported.
  • Adds tests/semantic/test_ds_swizzle_offset0.py (2/2 OK).
  • Verified locally:
    • python -I tests/semantic/test_ds_swizzle_offset0.py -v (2/2 OK)
    • git diff --check (clean)

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 9f6cdc17531e6a2aa4fa959691c8ca758ad27475 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

At 9f6cdc17, omitted-offset ds_swizzle_b32 selects the wrong source lane beyond the first quad. I ran a synthetic wave32 shader with lane IDs as its input, then read lanes 0, 4, 8, and 31 after the swizzle. The translated shader passed SPIR-V validation and returned 0, 4, 8, 28 on Linux RTX 5090. For a zero bitmask pattern all five lane-index bits are cleared, so the expected result is 0, 0, 0, 0.

The PR's equivalence test compares against quad permute. LLVM encodes that mode at 0x8000; the omitted offset defaults to zero, which selects bitmask mode. Please lower the zero pattern as a broadcast from lane 0 within each 32-lane group and test with distinguishable input values across quad boundaries. The observed words are from Vulkan translation; the encoding reference supplies the expected behavior. LLVM modifier syntax and LLVM encoding definitions.

AI-assisted verification.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 9f6cdc1 on Linux (Ubuntu 24.04, Python 3.12.3), CPU only, no game files: pass.

  • tests/semantic test_ds_swizzle_offset0.py: Ran 2 tests, OK (test_omitted_and_zero_offset_match_quad_perm_0 and test_nonzero_raw_offset_still_rejected).
  • tests/test_rdna2_decode.py with LLVM_MC unset: Ran 9 tests, OK (skipped=1, the llvm-mc parity test).

No build is involved, since the PR changes only tools/rdna2spirv.py and a Python test.

AI-assisted.

@XFlawless1

Copy link
Copy Markdown
Contributor

Confirming @tylerstraub's result on the CPU side at 9f6cdc17, and pointing to an overlapping PR.

  • Encodings: llvm-mc 21.1.8 (-mcpu=gfx1013) gives a plain ds_swizzle_b32 v0, v1, offset:swizzle(BROADCAST,32,0) and offset:swizzle(BITMASK_PERM,"00000") the same encoding ([0x00,0x00,0xd4,0xd8,...]); swizzle(QUAD_PERM,0,0,0,0) is [0x00,0x80,...].
  • Model: lds_fuzz.py's swizzle_src, checked against AMD hardware in Tools: hardware oracle for lds_fuzz — 60,000 LDS programs on real AMD hardware, 0 mismatches; answers SHADER-105 #1345, gives lane & ~31 for offset 0 (lane 0 of each 32-lane group), not lane & ~3.
  • This PR's translator: the plain form now produces the same SPIR-V as QUAD_PERM(0,0,0,0), and different SPIR-V from both BROADCAST,32,0 and BITMASK_PERM "00000", so test_ds_swizzle_offset0.py pins the quad reading.

Overlap: #4177 (SweatierKey, open, mergeable) already decodes the omitted and numeric offset:N forms with bit 15 clear as bitmask mode (offset 0 → broadcast of lane 0 per 32-lane group). Its tests cover omitted and offset:0 in wave32 and wave64. It may be simpler to review that one than to fix this one.

CPU only, Windows 11, Python 3.12. No game files. AI-assisted (Claude Code).

@Kam471 Kam471 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.

Ran this at 9f6cdc175 on Windows 11: tests/semantic/test_ds_swizzle_offset0.py -> 2 tests, OK; git diff --check clean.

ds_swizzle_b32 with offset:0 or an omitted offset is now accepted as the identity swizzle instead of being refused, matching LLVM's printing and the ISA's default; a non-zero offset and the other forms are unchanged. The new two-case test covers the printed and omitted forms and the still-refused malformed one. No blocking issue.

@dcastell1

Copy link
Copy Markdown
Contributor

Code read + CPU tests, 9f6cdc1: pass for this change, with the caveat that the suite as a whole is not green on main right now.

So: nothing new from #5101; once #3995 lands, a clean branch should show only the toolchain-dependent one.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 9f6cdc1 on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_ds_swizzle_offset0.py" -> Ran 2 tests, OK
  • Negative control (tools/rdna2spirv.py swapped to upstream/main): FAILED (errors=1)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

7 participants