Expand description
GPU compute pipeline system for Tessera UI framework.
This module provides the infrastructure for GPU compute operations in Tessera, enabling advanced visual effects and post-processing operations that would be inefficient or impossible to achieve with traditional CPU-based approaches.
§Architecture Overview
The compute pipeline system is designed to work seamlessly with the rendering pipeline, using a ping-pong buffer approach for efficient multi-pass operations. Each compute pipeline processes a specific type of compute command and operates on texture data using GPU compute shaders.
§Key Components
ComputablePipeline<C>: The main trait for implementing custom compute pipelinesComputePipelineRegistry: Manages and dispatches commands to registered compute pipelinesComputeResourceManager: Manages GPU buffers and resources for compute operations
§Design Philosophy
The compute pipeline system embraces WGPU’s compute shader capabilities to enable:
- Advanced Post-Processing: Blur, contrast adjustment, color grading, and other image effects
- Parallel Processing: Leverage GPU parallelism for computationally intensive operations
- Real-Time Effects: Achieve complex visual effects at interactive frame rates
- Memory Efficiency: Use GPU memory directly without CPU roundtrips
§Ping-Pong Rendering
The system uses a ping-pong approach where:
- Input Texture: Contains the result from previous rendering or compute pass
- Output Texture: Receives the processed result from the current compute operation
- Format Convention: All textures use
wgpu::TextureFormat::Rgba8Unormfor compatibility
This approach enables efficient chaining of multiple compute operations without intermediate CPU involvement.
§Implementation Guide
§Creating a Custom Compute Pipeline
To create a custom compute pipeline:
- Define your compute command struct implementing
ComputeCommand - Create a pipeline struct implementing
ComputablePipeline<YourCommand> - Write a compute shader in WGSL
- Register the pipeline with
ComputePipelineRegistry::register
§Performance Considerations
- Workgroup Size: Choose workgroup sizes that align with GPU architecture (typically 8x8 or 16x16)
- Memory Access: Optimize memory access patterns in shaders for better cache utilization
- Resource Reuse: Use the
ComputeResourceManagerto reuse buffers across frames - Batch Operations: Combine multiple similar operations when possible
§Texture Format Requirements
Due to WGPU limitations, compute shaders require specific texture formats:
- Input Textures: Can be any readable format, typically from render passes
- Output Textures: Must use
wgpu::TextureFormat::Rgba8Unormfor storage binding - sRGB Limitation: sRGB formats cannot be used as storage textures
The framework automatically handles format conversions when necessary.
Structs§
- Compute
Batch Item - Strongly typed metadata describing a compute command within a batch.
- Compute
Context - Provides comprehensive context for compute operations within a compute pass.
- Compute
Pipeline Registry - Registry for managing and dispatching compute pipelines.
- Erased
Compute Batch Item - Type-erased metadata describing a compute command within a batch.
Traits§
- Computable
Pipeline - Core trait for implementing GPU compute pipelines.