`Mesh` interface works against performance
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
The `Mesh` interface works with separate arrays of attributes, in an SoA fashion. GPU vertex buffers need packed vertices with all attributes, in an AoS fashion. This means the `Mesh` interface by design forces a costly repacking of data, even though the user might already have a proper GPU representation available.
In a custom project, building a mesh of cubes on a grid of 128^3, `allocate_and_free_meshes()` takes 150.8ms (Tracy), of which over 40% seems in `write_packed_vertex_buffer_data()` and about 30% in `create_buffer()` (VS profiler). Running in release with `-C target-cpu=native`.
## What solution would you like?
- An interface with a way to provide packed attribute data already laid out correctly.
- An interface with a way to pre-allocate a buffer and reuse it, so that I can quickly switch between grid resolution for live preview without re-allocating a GPU buffer each time (only need to update the vertex data).
## What alternative(s) have you considered?
Create a separate abstraction where I manage all `wgpu` objects manually, like Hanabi does. This feels terribly sad for a mesh buffer.
## Additional context
Trying to make a live preview of some algorithm, and I need to modify a mesh dynamically each time the user makes a change in some parameters. Ideally this should be interactive; currently this runs at 0.25 FPS, and between half and 2/3rd of the time is lost in the `Mesh` interface (the remaining is on my CPU algorithm, which is being optimized and should slim down).
Contributor guide
Research direction
Start by profiling the Mesh path around allocate_and_free_meshes(), especially write_packed_vertex_buffer_data() and create_buffer(), using the reported Tracy and VS profiler measurements. Review the existing Mesh interface and how it creates wgpu objects. Done should include a supported path for packed vertex data and buffer reuse, with evidence that dynamic mesh updates avoid the reported allocation and repacking costs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100