summaryrefslogtreecommitdiffstats
path: root/wgpu/src/buffer
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-02 18:53:21 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-12-02 18:53:21 +0100
commit4029a1cdaaac1abbdcc141b20469a49670cd99b6 (patch)
tree71fa9d9c4aa1f02ce05771db43a4bb7bc6570e77 /wgpu/src/buffer
parent676d8efe03ebdbeeb95aef96b8097395b788b1ab (diff)
parent8b55e9b9e6ba0b83038dd491dd34d95b4f9a381b (diff)
downloadiced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.gz
iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.tar.bz2
iced-4029a1cdaaac1abbdcc141b20469a49670cd99b6.zip
Merge branch 'master' into non-uniform-border-radius-for-quads
Diffstat (limited to 'wgpu/src/buffer')
-rw-r--r--wgpu/src/buffer/dynamic.rs22
-rw-r--r--wgpu/src/buffer/static.rs2
2 files changed, 22 insertions, 2 deletions
diff --git a/wgpu/src/buffer/dynamic.rs b/wgpu/src/buffer/dynamic.rs
index c0c48c74..18be03dd 100644
--- a/wgpu/src/buffer/dynamic.rs
+++ b/wgpu/src/buffer/dynamic.rs
@@ -1,10 +1,13 @@
//! Utilities for uniform buffer operations.
use encase::private::WriteInto;
use encase::ShaderType;
+
+use std::fmt;
use std::marker::PhantomData;
/// A dynamic buffer is any type of buffer which does not have a static offset.
-pub(crate) struct Buffer<T: ShaderType> {
+#[derive(Debug)]
+pub struct Buffer<T: ShaderType> {
offsets: Vec<wgpu::DynamicOffset>,
cpu: Internal,
gpu: wgpu::Buffer,
@@ -24,6 +27,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 +95,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 +159,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 +175,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 +187,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 +199,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);
@@ -197,3 +207,13 @@ impl Internal {
}
}
}
+
+impl fmt::Debug for Internal {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::Uniform(_) => write!(f, "Internal::Uniform(_)"),
+ #[cfg(not(target_arch = "wasm32"))]
+ Self::Storage(_) => write!(f, "Internal::Storage(_)"),
+ }
+ }
+}
diff --git a/wgpu/src/buffer/static.rs b/wgpu/src/buffer/static.rs
index cf06790c..ef87422f 100644
--- a/wgpu/src/buffer/static.rs
+++ b/wgpu/src/buffer/static.rs
@@ -8,7 +8,7 @@ const DEFAULT_STATIC_BUFFER_COUNT: wgpu::BufferAddress = 128;
/// A generic buffer struct useful for items which have no alignment requirements
/// (e.g. Vertex, Index buffers) & no dynamic offsets.
#[derive(Debug)]
-pub(crate) struct Buffer<T> {
+pub struct Buffer<T> {
//stored sequentially per mesh iteration; refers to the offset index in the GPU buffer
offsets: Vec<wgpu::BufferAddress>,
label: &'static str,