Skip to content

Translator: ds_read_u8/i8_d16[_hi] 8-bit LDS reads into a 16-bit half (SHADER-85) - #592

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
esteban-dcp:translator-shader-85
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
esteban-dcp:translator-shader-85

Conversation

@esteban-dcp

Copy link
Copy Markdown

SHADER-85 (claimed in #374): the 8-bit LDS reads into one 16-bit half, which the translator rejected.

What

RDNA2 ISA, DS opcodes 162–165:

  • ds_read_u8_d16: D[15:0] = zero-extend(MEM[ADDR][7:0]), D[31:16] kept

  • ds_read_u8_d16_hi: D[31:16] = zero-extend(MEM[ADDR][7:0]), D[15:0] kept

  • ds_read_i8_d16: D[15:0] = sign-extend 8→16, D[31:16] kept

  • ds_read_i8_d16_hi: D[31:16] = sign-extend 8→16, D[15:0] kept

  • tools/rdna2spirv.py (lds_op): added to the existing ds_read_u16_d16[_hi] / u8 / i8 path, which already handles address + offset:, byte extraction, EXEC and keeping the other half. The 16-bit insert takes the low 16 bits of the 32-bit-extended byte, so i8 is sign-extended 8→16 as the ISA says.

  • tools/lds_fuzz.py: now generates the four reads (its model already had them); the "rejected" comment now lists only ds_permute_b32. Note: FUZZ-10 (@FreddyxS) touches that same comment line, so whichever lands second has a one-line rebase.

  • tests/semantic/test_lds_read_u8_d16.py (+ fixture via regen_fixtures.py): the 8 words below; fails with Unsupported: ds_read_u8_d16 without the translator change. spirv_mini_interp.py now accepts Workgroup variables like Function ones (meaningful with one invocation only; documented in its header).

  • runtime/test/shaders/cs_w32_lds_u8_d16.asm: wave32 dump. LDS dword 0 = 0x7F80FF01, every destination preset to 0xBEEF1234, reads at offset: 1, 2, 3 with a non-zero base. Expected 0xBEEF00FF 0x00FF1234 0xBEEFFF80 0xFF801234 0xBEEF007F 0x007F1234 0xBEEF0080 0xFFFF1234. Registered in check.py and run_gpu_tests.py.

  • docs/design.md (LDS row) and docs/shader_validation.md (FUZZ-6 "not covered" line).

Tested

Linux 7.3.5 (CachyOS), python -I scripts/run_gpu_tests.py --build runtime/build/linux, each GPU pinned with VK_LOADER_DRIVERS_SELECT (device line checked), VK_LOADER_LAYERS_DISABLE=~implicit~:

  • NVIDIA RTX 4050 Laptop (Ada), driver 620.73.04, subgroup 32: 46/72 passed, 26 wave64 skipped; with LEONIDA_W64_EMULATE=1: 72/72
  • AMD Radeon 740M (RDNA3, RADV, Mesa 26.3.1), subgroup 32..64: 72/72
  • cs_w32_lds_u8_d16: the 8 expected words on all three runs
  • lds_fuzz.py --wave 32 --no-exec bpermute --programs 60 --seed 1 on the RTX 4050: 60/60 match, with 42 uses of the new reads. (Without --no-exec bpermute the only mismatches are wave32 ds_bpermute under EXEC, the Translator: wave32 ds_bpermute_b32 reads 0 from inactive source lanes #253 issue — same as on main.)
  • CPU: unittest discover -s tests/semantic 710 OK; regen_fixtures.py --check clean; pytest over tests/ shows the same 3 failures as main on Linux (test_mem_diff s_load subtest, 2 in test_swizzle_search)

No game files used. AI-assisted (Claude Code).

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 22, 2026 01:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Code looks right. op.split('_')[2] gives u8/i8, so 8 bits, and the insert keeps the low 16 bits of the sign-extended value, which is the 8 to 16 extension the ISA describes. It conflicts with main now (check.py, run_gpu_tests.py, regen_fixtures.py). Happy to approve after the rebase. AI-assisted review (Claude Code).

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

As promised: it now merges cleanly with main, and tests/semantic passes (785 tests). The code was already right. LGTM.

TL;DR: conflict gone, tests pass, approved. AI-assisted review (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

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

The native wave32 fixture cs_w32_lds_u8_d16 translated, passed SPIR-V validation, and returned all eight expected words:

beef00ff 00ff1234 beefff80 ff801234 beef007f 007f1234 beef0080 ffff1234

This checks signed and unsigned byte extension into either half of the destination register, including preservation of the other half. I also ran lds_fuzz.py --wave 32 --no-exec bpermute --seed 2 --programs 48 against the same build. All 48 GPU results matched the model, with zero skips, translation failures, or harness errors. The run covered translated wave32 on NVIDIA and kept all lanes active for bpermute.

AI-assisted verification.

@0xTehuti

Copy link
Copy Markdown
Contributor

Hi @esteban-dcp! In PR #605 we wrote focused unit tests for Program.model() in tests/test_lds_fuzz.py covering the four 8-bit d16 read instructions. As @tylerstraub noted, our semantic assertions match your GPU fixture (cs_w32_lds_u8_d16.asm) and semantic tests 100%.

Since SHADER-85 was claimed by you and #592 is the canonical PR, I've closed #605. In case you'd like to include direct unit test coverage for the fuzzer's reference model in #592, here are the tests:

    def test_u8_d16_read_zero_extends_into_low_half(self):
        p = f.Program(1, 0, 64)
        p.ops = [{"kind": "read", "name": "ds_read_u8_d16", "addr": (0, 0, 0), "dst": 20, "exec": None}]
        before = f.Program(1, 0, 64)
        before.ops = []
        old = before.model()[0][0][20]
        regs, lds = p.model()
        self.assertEqual(regs[0][20], (old & 0xFFFF0000) | lds[0])

    def test_u8_d16_hi_read_zero_extends_into_high_half(self):
        p = f.Program(1, 0, 64)
        p.ops = [{"kind": "read", "name": "ds_read_u8_d16_hi", "addr": (0, 0, 0), "dst": 20, "exec": None}]
        before = f.Program(1, 0, 64)
        before.ops = []
        old = before.model()[0][0][20]
        regs, lds = p.model()
        self.assertEqual(regs[0][20], (old & 0xFFFF) | (lds[0] << 16))

    def test_i8_d16_read_sign_extends_into_low_half(self):
        p = f.Program(1, 0, 64)
        p.ops = [{"kind": "read", "name": "ds_read_i8_d16", "addr": (0, 0, 0), "dst": 20, "exec": None}]
        before = f.Program(1, 0, 64)
        before.ops = []
        old = before.model()[0][0][20]
        regs, lds = p.model()
        byte = lds[0]
        sext = byte - 256 if byte & 0x80 else byte
        self.assertEqual(regs[0][20], (old & 0xFFFF0000) | (sext & 0xFFFF))

    def test_i8_d16_hi_read_sign_extends_into_high_half(self):
        p = f.Program(1, 0, 64)
        p.ops = [{"kind": "read", "name": "ds_read_i8_d16_hi", "addr": (0, 0, 0), "dst": 20, "exec": None}]
        before = f.Program(1, 0, 64)
        before.ops = []
        old = before.model()[0][0][20]
        regs, lds = p.model()
        byte = lds[0]
        sext = byte - 256 if byte & 0x80 else byte
        self.assertEqual(regs[0][20], (old & 0xFFFF) | ((sext & 0xFFFF) << 16))

All 23 tests pass cleanly under pytest tests/test_lds_fuzz.py. Feel free to adapt or drop them as you prefer!

AI-assisted.

esteban-dcp pushed a commit to esteban-dcp/Leonida that referenced this pull request Nov 22, 2026
…NotRexed#605)

Four unit tests for lds_fuzz.Program.model() covering zero- and sign-extension
into the low and the high half, the other half kept. Written by 0xTehuti in
the closed PR ItsNotRexed#605 and added here because ItsNotRexed#592 is the canonical SHADER-85 PR
and it adds these reads to the fuzzer's READS table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@esteban-dcp

Copy link
Copy Markdown
Author

@0xTehuti thanks, and thanks @tylerstraub for the RTX 5090 run. I added your four Program.model() tests to tests/test_lds_fuzz.py (new commit on top of the approved head, tests only; the file runs 22 OK). The commit message and a comment above the first test credit #605. No translator or fuzzer code changed.

esteban-dcp pushed a commit to esteban-dcp/Leonida that referenced this pull request Nov 22, 2026
…NotRexed#605)

Four unit tests for lds_fuzz.Program.model() covering zero- and sign-extension
into the low and the high half, the other half kept. Written by 0xTehuti in
the closed PR ItsNotRexed#605 and added here because ItsNotRexed#592 is the canonical SHADER-85 PR
and it adds these reads to the fuzzer's READS table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@esteban-dcp

Copy link
Copy Markdown
Author

Rebased onto current main (b68663f; it had conflicts again after the merge round). Only the test registration conflicted (check.py, run_gpu_tests.py, regen_fixtures.py), kept both sides; 0xTehuti's tests are still the last commit. Re-tested: RTX 4050 (Ada) 60/86 + 26 wave64 skipped, 86/86 with LEONIDA_W64_EMULATE=1; Radeon 740M (RADV) 86/86; cs_w32_lds_u8_d16 = 0xbeef00ff 0x00ff1234 0xbeefff80 0xff801234 0xbeef007f 0x007f1234 0xbeef0080 0xffff1234 on all three; unittest discover -s tests/semantic 807 OK; tests/test_lds_fuzz.py OK; regen_fixtures.py --check clean.

@esteban-dcp

Copy link
Copy Markdown
Author

Rebased a third time (3e01d90): #628, #599, #489 and #394 merged and touched the same registration lists and the LDS row in design.md; kept both sides. In the LDS row I took main's text (which now describes ds_permute_b32 as supported) and replaced only the sentence about the 8-bit d16 reads. docs/shader_validation.md Not covered now says the fuzzer does not generate ds_permute_b32 yet (FUZZ-10) and does generate the 8-bit d16 reads. Re-tested: RTX 4050 (Ada) 65/92 + 27 wave64 skipped, 92/92 with LEONIDA_W64_EMULATE=1; Radeon 740M (RADV) 92/92; cs_w32_lds_u8_d16 passes on all three; unittest discover -s tests/semantic 900 OK; tests/test_lds_fuzz.py OK; regen_fixtures.py --check clean.

esteban-dcp pushed a commit to esteban-dcp/Leonida that referenced this pull request Nov 22, 2026
…NotRexed#605)

Four unit tests for lds_fuzz.Program.model() covering zero- and sign-extension
into the low and the high half, the other half kept. Written by 0xTehuti in
the closed PR ItsNotRexed#605 and added here because ItsNotRexed#592 is the canonical SHADER-85 PR
and it adds these reads to the fuzzer's READS table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
SirAmong and others added 2 commits November 21, 2026 22:02
… (SHADER-85)

ds_read_u8_d16, ds_read_u8_d16_hi, ds_read_i8_d16 and ds_read_i8_d16_hi
(RDNA2 DS opcodes 162-165) were rejected. They reuse the u8/i8/u16_d16
path: the byte is zero- or sign-extended 8->16 into one half of the
destination and the other half is kept.

Tests: CPU value test on the new cs_w32_lds_u8_d16 fixture (mini
interpreter now accepts Workgroup variables for one invocation), GPU
dump cs_w32_lds_u8_d16.asm registered in check.py and run_gpu_tests.py,
lds_fuzz generates the four reads. Contract row in docs/design.md and
shader_validation.md updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NotRexed#605)

Four unit tests for lds_fuzz.Program.model() covering zero- and sign-extension
into the low and the high half, the other half kept. Written by 0xTehuti in
the closed PR ItsNotRexed#605 and added here because ItsNotRexed#592 is the canonical SHADER-85 PR
and it adds these reads to the fuzzer's READS table.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@esteban-dcp

Copy link
Copy Markdown
Author

Rebased a fourth time (f8235ed): main moved again (the cs_barrier_divergent test, a new Workgroup barriers row, ps_sff_imm) and the PR conflicted in the same registration lists, the LDS row in design.md and the spirv_mini_interp.py docstring. Kept both sides; in the LDS row I took main's text and replaced only the 8-bit d16 sentence. Re-tested: RTX 4050 (Ada) 71/98 + 27 wave64 skipped, 98/98 with LEONIDA_W64_EMULATE=1; Radeon 740M (RADV) 98/98; cs_w32_lds_u8_d16 passes on all three; unittest discover -s tests/semantic 974 OK; regen_fixtures.py --check clean. Approved already by IAmNotSiob; this only keeps it mergeable.

@ItsNotRexed
ItsNotRexed merged commit dee21a0 into ItsNotRexed:main Nov 22, 2026
10 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
All four raised Unsupported. They access two 64-bit elements at
vaddr + offset0 * unit and vaddr + offset1 * unit, with unit = 8 bytes (x64
for st64), each element two consecutive dwords; read2 fills v[d:d+3] after
all loads, write2 takes two VGPR pairs. The b32 forms share the code with
unit 4, unchanged.

tests/semantic/test_lds_read2_write2_b64.py runs compute listings on the CPU
(one invocation, LDS as a Workgroup variable from #592) and checks every
dword against a plain-Python LDS model.
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
spirv_mini_interp ran 32-bit atomics on physical-storage-buffer pointers
only, so the LDS atomics the translator emits (ds_add/sub/min/max/and/or/xor,
ds_wrxchg_rtn_b32, ds_cmpst_rtn_b32) had no value test. With one invocation an
atomic is read-combine-write on any pointer, so it now also takes the
variable-element pointers OpLoad/OpStore use (Workgroup = LDS since #592,
Function); push constants stay read-only.

tests/semantic/test_lds_atomics_values.py runs compute listings as one
invocation and checks the returned and stored words against a plain-Python
model of each RDNA2 DS atomic.
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.

6 participants