Repository navigation
perf(player): draw the frames into the window swapchain instead of reading them back - #224
Conversation
…ading them back The Metal backend draws into the drawables of a CAMetalLayer of the window and the Vulkan backend into the images of a VkSwapchainKHR. The CPU backend draws into the softbuffer pixel buffer of the window.
…is drawn With `PlayerOptions::vsync` set to false the Metal layer does not wait for the display and the Vulkan swapchain presents in the immediate or the mailbox mode. Vsync stays on by default.
…e title The counter counted the frames taken from the scheduler, and a frame can be replaced before a redraw shows it. With vsync it showed 128 fps on a 120 Hz display.
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://perf-player-present-to-window-fframes.dmitriy-86d.workers.dev (commit 35693e6)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
The native player draws each frame into the swapchain of the window: a
CAMetalLayerdrawable with Metal, aVkSwapchainKHRimage with Vulkan. The player no longer reads the frame back from the GPU and copies it through softbuffer, and the CPU backend draws into the softbuffer pixel buffer directly.PlayerOptions::vsync = falseshows each frame without a wait for the display refresh, and the fps in the title counts the frames drawn into the window.flowchart LR subgraph before A[Skia on the GPU] --> B[offscreen texture] --> C[read_pixels into RAM] --> D[softbuffer upload] --> E[window] end subgraph after F[Skia on the GPU] --> G[swapchain image of the window] --> H[window] endMeasured with
examples/hello_worldon an M4 Max, 120 Hz display, window about 3150x2194 px, 30 s per run. "Late" is the time from the moment a frame is due to the moment it is on screen.30 fps video
present()mean120 fps video
500 fps video,
vsync: falseBefore the fix the title showed 128 fps for this video with vsync on, but only 119 frames per second reached the window. It now shows 118 to 120.
Note
Metal, Vulkan and the CPU backend give the same pixel values for the same frame (the Metal layer has the sRGB color space). On Linux and Windows only the type check of the Xlib, Xcb, Wayland and Win32 surface code was done, not a run.
Note
New public API in
fframes_skia_renderer:SkiaVulkanCtx::new_with_instance_extensions, the accessorsentry,instance,physical_device,device,queue_family_index,create_contextwithVulkanContext, andSkiaMetalCtx::device,command_queue,create_context.Important
The player still waits for the GPU after each frame. The images of video frames point into the pixel buffers of the tree, and the next frame drops the tree.
Summary by CodeRabbit