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

Metal texture management and image upload #116

open opened by pierrelf.com

Phase 12: Metal GPU Compositor (3/7)#

Goal: Manage GPU textures for images and glyph data.

Depends on: Metal render pipeline: 2D shaders and vertex format

Requirements#

  • Implement MTLTexture creation and pixel data upload:

    • MTLTextureDescriptor configuration (2D, BGRA8Unorm or R8Unorm for glyphs)
    • replaceRegion:mipmapLevel:withBytes:bytesPerRow: for uploading pixel data
    • Support both RGBA8 image data and single-channel grayscale glyph data
  • Implement MTLSamplerState creation:

    • Nearest-neighbor filtering (matching current software renderer behavior)
    • Clamp-to-edge addressing
  • Add texture upload for decoded images:

    • Convert RGBA8 image data (from image crate decoders) to MTLTexture
    • Cache uploaded textures by node_id to avoid re-uploading unchanged images
    • Handle texture lifecycle (release when no longer needed)
  • Extend the Metal fragment shader to sample from textures:

    • Bind texture and sampler to fragment shader
    • Sample texture at interpolated UV coordinates
    • Multiply sampled color by vertex color for tinting

Acceptance Criteria#

  • Can create and upload RGBA8 textures to GPU
  • Can create and upload R8 (grayscale) textures to GPU
  • Texture cache avoids redundant uploads
  • Fragment shader correctly samples textures with proper alpha blending
  • Decoded PNG/JPEG images render correctly via Metal
  • 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/3mi435o7gyb2z