Skip to content

Shaders: lower numerical Wave32 mesh masks at uniform entry - #1759

Open
aycow wants to merge 3 commits into
Marvisak:mainfrom
aycow:shaders/mesh-wave32-70564ae
Open

aycow wants to merge 3 commits into
Marvisak:mainfrom
aycow:shaders/mesh-wave32-70564ae

Conversation

@aycow

@aycow aycow commented Nov 24, 2026 •

Copy link
Copy Markdown

Task SHADER-MESH-LANES-AMD. Upstream claim

Mesh shaders on main 70564ae reject the tracked Wave32 comparison mask in this fixture when a later instruction reads its numeric bits or population count. The original synthetic mesh fixture reproduces a lane mask read as data at byte offset 232 before pipeline creation. Its nonnumeric control translates. The older main ffe310e reproduces the same refusal.

Change

Materialize a tracked numerical Wave32 mask with a workgroup ballot indexed by flattened mesh thread ID. Each invocation clears a unique scratch dword. After a group synchronization it atomically contributes its logical lane bit to its virtual wave's first dword. A second synchronization makes the result visible before reads, and a third prevents scratch reuse until all reads finish. Scratch is separate from native LDS. The per-mesh capacity check includes declared LDS and uses the D3D12 28 KiB limit. The emitted pipeline metadata counts actual native LDS globals and ballot scratch.

The first materialization must occur in the once-reached native entry block and the current DXIL block must be group-uniform. The entry has no predecessors and a guard advances the uniform block only after its join. A previously materialized mask can be consumed after divergence. Unsupported masks, wider numerical waves, and over-capacity cases retain explicit refusals.

The mesh shader carries no required physical wave size. Shader Model 6.6 permits WaveSize on compute entry points, and current DXIL validation restricts this metadata to compute and node shaders. WaveSize specification · DXIL validator rules · D3D12 mesh limits

Reproduction

From the proposed head on Windows, point VICTORY_DXIL to the Windows SDK validator. Use Windows Graphics Tools and a 1.620.x Agility SDK for the native fixture.

$env:VICTORY_DXIL = 'C:\path\to\dxil.dll'
$env:VICTORY_MESH_MASK_TEST_SDK = 'C:\path\to\Agility\build\native\bin\x64'
cargo test --locked -p victory-shader --lib mesh_mask_tests -- --nocapture
foreach ($adapter in @('amd', 'nvidia', 'warp')) {
    $env:VICTORY_MESH_MASK_TEST_ADAPTER = $adapter
    cargo test --locked -p victory-shader --lib mesh_numeric_wave32_masks_control_two_triangles -- --ignored --nocapture --test-threads=1
    if ($LASTEXITCODE) { throw "mesh fixture failed on $adapter" }
}

Set the adapter list to the hardware available on the test machine. The fixture enables full GPU-based validation and checks the reported configuration itself. It builds original GFX10 shaders and verifies four independent raster regions. It exercises partial waves, nested EXEC branches, successive masks, a wrong-mask cull control, native LDS readback, declared but unused native LDS, and nonnumeric logical Wave64 controls.

To reproduce the main refusal in a disposable worktree, retain the test harness and restore only the two lowering files from upstream before running the positive translation test.

git worktree add --detach ../VIctory-mesh-stock-control HEAD
Push-Location ../VIctory-mesh-stock-control
git restore --source=70564ae -- crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/shader.rs
$env:CARGO_TARGET_DIR = "$env:TEMP/victory-mesh-stock-control-target"
cargo test --locked -p victory-shader --lib mesh_numeric_wave32_masks_translate_without_a_fixed_size -- --nocapture
Pop-Location

The numeric control should fail with the upstream refusal. Use a separate Cargo target directory for the candidate.

Validation

The independent reports ran exact 95ffced on Agility SDK 1.620.2 with full GPU-based validation. Both discrete adapters reported mesh tier 1, SM 6.6 and a 32–64 lane range.

Independent tester Adapter Driver Result
tumbubu Radeon RX 7900 XT (RDNA3) 32.0.31036.15 15 cases passed, zero debug-layer errors
Luislariosss Radeon RX 9060 XT (RDNA4) 32.0.32015.7029 15 cases passed, zero validator messages

Thank you to tumbubu and Luislariosss for the independent hardware runs. The RX 7900 XT report also included a passing Agility WARP run. The proposed head dc80215 ports this implementation to current main and adds the declared-but-unused LDS metadata correction and its sixteenth local case. The reports below distinguish the two exact revisions. RDNA3 report · RDNA4 report

  • Current-main implementation eac3a68 passed all 16 native cases on both AMD Radeon Graphics, driver 32.0.22042.1 with a 32–64 lane range, and Agility WARP with four lanes. Both devices reported mesh tier 1 and SM 6.6. All 128 pixel probes matched with full GPU-based validation and no D3D12 errors. The test exercised native LDS values after ballot scratch and the separate PSV test observed 256 bytes for scratch-only output when guest metadata declared 1,024 unused bytes.
  • The independent ffe310e integration with exact Shaders: one console wave sharing LDS runs in the console flow on 32-lane hosts #439 28aca3b required only fixture adaptation to pass its host Target and distinct tests for the integration. The integrated source passed all 16 native cases on AMD and WARP, plus Shaders: one console wave sharing LDS runs in the console flow on 32-lane hosts #439's original nested shared-atomic regression on AMD. Every group size from 1 to 128 emitted and passed SDK DXIL validation for the synthetic numerical Wave32 and nonnumeric Wave64 programs. Their emitted DXIL was identical across targets 4–4, 32–32, 32–64, and 64–64. The test's numeric Wave64 variant remained refused at each size. #439
  • Mesh tier 1 is required for native raster execution. The NVIDIA adapter was absent from this laptop's DXGI inventory. The actual physical wave width chosen for the AMD mesh shader was unmeasured. Shaders, CLI: name a host without mesh shaders in the pipeline census #1676 tracks reporting on devices without mesh support. #1676
  • Exact proposed head dc80215 passed the default-device workspace run with DXC and dxil.dll 1.9.2609.5: 479 passed, zero failed, and 9 ignored. Strict workspace Clippy and the 176-file asset policy passed. A separate WARP run with SDK 1.7 reported four failures that also reproduce on stock 70564ae: rectangle and signature PSV validation, a gather comparison, and a permute fixture whose Wave32 PSO was unavailable under WARP.

Performance and remaining evidence

On the measured AMD Radeon Graphics, driver 32.0.22042.1, the ffe310e-based 2,048-group synthetic dispatch with 128 threads per group took a median 198.61, 199.26, 251.59, and 341.98 µs with zero through three distinct ballots. These are medians across three independent process medians. The #439 integration's smaller workload medians in the same order were 4.150, 4.630, 5.455, and 6.995 µs at 32 groups and 34.930, 35.170, 45.315, and 60.140 µs at 256 groups. These intervals include raster work and surrounding mask arithmetic. Validation and the debug layer were disabled, and PSO creation and readback fall outside the timestamp region. Benchmark methodology

The RX 7900 XT control reported less than 1% overhead for three ballots relative to zero ballots. The integrated AMD device showed substantially larger overhead in the same 2,048-group workload. Values are median GPU microseconds per synthetic dispatch with validation disabled.

Threads per group RX 7900 XT, zero → three Integrated AMD, zero → three
32 33.51 → 33.74 (+0.7%) 56.36 → 101.58 (+80%)
64 66.74 → 67.21 (+0.7%) 112.03 → 172.17 (+54%)
128 133.33 → 133.86 (+0.4%) 198.61 → 341.98 (+72%)

The intervals include mask computation, shared-memory communication and rasterization. The three group synchronizations per mask and scratch usage of one dword per thread are part of the implementation. Timing varies by device and clock state. The separate scratch-bank experiment had mixed results. RDNA3 timings · Integrated AMD timings

A later NVIDIA regression run at the approved head dc80215 passed all 16 synthetic cases on a GeForce RTX 5070 Laptop GPU (driver 581.91, SM 6.6, 32-lane waves, mesh tier 1) with full GPU-based validation. This was a local run. A second NVIDIA tester result and RDNA4 timing remain open. NVIDIA validation Normal-title geometry and performance remain unverified. For a matched authorized title test, hold adapter, scene, diagnostics and warmed cache state fixed. Share aggregate numerical-mask refusals, admitted mesh dispatches and group sizes, submission GPU time, emitted primitive counts and final-frame geometry coverage. Tester coordination

On exact dc80215, tumbubu independently passed all 16 synthetic cases on the RX 7900 XT and the WARP control with full GPU-based validation. In the validation-off benchmark, three numerical ballots added 0.25, 0.44, and 0.53 µs per 2,048-group dispatch for 32-, 64-, and 128-thread groups on that card. Three runs used per-run medians. The integrated AMD measurements earlier in this description are from a separate adapter. Exact-head RDNA3 report

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

@Luislariosss Thanks for validating the 15-case RDNA4 fixture. When convenient on an idle machine, could you run the validation-off mesh_wave32_ballot_gpu_cost benchmark on this PR head and share the 32-, 64- and 128-thread GPU medians? The PR records the RDNA3 and integrated AMD results for comparison.

An independent NVIDIA regression check on dc80215 would also help. The generated mesh_numeric_wave32_masks_control_two_triangles fixture enables full GPU-based validation. Use VICTORY_MESH_MASK_TEST_ADAPTER=nvidia and report the adapter, driver, wave range, case count, and validation messages. Reproduction commands are in the description.

AI-assisted using Codex.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

An offline coverage check would complement the native fixture. On an authorized local shader corpus, compare stock 70564ae with dc80215 using the same translation options and adapter capability selection. The most useful output is aggregate mesh translated/refused counts by reason, including recovered numerical-mask refusals and any new failures. If an independent title comparison is available, start with the stock baseline and compare normal-frame mesh and geometry counts in a matched scene. Aggregates are sufficient. The independent NVIDIA regression and RDNA4 timing requests above remain open.

AI-assisted using Codex.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 121 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.

Numerical Wave32 mesh masks lowered at uniform entry: time_mesh/draw_inner/mesh_ballot + mesh() builder, mesh_numeric_wave32_masks_translate_without_a_fixed_size test. 1098-line diff across emit/lower paths. Docs updated too.

@tumbubu

tumbubu commented Nov 24, 2026

Copy link
Copy Markdown

dc80215 on an RX 7900 XT (RDNA3): all 16 cases pass, including the new EntryUnusedLds.

The earlier RDNA3 report in this PR's table was for 95ffced. This is the same run on the proposed head.

  • AMD Radeon RX 7900 XT, driver 32.0.31036.15, waves 32..64
  • Agility SDK 1.620.2 from nuget.org, full GBV
Result
mesh_numeric_wave32_masks_control_two_triangles, amd pass: 16 cases, mesh tier 0xa, SM 6.6, no debug-layer errors
EntryUnusedLds (64 threads, LDS 1024) two triangles, as for Entry with the same LDS
EntryMismatch control draws nothing
same test, warp (4..4 lanes) pass
cargo test -p victory-shader --locked -- --test-threads=1 212 passed, 0 failed, 4 ignored (main 70564ae: 209 passed, 2 ignored)

mesh_wave32_ballot_gpu_cost: three runs, GBV off, medians of the per-run medians in GPU µs per 2,048-group dispatch.

Threads per group No ballots One Two Three
32 33.51 33.58 33.67 33.76
64 66.76 66.89 67.04 67.20
128 133.28 133.47 133.63 133.81

These are within 0.1 µs of the 95ffced numbers, so three ballots still cost under 1% on this card. This time all three 128-thread runs agree, with no fast first run.

AI-assisted (Claude Code); generated shaders only, no game files.

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

NVIDIA follow-up on the approved head dc80215: all 16 synthetic mesh cases passed on the GeForce RTX 5070 Laptop GPU (driver 581.91, mesh tier 1, SM 6.6, 32-lane waves) with the D3D12 debug layer and full GPU-based validation. The matrix includes native Wave32 and logical Wave64 controls, scratch reuse, LDS coexistence, and the intentional wrong-mask case. The PR head is unchanged. This run covers synthetic correctness. Title-level geometry and RDNA4 performance remain pending.

@aycow
aycow requested a review from catminou4 November 25, 2026 02:58

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. This lowers numeric Wave32 masks in mesh shaders to a groupshared ballot with three group barriers, only in the group-uniform entry block (mesh_ballot, mesh_mask_point in emit/lower.rs), with the scratch counted against the 28 KiB limit in shader.rs. Testers report the synthetic fixture passing on RDNA3, RDNA4 and NVIDIA. Before review:

  • Please drop docs/mesh-wave32-numeric-masks.md or cut it to a few lines; design rationale, run instructions and measurements stay in the PR, not in the repository's docs.
  • mesh_numeric_wave32_masks_control_two_triangles loads a D3D12 runtime from the path in VICTORY_MESH_MASK_TEST_SDK through D3D12SDKConfiguration, which needs the maintainer's decision.
  • There is no evidence from the title yet.

CI has not run.


Generated by Claude Code

@aycow

aycow commented Nov 25, 2026

Copy link
Copy Markdown
Author

@Marvisak Could you confirm whether the ignored hardware fixture may load an explicitly selected Agility SDK through D3D12SDKConfiguration, or whether you prefer a different test setup? Could you also authorize the pending CI workflow for the approved head dc80215?

The PR description already carries the reproduction and measured results. I can combine the requested repository-doc trim with any fixture changes from that decision. The AMD and NVIDIA evidence is synthetic. Title-level geometry remains unverified.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Mericas77

Copy link
Copy Markdown

NVIDIA run of #1759, since the reports so far are AMD and WARP.

Setup: RTX 4070 (driver 621.01, Windows 11), Agility SDK 1.620.2 (NuGet), Graphics Tools, dxil.dll from SDK 10.0.26100. Tested head dc80215 merged onto main 940d32f (no conflicts).

Results

  • mesh_mask_tests: 3 passed, 2 ignored. The translated modules pass dxil.dll.

  • mesh_numeric_wave32_masks_control_two_triangles with GPU-based validation:

    • NVIDIA GeForce RTX 4070: mesh tier 0xa, shader model 0x66, wave range 32..32, GBV=true: all 16 cases pass.
    • Microsoft Basic Render Driver: wave range 4..4, GBV=true: all 16 cases pass, with the same probes as on NVIDIA.
    • No debug-layer or GPU-validation messages on either adapter, and no device removal.
  • mesh_wave32_ballot_gpu_cost on the 4070: GPU µs per dispatch of 2048 groups, median of 15 samples:

    threads 0 ballots 1 2 3
    32 13.57 13.82 14.08 14.21
    64 43.52 43.78 43.65 43.78
    128 33.54 33.66 33.66 33.79

    At 32 threads each ballot adds about 0.26 µs. At 64 and 128 threads the difference is within noise. The 64-thread baseline is unstable even with 0 ballots (min 16.9 µs, median 43.5 µs), and it is slower than 128 threads, so it looks unrelated to the ballots.

  • cargo test -p victory-shader --locked: 247 passed, 3 failed. The 3 failures are the known NVIDIA ones on main (two stride_tests and gathers_at_a_level_match_the_hardware). The other 244 match main; the 3 extra passes are this PR's tests.

AI-assisted.

@Mericas77

Copy link
Copy Markdown

Checked against current main (940d32f), translation only (no GPU in this run):

  • With only the test commit 01aef05 applied to 940d32f, the numeric fixture is still refused: mesh_numeric_wave32_masks_translate_without_a_fixed_size fails with Unsupported { offset: 232, what: "a lane mask read as data" }. So the refusal this PR targets is still on main.
  • eac3a68 applies to 940d32f without conflicts. With it, the three mesh_mask_tests translation tests pass, and cargo test --locked -p victory-shader gives 147 passed, 0 failed, 2 ignored.

One point for prioritising: #2268 reports an offline census on 940d32f with all 8,765 title mesh programs emitted. If that holds, the title no longer reaches this pattern, and the ~250 mesh refusals counted in #769 came from ffe310e. This PR would then be correctness coverage for numeric Wave32 mesh masks rather than an unblocker for the title's mesh shaders (which are wave64).

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants