Merge pull request #725 from PolyMeilex/wgpu-7.0

Update to wgpu 0.7
This commit is contained in:
Héctor Ramón 2021-02-06 16:18:19 +01:00 committed by GitHub
commit 2f10a1f2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 261 additions and 225 deletions

View File

@ -36,7 +36,7 @@ pub fn main() {
let (mut device, queue) = futures::executor::block_on(async { let (mut device, queue) = futures::executor::block_on(async {
let adapter = instance let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions { .request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default, power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&surface), compatible_surface: Some(&surface),
}) })
.await .await
@ -45,9 +45,9 @@ pub fn main() {
adapter adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(), features: wgpu::Features::empty(),
limits: wgpu::Limits::default(), limits: wgpu::Limits::default(),
shader_validation: false,
}, },
None, None,
) )
@ -63,7 +63,7 @@ pub fn main() {
device.create_swap_chain( device.create_swap_chain(
&surface, &surface,
&wgpu::SwapChainDescriptor { &wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: format, format: format,
width: size.width, width: size.width,
height: size.height, height: size.height,
@ -157,7 +157,7 @@ pub fn main() {
swap_chain = device.create_swap_chain( swap_chain = device.create_swap_chain(
&surface, &surface,
&wgpu::SwapChainDescriptor { &wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: format, format: format,
width: size.width, width: size.width,
height: size.height, height: size.height,

View File

@ -19,6 +19,7 @@ impl Scene {
background_color: Color, background_color: Color,
) -> wgpu::RenderPass<'a> { ) -> wgpu::RenderPass<'a> {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: target, attachment: target,
resolve_target: None, resolve_target: None,
@ -48,10 +49,10 @@ impl Scene {
fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline { fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
let vs_module = let vs_module =
device.create_shader_module(wgpu::include_spirv!("shader/vert.spv")); device.create_shader_module(&wgpu::include_spirv!("shader/vert.spv"));
let fs_module = let fs_module =
device.create_shader_module(wgpu::include_spirv!("shader/frag.spv")); device.create_shader_module(&wgpu::include_spirv!("shader/frag.spv"));
let pipeline_layout = let pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
@ -64,34 +65,33 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None, label: None,
layout: Some(&pipeline_layout), layout: Some(&pipeline_layout),
vertex_stage: wgpu::ProgrammableStageDescriptor { vertex: wgpu::VertexState {
module: &vs_module, module: &vs_module,
entry_point: "main", entry_point: "main",
buffers: &[],
}, },
fragment_stage: Some(wgpu::ProgrammableStageDescriptor { fragment: Some(wgpu::FragmentState {
module: &fs_module, module: &fs_module,
entry_point: "main", entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
color_blend: wgpu::BlendState::REPLACE,
alpha_blend: wgpu::BlendState::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}), }),
rasterization_state: Some(wgpu::RasterizationStateDescriptor { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Ccw, front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::None, cull_mode: wgpu::CullMode::None,
..Default::default() ..Default::default()
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
}, },
sample_count: 1, depth_stencil: None,
sample_mask: !0, multisample: wgpu::MultisampleState {
alpha_to_coverage_enabled: false, count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
}); });
pipeline pipeline

View File

@ -14,8 +14,8 @@ qr_code = ["iced_graphics/qr_code"]
default_system_font = ["iced_graphics/font-source"] default_system_font = ["iced_graphics/font-source"]
[dependencies] [dependencies]
wgpu = "0.6" wgpu = "0.7"
wgpu_glyph = "0.10" wgpu_glyph = "0.11"
glyph_brush = "0.7" glyph_brush = "0.7"
raw-window-handle = "0.3" raw-window-handle = "0.3"
log = "0.4" log = "0.4"

View File

@ -62,8 +62,9 @@ impl Pipeline {
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::VERTEX, visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer { ty: wgpu::BindingType::Buffer {
dynamic: false, ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new( min_binding_size: wgpu::BufferSize::new(
mem::size_of::<Uniforms>() as u64, mem::size_of::<Uniforms>() as u64,
), ),
@ -73,7 +74,10 @@ impl Pipeline {
wgpu::BindGroupLayoutEntry { wgpu::BindGroupLayoutEntry {
binding: 1, binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false }, ty: wgpu::BindingType::Sampler {
comparison: false,
filtering: true,
},
count: None, count: None,
}, },
], ],
@ -93,9 +97,11 @@ impl Pipeline {
entries: &[ entries: &[
wgpu::BindGroupEntry { wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer( resource: wgpu::BindingResource::Buffer {
uniforms_buffer.slice(..), buffer: &uniforms_buffer,
), offset: 0,
size: None,
},
}, },
wgpu::BindGroupEntry { wgpu::BindGroupEntry {
binding: 1, binding: 1,
@ -110,9 +116,11 @@ impl Pipeline {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture { ty: wgpu::BindingType::Texture {
dimension: wgpu::TextureViewDimension::D2, sample_type: wgpu::TextureSampleType::Float {
component_type: wgpu::TextureComponentType::Float, filterable: true,
},
view_dimension: wgpu::TextureViewDimension::D2Array,
multisampled: false, multisampled: false,
}, },
count: None, count: None,
@ -126,11 +134,11 @@ impl Pipeline {
bind_group_layouts: &[&constant_layout, &texture_layout], bind_group_layouts: &[&constant_layout, &texture_layout],
}); });
let vs_module = device.create_shader_module(wgpu::include_spirv!( let vs_module = device.create_shader_module(&wgpu::include_spirv!(
"shader/image.vert.spv" "shader/image.vert.spv"
)); ));
let fs_module = device.create_shader_module(wgpu::include_spirv!( let fs_module = device.create_shader_module(&wgpu::include_spirv!(
"shader/image.frag.spv" "shader/image.frag.spv"
)); ));
@ -138,72 +146,44 @@ impl Pipeline {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu::image pipeline"), label: Some("iced_wgpu::image pipeline"),
layout: Some(&layout), layout: Some(&layout),
vertex_stage: wgpu::ProgrammableStageDescriptor { vertex: wgpu::VertexState {
module: &vs_module, module: &vs_module,
entry_point: "main", entry_point: "main",
}, buffers: &[
fragment_stage: Some(wgpu::ProgrammableStageDescriptor { wgpu::VertexBufferLayout {
module: &fs_module, array_stride: mem::size_of::<Vertex>() as u64,
entry_point: "main",
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::None,
..Default::default()
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[
wgpu::VertexBufferDescriptor {
stride: mem::size_of::<Vertex>() as u64,
step_mode: wgpu::InputStepMode::Vertex, step_mode: wgpu::InputStepMode::Vertex,
attributes: &[wgpu::VertexAttributeDescriptor { attributes: &[wgpu::VertexAttribute {
shader_location: 0, shader_location: 0,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 0, offset: 0,
}], }],
}, },
wgpu::VertexBufferDescriptor { wgpu::VertexBufferLayout {
stride: mem::size_of::<Instance>() as u64, array_stride: mem::size_of::<Instance>() as u64,
step_mode: wgpu::InputStepMode::Instance, step_mode: wgpu::InputStepMode::Instance,
attributes: &[ attributes: &[
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 1, shader_location: 1,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 0, offset: 0,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 2, shader_location: 2,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 4 * 2, offset: 4 * 2,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 3, shader_location: 3,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 4 * 4, offset: 4 * 4,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 4, shader_location: 4,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 4 * 6, offset: 4 * 6,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 5, shader_location: 5,
format: wgpu::VertexFormat::Uint, format: wgpu::VertexFormat::Uint,
offset: 4 * 8, offset: 4 * 8,
@ -212,9 +192,36 @@ impl Pipeline {
}, },
], ],
}, },
sample_count: 1, fragment: Some(wgpu::FragmentState {
sample_mask: !0, module: &fs_module,
alpha_to_coverage_enabled: false, entry_point: "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,
},
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,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
}); });
let vertices = let vertices =
@ -415,6 +422,7 @@ impl Pipeline {
let mut render_pass = let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::image render pass"),
color_attachments: &[ color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor { wgpu::RenderPassColorAttachmentDescriptor {
attachment: target, attachment: target,
@ -431,7 +439,10 @@ impl Pipeline {
render_pass.set_pipeline(&self.pipeline); render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, &self.constants, &[]); render_pass.set_bind_group(0, &self.constants, &[]);
render_pass.set_bind_group(1, &self.texture, &[]); render_pass.set_bind_group(1, &self.texture, &[]);
render_pass.set_index_buffer(self.indices.slice(..)); render_pass.set_index_buffer(
self.indices.slice(..),
wgpu::IndexFormat::Uint16,
);
render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(0, self.vertices.slice(..));
render_pass.set_vertex_buffer(1, self.instances.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..));

View File

@ -24,8 +24,9 @@ impl Pipeline {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::VERTEX, visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer { ty: wgpu::BindingType::Buffer {
dynamic: false, ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: wgpu::BufferSize::new( min_binding_size: wgpu::BufferSize::new(
mem::size_of::<Uniforms>() as u64, mem::size_of::<Uniforms>() as u64,
), ),
@ -46,9 +47,11 @@ impl Pipeline {
layout: &constant_layout, layout: &constant_layout,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer( resource: wgpu::BindingResource::Buffer {
constants_buffer.slice(..), buffer: &constants_buffer,
), offset: 0,
size: None,
},
}], }],
}); });
@ -59,87 +62,61 @@ impl Pipeline {
bind_group_layouts: &[&constant_layout], bind_group_layouts: &[&constant_layout],
}); });
let vs_module = device let vs_module = device.create_shader_module(&wgpu::include_spirv!(
.create_shader_module(wgpu::include_spirv!("shader/quad.vert.spv")); "shader/quad.vert.spv"
));
let fs_module = device let fs_module = device.create_shader_module(&wgpu::include_spirv!(
.create_shader_module(wgpu::include_spirv!("shader/quad.frag.spv")); "shader/quad.frag.spv"
));
let pipeline = let pipeline =
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu::quad pipeline"), label: Some("iced_wgpu::quad pipeline"),
layout: Some(&layout), layout: Some(&layout),
vertex_stage: wgpu::ProgrammableStageDescriptor { vertex: wgpu::VertexState {
module: &vs_module, module: &vs_module,
entry_point: "main", entry_point: "main",
}, buffers: &[
fragment_stage: Some(wgpu::ProgrammableStageDescriptor { wgpu::VertexBufferLayout {
module: &fs_module, array_stride: mem::size_of::<Vertex>() as u64,
entry_point: "main",
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::None,
..Default::default()
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[
wgpu::VertexBufferDescriptor {
stride: mem::size_of::<Vertex>() as u64,
step_mode: wgpu::InputStepMode::Vertex, step_mode: wgpu::InputStepMode::Vertex,
attributes: &[wgpu::VertexAttributeDescriptor { attributes: &[wgpu::VertexAttribute {
shader_location: 0, shader_location: 0,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 0, offset: 0,
}], }],
}, },
wgpu::VertexBufferDescriptor { wgpu::VertexBufferLayout {
stride: mem::size_of::<layer::Quad>() as u64, array_stride: mem::size_of::<layer::Quad>() as u64,
step_mode: wgpu::InputStepMode::Instance, step_mode: wgpu::InputStepMode::Instance,
attributes: &[ attributes: &[
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 1, shader_location: 1,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 0, offset: 0,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 2, shader_location: 2,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 4 * 2, offset: 4 * 2,
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 3, shader_location: 3,
format: wgpu::VertexFormat::Float4, format: wgpu::VertexFormat::Float4,
offset: 4 * (2 + 2), offset: 4 * (2 + 2),
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 4, shader_location: 4,
format: wgpu::VertexFormat::Float4, format: wgpu::VertexFormat::Float4,
offset: 4 * (2 + 2 + 4), offset: 4 * (2 + 2 + 4),
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 5, shader_location: 5,
format: wgpu::VertexFormat::Float, format: wgpu::VertexFormat::Float,
offset: 4 * (2 + 2 + 4 + 4), offset: 4 * (2 + 2 + 4 + 4),
}, },
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 6, shader_location: 6,
format: wgpu::VertexFormat::Float, format: wgpu::VertexFormat::Float,
offset: 4 * (2 + 2 + 4 + 4 + 1), offset: 4 * (2 + 2 + 4 + 4 + 1),
@ -148,9 +125,36 @@ impl Pipeline {
}, },
], ],
}, },
sample_count: 1, fragment: Some(wgpu::FragmentState {
sample_mask: !0, module: &fs_module,
alpha_to_coverage_enabled: false, entry_point: "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,
},
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,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
}); });
let vertices = let vertices =
@ -232,6 +236,7 @@ impl Pipeline {
{ {
let mut render_pass = let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::quad render pass"),
color_attachments: &[ color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor { wgpu::RenderPassColorAttachmentDescriptor {
attachment: target, attachment: target,
@ -247,15 +252,19 @@ impl Pipeline {
render_pass.set_pipeline(&self.pipeline); render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, &self.constants, &[]); render_pass.set_bind_group(0, &self.constants, &[]);
render_pass.set_index_buffer(self.indices.slice(..)); render_pass.set_index_buffer(
self.indices.slice(..),
wgpu::IndexFormat::Uint16,
);
render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(0, self.vertices.slice(..));
render_pass.set_vertex_buffer(1, self.instances.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..));
render_pass.set_scissor_rect( render_pass.set_scissor_rect(
bounds.x, bounds.x,
bounds.y, bounds.y,
bounds.width, bounds.width,
// TODO: Address anti-aliasing adjustments properly // TODO: Address anti-aliasing adjustments properly
bounds.height + 1, bounds.height,
); );
render_pass.draw_indexed( render_pass.draw_indexed(

View File

@ -86,8 +86,9 @@ impl Pipeline {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::VERTEX, visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer { ty: wgpu::BindingType::Buffer {
dynamic: true, ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: true,
min_binding_size: wgpu::BufferSize::new( min_binding_size: wgpu::BufferSize::new(
mem::size_of::<Uniforms>() as u64, mem::size_of::<Uniforms>() as u64,
), ),
@ -109,11 +110,13 @@ impl Pipeline {
layout: &constants_layout, layout: &constants_layout,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer( resource: wgpu::BindingResource::Buffer {
constants_buffer buffer: &constants_buffer.raw,
.raw offset: 0,
.slice(0..std::mem::size_of::<Uniforms>() as u64), size: wgpu::BufferSize::new(
), std::mem::size_of::<Uniforms>() as u64,
),
},
}], }],
}); });
@ -124,11 +127,11 @@ impl Pipeline {
bind_group_layouts: &[&constants_layout], bind_group_layouts: &[&constants_layout],
}); });
let vs_module = device.create_shader_module(wgpu::include_spirv!( let vs_module = device.create_shader_module(&wgpu::include_spirv!(
"shader/triangle.vert.spv" "shader/triangle.vert.spv"
)); ));
let fs_module = device.create_shader_module(wgpu::include_spirv!( let fs_module = device.create_shader_module(&wgpu::include_spirv!(
"shader/triangle.frag.spv" "shader/triangle.frag.spv"
)); ));
@ -136,49 +139,21 @@ impl Pipeline {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu::triangle pipeline"), label: Some("iced_wgpu::triangle pipeline"),
layout: Some(&layout), layout: Some(&layout),
vertex_stage: wgpu::ProgrammableStageDescriptor { vertex: wgpu::VertexState {
module: &vs_module, module: &vs_module,
entry_point: "main", entry_point: "main",
}, buffers: &[wgpu::VertexBufferLayout {
fragment_stage: Some(wgpu::ProgrammableStageDescriptor { array_stride: mem::size_of::<Vertex2D>() as u64,
module: &fs_module,
entry_point: "main",
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::None,
..Default::default()
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
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, step_mode: wgpu::InputStepMode::Vertex,
attributes: &[ attributes: &[
// Position // Position
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 0, shader_location: 0,
format: wgpu::VertexFormat::Float2, format: wgpu::VertexFormat::Float2,
offset: 0, offset: 0,
}, },
// Color // Color
wgpu::VertexAttributeDescriptor { wgpu::VertexAttribute {
shader_location: 1, shader_location: 1,
format: wgpu::VertexFormat::Float4, format: wgpu::VertexFormat::Float4,
offset: 4 * 2, offset: 4 * 2,
@ -186,11 +161,38 @@ impl Pipeline {
], ],
}], }],
}, },
sample_count: u32::from( fragment: Some(wgpu::FragmentState {
antialiasing.map(|a| a.sample_count()).unwrap_or(1), module: &fs_module,
), entry_point: "main",
sample_mask: !0, targets: &[wgpu::ColorTargetState {
alpha_to_coverage_enabled: false, 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,
},
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,
multisample: wgpu::MultisampleState {
count: u32::from(
antialiasing.map(|a| a.sample_count()).unwrap_or(1),
),
mask: !0,
alpha_to_coverage_enabled: false,
},
}); });
Pipeline { Pipeline {
@ -252,11 +254,15 @@ impl Pipeline {
layout: &self.constants_layout, layout: &self.constants_layout,
entries: &[wgpu::BindGroupEntry { entries: &[wgpu::BindGroupEntry {
binding: 0, binding: 0,
resource: wgpu::BindingResource::Buffer( resource: wgpu::BindingResource::Buffer {
self.uniforms_buffer.raw.slice( buffer: &self.uniforms_buffer.raw,
0..std::mem::size_of::<Uniforms>() as u64, offset: 0,
), size: wgpu::BufferSize::new(std::mem::size_of::<
), Uniforms,
>(
)
as u64),
},
}], }],
}); });
} }
@ -356,6 +362,7 @@ impl Pipeline {
let mut render_pass = let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::triangle render pass"),
color_attachments: &[ color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor { wgpu::RenderPassColorAttachmentDescriptor {
attachment, attachment,
@ -390,6 +397,7 @@ impl Pipeline {
self.index_buffer self.index_buffer
.raw .raw
.slice(index_offset * mem::size_of::<u32>() as u64..), .slice(index_offset * mem::size_of::<u32>() as u64..),
wgpu::IndexFormat::Uint32,
); );
render_pass.set_vertex_buffer( render_pass.set_vertex_buffer(

View File

@ -32,7 +32,10 @@ impl Blit {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false }, ty: wgpu::BindingType::Sampler {
comparison: false,
filtering: false,
},
count: None, count: None,
}], }],
}); });
@ -53,9 +56,11 @@ impl Blit {
entries: &[wgpu::BindGroupLayoutEntry { entries: &[wgpu::BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT, visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture { ty: wgpu::BindingType::Texture {
dimension: wgpu::TextureViewDimension::D2, sample_type: wgpu::TextureSampleType::Float {
component_type: wgpu::TextureComponentType::Float, filterable: false,
},
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: false, multisampled: false,
}, },
count: None, count: None,
@ -69,11 +74,11 @@ impl Blit {
bind_group_layouts: &[&constant_layout, &texture_layout], bind_group_layouts: &[&constant_layout, &texture_layout],
}); });
let vs_module = device.create_shader_module(wgpu::include_spirv!( let vs_module = device.create_shader_module(&wgpu::include_spirv!(
"../shader/blit.vert.spv" "../shader/blit.vert.spv"
)); ));
let fs_module = device.create_shader_module(wgpu::include_spirv!( let fs_module = device.create_shader_module(&wgpu::include_spirv!(
"../shader/blit.frag.spv" "../shader/blit.frag.spv"
)); ));
@ -81,42 +86,41 @@ impl Blit {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("iced_wgpu::triangle::msaa pipeline"), label: Some("iced_wgpu::triangle::msaa pipeline"),
layout: Some(&layout), layout: Some(&layout),
vertex_stage: wgpu::ProgrammableStageDescriptor { vertex: wgpu::VertexState {
module: &vs_module, module: &vs_module,
entry_point: "main", entry_point: "main",
buffers: &[],
}, },
fragment_stage: Some(wgpu::ProgrammableStageDescriptor { fragment: Some(wgpu::FragmentState {
module: &fs_module, module: &fs_module,
entry_point: "main", entry_point: "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,
},
write_mask: wgpu::ColorWrite::ALL,
}],
}), }),
rasterization_state: Some(wgpu::RasterizationStateDescriptor { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
front_face: wgpu::FrontFace::Cw, front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::None, cull_mode: wgpu::CullMode::None,
..Default::default() ..Default::default()
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
}, },
sample_count: 1, depth_stencil: None,
sample_mask: !0, multisample: wgpu::MultisampleState {
alpha_to_coverage_enabled: false, count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
}); });
Blit { Blit {
@ -172,6 +176,7 @@ impl Blit {
) { ) {
let mut render_pass = let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::triangle::msaa render pass"),
color_attachments: &[ color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor { wgpu::RenderPassColorAttachmentDescriptor {
attachment: target, attachment: target,
@ -227,7 +232,7 @@ impl Targets {
sample_count, sample_count,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format, format,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
}); });
let resolve = device.create_texture(&wgpu::TextureDescriptor { let resolve = device.create_texture(&wgpu::TextureDescriptor {
@ -237,7 +242,7 @@ impl Targets {
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, dimension: wgpu::TextureDimension::D2,
format, format,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT usage: wgpu::TextureUsage::RENDER_ATTACHMENT
| wgpu::TextureUsage::SAMPLED, | wgpu::TextureUsage::SAMPLED,
}); });

View File

@ -27,7 +27,7 @@ impl Compositor {
let adapter = instance let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions { .request_adapter(&wgpu::RequestAdapterOptions {
power_preference: if settings.antialiasing.is_none() { power_preference: if settings.antialiasing.is_none() {
wgpu::PowerPreference::Default wgpu::PowerPreference::LowPower
} else { } else {
wgpu::PowerPreference::HighPerformance wgpu::PowerPreference::HighPerformance
}, },
@ -38,12 +38,14 @@ impl Compositor {
let (device, queue) = adapter let (device, queue) = adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: Some(
"iced_wgpu::window::compositor device descriptor",
),
features: wgpu::Features::empty(), features: wgpu::Features::empty(),
limits: wgpu::Limits { limits: wgpu::Limits {
max_bind_groups: 2, max_bind_groups: 2,
..wgpu::Limits::default() ..wgpu::Limits::default()
}, },
shader_validation: false,
}, },
None, None,
) )
@ -103,7 +105,7 @@ impl iced_graphics::window::Compositor for Compositor {
self.device.create_swap_chain( self.device.create_swap_chain(
surface, surface,
&wgpu::SwapChainDescriptor { &wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: self.settings.format, format: self.settings.format,
present_mode: self.settings.present_mode, present_mode: self.settings.present_mode,
width, width,
@ -130,6 +132,7 @@ impl iced_graphics::window::Compositor for Compositor {
); );
let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::window::Compositor render pass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view, attachment: &frame.output.view,
resolve_target: None, resolve_target: None,