From c148557cabf1fb9127b00b248479de2eb1d1d477 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 15:39:42 +0800 Subject: [PATCH 1/9] update `wgpu` to `0.13` --- examples/integration_wgpu/src/main.rs | 18 ++---- examples/integration_wgpu/src/scene.rs | 12 ++-- .../integration_wgpu/src/shader/frag.wgsl | 4 +- .../integration_wgpu/src/shader/vert.wgsl | 4 +- wgpu/Cargo.toml | 6 +- wgpu/src/image.rs | 22 +++---- wgpu/src/quad.rs | 22 +++---- wgpu/src/settings.rs | 2 +- wgpu/src/shader/blit.wgsl | 16 ++--- wgpu/src/shader/image.wgsl | 30 +++++----- wgpu/src/shader/quad.wgsl | 44 +++++++------- wgpu/src/shader/triangle.wgsl | 18 +++--- wgpu/src/triangle.rs | 18 +++--- wgpu/src/triangle/msaa.rs | 10 ++-- wgpu/src/window/compositor.rs | 60 +++++++++---------- 15 files changed, 141 insertions(+), 145 deletions(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 045ee0d3dc..7235e72b83 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -7,7 +7,6 @@ use scene::Scene; use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport}; use iced_winit::{conversion, futures, program, winit, Clipboard, Debug, Size}; -use futures::task::SpawnExt; use winit::{ dpi::PhysicalPosition, event::{Event, ModifiersState, WindowEvent}, @@ -90,9 +89,7 @@ pub fn main() { let needed_limits = wgpu::Limits::default(); ( - surface - .get_preferred_format(&adapter) - .expect("Get preferred format"), + surface.get_supported_formats(&adapter)[0], adapter .request_device( &wgpu::DeviceDescriptor { @@ -114,15 +111,14 @@ pub fn main() { format, width: physical_size.width, height: physical_size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }, ); 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 local_pool = futures::executor::LocalPool::new(); // Initialize scene and GUI controls let scene = Scene::new(&mut device, format); @@ -207,7 +203,7 @@ pub fn main() { format: format, width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, }, ); @@ -262,12 +258,8 @@ pub fn main() { ); // And recall staging buffers - local_pool - .spawner() - .spawn(staging_belt.recall()) - .expect("Recall staging buffers"); + staging_belt.recall(); - local_pool.run_until_stalled(); } Err(error) => match error { wgpu::SurfaceError::OutOfMemory => { diff --git a/examples/integration_wgpu/src/scene.rs b/examples/integration_wgpu/src/scene.rs index fbda132670..af75e67c79 100644 --- a/examples/integration_wgpu/src/scene.rs +++ b/examples/integration_wgpu/src/scene.rs @@ -23,7 +23,7 @@ impl Scene { ) -> wgpu::RenderPass<'a> { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: target, resolve_target: None, ops: wgpu::Operations { @@ -39,7 +39,7 @@ impl Scene { }), store: true, }, - }], + })], depth_stencil_attachment: None, }) } @@ -55,8 +55,8 @@ fn build_pipeline( texture_format: wgpu::TextureFormat, ) -> wgpu::RenderPipeline { let (vs_module, fs_module) = ( - 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/vert.wgsl")), + device.create_shader_module(wgpu::include_wgsl!("shader/frag.wgsl")), ); let pipeline_layout = @@ -78,14 +78,14 @@ fn build_pipeline( fragment: Some(wgpu::FragmentState { module: &fs_module, entry_point: "main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format: texture_format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, diff --git a/examples/integration_wgpu/src/shader/frag.wgsl b/examples/integration_wgpu/src/shader/frag.wgsl index a6f61336ee..cf27bb5639 100644 --- a/examples/integration_wgpu/src/shader/frag.wgsl +++ b/examples/integration_wgpu/src/shader/frag.wgsl @@ -1,4 +1,4 @@ -[[stage(fragment)]] -fn main() -> [[location(0)]] vec4 { +@fragment +fn main() -> @location(0) vec4 { return vec4(1.0, 0.0, 0.0, 1.0); } diff --git a/examples/integration_wgpu/src/shader/vert.wgsl b/examples/integration_wgpu/src/shader/vert.wgsl index 7ef47fb222..e353e6ba3b 100644 --- a/examples/integration_wgpu/src/shader/vert.wgsl +++ b/examples/integration_wgpu/src/shader/vert.wgsl @@ -1,5 +1,5 @@ -[[stage(vertex)]] -fn main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4 { +@vertex +fn main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4 { let x = f32(1 - i32(in_vertex_index)) * 0.5; let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5; return vec4(x, y, 0.0, 1.0); diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index a4378aa048..803f3e3bbc 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"] webgl = ["wgpu/webgl"] [dependencies] -wgpu = "0.12" -wgpu_glyph = "0.16" +wgpu = "0.13" +wgpu_glyph = {version = "0.16",path = "../../wgpu_glyph"} glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" @@ -39,7 +39,7 @@ kamadak-exif = "0.5" bitflags = "1.2" [dependencies.bytemuck] -version = "1.4" +version = "1.9" features = ["derive"] [dependencies.iced_native] diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 0fefbfaf82..750ad62a39 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -136,7 +136,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::image::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/image.wgsl"), @@ -176,7 +176,7 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent { @@ -191,7 +191,7 @@ impl Pipeline { }, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -406,14 +406,16 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::image render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 22f3b81538..a117df64c2 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -59,7 +59,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::quad::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/quad.wgsl"), @@ -100,7 +100,7 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState { color: wgpu::BlendComponent { @@ -115,7 +115,7 @@ impl Pipeline { }, }), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -211,14 +211,16 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::quad render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 23b5590479..7bc752ff04 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -63,7 +63,7 @@ impl Settings { impl Default for Settings { fn default() -> Settings { Settings { - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::AutoVsync, internal_backend: wgpu::Backends::all(), default_font: None, default_text_size: 20, diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl index f8f6e2d4da..5ff86f0a2a 100644 --- a/wgpu/src/shader/blit.wgsl +++ b/wgpu/src/shader/blit.wgsl @@ -16,19 +16,19 @@ var uvs: array, 6> = array, 6>( vec2(1.0, 1.0) ); -[[group(0), binding(0)]] var u_sampler: sampler; -[[group(1), binding(0)]] var u_texture: texture_2d; +@group(0) @binding(0) var u_sampler: sampler; +@group(1) @binding(0) var u_texture: texture_2d; struct VertexInput { - [[builtin(vertex_index)]] vertex_index: u32; + @builtin(vertex_index) vertex_index: u32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec2; + @builtin(position) position: vec4, + @location(0) uv: vec2, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; out.uv = uvs[input.vertex_index]; @@ -37,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return textureSample(u_texture, u_sampler, input.uv); } diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index ff304422bc..bb1c6b9df3 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -2,26 +2,26 @@ struct Globals { transform: mat4x4; }; -[[group(0), binding(0)]] var globals: Globals; -[[group(0), binding(1)]] var u_sampler: sampler; -[[group(1), binding(0)]] var u_texture: texture_2d_array; +@group(0) @binding(0) var globals: Globals; +@group(0) @binding(1) var u_sampler: sampler; +@group(1) @binding(0) var u_texture: texture_2d_array; struct VertexInput { - [[location(0)]] v_pos: vec2; - [[location(1)]] pos: vec2; - [[location(2)]] scale: vec2; - [[location(3)]] atlas_pos: vec2; - [[location(4)]] atlas_scale: vec2; - [[location(5)]] layer: i32; + @location(0) v_pos: vec2, + @location(1) pos: vec2, + @location(2) scale: vec2, + @location(3) atlas_pos: vec2, + @location(4) atlas_scale: vec2, + @location(5) layer: i32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec2; - [[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation. + @builtin(position) position: vec4, + @location(0) uv: vec2, + @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 { var out: VertexOutput; @@ -40,7 +40,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return textureSample(u_texture, u_sampler, input.uv, i32(input.layer)); } diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index 73f5d5971c..2e31cde394 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -1,31 +1,31 @@ struct Globals { - transform: mat4x4; - scale: f32; + transform: mat4x4, + scale: f32, }; -[[group(0), binding(0)]] var globals: Globals; +@group(0) @binding(0) var globals: Globals; struct VertexInput { - [[location(0)]] v_pos: vec2; - [[location(1)]] pos: vec2; - [[location(2)]] scale: vec2; - [[location(3)]] color: vec4; - [[location(4)]] border_color: vec4; - [[location(5)]] border_radius: f32; - [[location(6)]] border_width: f32; + @location(0) v_pos: vec2, + @location(1) pos: vec2, + @location(2) scale: vec2, + @location(3) color: vec4, + @location(4) border_color: vec4, + @location(5) border_radius: f32, + @location(6) border_width: f32, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] color: vec4; - [[location(1)]] border_color: vec4; - [[location(2)]] pos: vec2; - [[location(3)]] scale: vec2; - [[location(4)]] border_radius: f32; - [[location(5)]] border_width: f32; + @builtin(position) position: vec4, + @location(0) color: vec4, + @location(1) border_color: vec4, + @location(2) pos: vec2, + @location(3) scale: vec2, + @location(4) border_radius: f32, + @location(5) border_width: f32, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -77,10 +77,10 @@ fn distance_alg( } -[[stage(fragment)]] +@fragment fn fs_main( input: VertexOutput -) -> [[location(0)]] vec4 { +) -> @location(0) vec4 { var mixed_color: vec4 = input.color; if (input.border_width > 0.0) { @@ -96,7 +96,7 @@ fn fs_main( internal_border ); - var border_mix: f32 = smoothStep( + var border_mix: f32 = smoothstep( max(internal_border - 0.5, 0.0), internal_border + 0.5, internal_distance @@ -112,7 +112,7 @@ fn fs_main( 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), input.border_radius + 0.5, dist); diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl index 61d9c5a474..4348cffd7c 100644 --- a/wgpu/src/shader/triangle.wgsl +++ b/wgpu/src/shader/triangle.wgsl @@ -1,20 +1,20 @@ struct Globals { - transform: mat4x4; + transform: mat4x4, }; -[[group(0), binding(0)]] var globals: Globals; +@group(0) @binding(0) var globals: Globals; struct VertexInput { - [[location(0)]] position: vec2; - [[location(1)]] color: vec4; + @location(0) position: vec2, + @location(1) color: vec4, }; struct VertexOutput { - [[builtin(position)]] position: vec4; - [[location(0)]] color: vec4; + @builtin(position) position: vec4, + @location(0) color: vec4, }; -[[stage(vertex)]] +@vertex fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -24,7 +24,7 @@ fn vs_main(input: VertexInput) -> VertexOutput { return out; } -[[stage(fragment)]] -fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { +@fragment +fn fs_main(input: VertexOutput) -> @location(0) vec4 { return input.color; } diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index bed64e9991..40e2f8551d 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -132,7 +132,7 @@ impl Pipeline { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::triangle::shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("shader/triangle.wgsl"), @@ -160,11 +160,11 @@ impl Pipeline { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some(wgpu::BlendState::ALPHA_BLENDING), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -350,11 +350,13 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { - view: attachment, - resolve_target, - ops: wgpu::Operations { load, store: true }, - }], + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view: attachment, + resolve_target, + ops: wgpu::Operations { load, store: true }, + }, + )], depth_stencil_attachment: None, }); diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 5d3ee31195..7edeeb9440 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -74,7 +74,7 @@ impl Blit { }); let shader = - device.create_shader_module(&wgpu::ShaderModuleDescriptor { + device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("iced_wgpu::triangle::blit_shader"), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed( include_str!("../shader/blit.wgsl"), @@ -93,13 +93,13 @@ impl Blit { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", - targets: &[wgpu::ColorTargetState { + targets: &[Some(wgpu::ColorTargetState { format, blend: Some( wgpu::BlendState::PREMULTIPLIED_ALPHA_BLENDING, ), write_mask: wgpu::ColorWrites::ALL, - }], + })], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, @@ -169,14 +169,14 @@ impl Blit { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle::msaa render pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, store: true, }, - }], + })], depth_stencil_attachment: None, }); diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index dde5f09f6b..c064a86cf1 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -1,7 +1,6 @@ use crate::{Backend, Color, Error, Renderer, Settings, Viewport}; use futures::stream::{self, StreamExt}; -use futures::task::SpawnExt; use iced_graphics::compositor; use iced_native::futures; @@ -16,7 +15,6 @@ pub struct Compositor { device: wgpu::Device, queue: wgpu::Queue, staging_belt: wgpu::util::StagingBelt, - local_pool: futures::executor::LocalPool, format: wgpu::TextureFormat, } @@ -61,9 +59,14 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); - let format = compatible_surface - .as_ref() - .and_then(|surface| surface.get_preferred_format(&adapter))?; + let format = compatible_surface.as_ref().and_then(|surface| { + let formats = surface.get_supported_formats(&adapter); + if formats.is_empty() { + None + } else { + Some(formats[0]) + } + })?; log::info!("Selected format: {:?}", format); @@ -98,7 +101,6 @@ impl Compositor { .await?; let staging_belt = wgpu::util::StagingBelt::new(Self::CHUNK_SIZE); - let local_pool = futures::executor::LocalPool::new(); Some(Compositor { instance, @@ -107,7 +109,6 @@ impl Compositor { device, queue, staging_belt, - local_pool, format, }) } @@ -200,24 +201,26 @@ impl iced_graphics::window::Compositor for Compositor { label: Some( "iced_wgpu::window::Compositor render pass", ), - color_attachments: &[wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear({ - let [r, g, b, a] = - background_color.into_linear(); - - wgpu::Color { - r: f64::from(r), - g: f64::from(g), - b: f64::from(b), - a: f64::from(a), - } - }), - store: true, + color_attachments: &[Some( + wgpu::RenderPassColorAttachment { + view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear({ + let [r, g, b, a] = + background_color.into_linear(); + + wgpu::Color { + r: f64::from(r), + g: f64::from(g), + b: f64::from(b), + a: f64::from(a), + } + }), + store: true, + }, }, - }], + )], depth_stencil_attachment: None, }); @@ -235,16 +238,11 @@ impl iced_graphics::window::Compositor for Compositor { // Submit work self.staging_belt.finish(); - self.queue.submit(Some(encoder.finish())); + let _idx = self.queue.submit(Some(encoder.finish())); frame.present(); // Recall staging buffers - self.local_pool - .spawner() - .spawn(self.staging_belt.recall()) - .expect("Recall staging belt"); - - self.local_pool.run_until_stalled(); + self.staging_belt.recall(); Ok(()) } From 095ac18c158c352c9ca4214d4f136d3c06882e6d Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 15:55:10 +0800 Subject: [PATCH 2/9] replace `path` to `git` --- wgpu/Cargo.toml | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 803f3e3bbc..ec10a4ea18 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,35 +1,35 @@ [package] name = "iced_wgpu" version = "0.5.1" -authors = ["Héctor Ramón Jiménez "] +authors = [ "Héctor Ramón Jiménez " ] edition = "2021" description = "A wgpu renderer for Iced" license = "MIT AND OFL-1.1" repository = "https://github.com/iced-rs/iced" [features] -svg = ["resvg", "usvg", "tiny-skia"] -image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] -png = ["image_rs/png"] -jpeg = ["image_rs/jpeg"] -jpeg_rayon = ["image_rs/jpeg_rayon"] -gif = ["image_rs/gif"] -webp = ["image_rs/webp"] -pnm = ["image_rs/pnm"] -ico = ["image_rs/ico"] -bmp = ["image_rs/bmp"] -hdr = ["image_rs/hdr"] -dds = ["image_rs/dds"] -farbfeld = ["image_rs/farbfeld"] -canvas = ["iced_graphics/canvas"] -qr_code = ["iced_graphics/qr_code"] -default_system_font = ["iced_graphics/font-source"] -spirv = ["wgpu/spirv"] -webgl = ["wgpu/webgl"] +svg = [ "resvg", "usvg", "tiny-skia" ] +image = [ "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp" ] +png = [ "image_rs/png" ] +jpeg = [ "image_rs/jpeg" ] +jpeg_rayon = [ "image_rs/jpeg_rayon" ] +gif = [ "image_rs/gif" ] +webp = [ "image_rs/webp" ] +pnm = [ "image_rs/pnm" ] +ico = [ "image_rs/ico" ] +bmp = [ "image_rs/bmp" ] +hdr = [ "image_rs/hdr" ] +dds = [ "image_rs/dds" ] +farbfeld = [ "image_rs/farbfeld" ] +canvas = [ "iced_graphics/canvas" ] +qr_code = [ "iced_graphics/qr_code" ] +default_system_font = [ "iced_graphics/font-source" ] +spirv = [ "wgpu/spirv" ] +webgl = [ "wgpu/webgl" ] [dependencies] wgpu = "0.13" -wgpu_glyph = {version = "0.16",path = "../../wgpu_glyph"} +wgpu_glyph = { version = "0.16", git = "https://github.com/Cupnfish/wgpu_glyph.git", branch = "wgpu-0.13" } glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" @@ -40,7 +40,7 @@ bitflags = "1.2" [dependencies.bytemuck] version = "1.9" -features = ["derive"] +features = [ "derive" ] [dependencies.iced_native] version = "0.5" @@ -49,7 +49,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.3" path = "../graphics" -features = ["font-fallback", "font-icons"] +features = [ "font-fallback", "font-icons" ] [dependencies.image_rs] version = "0.23" @@ -70,5 +70,5 @@ version = "0.6" optional = true [package.metadata.docs.rs] -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = [ "--cfg", "docsrs" ] all-features = true From 64e37b26301eeab27b1089062bf24120306a3e86 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 20:30:28 +0800 Subject: [PATCH 3/9] remove unnecessary `Cargo.toml` formatting --- wgpu/Cargo.toml | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ec10a4ea18..62fba54b77 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -1,31 +1,31 @@ [package] name = "iced_wgpu" version = "0.5.1" -authors = [ "Héctor Ramón Jiménez " ] +authors = ["Héctor Ramón Jiménez "] edition = "2021" description = "A wgpu renderer for Iced" license = "MIT AND OFL-1.1" repository = "https://github.com/iced-rs/iced" [features] -svg = [ "resvg", "usvg", "tiny-skia" ] -image = [ "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp" ] -png = [ "image_rs/png" ] -jpeg = [ "image_rs/jpeg" ] -jpeg_rayon = [ "image_rs/jpeg_rayon" ] -gif = [ "image_rs/gif" ] -webp = [ "image_rs/webp" ] -pnm = [ "image_rs/pnm" ] -ico = [ "image_rs/ico" ] -bmp = [ "image_rs/bmp" ] -hdr = [ "image_rs/hdr" ] -dds = [ "image_rs/dds" ] -farbfeld = [ "image_rs/farbfeld" ] -canvas = [ "iced_graphics/canvas" ] -qr_code = [ "iced_graphics/qr_code" ] -default_system_font = [ "iced_graphics/font-source" ] -spirv = [ "wgpu/spirv" ] -webgl = [ "wgpu/webgl" ] +svg = ["resvg", "usvg", "tiny-skia"] +image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] +png = ["image_rs/png"] +jpeg = ["image_rs/jpeg"] +jpeg_rayon = ["image_rs/jpeg_rayon"] +gif = ["image_rs/gif"] +webp = ["image_rs/webp"] +pnm = ["image_rs/pnm"] +ico = ["image_rs/ico"] +bmp = ["image_rs/bmp"] +hdr = ["image_rs/hdr"] +dds = ["image_rs/dds"] +farbfeld = ["image_rs/farbfeld"] +canvas = ["iced_graphics/canvas"] +qr_code = ["iced_graphics/qr_code"] +default_system_font = ["iced_graphics/font-source"] +spirv = ["wgpu/spirv"] +webgl = ["wgpu/webgl"] [dependencies] wgpu = "0.13" @@ -40,7 +40,7 @@ bitflags = "1.2" [dependencies.bytemuck] version = "1.9" -features = [ "derive" ] +features = ["derive"] [dependencies.iced_native] version = "0.5" @@ -49,7 +49,7 @@ path = "../native" [dependencies.iced_graphics] version = "0.3" path = "../graphics" -features = [ "font-fallback", "font-icons" ] +features = ["font-fallback", "font-icons"] [dependencies.image_rs] version = "0.23" @@ -70,5 +70,5 @@ version = "0.6" optional = true [package.metadata.docs.rs] -rustdoc-args = [ "--cfg", "docsrs" ] +rustdoc-args = ["--cfg", "docsrs"] all-features = true From a88155b2a28bfcbe39c7b87d7e9befb73a7dc8d7 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 22:29:49 +0800 Subject: [PATCH 4/9] fix `wgsl` syntax --- wgpu/src/shader/image.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index bb1c6b9df3..773ef90a8d 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -1,5 +1,5 @@ struct Globals { - transform: mat4x4; + transform: mat4x4, }; @group(0) @binding(0) var globals: Globals; From 390e2a2d34d610dec057a3b6679b795e8c2a5c94 Mon Sep 17 00:00:00 2001 From: Cupnfish Date: Sat, 2 Jul 2022 22:51:51 +0800 Subject: [PATCH 5/9] better `wgsl` code style --- wgpu/src/shader/blit.wgsl | 4 ++-- wgpu/src/shader/image.wgsl | 6 +++--- wgpu/src/shader/quad.wgsl | 6 +++--- wgpu/src/shader/triangle.wgsl | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl index 5ff86f0a2a..c2ea223fdd 100644 --- a/wgpu/src/shader/blit.wgsl +++ b/wgpu/src/shader/blit.wgsl @@ -21,12 +21,12 @@ var uvs: array, 6> = array, 6>( struct VertexInput { @builtin(vertex_index) vertex_index: u32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index 773ef90a8d..5e22cdf482 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -1,6 +1,6 @@ struct Globals { transform: mat4x4, -}; +} @group(0) @binding(0) var globals: Globals; @group(0) @binding(1) var u_sampler: sampler; @@ -13,13 +13,13 @@ struct VertexInput { @location(3) atlas_pos: vec2, @location(4) atlas_scale: vec2, @location(5) layer: i32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, @location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation. -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index 2e31cde394..73edd97ce0 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -1,7 +1,7 @@ struct Globals { transform: mat4x4, scale: f32, -}; +} @group(0) @binding(0) var globals: Globals; @@ -13,7 +13,7 @@ struct VertexInput { @location(4) border_color: vec4, @location(5) border_radius: f32, @location(6) border_width: f32, -}; +} struct VertexOutput { @builtin(position) position: vec4, @@ -23,7 +23,7 @@ struct VertexOutput { @location(3) scale: vec2, @location(4) border_radius: f32, @location(5) border_width: f32, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl index 4348cffd7c..b24402f832 100644 --- a/wgpu/src/shader/triangle.wgsl +++ b/wgpu/src/shader/triangle.wgsl @@ -1,18 +1,18 @@ struct Globals { transform: mat4x4, -}; +} @group(0) @binding(0) var globals: Globals; struct VertexInput { @location(0) position: vec2, @location(1) color: vec4, -}; +} struct VertexOutput { @builtin(position) position: vec4, @location(0) color: vec4, -}; +} @vertex fn vs_main(input: VertexInput) -> VertexOutput { From 8b250d12e70f13240efd0f56828d06ab8ef78071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 3 Jul 2022 15:24:16 +0200 Subject: [PATCH 6/9] Use latest `wgpu_glyph` release on crates.io --- wgpu/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 62fba54b77..586f97d359 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -29,7 +29,7 @@ webgl = ["wgpu/webgl"] [dependencies] wgpu = "0.13" -wgpu_glyph = { version = "0.16", git = "https://github.com/Cupnfish/wgpu_glyph.git", branch = "wgpu-0.13" } +wgpu_glyph = "0.17" glyph_brush = "0.7" raw-window-handle = "0.4" log = "0.4" From 2010977bd20fe5f562e0389f24c5aa284d89e25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 3 Jul 2022 15:27:23 +0200 Subject: [PATCH 7/9] Use `expect` in `integration_wgpu` example ... together with `first` and `copied`. --- examples/integration_wgpu/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 7235e72b83..89ae03c6b7 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -89,7 +89,11 @@ pub fn main() { let needed_limits = wgpu::Limits::default(); ( - surface.get_supported_formats(&adapter)[0], + surface + .get_supported_formats(&adapter) + .first() + .copied() + .expect("Get preferred format"), adapter .request_device( &wgpu::DeviceDescriptor { From 3d38d0af91ce4a1165928cf933c1e40dc80983ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 3 Jul 2022 15:30:04 +0200 Subject: [PATCH 8/9] Simplify format selection in `iced_wgpu` --- wgpu/src/window/compositor.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index c064a86cf1..cff7104da8 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -60,12 +60,7 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); let format = compatible_surface.as_ref().and_then(|surface| { - let formats = surface.get_supported_formats(&adapter); - if formats.is_empty() { - None - } else { - Some(formats[0]) - } + surface.get_supported_formats(&adapter).first().copied() })?; log::info!("Selected format: {:?}", format); From 9adc20922d16b990eede1f6c5f059e68efe15d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 3 Jul 2022 15:48:32 +0200 Subject: [PATCH 9/9] Replace name abbreviation in `iced_wgpu` --- wgpu/src/window/compositor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index cff7104da8..91884ec48c 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -233,7 +233,7 @@ impl iced_graphics::window::Compositor for Compositor { // Submit work self.staging_belt.finish(); - let _idx = self.queue.submit(Some(encoder.finish())); + let _submission = self.queue.submit(Some(encoder.finish())); frame.present(); // Recall staging buffers