Skip to content

[Feature] Expose runtime MSAA toggling per-pass #106

@vmarcella

Description

@vmarcella

Overview

This feature request proposes surfacing the ability to toggle MSAA at runtime on a per-pass or per-pipeline basis while maintaining the existing efficient resource reuse pattern. This would allow applications to offer MSAA quality settings without requiring a restart.

Current State

MSAA color target management handles reuse and recreation appropriately:

  • MSAA resolve targets are created when sample_count > 1
  • Targets are recreated when sample count changes or surface resizes
  • Single pipeline sample count is set at build time

However, changing MSAA settings currently requires recreating pipelines and potentially other resources. There is no high-level API for toggling MSAA dynamically.

Scope

Goals:

  • Expose a method to change MSAA sample count at runtime
  • Maintain efficient resource reuse (only recreate what's necessary)
  • Allow per-pass MSAA configuration for hybrid rendering (e.g., 3D scene with MSAA, UI without)
  • Pipeline recreation helper or registry for sample count changes

Non-Goals:

  • Automatic quality detection based on performance
  • Temporal anti-aliasing or other AA techniques (separate feature)

Proposed API

// In crates/lambda-rs/src/render/pass.rs or similar
impl RenderContext {
  /// Change the MSAA sample count for future passes.
  ///
  /// This will trigger recreation of affected MSAA resolve targets.
  /// Pipelines using the previous sample count will need to be recreated.
  ///
  /// Valid values: 1 (disabled), 2, 4, 8 (depending on device support).
  pub fn set_sample_count(&mut self, count: u32) -> Result<(), MsaaError>;

  /// Get the current MSAA sample count.
  pub fn sample_count(&self) -> u32;
}

// Per-pass MSAA configuration
impl RenderPassBuilder {
  /// Override MSAA sample count for this pass only.
  ///
  /// Useful for rendering UI without MSAA after a scene pass with MSAA.
  pub fn with_sample_count(mut self, count: u32) -> Self;
}

// Pipeline registry helper for sample count changes
pub struct PipelineRegistry {
  // Stores pipeline configurations for recreation
}

impl PipelineRegistry {
  /// Recreate all registered pipelines with new sample count.
  pub fn update_sample_count(&mut self, gpu: &Gpu, count: u32);
}

Example Usage:

// User changes quality settings
fn on_quality_changed(ctx: &mut RenderContext, quality: QualityLevel) {
  let sample_count = match quality {
    QualityLevel::Low => 1,
    QualityLevel::Medium => 2,
    QualityLevel::High => 4,
    QualityLevel::Ultra => 8,
  };
  ctx.set_sample_count(sample_count)?;
  pipeline_registry.update_sample_count(&gpu, sample_count);
}

// Hybrid rendering: scene with MSAA, UI without
fn render_frame(ctx: &mut RenderContext) {
  // Scene pass with MSAA
  let scene_pass = RenderPassBuilder::new()
    .with_sample_count(4)
    .build();
  // ... render 3D scene ...

  // UI pass without MSAA
  let ui_pass = RenderPassBuilder::new()
    .with_sample_count(1)
    .build();
  // ... render UI ...
}

Acceptance Criteria

  • set_sample_count() method on render context or similar
  • MSAA resources correctly recreated on sample count change
  • Per-pass sample count override supported
  • Documentation explaining MSAA runtime changes and costs
  • Example demonstrating runtime MSAA toggle
  • Example demonstrating per-pass MSAA (scene + UI)

Affected Crates

lambda-rs, lambda-rs-platform

Notes

  • Sample count changes invalidate existing pipelines; consider a pipeline registry pattern
  • Device limits constrain valid sample counts (wgpu::TextureFormatFeatures::supported_sample_counts)
  • Per-pass MSAA requires careful resolve target management

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions