From 6102db886f8e04ed506ad333b2bf436c90c3aaea Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Tue, 1 Dec 2026 15:55:09 +0000 Subject: [PATCH 1/2] shader: accept the slot 57 heap descriptor load form The stable slot 57 profile 9482ea4411e1e03f reaches the mesh frontend with req_72e1909e13df6f66.m57 and refused at +0x614. The decoded instruction there is s_load_dwordx8 s[56:63], s[12:13], s22: SMEM op 3, immediate offset 0, an SGPR offset proven as a multiple of 32, and the base copied from heap SGPR 23 with a constant zero high word. It feeds image_load v[19:21], v11, s[56:63] at +0x700. - The mesh heap branch behind validate_uint_heap_reads accepted only op 2 (s_load_dwordx4); it now also accepts op 3 (s_load_dwordx8) with the same immediate-offset, high-word, destination-range and provenance rules. - A root-provided selector still records heap_fetches. A GPU-selected selector that is a proven multiple of 32 keeps the fetch opaque: it records the heap slot (bytes >> 5) by pc, but leaves all eight destination words symbolic. Their field bits are not available here, so a numeric read keeps refusing (unbound numeric SGPR s33 or s37) until a consumer supplies the fields. - With texture_heap_slot_map the texture branch keeps priority and words 1..3 remain the guest descriptor metadata from the remap record. - The write loop no longer indexes a fixed eight-word array for wider loads; it writes texture metadata only, so a sixteen-dword table or heap load cannot read past the record. Observed on the captured MS with the exact profile layout: - before: native compute +0x614: unsupported mesh heap descriptor address - now: native compute +0x69c: unbound numeric SGPR s57 That refusal is the intended boundary: the image consumer and its V# fields belong to the separate image-load change. tests/native_direct_mesh_check.py adds the eight-dword heap fetch feeding a typed load, a sixteen-dword table refusal, a sixteen-dword heap write-loop control, the GPU-selected typed/image/numeric refusals, and the texture fixture's masked and unmasked selectors. The slot-map form is the only one that reads descriptor word 1 numerically. Verified: - cmake --build --preset release --target compile_dxil - python -B tests/native_direct_mesh_check.py : exit 0, "mesh allocation, indexed outputs, group exchange and negative controls passed" - ctest --preset release --no-tests=error -R '^native_direct': 2/2 passed Refs #3497 --- .../native-mesh-heap-descriptor.md | 66 +++++++++++++ src/gfx1013_direct_mesh.inl | 25 ++++- tests/native_direct_mesh_check.py | 92 ++++++++++++++++--- 3 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 docs/experiments/native-mesh-heap-descriptor.md diff --git a/docs/experiments/native-mesh-heap-descriptor.md b/docs/experiments/native-mesh-heap-descriptor.md new file mode 100644 index 0000000000..a14e82f2e9 --- /dev/null +++ b/docs/experiments/native-mesh-heap-descriptor.md @@ -0,0 +1,66 @@ +# Slot 57 mesh heap descriptor load + +The stable slot 57 profile `9482ea4411e1e03f` (version 5, heap SGPR 23, +`validate_uint_heap_reads`, views s16..s19 for roots 0..3) reaches the mesh +frontend with `req_72e1909e13df6f66.m57`. The captured MS is the exact part +the profile carries, so `compile_dxil gfx1013-raw-ms` reproduces the run's +refusal byte for byte. + +## Decoded form + +At code offset `+0x614` the program issues + + s_load_dwordx8 s[56:63], s[12:13], s22 + +SMEM op 3 (eight dwords), immediate offset 0, SGPR offset s22, base s12:s13 +where s12 was copied from the heap SGPR s23 and s13 is the constant 0. The +preceding `s_lshl_b32 s22, s22, 5` proves the byte offset is a multiple of 32, +and the result feeds `image_load v[19:21], v11, s[56:63] dmask:0x7 +dim:SQ_RSRC_IMG_1D unorm` at `+0x700`. + +## Contract + +The mesh heap branch behind `validate_uint_heap_reads` accepted only +`i.op == 2` (one four-dword typed-buffer descriptor). It now also accepts +`i.op == 3`, the eight-dword texture descriptor, with the same address rules: +no immediate offset, an SGPR offset inside the SGPR range, a constant zero high +word and the destination range check. A root-provided selector still records +`heap_fetches`; a GPU-selected selector that is a proven multiple of 32 keeps +the fetch opaque and records only the heap slot: + +- the fetch records `bytes >> 5` by its pc for a consumer that brings its own + descriptor contract. The eight destination words stay symbolic; none of + their field bits are available, so a numeric read keeps refusing (for + example `unbound numeric SGPR s33` for word 1 and `s37` for word 5); +- with `texture_heap_slot_map` the texture branch keeps priority and words 1..3 + stay the guest descriptor metadata from the remap record; +- the consumers still need their own proof: a buffer load needs + `heap_fetches`/`token_fetches` and an image needs + `texture_heap_fetches`, so an unmapped selection still refuses. + +## Observed + +Before this change the request refused at `+0x614: unsupported mesh heap +descriptor address`. After accepting the eight-dword form it refused at +`+0x69c: unbound numeric SGPR s57` because the eight words stayed +`indexed_descriptor`. That refusal is the correct one here: the fetch has +recorded the slot, but the image still needs a consumer that can name the V# +fields. The slot-57 image change supplies that consumer separately; it must +use the recorded slot and keep the words symbolic. + +## Fixture + +[tests/native_direct_mesh_check.py](../../tests/native_direct_mesh_check.py) +adds the eight-dword heap fetch feeding a typed load (`typed-heap-descriptor-x8`), +a sixteen-dword refusal (`typed-heap-descriptor-x16`) and an unaligned-offset +refusal (`typed-heap-descriptor-unproven`). The GPU-selected form is covered by +`gpu-heap-descriptor-x8-typed`, `-x8-image`, `-word-1` and `-word-5`, all of +which keep refusing. `mesh-table-wide-load` and `mesh-heap-wide-load` cover a +sixteen-dword write loop against the eight-word record. The texture fixture has +a masked and an unmasked selector; only the slot-map form reads descriptor +word 1 (`s33`) numerically. + +**Reproduce** with +`ctest --preset release --no-tests=error -R '^native_direct'` and +`ctest --preset release --no-tests=error -R '^native_fixed_mesh57_warp$'`. + diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index abc97056b8..f94c6b76cb 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -96,6 +96,8 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout std::map heap_fetches; std::set heap_entry_offsets; std::map texture_heap_fetches; + // The heap slot an eight-dword descriptor fetch read, by the pc of that fetch. + std::map heap_descriptor_slots; // heap_tokens: the heap descriptor loads at a byte offset in heap_entry_offsets (a multiple of the 32-byte // descriptor size), by pc, with that offset. if (layout.heap_tokens && !layout.validate_uint_heap_reads) @@ -1447,19 +1449,38 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout ir.features|=16; emitter.result.mesh_texture_heap_slot_map=true; } else if (global && layout.validate_uint_heap_reads) { - if (i.op!=2 || offset_reg>=106 || (i.b&0xfffff) || + // A typed-buffer descriptor is one s_load_dwordx4 (op 2) and a + // texture descriptor is one s_load_dwordx8 (op 3); both take + // the same resource-heap address. + if ((i.op!=2 && i.op!=3) || offset_reg>=106 || (i.b&0xfffff) || !(state[i.src[0]+1]==Symbol{Symbol::Type::constant,0})) refuse(pc,"unsupported mesh heap descriptor address"); const auto bytes=alu.operand32(i,offset_reg); + bool heap_descriptor=false; const auto bits=root_values.find(bytes); - if (bits!=root_values.end() && bits->second.shift==5) + if (bits!=root_values.end() && bits->second.shift==5) { heap_fetches[pc]=bits->second; + heap_descriptor=true; + } else if (layout.heap_tokens && heap_entry_offsets.count(bytes)) token_fetches[pc]=bytes; else if (layout.heap_tokens) refuse(pc,"mesh heap token byte offset is not a proven multiple of 32"); + else if (i.op==3 && heap_entry_offsets.count(bytes)) + // A 32-byte-aligned eight-dword fetch whose slot comes from GPU data + // stays opaque. It records only the slot for a consumer that brings its + // own descriptor contract; it adds no heap_fetches, token_fetches or + // mesh_heap_reads entry and leaves the eight words symbolic. + heap_descriptor=true; else refuse(pc,"mesh heap slot lacks masked root constant provenance"); + if (i.op==3 && heap_descriptor) { + // The eight words are a whole guest V# whose field bits are not + // available here. Record only the heap slot; a consumer that can + // name the fields supplies its own contract, and a numeric read + // keeps refusing until then. + heap_descriptor_slots[pc]=ir.binary("lshr",bytes,"5"); + } } else { const auto offset=alu.graphics_registers.find(offset_reg); const bool uniform_load=i.op>=8 && whole_wave_execution() && !branch && forward.empty() && diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index 0816a19356..af1d2a868f 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -651,6 +651,19 @@ def run(name, words, expected=None): assert marker in text, marker overwritten = typed[:7] + [0xbea10380] + typed[7:] run('overwritten-heap-word',overwritten+exported,'overwritten mesh heap descriptor') + # The slot 57 descriptor load may be eight dwords wide: the same heap + # address and proven selector fetch one 32-byte descriptor, and the + # first four words stay the V# a typed load consumes. + x8_fetch = [0xf40c080f, 0x2a000000] # s_load_dwordx8 s[32:39], s[30:31], s21 + x8_load = [0x7e020280,0xe0002000,0x80080a01] # v1 = 0; buffer_load_format_x v10, v1, s[32:35] idxen + text = run('typed-heap-descriptor-x8', typed[:5] + x8_fetch + x8_load + exported) + for marker in ('createHandleFromHeap', 'bufferLoad.i32', 'i32 261'): + assert marker in text, marker + run('typed-heap-descriptor-x16', typed[:5] + [0xf410080f, 0x2a000000] + x8_load + exported, + '+0x14: unsupported mesh heap descriptor address') + run('typed-heap-descriptor-unproven', + [0xbe9e0317,0xbe9f0380,0x8f148415] + [0xf40c080f, 0x28000000] + x8_load + exported, + '+0xc: mesh heap slot lacks masked root constant provenance') # Unindexed buffer_load_format_x reads element 0 without touching vaddr, and its result is uniform under full EXEC. heap_setup = typed[:7] load_idxen = [0xe0002000, 0x80080a01] # buffer_load_format_x v10, v1, s[32:35], 0 idxen @@ -710,28 +723,57 @@ def skip_load(body, seed=True): ] text = run('typed-heap-saveexec-then', skip_load(saveexec_load)) assert 'bufferLoad.i32' in text and 'mesh_then' in text and 'phi i32' in text, text - texture = [ + texture_fetch = [ 0xbe9e0317, 0xbe9f0380, # heap base and zero high word - 0x8f148515, # s20 = s21 << 5 + 0x8715ff15, 31, # mask the root selector + 0x8f148515, # s20 = s21 << 5 0xf40c080f, 0x28000000, # s_load_dwordx8 s[32:39], s[30:31], s20 - 0x9394ff23, 0x4000c, 0x7e020214, # v1 = base mip from descriptor word 3 - 0xf0001f00, 0x00080a01, # image_load 1D v[10:13] at v1 ] + texture_zero = [0x7e020280] # v1 = 0 + texture_load = [0xf0001f00, 0x00080a01] # image_load 1D v[10:13] at v1 + texture_numeric = [0x9394ff21, 0x4000c, 0x7e020214] # v1 = field from word 1 texture_export = program.copy() texture_export[7] = 0x7e02030a # pass the red float to POS0.x - run('mesh-texture-heap-without-map',texture+texture_export,'unsupported mesh heap descriptor address') + # The eight words stay symbolic: without a contract a descriptor word + # has no numeric value, for word 1 and word 5 alike. + run('mesh-descriptor-word-1', texture_fetch + texture_numeric + texture_export, + 'unbound numeric SGPR s33') + run('mesh-descriptor-word-5', + texture_fetch + [0x9394ff25, 0x4000c, 0x7e020214] + texture_export, + 'unbound numeric SGPR s37') + # An image consumer needs the slot map even with a zero coordinate, so + # the descriptor-word read cannot refuse before the image does. + run('mesh-texture-heap-without-map', + texture_fetch + texture_zero + texture_load + texture_export, + 'unsupported mesh instruction or EXEC state: image_load') + # The unmasked selector reaches the GPU-selected branch through the + # proven 32-byte shift; it still needs the remapped view. + texture_gpu = [ + 0xbe9e0317, 0xbe9f0380, + 0x8f148515, + 0xf40c080f, 0x28000000, + ] + run('mesh-texture-heap-gpu-without-map', + texture_gpu + texture_zero + texture_load + texture_export, + 'unsupported mesh instruction or EXEC state: image_load') with layout.open('a') as meta: meta.write('\ntexture_heap_slot_map') - text = run('mesh-texture-heap-slot-map',texture+texture_export) + texture_mapped = texture_fetch + texture_numeric + texture_load + text = run('mesh-texture-heap-slot-map', texture_mapped + texture_export) for marker in ('t0,space1', 'RawBuffer', 'createHandleFromHeap', 'textureLoad.f32', 'texture1d'): assert marker.lower() in text.lower(), marker - bad_shift = texture.copy() - bad_shift[2] = 0x8f148415 - run('mesh-texture-heap-unaligned',bad_shift+texture_export,'32-byte alignment proof') - bad_dim = texture.copy() + text = run('mesh-texture-heap-gpu-slot-map', + texture_gpu + texture_zero + texture_load + texture_export) + assert 'textureLoad.f32' in text and 'createHandleFromHeap' in text, text + bad_shift = texture_mapped.copy() + bad_shift[4] = 0x8f148415 + run('mesh-texture-heap-unaligned', bad_shift + texture_export, '32-byte alignment proof') + bad_dim = texture_mapped.copy() bad_dim[-2] |= 8 - run('mesh-texture-heap-wrong-dimension',bad_dim+texture_export,'remapped Texture1D heap contract') - run('mesh-texture-heap-overwritten',texture[:5]+[0xbea70380]+texture[5:]+texture_export, + run('mesh-texture-heap-wrong-dimension', bad_dim + texture_export, + 'remapped Texture1D heap contract') + run('mesh-texture-heap-overwritten', + texture_mapped[:7] + [0xbea70380] + texture_mapped[7:] + texture_export, 'overwritten mesh texture heap descriptor') half_frontend = [0xcc210014, 242 | (242 << 9) | (242 << 18)] # v_fma_mixlo_f16 v20, 1, 1, 1 half_pack = [0xd711001a, 276 | (276 << 9)] # pack the defined low half of v20 twice @@ -754,6 +796,32 @@ def skip_load(body, seed=True): gpu_layout = 'mesh1 128 3 1 2 128 64\ntable 16 1\nresource_heap 23\nvalidate_uint_heap_reads' layout.write_text(gpu_layout) run('token-no-contract',selected+exported,'mesh heap slot lacks masked root constant provenance') + # A GPU-selected eight-dword descriptor fetch records only its slot. + # The typed consumer has no heap or token fetch, an image needs the + # slot map, and numeric reads of words 1 and 5 stay unbound. + selected_x8 = select_word + times_32 + heap_base + [0xf40c080f, 0x48000000] + run('gpu-heap-descriptor-x8-typed', selected_x8 + formatted + exported, + 'formatted mesh load lacks an R32_UINT resource heap contract') + run('gpu-heap-descriptor-x8-image', + selected_x8 + [0x7e020280, 0xf0001f00, 0x00080a01] + texture_export, + 'unsupported mesh instruction or EXEC state: image_load') + run('gpu-heap-descriptor-word-1', + selected_x8 + [0x9394ff21, 0x4000c, 0x7e020214] + exported, + 'unbound numeric SGPR s33') + run('gpu-heap-descriptor-word-5', + selected_x8 + [0x9394ff25, 0x4000c, 0x7e020214] + exported, + 'unbound numeric SGPR s37') + # A sixteen-dword table fetch is refused by the shared table bounds; + # a sixteen-dword heap fetch without the validated branch still reaches + # the write loop, which must stay inside the eight-word record. + wide_table = [0xf4100808, 0xfa000000] + run('mesh-table-wide-load', program[:5] + wide_table + [0x7e020220] + program[6:], + 'direct descriptor address outside bound table') + layout.write_text('mesh1 128 3 1 2 128 64\nresource_heap 23') + run('mesh-heap-wide-load', + program[:5] + [0xbe9e0317, 0xbe9f0380, 0xf410080f, 0xfa000000] + + [0x7e020220] + program[6:], + 'direct resource-heap load requires the selected GPU slot and its view type') layout.write_text('mesh1 128 3 1 2 128 64\ntable 16 1\nresource_heap 23\nheap_tokens') run('token-unvalidated',selected+exported,'mesh heap tokens require validated heap reads') token_layout = gpu_layout + '\nheap_tokens' From b4c5697aa1cf08c71c047f8ebc3f4db670d4fe7f Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Tue, 1 Dec 2026 16:22:40 +0000 Subject: [PATCH 2/2] shader: translate mesh image_load through a full table descriptor The slot 57 capture req_72e1909e13df6f66.m57 contains image_load v[19:21], v11, s[56:63] dmask:0x7 dim:SQ_RSRC_IMG_1D unorm at +0x700, fed by the eight-dword resource-heap fetch at +0x614. This is a complete guest V#, not a texture heap slot-map record, so the slot-map branch refuses it. - A mesh image branch handles the full-V# form when !layout.texture_heap_slot_map: image_load (op 0), dim 1D, dmask 0x7, UNORM, no LWE/TFE/R128/reserved bits, eight contiguous descriptor words sharing one fetch pc and a destination inside the VGPR range. - The eight words stay symbolic. The fetch is identified by heap_fetches (a root-proven selector) or heap_descriptor_slots (a GPU-selected selector); no projected_numeric flag is needed. - createHandleFromHeap(slot) is annotated Texture1D { 1, 1033 } and textureLoad.f32 reads mip 0 at the VGPR coordinate, writing the three integer channels. - Four-channel loads, other dimensions, missing UNORM or an unmatched descriptor keep refusing. Observed on the captured MS with the exact profile layout: - before: native compute +0x700: unsupported mesh instruction or EXEC state: image_load - now: native compute +0x69c: unbound numeric SGPR s57 The capture reads descriptor word 1 numerically at +0x69c (s_bfe_u32 s22, s57, 0x2001e) to build the image coordinate. After #3754's correction the words stay symbolic, which is the accurate refusal: this branch needs a contract that supplies the real V# field bits before the +0x700 image is reachable. The source-built fixtures use a constant coordinate and cover the translation itself; the earlier +0x7c0 observation belonged to the slot-materialising draft and no longer applies. tests/native_direct_mesh_check.py adds mesh-image-full-descriptor (root selector), mesh-image-full-descriptor-root/-gpu, the four-channel and 2D controls, and keeps the symbolic descriptor-word refusals. Verified: - cmake --build --preset release --target compile_dxil - python -B tests/native_direct_mesh_check.py : exit 0, "mesh allocation, indexed outputs, group exchange and negative controls passed" - ctest --preset release --no-tests=error -R '^native_direct': 2/2 passed - real capture: native compute +0x69c: unbound numeric SGPR s57 Refs #3497 --- docs/experiments/native-mesh-image-load.md | 65 +++++++++++++++++++++ src/gfx1013_direct_mesh.inl | 49 ++++++++++++++++ tests/native_direct_mesh_check.py | 66 ++++++++++++++++++---- 3 files changed, 168 insertions(+), 12 deletions(-) create mode 100644 docs/experiments/native-mesh-image-load.md diff --git a/docs/experiments/native-mesh-image-load.md b/docs/experiments/native-mesh-image-load.md new file mode 100644 index 0000000000..d714cc5ade --- /dev/null +++ b/docs/experiments/native-mesh-image-load.md @@ -0,0 +1,65 @@ +# Mesh image_load through a full table descriptor + +The slot 57 capture `req_72e1909e13df6f66.m57` reaches `+0x700` after the +eight-dword heap descriptor load of +[native-mesh-heap-descriptor.md](native-mesh-heap-descriptor.md): + + image_load v[19:21], v11, s[56:63] dmask:0x7 dim:SQ_RSRC_IMG_1D unorm + +The descriptor is a complete guest V# read from the resource heap, not a +texture heap slot-map record, so the existing image branch (which requires +`layout.texture_heap_slot_map`) refused it. + +## Lowering + +A mesh image branch now handles the full-V# form when +`!layout.texture_heap_slot_map`: + +- the instruction must be an `image_load` (op 0) with `dim 1D` (0), + `dmask 0x7`, `unorm` set, no LWE/TFE/R128/reserved bits, no cache-policy + or descriptor base bits in word 1, a destination inside the VGPR range and + eight descriptor words in range; +- the descriptor symbol must be an `indexed_descriptor` of the resource heap at + offset 0 whose eight words share its fetch pc and offsets 0, 4, ..., 28. The + fetch must be recorded by `heap_fetches` or `heap_descriptor_slots`; the + words stay symbolic and an overwritten word keeps refusing; +- the slot comes from the fetch: a root-proven selector uses the same + `heap_fetches` guard as the typed path, records a + `mesh_heap_reads` entry and takes `and(root, mask)`; a GPU-selected fetch + uses the `bytes >> 5` slot recorded by the eight-dword load; +- the load binds `createHandleFromHeap(slot)` as a Texture1D + (`annotateHandle { 1, 1033 }`) and issues `textureLoad.f32` at mip 0 with + the VGPR coordinate, writing the three integer channels. + +Four-channel loads, other dimensions, missing UNORM, a mismatched coordinate or +an unmatched descriptor still refuse with `unsupported mesh image load or +descriptor`. + +## Observed + +With #3754's corrected head the capture refuses at `+0x69c: unbound numeric +SGPR s57`: `s_bfe_u32 s22, s57, 0x2001e` reads descriptor word 1 to build the +image coordinate. The full-V# branch is covered by source-built fixtures with +a constant coordinate; reaching `+0x700` needs a contract that supplies the +real V# field bits. + +## Fixture + +[tests/native_direct_mesh_check.py](../../tests/native_direct_mesh_check.py) +adds `mesh-image-full-descriptor`: an eight-dword heap fetch behind a masked +root selector drives the 1D UNORM load, and the IR must hold +`createHandleFromHeap`, one `textureLoad.f32` at mip 0 and the three +extracted channels exported through POS0.x. `mesh-image-full-descriptor-root` +and `-gpu` cover the root-proven and GPU-selected fetch paths without a slot +map. `mesh-image-unsupported-dimension` flips the dimension to 2D and must +refuse; `mesh-image-four-channel-without-map` is the dmask-15 control. + +Observed on the captured MS with the v5 profile layout: the `+0x700` +`image_load` refusal is gone. The next refusal is +`+0x7c0: unproven mesh entry register 287`, the full `v31` read after the +`v_fma_mixlo_f16` / `v_fma_mixhi_f16` pair. + +**Reproduce** with +`ctest --preset release --no-tests=error -R '^native_direct'` and +`ctest --preset release --no-tests=error -R '^native_fixed_mesh57_warp$'`. + diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index f94c6b76cb..0d06d0399d 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -1566,6 +1566,55 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout alu.write(dst,ir.value("bitcast float "+value+" to i32")); if (!full_exec) partial_writes.insert(dst); } + } else if (i.enc==Encoding::Image && i.op==0 && !layout.texture_heap_slot_map && + (full_exec || exec_skip)) { + // A full V# fetched from the resource heap drives one 1D UNORM load + // of three channels at a VGPR coordinate. The runtime descriptor + // heap slot holds the guest texture descriptor, so this needs no + // slot map; the eight-dword fetch above recorded the slot. + const unsigned dim=(i.a>>3)&7, mask=(i.a>>8)&15; + const auto base=((i.b>>16)&31)*4; + const auto sym=state[base]; + if (dim!=0 || mask!=7 || !(i.a&0x1000) || (i.a&0x3c040) || (i.b&0xffe00000u) || + (i.b&0x3c000000u) || base+8>106 || i.dst>252 || + sym.type!=Symbol::Type::indexed_descriptor || sym.value!=compute_resource_heap || + sym.offset || + (!heap_fetches.count(sym.definition) && !heap_descriptor_slots.count(sym.definition))) + refuse(pc,"unsupported mesh image load or descriptor"); + for (unsigned j=1;j<8;++j) { + auto expected=sym; + expected.offset=4*j; + if (!(expected==state[base+j])) refuse(pc,"overwritten mesh texture descriptor"); + } + string slot; + const auto fetch=heap_fetches.find(sym.definition); + if (fetch!=heap_fetches.end()) { + const auto &guard=fetch->second; + const auto entry=std::find_if(root_values.begin(),root_values.end(),[&](const auto &x) { + return x.second.param==guard.param && x.second.dword==guard.dword && + !x.second.shift && x.second.mask==~0u; + }); + if (entry==root_values.end()) refuse(pc,"missing mesh heap selector"); + emitter.result.mesh_heap_reads.push_back({guard.param,guard.dword,guard.mask}); + slot=ir.binary("and",entry->first,to_string(guard.mask)); + } else { + const auto stored=heap_descriptor_slots.find(sym.definition); + if (stored==heap_descriptor_slots.end()) + refuse(pc,"mesh image load lacks a heap descriptor fetch"); + slot=stored->second; + } + ir.features|=0x40000000; + const auto handle=ir.heap_handle(slot,1,1033); + const auto x=alu.read(256+(i.b&255)); + const auto load=ir.invoke("%dx.types.ResRet.f32","textureLoad.f32",66, + {{"%dx.types.Handle",handle},{"i32","0"},{"i32",x},{"i32","undef"},{"i32","undef"}, + {"i32","undef"},{"i32","undef"},{"i32","undef"}},"nounwind readonly"); + for (unsigned j=0;j<3;++j) { + const auto value=ir.value("extractvalue %dx.types.ResRet.f32 "+load+", "+to_string(j)); + const auto dst=256+i.dst+j; + alu.write(dst,ir.value("bitcast float "+value+" to i32")); + if (!full_exec) partial_writes.insert(dst); + } } else if (op.form==gfx1013::Form::mtbuf && (full_exec || exec_skip)) { const auto base=((i.b>>16)&31)*4; const auto low=state[base]; diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index af1d2a868f..dfd418ca80 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -734,6 +734,11 @@ def skip_load(body, seed=True): texture_numeric = [0x9394ff21, 0x4000c, 0x7e020214] # v1 = field from word 1 texture_export = program.copy() texture_export[7] = 0x7e02030a # pass the red float to POS0.x + texture_gpu = [ + 0xbe9e0317, 0xbe9f0380, + 0x8f148515, + 0xf40c080f, 0x28000000, + ] # The eight words stay symbolic: without a contract a descriptor word # has no numeric value, for word 1 and word 5 alike. run('mesh-descriptor-word-1', texture_fetch + texture_numeric + texture_export, @@ -741,21 +746,24 @@ def skip_load(body, seed=True): run('mesh-descriptor-word-5', texture_fetch + [0x9394ff25, 0x4000c, 0x7e020214] + texture_export, 'unbound numeric SGPR s37') - # An image consumer needs the slot map even with a zero coordinate, so - # the descriptor-word read cannot refuse before the image does. - run('mesh-texture-heap-without-map', + # A 1D UNORM three-channel image uses the full V# consumer, with a root + # or GPU-selected fetch, without the slot map. Four channels stay out. + texture_load3 = [0xf0001700, 0x00080a01] # image_load 1D v[10:13] at v1, dmask 0x7 + text = run('mesh-image-full-descriptor-root', + texture_fetch + texture_zero + texture_load3 + texture_export) + assert 'createHandleFromHeap' in text and 'textureLoad.f32' in text, text + text = run('mesh-image-full-descriptor-gpu', + texture_gpu + texture_zero + texture_load3 + texture_export) + assert 'createHandleFromHeap' in text and 'textureLoad.f32' in text, text + run('mesh-image-four-channel-without-map', texture_fetch + texture_zero + texture_load + texture_export, - 'unsupported mesh instruction or EXEC state: image_load') + 'unsupported mesh image load or descriptor') # The unmasked selector reaches the GPU-selected branch through the - # proven 32-byte shift; it still needs the remapped view. - texture_gpu = [ - 0xbe9e0317, 0xbe9f0380, - 0x8f148515, - 0xf40c080f, 0x28000000, - ] + # proven 32-byte shift; its four-channel load stays outside the full-V# + # consumer and still needs the remapped view. run('mesh-texture-heap-gpu-without-map', texture_gpu + texture_zero + texture_load + texture_export, - 'unsupported mesh instruction or EXEC state: image_load') + 'unsupported mesh image load or descriptor') with layout.open('a') as meta: meta.write('\ntexture_heap_slot_map') texture_mapped = texture_fetch + texture_numeric + texture_load @@ -775,6 +783,40 @@ def skip_load(body, seed=True): run('mesh-texture-heap-overwritten', texture_mapped[:7] + [0xbea70380] + texture_mapped[7:] + texture_export, 'overwritten mesh texture heap descriptor') + # A full V# fetched from the resource heap drives a 1D UNORM load of + # three channels without the slot map: createHandleFromHeap selects the + # guest descriptor and textureLoad reads it at the VGPR coordinate. + saved_layout = layout.read_text() + layout.write_text('mesh1 128 3 1 2 128 64\nconstants 21 0 1\nresource_heap 23\nvalidate_uint_heap_reads') + full_image = [ + 0xbe9e0317, 0xbe9f0380, # heap base and zero high word + 0x8715ff15, 31, # mask the root selector + 0x8f158515, # s21 = s21 << 5 + 0xf40c080f, 0x2a000000, # s_load_dwordx8 s[32:39], s[30:31], s21 + 0x7e160280, # v11 = 0 + 0xf0001700, 0x0008130b, # image_load v[19:21], v11, s[32:39] dmask:0x7 1D unorm + ] + image_export = program.copy() + image_export[5] = 0x7e020313 # v_mov_b32 v1, v19 + image_export[6] = 0x7e040314 # v_mov_b32 v2, v20 + text = run('mesh-image-full-descriptor', full_image + image_export) + assert 'createHandleFromHeap' in text, text + loaded = re.search(r'(?P%[\w.]+) = call %dx\.types\.ResRet\.f32 @dx\.op\.textureLoad\.f32' + r'\(i32 66, %dx\.types\.Handle %[\w.]+, i32 0, i32 (?:%[\w.]+|-?\d+)', text) + assert loaded, text + first = re.search(rf'(?P%[\w.]+) = extractvalue %dx\.types\.ResRet\.f32 ' + rf'{re.escape(loaded["load"])}, 0\n\s*' + rf'(?P%[\w.]+) = bitcast float (?P=value) to i32\n', text) + assert first, text + assert_position_x(text, rf'bitcast float {re.escape(first["value"])} to i32') + for channel in (1, 2): + assert re.search(rf'= extractvalue %dx\.types\.ResRet\.f32 ' + rf'{re.escape(loaded["load"])}, {channel}\n', text), text + unsupported_dim = full_image.copy() + unsupported_dim[-2] = 0xf0001708 # dim 2D stays refused + run('mesh-image-unsupported-dimension', unsupported_dim + image_export, + 'unsupported mesh image load or descriptor') + layout.write_text(saved_layout) half_frontend = [0xcc210014, 242 | (242 << 9) | (242 << 18)] # v_fma_mixlo_f16 v20, 1, 1, 1 half_pack = [0xd711001a, 276 | (276 << 9)] # pack the defined low half of v20 twice text = run('mesh-pack-from-defined-half',half_frontend+half_pack+program) @@ -804,7 +846,7 @@ def skip_load(body, seed=True): 'formatted mesh load lacks an R32_UINT resource heap contract') run('gpu-heap-descriptor-x8-image', selected_x8 + [0x7e020280, 0xf0001f00, 0x00080a01] + texture_export, - 'unsupported mesh instruction or EXEC state: image_load') + 'unsupported mesh image load or descriptor') run('gpu-heap-descriptor-word-1', selected_x8 + [0x9394ff21, 0x4000c, 0x7e020214] + exported, 'unbound numeric SGPR s33')