summaryrefslogtreecommitdiffstats
path: root/wgpu/src
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src')
-rw-r--r--wgpu/src/buffers.rs2
-rw-r--r--wgpu/src/buffers/dynamic.rs6
-rw-r--r--wgpu/src/shader/triangle_gradient.wgsl4
-rw-r--r--wgpu/src/shader/triangle_solid.wgsl1
-rw-r--r--wgpu/src/triangle.rs4
-rw-r--r--wgpu/src/triangle/gradient.rs4
-rw-r--r--wgpu/src/triangle/solid.rs4
7 files changed, 13 insertions, 12 deletions
diff --git a/wgpu/src/buffers.rs b/wgpu/src/buffers.rs
index 7a15692b..6b9f487c 100644
--- a/wgpu/src/buffers.rs
+++ b/wgpu/src/buffers.rs
@@ -88,7 +88,7 @@ impl<T: Pod + Zeroable> StaticBuffer<T> {
let bytes = bytemuck::cast_slice(content);
let bytes_size = bytes.len() as u64;
- if let Some(buffer_size) = wgpu::BufferSize::new(bytes_size as u64) {
+ if let Some(buffer_size) = wgpu::BufferSize::new(bytes_size) {
let mut buffer = staging_belt.write_buffer(
encoder,
&self.gpu,
diff --git a/wgpu/src/buffers/dynamic.rs b/wgpu/src/buffers/dynamic.rs
index 75cc202c..dc30c56f 100644
--- a/wgpu/src/buffers/dynamic.rs
+++ b/wgpu/src/buffers/dynamic.rs
@@ -50,6 +50,7 @@ impl DynamicBufferType {
}
}
+/// A dynamic buffer is any type of buffer which does not have a static offset.
pub(crate) struct DynamicBuffer<T: ShaderType> {
offsets: Vec<wgpu::DynamicOffset>,
cpu: DynamicBufferType,
@@ -124,13 +125,15 @@ impl<T: ShaderType + WriteInto> DynamicBuffer<T> {
/// Write a new value to the CPU buffer with proper alignment. Stores the returned offset value
/// in the buffer for future use.
pub fn push(&mut self, value: &T) {
- //this write operation on the buffer will adjust for uniform alignment requirements
+ //this write operation on the cpu buffer will adjust for uniform alignment requirements
let offset = self.cpu.write(value);
self.offsets.push(offset as u32);
}
/// Resize buffer contents if necessary. This will re-create the GPU buffer if current size is
/// less than the newly computed size from the CPU buffer.
+ ///
+ /// If the gpu buffer is resized, its bind group will need to be recreated!
pub fn resize(&mut self, device: &wgpu::Device) -> bool {
let new_size = self.cpu.get_ref().len() as u64;
@@ -144,7 +147,6 @@ impl<T: ShaderType + WriteInto> DynamicBuffer<T> {
}
};
- //Re-create the GPU buffer since it needs to be resized.
self.gpu = DynamicBuffer::<T>::create_gpu_buffer(
device, self.label, usages, new_size,
);
diff --git a/wgpu/src/shader/triangle_gradient.wgsl b/wgpu/src/shader/triangle_gradient.wgsl
index 4efda260..03ba9d88 100644
--- a/wgpu/src/shader/triangle_gradient.wgsl
+++ b/wgpu/src/shader/triangle_gradient.wgsl
@@ -1,9 +1,8 @@
-// uniforms
struct GradientUniforms {
transform: mat4x4<f32>,
//xy = start, wz = end
position: vec4<f32>,
- //x = start, y = end, zw = padding
+ //x = start stop, y = end stop, zw = padding
stop_range: vec4<i32>,
}
@@ -32,6 +31,7 @@ fn vs_main(@location(0) input: vec2<f32>) -> VertexOutput {
return output;
}
+//TODO: rewrite without branching
@fragment
fn fs_gradient(input: VertexOutput) -> @location(0) vec4<f32> {
let start = uniforms.position.xy;
diff --git a/wgpu/src/shader/triangle_solid.wgsl b/wgpu/src/shader/triangle_solid.wgsl
index be51ebb0..9eb2df24 100644
--- a/wgpu/src/shader/triangle_solid.wgsl
+++ b/wgpu/src/shader/triangle_solid.wgsl
@@ -1,4 +1,3 @@
-// uniforms
struct SolidUniforms {
transform: mat4x4<f32>,
color: vec4<f32>
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 791c9833..48ddf28a 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -12,9 +12,9 @@ use crate::triangle::solid::SolidPipeline;
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
use layer::mesh;
+mod solid;
mod gradient;
mod msaa;
-mod solid;
/// Triangle pipeline for all mesh layers in a [`iced_graphics::Canvas`] widget.
#[derive(Debug)]
@@ -60,7 +60,7 @@ impl TrianglePipelines {
}
impl Pipeline {
- /// Creates supported GL programs, listed in [TrianglePipelines].
+ /// Creates supported pipelines, listed in [TrianglePipelines].
pub fn new(
device: &wgpu::Device,
format: wgpu::TextureFormat,
diff --git a/wgpu/src/triangle/gradient.rs b/wgpu/src/triangle/gradient.rs
index 11c072ca..07551368 100644
--- a/wgpu/src/triangle/gradient.rs
+++ b/wgpu/src/triangle/gradient.rs
@@ -26,7 +26,7 @@ pub(super) struct GradientUniforms {
transform: glam::Mat4,
//xy = start, zw = end
direction: Vec4,
- //x = start, y = end, zw = padding
+ //x = start stop, y = end stop, zw = padding
stop_range: IVec4,
}
@@ -55,7 +55,7 @@ impl GradientPipeline {
);
//Note: with a WASM target storage buffers are not supported. Will need to use UBOs & static
- // sized array (eg like the 64-sized array on OpenGL side right now) to make gradients work
+ // sized array (eg like the 32-sized array on OpenGL side right now) to make gradients work
let storage_buffer = DynamicBuffer::storage(
device,
"iced_wgpu::triangle [GRADIENT] storage",
diff --git a/wgpu/src/triangle/solid.rs b/wgpu/src/triangle/solid.rs
index d2b4d13b..abba4851 100644
--- a/wgpu/src/triangle/solid.rs
+++ b/wgpu/src/triangle/solid.rs
@@ -10,13 +10,13 @@ use iced_graphics::Transformation;
pub struct SolidPipeline {
pipeline: wgpu::RenderPipeline,
- pub(crate) buffer: DynamicBuffer<SolidUniforms>,
+ pub(super) buffer: DynamicBuffer<SolidUniforms>,
bind_group_layout: wgpu::BindGroupLayout,
bind_group: wgpu::BindGroup,
}
#[derive(Debug, Clone, Copy, ShaderType)]
-pub struct SolidUniforms {
+pub(super) struct SolidUniforms {
transform: glam::Mat4,
color: Vec4,
}