Improve WGPU buffer handling#422
Merged
Merged
Conversation
There was a problem hiding this comment.
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
Bufferinfidget-wgpu::voxelwith 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 introduceImageSize-based sizing for image-shaped buffers. - Rename/reshape raster size traits:
ImageSizeLike→RenderSize, and makeRenderConfig: 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 ImageSizeLike → RenderSize rename and RenderConfig: RenderSize change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 on lines
1994
to
1996
| nx * ny * nz | ||
| + (nx * ny) * ((64usize / 16).pow(3) + (64usize / 4).pow(3)) | ||
| } |
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 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bufferto the crate root and rename itGenericFlexBufferconst U: u32on the buffer, so it's specified at compile timeArrayBufferandImageBuffer, which take different size types