Skip to content

iOS / Metal (Ore GPUCanvas): MSAA render targets use MTLStorageModePrivate + ShaderRead (no Memoryless), causing ~16-20x slowdown on Apple Silicon TBDR #677

Backlog

Description

@alexflav23

Submission checklist

  • I have confirmed the issue is present in the latest version of the rive Flutter package (rive 0.15.0-dev.5 / rive_native 0.2.0-dev.5)
  • I have searched the documentation and forums and could not find an answer
  • I have searched existing issues and this is not a duplicate

Description

When a scripted GPUCanvas scene enables MSAA (sampleCount > 1) on iOS Metal (Factory.rive), frame times on physical Apple Silicon GPUs hit a ~16–20× cliff compared to sampleCount = 1, even when sampleCount = 1 renders 7× more pixels.

Inspecting runtime/renderer/src/ore/metal/ore_context_metal.mm in rive_native 0.2.0-dev.5 shows three Metal TBDR issues:

  1. MSAA render targets never use MTLStorageModeMemoryless and unconditionally set MTLTextureUsageShaderRead (ore_context_metal.mm:473-512):
    bool isMSAA = desc.sampleCount > 1 && desc.type == TextureType::texture2D;
    td.textureType = isMSAA ? MTLTextureType2DMultisample
                            : oreTextureTypeToMTL(desc.type);
    ...
    td.storageMode = desc.renderTarget
                         ? MTLStorageModePrivate
                         : uploadableTextureStorageMode(m_mtlDevice);
    td.usage = MTLTextureUsageShaderRead;
    ...
    if (desc.renderTarget)
    {
      td.usage |= MTLTextureUsageRenderTarget;
    }
    • ore::TextureDesc (ore_types.hpp:353-364) has no transient / memoryless field, so every multisampled color and depth texture is backed by system DRAM (MTLStorageModePrivate) instead of staying on-chip in Apple Silicon tile memory (MTLStorageModeMemoryless).
    • Adding MTLTextureUsageShaderRead to MTLTextureType2DMultisample is unnecessary (Ore scripts cannot sample multisampled textures directly via textureSample) and prevents Metal's tile-memory / lossless framebuffer compression optimizations.
  2. mtlPopulateFeatures() advertises maxSamples = 8 on iOS (ore_context_metal.mm:413-421):
    f.maxSamples = 1;
    for (uint32_t sc : {8u, 4u, 2u})
    {
      if ([device supportsTextureSampleCount:sc])
      {
        f.maxSamples = sc;
        break;
      }
    }
    Scripts that query maxSamples without manually clamping to 4 can allocate 8× MSAA targets on mobile silicon.
  3. Multi-pass MSAA with StoreOp::store emits MTLStoreActionStoreAndMultisampleResolve (ore_context_metal.mm:998-1001):
    While honoring StoreOp::store is required for correctness when a script reloads MSAA buffers across passes, there is currently no way for a script using StoreOp::discard + single-pass resolve to opt into MTLStorageModeMemoryless for its MSAA color/depth attachments on Apple Silicon TBDR.

Physical iOS --profile Measurements

Measured on a physical iPhone (iPhone19,4, iOS 27.3, 951×669 @ 3×, Flutter 3.47.8 --profile) running the exact same scripted 3D GPUCanvas scene across quality tiers and render scales:

Tier & renderScale Relative pixel area Flutter UI FPS Rive Paints/s Raster avg / p95 Replay ms >16.7 ms frames
High (sampleCount > 1), sc = 2.0 4.00× 12 fps 10–11/s 82.9 / 261.4 ms 69.26 ms 24 / 36
High (sampleCount > 1), sc = 1.5 2.25× 16–18 fps 15–17/s 55.9 / 173.2 ms 44.97 ms 36 / 54
High (sampleCount > 1), sc = 1.0 1.00× 26–29 fps 28–29/s 29.5 / 91.7 ms 23.82 ms 59 / 88
High (sampleCount > 1), sc = 0.75 0.56× 33 fps 33/s 26.1 / 82.0 ms 20.72 ms 65 / 99
Low (sampleCount = 1 + FXAA), sc = 2.0 4.00× (7.1× more px!) 121 fps 120/s 0.5 / 0.7 ms 1.31 ms 0 / 362
Low (sampleCount = 1 + FXAA), sc = 1.5, 60 fps cap (15 s heavy weather soak) 2.25× 120 fps 60/s 0.9 / 1.4 ms 2.01 ms 0 / 1,796

Per-pass ablation at High, sc = 1.0 confirmed that disabling individual optional shader effects (fxAA, fxEnv, fxBake, fxRooms, fxCar, fxWinDay) barely moved frame rate (21–26 fps, 27.5–31.8 ms replay), while switching from MSAA to single-sample (sampleCount = 1) at 7.1× higher pixel count jumped from 33 fps → 121 fps.

(Note: on the macOS iPad Pro M5 simulator this did not reproduce — all cases held flat 60 fps / ~0.7 ms replay — because desktop M-series GPUs mask the DRAM bandwidth penalty.)

Suggested Improvements

  1. Remove MTLTextureUsageShaderRead from MTLTextureType2DMultisample textures in ContextMetal::mtlMakeTexture() (ore_context_metal.mm:486), setting td.usage = MTLTextureUsageRenderTarget for MSAA textures.
  2. Support MTLStorageModeMemoryless on Apple Silicon TBDR (MTLGPUFamilyApple1+) — e.g. via an optional transient / memoryless flag in ore::TextureDesc (exposed to GPUTexture scripting) so MSAA color and depth attachments that only use LoadOp::clear/dontCare and StoreOp::discard (+ resolveTarget) stay completely on-chip with zero DRAM allocation or bandwidth.
  3. Consider capping f.maxSamples at 4u on iOS (#if defined(RIVE_IOS)) in mtlPopulateFeatures() (ore_context_metal.mm:414), matching mobile TBDR best practices.

Reproduction steps / code

  1. Create a scripted GPUCanvas scene with an MSAA color target (sampleCount = 4) + MSAA depth target (depth24plus-stencil8, sampleCount = 4) resolved to a single-sample texture, rendered at full-screen resolution on a physical iPhone/iPad (--profile).
  2. Compare frame times and deferredThreadStats() replay duration against the same scene using sampleCount = 1 (+ FXAA) at 2× the render scale.
  3. Observe a ~16–20× jump in GPU/replay time when MSAA is active on physical iOS hardware (whereas the iOS Simulator on Apple Silicon macOS masks it).

Rive Flutter package version

rive 0.15.0-dev.4 / rive_native 0.2.0-dev.4 (verified identical in rive_native 0.2.0-dev.5 source)

Flutter version

Flutter 3.47.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 737ba8f885 (5 weeks ago) • 2026-10-22 21:37:31 -0700
Engine • hash dfd2e6cb7d319db05e3bf1503f3e2ac60f6288a2 (revision cf636b1dfb)
Tools • Dart 3.13.7 • DevTools 2.60.0

Device

Physical iPhone (iPhone19,4, 120 Hz ProMotion)

OS version

iOS 27.3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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