wgpu: Update to 0.10
This commit is contained in:
parent
663c3685da
commit
18753b77fc
14 changed files with 100 additions and 89 deletions
|
|
@ -10,6 +10,7 @@ documentation = "https://docs.rs/iced"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
|
||||||
categories = ["gui"]
|
categories = ["gui"]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wgpu", "default_system_font"]
|
default = ["wgpu", "default_system_font"]
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,5 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced_winit = { path = "../../winit" }
|
iced_winit = { path = "../../winit" }
|
||||||
iced_wgpu = { path = "../../wgpu" }
|
iced_wgpu = { path = "../../wgpu", features=["spirv"] }
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ pub fn main() {
|
||||||
let mut clipboard = Clipboard::connect(&window);
|
let mut clipboard = Clipboard::connect(&window);
|
||||||
|
|
||||||
// Initialize wgpu
|
// Initialize wgpu
|
||||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
|
||||||
let surface = unsafe { instance.create_surface(&window) };
|
let surface = unsafe { instance.create_surface(&window) };
|
||||||
|
|
||||||
let (format, (mut device, queue)) = futures::executor::block_on(async {
|
let (format, (mut device, queue)) = futures::executor::block_on(async {
|
||||||
|
|
@ -44,8 +44,8 @@ pub fn main() {
|
||||||
.expect("Request adapter");
|
.expect("Request adapter");
|
||||||
|
|
||||||
(
|
(
|
||||||
adapter
|
surface
|
||||||
.get_swap_chain_preferred_format(&surface)
|
.get_preferred_format(&adapter)
|
||||||
.expect("Get preferred format"),
|
.expect("Get preferred format"),
|
||||||
adapter
|
adapter
|
||||||
.request_device(
|
.request_device(
|
||||||
|
|
@ -61,13 +61,13 @@ pub fn main() {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut swap_chain = {
|
{
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
device.create_swap_chain(
|
surface.configure(
|
||||||
&surface,
|
&device,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SurfaceConfiguration {
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
format,
|
format,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
|
|
@ -158,10 +158,10 @@ pub fn main() {
|
||||||
if resized {
|
if resized {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
swap_chain = device.create_swap_chain(
|
surface.configure(
|
||||||
&surface,
|
&device,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SurfaceConfiguration {
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
format: format,
|
format: format,
|
||||||
width: size.width,
|
width: size.width,
|
||||||
height: size.height,
|
height: size.height,
|
||||||
|
|
@ -172,7 +172,7 @@ pub fn main() {
|
||||||
resized = false;
|
resized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
match swap_chain.get_current_frame() {
|
match surface.get_current_frame() {
|
||||||
Ok(frame) => {
|
Ok(frame) => {
|
||||||
let mut encoder = device.create_command_encoder(
|
let mut encoder = device.create_command_encoder(
|
||||||
&wgpu::CommandEncoderDescriptor { label: None },
|
&wgpu::CommandEncoderDescriptor { label: None },
|
||||||
|
|
@ -180,10 +180,12 @@ pub fn main() {
|
||||||
|
|
||||||
let program = state.program();
|
let program = state.program();
|
||||||
|
|
||||||
|
let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
|
|
||||||
{
|
{
|
||||||
// We clear the frame
|
// We clear the frame
|
||||||
let mut render_pass = scene.clear(
|
let mut render_pass = scene.clear(
|
||||||
&frame.output.view,
|
&view,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
program.background_color(),
|
program.background_color(),
|
||||||
);
|
);
|
||||||
|
|
@ -197,7 +199,7 @@ pub fn main() {
|
||||||
&mut device,
|
&mut device,
|
||||||
&mut staging_belt,
|
&mut staging_belt,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
&frame.output.view,
|
&view,
|
||||||
&viewport,
|
&viewport,
|
||||||
state.primitive(),
|
state.primitive(),
|
||||||
&debug.overlay(),
|
&debug.overlay(),
|
||||||
|
|
@ -223,7 +225,7 @@ pub fn main() {
|
||||||
local_pool.run_until_stalled();
|
local_pool.run_until_stalled();
|
||||||
}
|
}
|
||||||
Err(error) => match error {
|
Err(error) => match error {
|
||||||
wgpu::SwapChainError::OutOfMemory => {
|
wgpu::SurfaceError::OutOfMemory => {
|
||||||
panic!("Swapchain error: {}. Rendering cannot continue.", error)
|
panic!("Swapchain error: {}. Rendering cannot continue.", error)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
|
||||||
color: wgpu::BlendComponent::REPLACE,
|
color: wgpu::BlendComponent::REPLACE,
|
||||||
alpha: wgpu::BlendComponent::REPLACE,
|
alpha: wgpu::BlendComponent::REPLACE,
|
||||||
}),
|
}),
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ pub trait Compositor: Sized {
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut Self::Renderer,
|
renderer: &mut Self::Renderer,
|
||||||
swap_chain: &mut Self::SwapChain,
|
swap_chain: &mut Self::SwapChain,
|
||||||
|
surface: &mut Self::Surface,
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,11 @@ farbfeld = ["image_rs/farbfeld"]
|
||||||
canvas = ["iced_graphics/canvas"]
|
canvas = ["iced_graphics/canvas"]
|
||||||
qr_code = ["iced_graphics/qr_code"]
|
qr_code = ["iced_graphics/qr_code"]
|
||||||
default_system_font = ["iced_graphics/font-source"]
|
default_system_font = ["iced_graphics/font-source"]
|
||||||
|
spirv = ["wgpu/spirv"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wgpu = "0.9"
|
wgpu = "0.10"
|
||||||
wgpu_glyph = "0.13"
|
wgpu_glyph = {git="https://github.com/rukai/wgpu_glyph.git", branch="update_wgpu_0.10"}
|
||||||
glyph_brush = "0.7"
|
glyph_brush = "0.7"
|
||||||
raw-window-handle = "0.3"
|
raw-window-handle = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ impl Pipeline {
|
||||||
entries: &[
|
entries: &[
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
visibility: wgpu::ShaderStages::VERTEX,
|
||||||
ty: wgpu::BindingType::Buffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
has_dynamic_offset: false,
|
has_dynamic_offset: false,
|
||||||
|
|
@ -73,7 +73,7 @@ impl Pipeline {
|
||||||
},
|
},
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler {
|
ty: wgpu::BindingType::Sampler {
|
||||||
comparison: false,
|
comparison: false,
|
||||||
filtering: true,
|
filtering: true,
|
||||||
|
|
@ -86,7 +86,7 @@ impl Pipeline {
|
||||||
let uniforms_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
let uniforms_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("iced_wgpu::image uniforms buffer"),
|
label: Some("iced_wgpu::image uniforms buffer"),
|
||||||
size: mem::size_of::<Uniforms>() as u64,
|
size: mem::size_of::<Uniforms>() as u64,
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -117,7 +117,7 @@ impl Pipeline {
|
||||||
label: Some("iced_wgpu::image texture atlas layout"),
|
label: Some("iced_wgpu::image texture atlas layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Texture {
|
ty: wgpu::BindingType::Texture {
|
||||||
sample_type: wgpu::TextureSampleType::Float {
|
sample_type: wgpu::TextureSampleType::Float {
|
||||||
filterable: true,
|
filterable: true,
|
||||||
|
|
@ -142,7 +142,6 @@ impl Pipeline {
|
||||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
||||||
include_str!("shader/image.wgsl"),
|
include_str!("shader/image.wgsl"),
|
||||||
)),
|
)),
|
||||||
flags: wgpu::ShaderFlags::all(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let pipeline =
|
let pipeline =
|
||||||
|
|
@ -155,7 +154,7 @@ impl Pipeline {
|
||||||
buffers: &[
|
buffers: &[
|
||||||
wgpu::VertexBufferLayout {
|
wgpu::VertexBufferLayout {
|
||||||
array_stride: mem::size_of::<Vertex>() as u64,
|
array_stride: mem::size_of::<Vertex>() as u64,
|
||||||
step_mode: wgpu::InputStepMode::Vertex,
|
step_mode: wgpu::VertexStepMode::Vertex,
|
||||||
attributes: &[wgpu::VertexAttribute {
|
attributes: &[wgpu::VertexAttribute {
|
||||||
shader_location: 0,
|
shader_location: 0,
|
||||||
format: wgpu::VertexFormat::Float32x2,
|
format: wgpu::VertexFormat::Float32x2,
|
||||||
|
|
@ -164,7 +163,7 @@ impl Pipeline {
|
||||||
},
|
},
|
||||||
wgpu::VertexBufferLayout {
|
wgpu::VertexBufferLayout {
|
||||||
array_stride: mem::size_of::<Instance>() as u64,
|
array_stride: mem::size_of::<Instance>() as u64,
|
||||||
step_mode: wgpu::InputStepMode::Instance,
|
step_mode: wgpu::VertexStepMode::Instance,
|
||||||
attributes: &wgpu::vertex_attr_array!(
|
attributes: &wgpu::vertex_attr_array!(
|
||||||
1 => Float32x2,
|
1 => Float32x2,
|
||||||
2 => Float32x2,
|
2 => Float32x2,
|
||||||
|
|
@ -192,7 +191,7 @@ impl Pipeline {
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: wgpu::BlendOperation::Add,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
|
@ -212,20 +211,20 @@ impl Pipeline {
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::image vertex buffer"),
|
label: Some("iced_wgpu::image vertex buffer"),
|
||||||
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
||||||
usage: wgpu::BufferUsage::VERTEX,
|
usage: wgpu::BufferUsages::VERTEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let indices =
|
let indices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::image index buffer"),
|
label: Some("iced_wgpu::image index buffer"),
|
||||||
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
||||||
usage: wgpu::BufferUsage::INDEX,
|
usage: wgpu::BufferUsages::INDEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let instances = device.create_buffer(&wgpu::BufferDescriptor {
|
let instances = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("iced_wgpu::image instance buffer"),
|
label: Some("iced_wgpu::image instance buffer"),
|
||||||
size: mem::size_of::<Instance>() as u64 * Instance::MAX as u64,
|
size: mem::size_of::<Instance>() as u64 * Instance::MAX as u64,
|
||||||
usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ impl Atlas {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
usage: wgpu::TextureUsage::COPY_DST
|
usage: wgpu::TextureUsages::COPY_DST
|
||||||
| wgpu::TextureUsage::COPY_SRC
|
| wgpu::TextureUsages::COPY_SRC
|
||||||
| wgpu::TextureUsage::SAMPLED,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
});
|
});
|
||||||
|
|
||||||
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor {
|
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor {
|
||||||
|
|
@ -107,7 +107,7 @@ impl Atlas {
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::image staging buffer"),
|
label: Some("iced_wgpu::image staging buffer"),
|
||||||
contents: &padded_data,
|
contents: &padded_data,
|
||||||
usage: wgpu::BufferUsage::COPY_SRC,
|
usage: wgpu::BufferUsages::COPY_SRC,
|
||||||
});
|
});
|
||||||
|
|
||||||
match &entry {
|
match &entry {
|
||||||
|
|
@ -316,6 +316,7 @@ impl Atlas {
|
||||||
y,
|
y,
|
||||||
z: layer as u32,
|
z: layer as u32,
|
||||||
},
|
},
|
||||||
|
aspect: wgpu::TextureAspect::default(),
|
||||||
},
|
},
|
||||||
extent,
|
extent,
|
||||||
);
|
);
|
||||||
|
|
@ -342,9 +343,9 @@ impl Atlas {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
usage: wgpu::TextureUsage::COPY_DST
|
usage: wgpu::TextureUsages::COPY_DST
|
||||||
| wgpu::TextureUsage::COPY_SRC
|
| wgpu::TextureUsages::COPY_SRC
|
||||||
| wgpu::TextureUsage::SAMPLED,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
});
|
});
|
||||||
|
|
||||||
let amount_to_copy = self.layers.len() - amount;
|
let amount_to_copy = self.layers.len() - amount;
|
||||||
|
|
@ -365,6 +366,7 @@ impl Atlas {
|
||||||
y: 0,
|
y: 0,
|
||||||
z: i as u32,
|
z: i as u32,
|
||||||
},
|
},
|
||||||
|
aspect: wgpu::TextureAspect::default(),
|
||||||
},
|
},
|
||||||
wgpu::ImageCopyTexture {
|
wgpu::ImageCopyTexture {
|
||||||
texture: &new_texture,
|
texture: &new_texture,
|
||||||
|
|
@ -374,6 +376,7 @@ impl Atlas {
|
||||||
y: 0,
|
y: 0,
|
||||||
z: i as u32,
|
z: i as u32,
|
||||||
},
|
},
|
||||||
|
aspect: wgpu::TextureAspect::default(),
|
||||||
},
|
},
|
||||||
wgpu::Extent3d {
|
wgpu::Extent3d {
|
||||||
width: SIZE,
|
width: SIZE,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl Pipeline {
|
||||||
label: Some("iced_wgpu::quad uniforms layout"),
|
label: Some("iced_wgpu::quad uniforms layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
visibility: wgpu::ShaderStages::VERTEX,
|
||||||
ty: wgpu::BindingType::Buffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
has_dynamic_offset: false,
|
has_dynamic_offset: false,
|
||||||
|
|
@ -38,7 +38,7 @@ impl Pipeline {
|
||||||
let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("iced_wgpu::quad uniforms buffer"),
|
label: Some("iced_wgpu::quad uniforms buffer"),
|
||||||
size: mem::size_of::<Uniforms>() as wgpu::BufferAddress,
|
size: mem::size_of::<Uniforms>() as wgpu::BufferAddress,
|
||||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -64,7 +64,6 @@ impl Pipeline {
|
||||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
||||||
include_str!("shader/quad.wgsl"),
|
include_str!("shader/quad.wgsl"),
|
||||||
)),
|
)),
|
||||||
flags: wgpu::ShaderFlags::all(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let pipeline =
|
let pipeline =
|
||||||
|
|
@ -77,7 +76,7 @@ impl Pipeline {
|
||||||
buffers: &[
|
buffers: &[
|
||||||
wgpu::VertexBufferLayout {
|
wgpu::VertexBufferLayout {
|
||||||
array_stride: mem::size_of::<Vertex>() as u64,
|
array_stride: mem::size_of::<Vertex>() as u64,
|
||||||
step_mode: wgpu::InputStepMode::Vertex,
|
step_mode: wgpu::VertexStepMode::Vertex,
|
||||||
attributes: &[wgpu::VertexAttribute {
|
attributes: &[wgpu::VertexAttribute {
|
||||||
shader_location: 0,
|
shader_location: 0,
|
||||||
format: wgpu::VertexFormat::Float32x2,
|
format: wgpu::VertexFormat::Float32x2,
|
||||||
|
|
@ -86,7 +85,7 @@ impl Pipeline {
|
||||||
},
|
},
|
||||||
wgpu::VertexBufferLayout {
|
wgpu::VertexBufferLayout {
|
||||||
array_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::VertexStepMode::Instance,
|
||||||
attributes: &wgpu::vertex_attr_array!(
|
attributes: &wgpu::vertex_attr_array!(
|
||||||
1 => Float32x2,
|
1 => Float32x2,
|
||||||
2 => Float32x2,
|
2 => Float32x2,
|
||||||
|
|
@ -115,7 +114,7 @@ impl Pipeline {
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: wgpu::BlendOperation::Add,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
|
@ -135,20 +134,20 @@ impl Pipeline {
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::quad vertex buffer"),
|
label: Some("iced_wgpu::quad vertex buffer"),
|
||||||
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
||||||
usage: wgpu::BufferUsage::VERTEX,
|
usage: wgpu::BufferUsages::VERTEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let indices =
|
let indices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::quad index buffer"),
|
label: Some("iced_wgpu::quad index buffer"),
|
||||||
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
||||||
usage: wgpu::BufferUsage::INDEX,
|
usage: wgpu::BufferUsages::INDEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let instances = device.create_buffer(&wgpu::BufferDescriptor {
|
let instances = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("iced_wgpu::quad instance buffer"),
|
label: Some("iced_wgpu::quad instance buffer"),
|
||||||
size: mem::size_of::<layer::Quad>() as u64 * MAX_INSTANCES as u64,
|
size: mem::size_of::<layer::Quad>() as u64 * MAX_INSTANCES as u64,
|
||||||
usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub struct Settings {
|
||||||
pub present_mode: wgpu::PresentMode,
|
pub present_mode: wgpu::PresentMode,
|
||||||
|
|
||||||
/// The internal graphics backend to use.
|
/// The internal graphics backend to use.
|
||||||
pub internal_backend: wgpu::BackendBit,
|
pub internal_backend: wgpu::Backends,
|
||||||
|
|
||||||
/// The bytes of the font that will be used by default.
|
/// The bytes of the font that will be used by default.
|
||||||
///
|
///
|
||||||
|
|
@ -54,7 +54,7 @@ impl Settings {
|
||||||
pub fn from_env() -> Self {
|
pub fn from_env() -> Self {
|
||||||
Settings {
|
Settings {
|
||||||
internal_backend: backend_from_env()
|
internal_backend: backend_from_env()
|
||||||
.unwrap_or(wgpu::BackendBit::PRIMARY),
|
.unwrap_or(wgpu::Backends::all()),
|
||||||
..Self::default()
|
..Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +64,7 @@ impl Default for Settings {
|
||||||
fn default() -> Settings {
|
fn default() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
present_mode: wgpu::PresentMode::Mailbox,
|
present_mode: wgpu::PresentMode::Mailbox,
|
||||||
internal_backend: wgpu::BackendBit::PRIMARY,
|
internal_backend: wgpu::Backends::all(),
|
||||||
default_font: None,
|
default_font: None,
|
||||||
default_text_size: 20,
|
default_text_size: 20,
|
||||||
text_multithreading: false,
|
text_multithreading: false,
|
||||||
|
|
@ -73,16 +73,16 @@ impl Default for Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backend_from_env() -> Option<wgpu::BackendBit> {
|
fn backend_from_env() -> Option<wgpu::Backends> {
|
||||||
std::env::var("WGPU_BACKEND").ok().map(|backend| {
|
std::env::var("WGPU_BACKEND").ok().map(|backend| {
|
||||||
match backend.to_lowercase().as_str() {
|
match backend.to_lowercase().as_str() {
|
||||||
"vulkan" => wgpu::BackendBit::VULKAN,
|
"vulkan" => wgpu::Backends::VULKAN,
|
||||||
"metal" => wgpu::BackendBit::METAL,
|
"metal" => wgpu::Backends::METAL,
|
||||||
"dx12" => wgpu::BackendBit::DX12,
|
"dx12" => wgpu::Backends::DX12,
|
||||||
"dx11" => wgpu::BackendBit::DX11,
|
"dx11" => wgpu::Backends::DX11,
|
||||||
"gl" => wgpu::BackendBit::GL,
|
"gl" => wgpu::Backends::GL,
|
||||||
"webgpu" => wgpu::BackendBit::BROWSER_WEBGPU,
|
"webgpu" => wgpu::Backends::BROWSER_WEBGPU,
|
||||||
"primary" => wgpu::BackendBit::PRIMARY,
|
"primary" => wgpu::Backends::PRIMARY,
|
||||||
other => panic!("Unknown backend: {}", other),
|
other => panic!("Unknown backend: {}", other),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ struct Buffer<T> {
|
||||||
label: &'static str,
|
label: &'static str,
|
||||||
raw: wgpu::Buffer,
|
raw: wgpu::Buffer,
|
||||||
size: usize,
|
size: usize,
|
||||||
usage: wgpu::BufferUsage,
|
usage: wgpu::BufferUsages,
|
||||||
_type: std::marker::PhantomData<T>,
|
_type: std::marker::PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ impl<T> Buffer<T> {
|
||||||
label: &'static str,
|
label: &'static str,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
size: usize,
|
size: usize,
|
||||||
usage: wgpu::BufferUsage,
|
usage: wgpu::BufferUsages,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let raw = device.create_buffer(&wgpu::BufferDescriptor {
|
let raw = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some(label),
|
label: Some(label),
|
||||||
|
|
@ -85,7 +85,7 @@ impl Pipeline {
|
||||||
label: Some("iced_wgpu::triangle uniforms layout"),
|
label: Some("iced_wgpu::triangle uniforms layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::VERTEX,
|
visibility: wgpu::ShaderStages::VERTEX,
|
||||||
ty: wgpu::BindingType::Buffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
has_dynamic_offset: true,
|
has_dynamic_offset: true,
|
||||||
|
|
@ -101,7 +101,7 @@ impl Pipeline {
|
||||||
"iced_wgpu::triangle uniforms buffer",
|
"iced_wgpu::triangle uniforms buffer",
|
||||||
device,
|
device,
|
||||||
UNIFORM_BUFFER_SIZE,
|
UNIFORM_BUFFER_SIZE,
|
||||||
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
);
|
);
|
||||||
|
|
||||||
let constant_bind_group =
|
let constant_bind_group =
|
||||||
|
|
@ -137,7 +137,6 @@ impl Pipeline {
|
||||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
||||||
include_str!("shader/triangle.wgsl"),
|
include_str!("shader/triangle.wgsl"),
|
||||||
)),
|
)),
|
||||||
flags: wgpu::ShaderFlags::all(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let pipeline =
|
let pipeline =
|
||||||
|
|
@ -149,7 +148,7 @@ impl Pipeline {
|
||||||
entry_point: "vs_main",
|
entry_point: "vs_main",
|
||||||
buffers: &[wgpu::VertexBufferLayout {
|
buffers: &[wgpu::VertexBufferLayout {
|
||||||
array_stride: mem::size_of::<Vertex2D>() as u64,
|
array_stride: mem::size_of::<Vertex2D>() as u64,
|
||||||
step_mode: wgpu::InputStepMode::Vertex,
|
step_mode: wgpu::VertexStepMode::Vertex,
|
||||||
attributes: &wgpu::vertex_attr_array!(
|
attributes: &wgpu::vertex_attr_array!(
|
||||||
// Position
|
// Position
|
||||||
0 => Float32x2,
|
0 => Float32x2,
|
||||||
|
|
@ -175,7 +174,7 @@ impl Pipeline {
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: wgpu::BlendOperation::Add,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
|
@ -203,13 +202,13 @@ impl Pipeline {
|
||||||
"iced_wgpu::triangle vertex buffer",
|
"iced_wgpu::triangle vertex buffer",
|
||||||
device,
|
device,
|
||||||
VERTEX_BUFFER_SIZE,
|
VERTEX_BUFFER_SIZE,
|
||||||
wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST,
|
wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
),
|
),
|
||||||
index_buffer: Buffer::new(
|
index_buffer: Buffer::new(
|
||||||
"iced_wgpu::triangle index buffer",
|
"iced_wgpu::triangle index buffer",
|
||||||
device,
|
device,
|
||||||
INDEX_BUFFER_SIZE,
|
INDEX_BUFFER_SIZE,
|
||||||
wgpu::BufferUsage::INDEX | wgpu::BufferUsage::COPY_DST,
|
wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl Blit {
|
||||||
label: Some("iced_wgpu::triangle:msaa uniforms layout"),
|
label: Some("iced_wgpu::triangle:msaa uniforms layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Sampler {
|
ty: wgpu::BindingType::Sampler {
|
||||||
comparison: false,
|
comparison: false,
|
||||||
filtering: false,
|
filtering: false,
|
||||||
|
|
@ -55,7 +55,7 @@ impl Blit {
|
||||||
label: Some("iced_wgpu::triangle::msaa texture layout"),
|
label: Some("iced_wgpu::triangle::msaa texture layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[wgpu::BindGroupLayoutEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Texture {
|
ty: wgpu::BindingType::Texture {
|
||||||
sample_type: wgpu::TextureSampleType::Float {
|
sample_type: wgpu::TextureSampleType::Float {
|
||||||
filterable: false,
|
filterable: false,
|
||||||
|
|
@ -80,7 +80,6 @@ impl Blit {
|
||||||
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
|
||||||
include_str!("../shader/blit.wgsl"),
|
include_str!("../shader/blit.wgsl"),
|
||||||
)),
|
)),
|
||||||
flags: wgpu::ShaderFlags::all(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let pipeline =
|
let pipeline =
|
||||||
|
|
@ -109,7 +108,7 @@ impl Blit {
|
||||||
operation: wgpu::BlendOperation::Add,
|
operation: wgpu::BlendOperation::Add,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
write_mask: wgpu::ColorWrite::ALL,
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
|
|
@ -232,7 +231,7 @@ impl Targets {
|
||||||
sample_count,
|
sample_count,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format,
|
format,
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
});
|
});
|
||||||
|
|
||||||
let resolve = device.create_texture(&wgpu::TextureDescriptor {
|
let resolve = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
|
|
@ -242,8 +241,8 @@ impl Targets {
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format,
|
format,
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
|
||||||
| wgpu::TextureUsage::SAMPLED,
|
| wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
});
|
});
|
||||||
|
|
||||||
let attachment =
|
let attachment =
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl Compositor {
|
||||||
|
|
||||||
let format = compatible_surface
|
let format = compatible_surface
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|surf| adapter.get_swap_chain_preferred_format(surf))?;
|
.and_then(|surf| surf.get_preferred_format(&adapter))?;
|
||||||
|
|
||||||
let (device, queue) = adapter
|
let (device, queue) = adapter
|
||||||
.request_device(
|
.request_device(
|
||||||
|
|
@ -88,7 +88,7 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
type Settings = Settings;
|
type Settings = Settings;
|
||||||
type Renderer = Renderer;
|
type Renderer = Renderer;
|
||||||
type Surface = wgpu::Surface;
|
type Surface = wgpu::Surface;
|
||||||
type SwapChain = wgpu::SwapChain;
|
type SwapChain = ();
|
||||||
|
|
||||||
fn new<W: HasRawWindowHandle>(
|
fn new<W: HasRawWindowHandle>(
|
||||||
settings: Self::Settings,
|
settings: Self::Settings,
|
||||||
|
|
@ -121,10 +121,10 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Self::SwapChain {
|
) -> Self::SwapChain {
|
||||||
self.device.create_swap_chain(
|
surface.configure(
|
||||||
surface,
|
&self.device,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SurfaceConfiguration {
|
||||||
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
format: self.format,
|
format: self.format,
|
||||||
present_mode: self.settings.present_mode,
|
present_mode: self.settings.present_mode,
|
||||||
width,
|
width,
|
||||||
|
|
@ -136,13 +136,14 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
fn draw<T: AsRef<str>>(
|
fn draw<T: AsRef<str>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut Self::Renderer,
|
renderer: &mut Self::Renderer,
|
||||||
swap_chain: &mut Self::SwapChain,
|
_swap_chain: &mut Self::SwapChain,
|
||||||
|
surface: &mut Self::Surface,
|
||||||
viewport: &Viewport,
|
viewport: &Viewport,
|
||||||
background_color: Color,
|
background_color: Color,
|
||||||
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
output: &<Self::Renderer as iced_native::Renderer>::Output,
|
||||||
overlay: &[T],
|
overlay: &[T],
|
||||||
) -> Result<mouse::Interaction, iced_graphics::window::SwapChainError> {
|
) -> Result<mouse::Interaction, iced_graphics::window::SwapChainError> {
|
||||||
match swap_chain.get_current_frame() {
|
match surface.get_current_frame() {
|
||||||
Ok(frame) => {
|
Ok(frame) => {
|
||||||
let mut encoder = self.device.create_command_encoder(
|
let mut encoder = self.device.create_command_encoder(
|
||||||
&wgpu::CommandEncoderDescriptor {
|
&wgpu::CommandEncoderDescriptor {
|
||||||
|
|
@ -150,13 +151,18 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let view = &frame
|
||||||
|
.output
|
||||||
|
.texture
|
||||||
|
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
|
|
||||||
let _ =
|
let _ =
|
||||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: Some(
|
label: Some(
|
||||||
"iced_wgpu::window::Compositor render pass",
|
"iced_wgpu::window::Compositor render pass",
|
||||||
),
|
),
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachment {
|
color_attachments: &[wgpu::RenderPassColorAttachment {
|
||||||
view: &frame.output.view,
|
view,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations {
|
ops: wgpu::Operations {
|
||||||
load: wgpu::LoadOp::Clear({
|
load: wgpu::LoadOp::Clear({
|
||||||
|
|
@ -180,7 +186,7 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
&mut self.device,
|
&mut self.device,
|
||||||
&mut self.staging_belt,
|
&mut self.staging_belt,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
&frame.output.view,
|
view,
|
||||||
viewport,
|
viewport,
|
||||||
output,
|
output,
|
||||||
overlay,
|
overlay,
|
||||||
|
|
@ -201,16 +207,16 @@ impl iced_graphics::window::Compositor for Compositor {
|
||||||
Ok(mouse_interaction)
|
Ok(mouse_interaction)
|
||||||
}
|
}
|
||||||
Err(error) => match error {
|
Err(error) => match error {
|
||||||
wgpu::SwapChainError::Timeout => {
|
wgpu::SurfaceError::Timeout => {
|
||||||
Err(iced_graphics::window::SwapChainError::Timeout)
|
Err(iced_graphics::window::SwapChainError::Timeout)
|
||||||
}
|
}
|
||||||
wgpu::SwapChainError::Outdated => {
|
wgpu::SurfaceError::Outdated => {
|
||||||
Err(iced_graphics::window::SwapChainError::Outdated)
|
Err(iced_graphics::window::SwapChainError::Outdated)
|
||||||
}
|
}
|
||||||
wgpu::SwapChainError::Lost => {
|
wgpu::SurfaceError::Lost => {
|
||||||
Err(iced_graphics::window::SwapChainError::Lost)
|
Err(iced_graphics::window::SwapChainError::Lost)
|
||||||
}
|
}
|
||||||
wgpu::SwapChainError::OutOfMemory => {
|
wgpu::SurfaceError::OutOfMemory => {
|
||||||
Err(iced_graphics::window::SwapChainError::OutOfMemory)
|
Err(iced_graphics::window::SwapChainError::OutOfMemory)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ async fn run_instance<A, E, C>(
|
||||||
use iced_futures::futures::stream::StreamExt;
|
use iced_futures::futures::stream::StreamExt;
|
||||||
use winit::event;
|
use winit::event;
|
||||||
|
|
||||||
let surface = compositor.create_surface(&window);
|
let mut surface = compositor.create_surface(&window);
|
||||||
let mut clipboard = Clipboard::connect(&window);
|
let mut clipboard = Clipboard::connect(&window);
|
||||||
|
|
||||||
let mut state = State::new(&application, &window);
|
let mut state = State::new(&application, &window);
|
||||||
|
|
@ -370,6 +370,7 @@ async fn run_instance<A, E, C>(
|
||||||
match compositor.draw(
|
match compositor.draw(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
&mut swap_chain,
|
&mut swap_chain,
|
||||||
|
&mut surface,
|
||||||
state.viewport(),
|
state.viewport(),
|
||||||
state.background_color(),
|
state.background_color(),
|
||||||
&primitive,
|
&primitive,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue