Skip to content

Shaders: lower compute thread-group info and s_get_waveid_in_workgroup - #551

Open
kilvynsilveira-tech wants to merge 1 commit into
Marvisak:mainfrom
kilvynsilveira-tech:shader-group-info-coverage
Open

kilvynsilveira-tech wants to merge 1 commit into
Marvisak:mainfrom
kilvynsilveira-tech:shader-group-info-coverage

Conversation

@kilvynsilveira-tech

@kilvynsilveira-tech kilvynsilveira-tech commented Nov 24, 2026 •

Copy link
Copy Markdown

Lower two workgroup wave-identity inputs the emitter previously refused:

  • Compute thread-group info SGPR (COMPUTE_PGM_RSRC2.TG_SIZE_EN): was "the thread-group info SGPR". Now packs the full hardware layout {first_wavefront, 14'b0, ordered_append_term[10:0], wave_count[5:0]} (LLVM AMDGPUUsage, Initial Kernel Execution State):
    • Bits 5:0: wave count in the group (threads.div_ceil(wave) & 0x3F, counting partial trailing waves).
    • Bits 11:6: wave index in the group (flattenedThreadIdInGroup >> log2(wave)), matching Mesa ACO's tg_size subgroup-id extraction (& 0xfc0 / s_bfe_u32 at offset 6, width 6) when GDS ordered append is disabled.
    • Bit 31: first_wavefront (1 on wave 0, 0 otherwise).
  • s_get_waveid_in_workgroup: was "a scalar memory read as data". Now writes the same wave index to its destination SGPR in compute and mesh stages (null destination is a no-op), and refuses cleanly outside compute and mesh (Ps / Vs).

Input::MergedWaveInfo now shares the same Lower::wave_id() helper.

(Note: pixel Input::SampleCoverage was dropped from this PR in favour of #1686 so the two PRs do not overlap.)

Tests (synthetic machine code only; cargo xtask policy passes)

  • emit::tests::group_info_and_waveid_in_workgroup_lower_and_validate (cross-platform + dxil.dll container/hash validation on Windows): compute in wave32 and wave64 ([96, 1, 1], joined across control flow, plus null destination), s_get_waveid_in_workgroup in HwStage::Ms, and clean refusals in HwStage::Ps and HwStage::Vs.
  • emit::valu_tests::compute_group_info_and_waveid_in_workgroup_match_the_group: 3D [8, 4, 3] (96-thread) compute dispatch in both wave32 (3 waves) and wave64 (2 waves, partial trailing wave), verifying all 32 bits of TG_SIZE (first_wavefront | wave_id << 6 | wave_count) and s_get_waveid_in_workgroup per thread on available SM 6.6 hardware and WARP backends.

Validation

  • cargo clippy --workspace --all-targets --locked -- -D warnings — clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — clean
  • cargo run -p xtask --locked -- policy — clean (191 files ok)
  • cargo test -p victory-shader --locked — new tests and non-SM 6.6 suite pass locally (dxil.dll validated; live SM 6.6 / WARP dispatch runs in CI and on SM 6.6 hosts; local GPU is RX 580)

@KoLolX3

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Check on Linux, not Windows: pass. Head f96ce2927 merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 94 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 2, of which 2 ran in the native run (the pass count rose by 2).
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

@catminou4

Copy link
Copy Markdown
Contributor

Triage note: overlaps #521 (model the compute thread-group info SGPR's wave count), which merges cleanly with main. This PR (#551, compute group info + wave id in workgroup + more) is broader in scope but has mergeable=false against current main. If #521 lands first, this one needs a rebase and a scope check that the remaining pieces (wave id, group info beyond the wave count) are still distinct.

@kilvynsilveira-tech

Copy link
Copy Markdown
Author

Rebased onto current \main\ (\ fe310e) and updated the new tests to pass \Some(&st)\ to
esource::track.

Regarding the overlap with #521:

If #521 lands first, I'm happy to rebase again and keep only the distinct pieces.

Re-verified after rebasing:

  • \cargo clippy -p victory-shader --all-targets\ clean
  • \cargo xtask policy\ passed
  • \group_info_and_waveid_in_workgroup_lower_and_validate\ and \sample_coverage_input_lowers_and_validates\ pass (validated with \dxil.dll)

@Calvix2k

Copy link
Copy Markdown
Contributor

Overlap with #1686: this PR also lowers pixel sample coverage via dx.op.coverage; #1686 does that part alone with a coverage-mask readback test and is already rebased onto 70564ae. The compute group-info/wave-id lowering here is separate and may still be useful. Suggest splitting the coverage part out (or dropping it in favour of #1686) so the two do not compete.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Thanks for rebasing and for dropping the coverage part in favour of #1686. The new head merges cleanly and is now reviewed.

In crates/victory-shader/src/emit/lower.rs, Input::GroupInfo now builds the TG_SIZE SGPR as first_wavefront << 31 | wave_index << 6 | wave_count. That matches the public layout in LLVM AMDGPUUsage and the way Mesa ACO extracts the subgroup id (bits 6-11). s_get_waveid_in_workgroup returns the same wave index through the new wave_id() helper, which MergedWaveInfo now shares, and it is refused outside compute and mesh. The readback test in valu_tests.rs covers a partial wave64 wave and checks all 32 bits.

This also covers the wave-count part of #521, so only one of the two should land.

Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.


Generated by Claude Code

@Calvix2k

Copy link
Copy Markdown
Contributor

Triage is right: the branch is based on fe310e and crates/victory-shader/src/emit/lower.rs has moved since. I do not have push access to your fork, but the conflict is confined to the lower match arms for the group-info ops; a git rebase origin/main and keeping the new arms alongside the added ones resolves it. Happy to review the rebased head.

Model the full COMPUTE_PGM_RSRC2.TG_SIZE_EN layout ({first_wavefront, 14'b0, wave_id[10:0], wave_count[5:0]}), lower s_get_waveid_in_workgroup in compute and mesh stages, and share wave_id() with MergedWaveInfo. Drop SampleCoverage in favour of Marvisak#1686.
@kilvynsilveira-tech kilvynsilveira-tech changed the title Shaders: lower compute group info, wave id in workgroup, and sample coverage Shaders: lower compute thread-group info and s_get_waveid_in_workgroup Nov 26, 2026
@kilvynsilveira-tech

Copy link
Copy Markdown
Author

Rebased onto latest main (63bcca4 -> b97b7bb) and incorporated the review feedback and several improvements:

  1. Dropped SampleCoverage in favour of Shaders: lower pixel shader SV_Coverage input via dx.op.coverage #1686 (thanks @Calvix2k for the heads-up) so this PR stays focused on compute GroupInfo (TG_SIZE_EN) and s_get_waveid_in_workgroup.
  2. Completed the TG_SIZE_EN hardware field layout: in addition to the masked 6-bit wave count (threads.div_ceil(wave) & 0x3F, bits 5:0) and wave index (flattenedThreadIdInGroup >> log2(wave), bits 11:6), bit 31 (first_wavefront, w == 0) is now populated too ({first_wavefront, 14'b0, wave_id[10:0], wave_count[5:0]}), so full-width reads, first_wave checks, s_bfe_u32 / s_and_b32 extractions, and values carried across phis/copies all match the console register layout.
  3. s_get_waveid_in_workgroup polish: handles null destination without emitting dead instructions, and covers HwStage::Ms as well as Ps/Vs refusals.
  4. Expanded tests (kept cross-platform lowering tests in emit/mod.rs so emit/lower.rs stays below the 512 KiB xtask policy limit, and added emit::valu_tests::compute_group_info_and_waveid_in_workgroup_match_the_group to verify per-thread TG_SIZE and s_get_waveid_in_workgroup readback across a [8, 4, 3] 96-thread group in both wave32 and wave64 on SM 6.6 / WARP).

Verified locally:

  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo run -p xtask --locked -- policy: 191 files ok
  • dxil.dll container & hash validation passing on all emitted Cs (wave32/wave64) and Ms shaders.

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