summaryrefslogtreecommitdiffstats
path: root/wgpu/src/quad.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-05-24 20:26:56 +0700
committerLibravatar GitHub <noreply@github.com>2021-05-24 20:26:56 +0700
commitdf971ac99beedb41537763f95f7b14d8bf7475a8 (patch)
tree70bf9d7aac84ae05f841b51dca6eb66c1769de93 /wgpu/src/quad.rs
parent3918257883dba3cf260bd9764cb7b34101c435e6 (diff)
parent4cbc34524598756ce18cb25a664bc6f256d42851 (diff)
downloadiced-df971ac99beedb41537763f95f7b14d8bf7475a8.tar.gz
iced-df971ac99beedb41537763f95f7b14d8bf7475a8.tar.bz2
iced-df971ac99beedb41537763f95f7b14d8bf7475a8.zip
Merge pull request #830 from Dispersia/upgrade-wgpu
Upgrade wgpu
Diffstat (limited to 'wgpu/src/quad.rs')
-rw-r--r--wgpu/src/quad.rs91
1 files changed, 46 insertions, 45 deletions
diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs
index e0a6e043..6f221ca3 100644
--- a/wgpu/src/quad.rs
+++ b/wgpu/src/quad.rs
@@ -28,7 +28,7 @@ impl Pipeline {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new(
- mem::size_of::<Uniforms>() as u64,
+ mem::size_of::<Uniforms>() as wgpu::BufferAddress,
),
},
count: None,
@@ -37,7 +37,7 @@ impl Pipeline {
let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("iced_wgpu::quad uniforms buffer"),
- size: mem::size_of::<Uniforms>() as u64,
+ size: mem::size_of::<Uniforms>() as wgpu::BufferAddress,
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
mapped_at_creation: false,
});
@@ -47,11 +47,7 @@ impl Pipeline {
layout: &constant_layout,
entries: &[wgpu::BindGroupEntry {
binding: 0,
- resource: wgpu::BindingResource::Buffer {
- buffer: &constants_buffer,
- offset: 0,
- size: None,
- },
+ resource: constants_buffer.as_entire_binding(),
}],
});
@@ -62,28 +58,29 @@ impl Pipeline {
bind_group_layouts: &[&constant_layout],
});
- let vs_module = device.create_shader_module(&wgpu::include_spirv!(
- "shader/quad.vert.spv"
- ));
-
- let fs_module = device.create_shader_module(&wgpu::include_spirv!(
- "shader/quad.frag.spv"
- ));
+ let shader =
+ device.create_shader_module(&wgpu::ShaderModuleDescriptor {
+ label: Some("iced_wgpu::quad::shader"),
+ source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
+ include_str!("shader/quad.wgsl"),
+ )),
+ flags: wgpu::ShaderFlags::all(),
+ });
let pipeline =
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu::quad pipeline"),
layout: Some(&layout),
vertex: wgpu::VertexState {
- module: &vs_module,
- entry_point: "main",
+ module: &shader,
+ entry_point: "vs_main",
buffers: &[
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Vertex>() as u64,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
shader_location: 0,
- format: wgpu::VertexFormat::Float2,
+ format: wgpu::VertexFormat::Float32x2,
offset: 0,
}],
},
@@ -93,32 +90,32 @@ impl Pipeline {
attributes: &[
wgpu::VertexAttribute {
shader_location: 1,
- format: wgpu::VertexFormat::Float2,
+ format: wgpu::VertexFormat::Float32x2,
offset: 0,
},
wgpu::VertexAttribute {
shader_location: 2,
- format: wgpu::VertexFormat::Float2,
+ format: wgpu::VertexFormat::Float32x2,
offset: 4 * 2,
},
wgpu::VertexAttribute {
shader_location: 3,
- format: wgpu::VertexFormat::Float4,
+ format: wgpu::VertexFormat::Float32x4,
offset: 4 * (2 + 2),
},
wgpu::VertexAttribute {
shader_location: 4,
- format: wgpu::VertexFormat::Float4,
+ format: wgpu::VertexFormat::Float32x4,
offset: 4 * (2 + 2 + 4),
},
wgpu::VertexAttribute {
shader_location: 5,
- format: wgpu::VertexFormat::Float,
+ format: wgpu::VertexFormat::Float32,
offset: 4 * (2 + 2 + 4 + 4),
},
wgpu::VertexAttribute {
shader_location: 6,
- format: wgpu::VertexFormat::Float,
+ format: wgpu::VertexFormat::Float32,
offset: 4 * (2 + 2 + 4 + 4 + 1),
},
],
@@ -126,27 +123,28 @@ impl Pipeline {
],
},
fragment: Some(wgpu::FragmentState {
- module: &fs_module,
- entry_point: "main",
+ module: &shader,
+ entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
format,
- color_blend: wgpu::BlendState {
- src_factor: wgpu::BlendFactor::SrcAlpha,
- dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
- operation: wgpu::BlendOperation::Add,
- },
- alpha_blend: wgpu::BlendState {
- src_factor: wgpu::BlendFactor::One,
- dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
- operation: wgpu::BlendOperation::Add,
- },
+ blend: Some(wgpu::BlendState {
+ color: wgpu::BlendComponent {
+ src_factor: wgpu::BlendFactor::SrcAlpha,
+ dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
+ operation: wgpu::BlendOperation::Add,
+ },
+ alpha: wgpu::BlendComponent {
+ src_factor: wgpu::BlendFactor::One,
+ dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
+ operation: wgpu::BlendOperation::Add,
+ },
+ }),
write_mask: wgpu::ColorWrite::ALL,
}],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Cw,
- cull_mode: wgpu::CullMode::None,
..Default::default()
},
depth_stencil: None,
@@ -237,16 +235,14 @@ impl Pipeline {
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::quad render pass"),
- color_attachments: &[
- wgpu::RenderPassColorAttachmentDescriptor {
- attachment: target,
- resolve_target: None,
- ops: wgpu::Operations {
- load: wgpu::LoadOp::Load,
- store: true,
- },
+ color_attachments: &[wgpu::RenderPassColorAttachment {
+ view: target,
+ resolve_target: None,
+ ops: wgpu::Operations {
+ load: wgpu::LoadOp::Load,
+ store: true,
},
- ],
+ }],
depth_stencil_attachment: None,
});
@@ -309,6 +305,9 @@ const MAX_INSTANCES: usize = 100_000;
struct Uniforms {
transform: [f32; 16],
scale: f32,
+ // Uniforms must be aligned to their largest member,
+ // this uses a mat4x4<f32> which aligns to 16, so align to that
+ _padding: [f32; 3],
}
impl Uniforms {
@@ -316,6 +315,7 @@ impl Uniforms {
Self {
transform: *transformation.as_ref(),
scale,
+ _padding: [0.0; 3],
}
}
}
@@ -325,6 +325,7 @@ impl Default for Uniforms {
Self {
transform: *Transformation::identity().as_ref(),
scale: 1.0,
+ _padding: [0.0; 3],
}
}
}