Skip to content

Add support for Uniform Buffer objects - #64

Merged
vmarcella merged 17 commits into
mainfrom
vmarcella/ubos
Oct 30, 2025
Merged

Add support for Uniform Buffer objects#64
vmarcella merged 17 commits into
mainfrom
vmarcella/ubos

Conversation

@vmarcella

Copy link
Copy Markdown
Member

No description provided.

CopilotAI left a comment

Copy link
Copy Markdown

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 adds comprehensive support for uniform buffer objects (UBOs) to the rendering system, enabling shaders to receive structured constant data through bind groups. The implementation spans platform bindings, high-level API wrappers, documentation, and working examples.

  • Core bind group and bind group layout builders with uniform buffer support and dynamic offset capabilities
  • Scene math utilities for common 3D transformations (model, view, projection matrices)
  • Validation helpers for alignment and offset checking
  • Complete tutorial and specification documentation with working example

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
FileDescription
docs/tutorials/uniform-buffers.mdTutorial demonstrating uniform buffer usage with a spinning triangle example
docs/tutorials/README.mdIndex page linking to the uniform buffers tutorial
docs/specs/uniform-buffers-and-bind-groups.mdSpecification detailing UBO architecture, API design, and constraints
docs/specs/_spec-template.mdTemplate for future specification documents
crates/lambda-rs/src/render/validation.rsAlignment and dynamic offset validation helpers
crates/lambda-rs/src/render/scene_math.rsCamera and transform matrix computation utilities
crates/lambda-rs/src/render/pipeline.rsPipeline builder extended with bind group layouts and culling mode
crates/lambda-rs/src/render/mod.rsModule exports and render context updates for bind groups
crates/lambda-rs/src/render/command.rsSetBindGroup command for binding resources during render passes
crates/lambda-rs/src/render/buffer.rsBuffer write utilities and UniformBuffer wrapper type
crates/lambda-rs/src/render/bind.rsHigh-level bind group and layout builders
crates/lambda-rs/examples/uniform_buffer_triangle.rsWorking example demonstrating uniform buffer usage
crates/lambda-rs/examples/push_constants.rsUpdated to use scene_math helpers
crates/lambda-rs-platform/src/wgpu/mod.rsPlatform module exports for bind functionality
crates/lambda-rs-platform/src/wgpu/bind.rsPlatform-layer bind group wrappers and builders
README.mdUpdated with tutorials section and links

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

Comment threaddocs/tutorials/uniform-buffers.md Outdated
&camera,
width.max(1),
height.max(1),
[0.0, -1.0 / 3.0, 0.0], // pivot

CopilotAIOct 24, 2025

Copy link

Choose a reason for hiding this comment

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

The inline comment for the pivot parameter does not explain why this specific value (-1/3 on Y axis) is chosen. Consider adding context about what geometric feature this pivot represents (e.g., 'pivot at triangle centroid' or 'pivot at geometric center').

Suggested change
[0.0, -1.0 / 3.0, 0.0], // pivot
[0.0, -1.0 / 3.0, 0.0], // pivot at triangle centroid (geometric center)

Copilot uses AI. Check for mistakes.
}
let align = alignment.max(1);
for (i, off) in offsets.iter().enumerate() {
if (*off as u32) % align != 0 {

CopilotAIOct 24, 2025

Copy link

Choose a reason for hiding this comment

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

The cast (*off as u32) is redundant since off is already dereferenced from &[u32] and is therefore type u32. Simplify to if *off % align != 0.

Suggested change
if(*offasu32) % align != 0{
if*off % align != 0{

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +162
pub fn with_layouts(mut self, layouts: &[&bind::BindGroupLayout]) -> Self {
self.bind_group_layouts = layouts
.iter()
.map(|l| std::rc::Rc::new(l.raw().clone()))

CopilotAIOct 24, 2025

Copy link

Choose a reason for hiding this comment

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

Cloning the underlying wgpu::BindGroupLayout for each layout entry may be expensive. Consider whether the high-level BindGroupLayout can be stored directly with Rc to avoid cloning the GPU resource, or document why the clone is necessary here.

Suggested change
pubfn with_layouts(mutself,layouts:&[&bind::BindGroupLayout]) -> Self{
self.bind_group_layouts = layouts
.iter()
.map(|l| std::rc::Rc::new(l.raw().clone()))
pubfn with_layouts(mutself,layouts:&[std::rc::Rc<bind::BindGroupLayout>]) -> Self{
self.bind_group_layouts = layouts
.iter()
.cloned()

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +134
let bytes = unsafe {
std::slice::from_raw_parts(
(data as *const T) as *const u8,
std::mem::size_of::<T>(),
)
};

CopilotAIOct 24, 2025

Copy link

Choose a reason for hiding this comment

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

The unsafe block lacks a SAFETY comment explaining why the raw pointer dereference is safe. Add documentation stating that data is a valid reference to T, T is Copy (ensuring no invalid bit patterns), and the lifetime of the slice does not exceed the borrow of data.

Copilot uses AI. Check for mistakes.
&camera,
self.width.max(1),
self.height.max(1),
[0.0, -1.0 / 3.0, 0.0],

CopilotAIOct 24, 2025

Copy link

Choose a reason for hiding this comment

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

The magic number -1.0 / 3.0 appears multiple times in the file (lines 195, 300) without explanation. Consider defining this as a named constant like TRIANGLE_PIVOT_Y to improve code clarity and maintainability.

Copilot uses AI. Check for mistakes.
@vmarcella
vmarcella merged commit d3dc435 into mainOct 30, 2025
5 checks passed
@vmarcella
vmarcella deleted the vmarcella/ubos branch October 30, 2025 21:42
Sign up for freeto 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

@vmarcella