upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-27 06:39:35 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-27 06:39:35 -0500
commitb0712ff2ce72796d0db2d833ec3d5d0a542e2142 (patch)
tree2553007a564e692af4aff036e43c98a1b4b31c06 /docs
parent23c33411962b84ecae28f4e82bd62fc6fba79444 (diff)
parent3c9820f8daae7e478cdca7f7e1d395e60d7c4ddf (diff)
Merge test/round2 into heaps-in-place: per-piece sums and the T# index word for heaps read in place
title_mirror.h: a filtered page's sums per 256-byte piece are of the title's bytes (title compared with title); the filter runs after that compare, only when a piece changed or the home is fresh, and writes the home. write_back skips a filtered home, so page_mirror_write_back takes TitleMirror::write_back as is. A home leaving its filter is copied whole once. The T# index word (tsharp_index_word) is written by finish_in_place into the home's dword 6 once the T# is bound; the filter leaves 0 (the fallback) there meanwhile, so the title's own dword 6 is never read as an index. Copy-path heaps keep fix_console_slot's write. d3d12_heap_in_place_test checks a T# slot reads the tag and index while the title's bytes keep their dword 6; title_mirror_hooks_test checks write-back skips filtered homes and the filter is not called again for unchanged title bytes. set_tsharp_index_words_for_test for the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/d3d12_vulkan.md18
-rw-r--r--docs/design.md1
2 files changed, 16 insertions, 3 deletions
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md
index cd325bded..bd7acdb11 100644
--- a/docs/d3d12_vulkan.md
+++ b/docs/d3d12_vulkan.md
@@ -2202,8 +2202,12 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all
2202 any reader names title memory) or in a buffer of ours as the title wrote it (`reachable_as_written`), other words 2202 any reader names title memory) or in a buffer of ours as the title wrote it (`reachable_as_written`), other words
2203 null. The filter runs inside the mirror's fills, under its lock, so it takes no other lock of ours: a V# the mirror 2203 null. The filter runs inside the mirror's fills, under its lock, so it takes no other lock of ours: a V# the mirror
2204 does not hold (an interim, until every title allocation is in the mirror) reads null until the heap's refresh 2204 does not hold (an interim, until every title allocation is in the mirror) reads null until the heap's refresh
2205 resolves it as a copied slot was, and a T# is bound there too (its bindless index in the entry comes later), each 2205 resolves it as a copied slot was, and a T# is bound there too, its home dword 6 then taking the bindless index word
2206 result written into the home unless the title rewrote the slot meanwhile (`finish_in_place`). Lock order: 2206 (`tsharp_index_word`, docs/design.md "Bindless index in the T#"; 0, the fallback, from the filter until then and
2207 while the T# waits; the title's dword 6 stays in its bytes), each result written into the home unless the title
2208 rewrote the slot meanwhile (`finish_in_place`). The upload's sums per 256-byte piece are of the title's bytes for
2209 such a page, so the mirror calls the filter only when a piece of the title's page changed, and `write_back` skips
2210 it. Lock order:
2207 `console_heap_mutex`, then the mirror's, then the change list's. The changes are applied to the homes at the 2211 `console_heap_mutex`, then the mirror's, then the change list's. The changes are applied to the homes at the
2208 mirror's refresh, before the pages written since are filled. No GPU write is ever copied back from these pages 2212 mirror's refresh, before the pages written since are filled. No GPU write is ever copied back from these pages
2209 (`TitleMirror::filtered_at`). A heap the mirror does not hold (a device without the mirror, memory outside its 2213 (`TitleMirror::filtered_at`). A heap the mirror does not hold (a device without the mirror, memory outside its
@@ -2235,7 +2239,9 @@ The layer's descriptor model:
2235 which is the assumption to verify. If it uses an opaque format, the layer must translate at bind time. 2239 which is the assumption to verify. If it uses an opaque format, the layer must translate at bind time.
2236- At execution, for each bound table (or the whole bound heap when direct indexing is enabled), the layer walks 2240- At execution, for each bound table (or the whole bound heap when direct indexing is enabled), the layer walks
2237 the declared descriptor range with the heap's stride, parses each T#/S#, and ensures a bindless entry exists: 2241 the declared descriptor range with the heap's stride, parses each T#/S#, and ensures a bindless entry exists:
2238 - image T# → `VkImageView` (format, view type, mip range, array layers) → bindless image index; 2242 - image T# → `VkImageView` (format, view type, mip range, array layers) → bindless image index, which the layer
2243 writes into dword 6 of the T# where shaders read it (the console heap copy's slot, or the layer's own heap), with
2244 the arrays it is bound in (`docs/design.md`, "Bindless index in the T#"); the hash table keeps the key as written;
2239 - sampler S# → `VkSampler` (filter, address modes, LOD, compare, anisotropy) → bindless sampler index; 2245 - sampler S# → `VkSampler` (filter, address modes, LOD, compare, anisotropy) → bindless sampler index;
2240 - buffer V# / CBV → no Vulkan view; the descriptor already contains a console VA the shader dereferences. 2246 - buffer V# / CBV → no Vulkan view; the descriptor already contains a console VA the shader dereferences.
2241- **Buffer UAVs.** `CreateUnorderedAccessView` on a buffer writes a V# in the first 16 bytes of the slot (the rest of 2247- **Buffer UAVs.** `CreateUnorderedAccessView` on a buffer writes a V# in the first 16 bytes of the slot (the rest of
@@ -4801,6 +4807,12 @@ store, load, mesh, geometry and BVH tests; this layer is the other half.
4801 4807
4802### 5.1 Descriptor hash table details 4808### 5.1 Descriptor hash table details
4803 4809
4810Since the T# index word (`docs/design.md`, "Bindless index in the T#") the table serves only what the word does not
4811reach: every S#, and the T#s a translated module cannot trace to a heap slot (1,062 of the 439,415 T# operands of
4812the 1.0.2.1 corpus, in 108 modules). A T# loaded from a heap the layer writes carries its index and kind in dword 6
4813and is never looked up. Every T# key is still inserted, as the title wrote it: a T# outside the heaps is found by
4814those words.
4815
4804The exact layout the shader reads (from `tools/rdna2spirv.py`, `desc_lookup`): 4816The exact layout the shader reads (from `tools/rdna2spirv.py`, `desc_lookup`):
4805 4817
4806``` 4818```
diff --git a/docs/design.md b/docs/design.md
index 7d7f80949..96f13981b 100644
--- a/docs/design.md
+++ b/docs/design.md
@@ -329,6 +329,7 @@ How the generated SPIR-V expects the runtime to work:
329| 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. | 329| 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. |
330| 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 ×1/2/4, sint8 ×1/2/4, unorm16 ×1/2/4, snorm16 ×1/2/4, uint16 ×1/2/4, sint16 ×1/2/4, 10-10-10-2 and 2-10-10-10 unorm, and, since 2026-11-22, the other GFX10 buffer codes 1–77 (every USCALED/SSCALED, 10_11_11 and 11_11_10 FLOAT, the 10_10_10_2 and 2_10_10_10 families, 8_8_8_8 and 16_16_16_16 SINT and SCALED; see *Typed buffer formats*). Others (code 0 and 78 up) give 0. The 8- and 16-bit UINT/SINT formats 5, 6, 11, 12, 18, 19, 28, 61 and 70 were missing until 2026-11-22 and read 0: UINT channels zero-extend, SINT channels sign-extend, d16 packs them as 16-bit integers, measured natively on gfx1036 (wave32 and wave64) with `tools/hw_oracle` and checked word for word by `tests/semantic/test_buffer_format_narrow_int.py`; GPU-checked by `runtime/test/shaders/cs_fmt_int_narrow.asm`, whose 136 expected words are the same program run natively on gfx1036 (exact on an RTX 5080 and on the gfx1036 iGPU through Vulkan). 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. The `_xy` and `_xyz` forms (buffer and tbuffer) are GPU-checked by `cs_fmt_xy_xyz.asm`, whose words were measured natively on a Radeon 680M (gfx1035, RDNA2): they write only their 2 or 3 VGPRs, and missing channels repeat there too (TEST-185). | 330| 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 ×1/2/4, sint8 ×1/2/4, unorm16 ×1/2/4, snorm16 ×1/2/4, uint16 ×1/2/4, sint16 ×1/2/4, 10-10-10-2 and 2-10-10-10 unorm, and, since 2026-11-22, the other GFX10 buffer codes 1–77 (every USCALED/SSCALED, 10_11_11 and 11_11_10 FLOAT, the 10_10_10_2 and 2_10_10_10 families, 8_8_8_8 and 16_16_16_16 SINT and SCALED; see *Typed buffer formats*). Others (code 0 and 78 up) give 0. The 8- and 16-bit UINT/SINT formats 5, 6, 11, 12, 18, 19, 28, 61 and 70 were missing until 2026-11-22 and read 0: UINT channels zero-extend, SINT channels sign-extend, d16 packs them as 16-bit integers, measured natively on gfx1036 (wave32 and wave64) with `tools/hw_oracle` and checked word for word by `tests/semantic/test_buffer_format_narrow_int.py`; GPU-checked by `runtime/test/shaders/cs_fmt_int_narrow.asm`, whose 136 expected words are the same program run natively on gfx1036 (exact on an RTX 5080 and on the gfx1036 iGPU through Vulkan). 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. The `_xy` and `_xyz` forms (buffer and tbuffer) are GPU-checked by `cs_fmt_xy_xyz.asm`, whose words were measured natively on a Radeon 680M (gfx1035, RDNA2): they write only their 2 or 3 VGPRs, and missing channels repeat there too (TEST-185). |
331| Descriptor hash table | `uint mask; entries[mask+1] of 10 uints: key[0..7], index, kind`. The last word is 0 in an empty slot; otherwise bit 31 marks it occupied and bits 0..5 / 8..11 name the sampled / storage arrays the index is bound in (docs/d3d12_vulkan.md section 5.1, "Images and samplers (T# dimension)" below). A module reads it only when its index entry says `"descriptor_table": "tagged"`; `--descriptor-table plain` leaves the word unread and gives byte-identical modules to the translator before the marker (checked with a 5-instruction pixel shader: old and plain output are the same bytes). The key is a T# or a padded S#. FNV-1a over the eight key words selects the first slot by default. With `--descriptor-hash=fnv1a_fmix32` the shader applies MurmurHash3 fmix32 before masking the slot. Every translated module then records `"descriptor_hash": "fnv1a_fmix32"` in its index entry. An absent key means `fnv1a`. The runtime and shader must select the same hash. The shared SPIR-V lookup probes up to eight slots and returns index 0 on a miss. The runtime supplies a fallback at index 0 and maps live descriptor keys to bindless indices. Outside the wave64 emulation, the lookup's result goes through `OpGroupNonUniformBroadcastFirst` before it indexes the image or sampler array. The lookup key words come from SGPRs, so every invocation in a subgroup has the same index; the broadcast is an identity on all drivers and marks the value uniform for the compiler. It declares `GroupNonUniform` and `GroupNonUniformBallot`, without a shuffle capability or subgroup-lane input. The shader index records the capabilities; its `features` field lists optional Vulkan device features. Mesa ANV 26.2.7 on an Intel Alder Lake-S UHD (Xe-LP, Linux) segfaults in `vkCreate*Pipelines` on a sampler index taken straight from the probe loop when that sampler serves both a float and an integer image (`cs_sample_lz_int_d16`, `ps_ssharp`); with the broadcast both pass. Checked by the unit test `test_lookup_result_is_broadcast_before_use` in `tests/test_desc_cache.py` (standard library only: no GPU, LLVM or SPIRV-Tools). | 331| Descriptor hash table | `uint mask; entries[mask+1] of 10 uints: key[0..7], index, kind`. The last word is 0 in an empty slot; otherwise bit 31 marks it occupied and bits 0..5 / 8..11 name the sampled / storage arrays the index is bound in (docs/d3d12_vulkan.md section 5.1, "Images and samplers (T# dimension)" below). A module reads it only when its index entry says `"descriptor_table": "tagged"`; `--descriptor-table plain` leaves the word unread and gives byte-identical modules to the translator before the marker (checked with a 5-instruction pixel shader: old and plain output are the same bytes). The key is a T# or a padded S#. FNV-1a over the eight key words selects the first slot by default. With `--descriptor-hash=fnv1a_fmix32` the shader applies MurmurHash3 fmix32 before masking the slot. Every translated module then records `"descriptor_hash": "fnv1a_fmix32"` in its index entry. An absent key means `fnv1a`. The runtime and shader must select the same hash. The shared SPIR-V lookup probes up to eight slots and returns index 0 on a miss. The runtime supplies a fallback at index 0 and maps live descriptor keys to bindless indices. Outside the wave64 emulation, the lookup's result goes through `OpGroupNonUniformBroadcastFirst` before it indexes the image or sampler array. The lookup key words come from SGPRs, so every invocation in a subgroup has the same index; the broadcast is an identity on all drivers and marks the value uniform for the compiler. It declares `GroupNonUniform` and `GroupNonUniformBallot`, without a shuffle capability or subgroup-lane input. The shader index records the capabilities; its `features` field lists optional Vulkan device features. Mesa ANV 26.2.7 on an Intel Alder Lake-S UHD (Xe-LP, Linux) segfaults in `vkCreate*Pipelines` on a sampler index taken straight from the probe loop when that sampler serves both a float and an integer image (`cs_sample_lz_int_d16`, `ps_ssharp`); with the broadcast both pass. Checked by the unit test `test_lookup_result_is_broadcast_before_use` in `tests/test_desc_cache.py` (standard library only: no GPU, LLVM or SPIRV-Tools). |
332| Bindless index in the T# | On the console a texture access loads the T# and samples; the hash-table lookup above made every access hash the eight T# words and probe up to eight table slots (in `3TL_PS_NoDir_PBR_MATERIAL_STANDARD_42ad1e50`, the tiled-lighting pixel shader, 62 lookups and 19,714 RADV instructions against 3,080 in the native program). **What pack and runtime agree on:** in every heap shaders read, the layer writes dword 6 of each T# as `0xA << 28 \| storage kind << 23 \| sampled kind << 16 \| index`: the tag `0xA` in [31:28], the table's storage kind bits 8..12 in [27:23], its sampled kind bits 0..6 in [22:16] and the bindless index in [15:0] (`runtime/src/gfx10_descriptors.h`, `tsharp_index_word`). **Index 0** is the fallback of the array the instruction reads: the word is 0 while the T# has no entry (no texture at its address yet, a stream pending, no room in its array), for index 0 itself and for an index past 16 bits, and a shader reads index and kind 0 unless the word has the tag **and** dword 3 names an image (TYPE 8..15, bit 31), so a V#, a data slot or a zero slot read as a T# never passes. Then, as for a table entry, the kind bit of the instruction's array decides between the index and that array's fallback. The heaps: the copies of the console resource heaps (`fix_console_slot`, fixed again whenever the texture at the T#'s address comes, goes or is replaced, or the T#'s entry is replaced) and the layer's own heaps (`write_image_descriptor`; `scan_title_table` refreshes bound tables; a view `LEONIDA_PIPELINE_COMPILE=on-demand` defers gets its word when it is made, `materialize_table`). Dword 6 is the hardware's compression metadata, which no Vulkan view uses; the title's own bytes and the T#'s table key keep the title's dword 6 (`tsharp_key` strips the word from bytes read back from the layer's heaps). **Translator** (`Gen.tsharp_index_sgpr`, `tools/descriptor_sources.py`): a forward SGPR dataflow over the basic blocks marks each image instruction whose T# dword 6 is dword 6 of a heap slot: an `s_load` from a 32-bit pointer in a user SGPR (a descriptor table or a directly indexed heap, `docs/d3d12_vulkan.md` section 3.4) at slot position 24 (a static offset is checked; a run-time one is the heap index times 32), followed through copies, joins of two such loads, SGPRs parked in VGPR lanes (`v_writelane`/`v_readlane`) and VCC used as two more SGPRs. Those instructions read index and kind from the word, with no memory access and no lookup. Any other T# keeps the lookup inside a uniform branch taken only when its dword 6 has no tag, so a heap T# the dataflow could not place costs no probe either (`Gen.tsharp_lookup`). S#s keep the lookup: the console sampler heaps are the title's pages read in place, and S#s have no free field. **Older packs** are told apart by the module meta: every module this translator writes has `"tsharp_index": "dword6"` (with its counts `tsharp_index_reads` and `tsharp_lookups`); the runtime counts them (`TsharpIndexCensus`) and writes the word when any module reads it, logging `T# index word: written into the heaps' T#s (all N modules)` or `not read`. A pack without the key keeps working as before: no word is written and its modules find every T# by its words. A library mixing both is logged, since its older modules then miss heap T#s (their copy's dword 6 is not the key). `LEONIDA_CONSOLE_HEAP_GPU`'s pass copies T#s as written, so with an index-word pack the resource heaps are fixed on the CPU (logged once, `runtime/README.md`). Modules change, so pipeline keys change with them. **Counts** (`tools/descriptor_source_census.py`): 1.0.2.1 carve, 26,503 listings: 439,415 image instructions with a T# in 17,540 modules; 437,263 take the whole T# from such a heap load (257,962 static, 179,301 run-time offset), 1,916 are lost at joins or computed, 235 come from another base, 1 from a 64-bit pointer, none from a title buffer through a V#, none built from constants and none edited in dword 6. No scalar instruction reads dword 5, 6 or 7 of a heap T# (dword 1: 8,065, 2: 12,069, 3: 9,177, 4: 3, 0: 1), so the shaders' own maths never sees the word. The translator marks 438,693 (99.84%; 17,474 of the 17,540 modules keep no T# lookup) before the VCC rule, which only adds. Pipeline library, 2,684 programs: 113,585 of 157,410 (72%; 1,649 of 2,235 modules), the rest mostly pointers rebuilt through paths the dataflow does not follow (those run the branch above). Of the carve's 366,628 S# operands, 188,732 come from heap loads, 146,036 are literal and 31,860 from elsewhere. **Cost**, RADV (Mesa 26.3.1) on an RX 7900 XTX, `vk_pipeline_check --stats`: the lighting shader above, instructions 19,714 → 17,568, latency 73,690 → 32,458, inverse throughput 16,453 → 7,468, spilled SGPRs 31 → 17 (its 20 remaining lookups are S#s); the library program `lib_cs_01296` (screen-probe ray activation), instructions 40,901 → 36,046, latency 88,291 → 52,359, inverse throughput 20,579 → 13,451, spilled SGPRs 1,007 → 43. **Checked by** `tests/semantic/test_tsharp_index_word.py` (the interpreter reads the image the word names with no table bound; an untagged word, a 3D kind for a 2D load, a dword 3 that names no image and a zero slot read the fallback; a 64-bit-pointer T# looks the table up only without the word; the fixture `ps_tsharp_index_word.s` with a T# loaded in either arm of a branch; the dataflow's static and run-time offsets, a slot read as two halves, VGPR-lane spills, VCC, and the sources that keep the lookup), `runtime/test/gfx10_descriptors_test.cpp` (the word's bits and the key), `shader_library_test` (the census) and the Wine suite's d3d12 tests, which read the word back through `bindless_hash_lookup`. GPU-checked on the Ryzen 9 7950X3D's integrated GPU (RADV RAPHAEL_MENDOCINO, Mesa 26.3.1): `ps_texture_sample` and `ps_table_fetch` load their T# through a table pointer as the title's shaders do and `vk_texture_test` writes the word: the gradient sample and 4096 exact pixels each for SINT, UINT and the miss control (a dword 6 without the tag reads index 0), with no T# lookup in either module. |
332| Run-time format decode cost | A `buffer_load_format_*` whose format comes from the V# is decoded by table, without a branch: one shared function per output component (`%fmt_dec_c0`…`%fmt_dec_c3`) reads the format's kind, channel count and channel widths from the module table `%fmt_desc_tab`, and the kind picks the conversion with `OpSelect`; the exact UNORM/SNORM quotient comes from the shared `%fmt_norm_bits`, whose width's 64-bit repeat constant is read from `%fmt_norm_rep_tab`. A code outside the table gives zeros, a format with fewer channels repeats its own (component *c* = *c* mod *n*), and the element size is selected from the format alone (`%fmt_size_tab`), the per-lane byte offset added once. Until 2026-11-23 the shared function instead held every format's decode and a binary search over the codes (`OpSelectionMerge` with `DontFlatten`): 3,498 instructions and 306 branches in the module of a shader with one dynamic-format load (250,869 bytes). Now the four functions hold 565 instructions and no branch, and that module is 56,763 bytes. The decode functions take the format code and the element's four dwords as a `v4uint`, so their function type has a structure of its own: a type of `uint` × 5 repeats the type of the `x_round` helpers, and SPIR-V forbids two non-aggregate types with the same structure. Over the 1.0.2.1 corpus the 11,400 shaders that use this path all translate and pass \spirv-val\ (the previous translator included), and their modules shrink from 11,163,872,428 to 10,454,474,528 bytes (-6.35%). The 15,103 shaders without a run-time FORMAT come out byte for byte identical (checked on a 297-shader sample, every 51st of them). The values are unchanged: every one of the 128 codes gives the same words as the branch search, checked by `tests/semantic/test_format_decode_table.py` (each code against a reference decoded from the raw bits with exact quotients, plus the branch-free and shared-per-component shape). The old translation was confirmed on an RTX 4090 (621.01) against the decode-everything translation: identical output buffers for all 128 codes in four configurations (four byte alignments, out-of-range records, constant DST_SEL), xyzw and d16_xyzw. The branch-free decode costs more ALU per load than the search (every kind's conversion is computed and one is kept), so it trades run time for module size and compile time. | 333| Run-time format decode cost | A `buffer_load_format_*` whose format comes from the V# is decoded by table, without a branch: one shared function per output component (`%fmt_dec_c0`…`%fmt_dec_c3`) reads the format's kind, channel count and channel widths from the module table `%fmt_desc_tab`, and the kind picks the conversion with `OpSelect`; the exact UNORM/SNORM quotient comes from the shared `%fmt_norm_bits`, whose width's 64-bit repeat constant is read from `%fmt_norm_rep_tab`. A code outside the table gives zeros, a format with fewer channels repeats its own (component *c* = *c* mod *n*), and the element size is selected from the format alone (`%fmt_size_tab`), the per-lane byte offset added once. Until 2026-11-23 the shared function instead held every format's decode and a binary search over the codes (`OpSelectionMerge` with `DontFlatten`): 3,498 instructions and 306 branches in the module of a shader with one dynamic-format load (250,869 bytes). Now the four functions hold 565 instructions and no branch, and that module is 56,763 bytes. The decode functions take the format code and the element's four dwords as a `v4uint`, so their function type has a structure of its own: a type of `uint` × 5 repeats the type of the `x_round` helpers, and SPIR-V forbids two non-aggregate types with the same structure. Over the 1.0.2.1 corpus the 11,400 shaders that use this path all translate and pass \spirv-val\ (the previous translator included), and their modules shrink from 11,163,872,428 to 10,454,474,528 bytes (-6.35%). The 15,103 shaders without a run-time FORMAT come out byte for byte identical (checked on a 297-shader sample, every 51st of them). The values are unchanged: every one of the 128 codes gives the same words as the branch search, checked by `tests/semantic/test_format_decode_table.py` (each code against a reference decoded from the raw bits with exact quotients, plus the branch-free and shared-per-component shape). The old translation was confirmed on an RTX 4090 (621.01) against the decode-everything translation: identical output buffers for all 128 codes in four configurations (four byte alignments, out-of-range records, constant DST_SEL), xyzw and d16_xyzw. The branch-free decode costs more ALU per load than the search (every kind's conversion is computed and one is kept), so it trades run time for module size and compile time. |
333| 3D explicit-gradient texture samples | For `image_sample_d` and `image_sample_d_cl` on a 3D view, the first six address VGPRs contain dP/dx.xyz and dP/dy.xyz. XYZ and the optional minimum LOD follow. With `a16`, the six derivative VGPRs still hold f32; the following two words contain packed f16 coordinates and the optional clamp. The hand-written `tests/semantic/fixtures/volume_gradients.asm` checks the source registers of both gradients, coordinates and clamp. LLVM gfx1030 assembles all four forms and their modules validate for Vulkan 1.2. [LLVM GFX10 address sizing](https://reviews.llvm.org/D102231) and [SPIR-V Grad operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Image_Operands) | 334| 3D explicit-gradient texture samples | For `image_sample_d` and `image_sample_d_cl` on a 3D view, the first six address VGPRs contain dP/dx.xyz and dP/dy.xyz. XYZ and the optional minimum LOD follow. With `a16`, the six derivative VGPRs still hold f32; the following two words contain packed f16 coordinates and the optional clamp. The hand-written `tests/semantic/fixtures/volume_gradients.asm` checks the source registers of both gradients, coordinates and clamp. LLVM gfx1030 assembles all four forms and their modules validate for Vulkan 1.2. [LLVM GFX10 address sizing](https://reviews.llvm.org/D102231) and [SPIR-V Grad operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Image_Operands) |
334| `image_sample_c_l` | Scalar 2D depth comparison (`dmask:0x1`) takes the f32 reference, XY coordinates and explicit mip in that order. Under A16 the reference stays full-width; XY share a VGPR and LOD uses the next low half. D16 returns the comparison in the low half of the destination. Confirmed against LLVM AMDGPU's `llvm.amdgcn.image.sample[.a16].dim.ll` lowering and synthetic Vulkan 1.2 modules in `test_explicit_mip_depth_compare`. | 335| `image_sample_c_l` | Scalar 2D depth comparison (`dmask:0x1`) takes the f32 reference, XY coordinates and explicit mip in that order. Under A16 the reference stays full-width; XY share a VGPR and LOD uses the next low half. D16 returns the comparison in the low half of the destination. Confirmed against LLVM AMDGPU's `llvm.amdgcn.image.sample[.a16].dim.ll` lowering and synthetic Vulkan 1.2 modules in `test_explicit_mip_depth_compare`. |