Repository navigation
Translator: ds_read_u8/i8_d16[_hi] 8-bit LDS reads into a 16-bit half (SHADER-85) - #592
Conversation
IAmNotSiob
left a comment
There was a problem hiding this comment.
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).
8caffe6 to
9f94534
Compare
IAmNotSiob
left a comment
There was a problem hiding this comment.
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).
|
Tested The native wave32 fixture
This checks signed and unsigned byte extension into either half of the destination register, including preservation of the other half. I also ran AI-assisted verification. |
|
Hi @esteban-dcp! In PR #605 we wrote focused unit tests for 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 AI-assisted. |
…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>
|
@0xTehuti thanks, and thanks @tylerstraub for the RTX 5090 run. I added your four |
…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>
|
Rebased onto current |
67c65bd to
b68663f
Compare
|
Rebased a third time (3e01d90): #628, #599, #489 and #394 merged and touched the same registration lists and the LDS row in |
…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>
b68663f to
3e01d90
Compare
… (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>
|
Rebased a fourth time (f8235ed): |
3e01d90 to
f8235ed
Compare
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.
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.
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] keptds_read_u8_d16_hi: D[31:16] = zero-extend(MEM[ADDR][7:0]), D[15:0] keptds_read_i8_d16: D[15:0] = sign-extend 8→16, D[31:16] keptds_read_i8_d16_hi: D[31:16] = sign-extend 8→16, D[15:0] kepttools/rdna2spirv.py(lds_op): added to the existingds_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 onlyds_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 viaregen_fixtures.py): the 8 words below; fails withUnsupported: ds_read_u8_d16without the translator change.spirv_mini_interp.pynow acceptsWorkgroupvariables likeFunctionones (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 to0xBEEF1234, reads atoffset:1, 2, 3 with a non-zero base. Expected0xBEEF00FF 0x00FF1234 0xBEEFFF80 0xFF801234 0xBEEF007F 0x007F1234 0xBEEF0080 0xFFFF1234. Registered incheck.pyandrun_gpu_tests.py.docs/design.md(LDS row) anddocs/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 withVK_LOADER_DRIVERS_SELECT(device line checked),VK_LOADER_LAYERS_DISABLE=~implicit~:LEONIDA_W64_EMULATE=1: 72/72cs_w32_lds_u8_d16: the 8 expected words on all three runslds_fuzz.py --wave 32 --no-exec bpermute --programs 60 --seed 1on the RTX 4050: 60/60 match, with 42 uses of the new reads. (Without--no-exec bpermutethe only mismatches are wave32ds_bpermuteunder EXEC, the Translator: wave32 ds_bpermute_b32 reads 0 from inactive source lanes #253 issue — same as onmain.)unittest discover -s tests/semantic710 OK;regen_fixtures.py --checkclean; pytest overtests/shows the same 3 failures asmainon Linux (test_mem_diffs_load subtest, 2 intest_swizzle_search)No game files used. AI-assisted (Claude Code).
🤖 Generated with Claude Code