shader: fail closed on stale mesh lane masks and partial VGPRs #3450
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3450"
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-29T11:22:37Z.
Part of #3416.
Wrong translations on main
Three mesh programs are accepted and translated to DXIL that differs from the guest. All were measured with
compile_dxilon source-built fixtures, the DXIL read withdxc -dumpbin; nothing was run on a GPU. Fixture registers: v0 = lane, v1 = lane & 1, v2 = lane >> 1; v1 feeds position x. Line numbers aresrc/gfx1013_direct_mesh.inlate358cf5f.1. VGPR written under narrowed EXEC, read after EXEC widens
A VALU write under narrowed EXEC becomes
select(lane_active, new, before)only when the register is not already partial (:1162). A second write under a narrower EXEC, or in the other arm of an if/else, stays raw and the register stays inpartial_writes. Thes_or_b64/s_and_b64/s_andn2_b64handler with dst EXEC recomputeslane_activeand never touchespartial_writes, so a read after lanes are added takes the raw last value in every lane.s_or_b64 exec, exec, s[22:23],v_cmp_eq_u32 vcc, 2, v10s_andn2_b64 exec, s[22:23], exec, widened, readMeasured on
1a0120ba; not re-measured as DXIL one358cf5f, where the first commit with its clear disabled accepts the first case again (mutation below). Control: withs_mov_b64 exec, s[22:23]in place of thes_or_b64, the first case is refused (+0x38: graphics register undefined on an incoming path: 266). Inside ans_cbranch_execzlane-skip block the same sequence is refused at the EXEC write since #3443.2. Scalar ALU write to EXEC_LO / EXEC_HI outside a lane-skip block
Scalar writes to dst 126/127 are refused only inside an open skip (:868-875). Outside one, three handlers pass them to
alu.write:s_mulk_i32,s_addk_i32,s_mul_i32,s_add_u32,s_add_i32,s_max_u32,s_cselect_b32;s_bfe_u32,s_min_u32;s_pack_ll_b32_b16,s_pack_hh_b32_b16.The write only stores the register value;
after_graphics_write(:33-39) ignores 126/127, sofull_exec,lane_active,wave_active,exec_valueandpartial_writeskeep the old mask.Fixture (wave64): v10 = 3 under full EXEC,
v_cmpx_eq_u32 0, v2narrows to lanes 0-1, v10 = 1 there, the scalar write,v_cmp_eq_u32 vcc, 3, v10,s_mov_b64 exec, -1,v1 = vcc ? v1 : 5.s_max_u32 exec_lo, -1, 0,s_pack_ll_b32_b16 exec_lo, -1, -1s_max_u32 exec_hi, -1, 0,s_pack_hh_b32_b16 exec_hi, -1, -1The DXIL of each accepted case is the
s_nopcontrol plus three dead scalar instructions. Measured one358cf5fplus the first commit, which does not touch these handlers.3. Scalar ALU write to VCC_LO / VCC_HI
The same three handlers accept dst 106/107. The scalar word is stored in register 106,
after_graphics_writeclears only the VCC word facts, andgraphics_lane_mask(src/gfx1013_direct_compute.inl:2716) then returns that word as the per-lane bit.Fixture: VCC = 0,
s_pack_ll_b32_b16 vcc_lo, 5, 0,v1 = vcc ? v1 : 5.icmp ne i32 <word>, 0used as the predicate of every lane; vertex 1 position x 1.0A write to vcc_hi leaves the lane bit in 106 unchanged. Measured on
e358cf5fplus the first two commits.Change
All four commits touch
src/gfx1013_direct_mesh.inlandtests/native_direct_mesh_check.pyonly (+13 / +48).6c268218: in the EXEC-destinations_or_b64/s_and_b64/s_andn2_b64handler, unless the op can only narrow, every register inpartial_writesis written undefined and the set is cleared, ass_mov_b64 exec, -1already does. A later read refuses. Narrowing-only forms keep the set:s_and_b64with EXEC as either source,s_andn2_b64with EXEC as src0,s_or_b64 exec, exec, exec.21ccd56e: the three handlers of case 2 refuse dst 126/127 (mesh scalar write to EXEC).8ee5b5c6: the same handlers refuse dst 106/107 (mesh scalar write to VCC); adds thes_min_u32EXEC case.a87c6f7e: test only, pins thes_bfe_u32/s_min_u32VCC refusal.The dedicated EXEC and VCC paths (
v_cmp_*,v_cmpx_*,s_cselect_b64, the B64 mask ops,s_mov_b64) are unchanged.Tests and mutations
native_direct_meshcases, each refusal asserting a nonzero exit, the diagnostic with its offset, and no output file:nested-or-widen,else-arm-widen: the two rows of case 1,+0x38: graphics register undefined on an incoming path: 266.merged-or-widen: v10 first written under full EXEC, then the nested sequence; accepted, assertsselect i1.scalar-exec-{pack-ll-lo,pack-hh-hi,max-lo,max-hi,min-lo}:+0x2c: mesh scalar write to EXEC.scalar-exec-nop: same program withs_nop, accepted.scalar-vcc-{pack-ll-lo,max-hi,min-lo}:+0x20: mesh scalar write to VCC.Results:
ctest -R '^(native_direct_mesh|native_compile_dxil_refusals.*)$'2/2 on6c268218. On the heada87c6f7e,ctest -R '^(native_direct_mesh|native_compile_dxil_refusals.*|native_fixed_mesh57.*_warp)$'12/12; with thes_bfe_u32/s_min_u32VCC guard removed,native_direct_meshfails atscalar-vcc-min-lo.Mutations, each rebuilt and reverted:
6c268218nested-or-widenfails (accepted)6c268218s_or_b64with EXEC as src0 and any src1nested-or-widenfails6c2682181a0120ba)nested-or-widenfails6c268218s_andn2_b64exemption (on1a0120ba)21ccd56escalar-exec-max-lofails21ccd56edst==127changed todst==128therescalar-exec-max-hifails21ccd56escalar-exec-pack-ll-lofails8ee5b5c6s_bfe_u32/s_min_u32handlerscalar-exec-min-lofails8ee5b5c6dst==106scalar-vcc-max-hifails8ee5b5c6scalar-vcc-pack-ll-lofailsCorrect on main, now refused
v_cndmask_b32: main lowered these correctly,8ee5b5c6refuses them. No test depends on them.partial_writeswhen EXEC may widen is refused on a later read, including a single narrowed write over an undefined value. A single narrowed write over a defined value already becomes a select and leaves the set (merged-or-widen).s_and_b64of two non-EXEC masks that happens to narrow is treated as widening.No EXEC form that main translated correctly was found to be refused by
21ccd56e: none of the three handlers updated the lane state for dst 126/127.Not covered
s_and_b64ands_andn2_b64exemptions have no test; removing them only makes more programs refuse.mesh request has no entry layoutbefore this code runs.A select-based alternative for case 1 (merging the second write as
select(lane_active, new, before)too) was evaluated and not shipped: it still reads the raw value in the widened lanes when the earlier value had been cleared bys_mov_b64 exec, -1(lane 1 position x 1.0, guest 5.0), a case this change refuses.Base:
e358cf5f.git merge-tree --write-treeagainst main20bd1553is clean.