Skip to content

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

Closed
UnkwnDev wants to merge 4 commits into
Marvisak:mainfrom
UnkwnDev:arc-optimizations
Closed

UnkwnDev wants to merge 4 commits into
Marvisak:mainfrom
UnkwnDev:arc-optimizations

Conversation

@UnkwnDev

@UnkwnDev UnkwnDev commented Nov 24, 2026 •

Copy link
Copy Markdown

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 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.

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

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown

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).

@Marvisak

Copy link
Copy Markdown
Owner

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.

@Marvisak Marvisak closed this Nov 25, 2026
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.

Patch (fork): indirect draw stream compaction pass and Intel Arc DG2 wave clamping

4 participants