shader: read GPU-selected mesh heap buffers through view tokens #3619
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3619"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T15:37:10Z.
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 #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 #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
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T19:33:55Z.
Review: COMMENTED
The current head conflicts with the mesh frontend and binding metadata that landed in #3638. Please rebase the opt-in slot 57
heap_tokenswork while preserving the existing slot 86 selector path and its controls. Please show the exact-headnative_direct_meshresult for both the existing selector path and the new token accept/refuse cases. #3416 tracks this first-refusal family.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T19:51:12Z.
Rebased onto main
a0e126c2(#3638). New headc076b273.compile_dxilreport line and the result field. #3638'sheap_entry_offsetschecks the same thing as this PR's own set (a value shifted left by 5 or more), so the token route now uses it and the duplicate is gone. The slot 86 selector branch (texture_heap_slot_map) and the root-constant route are unchanged.(kind & 16) != 0, so one view id can also carry #3631's raw bit (0x20).native_direct_meshatc076b273: Passed (1/1). Per-casecompile_dxilresults from the same test at5246f670(same code;c076b273only changes the doc paragraph):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 1.620.2 runtime (RTX 3080 Ti, driver 610.47, debug layer on): 19/19 passed, including
startup_indirect_mesh_cache_{heap,texture_map,heap_wide,constants_wide}_hardware. On the in-box Windows 10 runtime,startup_indirect_mesh_cache_{heap,texture_map,heap_wide}_hardwarefail withserialize root failed (0x80070057), the same as on plaina0e126c2.Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T00:04:11Z.
Review: APPROVED
Read at
e4b126cc, which isc076b273plus a merge ofmain; diff only. The token route is taken only withlayout.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).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.