Skip to content

render: Re-evaluate virtual geometry with native Metal MDI #61

Description

@hmans

Context

Scrapbot currently uses portable GPU compaction for virtual-geometry submission on Metal because the pinned wgpu-native backend does not advertise MultiDrawIndirectCount. Fixed-count multi-draw is callable, but the current Metal backend may lower it to repeated indirect draws.

This is not a permanent Metal limitation. wgpu has native Metal Indirect Command Buffer work in progress:

Re-evaluate Scrapbot's choice once an applicable implementation is merged, released, and included in our pinned wgpu-native build.

Current evidence

A controlled Apple M4 / Metal comparison used the Sponza example at a fixed 1920×1080 resolution. Each mode was profiled twice in alternating order with 60 warmup frames and 240 measured frames.

Median Portable compaction Current fixed-MDI route Change
CPU active 1.01 ms 7.23 ms +615%
GPU frame 15.15 ms 17.45 ms +15%
GPU culling 0.88 ms 1.61 ms +83%
GPU shadows 1.27 ms 2.55 ms +101%
GPU depth 0.31 ms 0.55 ms +74%
GPU world 3.47 ms 3.37 ms -3%

The current MDI route slightly improves world shading, but loses badly overall. The dominant CPU regression is consistent with fixed-count MDI ranges being expanded by the current Metal backend. The route also sends meshlet work through depth and four shadow cascades, increasing GPU cost.

A control with zero visible shadow casters still retained substantial MDI submission cost, showing that zero-instance indirect commands in the encoded ranges are not free under the current lowering.

Upstream dependencies

Re-evaluation checklist

  • Confirm the relevant upstream implementation is merged and present in Scrapbot's pinned wgpu-native artifact.
  • Confirm adapter feature reporting distinguishes native fixed-count MDI from an emulated fallback.
  • Preserve portable compaction for adapters without a genuinely native path.
  • Profile identical project state, camera, resolution, render features, warmup, and measured-frame count.
  • Run at least two alternating repetitions per path to reduce order and thermal bias.
  • Compare raw median/p95/worst CPU and valid GPU timings with mise profile-analyze.
  • Compare workload and counter fields, especially cluster command count, visible frontier, draw submissions, cull workgroups, depth, and every shadow cascade.
  • Test both the ordinary camera path and a shadow-heavy case.
  • Verify output with matching frame captures and virtual-geometry debug views.
  • Update the rendering FDR/ADR and architecture inventory if capability selection or submission ownership changes.

Acceptance criteria

Adopt native Metal MDI only when it is a measurable overall improvement for representative virtual-geometry workloads without regressing correctness. Do not decide from the world pass alone: CPU encoding, culling, depth, shadows, and full GPU-frame cost are part of the decision.

If native ICB MDI is not consistently better, retain portable compaction and record the measured reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions