update wgpu to 0.13

This commit is contained in:
Cupnfish 2022-07-02 15:39:42 +08:00
parent e6e3eff876
commit c148557cab
15 changed files with 140 additions and 144 deletions

View file

@ -7,7 +7,6 @@ use scene::Scene;
use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport}; use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport};
use iced_winit::{conversion, futures, program, winit, Clipboard, Debug, Size}; use iced_winit::{conversion, futures, program, winit, Clipboard, Debug, Size};
use futures::task::SpawnExt;
use winit::{ use winit::{
dpi::PhysicalPosition, dpi::PhysicalPosition,
event::{Event, ModifiersState, WindowEvent}, event::{Event, ModifiersState, WindowEvent},
@ -90,9 +89,7 @@ pub fn main() {
let needed_limits = wgpu::Limits::default(); let needed_limits = wgpu::Limits::default();
( (
surface surface.get_supported_formats(&adapter)[0],
.get_preferred_format(&adapter)
.expect("Get preferred format"),
adapter adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
@ -114,15 +111,14 @@ pub fn main() {
format, format,
width: physical_size.width, width: physical_size.width,
height: physical_size.height, height: physical_size.height,
present_mode: wgpu::PresentMode::Mailbox, present_mode: wgpu::PresentMode::AutoVsync,
}, },
); );
let mut resized = false; let mut resized = false;
// Initialize staging belt and local pool // Initialize staging belt
let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024); let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024);
let mut local_pool = futures::executor::LocalPool::new();
// Initialize scene and GUI controls // Initialize scene and GUI controls
let scene = Scene::new(&mut device, format); let scene = Scene::new(&mut device, format);
@ -207,7 +203,7 @@ pub fn main() {
format: format, format: format,
width: size.width, width: size.width,
height: size.height, height: size.height,
present_mode: wgpu::PresentMode::Mailbox, present_mode: wgpu::PresentMode::AutoVsync,
}, },
); );
@ -262,12 +258,8 @@ pub fn main() {
); );
// And recall staging buffers // And recall staging buffers
local_pool staging_belt.recall();
.spawner()
.spawn(staging_belt.recall())
.expect("Recall staging buffers");
local_pool.run_until_stalled();
} }
Err(error) => match error { Err(error) => match error {
wgpu::SurfaceError::OutOfMemory => { wgpu::SurfaceError::OutOfMemory => {

View file

@ -23,7 +23,7 @@ impl Scene {
) -> wgpu::RenderPass<'a> { ) -> wgpu::RenderPass<'a> {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor { encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None, label: None,
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target, view: target,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
@ -39,7 +39,7 @@ impl Scene {
}), }),
store: true, store: true,
}, },
}], })],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}) })
} }
@ -55,8 +55,8 @@ fn build_pipeline(
texture_format: wgpu::TextureFormat, texture_format: wgpu::TextureFormat,
) -> wgpu::RenderPipeline { ) -> wgpu::RenderPipeline {
let (vs_module, fs_module) = ( let (vs_module, fs_module) = (
device.create_shader_module(&wgpu::include_wgsl!("shader/vert.wgsl")), device.create_shader_module(wgpu::include_wgsl!("shader/vert.wgsl")),
device.create_shader_module(&wgpu::include_wgsl!("shader/frag.wgsl")), device.create_shader_module(wgpu::include_wgsl!("shader/frag.wgsl")),
); );
let pipeline_layout = let pipeline_layout =
@ -78,14 +78,14 @@ fn build_pipeline(
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &fs_module, module: &fs_module,
entry_point: "main", entry_point: "main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format: texture_format, format: texture_format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE, color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE,
}), }),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,

View file

@ -1,4 +1,4 @@
[[stage(fragment)]] @fragment
fn main() -> [[location(0)]] vec4<f32> { fn main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0); return vec4<f32>(1.0, 0.0, 0.0, 1.0);
} }

View file

@ -1,5 +1,5 @@
[[stage(vertex)]] @vertex
fn main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> { fn main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(1 - i32(in_vertex_index)) * 0.5; let x = f32(1 - i32(in_vertex_index)) * 0.5;
let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5; let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5;
return vec4<f32>(x, y, 0.0, 1.0); return vec4<f32>(x, y, 0.0, 1.0);

View file

@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"]
webgl = ["wgpu/webgl"] webgl = ["wgpu/webgl"]
[dependencies] [dependencies]
wgpu = "0.12" wgpu = "0.13"
wgpu_glyph = "0.16" wgpu_glyph = {version = "0.16",path = "../../wgpu_glyph"}
glyph_brush = "0.7" glyph_brush = "0.7"
raw-window-handle = "0.4" raw-window-handle = "0.4"
log = "0.4" log = "0.4"
@ -39,7 +39,7 @@ kamadak-exif = "0.5"
bitflags = "1.2" bitflags = "1.2"
[dependencies.bytemuck] [dependencies.bytemuck]
version = "1.4" version = "1.9"
features = ["derive"] features = ["derive"]
[dependencies.iced_native] [dependencies.iced_native]

View file

@ -136,7 +136,7 @@ impl Pipeline {
}); });
let shader = let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor { device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::image::shader"), label: Some("iced_wgpu::image::shader"),
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"),
@ -176,7 +176,7 @@ impl Pipeline {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent { color: wgpu::BlendComponent {
@ -191,7 +191,7 @@ impl Pipeline {
}, },
}), }),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
@ -406,14 +406,16 @@ 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"), label: Some("iced_wgpu::image render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(
view: target, wgpu::RenderPassColorAttachment {
resolve_target: None, view: target,
ops: wgpu::Operations { resolve_target: None,
load: wgpu::LoadOp::Load, ops: wgpu::Operations {
store: true, load: wgpu::LoadOp::Load,
store: true,
},
}, },
}], )],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });

View file

@ -59,7 +59,7 @@ impl Pipeline {
}); });
let shader = let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor { device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::quad::shader"), label: Some("iced_wgpu::quad::shader"),
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"),
@ -100,7 +100,7 @@ impl Pipeline {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState { blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent { color: wgpu::BlendComponent {
@ -115,7 +115,7 @@ impl Pipeline {
}, },
}), }),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
@ -211,14 +211,16 @@ 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"), label: Some("iced_wgpu::quad render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(
view: target, wgpu::RenderPassColorAttachment {
resolve_target: None, view: target,
ops: wgpu::Operations { resolve_target: None,
load: wgpu::LoadOp::Load, ops: wgpu::Operations {
store: true, load: wgpu::LoadOp::Load,
store: true,
},
}, },
}], )],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });

View file

@ -63,7 +63,7 @@ impl Settings {
impl Default for Settings { impl Default for Settings {
fn default() -> Settings { fn default() -> Settings {
Settings { Settings {
present_mode: wgpu::PresentMode::Mailbox, present_mode: wgpu::PresentMode::AutoVsync,
internal_backend: wgpu::Backends::all(), internal_backend: wgpu::Backends::all(),
default_font: None, default_font: None,
default_text_size: 20, default_text_size: 20,

View file

@ -16,19 +16,19 @@ var<private> uvs: array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2<f32>(1.0, 1.0) vec2<f32>(1.0, 1.0)
); );
[[group(0), binding(0)]] var u_sampler: sampler; @group(0) @binding(0) var u_sampler: sampler;
[[group(1), binding(0)]] var u_texture: texture_2d<f32>; @group(1) @binding(0) var u_texture: texture_2d<f32>;
struct VertexInput { struct VertexInput {
[[builtin(vertex_index)]] vertex_index: u32; @builtin(vertex_index) vertex_index: u32,
}; };
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] uv: vec2<f32>; @location(0) uv: vec2<f32>,
}; };
[[stage(vertex)]] @vertex
fn vs_main(input: VertexInput) -> VertexOutput { fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
out.uv = uvs[input.vertex_index]; out.uv = uvs[input.vertex_index];
@ -37,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
return out; return out;
} }
[[stage(fragment)]] @fragment
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> { fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(u_texture, u_sampler, input.uv); return textureSample(u_texture, u_sampler, input.uv);
} }

View file

@ -2,26 +2,26 @@ struct Globals {
transform: mat4x4<f32>; transform: mat4x4<f32>;
}; };
[[group(0), binding(0)]] var<uniform> globals: Globals; @group(0) @binding(0) var<uniform> globals: Globals;
[[group(0), binding(1)]] var u_sampler: sampler; @group(0) @binding(1) var u_sampler: sampler;
[[group(1), binding(0)]] var u_texture: texture_2d_array<f32>; @group(1) @binding(0) var u_texture: texture_2d_array<f32>;
struct VertexInput { struct VertexInput {
[[location(0)]] v_pos: vec2<f32>; @location(0) v_pos: vec2<f32>,
[[location(1)]] pos: vec2<f32>; @location(1) pos: vec2<f32>,
[[location(2)]] scale: vec2<f32>; @location(2) scale: vec2<f32>,
[[location(3)]] atlas_pos: vec2<f32>; @location(3) atlas_pos: vec2<f32>,
[[location(4)]] atlas_scale: vec2<f32>; @location(4) atlas_scale: vec2<f32>,
[[location(5)]] layer: i32; @location(5) layer: i32,
}; };
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] uv: vec2<f32>; @location(0) uv: vec2<f32>,
[[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation. @location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation.
}; };
[[stage(vertex)]] @vertex
fn vs_main(input: VertexInput) -> VertexOutput { fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
@ -40,7 +40,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
return out; return out;
} }
[[stage(fragment)]] @fragment
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> { fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(u_texture, u_sampler, input.uv, i32(input.layer)); return textureSample(u_texture, u_sampler, input.uv, i32(input.layer));
} }

View file

@ -1,31 +1,31 @@
struct Globals { struct Globals {
transform: mat4x4<f32>; transform: mat4x4<f32>,
scale: f32; scale: f32,
}; };
[[group(0), binding(0)]] var<uniform> globals: Globals; @group(0) @binding(0) var<uniform> globals: Globals;
struct VertexInput { struct VertexInput {
[[location(0)]] v_pos: vec2<f32>; @location(0) v_pos: vec2<f32>,
[[location(1)]] pos: vec2<f32>; @location(1) pos: vec2<f32>,
[[location(2)]] scale: vec2<f32>; @location(2) scale: vec2<f32>,
[[location(3)]] color: vec4<f32>; @location(3) color: vec4<f32>,
[[location(4)]] border_color: vec4<f32>; @location(4) border_color: vec4<f32>,
[[location(5)]] border_radius: f32; @location(5) border_radius: f32,
[[location(6)]] border_width: f32; @location(6) border_width: f32,
}; };
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] color: vec4<f32>; @location(0) color: vec4<f32>,
[[location(1)]] border_color: vec4<f32>; @location(1) border_color: vec4<f32>,
[[location(2)]] pos: vec2<f32>; @location(2) pos: vec2<f32>,
[[location(3)]] scale: vec2<f32>; @location(3) scale: vec2<f32>,
[[location(4)]] border_radius: f32; @location(4) border_radius: f32,
[[location(5)]] border_width: f32; @location(5) border_width: f32,
}; };
[[stage(vertex)]] @vertex
fn vs_main(input: VertexInput) -> VertexOutput { fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
@ -77,10 +77,10 @@ fn distance_alg(
} }
[[stage(fragment)]] @fragment
fn fs_main( fn fs_main(
input: VertexOutput input: VertexOutput
) -> [[location(0)]] vec4<f32> { ) -> @location(0) vec4<f32> {
var mixed_color: vec4<f32> = input.color; var mixed_color: vec4<f32> = input.color;
if (input.border_width > 0.0) { if (input.border_width > 0.0) {
@ -96,7 +96,7 @@ fn fs_main(
internal_border internal_border
); );
var border_mix: f32 = smoothStep( var border_mix: f32 = smoothstep(
max(internal_border - 0.5, 0.0), max(internal_border - 0.5, 0.0),
internal_border + 0.5, internal_border + 0.5,
internal_distance internal_distance
@ -112,7 +112,7 @@ fn fs_main(
input.border_radius input.border_radius
); );
var radius_alpha: f32 = 1.0 - smoothStep( var radius_alpha: f32 = 1.0 - smoothstep(
max(input.border_radius - 0.5, 0.0), max(input.border_radius - 0.5, 0.0),
input.border_radius + 0.5, input.border_radius + 0.5,
dist); dist);

View file

@ -1,20 +1,20 @@
struct Globals { struct Globals {
transform: mat4x4<f32>; transform: mat4x4<f32>,
}; };
[[group(0), binding(0)]] var<uniform> globals: Globals; @group(0) @binding(0) var<uniform> globals: Globals;
struct VertexInput { struct VertexInput {
[[location(0)]] position: vec2<f32>; @location(0) position: vec2<f32>,
[[location(1)]] color: vec4<f32>; @location(1) color: vec4<f32>,
}; };
struct VertexOutput { struct VertexOutput {
[[builtin(position)]] position: vec4<f32>; @builtin(position) position: vec4<f32>,
[[location(0)]] color: vec4<f32>; @location(0) color: vec4<f32>,
}; };
[[stage(vertex)]] @vertex
fn vs_main(input: VertexInput) -> VertexOutput { fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput; var out: VertexOutput;
@ -24,7 +24,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
return out; return out;
} }
[[stage(fragment)]] @fragment
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> { fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
return input.color; return input.color;
} }

View file

@ -132,7 +132,7 @@ impl Pipeline {
}); });
let shader = let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor { device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::triangle::shader"), label: Some("iced_wgpu::triangle::shader"),
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"),
@ -160,11 +160,11 @@ impl Pipeline {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format, format,
blend: Some(wgpu::BlendState::ALPHA_BLENDING), blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
@ -350,11 +350,13 @@ 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"), label: Some("iced_wgpu::triangle render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(
view: attachment, wgpu::RenderPassColorAttachment {
resolve_target, view: attachment,
ops: wgpu::Operations { load, store: true }, resolve_target,
}], ops: wgpu::Operations { load, store: true },
},
)],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });

View file

@ -74,7 +74,7 @@ impl Blit {
}); });
let shader = let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor { device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::triangle::blit_shader"), label: Some("iced_wgpu::triangle::blit_shader"),
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"),
@ -93,13 +93,13 @@ impl Blit {
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {
module: &shader, module: &shader,
entry_point: "fs_main", entry_point: "fs_main",
targets: &[wgpu::ColorTargetState { targets: &[Some(wgpu::ColorTargetState {
format, format,
blend: Some( blend: Some(
wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING, wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING,
), ),
write_mask: wgpu::ColorWrites::ALL, write_mask: wgpu::ColorWrites::ALL,
}], })],
}), }),
primitive: wgpu::PrimitiveState { primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
@ -169,14 +169,14 @@ 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"), label: Some("iced_wgpu::triangle::msaa render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target, view: target,
resolve_target: None, resolve_target: None,
ops: wgpu::Operations { ops: wgpu::Operations {
load: wgpu::LoadOp::Load, load: wgpu::LoadOp::Load,
store: true, store: true,
}, },
}], })],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });

View file

@ -1,7 +1,6 @@
use crate::{Backend, Color, Error, Renderer, Settings, Viewport}; use crate::{Backend, Color, Error, Renderer, Settings, Viewport};
use futures::stream::{self, StreamExt}; use futures::stream::{self, StreamExt};
use futures::task::SpawnExt;
use iced_graphics::compositor; use iced_graphics::compositor;
use iced_native::futures; use iced_native::futures;
@ -16,7 +15,6 @@ pub struct Compositor {
device: wgpu::Device, device: wgpu::Device,
queue: wgpu::Queue, queue: wgpu::Queue,
staging_belt: wgpu::util::StagingBelt, staging_belt: wgpu::util::StagingBelt,
local_pool: futures::executor::LocalPool,
format: wgpu::TextureFormat, format: wgpu::TextureFormat,
} }
@ -61,9 +59,14 @@ impl Compositor {
log::info!("Selected: {:#?}", adapter.get_info()); log::info!("Selected: {:#?}", adapter.get_info());
let format = compatible_surface let format = compatible_surface.as_ref().and_then(|surface| {
.as_ref() let formats = surface.get_supported_formats(&adapter);
.and_then(|surface| surface.get_preferred_format(&adapter))?; if formats.is_empty() {
None
} else {
Some(formats[0])
}
})?;
log::info!("Selected format: {:?}", format); log::info!("Selected format: {:?}", format);
@ -98,7 +101,6 @@ impl Compositor {
.await?; .await?;
let staging_belt = wgpu::util::StagingBelt::new(Self::CHUNK_SIZE); let staging_belt = wgpu::util::StagingBelt::new(Self::CHUNK_SIZE);
let local_pool = futures::executor::LocalPool::new();
Some(Compositor { Some(Compositor {
instance, instance,
@ -107,7 +109,6 @@ impl Compositor {
device, device,
queue, queue,
staging_belt, staging_belt,
local_pool,
format, format,
}) })
} }
@ -200,24 +201,26 @@ impl iced_graphics::window::Compositor for Compositor {
label: Some( label: Some(
"iced_wgpu::window::Compositor render pass", "iced_wgpu::window::Compositor render pass",
), ),
color_attachments: &[wgpu::RenderPassColorAttachment { color_attachments: &[Some(
view, wgpu::RenderPassColorAttachment {
resolve_target: None, view,
ops: wgpu::Operations { resolve_target: None,
load: wgpu::LoadOp::Clear({ ops: wgpu::Operations {
let [r, g, b, a] = load: wgpu::LoadOp::Clear({
background_color.into_linear(); let [r, g, b, a] =
background_color.into_linear();
wgpu::Color { wgpu::Color {
r: f64::from(r), r: f64::from(r),
g: f64::from(g), g: f64::from(g),
b: f64::from(b), b: f64::from(b),
a: f64::from(a), a: f64::from(a),
} }
}), }),
store: true, store: true,
},
}, },
}], )],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });
@ -235,16 +238,11 @@ impl iced_graphics::window::Compositor for Compositor {
// Submit work // Submit work
self.staging_belt.finish(); self.staging_belt.finish();
self.queue.submit(Some(encoder.finish())); let _idx = self.queue.submit(Some(encoder.finish()));
frame.present(); frame.present();
// Recall staging buffers // Recall staging buffers
self.local_pool self.staging_belt.recall();
.spawner()
.spawn(self.staging_belt.recall())
.expect("Recall staging belt");
self.local_pool.run_until_stalled();
Ok(()) Ok(())
} }