mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-08 23:45:46 +01:00
Rework the Metal 4 backend and example for correct, glitch-free multi-viewport rendering on macOS, and convert example_apple_metal4 off MTKView. Backend (imgui_impl_metal4.mm): - Per-window argument tables so overlapping per-window GPU work within a frame can't corrupt each other's bindings (multi-viewport flicker). - Hold per-slot vertex/index buffers until their frame completes, so a second viewport rendered later in the same frame can't overwrite a buffer still in flight (blink). - Make hand-built render-pass drawables resident, and evict stale (resized-away) drawables from the residency set so it can't grow without bound during a live resize. - Present secondary viewports in-transaction on the frame they were resized so content stays glued to the new size (no stutter). Example (example_apple_metal4/main.mm): - Replace MTKView with a custom NSView/UIView + CAMetalLayer driven by a display link. - Proper frames-in-flight: per-slot command allocators, rotating slots, and a semaphore gate released on GPU completion via an MTLSharedEvent listener. - Glitch-free main-window resize: present in-transaction during a live resize, driven by AppKit (the display link steps aside) so the transaction commits and drawables aren't starved; async present otherwise (avoids a ~1s nextDrawable stall / freeze). - Idle CPU throttling: only redraw on input/activity plus a slow heartbeat, so the main thread sleeps when nothing changes.