Shaders: narrow mesh output bounds from GS_ALLOC_REQ M0 analysis (#201) #1385
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1385
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1385"
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?
@Ctrl-Alt-Haze on GitHub · 2026-11-24 17:40 UTC · original
Ctrl-Alt-Haze:fix/mesh-gs-alloc-req-bounds→main· +1602 −39 · 3 files · 2 commits · openSummary
Fixes #201 (mesh shaders exceeding the 32,768 B DXIL output limit because declared
PSV0max_vertices/max_primitivesbounds remain at worst-case 256/256 instead of the provens_sendmsg(MSG_GS_ALLOC_REQ)M0allocation bounds).(Note: #586 has merge conflicts and touches 22 files; this PR is a focused 3-file implementation cleanly on
ffe310eb.)Changes
crates/victory-shader/src/emit/lower.rs:ScalarBoundfixpoint analysis +slice_range_val((m0 >> shift) & 0x3FF) acrosss_mov_b32,s_movk_i32,s_or_b32,s_lshl_b32,s_lshr_b32,s_and_b32,s_bfe_u32,s_min_u32,s_max_u32,s_add_*,s_sub_*,s_cselect_b32,s_cmov_b32/s_cmovk_i32, andPhijoins (with widening on loop phis).shader::Mesh.max_vertices/max_primitivesto the conservative max across alls_sendmsg(GS_ALLOC_REQ)sites only when every site is proven<= 256(clamped toms.max_vertices/ms.max_primitivesand256; left unchanged when 0 sites or any site is unproven).M0lowering forsetMeshOutputCounts(min(v, max_v), min(p, max_p))(inline at block-0GS_ALLOC_REQ, or pure-SOP materialization hoisted to block-0 end for lane-0 guardedGS_ALLOC_REQ), plusmesh_export_limits(MeshExportLimit::Const/Dynamic) somesh_export_guardchecksthreads > emitted_limiteven whenmesh.max_*stays unnarrowed.s_cmov_b32/s_cmovk_i32lowering insop(). Zerounsafeblocks added.crates/victory-shader/src/emit/mod.rs&crates/victory-shader/src/emit/mesh_tests.rs:dxil.dllrejection without narrowing vs DXIL validation + RTX 5070 Ti & WARP Mesh Shader PSO +DispatchMeshexecution for literalM0,s_min_u32-bounded dynamicM0, lane-0 guarded dynamicM0,s_and_b32/s_bfe_u32/s_cselect_b32/Phinarrowing, mixed unbounded-vertex + small-constant-primitive export guarding, and negative soundness controls (unboundedM0,& 0x3FF, unboundedPhi, clamping, multi-site max, fail-open when any site is unproven).Verification
32.0.16.2135), WARP (VICTORY_WARP=1/VICTORY_D3D12_WARP=1), Windows SDK10.0.26100.0dxil.dll, Rust1.98.1, baseffe310eb.cargo xtask policy:155 files okcargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedcargo test --workspace --locked:349 passed, 0 failed, 6 ignored(victory-shader127/1 ign)cargo test -p victory-shader --features host --locked(RTX 5070 Ti):127 passed, 0 failed, 1 ignoredVICTORY_WARP=1 cargo test -p victory-shader --features host --locked(WARP):127 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --features diagnostics --locked&VICTORY_D3D12_WARP=1:53 passed, 0 failed, 1 ignoredeachrustfmt --edition 2024 --checkon modified files: zero diffs onmesh_tests.rsand all added/modified lines inlower.rsandmod.rs.AI use: Written and verified locally with an AI coding swarm (
gemini-4-hydrogen-high), then independently audited and tested on RTX 5070 Ti + WARP.@Ctrl-Alt-Haze on GitHub · 2026-11-24 18:28 UTC · original
@catminou4 Thanks for reviewing and testing on macOS arm64!
@marquezinii on GitHub · 2026-11-24 18:48 UTC · original
Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at
9e77b5c.cargo test -p victory-shader --lib -- --test-threads=1 --nocapturegives 127 passed, 0 failed, 1 ignored. All sevenmesh_testspass, including the two that create a mesh PSO and draw (s_min_u32_dynamic_m0_narrows_below_32kb_and_creates_pso,guarded_lane0_dynamic_m0_materializes_and_creates_pso), on the hardware adapter and WARP.Not covered here: whether this clears the 53 programs from #201 that #459 left at 53. That needs the title's
shaders.rpf, and I don't have it. Atranslate --validatecount from someone with the pack would show how many of the 53 the M0 analysis proves.@Ctrl-Alt-Haze on GitHub · 2026-11-24 18:57 UTC · original
@marquezinii Thanks for verifying
9e77b5con your desktop RTX 5070 + WARP (including both live mesh PSO draw tests)!@Ctrl-Alt-Haze on GitHub · 2026-11-24 21:54 UTC · original
Rebased onto upstream
main(70564ae) at3e630d3cleanly (resolvedcrates/victory-shader/src/emit/mod.rs).Verified locally on Windows 11 x64 / NVIDIA GeForce RTX 5070 Ti + WARP:
cargo xtask policy: passed (175 files ok)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): passedvictory-shadertargeted mesh checks (mesh_tests,translated_mesh_shaders_draw_as_pc_ones): passedcargo test -p victory-shader --features host --locked(hardware):213 passed; 3 failed; 2 ignored(the 3 failures are pre-existing on cleanupstream/main70564aeon RTX 5070 Ti:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware)VICTORY_WARP=1 cargo test -p victory-shader --features host --locked:214 passed; 2 failed; 2 ignored(pre-existinggathers_at_a_level_match_the_hardware, pluspermutes_read_the_lane_named_and_zero_from_lanes_left_outwhich skips underVICTORY_WARP=1and passed on RTX hardware)cargo test -p victory-gpu --locked -- --test-threads=1:76 passed; 2 failed; 1 ignored(both failures are pre-existing on clean70564ae:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views)@Marvisak on GitHub · 2026-11-25 02:38 UTC · original · edited 2026-11-25 03:22 UTC
Automated triage for the maintainers.
Proposed close: no measured value. This adds about 1,100 lines to
crates/victory-shader/src/emit/lower.rs(ScalarBound,analyze_mesh_alloc, block-0 materialization) to narrowsetMeshOutputCountsfrom M0, aimed at the over-32 KiB mesh programs in #201. The author's owntranslate --validatecensus on the full shader pack, againstmain70564ae, shows the same counts before and after: 8,694 mesh programs validated, 71 over-limit failures, and no program gained or lost. The runtime approach to the allocation request is in #586. CI has not run on this head.On your reply: thank you for running the census and citing the M0 layout sources. With none of the 71 failures cleared, the analysis does not pay for its size, and closing it as you suggest is the right call. The M0 layout references would help in #586.
This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
@Ctrl-Alt-Haze on GitHub · 2026-11-25 03:07 UTC · original
Thanks for the detailed triage review. I ran the clean-room
victory translate --validatebefore/after census on a 1.0.2.1shaders.rpf(26,503containers /26,084programs) comparing70564aeagainst#1385(3e630d3):> 32768mesh validator failures70564ae)#1385(3e630d3)0gained,0lost across all 26,084 programs (counts only; no shader names or data included perdocs/asset-policy.md).Addressing your three points:
AMDGPU::SendMsg::ID_GS_ALLOC_REQ = 9in LLVM (SIDefines.h) and Mesa's NGG lowering (ac_nir_lower_ngg.c), which pack(num_verts) | (num_prims << 12)intoM0(GS_ALLOC_COUNT_MASK0x3FFfor the 10-bit 0..1023 RDNA2 count range vs0xFFF12-bit slot width;GS_ALLOC_PRIM_SHIFT = 12).emit_mesh_counts_block0_end):collect_block0_materializationrefusesPhis,EXECreads (s_and_saveexec, etc.),st.masks/st.highs, memory/descriptor loads, and any non-pure SOP ops, accepting only acyclicis_pure_32bit_sopALU ops rooted at entry inputs or block-0 definitions — so even whens_sendmsg(GS_ALLOC_REQ)itself sits inside a lane-0-guarded block, the hoisted scalar dependency slice is uniform and lane-independent.#201: The measurement above confirmsScalarBoundstatic SOPM0narrowing clears0 / 71of the> 32768mesh failures on70564ae. That means carrying ~1,100 lines of static interval analysis andM0materialization inlower.rsis not justified by the corpus data.#586: Runtimes_sendmsg(GS_ALLOC_REQ)lowering belongs with#586(uniform join + LDS staging), rather than staticScalarBoundmetadata narrowing.crates/victory-shader/src/emit/mesh_tests.rs.Since
#1385clears 0 real> 32 KiBmesh programs onshaders.rpf, I don't think it is worth merging as-is and am happy to close it rather than ask maintainers for more review cycles unless you see another use for it.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.