Phase 12: Metal GPU Compositor (1/7)#
Goal: Set up the foundational Metal infrastructure in the platform crate.
Requirements#
-
Add Metal framework FFI bindings to
platformcrate:MTLCreateSystemDefaultDevice()— obtain default GPU deviceMTLDeviceprotocol:newCommandQueue,newLibraryWithSource:options:error:,newRenderPipelineStateWithDescriptor:error:,newBufferWithBytes:length:options:,newTextureWithDescriptor:MTLCommandQueue:commandBufferMTLCommandBuffer:renderCommandEncoderWithDescriptor:,presentDrawable:,commit,waitUntilCompletedCAMetalLayer:setDevice:,setPixelFormat:,nextDrawable,setFramebufferOnly:CAMetalDrawable:textureMTLRenderPassDescriptorsetup
-
Replace
WeView'sdrawRect:-based CGImage blitting with aCAMetalLayer-backed view:- Set the view's
wantsLayer = YESand replace backing layer withCAMetalLayer - Configure pixel format (
MTLPixelFormatBGRA8Unorm) - Set drawable size to match view size in points × backing scale factor
- Set the view's
-
Implement basic "clear to color" proof-of-concept:
- Create command buffer, get next drawable
- Create render pass descriptor targeting drawable texture
- Set clear color, encode empty render pass
- Present drawable and commit
-
Double-buffered presentation via
CAMetalLayer.nextDrawable
Acceptance Criteria#
-
cargo run -p we-browseropens a window with a Metal-rendered solid color background - Resize correctly updates the CAMetalLayer drawable size
- All new code is in
platformcrate (unsafe allowed here) - No external crate dependencies
-
cargo clippy --workspace -- -D warningspasses -
cargo test --workspacepasses