we (web engine): Experimental web browser project to understand the limits of Claude

Metal device, command queue, and CAMetalLayer setup #114

open opened by pierrelf.com

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 platform crate:

    • MTLCreateSystemDefaultDevice() — obtain default GPU device
    • MTLDevice protocol: newCommandQueue, newLibraryWithSource:options:error:, newRenderPipelineStateWithDescriptor:error:, newBufferWithBytes:length:options:, newTextureWithDescriptor:
    • MTLCommandQueue: commandBuffer
    • MTLCommandBuffer: renderCommandEncoderWithDescriptor:, presentDrawable:, commit, waitUntilCompleted
    • CAMetalLayer: setDevice:, setPixelFormat:, nextDrawable, setFramebufferOnly:
    • CAMetalDrawable: texture
    • MTLRenderPassDescriptor setup
  • Replace WeView's drawRect:-based CGImage blitting with a CAMetalLayer-backed view:

    • Set the view's wantsLayer = YES and replace backing layer with CAMetalLayer
    • Configure pixel format (MTLPixelFormatBGRA8Unorm)
    • Set drawable size to match view size in points × backing scale factor
  • 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-browser opens a window with a Metal-rendered solid color background
  • Resize correctly updates the CAMetalLayer drawable size
  • All new code is in platform crate (unsafe allowed here)
  • No external crate dependencies
  • cargo clippy --workspace -- -D warnings passes
  • cargo test --workspace passes
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mi434slnsv2g