summaryrefslogtreecommitdiffstats
path: root/wgpu/src/triangle
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-07 05:48:21 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-07 05:48:21 +0200
commitd807ef367e0257ba54f8cf38708a7a61e28a4acb (patch)
tree1ee065aa7f47cc9a3e3e642c9b58576dd54d3327 /wgpu/src/triangle
parent703beae05ec2988b9a6b15e84291ec818b37bf5b (diff)
downloadiced-d807ef367e0257ba54f8cf38708a7a61e28a4acb.tar.gz
iced-d807ef367e0257ba54f8cf38708a7a61e28a4acb.tar.bz2
iced-d807ef367e0257ba54f8cf38708a7a61e28a4acb.zip
Update `wgpu` to `0.5` in `iced_wgpu` :tada:
Diffstat (limited to '')
-rw-r--r--wgpu/src/triangle.rs90
-rw-r--r--wgpu/src/triangle/msaa.rs23
2 files changed, 63 insertions, 50 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 51a6f954..471abe22 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -2,6 +2,7 @@
use crate::{settings, Transformation};
use iced_native::{Point, Rectangle};
use std::mem;
+use zerocopy::AsBytes;
mod msaa;
@@ -34,6 +35,7 @@ impl<T> Buffer<T> {
usage: wgpu::BufferUsage,
) -> Self {
let raw = device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
size: (std::mem::size_of::<T>() * size) as u64,
usage,
});
@@ -49,6 +51,7 @@ impl<T> Buffer<T> {
pub fn ensure_capacity(&mut self, device: &wgpu::Device, size: usize) {
if self.size < size {
self.raw = device.create_buffer(&wgpu::BufferDescriptor {
+ label: None,
size: (std::mem::size_of::<T>() * size) as u64,
usage: self.usage,
});
@@ -66,7 +69,8 @@ impl Pipeline {
) -> Pipeline {
let constant_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
- bindings: &[wgpu::BindGroupLayoutBinding {
+ label: None,
+ bindings: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer { dynamic: true },
@@ -81,6 +85,7 @@ impl Pipeline {
let constant_bind_group =
device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: None,
layout: &constant_layout,
bindings: &[wgpu::Binding {
binding: 0,
@@ -142,25 +147,27 @@ impl Pipeline {
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
- index_format: wgpu::IndexFormat::Uint32,
- vertex_buffers: &[wgpu::VertexBufferDescriptor {
- stride: mem::size_of::<Vertex2D>() as u64,
- step_mode: wgpu::InputStepMode::Vertex,
- attributes: &[
- // Position
- wgpu::VertexAttributeDescriptor {
- shader_location: 0,
- format: wgpu::VertexFormat::Float2,
- offset: 0,
- },
- // Color
- wgpu::VertexAttributeDescriptor {
- shader_location: 1,
- format: wgpu::VertexFormat::Float4,
- offset: 4 * 2,
- },
- ],
- }],
+ vertex_state: wgpu::VertexStateDescriptor {
+ index_format: wgpu::IndexFormat::Uint32,
+ vertex_buffers: &[wgpu::VertexBufferDescriptor {
+ stride: mem::size_of::<Vertex2D>() as u64,
+ step_mode: wgpu::InputStepMode::Vertex,
+ attributes: &[
+ // Position
+ wgpu::VertexAttributeDescriptor {
+ shader_location: 0,
+ format: wgpu::VertexFormat::Float2,
+ offset: 0,
+ },
+ // Color
+ wgpu::VertexAttributeDescriptor {
+ shader_location: 1,
+ format: wgpu::VertexFormat::Float4,
+ offset: 4 * 2,
+ },
+ ],
+ }],
+ },
sample_count: antialiasing
.map(|a| a.sample_count())
.unwrap_or(1),
@@ -230,19 +237,15 @@ impl Pipeline {
.into(),
};
- let vertex_buffer = device
- .create_buffer_mapped(
- mesh.vertices.len(),
- wgpu::BufferUsage::COPY_SRC,
- )
- .fill_from_slice(&mesh.vertices);
+ let vertex_buffer = device.create_buffer_with_data(
+ mesh.vertices.as_bytes(),
+ wgpu::BufferUsage::COPY_SRC,
+ );
- let index_buffer = device
- .create_buffer_mapped(
- mesh.indices.len(),
- wgpu::BufferUsage::COPY_SRC,
- )
- .fill_from_slice(&mesh.indices);
+ let index_buffer = device.create_buffer_with_data(
+ mesh.indices.as_bytes(),
+ wgpu::BufferUsage::COPY_SRC,
+ );
encoder.copy_buffer_to_buffer(
&vertex_buffer,
@@ -271,9 +274,10 @@ impl Pipeline {
last_index += mesh.indices.len();
}
- let uniforms_buffer = device
- .create_buffer_mapped(uniforms.len(), wgpu::BufferUsage::COPY_SRC)
- .fill_from_slice(&uniforms);
+ let uniforms_buffer = device.create_buffer_with_data(
+ uniforms.as_bytes(),
+ wgpu::BufferUsage::COPY_SRC,
+ );
encoder.copy_buffer_to_buffer(
&uniforms_buffer,
@@ -327,20 +331,20 @@ impl Pipeline {
render_pass.set_bind_group(
0,
&self.constants,
- &[(std::mem::size_of::<Uniforms>() * i) as u64],
+ &[(std::mem::size_of::<Uniforms>() * i) as u32],
);
render_pass.set_index_buffer(
&self.index_buffer.raw,
index_offset * std::mem::size_of::<u32>() as u64,
+ 0,
);
- render_pass.set_vertex_buffers(
+ render_pass.set_vertex_buffer(
+ 0,
+ &self.vertex_buffer.raw,
+ vertex_offset * std::mem::size_of::<Vertex2D>() as u64,
0,
- &[(
- &self.vertex_buffer.raw,
- vertex_offset * std::mem::size_of::<Vertex2D>() as u64,
- )],
);
render_pass.draw_indexed(0..indices as u32, 0, 0..1);
@@ -354,7 +358,7 @@ impl Pipeline {
}
#[repr(C)]
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, AsBytes)]
struct Uniforms {
transform: [f32; 16],
}
@@ -369,7 +373,7 @@ impl Default for Uniforms {
/// A two-dimensional vertex with some color in __linear__ RGBA.
#[repr(C)]
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, AsBytes)]
pub struct Vertex2D {
/// The vertex position
pub position: [f32; 2],
diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs
index f65f0a00..f52c888b 100644
--- a/wgpu/src/triangle/msaa.rs
+++ b/wgpu/src/triangle/msaa.rs
@@ -25,20 +25,22 @@ impl Blit {
mipmap_filter: wgpu::FilterMode::Linear,
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
- compare_function: wgpu::CompareFunction::Always,
+ compare: wgpu::CompareFunction::Always,
});
let constant_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
- bindings: &[wgpu::BindGroupLayoutBinding {
+ label: None,
+ bindings: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT,
- ty: wgpu::BindingType::Sampler,
+ ty: wgpu::BindingType::Sampler { comparison: false },
}],
});
let constant_bind_group =
device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: None,
layout: &constant_layout,
bindings: &[wgpu::Binding {
binding: 0,
@@ -48,12 +50,14 @@ impl Blit {
let texture_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
- bindings: &[wgpu::BindGroupLayoutBinding {
+ label: None,
+ bindings: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
- multisampled: false,
dimension: wgpu::TextureViewDimension::D2,
+ component_type: wgpu::TextureComponentType::Float,
+ multisampled: false,
},
}],
});
@@ -109,8 +113,10 @@ impl Blit {
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
- index_format: wgpu::IndexFormat::Uint16,
- vertex_buffers: &[],
+ vertex_state: wgpu::VertexStateDescriptor {
+ index_format: wgpu::IndexFormat::Uint16,
+ vertex_buffers: &[],
+ },
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
@@ -222,6 +228,7 @@ impl Targets {
};
let attachment = device.create_texture(&wgpu::TextureDescriptor {
+ label: None,
size: extent,
array_layer_count: 1,
mip_level_count: 1,
@@ -232,6 +239,7 @@ impl Targets {
});
let resolve = device.create_texture(&wgpu::TextureDescriptor {
+ label: None,
size: extent,
array_layer_count: 1,
mip_level_count: 1,
@@ -246,6 +254,7 @@ impl Targets {
let resolve = resolve.create_default_view();
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: None,
layout: texture_layout,
bindings: &[wgpu::Binding {
binding: 0,