Description
Submission checklist
- I have confirmed the issue is present in the latest version of the
riveFlutter 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:
- MSAA render targets never use
MTLStorageModeMemorylessand unconditionally setMTLTextureUsageShaderRead(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 notransient/memorylessfield, 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
MTLTextureUsageShaderReadtoMTLTextureType2DMultisampleis unnecessary (Ore scripts cannot sample multisampled textures directly viatextureSample) and prevents Metal's tile-memory / lossless framebuffer compression optimizations.
mtlPopulateFeatures()advertisesmaxSamples = 8on iOS (ore_context_metal.mm:413-421):Scripts that queryf.maxSamples = 1; for (uint32_t sc : {8u, 4u, 2u}) { if ([device supportsTextureSampleCount:sc]) { f.maxSamples = sc; break; } }
maxSampleswithout manually clamping to 4 can allocate 8× MSAA targets on mobile silicon.- Multi-pass MSAA with
StoreOp::storeemitsMTLStoreActionStoreAndMultisampleResolve(ore_context_metal.mm:998-1001):
While honoringStoreOp::storeis required for correctness when a script reloads MSAA buffers across passes, there is currently no way for a script usingStoreOp::discard+ single-pass resolve to opt intoMTLStorageModeMemorylessfor 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
- Remove
MTLTextureUsageShaderReadfromMTLTextureType2DMultisampletextures inContextMetal::mtlMakeTexture()(ore_context_metal.mm:486), settingtd.usage = MTLTextureUsageRenderTargetfor MSAA textures. - Support
MTLStorageModeMemorylesson Apple Silicon TBDR (MTLGPUFamilyApple1+) — e.g. via an optionaltransient/memorylessflag inore::TextureDesc(exposed toGPUTexturescripting) so MSAA color and depth attachments that only useLoadOp::clear/dontCareandStoreOp::discard(+resolveTarget) stay completely on-chip with zero DRAM allocation or bandwidth. - Consider capping
f.maxSamplesat4uon iOS (#if defined(RIVE_IOS)) inmtlPopulateFeatures()(ore_context_metal.mm:414), matching mobile TBDR best practices.
Reproduction steps / code
- Create a scripted
GPUCanvasscene 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). - Compare frame times and
deferredThreadStats()replay duration against the same scene usingsampleCount = 1(+ FXAA) at 2× the render scale. - 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