[wgpu 0.7] Update image.rs
This commit is contained in:
parent
e2595ac0aa
commit
4a6db30d47
|
@ -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: false,
|
||||||
|
},
|
||||||
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: false,
|
||||||
|
},
|
||||||
|
view_dimension: wgpu::TextureViewDimension::D2,
|
||||||
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(..));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue