Skip to content

Shaders: lower v_mbcnt through Ubfe - #3686

Open
Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/mbcnt-prefix-extract
Open

Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/mbcnt-prefix-extract

Conversation

@Ingenioeren

Copy link
Copy Markdown
Contributor

v_mbcnt_lo_u32_b32 and v_mbcnt_hi_u32_b32 currently build (1 << below) - 1, select the full-width mask, AND it with the source, and then count bits. Extracting the low bits with DXIL Ubfe removes three written instructions per form. The full-source select is retained for widths of 32 or more, since Ubfe masks its width to five bits. Lane selection, wave-size requirements and accumulation are unchanged.

Synthetic compute shaders with a dynamic mask and accumulator, counting the complete written function body:

Form main this PR
v_mbcnt_lo_u32_b32 27 24
v_mbcnt_hi_u32_b32 30 27

These are DXIL instruction counts, not GPU timing or frame-rate measurements. The test-only instruction counter is identical to #3600 and the subsequent lowering PRs.

Validation:

  • cargo test --locked --offline -p victory-shader mbcnt -- --nocapture: the count regression fails on the original lowering at 27/30 and passes at 24/27 after the change. The execution test passes before and after: 113,280 inputs for each of wave32/wave64 and full/even-lane EXEC, 453,120 cases per revision on RX 6750 XT. It checks low/high counts, their chained accumulation, unsigned wraparound, single-bit/complement/edge/random masks, all lane positions and inactive destinations against an independent per-bit CPU reference. DXIL validation passes. WARP reports no wave support and skips these executions.
  • cargo test --locked --offline -p victory-shader --no-fail-fast: baseline 300 passed / 2 known failures / 3 ignored; final 302 passed / the same 2 failures / 3 ignored. The two existing local validator failures remain rectangles_get_their_fourth_corner and elements_sharing_a_row_keep_their_order (PSV mismatch). Integration: 3 passed / 1 ignored; doc tests: 0.
  • cargo clippy --locked --offline -p victory-shader --all-targets --all-features -- -D warnings: passed.
  • cargo run --locked --offline -p xtask -- policy --staged: passed for all 3 changed files. Existing formatting deviations match main in each changed file.

No game files were used and no game run was performed. Other GPU vendors, Linux/RADV, graphics and mesh execution were not tested. #599/#3556 address separate ballot/lane semantics in or near this arm; this PR retains main's behavior and may need a small rebase depending on merge order.

AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.

@ColorMeBoom

Copy link
Copy Markdown

Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head 7905626 on 63bcca4. Both of this PR's GPU checks need a wave size that WARP refuses, so this is their only physical coverage so far:

  • mbcnt_counts_each_half_before_the_lane passes on the card at both wave sizes:
    hardware wave32, guarded=false: 113280 inputs matched
    hardware wave32, guarded=true: 113280 inputs matched
    hardware wave64, guarded=false: 113280 inputs matched
    hardware wave64, guarded=true: 113280 inputs matched
    warp: no wave32 support; skipped
    warp: no wave64 support; skipped
    
  • mbcnt_extracts_the_bits_below_the_lane passes.
  • Full victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants