Skip to content

feat(metal): implement dispatch_workgroups_indirect on native Metal backend - #2642

Merged
Hona merged 1 commit into
devfrom
fix/2545-metal-indirect-compute
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
fix/2545-metal-indirect-compute

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

Implements ComputePass::dispatch_workgroups_indirect on Rune's native Apple Metal backend instead of panicking with unsupported!("indirect dispatches").

Addresses #2545

Design

  • Indirect validation (crates/rune-gpu/src/indirect.rs): Validates BufferUsages::INDIRECT, 4-byte offset alignment, and overflow-checked offset..offset + 12 bounds against the logical buffer size (DispatchIndirectArgs) before issuing the unsafe Metal call. Invalid calls report a wgpu::Error::Validation through the thread's active error scope (or panic when uncaptured).
  • Native Metal dispatch (crates/rune-gpu/src/metal/compute.rs): Tracks MetalBuffer::usage, flushes dirty bind groups / storage buffer swaps / sizes / immediates, forwards to dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup: with the bound pipeline's workgroup size, and retains the current BufferRaw in self.keep until the unretained command buffer retires.
  • Scope: Focused on indirect compute dispatch; indirect render draws (draw_indirect / draw_indexed_indirect) remain out of scope.

Verification

  • Local (Windows):
    • cargo test -p rune-gpu --lib (60 passed, including 5 new indirect::tests covering DispatchIndirectArgs layout, alignment, BufferUsages::INDIRECT, bounds, and u64 overflow).
    • CARGO_FEATURE_PURE=1 cargo check -p rune-gpu --target aarch64-apple-darwin --tests (0 warnings/errors).
    • CARGO_FEATURE_PURE=1 cargo clippy -p rune-gpu --target aarch64-apple-darwin --tests --no-deps (0 new warnings).
    • cargo check -p rune-gpu --no-default-features --target wasm32-unknown-unknown (clean).
  • Not run on real macOS Metal hardware: New GPU parity and error-scope tests in crates/rune-gpu/src/metal/compute_tests.rs (indirect_dispatch_matches_wgpus_bit_for_bit, indirect_dispatch_validation_captures_errors) compile-checked for aarch64-apple-darwin but not executed on Apple Metal hardware locally.

@Hona
Hona merged commit 97d442e into dev Nov 27, 2026
2 checks passed
@Hona
Hona deleted the fix/2545-metal-indirect-compute branch November 27, 2026 15:22
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.

1 participant