shader: refuse mesh VGPRs written under a narrowed EXEC and read after the count exchange #3422
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3422"
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 Leyukaka on 2026-11-29T00:31:26Z.
Change
The count-exchange matcher in
lower_meshaccepts a narrowed incoming EXEC and then setsfull_exec=true, but it leftpartial_writesas it was. A VGPR first written under the narrowed EXEC therefore kept its narrowed definition after the exchange, and a vertex export after the exchange read it for every vertex up to the exchanged count.This change adds, after
full_exec=true; ...in the matcher (src/gfx1013_direct_mesh.inl:446-447):This is the same pair the explicit
s_mov_b64 exec, -1(0xbefe04c1) reset runs at:900-901. The exchange consumes its own trailingbefe04c1inside the matcher, so that reset never ran there.partial_writesonly holds registers with no prior full value (:1106-1111merges a partial write over an existing value with a lane select and removes it from the set), so only VGPRs first defined under a narrowed EXEC are invalidated. A later read of one raises the existing diagnosticgraphics register undefined on an incoming path: <r>(src/gfx1013_direct_compute.inl:113).Trade-off: the rule ignores the vertex count. When the count equals the writer bound, every exported lane executed the write and the translated value would be correct, but that case is now refused too. This is conservative and fails closed. A later change could prove the
min(count, bound)relation and accept that case.Tests (
tests/native_direct_mesh_check.py): two probes write v10 withv_cndmask_b32underv_cmpx_gt_u32 s23, v0(threads 0..2), run the unchanged count exchange, then export v10 as PARAM0.count-exceeds-writer-bounduses vertex count 4,count-equals-writer-bounduses 3. Both assert a nonzero exit, a stderr ending ingraphics register undefined on an incoming path: 266(256 + 10 = v10) and no DXIL file.run()is split intocompile_mesh()andrun()with the same behavior.Refs #2413, #3416 (last claimed item; the control showed the count-4 case translating, so this adds the refusal as well).
Verification
Base
main51472392, release build.ctest --test-dir out\build\release --no-tests=error --output-on-failure -V -R "^native_direct_mesh$"passed and printedcount-exceeds-writer-bound: translatedandcount-equals-writer-bound: translated.dxc -dumpbinof the count-4 probe's DXIL: v10 isselect i1 %t48, i32 1065353216, i32 0computed for every thread, the cmpx guard (icmp ult i32 %t0, %t27) is never used to merge it, and the PARAM0 export is guarded only byicmp ult i32 %t0, %t53where%t53is the exchanged count (4). Vertex 3 exports 0.0. In the guest, lane 3 skipped thev_cndmask_b32, so its v10 holds a value the guest never wrote..inl), the count-4 probe compiles (exit 0, 4177 bytes) andnative_direct_meshfails withAssertionError: ('count-exceeds-writer-bound', ...). Main's.inlwith main's test file passes.-R "native_direct_mesh|native_compile_dxil_refusals|native_fixed_mesh57.*"(22 tests): same results with the fix and with main's.inl, exceptnative_direct_mesh(passes with the fix, fails on main's.inlas above).native_fixed_mesh57_waterfall_fine_hardwarefails in both withnative slot57 mesh efb95ca628778f2c refused: profile input bytes differ.ctest --test-dir out/build/release --no-tests=error -R meshwith the fix (170 tests): 167 pass, 1 fails, 2 skipped.native_fixed_mesh57_waterfall_fine_hardwarefails withprofile input bytes differ(pre-existing, also fails on main);mesh_two_exits_hardwareandmesh_two_exits_warpskip (requires LLVM 15 with AMDGPU). No existing accepted fixture reads such a register across the exchange.Evidence and follow-up
Not covered:
min(count, bound)relation that would let the count == bound case translate.:897-903) also callsexport_limit.clear()(:899); the matcher still does not. Not examined.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-29T08:38:28Z.
Review: COMMENTED
Reviewed
0ceb1bcdd71393c48e9d090288165c23a2014334:src/gfx1013_direct_mesh.inl: clears allpartial_writesregisters inaluand emptiespartial_writeswhen restoringfull_exec = trueon mesh allocation/exchange, preventing VGPRs written under a narrowed EXEC from remaining valid after EXEC is restored.tests/native_direct_mesh_check.py: addscount-exceeds-writer-boundandcount-equals-writer-boundnegative controls verifying both refuse withgraphics register undefined on an incoming path: 266.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
0ceb1bcdd71393c48e9d090288165c23a2014334:ctest --preset dev -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure: 1/1 passed (1.14s)ctest --preset release -R '^native_direct_mesh$' --parallel 2 --no-tests=error --output-on-failure: 1/1 passed (1.18s)AI-assisted; commands listed were executed locally.