gpu, shader: Intel Arc DG2/Battlemage optimizations and hardware execution fallbacks #1066

Closed
UnkwnDev wants to merge 4 commits from upstream-pr/1066 into main
UnkwnDev commented 2026-11-24 15:27:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-24T15:27:04Z.


Resolves #740

Summary

Hardware execution fallbacks and shader optimizations targeting Intel Arc DG2 and Battlemage architectures.

Changes

  • Indirect draw stream compaction pass to eliminate empty draw stalls on host command lists.
  • DXIL WaveSize clamping to hardware capability (e.g. Wave32 on Arc) and bit-exact NaN handling.
  • Packed dot product lowering to DXIL dot4AddPacked and fused multiply-adds (v_dot4_i32_i8, v_dot4_u32_u8, v_dot2_f32_f16, v_dot2_i32_i16, v_dot2_u32_u16, v_dot8_u32_u4).
  • Whole-wave simulation width clamping to wave_size_max for Wave32 execution.
  • Comprehensive unit and integration test fixtures.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6585291881 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-24T15:27:04Z. --- Resolves #740 ### Summary Hardware execution fallbacks and shader optimizations targeting Intel Arc DG2 and Battlemage architectures. ### Changes * Indirect draw stream compaction pass to eliminate empty draw stalls on host command lists. * DXIL WaveSize clamping to hardware capability (e.g. Wave32 on Arc) and bit-exact NaN handling. * Packed dot product lowering to DXIL dot4AddPacked and fused multiply-adds (v_dot4_i32_i8, v_dot4_u32_u8, v_dot2_f32_f16, v_dot2_i32_i16, v_dot2_u32_u16, v_dot8_u32_u4). * Whole-wave simulation width clamping to wave_size_max for Wave32 execution. * Comprehensive unit and integration test fixtures.
catminou4 commented 2026-11-24 16:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T15:37:34Z.

Review: COMMENTED


Test-merge with current main (ffe310e) conflicts — the Intel Arc DG2/Battlemage changes touch files main has moved since the branch point (the shader side overlaps the waterfall/EXEC work that landed in #566). A rebase is needed before this can be evaluated; the +622/-41 split across victory-gpu and victory-shader also means the shader half could in principle be split out for separate review, since the GPU half is Windows-only and can't be exercised from macOS. I'll take another look once it's rebased.

<!-- greyfinch-sync:Marvisak/VIctory:review:6042384682 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066#pullrequestreview-6042384682). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T15:37:34Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) conflicts — the Intel Arc DG2/Battlemage changes touch files main has moved since the branch point (the shader side overlaps the waterfall/EXEC work that landed in #566). A rebase is needed before this can be evaluated; the +622/-41 split across `victory-gpu` and `victory-shader` also means the shader half could in principle be split out for separate review, since the GPU half is Windows-only and can't be exercised from macOS. I'll take another look once it's rebased.
UnkwnDev commented 2026-11-24 19:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-24T18:30:46Z.


Rebased cleanly onto main at ffe310e. Conflicts in crates/victory-shader/src/emit/valu_tests.rs have been resolved to preserve our Wave32 simulation and packed dot product tests alongside the waterfall/EXEC tests from #566, including synchronizing dispatch tests under ONE_AT_A_TIME. All workspace tests and clippy checks (--all-targets, with and without --all-features) pass cleanly.

Regarding the split: if separating the victory-shader changes from the Windows-only victory-gpu compaction pass makes review and testing on macOS easier, let me know and I can extract the shader commits into a separate PR.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140748236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066#issuecomment-7140748236). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-24T18:30:46Z. --- Rebased cleanly onto main at ffe310e. Conflicts in crates/victory-shader/src/emit/valu_tests.rs have been resolved to preserve our Wave32 simulation and packed dot product tests alongside the waterfall/EXEC tests from #566, including synchronizing dispatch tests under ONE_AT_A_TIME. All workspace tests and clippy checks (--all-targets, with and without --all-features) pass cleanly. Regarding the split: if separating the victory-shader changes from the Windows-only victory-gpu compaction pass makes review and testing on macOS easier, let me know and I can extract the shader commits into a separate PR.
UnkwnDev commented 2026-11-24 19:04:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by UnkwnDev on 2026-11-24T18:51:06Z.


Updated branch at dc1aa37 following a self-review pass:

  1. Fixed VOP2/VOP3 v_dot2c_f32_f16 operand extraction in crates/victory-shader/src/emit/lower.rs: since non-VOP3P encodings leave opsel_hi unset, v_dot2c_f32_f16 now explicitly slices [15:0] and [31:16] via f16_operand instead of reading the low half twice.
  2. Added v.clamp saturation for integer dot products (v_dot4_i32_i8, v_dot4c_i32_i8, v_dot4_u32_u8, v_dot2_i32_i16, v_dot2_u32_u16, v_dot8_u32_u4) and routed v_dot2_i32_i16/u16 through packed_src so VOP3P opsel/opsel_hi are honored.
  3. Added a shared-memory prefix scan in crates/victory-gpu/src/indirect.rs for single-group batches (<= 64 commands) so compaction preserves exact command order and avoids global atomic contention.
  4. Eliminated environment variable mutation from wave::tests::wave64_section_simulates_wave32_when_clamped.

Re-verified with cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, and full cargo test --workspace --locked (all tests passing, including new VOP2 dot2c, integer clamp, and opsel hardware tests).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141240798 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066#issuecomment-7141240798). Originally posted by [UnkwnDev](https://github.com/UnkwnDev) on 2026-11-24T18:51:06Z. --- Updated branch at dc1aa37 following a self-review pass: 1. Fixed VOP2/VOP3 v_dot2c_f32_f16 operand extraction in crates/victory-shader/src/emit/lower.rs: since non-VOP3P encodings leave opsel_hi unset, v_dot2c_f32_f16 now explicitly slices [15:0] and [31:16] via f16_operand instead of reading the low half twice. 2. Added v.clamp saturation for integer dot products (v_dot4_i32_i8, v_dot4c_i32_i8, v_dot4_u32_u8, v_dot2_i32_i16, v_dot2_u32_u16, v_dot8_u32_u4) and routed v_dot2_i32_i16/u16 through packed_src so VOP3P opsel/opsel_hi are honored. 3. Added a shared-memory prefix scan in crates/victory-gpu/src/indirect.rs for single-group batches (<= 64 commands) so compaction preserves exact command order and avoids global atomic contention. 4. Eliminated environment variable mutation from wave::tests::wave64_section_simulates_wave32_when_clamped. Re-verified with cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, and full cargo test --workspace --locked (all tests passing, including new VOP2 dot2c, integer clamp, and opsel hardware tests).
DeerSilver commented 2026-11-25 00:06:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T23:06:37Z.


Tested on an Intel Xe-LP iGPU (not Arc) and an NVIDIA card. Setup: one laptop with an NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell, 10de:2d59, driver 621.24) and an Intel UHD Graphics (Raptor Lake Xe-LP, 8086:a788, driver 32.0.101.7088), Windows 11 26300, Rust 1.98.1. The PR was merged onto main ffe310e.

  • cargo test --workspace --all-features --locked --no-fail-fast -- --test-threads=1 with the D3D12 debug layer on (VICTORY_D3D12_DEBUG=1, and a local, uncommitted change that also turns the debug layer on in victory-shader's test Host): 350 passed, 0 failed, 6 ignored. The four new tests passed in that run, which used the default adapter, the RTX.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean

victory-shader's lib tests on each adapter (cargo test --locked -p victory-shader --lib -- --test-threads=1, with a local switch that creates the test Host on a chosen DXGI adapter and prints its name):

RTX 5060 Laptop Intel UHD
main (not run) 119 passed, 1 failed (v_med3_f32_matches_rdna2_with_nan)
main + this PR 124 passed, 0 failed 123 passed, 1 failed

The PR's NaN bit test fixes v_med3_f32 on the Intel UHD. The failure with the PR is the new wave32_simulation_and_reduction_executes_cleanly:

hardware: compute_pipeline failed: The parameter is incorrect.

The debug layer gives the reason:

D3D12 ERROR: ID3D12Device::CreateComputeShader: Shader wants wave lane count of 32 but maximum wave lane count for device is 16. [ STATE_CREATION ERROR #622: CREATESHADER_INVALIDBYTECODE]

This Xe-LP reports a maximum of 16 lanes, so a shader with a fixed wave size of 32 can't be created there. The test skips WARP on a compute_pipeline error but panics for hardware. Checking D3D12_FEATURE_DATA_D3D12_OPTIONS1.WaveLaneCountMin/Max and skipping when 32 is out of range would fix that. I don't know whether Arc reports the same 16-lane maximum; it's worth checking, since the PR targets Arc.

No game data used. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147024209 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066#issuecomment-7147024209). Originally posted by [DeerSilver](https://github.com/DeerSilver) on 2026-11-24T23:06:37Z. --- Tested on an Intel Xe-LP iGPU (not Arc) and an NVIDIA card. **Setup:** one laptop with an NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell, `10de:2d59`, driver 621.24) and an Intel UHD Graphics (Raptor Lake Xe-LP, `8086:a788`, driver 32.0.101.7088), Windows 11 26300, Rust 1.98.1. The PR was merged onto `main` `ffe310e`. - `cargo test --workspace --all-features --locked --no-fail-fast -- --test-threads=1` with the D3D12 debug layer on (`VICTORY_D3D12_DEBUG=1`, and a local, uncommitted change that also turns the debug layer on in victory-shader's test `Host`): 350 passed, 0 failed, 6 ignored. The four new tests passed in that run, which used the default adapter, the RTX. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean victory-shader's lib tests on each adapter (`cargo test --locked -p victory-shader --lib -- --test-threads=1`, with a local switch that creates the test `Host` on a chosen DXGI adapter and prints its name): | | RTX 5060 Laptop | Intel UHD | |---|---|---| | `main` | (not run) | 119 passed, 1 failed (`v_med3_f32_matches_rdna2_with_nan`) | | `main` + this PR | 124 passed, 0 failed | 123 passed, **1 failed** | The PR's NaN bit test fixes `v_med3_f32` on the Intel UHD. The failure with the PR is the new `wave32_simulation_and_reduction_executes_cleanly`: ``` hardware: compute_pipeline failed: The parameter is incorrect. ``` The debug layer gives the reason: ``` D3D12 ERROR: ID3D12Device::CreateComputeShader: Shader wants wave lane count of 32 but maximum wave lane count for device is 16. [ STATE_CREATION ERROR #622: CREATESHADER_INVALIDBYTECODE] ``` This Xe-LP reports a maximum of 16 lanes, so a shader with a fixed wave size of 32 can't be created there. The test skips WARP on a `compute_pipeline` error but panics for hardware. Checking `D3D12_FEATURE_DATA_D3D12_OPTIONS1.WaveLaneCountMin/Max` and skipping when 32 is out of range would fix that. I don't know whether Arc reports the same 16-lane maximum; it's worth checking, since the PR targets Arc. No game data used. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:05:27 +00:00
Marvisak commented 2026-11-25 01:07:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:31:26Z.


Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

A release environment variable (VICTORY_WAVE_SIZE_MAX) makes console wave64 programs that depend on lane order declare WaveSize(32) and simulates their whole-wave sections at 32 lanes, with no emulation and outside the shader cache key: wrong results where it is used. Its other parts exist elsewhere (v_dot4* in main, the med3 NaN test is #1689) or are unrelated (indirect stream compaction against a rewritten indirect.rs).

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148595278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1066#issuecomment-7148595278). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:31:26Z. --- Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. A release environment variable (VICTORY_WAVE_SIZE_MAX) makes console wave64 programs that depend on lane order declare WaveSize(32) and simulates their whole-wave sections at 32 lanes, with no emulation and outside the shader cache key: wrong results where it is used. Its other parts exist elsewhere (v_dot4* in main, the med3 NaN test is #1689) or are unrelated (indirect stream compaction against a rewritten indirect.rs). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1066
No description provided.