Added conditional configurations for WASM target for gradients & storage buffers, since storage buffers are not supported on wgpu WASM target at the moment.

This commit is contained in:
bungoboingo 2022-11-10 14:43:38 -08:00
parent 23299a555f
commit 365f37a3ae
5 changed files with 27 additions and 3 deletions

View file

@ -24,6 +24,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
)
}
#[cfg(not(target_arch = "wasm32"))]
/// Creates a new dynamic storage buffer.
pub fn storage(device: &wgpu::Device, label: &'static str) -> Self {
Buffer::new(
@ -91,6 +92,7 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
Internal::Uniform(_) => {
wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST
}
#[cfg(not(target_arch = "wasm32"))]
Internal::Storage(_) => {
wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST
}
@ -154,6 +156,8 @@ impl<T: ShaderType + WriteInto> Buffer<T> {
// Currently supported dynamic buffers.
enum Internal {
Uniform(encase::DynamicUniformBuffer<Vec<u8>>),
#[cfg(not(target_arch = "wasm32"))]
//storage buffers are not supported on wgpu wasm target (yet)
Storage(encase::DynamicStorageBuffer<Vec<u8>>),
}
@ -168,6 +172,7 @@ impl Internal {
.write(value)
.expect("Error when writing to dynamic uniform buffer.")
as u32,
#[cfg(not(target_arch = "wasm32"))]
Internal::Storage(buf) => buf
.write(value)
.expect("Error when writing to dynamic storage buffer.")
@ -179,6 +184,7 @@ impl Internal {
pub(super) fn get_ref(&self) -> &Vec<u8> {
match self {
Internal::Uniform(buf) => buf.as_ref(),
#[cfg(not(target_arch = "wasm32"))]
Internal::Storage(buf) => buf.as_ref(),
}
}
@ -190,6 +196,7 @@ impl Internal {
buf.as_mut().clear();
buf.set_offset(0);
}
#[cfg(not(target_arch = "wasm32"))]
Internal::Storage(buf) => {
buf.as_mut().clear();
buf.set_offset(0);