diff options
| author | 2022-11-10 14:43:38 -0800 | |
|---|---|---|
| committer | 2022-11-10 15:25:54 -0800 | |
| commit | 365f37a3ae10e7aff407b84050f77da10820866e (patch) | |
| tree | 471643b7f81019ef9cb0328c6d5ac6f4c625c90e /wgpu/src | |
| parent | 23299a555f8b7e908a6a14915307792a7cf97b9a (diff) | |
| download | iced-365f37a3ae10e7aff407b84050f77da10820866e.tar.gz iced-365f37a3ae10e7aff407b84050f77da10820866e.tar.bz2 iced-365f37a3ae10e7aff407b84050f77da10820866e.zip | |
Added conditional configurations for WASM target for gradients & storage buffers, since storage buffers are not supported on wgpu WASM target at the moment.
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/buffer/dynamic.rs | 7 | ||||
| -rw-r--r-- | wgpu/src/triangle.rs | 15 | 
2 files changed, 20 insertions, 2 deletions
| diff --git a/wgpu/src/buffer/dynamic.rs b/wgpu/src/buffer/dynamic.rs index c0c48c74..2a675d81 100644 --- a/wgpu/src/buffer/dynamic.rs +++ b/wgpu/src/buffer/dynamic.rs @@ -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); diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index f9abf2b5..c51b5339 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -1,4 +1,5 @@  //! Draw meshes of triangles. +#[cfg(not(target_arch = "wasm32"))]  mod gradient;  mod msaa;  mod solid; @@ -27,6 +28,8 @@ pub(crate) struct Pipeline {  /// Supported triangle pipelines for different fills.  pub(crate) struct PipelineList {      solid: solid::Pipeline, +    /// Gradients are currently not supported on WASM targets due to their need of storage buffers. +    #[cfg(not(target_arch = "wasm32"))]      gradient: gradient::Pipeline,  } @@ -40,8 +43,11 @@ impl PipelineList {      /// Resets each pipeline's buffers.      fn clear(&mut self) {          self.solid.buffer.clear(); -        self.gradient.uniform_buffer.clear(); -        self.gradient.storage_buffer.clear(); +        #[cfg(not(target_arch = "wasm32"))] +        { +            self.gradient.uniform_buffer.clear(); +            self.gradient.storage_buffer.clear(); +        }      }      /// Writes the contents of each pipeline's CPU buffer to the GPU, resizing the GPU buffer @@ -53,6 +59,7 @@ impl PipelineList {          encoder: &mut wgpu::CommandEncoder,      ) {          self.solid.write(device, staging_belt, encoder); +        #[cfg(not(target_arch = "wasm32"))]          self.gradient.write(device, staging_belt, encoder);      }  } @@ -79,6 +86,7 @@ impl Pipeline {              index_strides: Vec::new(),              pipelines: PipelineList {                  solid: solid::Pipeline::new(device, format, antialiasing), +                #[cfg(not(target_arch = "wasm32"))]                  gradient: gradient::Pipeline::new(device, format, antialiasing),              },          } @@ -145,6 +153,7 @@ impl Pipeline {                  triangle::Style::Solid(color) => {                      self.pipelines.solid.push(transform, color);                  } +                #[cfg(not(target_arch = "wasm32"))]                  triangle::Style::Gradient(gradient) => {                      self.pipelines.gradient.push(transform, gradient);                  } @@ -186,6 +195,7 @@ impl Pipeline {                  });              let mut num_solids = 0; +            #[cfg(not(target_arch = "wasm32"))]              let mut num_gradients = 0;              let mut last_is_solid = None; @@ -216,6 +226,7 @@ impl Pipeline {                          num_solids += 1;                      } +                    #[cfg(not(target_arch = "wasm32"))]                      triangle::Style::Gradient(_) => {                          if last_is_solid.unwrap_or(true) {                              self.pipelines | 
