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
MTLTexturecreation and pixel data upload:MTLTextureDescriptorconfiguration (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
MTLSamplerStatecreation:- Nearest-neighbor filtering (matching current software renderer behavior)
- Clamp-to-edge addressing
-
Add texture upload for decoded images:
- Convert RGBA8 image data (from
imagecrate decoders) to MTLTexture - Cache uploaded textures by node_id to avoid re-uploading unchanged images
- Handle texture lifecycle (release when no longer needed)
- Convert RGBA8 image data (from
-
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 warningspasses -
cargo test --workspacepasses