Skip to content

perf(lambda-rs): Cache missing per-instance vertex buffer slots#191

Merged
vmarcella merged 1 commit intomainfrom
vmarcella/optimize-render-instance-validation
Mar 8, 2026
Merged

perf(lambda-rs): Cache missing per-instance vertex buffer slots#191
vmarcella merged 1 commit intomainfrom
vmarcella/optimize-render-instance-validation

Conversation

@vmarcella
Copy link
Member

Summary

Cache missing per-instance vertex buffer slots in the render encoder so
instancing validation no longer rescans every pipeline slot on every draw.
This reduces validation overhead in instanced render passes from O(D * S) to
O(S + B + D), where D is draw calls, S is per-instance slots, and B is
vertex buffer binds.

Related Issues

Changes

  • Cache missing per-instance slots when RenderPassEncoder::set_pipeline is called.
  • Update the cache incrementally in RenderPassEncoder::set_vertex_buffer.
  • Replace per-draw full scans with a constant-time cached missing-slot check in
    draw and draw_indexed.
  • Centralize the missing-instance-binding error message in render validation helpers.
  • Add encoder tests covering both post-pipeline binding and prebound-slot cases.
  • Add rustdoc for cached instancing validation behavior and the instanced test helper.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (updates to docs, specs, tutorials, or comments)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Performance (change that improves performance)
  • Test (adding or updating tests)
  • Build/CI (changes to build process or CI configuration)

Affected Crates

  • lambda-rs
  • lambda-rs-platform
  • lambda-rs-args
  • lambda-rs-logging
  • Other:

Checklist

  • Code follows the repository style guidelines (cargo +nightly fmt --all)
  • Code passes clippy (cargo clippy --workspace --all-targets -- -D warnings)
  • Tests pass (cargo test --workspace)
  • New code includes appropriate documentation
  • Public API changes are documented
  • Breaking changes are noted in this PR description

Testing

Commands run:

cargo fmt --package lambda-rs
cargo test -p lambda-rs render_pass_encoder_ -- --nocapture
cargo test -p lambda-rs validate_instance_ -- --nocapture

Manual verification steps (if applicable):

  1. Confirmed instanced draws fail with the existing validation error until the
    required per-instance slot is bound.
  2. Confirmed binding the required instance slot after set_pipeline allows the
    draw to proceed.
  3. Confirmed prebinding the instance slot before set_pipeline is respected by
    the cached validation state.

Screenshots/Recordings

Not applicable.

Platform Testing

  • macOS
  • Windows
  • Linux

Additional Notes

@github-actions
Copy link

github-actions bot commented Mar 8, 2026

✅ Coverage Report

📊 View Full HTML Report (download artifact)

Overall Coverage

Metric Value
Total Line Coverage 76.88%
Lines Covered 12676 / 16487

Changed Files in This PR

File Coverage Lines
crates/lambda-rs/src/render/encoder.rs 85.77% 639/745
crates/lambda-rs/src/render/validation.rs 100.00% 131/131

PR Files Coverage: 87.89% (770/876 lines)


Generated by cargo-llvm-cov · Latest main coverage

Last updated: 2026-03-08 22:17:02 UTC · Commit: 4c72dfe

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes instanced draw validation in lambda-rs by caching which per-instance vertex buffer slots are missing at set_pipeline time and updating that cache incrementally on set_vertex_buffer, avoiding per-draw rescans.

Changes:

  • Cache missing per-instance vertex buffer slots during RenderPassEncoder::set_pipeline and update the cache in set_vertex_buffer.
  • Replace per-draw full scans with a cached missing-slot check in draw / draw_indexed, and centralize the missing-binding error message.
  • Add tests and rustdoc covering cached instancing validation behavior, including “bind-after-pipeline” and “prebound slot” cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/lambda-rs/src/render/validation.rs Centralizes the missing per-instance binding error message and documents the full-scan helper vs cached paths; adds a small formatter test.
crates/lambda-rs/src/render/encoder.rs Implements cached missing-slot tracking in the render pass encoder and adds targeted tests for incremental cache updates and prebound behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vmarcella vmarcella merged commit d00056e into main Mar 8, 2026
14 checks passed
@vmarcella vmarcella deleted the vmarcella/optimize-render-instance-validation branch March 8, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants