Fixed some more imports/documentation.

This commit is contained in:
shan 2022-10-06 19:41:00 -07:00
parent 72feba51be
commit f9a6efcaa0
12 changed files with 28 additions and 26 deletions

View file

@ -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,

View file

@ -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,
);

View file

@ -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;

View file

@ -1,4 +1,3 @@
// uniforms
struct SolidUniforms {
transform: mat4x4<f32>,
color: vec4<f32>

View file

@ -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,

View file

@ -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",

View file

@ -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,
}