Module pipeline

Module pipeline 

Source
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

§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:

  1. Input Texture: Contains the result from previous rendering or compute pass
  2. Output Texture: Receives the processed result from the current compute operation
  3. Format Convention: All textures use wgpu::TextureFormat::Rgba8Unorm for 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:

  1. Define your compute command struct implementing ComputeCommand
  2. Create a pipeline struct implementing ComputablePipeline<YourCommand>
  3. Write a compute shader in WGSL
  4. 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 ComputeResourceManager to 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::Rgba8Unorm for storage binding
  • sRGB Limitation: sRGB formats cannot be used as storage textures

The framework automatically handles format conversions when necessary.

Structs§

ComputeBatchItem
Strongly typed metadata describing a compute command within a batch.
ComputeContext
Provides comprehensive context for compute operations within a compute pass.
ComputePipelineRegistry
Registry for managing and dispatching compute pipelines.
ErasedComputeBatchItem
Type-erased metadata describing a compute command within a batch.

Traits§

ComputablePipeline
Core trait for implementing GPU compute pipelines.