From e88177e53a86ac26d26c94f3788afa1296e3ed55 Mon Sep 17 00:00:00 2001 From: Coderlord <162019045+Coderlord@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:05:17 +0300 Subject: [PATCH] rdna2spirv: restore the dot4 inline op_sel_hi under exact re-anchoring too (SHADER-FSPX-DOT4-EXACT) A listing whose undecodable words sit at offsets its llvm-mc messages name is re-anchored exactly (#984's invalid_at). That branch tried the v_fma_mix literal restores but not restore_dot4_inline_sel, which the search branch and check_printed_encodings both try, so a v_dot4_i32_i8 whose src1 is a replicated inline integer (llvm-mc prints op_sel_hi[1] set where the program's word has it clear) was marked normalized and the program refused as "reachable instruction with normalized encoding". llvm-mc 23.1.6 names every rejected word, so two of the 29 FSPX programs of the FidelityFX DLL took that branch and did not translate (27 of 29). The title then had no pipeline for one of them at the start of the story, and the DLL read through the missing object (an access violation at amd_fidelityfx_upscaler_xbox.dll+0x65ff, 50 s after the first-run setup, native Windows, RTX 5080). With the restore the FSPX step translates 29 of 29, all passing spirv-val. test_rdna2spirv_decode: a listing with one rejected word at a known offset after s_endpgm and a dot4 printed with the default op_sel_hi translates (it raised before). Co-Authored-By: Claude Opus 5.5 --- tests/test_rdna2spirv_decode.py | 44 +++++++++++++++++++++++++++++++++ tools/rdna2spirv.py | 6 ++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/test_rdna2spirv_decode.py b/tests/test_rdna2spirv_decode.py index dc1f0ed9e5..a692bdeaac 100644 --- a/tests/test_rdna2spirv_decode.py +++ b/tests/test_rdna2spirv_decode.py @@ -483,6 +483,50 @@ def test_native_blob_mismatched_encoding_reachable_normalized(self): with self.assertRaisesRegex(rdna2spirv.Unsupported, "reachable instruction with normalized encoding"): rdna2spirv.translate(src) + def test_exact_anchoring_restores_dot4_inline_sel(self): + # FSPX programs of the FidelityFX DLL: llvm-mc decodes a v_dot4_i32_i8 whose src1 is an inline integer and + # prints op_sel_hi[1] set where the program's word has it clear (restore_dot4_inline_sel). When the listing's + # undecodable words sit at offsets its llvm-mc messages name (llvm-mc 23 names each one, so the re-anchoring + # is exact), that restore has to apply as well: it did not, the instruction was "normalized" and the program + # refused (2 of the 29 FSPX programs with llvm-mc 23.1.6). + mov0 = [0xF2, 0x02, 0x00, 0x7E] # v_mov_b32_e32 v0, 1.0 + mov1 = [0xF2, 0x02, 0x02, 0x7E] # v_mov_b32_e32 v1, 1.0 + dot_raw = [0x00, 0x40, 0x16, 0xCC, 0x01, 0x15, 0x01, 0x0C] # op_sel_hi:[1,0,1] + dot_printed = [0x00, 0x40, 0x16, 0xCC, 0x01, 0x15, 0x01, 0x1C] # llvm-mc's default [1,1,1] + export = [0x0F, 0x18, 0x00, 0xF8, 0x00, 0x01, 0x00, 0x01] + endpgm = [0x00, 0x00, 0x81, 0xBF] + data = [0xFF, 0xFF, 0xFF, 0xFF] # a word llvm-mc rejected, after the end + + def enc(words): + return ",".join(f"0x{b:02x}" for b in words) + + with tempfile.TemporaryDirectory() as tmp: + disasm = os.path.join(tmp, "disasm") + fssm = os.path.join(tmp, "fssm") + os.makedirs(disasm) + os.makedirs(fssm) + with open(os.path.join(tmp, "ps_dot.dxbc"), "wb") as f: + f.write(STUB_DXBC) + with open(os.path.join(fssm, "ps_dot.fssm"), "wb") as f: + f.write(bytes(mov0 + mov1 + dot_raw + export + endpgm + data)) + shader_text = ( + "; ps_dot code 0x0..0x20 (fssm), gfx1030, 1 invalid words\n" + f"\tv_mov_b32_e32 v0, 1.0 ; encoding: [{enc(mov0)}]\n" + f"\tv_mov_b32_e32 v1, 1.0 ; encoding: [{enc(mov1)}]\n" + f"\tv_dot4_i32_i8 v0, v1, 10, v0 ; encoding: [{enc(dot_printed)}]\n" + f"\texp mrt0 v0, v1, v0, v1 done vm ; encoding: [{enc(export)}]\n" + f"\ts_endpgm ; encoding: [{enc(endpgm)}]\n" + "\n; --- llvm-mc messages ---\n" + "; :8:1: warning: invalid instruction encoding\n" + ) + src = os.path.join(disasm, "ps_dot.s") + with open(src, "w", encoding="utf-8") as f: + f.write(shader_text) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", ResourceWarning) + text = rdna2spirv.translate(src) + self.assertTrue(text) + def test_invalid_opcode_in_shader_listing(self): with tempfile.TemporaryDirectory() as tmp: disasm = os.path.join(tmp, "disasm") diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 95f11d961c..7af3705762 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -17874,7 +17874,11 @@ def translate(path): while pos in bad and not same_encoding(blob[pos:pos + len(enc)], enc, op, operand_count): pos += 4 window = blob[pos:pos + len(enc)] - if not same_encoding(window, enc, op, operand_count): + # The same restores as the search below and check_printed_encodings: a listing whose undecodable + # words sit at known offsets (llvm-mc 23 names each one) reaches this branch, and an FSPX program's + # v_dot4_i32_i8 with a replicated inline integer was refused here as "normalized" for want of it. + if not same_encoding(window, enc, op, operand_count) and \ + not restore_dot4_inline_sel(ins, window, enc): literal = mix_literal(window, enc, base_op(op)) if literal is not None: restore_mix_literal(ins, window, literal)