Easy WGPU:
This crate provides a wrapper on wgpu. It is still in an early state and changes can happen that break existing code. The main focus is to make the writing of graphics application, for which engines are too high level, easy. This crate therefore re-implements some of the types from wgpu using generics to make it safer and easier. Though the main goal is comfort, runtime performance should not be impacted.
Examples:
Wgpu Buffers can be unsafe when types do not match:
let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
label: None,
contents: bytemuck::cast_slice(data),
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::MAP_READ,
});
When reading the buffer back from the GPU it is not guaranteed that the buffer has the same format.
In this library:
let buffer = BufferBuilder::new()
.storage().read().write()
.append_slice(&[0, 1, 2, 3])
.build(device);
Now when reading the buffer back the mapped slice is of the same type as the provided data and therefore no "undefined behaviour" will occur.
This library also provides builders for some of its types since they are easier to use than wgpu's descriptors since they can provide sane defaults whilst still allowing detailed configuration.
Motivation:
I have noticed that nearly all projects using wgpu that are listed on their website https://wgpu.rs/ (bevy, Veloren, blub) implement somewhat common wrappers around wgpu to make it easier and safer to program with it.
Features:
- Buffers with type generics to prevent wrong casts.
- BindGroup generics that allow grouping of bind groups.
- BindGroup(Layout) builders.
- A framework for initializing a window and handling states.
- Generic mesh and model structs.
- Fragment/Vertex State builders.
- Pipeline layout builder.
- A seperate RenderPassPipeline type that could be used for predefined pipeline layouts.
- ComputePipeline builder.
- RenderPass builder.
- RenderPipeline builder.
- Render Target functions simplifying use of multiple color attachments.
- Texture with load and new functions.
- Uniforms with generic types.
- Vert2 default vertex struct.
- Vert3 default vertex struct.
Goals:
Hide all operations in wgpu that could result in panics and/or undefined behaviour behind rust's safety infrastructure if possible. And make it as easy as possible to write simple graphics programs.
Immediate Goals:
- Write unit tests for all testable modules.
- Rename all generic default names from C to T.