From bda17759e412a1154f330e12a633a51c79380bbf Mon Sep 17 00:00:00 2001 From: SweatierKey <53280918+SweatierKey@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:26:36 +0100 Subject: [PATCH] rdna2spirv: VCCTuple scalar lists, src_scc, and image_atomic a16 (FSPX) --- docs/design.md | 4 +- tests/semantic/test_fspx_rules.py | 229 ++++++++++++++++++++++++++++++ tools/lane_masks.py | 2 + tools/rdna2spirv.py | 122 ++++++++++++---- tools/shader_ir.py | 5 + tools/shader_meta.py | 2 + 6 files changed, 331 insertions(+), 33 deletions(-) create mode 100644 tests/semantic/test_fspx_rules.py diff --git a/docs/design.md b/docs/design.md index 3f0dfbe8ec..dc06157f62 100644 --- a/docs/design.md +++ b/docs/design.md @@ -228,9 +228,9 @@ How the generated SPIR-V expects the runtime to work: | Global atomics (`global_atomic_*`, 32-bit) | `add`, `sub`, `smin/umin`, `smax/umax`, `and`, `or`, `xor`, `swap` and `cmpswap` at the `global_load/store` address (same `Gen.global_address`: saddr pair plus zero-extended vaddr, or a 64-bit vaddr with `off`, plus the signed 12-bit offset), as one `OpAtomic*` on the PhysicalStorageBuffer dword, device scope, guarded so inactive lanes don't touch memory. With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. Still `Unsupported`: the `_x2` 64-bit forms, `inc`/`dec`, the float atomics, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten ops on a value grid with and without `glc`, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis). **Not GPU-verified.** | | 8/16-bit global stores and d16 loads | `global_store_byte`/`short` write the low 8/16 bits of the data VGPR (the `_d16_hi` forms its high half). `global_load_{u,s}byte_d16` and `global_load_short_d16` write the low 16 bits of `vdst` (the `_hi` forms the high 16) and keep the other half; `ubyte` zero-extends and `sbyte` sign-extends the byte to 16 bits. The address is the `global_load/store` one (`Gen.global_address`). The access goes one byte at a time, so a 16-bit access that crosses a dword (at byte 3) is exact too. A store merges each byte into its dword with atomic and/or, which keeps neighbouring bytes even when another lane writes them, as buffer byte stores do. A load reads each byte. Inactive lanes neither store nor load. The first-read analysis counts a d16 load's `vdst` as read, for the half it keeps. `global_load/store_dword_addtid` (lane-id and M0 addressing) raise `Unsupported`; until 2026-11-22 they crashed with `IndexError`, and the ten sub-dword ops raised `Unsupported`. CPU-checked by `tests/semantic/test_global_sub_dword.py` (every byte offset 0 to 7 for each op, an inactive lane, rejected forms, the first-read analysis). **Not GPU-verified.** | | Literal samplers | Some shaders build their S# from immediates (for example `0x92, 0xC00000, 0x14500000, 0`). The runtime registers those in the descriptor hash table too, by scanning the translated shaders' constant S# values, not only S#s the game binds. | -| Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). The base comes from the 64-bit SGPR pointer or the V# (dword0 \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). Not measured: `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0, so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. | +| Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). LLVM `VCCTuple` scalar register lists ending in `vcc_lo,vcc_hi` (e.g. `[s100,s101,s102,s103,s104,s105,vcc_lo,vcc_hi]`, `[s92,...,s105,vcc_lo,vcc_hi]`, seen in 6 FidelityFX FSPX shaders) are parsed as `slist` operands in `tools/shader_ir.py`, clear `vcc` from the lane-mask state in `tools/lane_masks.py`, and route `sN` slots to `%sgpr` and `vcc_lo`/`vcc_hi` to `%vcc`/`%vcc_hi` across SMEM loads, T#/S#/V# descriptor reads, and `global_*` `saddr`. `src_scc` reads `%scc` (0 or 1, RDNA2 inline constant 253), matching `scc`. `image_atomic_*` and `image_atomic_cmpswap` accept `a16` packed 16-bit unsigned coordinates (low half first, matching `image_store`). CPU-checked by `tests/semantic/test_fspx_rules.py` and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** The base comes from the 64-bit SGPR pointer or the V# (dword0 \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). Not measured: `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0, so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. | | 2D array resource dimensions | For `image_get_resinfo` on a 2D array, X/Y are the width/height at the requested mip, Z is the view layer count and W is its mip count. The query reads the sampled array at binding 3. A native gfx1036 kernel returned (19,11,5,3), (9,5,5,3) and (4,2,5,3) for the three mips of a synthetic array. On RTX 5080 and Radeon Graphics the translated query matched those tuples and returned (4,2,3,2) at relative mip 1 with a view starting at mip 1 and covering three layers. The registered `ps_array_resinfo` draw checks all 4096 pixels against (8,8,12,1). | -| Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). The base comes from the 64-bit SGPR pointer or the V# (dword0 \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). Not measured: `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0, so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. | +| Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). LLVM `VCCTuple` scalar register lists ending in `vcc_lo,vcc_hi` (e.g. `[s100,s101,s102,s103,s104,s105,vcc_lo,vcc_hi]`, `[s92,...,s105,vcc_lo,vcc_hi]`, seen in 6 FidelityFX FSPX shaders) are parsed as `slist` operands in `tools/shader_ir.py`, clear `vcc` from the lane-mask state in `tools/lane_masks.py`, and route `sN` slots to `%sgpr` and `vcc_lo`/`vcc_hi` to `%vcc`/`%vcc_hi` across SMEM loads, T#/S#/V# descriptor reads, and `global_*` `saddr`. `src_scc` reads `%scc` (0 or 1, RDNA2 inline constant 253), matching `scc`. `image_atomic_*` and `image_atomic_cmpswap` accept `a16` packed 16-bit unsigned coordinates (low half first, matching `image_store`). CPU-checked by `tests/semantic/test_fspx_rules.py` and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** The base comes from the 64-bit SGPR pointer or the V# (dword0 \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). Not measured: `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0, so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. | | Images and samplers | `image_sample_l` on 2D arrays used to read its LOD from the array layer; it now reads the LOD after all coordinates. `image_get_lod` and `image_gather4_lz` also work on 2D arrays. With `d16` every sample result is f16, packed two to a VGPR from the low half (the packed D16 of GFX10, as LLVM returns D16 image data); `image_sample_c_lz`/`_c_lz_o` follow it too, and until 2026-11-21 their compare result was written as f32 bits, which read as 0 in the low half. Checked by `tests/test_translate.py` (`test_depth_compare_sample_result_width`) and GPU-checked with `runtime/test/shaders/ps_sample_c_lz.asm` (`vk_texture_test dref`: a D32 texture and a LESS_OR_EQUAL compare sampler) on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06): 4096/4096 pixels exact for f32 and `d16`; with the old translator the `d16` result read 0 in the 2048 pixels whose compare passes. | | Typed buffer loads | The format is V# word3[18:12] (GFX10_FORMAT, from Mesa's `gfx10-rsrc.json`, saved as `tools\gfx10_formats.json`). Supported: f32 ×1–4, u32 ×1–4, i32 ×1–4 (formats 21/63/73/76), f16 ×1/2/4, unorm8 ×1/2/4, snorm8 ×1/2/4, uint8 ×4, unorm16 ×1/2/4, snorm16 ×1/2/4, 10-10-10-2 and 2-10-10-10 unorm. Others give 0. Full-width SINT accesses preserve integer bits. D16 SINT loads saturate to signed 16-bit and D16 stores sign-extend, covered by the synthetic `cs_fmt_sint32.asm` readback. DST_SEL swizzle is applied (0→0, 1→1.0f for float/norm or integer 1 for UINT/SINT, 4..7→X..W). Missing channels repeat the format's own (component *c* = *c* mod *n*), measured on an RX 6700 (SHADER-86). UNORM/SNORM give the correctly rounded quotient by (2ⁿ−1), as the hardware does (0 mismatches vs hardware over 395,776 conversions on that GPU). It is built with integer ops (`Gen.norm_bits`): x/(2ⁿ−1) in binary is x's bits repeated, so a 64-bit multiply by the repeat pattern, `FindUMsb` and the round bit give the f32 exactly (the tail never ends, so there are no ties). `OpFDiv` is not enough on the GPU: Vulkan allows it 2.5 ULP, and on an RX 6700 (AMD Windows 26.11.2) and an RTX 5090 it returned the reciprocal-multiply bits (8_UNORM 130/256 exact, #599). Checked against exact values in `tests/semantic/test_norm_decode.py` (every value up to 8 bits, edges and the reciprocal-multiply misses for 10, 15 and 16 bits). 8_SNORM (2), 16_SNORM (8) and 8_8_SNORM (15) were missing until 2026-11-22 and decoded to 0. Format names list the channel widths from the top bit, so `2_10_10_10` (50) is R10G10B10A2 and `10_10_10_2` (44) has a 2-bit x (Mesa `gfx10_format_table.py`, `ac_formats.c`). Until 2026-11-22 the two were swapped, in stores too. Until 2026-11-21 an element that started mid-dword re-read dword 0 for its tail (`need` was `ceil(size/4)` and only the first dword was shifted); loads now take `need = ceil((byte_shift + size) / 4)` dwords and shift the whole window so the packed stream starts at the element (FUZZ-5, leftover from #234). The 10:10:10:2 order is checked by `cs_fmt_1010102` in `tests/semantic/test_value_semantics.py` (the shader decodes the format, so a GPU run can't check it). Mid-dword spanning elements are checked by `tests/semantic/test_buffer_load_format.py` (`CrossingDwordBoundary`); repeat / UNORM / DST_SEL 1 by the SHADER-86 cases in the same file. | | Images and samplers (core) | Bindless. Set 0: binding 0 = 2D sampled images, 1 = samplers, 2 = descriptor hash table (storage buffer), 3 = 2D-array images (**cube textures are bound here as 6-layer 2D-array views**, cube arrays as 6N layers: the shader already selected the face with `v_cube*`), 4 = r32ui storage images, 5 = 1D, 6 = 3D. A cube sample's s and t come in [1, 2] and its third coordinate is 8·slice + face, as the hardware takes them (Mesa `ac_nir_lower_tex_coords.c`, LLPC `ImageBuilder.cpp`); the view is read at (s − 1, t − 1), layer 6·slice + face. GPU-checked with `runtime/test/shaders/ps_cube_sample.asm` (`vk_texture_test cube`). For a native Metal path, `tools/spirv_metal_set0.py` sizes set 0's runtime arrays from `vulkan_bindless.h` and moves each binding to its own argument-buffer ID range (binding b starts at the capacities of bindings 0..b-1 added up), to convert with SPIRV-Cross `--msl-decoration-binding`: SPIRV-Cross 1.4.363.0 otherwise puts every runtime array at one ID and comments all but one out as "Overlapping binding" (SHADER-161). `cs_imgstore` converted this way writes all 3×64 texels correctly in a native Metal dispatch on an Apple A18 Pro. | diff --git a/tests/semantic/test_fspx_rules.py b/tests/semantic/test_fspx_rules.py new file mode 100644 index 0000000000..a0a3555982 --- /dev/null +++ b/tests/semantic/test_fspx_rules.py @@ -0,0 +1,229 @@ +"""Semantic tests for FSPX / FidelityFX translator rules (#1754 follow-ups, docs/fspx.md): + +1. LLVM VCCTuple scalar register lists ending in vcc_lo,vcc_hi (`[s100,...,s105,vcc_lo,vcc_hi]` and + `[s92,...,s105,vcc_lo,vcc_hi]`) parsed in tools/shader_ir.py, clearing `vcc` in tools/lane_masks.py, + and handled in s_buffer_load_dwordx*/s_load_dword*, buffer/global addressing, and T#/S# lookups. +2. `src_scc` special source operand (RDNA2 encoding 253 = SCC, 0 or 1) in scalar and vector ALU ops. +3. `image_atomic_*` / `image_atomic_cmpswap` with `a16` packed 16-bit unsigned coordinates (2D and 3D). + +Standard library only; no GPU, no LLVM, no game files. +""" +from __future__ import annotations + +import os +import struct +import sys +import tempfile +import unittest +import warnings + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +sys.dont_write_bytecode = True +sys.path.insert(0, os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools")) +sys.path.insert(0, HERE) + +import lane_masks # noqa: E402 +import rdna2spirv # noqa: E402 +import shader_ir # noqa: E402 +import shader_meta # noqa: E402 +import spirv_mini_interp as si # noqa: E402 + +STUB_DXBC = b"DXBC" + bytes(24) + struct.pack(" SCC = 0 + "v_add_nc_u32_e32 v3, src_scc, v1", # 20 + "v_mov_b32_e32 v4, s6", + "v_mov_b32_e32 v5, s7", + f"v_mov_b32_e32 v8, {OUT:#x}", + "global_store_dwordx4 v8, v[2:5], s[0:1]", + ] + res = run_cs(body, {}) + self.assertEqual([res.get(OUT + 4 * i) for i in range(4)], [21, 20, 1, 11]) + + +class ImageAtomicA16Tests(unittest.TestCase): + def test_image_atomic_add_2d_and_3d_a16_translate(self): + # 2D a16: one VGPR packs (x: u16 low, y: u16 high); 3D a16: two VGPRs pack (x, y) and (z, _). + spv_2d = translate([ + "v_mov_b32_e32 v1, 0x00050003", # x=3, y=5 + "v_mov_b32_e32 v2, 1", + "image_atomic_add v2, v1, s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm a16 glc", + "s_waitcnt vmcnt(0)", + f"v_mov_b32_e32 v6, {OUT:#x}", + "global_store_dword v6, v2, s[0:1]", + ]) + self.assertIn("OpImageTexelPointer", spv_2d) + self.assertIn("OpAtomicIAdd", spv_2d) + self.assertIn("OpShiftRightLogical %uint", spv_2d) + + spv_3d = translate([ + "v_mov_b32_e32 v1, 0x00050003", # x=3, y=5 + "v_mov_b32_e32 v2, 0x00000007", # z=7 + "v_mov_b32_e32 v3, 1", + "image_atomic_add v3, v[1:2], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_3D unorm a16", + "s_waitcnt vmcnt(0)", + ]) + self.assertIn("OpCompositeConstruct %v3int", spv_3d) + self.assertIn("OpAtomicIAdd", spv_3d) + + def test_image_atomic_2d_too_few_coords_rejected(self): + with self.assertRaises(rdna2spirv.Unsupported): + translate([ + "v_mov_b32_e32 v1, 0", "v_mov_b32_e32 v2, 1", + "image_atomic_add v2, v1, s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm", + ]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/lane_masks.py b/tools/lane_masks.py index 80292528c4..c0cafe728d 100644 --- a/tools/lane_masks.py +++ b/tools/lane_masks.py @@ -87,6 +87,8 @@ def put(state, a, k): state[a["r"] + 1] = MASK_HI return regs = [a["r"] + i for i in range(n)] + elif a["k"] == "slist": + regs = [r if isinstance(r, int) else "vcc" for r in a["r"]] elif a["k"] == "special" and a.get("t") in ("vcc", "vcc_lo"): regs = ["vcc"] elif a["k"] == "special" and a.get("t") == "vcc_hi": diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py index 6806a4b1be..aad2db08cf 100644 --- a/tools/rdna2spirv.py +++ b/tools/rdna2spirv.py @@ -313,7 +313,7 @@ def src_u(self, a): # wave32 (or plain data): vcc_hi is an ordinary SGPR. v = self.tmp() self.emit(f"{v} = OpLoad %uint {'%vcc' if (self.wave64 and 'vcc' in self.cur_masks) else '%vcc_hi'}") - elif k == "special" and a["t"] == "scc": + elif k == "special" and a["t"] in ("scc", "src_scc"): v = self.tmp() self.emit(f"{v} = OpLoad %uint %scc") elif k == "special" and a["t"] == "src_pops_exiting_wave_id": @@ -1842,8 +1842,8 @@ def global_address(self, op, vaddr, saddr, mods): inst -= 0x1000 # the raw 12-bit field from a tool that prints it unsigned: same offset if not -0x800 <= inst <= 0x7FF: raise Unsupported(f"{op} offset:{inst}") # not a 12-bit value: don't guess an address - if saddr["k"] == "sgpr" and saddr.get("n") == 2: - lo, hi = self.load_reg("sgpr", saddr["r"]), self.load_reg("sgpr", saddr["r"] + 1) + if (saddr["k"] == "sgpr" and saddr.get("n") == 2) or (saddr["k"] == "slist" and len(saddr["r"]) == 2): + lo, hi = self.sgpr_words(saddr, 2) voff = self.load_reg("vgpr", vaddr["r"]) l64, h64, sh, base, v64, va = (self.tmp() for _ in range(6)) self.emit(f"{l64} = OpUConvert %ulong {lo}") @@ -2061,10 +2061,14 @@ def buffer_address(self, a, mods, parts=False, elem=None, fixed_fmt=None): when swizzled, selected at run time for a run-time word1), for buf_dword_ptr.""" vaddr, rsrc = a[1], a[2] soff = a[3] if len(a) > 3 else {"k": "imm", "v": 0} - if rsrc["k"] != "sgpr" or rsrc.get("n") != 4: + if (rsrc["k"] == "sgpr" and rsrc.get("n") == 4): + lit3, lit1 = self.sgpr_imm.get(rsrc["r"] + 3), self.sgpr_imm.get(rsrc["r"] + 1) + elif rsrc["k"] == "slist" and len(rsrc["r"]) == 4: + lit3 = self.sgpr_imm.get(rsrc["r"][3]) if isinstance(rsrc["r"][3], int) else None + lit1 = self.sgpr_imm.get(rsrc["r"][1]) if isinstance(rsrc["r"][1], int) else None + else: raise Unsupported("buffer V#") - lit3, lit1 = self.sgpr_imm.get(rsrc["r"] + 3), self.sgpr_imm.get(rsrc["r"] + 1) - d0, d1, d2, d3 = (self.load_reg("sgpr", rsrc["r"] + i) for i in (0, 1, 2, 3)) + d0, d1, d2, d3 = self.sgpr_words(rsrc, 4) hi, stride = self.tmp(), self.tmp() self.emit(f"{hi} = OpBitwiseAnd %uint {d1} {self.cu(0xFFFF)}") self.emit(f"{stride} = OpBitFieldUExtract %uint {d1} {self.cu(16)} {self.cu(14)}") @@ -6900,23 +6904,42 @@ def scalar_load(self, op, a, mods): x8), an s_buffer_load immediate with bit 20 set or a negative one (kept as the 32-bit value, as before).""" n = 1 if op.endswith("dword") else int(op.rsplit("x", 1)[1]) d, base = a[0], a[1] - # A single dword may also land in vcc_lo / m0 / vcc_hi (seen: s_buffer_load_dword vcc_lo, ...). + # A single dword may also land in vcc_lo / m0 / vcc_hi (seen: s_buffer_load_dword vcc_lo, ...), and a wide + # load may target an LLVM VCCTuple list ending in vcc_lo,vcc_hi (seen in 6 FSPX shaders: s[100..105]+vcc). single_special = (n == 1 and d["k"] == "special" and d["t"] in ("vcc_lo", "vcc", "m0", "vcc_hi")) or \ (n == 2 and d["k"] == "special" and d["t"] == "vcc") - if (d["k"] != "sgpr" and not single_special) or base["k"] != "sgpr": + slist_dst = d["k"] == "slist" and len(d["r"]) == n + base_slots = (list(range(base["r"], base["r"] + base.get("n", 1))) if base["k"] == "sgpr" + else list(base["r"]) if base["k"] == "slist" else None) + if (d["k"] != "sgpr" and not single_special and not slist_dst) or base_slots is None: raise Unsupported(f"{op} operands {d.get('t', d['k'])} {base.get('t', base['k'])}") + + def load_slot(slot): + if isinstance(slot, int): + return self.load_reg("sgpr", slot) + t = self.tmp() + self.emit(f"{t} = OpLoad %uint {'%vcc' if slot == 'vcc_lo' else '%vcc_hi'}") + return t + + def store_slot(slot, val): + if isinstance(slot, int): + self.store_reg("sgpr", slot, val) + else: + self.emit(f"OpStore {'%vcc' if slot == 'vcc_lo' else '%vcc_hi'} {val}") + sbuf = op.startswith("s_buffer") - lo, hi = self.load_reg("sgpr", base["r"]), self.load_reg("sgpr", base["r"] + 1) - word1 = hi if sbuf: - if base.get("n") != 4: + if len(base_slots) != 4: raise Unsupported("s_buffer_load without V#") + else: + if len(base_slots) != 2: + raise Unsupported("s_load without 64-bit pointer") + lo, hi = load_slot(base_slots[0]), load_slot(base_slots[1]) + word1 = hi + if sbuf: m = self.tmp() self.emit(f"{m} = OpBitwiseAnd %uint {hi} {self.cu(0xFFFF)}") hi = m - else: - if base.get("n") != 2: - raise Unsupported("s_load without 64-bit pointer") off = a[2] if len(a) > 2 else {"k": "imm", "v": 0} inst = [m.split(":", 1)[1] for m in mods if m.startswith("offset:")] if len(a) > 3 or len(inst) > 1 or (inst and off["k"] == "imm"): @@ -6967,15 +6990,15 @@ def scalar_load(self, op, a, mods): lim_val = None if sbuf: # limit = NUM_RECORDS * stride, or NUM_RECORDS when stride is 0 (bytes, 64-bit so the product can't wrap) - lit1 = self.sgpr_imm.get(base["r"] + 1) - lit2 = self.sgpr_imm.get(base["r"] + 2) + lit1 = self.sgpr_imm.get(base_slots[1]) if isinstance(base_slots[1], int) else None + lit2 = self.sgpr_imm.get(base_slots[2]) if isinstance(base_slots[2], int) else None if lit1 is not None and lit2 is not None: stride = (lit1 >> 16) & 0x3FFF lim_val = lit2 if stride == 0 else lit2 * stride lim = self.cl(lim_val) else: stride, nr64, st64, prod, raw, lim = (self.tmp() for _ in range(6)) - nr = self.load_reg("sgpr", base["r"] + 2) + nr = load_slot(base_slots[2]) self.emit(f"{stride} = OpBitFieldUExtract %uint {word1} {self.cu(16)} {self.cu(14)}") self.emit(f"{nr64} = OpUConvert %ulong {nr}") self.emit(f"{st64} = OpUConvert %ulong {stride}") @@ -7017,6 +7040,8 @@ def scalar_load(self, op, a, mods): self.emit(f"OpStore {'%vcc' if i == 0 else '%vcc_hi'} {v}") else: self.dst(d, v) + elif slist_dst: + store_slot(d["r"][i], v) else: self.store_reg("sgpr", d["r"] + i, v) @@ -7240,6 +7265,11 @@ def desc_lookup_sgpr(self, a, n): ones, which are two calls, s_load results, v_readlane/v_readfirstlane results and the spare slots lane masks are parked in) and cleared when a basic block starts. Only lookups made at the block's top level are remembered, see desc_cache_ok. Returns the bindless index (a uint id).""" + if a["k"] == "slist" and len(a["r"]) >= n: + words = self.sgpr_words(a, n) + if n < 8: + words = words + [self.cu(0xFFFFFFFF)] * (8 - n) + return self.desc_lookup(words) if a["k"] != "sgpr" or a.get("n", 1) < n: raise Unsupported("descriptor operand") key = (a["r"], n) @@ -7255,10 +7285,24 @@ def desc_lookup_sgpr(self, a, n): self.desc_cache[key] = idx return idx + def sgpr_word(self, a, i): + if a["k"] == "sgpr": + return self.load_reg("sgpr", a["r"] + i) + if a["k"] == "slist": + slot = a["r"][i] + if isinstance(slot, int): + return self.load_reg("sgpr", slot) + t = self.tmp() + self.emit(f"{t} = OpLoad %uint {'%vcc' if slot == 'vcc_lo' else '%vcc_hi'}") + return t + raise Unsupported("descriptor operand") + def sgpr_words(self, a, n): - if a["k"] != "sgpr" or a.get("n", 1) < n: - raise Unsupported("descriptor operand") - return [self.load_reg("sgpr", a["r"] + i) for i in range(n)] + if a["k"] == "sgpr" and a.get("n", 1) >= n: + return [self.load_reg("sgpr", a["r"] + i) for i in range(n)] + if a["k"] == "slist" and len(a["r"]) >= n: + return [self.sgpr_word(a, i) for i in range(n)] + raise Unsupported("descriptor operand") def addr_regs(self, a): """Image address operand: contiguous v[x:y] or an NSA list.""" @@ -7356,7 +7400,7 @@ def image_op(self, op, a, mods): iv = self.tmp() self.emit(f"{iv} = OpCompositeConstruct {'%v2int' if ncoord == 2 else '%v3int'} {' '.join(ints)}") if dim in self.STORE_DIMS: - self.image_load_typed(dim, self.load_reg("sgpr", a[2]["r"] + 1), iv, img, img_idx, + self.image_load_typed(dim, self.sgpr_word(a[2], 1), iv, img, img_idx, dmask, vdata, self.cu(0), d16) return res = self.tmp() @@ -7462,7 +7506,7 @@ def gather_mip(image: str, cls: int, ty: str) -> str: self.emit(f"{result} = OpCompositeConstruct {ty} {' '.join(taps)}") return result - self.image_read_typed(dim, self.load_reg("sgpr", a[2]["r"] + 1), img, img_idx, + self.image_read_typed(dim, self.sgpr_word(a[2], 1), img, img_idx, 0xf, vdata, d16, gather_mip) self.uses_fhalf = True return @@ -7489,7 +7533,7 @@ def gather(image, cls, ty): if dim == "dim:SQ_RSRC_IMG_2D": self.uses_int_sampler = True # dmask selects one texture channel; all four taps are written. - self.image_read_typed(dim, self.load_reg("sgpr", a[2]["r"] + 1), img, img_idx, + self.image_read_typed(dim, self.sgpr_word(a[2], 1), img, img_idx, 0xf, vdata, d16, gather) return res = gather(img, 0, "%v4float") @@ -7583,7 +7627,7 @@ def sample(image, cls, ty): return result self.uses_int_sampler = True - self.image_read_typed(dim, self.load_reg("sgpr", a[2]["r"] + 1), img, img_idx, + self.image_read_typed(dim, self.sgpr_word(a[2], 1), img, img_idx, dmask, vdata, d16, sample) return res = self.tmp() @@ -7816,7 +7860,7 @@ def image_store(self, a, mods, dim): vals = [self.load_reg("vgpr", next(regs)) if dmask >> c & 1 else self.cu(0) for c in range(4)] coords = [self.as_int(c) for c in raw[:nc]] idx = self.desc_lookup_sgpr(a[2], 8) - t1 = self.load_reg("sgpr", a[2]["r"] + 1) + t1 = self.sgpr_word(a[2], 1) self.uses_store_views.add(di) for w in [16] + sum(self.int_format_masks(), []): # constants used by assemble's format masks self.cu(w) @@ -7894,17 +7938,33 @@ def image_misc(self, op, a, mods): self.dst({"k": "vgpr", "r": vdata["r"] + out, "n": 1}, self.tou(comp)) out += 1 return - if ((dim != "dim:SQ_RSRC_IMG_2D" and not (is3d_atomic or array_query)) or "a16" in mods + is_atomic = op in self.IMG_ATOMICS or op == "image_atomic_cmpswap" + if ((dim != "dim:SQ_RSRC_IMG_2D" and not (is3d_atomic or array_query)) + or ("a16" in mods and not is_atomic) or ("d16" in mods and op != "image_load_mip")): raise Unsupported(op + " " + dim.split("SQ_RSRC_IMG_")[-1]) vdata, addr = a[0], self.addr_regs(a[1]) idx = self.desc_lookup_sgpr(a[2], 8) + + def atomic_coords(nc): + raw = [self.load_reg("vgpr", r) for r in addr] + if "a16" in mods: + # 16-bit packed unsigned coordinates: two per VGPR, low half first (same as image_store). + halves = [] + for c in raw: + lo, hi = self.tmp(), self.tmp() + self.emit(f"{lo} = OpBitwiseAnd %uint {c} {self.cu(0xFFFF)}") + self.emit(f"{hi} = OpShiftRightLogical %uint {c} {self.cu(16)}") + halves += [lo, hi] + raw = halves + if len(raw) < nc: + raise Unsupported(op + " coords") + return [self.as_int(c) for c in raw[:nc]] + if is3d_atomic: # 3D r32ui storage image atomics (binding 7). self.uses_storage3d = True - coords = [self.as_int(self.load_reg("vgpr", r)) for r in addr[:3]] - if len(coords) < 3: - raise Unsupported(op + " coords") + coords = atomic_coords(3) iv, ip, tp, old, safe = (self.tmp() for _ in range(5)) self.emit(f"{iv} = OpCompositeConstruct %v3int {coords[0]} {coords[1]} {coords[2]}") self.emit(f"{ip} = OpAccessChain %_ptr_UC_simg3 %simages3d {idx}") @@ -7936,7 +7996,7 @@ def image_misc(self, op, a, mods): if op in self.IMG_ATOMICS or op == "image_atomic_cmpswap": # Storage image (2D r32ui). Atomics: vdata holds the operand; with 'glc' the pre-op value comes back. self.uses_storage = True - coords = [self.as_int(self.load_reg("vgpr", r)) for r in addr[:2]] + coords = atomic_coords(2) iv = self.tmp() self.emit(f"{iv} = OpCompositeConstruct %v2int {coords[0]} {coords[1]}") ip = self.tmp() @@ -8020,7 +8080,7 @@ def image_misc(self, op, a, mods): xs = [self.as_int(self.load_reg("vgpr", r)) for r in addr[:3]] iv = self.tmp() self.emit(f"{iv} = OpCompositeConstruct %v2int {xs[0]} {xs[1]}") - self.image_load_typed(dim, self.load_reg("sgpr", a[2]["r"] + 1), iv, img, idx, dmask, vdata, xs[2], d16="d16" in mods) + self.image_load_typed(dim, self.sgpr_word(a[2], 1), iv, img, idx, dmask, vdata, xs[2], d16="d16" in mods) def interp_pair_src(self, op, a, ins): diff --git a/tools/shader_ir.py b/tools/shader_ir.py index ba294f7f89..1ad2a00c9d 100644 --- a/tools/shader_ir.py +++ b/tools/shader_ir.py @@ -29,6 +29,7 @@ _REG_RANGE = re.compile(r"([sv])\[(\d+):(\d+)\]") _TTMP = re.compile(r"ttmp(\d+)|ttmp\[(\d+):(\d+)\]") _VLIST = re.compile(r"\[(v\d+(?:,\s*v\d+)+)\]") +_SLIST = re.compile(r"\[((?:s\d+|vcc_lo|vcc_hi)(?:\s*,\s*(?:s\d+|vcc_lo|vcc_hi))+)\]") _ATTR = re.compile(r"attr(\d+)\.([xyzw])") _TARGET = re.compile(r"(pos|param|mrt|mrtz|null|prim)(\d*)") _INT = re.compile(r"-?(0x[0-9a-fA-F]+|\d+)") @@ -99,6 +100,10 @@ def operand(tok): m = _VLIST.fullmatch(core) if m: # NSA image address: non-contiguous VGPR list return {"k": "vlist", "r": [int(x.strip()[1:]) for x in m.group(1).split(",")]} + m = _SLIST.fullmatch(core) + if m: # LLVM VCCTuple scalar register list, e.g. [s100,s101,s102,s103,s104,s105,vcc_lo,vcc_hi] + items = [int(x[1:]) if x.startswith("s") else x for x in (t.strip() for t in m.group(1).split(","))] + return {"k": "slist", "r": items, "n": len(items)} m = _ATTR.fullmatch(core) if m: return {"k": "attr", "a": int(m.group(1)), "c": "xyzw".index(m.group(2))} diff --git a/tools/shader_meta.py b/tools/shader_meta.py index d0a11c7245..4b1a5f2c57 100644 --- a/tools/shader_meta.py +++ b/tools/shader_meta.py @@ -82,6 +82,8 @@ def _imm_u32(a): def _sgpr_regs(a): if a["k"] == "sgpr": return list(range(a["r"], a["r"] + a.get("n", 1))) + if a["k"] == "slist": + return [r for r in a["r"] if isinstance(r, int)] return []