gpu/mtl_swap.rs (Apple)#
Source: lib/gpu/mtl_swap.rs
mtl_swap -- swapchains on Metal (AP6c, docs/APPLE.md): a CAMetalLayer on a plat window
Surface::new(&instance, window) macOS: the window's GPU layer, shown (plat::win_native)
Surface::native(&instance, nw, window) the UI output's layer (plat::win_gpu_child, hidden until
the output shows it)
device.create_swapchain(&surface, &desc) the layer gets the device, the format (BGRA8, sRGB
when asked), framebufferOnly unless copy_src, three drawables, the window's size
try_acquire() never waits: nextDrawable only while fewer drawables are in use than the layer
has (in use: this swapchain's taken and not presented, the layer's presented and not yet
on the screen -- also those of an earlier swapchain on it --, plus the one on the screen;
the drawables' presented handlers count what reached it); NotReady otherwise
present(frame, cmds) the last command buffer presents the drawable
Present modes: Fifo only. Without displaySyncEnabled a window on macOS still shows at the rate of
the compositor (measured: 8.3 ms per frame either way at 120 Hz), so Immediate and Mailbox are Fifo
here, as the API allows for a missing mode. The layer's colour space is sRGB, as the CGImage of the CPU path (plat's
apple_mac.rs): both show the same pixels. Layer properties change inside a Core Animation
transaction, so a swapchain may live on another thread than the window (the UI's output job).
struct Surface(pub(crate) Arc<SurfInner>)a window as a target for swapchains
impl Surface
fn track_size(&self)the window's size now, for a swapchain made or rebuilt on a worker (call on the main thread)fn new(instance: &Instance, window: i32) -> Result<Surface>the surface of plat windowwindow: its GPU layer, shownfn native(_instance: &Instance, nw: plat::NativeWindow, window: i32) -> Result<Surface>the surface of a window given by its GPU layer (plat::win_gpu_child) whose size and state are those of plat windowwindowstruct Framea frame being drawnenum TryAcquirewhat Swapchain::try_acquire foundFrame(Frame)NotReady-- no drawable free yet (try again with the next look)Stale-- the swapchain does not fit the window any more: Swapchain::rebuild firstNoArea-- the window has no area (minimised, hidden or gone)
impl Frame
fn index(&self) -> u32fn size(&self) -> (u32, u32)struct Swapchainimages shown in a window through its CAMetalLayer
impl Device
fn create_swapchain(&self, surface: &Surface, desc: &SwapchainDesc) -> Result<Swapchain>
impl Swapchain
fn rebuild(&mut self) -> Result<()>the drawables take the window's size nowfn try_acquire(&mut self) -> Result<TryAcquire>the image to draw into, never waitingfn acquire(&mut self) -> Result<Option<Frame>>the image to draw into (waits for a drawable); None while the window has no areafn view(&self, _frame: &Frame) -> &TextureViewthe frame's image as a render targetfn texture(&self, _frame: &Frame) -> &Texturethe frame's image (copies: SwapchainDesc::copy_src)fn present<'a, I: IntoIterator<Item = CommandBuffer<'a>>>(&self, mut frame: Frame, cmds: I) -> Result<SubmitId>submit the frame's commands; the last command buffer presents its drawablefn prepare(&mut self) -> Result<bool>(Linux: the display has answered for the images; here nothing to wait for)fn flush(&self) -> Result<bool>(Linux: a frame reaches the window after the GPU finished it; Metal does that)fn busy(&self) -> boola frame is on its way to the screenfn next_look(&self, retry: u64) -> u64when a frame that found NotReady should try againfn damage(&self, _rects: Option<&[[i32; 4]]>)(Linux: what the next image changes, for the compositor; here the whole image counts)fn resize(&mut self)the next acquire takes the window's sizefn set_present_mode(&mut self, _m: PresentMode)(Fifo only: see the top)fn present_mode(&self) -> PresentModefn format(&self) -> Formatfn size(&self) -> (u32, u32)fn image_count(&self) -> usize