Skip to content

[Feature] Expose Present Mode and VSync Configuration in RenderContextBuilder #82

@vmarcella

Description

@vmarcella

Overview

Plumb the existing with_vsync flag from WindowBuilder through to RenderContextBuilder (Or one of it's settings) and expose explicit PresentMode selection for users.

Current State

WindowBuilder has a with_vsync method, but it is currently a no-op:

// crates/lambda-rs/src/render/window.rs
/// Request vertical sync behavior for the swapchain.
///
/// Note: present mode is ultimately selected when configuring the rendering
/// surface in `RenderContextBuilder`. This flag is reserved to influence
/// that choice and is currently a no‑op.
pub fn with_vsync(mut self, vsync: bool) -> Self {
  self.vsync = vsync;
  return self;
}

And within the platform layer, we already support present mode selection:

// crates/lambda-rs-platform/src/wgpu/surface.rs
pub enum PresentMode {
  Fifo,        // VSync on
  Immediate,   // VSync off, may tear
  Mailbox,     // Triple buffering
  AutoVsync,
  // ...
}

But RenderContextBuilder::build() currently hardcodes PresentMode::Fifo for the surface.

Scope

  • Add with_vsync(bool) to RenderContextBuilderthat maps toFifowhen true, or Immediate/Mailbox` when not.
  • Add with_present_mode(PresentMode) for explicit control
  • Expose higher level PresentMode enum in lambda-rs
  • Validate requested mode against adapter capabilities; fall back to something that is supported if the requested mode is not available.

Proposed API

// crates/lambda-rs/src/render/mod.rs
pub enum PresentMode {
  /// VSync enabled, capped to display refresh rate (FIFO).
  Vsync,
  /// VSync disabled, immediate presentation (may tear).
  Immediate,
  /// Triple buffering, low latency without tearing if supported.
  Mailbox,
}

impl RenderContextBuilder {
  /// Enable or disable vertical sync (defaults to enabled).
  pub fn with_vsync(mut self, enabled: bool) -> Self;
  
  /// Explicitly select a presentation mode.
  pub fn with_present_mode(mut self, mode: PresentMode) -> Self;
}

Acceptance Criteria

  • RenderContextBuilder::with_vsync(bool) to enable vsync
  • RenderContextBuilder::with_present_mode(PresentMode) for explicit selection
  • PresentMode implementation in lambda-rs
  • Adapter validation and fallback support
  • Documentation and example Usage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions