Crates.io | ewgpu |
lib.rs | ewgpu |
version | 0.1.0 |
source | src |
created_at | 2022-03-29 20:06:45.919277 |
updated_at | 2022-03-29 20:06:45.919277 |
description | An easy wrapper for WGPU. |
homepage | |
repository | https://github.com/DoeringChristian/ewgpu/ |
max_upload_size | |
id | 558776 |
size | 140,183 |
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.
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.
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.
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.