Repository navigation
shader: read GPU-selected mesh heap buffers through view tokens - #3619
Conversation
A slot 57 mesh program may load a buffer descriptor from the resource heap at a byte offset chosen by GPU data (a dword read from a root-table buffer SRV, shifted left by 5). With the opt-in `.mslayout` keyword `heap_tokens` (next to `validate_uint_heap_reads`) the translator reads the view token at that address instead of trusting the title's value: magic, view id and a per-id kind (16: one-channel 32-bit typed buffer). A valid token reads ResourceDescriptorHeap[base + id]; anything else reads the null slot and the first lane counts a miss. base, count and null come from cbuffer b1. Translator only: native preparation does not set the option and refuses a program with token reads by name. Refs R0Y00#2413, R0Y00#3023. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
The current head conflicts with the mesh frontend and binding metadata that landed in #3638. Please rebase the opt-in slot 57 heap_tokens work while preserving the existing slot 86 selector path and its controls. Please show the exact-head native_direct_mesh result for both the existing selector path and the new token accept/refuse cases. #3416 tracks this first-refusal family.
500b0cd to
5246f67
Compare
The token guard compared the kind word with heap_token_r32_uint_buffer (16). A view id can carry other kind bits as well, such as the raw-buffer bit from R0Y00#3631, so test (kind & 16) != 0 instead. The fixture checks the and/icmp ne pair and that no equality test against 16 remains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5246f67 to
c076b27
Compare
|
Rebased onto main
Mesh hardware tests on the Agility 1.620.2 runtime (RTX 3080 Ti, driver 610.47, debug layer on): 19/19 passed, including |
Leyukaka
left a comment
There was a problem hiding this comment.
Read at e4b126cc, which is c076b273 plus a merge of main; diff only. The token route is taken only with layout.heap_tokens (src/gfx1013_direct_mesh.inl:1101-1108), the root-constant route is unchanged, and the runtime refuses token reads until their binding exists (src/startup_stubs/native_mesh57.inl:405-407).
- NIT
src/gfx1013_direct_mesh.inl:122-124: withcount == 0,in_rangeis false, so the null slot is chosen correctly. However,clampedbecomescount - 1 = 0xffffffff, and the kind load reads byte0xfffffffcofkinds. A descriptor-bound view returns 0 for that read, but a root SRV has no bounds check. Selecting0instead ofcount - 1for an out-of-range id avoids depending on how the runtime follow-up bindskinds_srv.
Change
The slot 57 mesh frontend refuses a heap buffer read whose slot comes from GPU data:
mesh heap slot lacks masked root constant provenance. This is the largest C++ refusal by refusedDispatchMeshcalls in a 360 s native run (#3416). The program loads a dword from a root-table buffer SRV, shifts it left by 5, loads the descriptor at that heap byte offset and reads it withbuffer_load_format_x … idxen.With a new opt-in
.mslayoutkeyword,heap_tokens(next tovalidate_uint_heap_reads), the translator reads such a descriptor through its view token, as #3544 does for compute textures. It never uses the title's value as a slot. Per read:heap_entry_offsets(a value shifted left by 5 or more, the 32-byte alignment proof runtime: wire native slot 86 mesh bindings and direct DispatchMesh #3638 added for the slot 86 Texture1D map);0x56573258, word 1 view id) and the id's entry in a per-id kind table, and tests bit 16 (a one-channel 32-bit typed buffer). A bit test, so one view id can also carry other kind bits, such as the raw-buffer bit 0x20 from native: raw buffer loads through heap view tokens (#3023 stage 3, translator) #3631;id < countand(kind & 16) != 0, it readsResourceDescriptorHeap[base + id]as a typed U32 buffer. Otherwise it reads the null slot, and the first lane of the wave adds one to a miss counter.The runtime provides the token memory and kind table (raw SRVs), the miss counter (raw UAV) and
base,count,null(cbufferb1, kept apart fromb0so the root-constant layout is unchanged).compile_dxilprintsrequires_heap_tokens srv=… kinds_srv=… miss_uav=… words=b1 reads=N.Translator only: native preparation does not set the option and refuses such a program by name (
MS heap token reads are not bound yet). Binding is a follow-up. Refs #2413, #3416, #3023.texture_heap_slot_map) and the root-constant route are unchanged.prepare_native_mesh57block where this PR adds its 3-line refusal; whichever lands second needs a small rebase.Verification
Commit
c076b273(on maina0e126c2;native_direct_meshre-run there; the other runs below were at5246f670, which differs only in the doc paragraph) on Windows 10 22H2 (build 19045), Visual Studio 2026 (MSVC 19.52.37029), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7, DXC 1.9.2609.5. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047 (610.47), debug layer on.The three hardware failures are the same on
a0e126c2in the same tree (0% tests passed, 3 tests failed out of 3): the Windows 10 in-box runtime on this host. They pass on the Agility SDK runtime.Per-case
compile_dxilresults insidenative_direct_meshat5246f670(same code):typed-heap;token-root-route(heap_tokenson, no token views)overwritten-heap-wordmesh-texture-heap-slot-map-without-map,-unaligned,-wrong-dimension,-overwrittentoken,token-twice(reads=2),token-wave32token-no-contract,token-unvalidated,token-shift4,token-unshifted,token-raw-read,token-overwrittenMesh hardware tests on the Agility SDK runtime (a second tree configured with
-DOFFSCREEN_AGILITY_620_DIR=<Agility 1.620.2>; the Windows 10 in-box runtime rejectsms_6_6mesh shaders on this host, with or without this change):Evidence and follow-up
Fixtures are source-built gfx1013 words in
tests/native_direct_mesh_check.py(MIT). They check:and i32 kind, 16+icmp ne … 0, noicmp eq … 16),id < count,waveIsFirstLane+ atomic add, theb1load, a heap index that is aselectof base + id or null, and the token read atselector << 5;reads=2), a wave32 entry, and the unchanged root-constant route withheap_tokenson;On the captured programs behind the #3416 table (raw
.m57+.mslayout+.rootfrom a 360 s native run,compile_dxil <dxc dir> <cache> gfx1013-raw-ms <key>.m57 <out>),heap_tokensmoves the top two frommesh heap slot lacks masked root constant provenance(+0x2a0 / +0x2a8) tov_readfirstlane_b32(+0x470 / +0x474). The next three keep their refusals (+0x370, +0x46c, +0x70c) with and without the keyword. (Measured at500b0cda, before the rebase.)Follow-up (runtime, separate PR): bind the token memory, kind table, miss UAV and
b1words inprepare_native_mesh57, setheap_tokensthere, and add a hardware fixture with valid, wrong-magic, out-of-range-id and wrong-kind tokens (including an id with only the raw bit 0x20). On the title programs the next refusal after this one isv_readfirstlane_b32(#3416).Checklist
AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.
🤖 Generated with Claude Code