Skip to content

Improve WGPU buffer handling#422

Merged
mkeeter merged 7 commits into
mainfrom
wgpu-buffers
Jun 11, 2026
Merged

Improve WGPU buffer handling#422
mkeeter merged 7 commits into
mainfrom
wgpu-buffers

Conversation

@mkeeter

@mkeeter mkeeter commented Jun 10, 2026

Copy link
Copy Markdown
Owner
  • Move the resizable Buffer to the crate root and rename it GenericFlexBuffer
    • Make the buffer size (as an item count) a generic parameter
    • Make the buffer item type a generic parameter
    • Move usage to a const U: u32 on the buffer, so it's specified at compile time
    • Move buffer errors to the crate root as well
  • Add helper types for ArrayBuffer and ImageBuffer, which take different size types

Copilot AI 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 refactors GPU buffer management in fidget-wgpu by replacing the bespoke resizable Buffer with a generic, item-count-based flex buffer type hosted at the crate root, and updates voxel rendering code to use typed buffer wrappers for array- and image-shaped allocations. It also refines fidget-raster’s size/config traits by renaming ImageSizeLike to RenderSize and restructuring RenderConfig to inherit width/height via that trait.

Changes:

  • Replace the old growable WGPU Buffer in fidget-wgpu::voxel with crate-root generic buffer helpers (ArrayBuffer / ImageBuffer) plus shared buffer sizing errors/types.
  • Update voxel rendering buffer sizing APIs to use item counts (usize) and introduce ImageSize-based sizing for image-shaped buffers.
  • Rename/reshape raster size traits: ImageSizeLikeRenderSize, and make RenderConfig: RenderSize.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
fidget-wgpu/src/voxel.rs Switch voxel pipeline buffers over to typed flex buffers and item-count/image-size sizing helpers.
fidget-wgpu/src/lib.rs Introduce crate-root generic flex buffer implementation plus shared buffer sizing errors/types and usage constants.
fidget-raster/src/voxel.rs Update 3D raster config to implement the new RenderConfig + RenderSize traits.
fidget-raster/src/pixel.rs Update 2D raster config to implement the new RenderConfig + RenderSize traits.
fidget-raster/src/lib.rs Define RenderSize, adjust RenderConfig to inherit size, and update Image generics accordingly.
CHANGELOG.md Document the ImageSizeLikeRenderSize rename and RenderConfig: RenderSize change.

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

Comment thread fidget-wgpu/src/lib.rs Outdated
Comment on lines +122 to +126
let size =
u64::try_from(item_count * std::mem::size_of::<T>()).unwrap();
assert_eq!(size % 4, 0);
let usage = wgpu::BufferUsages::from_bits(U).unwrap();
Self::check_size(usage, size)?;
Comment thread fidget-wgpu/src/lib.rs
Comment thread fidget-wgpu/src/lib.rs Outdated
Comment thread fidget-wgpu/src/lib.rs
Comment thread fidget-wgpu/src/lib.rs
Comment thread fidget-wgpu/src/lib.rs
Comment thread fidget-wgpu/src/voxel.rs Outdated
Comment on lines 1994 to 1996
nx * ny * nz
+ (nx * ny) * ((64usize / 16).pow(3) + (64usize / 4).pow(3))
}
Comment thread fidget-wgpu/src/voxel.rs Outdated
Comment on lines 2003 to 2006
fn geom_buf_size(image_size: VoxelSize) -> usize {
usize::try_from(image_size.width()).unwrap()
* usize::try_from(image_size.height()).unwrap()
}
Comment thread fidget-wgpu/src/voxel.rs Outdated
Comment on lines +2008 to +2011
fn image_buf_size(image_size: VoxelSize) -> usize {
// Allocate an extra 16 bytes for timestamp queries
Self::geom_buf_size(image_size) + 16
Self::geom_buf_size(image_size) * std::mem::size_of::<GeometryPixel>()
+ 16
@mkeeter mkeeter merged commit 6eb0fca into main Jun 11, 2026
14 checks passed
@mkeeter mkeeter deleted the wgpu-buffers branch June 11, 2026 15:22
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