Files
mandy/runtime/test/shaders/ps_table_fetch.asm
Jan Trencansky 872a8cf417 descriptors: a heap T# carries its bindless index in dword 6; shaders read it there instead of probing the hash table
On the console a texture access loads the T# and samples. Translated shaders hashed the eight T# words and probed up
to eight slots of the descriptor table for every access: 62 lookups and 19,714 RADV instructions in the tiled-lighting
pixel shader (3,080 in the native program).

The layer now writes the index into dword 6 of every T# in the heaps shaders read, as TAG 0xA [31:28] | storage kind
[27:23] | sampled kind [22:16] | index [15:0] (gfx10_descriptors.h, tsharp_index_word): the console resource heap
copies (fix_console_slot, again whenever the texture at the T#'s address comes, goes or is replaced) and its own
shader-visible heaps (write_image_descriptor, refreshed for bound tables by scan_title_table). The title's bytes and
the T#'s table key keep the title's dword 6.

The translator (tools/descriptor_sources.py, Gen.tsharp_index_sgpr) follows the SGPR dataflow and takes the index from
dword 6, with no lookup, for every T# whose dword 6 it traces to a heap slot (an s_load from a 32-bit descriptor-table
or heap pointer in user data); index 0 unless the word has the tag and dword 3 names an image. Other T#s are looked up
and prefer a tagged word. S#s keep the lookup (sampler heaps are read in place; 40% are literals).

Over the 1.0.2.1 corpus (tools/descriptor_source_census.py) 438,353 of 439,415 T# operands (99.76%) take the word and
17,432 of 17,540 modules keep no T# lookup; no scalar instruction reads dword 5-7 of a heap T#. RADV on an RX 7900 XTX,
lighting shader: instructions 19,714 -> 17,568, latency 73,690 -> 32,458, inverse throughput 16,453 -> 7,468.

Modules record "tsharp_index": "dword6"; the runtime writes the word when the library's modules read it, so packs
translated before keep working as they did. LEONIDA_CONSOLE_HEAP_GPU's pass copies T#s as written, so such a library's
console heaps are fixed on the CPU.

Tests: tests/semantic/test_tsharp_index_word.py (interpreter and dataflow), gfx10_descriptors_test, shader_library_test;
ps_texture_sample and ps_table_fetch now load their T# through a table pointer and vk_texture_test writes the word
(integrated GPU, RADV).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 05:20:52 -05:00

19 lines
787 B
NASM

; vk_texture_test fetch-sint / fetch-uint / fetch-miss. Texel (0,0) holds bytes
; 82 22 f8 4d: expect (-126,34,-8,77) or (130,34,248,77). A key mismatch
; fetches magenta UNORM at index zero. Convert raw integer words for RGBA32F output.
; s0 is a descriptor-table pointer (s1 = 0): the index comes from the T#'s dword 6 (docs/design.md, "Bindless index in
; the T#"), and fetch-miss writes a dword 6 without the index tag, which must read index zero.
s_mov_b32 s1, 0
s_load_dwordx8 s[8:15], s[0:1], 0
s_waitcnt lgkmcnt(0)
v_mov_b32_e32 v0, 0
v_mov_b32_e32 v1, 0
image_load v[4:7], v[0:1], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_2D
s_waitcnt vmcnt(0)
v_cvt_f32_i32_e32 v4, v4
v_cvt_f32_i32_e32 v5, v5
v_cvt_f32_i32_e32 v6, v6
v_cvt_f32_i32_e32 v7, v7
exp mrt0 v4, v5, v6, v7 done vm
s_endpgm