-
Notifications
You must be signed in to change notification settings - Fork 2
Begin refactoring of rendering engine #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,161 @@ | ||||||
| //! Buffer wrappers and builders for the platform layer. | ||||||
| //! | ||||||
| //! This module provides a thin wrapper over `wgpu::Buffer` plus a small | ||||||
| //! builder that handles common initialization patterns and keeps label and | ||||||
| //! usage metadata for debugging/inspection. | ||||||
| use crate::wgpu::{ | ||||||
| types as wgpu, | ||||||
| types::util::DeviceExt, | ||||||
| }; | ||||||
|
|
||||||
| #[derive(Clone, Copy, Debug)] | ||||||
| /// Platform buffer usage flags. | ||||||
| pub struct Usage(pub(crate) wgpu::BufferUsages); | ||||||
|
|
||||||
| impl Usage { | ||||||
| /// Vertex buffer usage. | ||||||
| pub const VERTEX: Usage = Usage(wgpu::BufferUsages::VERTEX); | ||||||
| /// Index buffer usage. | ||||||
| pub const INDEX: Usage = Usage(wgpu::BufferUsages::INDEX); | ||||||
| /// Uniform buffer usage. | ||||||
| pub const UNIFORM: Usage = Usage(wgpu::BufferUsages::UNIFORM); | ||||||
| /// Storage buffer usage. | ||||||
| pub const STORAGE: Usage = Usage(wgpu::BufferUsages::STORAGE); | ||||||
| /// Copy destination (for CPU-visible uploads). | ||||||
| pub const COPY_DST: Usage = Usage(wgpu::BufferUsages::COPY_DST); | ||||||
|
|
||||||
| pub(crate) fn to_wgpu(self) -> wgpu::BufferUsages { | ||||||
| return self.0; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl std::ops::BitOr for Usage { | ||||||
| type Output = Usage; | ||||||
| fn bitor(self, rhs: Usage) -> Usage { | ||||||
| return Usage(self.0 | rhs.0); | ||||||
|
||||||
| return Usage(self.0 | rhs.0); | |
| Usage(self.0 | rhs.0) |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary return statement. Consider removing return to follow idiomatic Rust style: Usage(wgpu::BufferUsages::VERTEX)
| return Usage(wgpu::BufferUsages::VERTEX); | |
| Usage(wgpu::BufferUsages::VERTEX) |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary return statement. Consider removing return to follow idiomatic Rust style: &self.raw
| return &self.raw; | |
| &self.raw |
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ use wgpu::rwh::{ | |||||
| use crate::winit::WindowHandle; | ||||||
|
|
||||||
| pub mod bind; | ||||||
| pub mod buffer; | ||||||
|
|
||||||
| #[derive(Debug, Clone)] | ||||||
| /// Builder for creating a `wgpu::Instance` with consistent defaults. | ||||||
|
|
@@ -342,6 +343,117 @@ impl Frame { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // ---------------------- Command Encoding Abstractions ----------------------- | ||||||
|
|
||||||
| #[derive(Debug)] | ||||||
| /// Thin wrapper around `wgpu::CommandEncoder` with convenience helpers. | ||||||
| pub struct CommandEncoder { | ||||||
| raw: wgpu::CommandEncoder, | ||||||
| } | ||||||
|
|
||||||
| impl CommandEncoder { | ||||||
| /// Create a new command encoder with an optional label. | ||||||
| pub fn new(device: &wgpu::Device, label: Option<&str>) -> Self { | ||||||
| let raw = | ||||||
| device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label }); | ||||||
| return Self { raw }; | ||||||
vmarcella marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| /// Begin a render pass targeting a single color attachment with the provided | ||||||
| /// load/store operations. Depth/stencil is not attached by this helper. | ||||||
| pub fn begin_render_pass<'view>( | ||||||
| &'view mut self, | ||||||
| label: Option<&str>, | ||||||
| view: &'view wgpu::TextureView, | ||||||
| ops: wgpu::Operations<wgpu::Color>, | ||||||
| ) -> RenderPass<'view> { | ||||||
| let color_attachment = wgpu::RenderPassColorAttachment { | ||||||
| view, | ||||||
| resolve_target: None, | ||||||
| depth_slice: None, | ||||||
| ops, | ||||||
| }; | ||||||
| let color_attachments = [Some(color_attachment)]; | ||||||
| let pass = self.raw.begin_render_pass(&wgpu::RenderPassDescriptor { | ||||||
| label, | ||||||
| color_attachments: &color_attachments, | ||||||
| depth_stencil_attachment: None, | ||||||
| timestamp_writes: None, | ||||||
| occlusion_query_set: None, | ||||||
| }); | ||||||
| return RenderPass { raw: pass }; | ||||||
|
||||||
| return RenderPass { raw: pass }; | |
| RenderPass { raw: pass } |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary return statement. Consider removing return to follow idiomatic Rust style: self.raw.finish()
| return self.raw.finish(); | |
| self.raw.finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary
returnstatement. Consider removingreturnto follow idiomatic Rust style:self.0