perf(shader): experiment with fixed mesh output limits and index initialization #469
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!469
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-469"
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?
@tommiehansen on GitHub · 2026-12-04 14:38 UTC · original
tommiehansen:codex/mesh-output-counts→main· +335 −45 · 6 files · 9 commits · openWhy
Mesh shaders with small proven output counts can reserve storage for much larger outputs and initialize indices that are subsequently overwritten. On RDNA, declared output maxima may constrain export occupancy.
What changes
Two independent modes: VICTORY_MESH_OPT=1 uses a proven entry-block GS_ALLOC_REQ/reaching constant M0 to update counts, metadata, PSV0, export guards and connectivity together; mode 2 skips redundant index initialization only when a straight-line unmasked export covers every declared primitive. Mode 3 combines them; mode 0 remains default. Unproven paths fall back. Translator version and mode participate in cache identity.
Benchmark results
Historical synthetic fixture (not physical mesh time):
Both modes increase CPU translation time on this small fixture except init-only. Twelve production mesh variants and one pixel shader passed static DXIL→SPIR-V validation; no verified physical mesh speedup. Earlier audit.
Why this should be merged
Eliminate demonstrably redundant output reservation/initialization under proven conditions; the potential AMD occupancy benefit still requires representative physical measurements. Keep opt-in and review the two modes independently.
Validation
Current 755d41d CI: Linux full tests, Windows focused debug/release, production compilation and mesh translation variants passed. Full Windows suite retains the unchanged-main descriptor PSO failure (control).
Compatibility and dependencies
No HWRT dependency; overlaps lowering/cache with #467 and other shader changes. Separate from literal lane-count/NGG work; retain native AMD execution, exact output and occupancy/timing gates.
Previous detailed description, historical measurements and checklist.
@Kal0s-design on GitHub · 2026-12-04 16:54 UTC · original
Checked
0ddf76cnatively on Windows (x86_64-pc-windows-msvc, not Wine) on one NVIDIA desktop card and on WARP, with VICTORY_D3D12_DEBUG=1 and the DXIL validator from dxil.dll. No AMD card here, so nothing about occupancy or frame time, only whether the output is legal and draws the same.Off by default
VICTORY_MESH_OPTis read once and anything other than 0 to 3 falls back to 0 (lower.rs:403-414). With mode 0,allocationisNoneand the init skip can't fire (lower.rs:7365-7391), so the mesh path is the same as on the merge base. I hashed every DXIL container the victory-shader lib tests produce (local hook inShader::finish, not pushed) on the merge base0fd7614and on this PR with the switch unset. All 834 containers produced by tests that exist on both sides came out byte-identical. The only differences come from the new tests and fromedge_flagged_triangles_draw_as_unflagged_ones, which the PR rewrote, and the six programs that test drew on main still come out with the same hashes fromprimitive_export_indices_drop_the_edge_flagsand other tests on the PR.Modes 1 to 3 on the devices
I wrote a local test (not pushed) that runs the synthetic triangle in all four modes, culled and not, with three prefixes: the PR's 3v/1p allocation, a 3v/2p allocation, and no allocation. For each it runs the DXIL validator, creates the mesh PSO and draws on both adapters, then drains the info queue after the PSO and after the draw. All 24 cases per adapter (3 prefixes x 4 modes x culled or not) validated, the validator's hash matched ours, the PSOs were created, the draws came out right (256/256 lit, or 0 for the culled triangle), and the info queue stayed empty on both the NVIDIA card and WARP. The PSV0 limits were 3/1 and 3/2 in the count modes and 32/32 otherwise, and the no-allocation program stayed 32/32 in every mode. The DXIL metadata takes the same reduced numbers (shader.rs:1086-1096 reads
self.mesh), and the validator accepted all of them. The PR's own device testedge_flagged_triangles_draw_as_unflagged_onesalso passes on both adapters under the debug layer.On the D3D12 limits, mode 1 only ever lowers the maxima (lower.rs:7369-7371 keeps a proven count only if it's at or below the declared and lane-limited one), and the 32 KiB check runs before that (lower.rs:7350-7364), so the limits can't go up.
setMeshOutputCountsis still a single call in the entry block, before any output write (lower.rs:7398-7399). Vertex and primitive exports past the new counts are still guarded by the samemax_verticesandmax_primitives(lower.rs:18554-18576, 18719-18731), so with 3/1 only lanes 0-2 write vertices and only lane 0 writes a primitive.For the init skip I tried to break it. It needs a single block (
exits == [End]) with an unguarded primitive export andmax_primitives <= threads(lower.rs:7383-7391). Every primitive below the count then has a lane that writes it, since the export is only guarded byflat < max_primitives. Writing EXEC with a scalar op (s_mov_b32 exec_lo, 1ors_and_b32 exec_lo, ...) between the request and the export can't slip through, because the translator refuses those programs in every mode ("a constant lane mask", "an opaque lane mask"). wave64 with 64 threads skips init as expected. With 16 threads and a 32/32 declaration it keeps init in mode 2 and only skips in mode 3, where the count is down to 1. I didn't find a case where an index is left unwritten.Some things to look at
TRANSLATOR_VERSIONgoes from 20 to 23 (lib.rs:30), one step per commit. The comment above it (lib.rs:22-29) says to bump only when a translation changes. Mode 0 output is identical, and the mode is already in the key (shader_cache.rs:133), so the bump just throws away everyone's cached translations and pipeline library (pipeline/known.rs:591-593 hashes the same key) for nothing. If you keep it, one step would do.edge_flagged_triangles_draw_as_unflagged_onesnow always uses the allocation prefix (mod.rs:2929-2940), so the program without thes_sendmsgthat main drew is no longer drawn there. Mode 0 DXIL for the two differs (2164 vs 2168 bytes here), so one plain case could stay.VICTORY_MESH_OPT=3for the whole run changes nothing in the existing tests. The mesh,emit::tests,ioandnativetests give byte-identical output with it set and unset, because the only programs with a provable allocation are the PR's own fixtures, and those use the thread-local override.translated_mesh_shaders_draw_as_pc_onesskips without the console compiler, so I couldn't check how many real title mesh shadersfixed_mesh_countswould actually prove.victory-shader lib tests (release, two threads): 419 passed and 1 failed on the merge base, 422 passed and 1 failed on the PR, not counting my two local tests. The failure is
emit::size_tests::a_reused_descriptor_register_read_only_behind_its_flagon both sides, which fails on WARP here anyway. WithVICTORY_MESH_OPT=3set, theemit::tests,io,nativeandmeshfiltered runs all pass. victory-gpu lib on the PR: 340 passed, 4 failed (the twoindirect::host_list_*tests plusa_mesh_pipeline_loads_from_the_libraryanddepth_bounds_pipeline_loads_and_filters_draws), the same four fail on the merge base here (it also had onewatch::failure that passed on the PR, unrelated).descriptor::tests::views_die_with_their_resourcecrashes the process on both sides here, so I skipped it.a_mesh_pipeline_loads_from_the_librarycompiles its shaders with the PC dxc, so it doesn't go through this code.AI-assisted: yes
@Xough on GitHub · 2026-12-04 21:43 UTC · original
Tested on an RX 6700 XT (12 GB, RDNA 2), Ryzen 9 7900X, CachyOS, ray tracing off, preset high, FSR 4.1 performance, no frame generation, 1920x1080 output. Built-in benchmark (
VICTORY_BENCH=nort, 3 min each, first 60 s excluded), this PR merged on top of main. A warm-up run came first, so the translation cache was rebuilt before measuring.VICTORY_MESH_OPTNo gain in the real title on this card; mode 3 is about 0.5 fps below mode 0, close to run-to-run noise (about 0.3-0.5 fps here). I only measured frame rates, not rendering correctness. The GPU frame here is spread over thousands of small dispatches and about 575 mesh dispatches per frame, so mesh occupancy may simply not be the limiter on this GPU.
shader: experiment with fixed mesh output limits and index initializationto perf(shader): experiment with fixed mesh output limits and index initialization@tommiehansen on GitHub · 2026-12-05 10:19 UTC · original
Thanks @Kal0s-design for the cache and fixture findings. 9469e2a retains translator version 20, namespaces only nonzero mesh modes and includes no-allocation and 3v/2p cases. All 12 production mesh variants and the pixel shader passed static Vulkan conversion/validation; actual Vulkan mesh execution remains unverified. Thanks also @Xough for the neutral RDNA2 measurements — no FPS gain is claimed.
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.