Metal: lower large indexed multi-draws to ICBs#263
Open
besmpl wants to merge 1 commit into
Open
Conversation
besmpl
marked this pull request as ready for review
July 15, 2026 11:52
besmpl
force-pushed
the
besmpl/metal-icb-lowering
branch
3 times, most recently
from
July 22, 2026 06:44
79b7521 to
05f98b7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
besmpl
force-pushed
the
besmpl/metal-icb-lowering
branch
from
July 22, 2026 13:34
05f98b7 to
4da2d64
Compare
kolkov
approved these changes
Jul 22, 2026
kolkov
left a comment
Contributor
There was a problem hiding this comment.
First review. This is high-quality engineering — an original optimization beyond Rust wgpu parity (Rust uses a simple loop for draw_indexed_indirect, confirmed at command.rs:1277-1308).
The architecture is sound at every level:
- Deferred render encoder — delays native encoder creation until first draw, enabling ICB compute dispatch for eligible first indexed multi-draws.
- Bounded state journaling — pipeline, bind groups, vertex buffers, viewport, scissor, blend, stencil recorded in fixed-size arrays with zero allocations (benchmarked).
- ICB eligibility — correctly gated: buffer-only bindings, triangle-list topology, Apple7+ GPU family, 1024–52428 command range. Non-eligible calls fall back to loop — fail-safe at every decision point.
- Compute kernel — per-index-format (uint16/uint32), translates
DrawIndexedArgsinto ICB commands. Cached per device. - Ownership — ICB + argument buffer retained through command buffer completion with
sync.Oncecleanup. LIFO release order correct.
Test coverage is exceptional: 36 test functions, 7 benchmarks, pixel-level ICB vs loop parity test with GPU-written indirect args. 96% patch coverage.
Minor notes (non-blocking):
- Per-call ICB creation (no pooling) — acceptable for v1, future optimization opportunity
- DX12 unconditionally reports
FeatureMultiDrawIndirect— correct for D3D12 but worth a comment
Should merge after #253 (stacked dependency). LGTM.
besmpl
force-pushed
the
besmpl/metal-icb-lowering
branch
from
July 22, 2026 16:31
4da2d64 to
0310f07
Compare
Contributor
besmpl
force-pushed
the
besmpl/metal-icb-lowering
branch
from
July 22, 2026 17:28
0310f07 to
b600f29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack and review order
This is a stacked PR built on the current head of #253 (
1953452) and is ready for review. Please approve the prerequisite PRs before this one.Please review and land the stack in this order:
Until #253 lands, GitHub shows its commits in this PR's diff because its head branch is in a fork and cannot be selected as an upstream base. After the prerequisites settle, this branch will be rebased onto
mainand the verification below rerun.What changed
Scope
The optimization is entirely private to
hal/metal. It adds no public feature, flag, token, prepared-command API, or caller-managed lifetime. Metal feature reporting remains unchanged.The initial eligibility policy is intentionally narrow:
Verification
CGO_ENABLED=0 go test ./...baseVertex,firstInstance, GPU-written indirect arguments, bound uniform/read-only-storage buffers, first-vs-later execution, and clear-only passesgit diff --checkand formatting checksPaired Apple M1 complete-frame benchmarks against the exact #253 base measured median improvements of about 19% at 1,024 commands and 60% at 10,000 commands. Direct, count-1, and count-20 controls stayed within the 5% time/allocation gate in the stable paired run.