From 81f37123ad23ec5c0812604f1bb8e93fcdf4f6a0 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 25 Nov 2020 22:25:15 +0300 Subject: Update resvg to `0.12` --- wgpu/src/image/vector.rs | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 95df2e99..ab0f67d0 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -3,7 +3,7 @@ use iced_native::svg; use std::collections::{HashMap, HashSet}; pub enum Svg { - Loaded(resvg::usvg::Tree), + Loaded(usvg::Tree), NotFound, } @@ -43,17 +43,15 @@ impl Cache { return self.svgs.get(&handle.id()).unwrap(); } - let opt = resvg::Options::default(); - let svg = match handle.data() { svg::Data::Path(path) => { - match resvg::usvg::Tree::from_file(path, &opt.usvg) { + match usvg::Tree::from_file(path, &Default::default()) { Ok(tree) => Svg::Loaded(tree), Err(_) => Svg::NotFound, } } svg::Data::Bytes(bytes) => { - match resvg::usvg::Tree::from_data(&bytes, &opt.usvg) { + match usvg::Tree::from_data(&bytes, &Default::default()) { Ok(tree) => Svg::Loaded(tree), Err(_) => Svg::NotFound, } @@ -101,23 +99,38 @@ impl Cache { // We currently rerasterize the SVG when its size changes. This is slow // as heck. A GPU rasterizer like `pathfinder` may perform better. // It would be cool to be able to smooth resize the `svg` example. - let screen_size = - resvg::ScreenSize::new(width, height).unwrap(); + let img = resvg::render( + tree, + if width > height { + usvg::FitTo::Width(width) + } else { + usvg::FitTo::Height(height) + }, + None, + )?; + let width = img.width(); + let height = img.height(); - let mut canvas = - resvg::raqote::DrawTarget::new(width as i32, height as i32); + let mut rgba = img.take().into_iter(); - resvg::backend_raqote::render_to_canvas( - tree, - &resvg::Options::default(), - screen_size, - &mut canvas, - ); + // TODO: Perform conversion in the GPU + let bgra: Vec = std::iter::from_fn(move || { + use std::iter::once; + + let r = rgba.next()?; + let g = rgba.next()?; + let b = rgba.next()?; + let a = rgba.next()?; + + Some(once(b).chain(once(g)).chain(once(r)).chain(once(a))) + }) + .flatten() + .collect(); let allocation = texture_atlas.upload( width, height, - bytemuck::cast_slice(canvas.get_data()), + bytemuck::cast_slice(bgra.as_slice()), device, encoder, )?; -- cgit From a7bb7bb2eaaae5a016721788fcaf03c4c7413acd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Jan 2021 15:28:38 +0100 Subject: Implement split highlight on hover for `PaneGrid` --- wgpu/src/widget/pane_grid.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/widget/pane_grid.rs b/wgpu/src/widget/pane_grid.rs index c26dde48..44f9201c 100644 --- a/wgpu/src/widget/pane_grid.rs +++ b/wgpu/src/widget/pane_grid.rs @@ -9,9 +9,9 @@ //! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid use crate::Renderer; -pub use iced_native::pane_grid::{ - Axis, Configuration, Direction, DragEvent, Node, Pane, ResizeEvent, Split, - State, +pub use iced_graphics::pane_grid::{ + Axis, Configuration, Direction, DragEvent, Line, Node, Pane, ResizeEvent, + Split, State, StyleSheet, }; /// A collection of panes distributed using either vertical or horizontal splits -- cgit From 2d76c7165c4a82f27090cbf69f811f8e0f2f28a4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:21:02 +0100 Subject: [wgpu 0.7] Update quad.rs --- wgpu/src/quad.rs | 116 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 54 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 24d20cfa..c1399d53 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -24,8 +24,9 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: false, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -46,9 +47,11 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - constants_buffer.slice(..), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &constants_buffer, + offset: 0, + size: None, + }, }], }); @@ -59,87 +62,61 @@ impl Pipeline { bind_group_layouts: &[&constant_layout], }); - let vs_module = device - .create_shader_module(wgpu::include_spirv!("shader/quad.vert.spv")); + let vs_module = device.create_shader_module(&wgpu::include_spirv!( + "shader/quad.vert.spv" + )); - let fs_module = device - .create_shader_module(wgpu::include_spirv!("shader/quad.frag.spv")); + let fs_module = device.create_shader_module(&wgpu::include_spirv!( + "shader/quad.frag.spv" + )); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::quad pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[ - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[ + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[wgpu::VertexAttributeDescriptor { + attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }], }, - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, attributes: &[ - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float2, offset: 0, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 2, format: wgpu::VertexFormat::Float2, offset: 4 * 2, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 3, format: wgpu::VertexFormat::Float4, offset: 4 * (2 + 2), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 4, format: wgpu::VertexFormat::Float4, offset: 4 * (2 + 2 + 4), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 5, format: wgpu::VertexFormat::Float, offset: 4 * (2 + 2 + 4 + 4), }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 6, format: wgpu::VertexFormat::Float, offset: 4 * (2 + 2 + 4 + 4 + 1), @@ -148,9 +125,36 @@ impl Pipeline { }, ], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + 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 = @@ -232,6 +236,7 @@ impl Pipeline { { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::quad render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -247,7 +252,10 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, &self.constants, &[]); - render_pass.set_index_buffer(self.indices.slice(..)); + render_pass.set_index_buffer( + self.indices.slice(..), + wgpu::IndexFormat::Uint16, + ); render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..)); render_pass.set_scissor_rect( -- cgit From 98d108d2b73b994a63140361110dec6401a80ae4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 19:32:30 +0100 Subject: [wgpu 0.7] Update window/compositor.rs Notes: - wgpu::PowerPreference::Default no longer exists, maybe there is another way to replicate its behavior. --- wgpu/src/window/compositor.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 492efb42..492cb955 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -27,7 +27,7 @@ impl Compositor { let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { - wgpu::PowerPreference::Default + wgpu::PowerPreference::default() } else { wgpu::PowerPreference::HighPerformance }, @@ -38,12 +38,14 @@ impl Compositor { let (device, queue) = adapter .request_device( &wgpu::DeviceDescriptor { + label: Some( + "iced_wgpu::window::Compositor Device Descriptor", + ), features: wgpu::Features::empty(), limits: wgpu::Limits { max_bind_groups: 2, ..wgpu::Limits::default() }, - shader_validation: false, }, None, ) @@ -103,7 +105,7 @@ impl iced_graphics::window::Compositor for Compositor { self.device.create_swap_chain( surface, &wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, format: self.settings.format, present_mode: self.settings.present_mode, width, @@ -130,6 +132,7 @@ impl iced_graphics::window::Compositor for Compositor { ); let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::window::Compositor Render Pass"), color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.output.view, resolve_target: None, -- cgit From 5f935c34fdd23a99e39ea80fef3845d476fc78f4 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:05:37 +0100 Subject: [wgpu 0.7] Update triangle/msaa.rs Notes: - not sure if `filtering sampler` should be used, so for now it is not used . --- wgpu/src/triangle/msaa.rs | 74 +++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 34 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index db86f748..13c2a3c4 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -32,7 +32,10 @@ impl Blit { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler { comparison: false }, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: true, + }, count: None, }], }); @@ -53,9 +56,11 @@ impl Blit { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::SampledTexture { - dimension: wgpu::TextureViewDimension::D2, - component_type: wgpu::TextureComponentType::Float, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: true, + }, + view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, count: None, @@ -69,11 +74,11 @@ impl Blit { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "../shader/blit.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "../shader/blit.frag.spv" )); @@ -81,42 +86,42 @@ impl Blit { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle::msaa pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", + buffers: &[], }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { + fragment: Some(wgpu::FragmentState { module: &fs_module, entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, front_face: wgpu::FrontFace::Cw, 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: &[], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + depth_stencil: None, + + multisample: wgpu::MultisampleState { + count: 1, + mask: !0, + alpha_to_coverage_enabled: false, + }, }); Blit { @@ -172,6 +177,7 @@ impl Blit { ) { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::triangle::msaa Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -227,7 +233,7 @@ impl Targets { sample_count, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, }); let resolve = device.create_texture(&wgpu::TextureDescriptor { @@ -237,7 +243,7 @@ impl Targets { sample_count: 1, dimension: wgpu::TextureDimension::D2, format, - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT + usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, }); -- cgit From e2595ac0aa53448feb421c1591178b748814055a Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:06:07 +0100 Subject: [wgpu 0.7] Update triangle.rs --- wgpu/src/triangle.rs | 112 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 52 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 61a771d8..d23ce29e 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -86,8 +86,9 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: true, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -109,11 +110,13 @@ impl Pipeline { layout: &constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - constants_buffer - .raw - .slice(0..std::mem::size_of::() as u64), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &constants_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new( + std::mem::size_of::() as u64, + ), + }, }], }); @@ -124,11 +127,11 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.frag.spv" )); @@ -136,49 +139,21 @@ impl Pipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint32, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[ // Position - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }, // Color - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float4, offset: 4 * 2, @@ -186,11 +161,38 @@ impl Pipeline { ], }], }, - sample_count: u32::from( - antialiasing.map(|a| a.sample_count()).unwrap_or(1), - ), - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + 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: u32::from( + antialiasing.map(|a| a.sample_count()).unwrap_or(1), + ), + mask: !0, + alpha_to_coverage_enabled: false, + }, }); Pipeline { @@ -252,11 +254,15 @@ impl Pipeline { layout: &self.constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - self.uniforms_buffer.raw.slice( - 0..std::mem::size_of::() as u64, - ), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &self.uniforms_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new(std::mem::size_of::< + Uniforms, + >( + ) + as u64), + }, }], }); } @@ -356,6 +362,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::triangle Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment, @@ -390,6 +397,7 @@ impl Pipeline { self.index_buffer .raw .slice(index_offset * mem::size_of::() as u64..), + wgpu::IndexFormat::Uint32, ); render_pass.set_vertex_buffer( -- cgit From 4a6db30d47683110663bc610c9ef9c7a9c9ac184 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:24:48 +0100 Subject: [wgpu 0.7] Update image.rs --- wgpu/src/image.rs | 121 +++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 55 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index c256ca7e..b44d621b 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -62,8 +62,9 @@ impl Pipeline { wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: false, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -73,7 +74,10 @@ impl Pipeline { wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler { comparison: false }, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: false, + }, count: None, }, ], @@ -93,9 +97,11 @@ impl Pipeline { entries: &[ wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - uniforms_buffer.slice(..), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &uniforms_buffer, + offset: 0, + size: None, + }, }, wgpu::BindGroupEntry { binding: 1, @@ -110,9 +116,11 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::SampledTexture { - dimension: wgpu::TextureViewDimension::D2, - component_type: wgpu::TextureComponentType::Float, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { + filterable: false, + }, + view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, count: None, @@ -126,11 +134,11 @@ impl Pipeline { 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" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/image.frag.spv" )); @@ -138,72 +146,44 @@ impl Pipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::image pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[ - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[ + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[wgpu::VertexAttributeDescriptor { + attributes: &[wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }], }, - wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, attributes: &[ - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float2, offset: 0, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 2, format: wgpu::VertexFormat::Float2, offset: 4 * 2, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 3, format: wgpu::VertexFormat::Float2, offset: 4 * 4, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 4, format: wgpu::VertexFormat::Float2, offset: 4 * 6, }, - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 5, format: wgpu::VertexFormat::Uint, offset: 4 * 8, @@ -212,9 +192,36 @@ impl Pipeline { }, ], }, - sample_count: 1, - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + 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 = @@ -415,6 +422,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::image Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, @@ -431,7 +439,10 @@ impl Pipeline { render_pass.set_pipeline(&self.pipeline); render_pass.set_bind_group(0, &self.constants, &[]); 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(1, self.instances.slice(..)); -- cgit From c5d6ddc1264a294cab8e41e05828ece3e7df5945 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 21:13:51 +0100 Subject: [wgpu 0.7] triangle/msaa disable filtering --- wgpu/src/triangle/msaa.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 13c2a3c4..0a5a703e 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -34,7 +34,7 @@ impl Blit { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, - filtering: true, + filtering: false, }, count: None, }], @@ -58,7 +58,7 @@ impl Blit { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { - filterable: true, + filterable: false, }, view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, -- cgit From bd6b8304bd940c5519fdf705698974994d5d1ca1 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 21:51:11 +0100 Subject: Fix ScissorRect - Breaks `TODO: Address anti-aliasing adjustments properly` --- wgpu/src/quad.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index c1399d53..f8531992 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -258,12 +258,13 @@ impl Pipeline { ); render_pass.set_vertex_buffer(0, self.vertices.slice(..)); render_pass.set_vertex_buffer(1, self.instances.slice(..)); + render_pass.set_scissor_rect( bounds.x, bounds.y, bounds.width, // TODO: Address anti-aliasing adjustments properly - bounds.height + 1, + bounds.height, ); render_pass.draw_indexed( -- cgit From 1fb60c5dcbea77bf36934f243bb0832c3e5a116e Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 22:26:53 +0100 Subject: Fix TextureViewDimension for image wgpu validation helped to find this long standing type error --- wgpu/src/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index b44d621b..32843828 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -120,7 +120,7 @@ impl Pipeline { sample_type: wgpu::TextureSampleType::Float { filterable: false, }, - view_dimension: wgpu::TextureViewDimension::D2, + view_dimension: wgpu::TextureViewDimension::D2Array, multisampled: false, }, count: None, -- cgit From b0d1be69d679444e7d0957e1b619720705e03107 Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 23:50:03 +0100 Subject: Change `PowerPreference` from `default()` to `LowPower` There is no reason to hide the fact that this is always in `LowPower` mode --- wgpu/src/window/compositor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 492cb955..361b9ecf 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -27,7 +27,7 @@ impl Compositor { let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { - wgpu::PowerPreference::default() + wgpu::PowerPreference::LowPower } else { wgpu::PowerPreference::HighPerformance }, -- cgit From ffdf87fbe2cf132b63d0a5af46c8ec1aead9af12 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 15:37:05 +0100 Subject: Use lowercase in `wgpu` labels for consistency --- wgpu/src/image.rs | 2 +- wgpu/src/triangle.rs | 2 +- wgpu/src/triangle/msaa.rs | 2 +- wgpu/src/window/compositor.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 32843828..e34cbb0a 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -422,7 +422,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::image Render Pass"), + label: Some("iced_wgpu::image render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment: target, diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index d23ce29e..2f255940 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -362,7 +362,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::triangle Render Pass"), + label: Some("iced_wgpu::triangle render pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment, diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 0a5a703e..4c8fe20c 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -177,7 +177,7 @@ impl Blit { ) { let mut render_pass = 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::RenderPassColorAttachmentDescriptor { attachment: target, diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 361b9ecf..36d6ab1a 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -39,7 +39,7 @@ impl Compositor { .request_device( &wgpu::DeviceDescriptor { label: Some( - "iced_wgpu::window::Compositor Device Descriptor", + "iced_wgpu::window::compositor device descriptor", ), features: wgpu::Features::empty(), limits: wgpu::Limits { @@ -132,7 +132,7 @@ impl iced_graphics::window::Compositor for Compositor { ); let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("iced_wgpu::window::Compositor Render Pass"), + label: Some("iced_wgpu::window::Compositor render pass"), color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.output.view, resolve_target: None, -- cgit From 15c4901aba7fbcc5373b68e0d1a52ad446b64b48 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 15:38:02 +0100 Subject: Remove unnecessary line break in `triangle::msaa` --- wgpu/src/triangle/msaa.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index 4c8fe20c..d964f815 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -116,7 +116,6 @@ impl Blit { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState { count: 1, mask: !0, -- cgit From 7eefad34fc93838a5a3fe976ed0ee47818004b83 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 15:55:03 +0100 Subject: List `color_blend` first in `wgpu::quad` --- wgpu/src/quad.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index f8531992..e0a6e043 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -130,13 +130,13 @@ impl Pipeline { entry_point: "main", targets: &[wgpu::ColorTargetState { format, - alpha_blend: wgpu::BlendState { - src_factor: wgpu::BlendFactor::One, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, operation: wgpu::BlendOperation::Add, }, - color_blend: wgpu::BlendState { - src_factor: wgpu::BlendFactor::SrcAlpha, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, operation: wgpu::BlendOperation::Add, }, -- cgit From 74b9ea520f0f861bda82bbf79a6d4327e42a62fc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 6 Feb 2021 16:04:43 +0100 Subject: Enable filtering in `wgpu::image` --- wgpu/src/image.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index e34cbb0a..70bfe586 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -76,7 +76,7 @@ impl Pipeline { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Sampler { comparison: false, - filtering: false, + filtering: true, }, count: None, }, @@ -118,7 +118,7 @@ impl Pipeline { visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::Texture { sample_type: wgpu::TextureSampleType::Float { - filterable: false, + filterable: true, }, view_dimension: wgpu::TextureViewDimension::D2Array, multisampled: false, -- cgit From 9e453843b26f2f73228316334298a4c608b2f050 Mon Sep 17 00:00:00 2001 From: anunge Date: Fri, 12 Feb 2021 21:52:20 +0200 Subject: Touch support for `PaneGrid` and `PickList` (#650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * touch events properly parsed and converted to logical size, button working * scrolling with a nice touch * fixed application state level touch cursor. panel_grid is touchable now. * format glicthes fixes * format glitches * tight format * fixed pane grid * fixing with upstream * Remove unused `touch` module from `iced_core` * Remove unused `crate::text` import in `iced_native` * Remove redundant match branch in `iced_winit` * Keep removed line break in `UserInterface::update` * Compute `text_size` only when bounds contains cursor in `overlay::menu` Co-authored-by: Héctor Ramón Jiménez --- wgpu/src/text.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'wgpu/src') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 78999cf8..4d92d9e9 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -19,6 +19,7 @@ impl Pipeline { let default_font = default_font.map(|slice| slice.to_vec()); // TODO: Font customization + #[cfg(not(target_os = "ios"))] #[cfg(feature = "default_system_font")] let default_font = { default_font.or_else(|| { -- cgit From 8f126c212b887b2621cd8220bc4a52ba4febb1eb Mon Sep 17 00:00:00 2001 From: Greg V Date: Fri, 5 Jun 2020 21:18:22 +0300 Subject: Add image format options to reduce code bloat, fixes #376 --- wgpu/src/backend.rs | 14 +++++++------- wgpu/src/image.rs | 18 +++++++++--------- wgpu/src/image/atlas/entry.rs | 2 +- wgpu/src/image/raster.rs | 8 ++++---- wgpu/src/lib.rs | 2 +- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index fccb5ac7..534c6cb7 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -9,7 +9,7 @@ use iced_graphics::{Primitive, Viewport}; use iced_native::mouse; use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment}; -#[cfg(any(feature = "image", feature = "svg"))] +#[cfg(any(feature = "image_rs", feature = "svg"))] use crate::image; /// A [`wgpu`] graphics backend for [`iced`]. @@ -22,7 +22,7 @@ pub struct Backend { text_pipeline: text::Pipeline, triangle_pipeline: triangle::Pipeline, - #[cfg(any(feature = "image", feature = "svg"))] + #[cfg(any(feature = "image_rs", feature = "svg"))] image_pipeline: image::Pipeline, default_text_size: u16, @@ -40,7 +40,7 @@ impl Backend { settings.antialiasing, ); - #[cfg(any(feature = "image", feature = "svg"))] + #[cfg(any(feature = "image_rs", feature = "svg"))] let image_pipeline = image::Pipeline::new(device, settings.format); Self { @@ -48,7 +48,7 @@ impl Backend { text_pipeline, triangle_pipeline, - #[cfg(any(feature = "image", feature = "svg"))] + #[cfg(any(feature = "image_rs", feature = "svg"))] image_pipeline, default_text_size: settings.default_text_size, @@ -92,7 +92,7 @@ impl Backend { ); } - #[cfg(any(feature = "image", feature = "svg"))] + #[cfg(any(feature = "image_rs", feature = "svg"))] self.image_pipeline.trim_cache(); *mouse_interaction @@ -142,7 +142,7 @@ impl Backend { ); } - #[cfg(any(feature = "image", feature = "svg"))] + #[cfg(any(feature = "image_rs", feature = "svg"))] { if !layer.images.is_empty() { let scaled = transformation @@ -270,7 +270,7 @@ impl backend::Text for Backend { } } -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] impl backend::Image for Backend { fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) { self.image_pipeline.dimensions(handle) diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 70bfe586..5511565e 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -1,6 +1,6 @@ mod atlas; -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] mod raster; #[cfg(feature = "svg")] @@ -16,7 +16,7 @@ use std::mem; use bytemuck::{Pod, Zeroable}; -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] use iced_native::image; #[cfg(feature = "svg")] @@ -24,7 +24,7 @@ use iced_native::svg; #[derive(Debug)] pub struct Pipeline { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] raster_cache: RefCell, #[cfg(feature = "svg")] vector_cache: RefCell, @@ -259,7 +259,7 @@ impl Pipeline { }); Pipeline { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] raster_cache: RefCell::new(raster::Cache::new()), #[cfg(feature = "svg")] @@ -278,7 +278,7 @@ impl Pipeline { } } - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) { let mut cache = self.raster_cache.borrow_mut(); let memory = cache.load(&handle); @@ -307,7 +307,7 @@ impl Pipeline { ) { let instances: &mut Vec = &mut Vec::new(); - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] let mut raster_cache = self.raster_cache.borrow_mut(); #[cfg(feature = "svg")] @@ -315,7 +315,7 @@ impl Pipeline { for image in images { match &image { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] layer::Image::Raster { handle, bounds } => { if let Some(atlas_entry) = raster_cache.upload( handle, @@ -331,7 +331,7 @@ impl Pipeline { ); } } - #[cfg(not(feature = "image"))] + #[cfg(not(feature = "image_rs"))] layer::Image::Raster { .. } => {} #[cfg(feature = "svg")] @@ -464,7 +464,7 @@ impl Pipeline { } pub fn trim_cache(&mut self) { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] self.raster_cache.borrow_mut().trim(&mut self.texture_atlas); #[cfg(feature = "svg")] diff --git a/wgpu/src/image/atlas/entry.rs b/wgpu/src/image/atlas/entry.rs index 0310fc54..9b3f16df 100644 --- a/wgpu/src/image/atlas/entry.rs +++ b/wgpu/src/image/atlas/entry.rs @@ -10,7 +10,7 @@ pub enum Entry { } impl Entry { - #[cfg(feature = "image")] + #[cfg(feature = "image_rs")] pub fn size(&self) -> (u32, u32) { match self { Entry::Contiguous(allocation) => allocation.size(), diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index 25607dab..d5c62545 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -4,7 +4,7 @@ use std::collections::{HashMap, HashSet}; #[derive(Debug)] pub enum Memory { - Host(::image::ImageBuffer<::image::Bgra, Vec>), + Host(::image_rs::ImageBuffer<::image_rs::Bgra, Vec>), Device(atlas::Entry), NotFound, Invalid, @@ -42,14 +42,14 @@ impl Cache { let memory = match handle.data() { image::Data::Path(path) => { - if let Ok(image) = ::image::open(path) { + if let Ok(image) = ::image_rs::open(path) { Memory::Host(image.to_bgra8()) } else { Memory::NotFound } } image::Data::Bytes(bytes) => { - if let Ok(image) = ::image::load_from_memory(&bytes) { + if let Ok(image) = ::image_rs::load_from_memory(&bytes) { Memory::Host(image.to_bgra8()) } else { Memory::Invalid @@ -60,7 +60,7 @@ impl Cache { height, pixels, } => { - if let Some(image) = ::image::ImageBuffer::from_vec( + if let Some(image) = ::image_rs::ImageBuffer::from_vec( *width, *height, pixels.to_vec(), diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index a4c2ac0e..e868a655 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -49,7 +49,7 @@ pub use widget::*; pub(crate) use iced_graphics::Transformation; -#[cfg(any(feature = "image", feature = "svg"))] +#[cfg(any(feature = "image_rs", feature = "svg"))] mod image; /// A [`wgpu`] graphics renderer for [`iced`]. -- cgit From a19f89d3a6af2804f2ac4e30f6d639b56a9bebfd Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 28 Jul 2020 18:07:46 +0300 Subject: feat(native): add Tooltip widget --- wgpu/src/widget.rs | 3 +++ wgpu/src/widget/tooltip.rs | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 wgpu/src/widget/tooltip.rs (limited to 'wgpu/src') diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs index 177ae1b6..304bb726 100644 --- a/wgpu/src/widget.rs +++ b/wgpu/src/widget.rs @@ -20,6 +20,7 @@ pub mod rule; pub mod scrollable; pub mod slider; pub mod text_input; +pub mod tooltip; #[doc(no_inline)] pub use button::Button; @@ -43,6 +44,8 @@ pub use scrollable::Scrollable; pub use slider::Slider; #[doc(no_inline)] pub use text_input::TextInput; +#[doc(no_inline)] +pub use tooltip::Tooltip; #[cfg(feature = "canvas")] #[cfg_attr(docsrs, doc(cfg(feature = "canvas")))] diff --git a/wgpu/src/widget/tooltip.rs b/wgpu/src/widget/tooltip.rs new file mode 100644 index 00000000..b7d4f11e --- /dev/null +++ b/wgpu/src/widget/tooltip.rs @@ -0,0 +1,6 @@ +//! Display a widget over another. +/// A widget allowing the selection of a single value from a list of options. +pub type Tooltip<'a, Message> = + iced_native::Tooltip<'a, Message, crate::Renderer>; + +pub use iced_native::tooltip::TooltipPosition; -- cgit From 81c75c15249b608dd8a6d47e25f96feb10ca68da Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Feb 2021 03:09:16 +0100 Subject: Change `Tooltip` to support `Text` only for now --- wgpu/src/widget/tooltip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/widget/tooltip.rs b/wgpu/src/widget/tooltip.rs index b7d4f11e..89ab3a15 100644 --- a/wgpu/src/widget/tooltip.rs +++ b/wgpu/src/widget/tooltip.rs @@ -3,4 +3,4 @@ pub type Tooltip<'a, Message> = iced_native::Tooltip<'a, Message, crate::Renderer>; -pub use iced_native::tooltip::TooltipPosition; +pub use iced_native::tooltip::Position; -- cgit From ab8dcf91bdcad6c8d0a39802f2823e65aafa8f0a Mon Sep 17 00:00:00 2001 From: Downtime Date: Sun, 21 Mar 2021 11:42:25 +0800 Subject: Support choosing `wgpu` backend using env var --- wgpu/src/window/compositor.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 36d6ab1a..3d785f71 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -15,6 +15,35 @@ pub struct Compositor { local_pool: futures::executor::LocalPool, } +#[derive(Clone)] +pub enum WgpuBackend { + Auto, + Vulkan, + Metal, + Dx12, + Dx11, + Gl, + BrowserWgpu, +} + +impl WgpuBackend { + fn from_env() -> Self { + if let Ok(backend) = std::env::var("WGPU_BACKEND") { + match backend.to_lowercase().as_str() { + "vulkan" => WgpuBackend::Vulkan, + "metal" => WgpuBackend::Metal, + "dx12" => WgpuBackend::Dx12, + "dx11" => WgpuBackend::Dx11, + "gl" => WgpuBackend::Gl, + "webgpu" => WgpuBackend::BrowserWgpu, + other => panic!("Unknown backend: {}", other), + } + } else { + WgpuBackend::Auto + } + } +} + impl Compositor { const CHUNK_SIZE: u64 = 10 * 1024; @@ -22,7 +51,17 @@ impl Compositor { /// /// Returns `None` if no compatible graphics adapter could be found. pub async fn request(settings: Settings) -> Option { - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let backend = match WgpuBackend::from_env() { + WgpuBackend::Auto => wgpu::BackendBit::PRIMARY, + WgpuBackend::Vulkan => wgpu::BackendBit::VULKAN, + WgpuBackend::Metal => wgpu::BackendBit::METAL, + WgpuBackend::Dx12 => wgpu::BackendBit::DX12, + WgpuBackend::Dx11 => wgpu::BackendBit::DX11, + WgpuBackend::Gl => wgpu::BackendBit::GL, + WgpuBackend::BrowserWgpu => wgpu::BackendBit::BROWSER_WEBGPU, + }; + + let instance = wgpu::Instance::new(backend); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { -- cgit From 883c7e71ae699a29c23b8f95b7335d015e5a985d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 25 Mar 2021 11:27:31 +0100 Subject: Introduce `internal_backend` to `iced_wgpu::Settings` --- wgpu/src/settings.rs | 41 +++++++++++++++++++++++++++++++++++++++++ wgpu/src/window/compositor.rs | 41 +---------------------------------------- 2 files changed, 42 insertions(+), 40 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 26763e22..abc404dc 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -16,6 +16,9 @@ pub struct Settings { /// [`Backend`]: crate::Backend pub present_mode: wgpu::PresentMode, + /// The internal graphics backend to use. + pub internal_backend: wgpu::BackendBit, + /// The bytes of the font that will be used by default. /// /// If `None` is provided, a default system font will be chosen. @@ -30,14 +33,52 @@ pub struct Settings { pub antialiasing: Option, } +impl Settings { + /// Creates new [`Settings`] using environment configuration. + /// + /// Specifically: + /// + /// - The `internal_backend` can be configured using the `WGPU_BACKEND` + /// environment variable. If the variable is not set, the primary backend + /// will be used. The following values are allowed: + /// - `vulkan` + /// - `metal` + /// - `dx12` + /// - `dx11` + /// - `gl` + /// - `webgpu` + pub fn from_env() -> Self { + Settings { + internal_backend: backend_from_env() + .unwrap_or(wgpu::BackendBit::PRIMARY), + ..Self::default() + } + } +} + impl Default for Settings { fn default() -> Settings { Settings { format: wgpu::TextureFormat::Bgra8UnormSrgb, present_mode: wgpu::PresentMode::Mailbox, + internal_backend: wgpu::BackendBit::PRIMARY, default_font: None, default_text_size: 20, antialiasing: None, } } } + +fn backend_from_env() -> Option { + std::env::var("WGPU_BACKEND").ok().map(|backend| { + match backend.to_lowercase().as_str() { + "vulkan" => wgpu::BackendBit::VULKAN, + "metal" => wgpu::BackendBit::METAL, + "dx12" => wgpu::BackendBit::DX12, + "dx11" => wgpu::BackendBit::DX11, + "gl" => wgpu::BackendBit::GL, + "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + other => panic!("Unknown backend: {}", other), + } + }) +} diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 3d785f71..fdd648e8 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -15,35 +15,6 @@ pub struct Compositor { local_pool: futures::executor::LocalPool, } -#[derive(Clone)] -pub enum WgpuBackend { - Auto, - Vulkan, - Metal, - Dx12, - Dx11, - Gl, - BrowserWgpu, -} - -impl WgpuBackend { - fn from_env() -> Self { - if let Ok(backend) = std::env::var("WGPU_BACKEND") { - match backend.to_lowercase().as_str() { - "vulkan" => WgpuBackend::Vulkan, - "metal" => WgpuBackend::Metal, - "dx12" => WgpuBackend::Dx12, - "dx11" => WgpuBackend::Dx11, - "gl" => WgpuBackend::Gl, - "webgpu" => WgpuBackend::BrowserWgpu, - other => panic!("Unknown backend: {}", other), - } - } else { - WgpuBackend::Auto - } - } -} - impl Compositor { const CHUNK_SIZE: u64 = 10 * 1024; @@ -51,17 +22,7 @@ impl Compositor { /// /// Returns `None` if no compatible graphics adapter could be found. pub async fn request(settings: Settings) -> Option { - let backend = match WgpuBackend::from_env() { - WgpuBackend::Auto => wgpu::BackendBit::PRIMARY, - WgpuBackend::Vulkan => wgpu::BackendBit::VULKAN, - WgpuBackend::Metal => wgpu::BackendBit::METAL, - WgpuBackend::Dx12 => wgpu::BackendBit::DX12, - WgpuBackend::Dx11 => wgpu::BackendBit::DX11, - WgpuBackend::Gl => wgpu::BackendBit::GL, - WgpuBackend::BrowserWgpu => wgpu::BackendBit::BROWSER_WEBGPU, - }; - - let instance = wgpu::Instance::new(backend); + let instance = wgpu::Instance::new(settings.internal_backend); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { -- cgit From 9a2c78c4059d2be37d10adda397fb6e64f38ac02 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Sun, 11 Apr 2021 18:55:57 -0700 Subject: Upgrade wgpu --- wgpu/src/image.rs | 59 +++++++++--------- wgpu/src/image/atlas.rs | 24 ++++---- wgpu/src/quad.rs | 76 +++++++++++------------ wgpu/src/shader/blit.frag | 12 ---- wgpu/src/shader/blit.frag.spv | Bin 684 -> 0 bytes wgpu/src/shader/blit.vert | 26 -------- wgpu/src/shader/blit.vert.spv | Bin 1384 -> 0 bytes wgpu/src/shader/blit.wgsl | 43 +++++++++++++ wgpu/src/shader/image.frag | 12 ---- wgpu/src/shader/image.frag.spv | Bin 684 -> 0 bytes wgpu/src/shader/image.vert | 27 --------- wgpu/src/shader/image.vert.spv | Bin 2504 -> 0 bytes wgpu/src/shader/image.wgsl | 45 ++++++++++++++ wgpu/src/shader/quad.frag | 66 -------------------- wgpu/src/shader/quad.frag.spv | Bin 4212 -> 0 bytes wgpu/src/shader/quad.vert | 47 --------------- wgpu/src/shader/quad.vert.spv | Bin 3604 -> 0 bytes wgpu/src/shader/quad.wgsl | 123 ++++++++++++++++++++++++++++++++++++++ wgpu/src/shader/triangle.frag | 8 --- wgpu/src/shader/triangle.frag.spv | Bin 372 -> 0 bytes wgpu/src/shader/triangle.vert | 15 ----- wgpu/src/shader/triangle.vert.spv | Bin 1256 -> 0 bytes wgpu/src/shader/triangle.wgsl | 31 ++++++++++ wgpu/src/triangle.rs | 57 +++++++++--------- wgpu/src/triangle/msaa.rs | 49 ++++++++------- wgpu/src/window/compositor.rs | 4 +- 26 files changed, 378 insertions(+), 346 deletions(-) delete mode 100644 wgpu/src/shader/blit.frag delete mode 100644 wgpu/src/shader/blit.frag.spv delete mode 100644 wgpu/src/shader/blit.vert delete mode 100644 wgpu/src/shader/blit.vert.spv create mode 100644 wgpu/src/shader/blit.wgsl delete mode 100644 wgpu/src/shader/image.frag delete mode 100644 wgpu/src/shader/image.frag.spv delete mode 100644 wgpu/src/shader/image.vert delete mode 100644 wgpu/src/shader/image.vert.spv create mode 100644 wgpu/src/shader/image.wgsl delete mode 100644 wgpu/src/shader/quad.frag delete mode 100644 wgpu/src/shader/quad.frag.spv delete mode 100644 wgpu/src/shader/quad.vert delete mode 100644 wgpu/src/shader/quad.vert.spv create mode 100644 wgpu/src/shader/quad.wgsl delete mode 100644 wgpu/src/shader/triangle.frag delete mode 100644 wgpu/src/shader/triangle.frag.spv delete mode 100644 wgpu/src/shader/triangle.vert delete mode 100644 wgpu/src/shader/triangle.vert.spv create mode 100644 wgpu/src/shader/triangle.wgsl (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 5511565e..713af209 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -134,28 +134,26 @@ impl Pipeline { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/image.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/image.frag.spv" - )); + let shader = 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"))), + flags: wgpu::ShaderFlags::all() + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::image pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[ wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[wgpu::VertexAttribute { shader_location: 0, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }], }, @@ -165,27 +163,27 @@ impl Pipeline { attributes: &[ wgpu::VertexAttribute { shader_location: 1, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }, wgpu::VertexAttribute { shader_location: 2, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 2, }, wgpu::VertexAttribute { shader_location: 3, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 4, }, wgpu::VertexAttribute { shader_location: 4, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 6, }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Uint, + format: wgpu::VertexFormat::Uint32, offset: 4 * 8, }, ], @@ -193,27 +191,28 @@ impl Pipeline { ], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -424,8 +423,8 @@ impl Pipeline { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::image render pass"), color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment: target, + wgpu::RenderPassColorAttachment { + view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 660ebe44..4855fa4a 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -4,6 +4,8 @@ mod allocation; mod allocator; mod layer; +use std::num::NonZeroU32; + pub use allocation::Allocation; pub use entry::Entry; pub use layer::Layer; @@ -24,7 +26,7 @@ impl Atlas { let extent = wgpu::Extent3d { width: SIZE, height: SIZE, - depth: 1, + depth_or_array_layers: 1, }; let texture = device.create_texture(&wgpu::TextureDescriptor { @@ -294,19 +296,19 @@ impl Atlas { let extent = wgpu::Extent3d { width, height, - depth: 1, + depth_or_array_layers: 1, }; encoder.copy_buffer_to_texture( - wgpu::BufferCopyView { + wgpu::ImageCopyBuffer { buffer, - layout: wgpu::TextureDataLayout { + layout: wgpu::ImageDataLayout { offset: offset as u64, - bytes_per_row: 4 * image_width + padding, - rows_per_image: image_height, + bytes_per_row: NonZeroU32::new(4 * image_width + padding), + rows_per_image: NonZeroU32::new(image_height), }, }, - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d { @@ -334,7 +336,7 @@ impl Atlas { size: wgpu::Extent3d { width: SIZE, height: SIZE, - depth: self.layers.len() as u32, + depth_or_array_layers: self.layers.len() as u32, }, mip_level_count: 1, sample_count: 1, @@ -355,7 +357,7 @@ impl Atlas { } encoder.copy_texture_to_texture( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &self.texture, mip_level: 0, origin: wgpu::Origin3d { @@ -364,7 +366,7 @@ impl Atlas { z: i as u32, }, }, - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &new_texture, mip_level: 0, origin: wgpu::Origin3d { @@ -376,7 +378,7 @@ impl Atlas { wgpu::Extent3d { width: SIZE, height: SIZE, - depth: 1, + depth_or_array_layers: 1, }, ); } diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index e0a6e043..458679e4 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -62,28 +62,29 @@ impl Pipeline { bind_group_layouts: &[&constant_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/quad.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/quad.frag.spv" - )); + let shader = + 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"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::quad pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[ wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[wgpu::VertexAttribute { shader_location: 0, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }], }, @@ -93,32 +94,32 @@ impl Pipeline { attributes: &[ wgpu::VertexAttribute { shader_location: 1, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }, wgpu::VertexAttribute { shader_location: 2, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 4 * 2, }, wgpu::VertexAttribute { shader_location: 3, - format: wgpu::VertexFormat::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * (2 + 2), }, wgpu::VertexAttribute { shader_location: 4, - format: wgpu::VertexFormat::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * (2 + 2 + 4), }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Float, + format: wgpu::VertexFormat::Float32, offset: 4 * (2 + 2 + 4 + 4), }, wgpu::VertexAttribute { shader_location: 6, - format: wgpu::VertexFormat::Float, + format: wgpu::VertexFormat::Float32, offset: 4 * (2 + 2 + 4 + 4 + 1), }, ], @@ -126,27 +127,28 @@ impl Pipeline { ], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -237,16 +239,14 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::quad render pass"), - color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, - }, + color_attachments: &[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/shader/blit.frag b/wgpu/src/shader/blit.frag deleted file mode 100644 index dfed960f..00000000 --- a/wgpu/src/shader/blit.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 v_Uv; - -layout(set = 0, binding = 0) uniform sampler u_Sampler; -layout(set = 1, binding = 0) uniform texture2D u_Texture; - -layout(location = 0) out vec4 o_Color; - -void main() { - o_Color = texture(sampler2D(u_Texture, u_Sampler), v_Uv); -} diff --git a/wgpu/src/shader/blit.frag.spv b/wgpu/src/shader/blit.frag.spv deleted file mode 100644 index 2c5638b5..00000000 Binary files a/wgpu/src/shader/blit.frag.spv and /dev/null differ diff --git a/wgpu/src/shader/blit.vert b/wgpu/src/shader/blit.vert deleted file mode 100644 index 899cd39d..00000000 --- a/wgpu/src/shader/blit.vert +++ /dev/null @@ -1,26 +0,0 @@ -#version 450 - -layout(location = 0) out vec2 o_Uv; - -const vec2 positions[6] = vec2[6]( - vec2(-1.0, 1.0), - vec2(-1.0, -1.0), - vec2(1.0, -1.0), - vec2(-1.0, 1.0), - vec2(1.0, 1.0), - vec2(1.0, -1.0) -); - -const vec2 uvs[6] = vec2[6]( - vec2(0.0, 0.0), - vec2(0.0, 1.0), - vec2(1.0, 1.0), - vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) -); - -void main() { - o_Uv = uvs[gl_VertexIndex]; - gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); -} diff --git a/wgpu/src/shader/blit.vert.spv b/wgpu/src/shader/blit.vert.spv deleted file mode 100644 index e0b436ce..00000000 Binary files a/wgpu/src/shader/blit.vert.spv and /dev/null differ diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl new file mode 100644 index 00000000..7a987c2c --- /dev/null +++ b/wgpu/src/shader/blit.wgsl @@ -0,0 +1,43 @@ +var positions: array, 6> = array, 6>( + vec2(-1.0, 1.0), + vec2(-1.0, -1.0), + vec2(1.0, -1.0), + vec2(-1.0, 1.0), + vec2(1.0, 1.0), + vec2(1.0, -1.0) +); + +var uvs: array, 6> = array, 6>( + vec2(0.0, 0.0), + vec2(0.0, 1.0), + vec2(1.0, 1.0), + vec2(0.0, 0.0), + vec2(1.0, 0.0), + vec2(1.0, 1.0) +); + +[[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; +}; + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] uv: vec2; +}; + +[[stage(vertex)]] +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + out.uv = uvs[input.vertex_index]; + out.position = vec4(positions[input.vertex_index], 0.0, 1.0); + + return out; +} + +[[stage(fragment)]] +fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(u_texture, u_sampler, input.uv); +} \ No newline at end of file diff --git a/wgpu/src/shader/image.frag b/wgpu/src/shader/image.frag deleted file mode 100644 index 2809e9e6..00000000 --- a/wgpu/src/shader/image.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 - -layout(location = 0) in vec3 v_Uv; - -layout(set = 0, binding = 1) uniform sampler u_Sampler; -layout(set = 1, binding = 0) uniform texture2DArray u_Texture; - -layout(location = 0) out vec4 o_Color; - -void main() { - o_Color = texture(sampler2DArray(u_Texture, u_Sampler), v_Uv); -} diff --git a/wgpu/src/shader/image.frag.spv b/wgpu/src/shader/image.frag.spv deleted file mode 100644 index 65b08aa3..00000000 Binary files a/wgpu/src/shader/image.frag.spv and /dev/null differ diff --git a/wgpu/src/shader/image.vert b/wgpu/src/shader/image.vert deleted file mode 100644 index dab53cfe..00000000 --- a/wgpu/src/shader/image.vert +++ /dev/null @@ -1,27 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 v_Pos; -layout(location = 1) in vec2 i_Pos; -layout(location = 2) in vec2 i_Scale; -layout(location = 3) in vec2 i_Atlas_Pos; -layout(location = 4) in vec2 i_Atlas_Scale; -layout(location = 5) in uint i_Layer; - -layout (set = 0, binding = 0) uniform Globals { - mat4 u_Transform; -}; - -layout(location = 0) out vec3 o_Uv; - -void main() { - o_Uv = vec3(v_Pos * i_Atlas_Scale + i_Atlas_Pos, i_Layer); - - mat4 i_Transform = mat4( - vec4(i_Scale.x, 0.0, 0.0, 0.0), - vec4(0.0, i_Scale.y, 0.0, 0.0), - vec4(0.0, 0.0, 1.0, 0.0), - vec4(i_Pos, 0.0, 1.0) - ); - - gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); -} diff --git a/wgpu/src/shader/image.vert.spv b/wgpu/src/shader/image.vert.spv deleted file mode 100644 index 21f5db2d..00000000 Binary files a/wgpu/src/shader/image.vert.spv and /dev/null differ diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl new file mode 100644 index 00000000..c623247e --- /dev/null +++ b/wgpu/src/shader/image.wgsl @@ -0,0 +1,45 @@ +[[block]] +struct Globals { + transform: mat4x4; +}; + +[[group(0), binding(0)]] var globals: Globals; +[[group(0), binding(1)]] var u_sampler: sampler; +[[group(0), binding(2)]] var u_texture: texture2d; + +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: u32; +}; + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] uv: vec3; +}; + +[[stage(vertex)]] +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + + out.uv = vec3(input.v_pos * input.atlas_scale + input.atlas_pos, input.layer); + + var transform: mat4x4 = mat4x4( + vec4(input.scale.x, 0.0, 0.0, 0.0), + vec4(0.0, scale.y, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(input.pos, 0.0, 1.0) + ); + + out.position = globals.transform * transform * vec4(input.v_pos, 0.0, 1.0); + + return out; +} + +[[stage(fragment)]] +fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(u_texture, u_sampler, input.uv); +} diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag deleted file mode 100644 index ad1af1ad..00000000 --- a/wgpu/src/shader/quad.frag +++ /dev/null @@ -1,66 +0,0 @@ -#version 450 - -layout(location = 0) in vec4 v_Color; -layout(location = 1) in vec4 v_BorderColor; -layout(location = 2) in vec2 v_Pos; -layout(location = 3) in vec2 v_Scale; -layout(location = 4) in float v_BorderRadius; -layout(location = 5) in float v_BorderWidth; - -layout(location = 0) out vec4 o_Color; - -float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius) -{ - // TODO: Try SDF approach: https://www.shadertoy.com/view/wd3XRN - vec2 inner_size = size - vec2(radius, radius) * 2.0; - vec2 top_left = position + vec2(radius, radius); - vec2 bottom_right = top_left + inner_size; - - vec2 top_left_distance = top_left - frag_coord; - vec2 bottom_right_distance = frag_coord - bottom_right; - - vec2 distance = vec2( - max(max(top_left_distance.x, bottom_right_distance.x), 0), - max(max(top_left_distance.y, bottom_right_distance.y), 0) - ); - - return sqrt(distance.x * distance.x + distance.y * distance.y); -} - -void main() { - vec4 mixed_color; - - // TODO: Remove branching (?) - if(v_BorderWidth > 0) { - float internal_border = max(v_BorderRadius - v_BorderWidth, 0); - - float internal_distance = distance( - gl_FragCoord.xy, - v_Pos + vec2(v_BorderWidth), - v_Scale - vec2(v_BorderWidth * 2.0), - internal_border - ); - - float border_mix = smoothstep( - max(internal_border - 0.5, 0.0), - internal_border + 0.5, - internal_distance - ); - - mixed_color = mix(v_Color, v_BorderColor, border_mix); - } else { - mixed_color = v_Color; - } - - float d = distance( - gl_FragCoord.xy, - v_Pos, - v_Scale, - v_BorderRadius - ); - - float radius_alpha = - 1.0 - smoothstep(max(v_BorderRadius - 0.5, 0), v_BorderRadius + 0.5, d); - - o_Color = vec4(mixed_color.xyz, mixed_color.w * radius_alpha); -} diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv deleted file mode 100644 index 519f5f01..00000000 Binary files a/wgpu/src/shader/quad.frag.spv and /dev/null differ diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert deleted file mode 100644 index 09a278b1..00000000 --- a/wgpu/src/shader/quad.vert +++ /dev/null @@ -1,47 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 v_Pos; -layout(location = 1) in vec2 i_Pos; -layout(location = 2) in vec2 i_Scale; -layout(location = 3) in vec4 i_Color; -layout(location = 4) in vec4 i_BorderColor; -layout(location = 5) in float i_BorderRadius; -layout(location = 6) in float i_BorderWidth; - -layout (set = 0, binding = 0) uniform Globals { - mat4 u_Transform; - float u_Scale; -}; - -layout(location = 0) out vec4 o_Color; -layout(location = 1) out vec4 o_BorderColor; -layout(location = 2) out vec2 o_Pos; -layout(location = 3) out vec2 o_Scale; -layout(location = 4) out float o_BorderRadius; -layout(location = 5) out float o_BorderWidth; - -void main() { - vec2 p_Pos = i_Pos * u_Scale; - vec2 p_Scale = i_Scale * u_Scale; - - float i_BorderRadius = min( - i_BorderRadius, - min(i_Scale.x, i_Scale.y) / 2.0 - ); - - mat4 i_Transform = mat4( - vec4(p_Scale.x + 1.0, 0.0, 0.0, 0.0), - vec4(0.0, p_Scale.y + 1.0, 0.0, 0.0), - vec4(0.0, 0.0, 1.0, 0.0), - vec4(p_Pos - vec2(0.5, 0.5), 0.0, 1.0) - ); - - o_Color = i_Color; - o_BorderColor = i_BorderColor; - o_Pos = p_Pos; - o_Scale = p_Scale; - o_BorderRadius = i_BorderRadius * u_Scale; - o_BorderWidth = i_BorderWidth * u_Scale; - - gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); -} diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv deleted file mode 100644 index fa71ba1e..00000000 Binary files a/wgpu/src/shader/quad.vert.spv and /dev/null differ diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl new file mode 100644 index 00000000..c67b45e3 --- /dev/null +++ b/wgpu/src/shader/quad.wgsl @@ -0,0 +1,123 @@ +[[block]] +struct Globals { + transform: mat4x4; + scale: f32; +}; + +[[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; +}; + +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; +}; + +[[stage(vertex)]] +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + + var pos: vec2 = input.pos * globals.scale; + var scale: vec2 = input.scale * globals.scale; + + var border_radius: f32 = min( + input.border_radius, + min(input.scale.x, input.scale.y) / 2.0 + ); + + var transform: mat4x4 = mat4x4( + vec4(scale.x + 1.0, 0.0, 0.0, 0.0), + vec4(0.0, scale.y + 1.0, 0.0, 0.0), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(pos - vec2(0.5, 0.5), 0.0, 1.0) + ); + + out.color = input.color; + out.border_color = input.border_color; + out.pos = pos; + out.scale = scale; + out.border_radius = border_radius * globals.scale; + out.border_width = input.border_width * globals.scale; + out.position = globals.transform * transform * vec4(input.v_pos, 0.0, 1.0); + + return out; +} + +fn distance_alg( + frag_coord: vec2, + position: vec2, + size: vec2, + radius: f32 +) -> f32 { + var inner_size: vec2 = size - vec2(radius, radius) * 2.0; + var top_left: vec2 = position + vec2(radius, radius); + var bottom_right: vec2 = top_left + inner_size; + + var top_left_distance: vec2 = top_left - frag_coord; + var bottom_right_distance: vec2 = frag_coord - bottom_right; + + var dist: vec2 = vec2( + max(max(top_left_distance.x, bottom_right_distance.x), 0.0), + max(max(top_left_distance.y, bottom_right_distance.y), 0.0) + ); + + return sqrt(dist.x * dist.x + dist.y * dist.y); +} + + +[[stage(fragment)]] +fn fs_main( + input: VertexOutput, + [[builtin(position)]] coord: vec4 +) -> [[location(0)]] vec4 { + var mixed_color: vec4 = input.color; + + if (input.border_width > 0.0) { + var internal_border: f32 = max( + input.border_radius - input.border_width, + 0.0 + ); + + var internal_distance: f32 = distance_alg( + vec2(coord.x, coord.y), + input.pos + vec2(input.border_width, input.border_width), + input.scale - vec2(input.border_width * 2.0, input.border_width * 2.0), + internal_border + ); + + var border_mix: f32 = smoothStep( + max(internal_border - 0.5, 0.0), + internal_border + 0.5, + internal_distance + ); + + mixed_color = mix(input.color, input.border_color, vec4(border_mix, border_mix, border_mix, border_mix)); + } + + var dist: f32 = distance_alg( + vec2(coord.x, coord.y), + input.pos, + input.scale, + input.border_radius + ); + + var radius_alpha: f32 = 1.0 - smoothStep( + max(input.border_radius - 0.5, 0.0), + input.border_radius + 0.5, + dist); + + return vec4(radius_alpha, radius_alpha, radius_alpha, radius_alpha); +} \ No newline at end of file diff --git a/wgpu/src/shader/triangle.frag b/wgpu/src/shader/triangle.frag deleted file mode 100644 index e39c45e7..00000000 --- a/wgpu/src/shader/triangle.frag +++ /dev/null @@ -1,8 +0,0 @@ -#version 450 - -layout(location = 0) in vec4 i_Color; -layout(location = 0) out vec4 o_Color; - -void main() { - o_Color = i_Color; -} diff --git a/wgpu/src/shader/triangle.frag.spv b/wgpu/src/shader/triangle.frag.spv deleted file mode 100644 index 11201872..00000000 Binary files a/wgpu/src/shader/triangle.frag.spv and /dev/null differ diff --git a/wgpu/src/shader/triangle.vert b/wgpu/src/shader/triangle.vert deleted file mode 100644 index 1f2c009b..00000000 --- a/wgpu/src/shader/triangle.vert +++ /dev/null @@ -1,15 +0,0 @@ -#version 450 - -layout(location = 0) in vec2 i_Position; -layout(location = 1) in vec4 i_Color; - -layout(location = 0) out vec4 o_Color; - -layout (set = 0, binding = 0) uniform Globals { - mat4 u_Transform; -}; - -void main() { - gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); - o_Color = i_Color; -} diff --git a/wgpu/src/shader/triangle.vert.spv b/wgpu/src/shader/triangle.vert.spv deleted file mode 100644 index 871f4f55..00000000 Binary files a/wgpu/src/shader/triangle.vert.spv and /dev/null differ diff --git a/wgpu/src/shader/triangle.wgsl b/wgpu/src/shader/triangle.wgsl new file mode 100644 index 00000000..96eaabcc --- /dev/null +++ b/wgpu/src/shader/triangle.wgsl @@ -0,0 +1,31 @@ +[[block]] +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; +}; + +[[stage(vertex)]] +fn vs_main(input: VertexInput) -> VertexOutput { + var out: VertexOutput; + + out.color = input.color; + out.position = globals.transform * vec4(input.position, 0.0, 1.0); + + return out; +} + +[[stage(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 2f255940..168ff953 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -127,21 +127,19 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/triangle.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/triangle.frag.spv" - )); + let shader = 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"))), + flags: wgpu::ShaderFlags::all() + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, @@ -149,40 +147,41 @@ impl Pipeline { // Position wgpu::VertexAttribute { shader_location: 0, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }, // Color wgpu::VertexAttribute { shader_location: 1, - format: wgpu::VertexFormat::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * 2, }, ], }], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -261,7 +260,8 @@ impl Pipeline { Uniforms, >( ) - as u64), + as + u64), }, }], }); @@ -303,6 +303,8 @@ impl Pipeline { vertex_buffer.copy_from_slice(vertices); } + println!("Indices: {} - Index Size: {}", indices_size, self.index_buffer.size); + { let mut index_buffer = staging_belt.write_buffer( encoder, @@ -331,6 +333,7 @@ impl Pipeline { let uniforms = bytemuck::cast_slice(&uniforms); + if let Some(uniforms_size) = wgpu::BufferSize::new(uniforms.len() as u64) { @@ -364,8 +367,8 @@ impl Pipeline { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle render pass"), color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment, + wgpu::RenderPassColorAttachment { + view: attachment, resolve_target, ops: wgpu::Operations { load, store: true }, }, diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index d964f815..d155f3ec 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -74,45 +74,44 @@ impl Blit { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "../shader/blit.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "../shader/blit.frag.spv" - )); + let shader = 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"))), + flags: wgpu::ShaderFlags::all() + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle::msaa pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -178,8 +177,8 @@ impl Blit { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle::msaa render pass"), color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment: target, + wgpu::RenderPassColorAttachment { + view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, @@ -222,7 +221,7 @@ impl Targets { let extent = wgpu::Extent3d { width, height, - depth: 1, + depth_or_array_layers: 1, }; let attachment = device.create_texture(&wgpu::TextureDescriptor { diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fdd648e8..6ff499af 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -133,8 +133,8 @@ impl iced_graphics::window::Compositor for Compositor { let _ = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::window::Compositor render pass"), - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.output.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.output.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear({ -- cgit From c719091c3d7b5f71899530437fde9b512bc2b0f3 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 22:06:16 -0700 Subject: Add staging belt fix --- wgpu/src/triangle.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 168ff953..67f14e4d 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -127,11 +127,14 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let shader = 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"))), - flags: wgpu::ShaderFlags::all() - }); + let shader = + 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"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -303,8 +306,6 @@ impl Pipeline { vertex_buffer.copy_from_slice(vertices); } - println!("Indices: {} - Index Size: {}", indices_size, self.index_buffer.size); - { let mut index_buffer = staging_belt.write_buffer( encoder, @@ -366,13 +367,11 @@ 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: &[wgpu::RenderPassColorAttachment { + view: attachment, + resolve_target, + ops: wgpu::Operations { load, store: true }, + }], depth_stencil_attachment: None, }); -- cgit From 0722d5e3ec307fd82a1cc76593d17d83cf828943 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:07:58 -0700 Subject: add temporary fix for image wgsl --- wgpu/src/image.rs | 2 +- wgpu/src/shader/blit.wgsl | 2 +- wgpu/src/shader/image.wgsl | 14 ++++++++------ wgpu/src/shader/quad.wgsl | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 713af209..45b63701 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -183,7 +183,7 @@ impl Pipeline { }, wgpu::VertexAttribute { shader_location: 5, - format: wgpu::VertexFormat::Uint32, + format: wgpu::VertexFormat::Sint32, offset: 4 * 8, }, ], diff --git a/wgpu/src/shader/blit.wgsl b/wgpu/src/shader/blit.wgsl index 7a987c2c..694f192e 100644 --- a/wgpu/src/shader/blit.wgsl +++ b/wgpu/src/shader/blit.wgsl @@ -40,4 +40,4 @@ fn vs_main(input: VertexInput) -> VertexOutput { [[stage(fragment)]] fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { return textureSample(u_texture, u_sampler, input.uv); -} \ No newline at end of file +} diff --git a/wgpu/src/shader/image.wgsl b/wgpu/src/shader/image.wgsl index c623247e..a63ee8f6 100644 --- a/wgpu/src/shader/image.wgsl +++ b/wgpu/src/shader/image.wgsl @@ -5,7 +5,7 @@ struct Globals { [[group(0), binding(0)]] var globals: Globals; [[group(0), binding(1)]] var u_sampler: sampler; -[[group(0), binding(2)]] var u_texture: texture2d; +[[group(1), binding(0)]] var u_texture: texture_2d_array; struct VertexInput { [[location(0)]] v_pos: vec2; @@ -13,23 +13,25 @@ struct VertexInput { [[location(2)]] scale: vec2; [[location(3)]] atlas_pos: vec2; [[location(4)]] atlas_scale: vec2; - [[location(5)]] layer: u32; + [[location(5)]] layer: i32; }; struct VertexOutput { [[builtin(position)]] position: vec4; - [[location(0)]] uv: vec3; + [[location(0)]] uv: vec2; + [[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation. }; [[stage(vertex)]] fn vs_main(input: VertexInput) -> VertexOutput { var out: VertexOutput; - out.uv = vec3(input.v_pos * input.atlas_scale + input.atlas_pos, input.layer); + out.uv = vec2(input.v_pos * input.atlas_scale + input.atlas_pos); + out.layer = f32(input.layer); var transform: mat4x4 = mat4x4( vec4(input.scale.x, 0.0, 0.0, 0.0), - vec4(0.0, scale.y, 0.0, 0.0), + vec4(0.0, input.scale.y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(input.pos, 0.0, 1.0) ); @@ -41,5 +43,5 @@ fn vs_main(input: VertexInput) -> VertexOutput { [[stage(fragment)]] fn fs_main(input: VertexOutput) -> [[location(0)]] vec4 { - return textureSample(u_texture, u_sampler, input.uv); + 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 c67b45e3..3c0aa9f2 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -120,4 +120,4 @@ fn fs_main( dist); return vec4(radius_alpha, radius_alpha, radius_alpha, radius_alpha); -} \ No newline at end of file +} -- cgit From 983aa1b3665c6b546700767d21d73de72372ddad Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:23:47 -0700 Subject: Run cargo fmt --- wgpu/src/image.rs | 29 +++++++++++++++-------------- wgpu/src/shader/quad.wgsl | 2 +- wgpu/src/triangle/msaa.rs | 29 +++++++++++++++-------------- 3 files changed, 31 insertions(+), 29 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 45b63701..78f70dd8 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -134,11 +134,14 @@ impl Pipeline { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let shader = 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"))), - flags: wgpu::ShaderFlags::all() - }); + let shader = + 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"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -422,16 +425,14 @@ 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: &[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/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index 3c0aa9f2..bae05a0c 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -119,5 +119,5 @@ fn fs_main( input.border_radius + 0.5, dist); - return vec4(radius_alpha, radius_alpha, radius_alpha, radius_alpha); + return vec4(mixed_color.x, mixed_color.y, mixed_color.z, mixed_color.w * radius_alpha); } diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index d155f3ec..cc19539a 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -74,11 +74,14 @@ impl Blit { bind_group_layouts: &[&constant_layout, &texture_layout], }); - let shader = 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"))), - flags: wgpu::ShaderFlags::all() - }); + let shader = + 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"), + )), + flags: wgpu::ShaderFlags::all(), + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { @@ -176,16 +179,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 { - view: target, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, - store: true, - }, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, }, - ], + }], depth_stencil_attachment: None, }); -- cgit From 3840b75beaa3925f3438a7b40f01aaac221b8206 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 5 May 2021 14:33:03 +0700 Subject: Provide `compatible_surface` in `iced_wgpu::Compositor` --- wgpu/src/window/compositor.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index fdd648e8..aa873df8 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -21,9 +21,16 @@ impl Compositor { /// Requests a new [`Compositor`] with the given [`Settings`]. /// /// Returns `None` if no compatible graphics adapter could be found. - pub async fn request(settings: Settings) -> Option { + pub async fn request( + settings: Settings, + compatible_window: Option<&W>, + ) -> Option { let instance = wgpu::Instance::new(settings.internal_backend); + #[allow(unsafe_code)] + let compatible_surface = compatible_window + .map(|window| unsafe { instance.create_surface(window) }); + let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { power_preference: if settings.antialiasing.is_none() { @@ -31,7 +38,7 @@ impl Compositor { } else { wgpu::PowerPreference::HighPerformance }, - compatible_surface: None, + compatible_surface: compatible_surface.as_ref(), }) .await?; @@ -77,9 +84,15 @@ impl iced_graphics::window::Compositor for Compositor { type Surface = wgpu::Surface; type SwapChain = wgpu::SwapChain; - fn new(settings: Self::Settings) -> Result<(Self, Renderer), Error> { - let compositor = futures::executor::block_on(Self::request(settings)) - .ok_or(Error::AdapterNotFound)?; + fn new( + settings: Self::Settings, + compatible_window: Option<&W>, + ) -> Result<(Self, Renderer), Error> { + let compositor = futures::executor::block_on(Self::request( + settings, + compatible_window, + )) + .ok_or(Error::AdapterNotFound)?; let backend = compositor.create_backend(); -- cgit From 77a17cde83c9bdb8a61b871c7a15303f13e8d781 Mon Sep 17 00:00:00 2001 From: Zak Date: Tue, 11 May 2021 22:41:55 +0100 Subject: This commit optimizes the function used to converg rgba pixels into bgra pixels. --- wgpu/src/image/vector.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index ab0f67d0..8c7de617 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -1,7 +1,8 @@ -use crate::image::atlas::{self, Atlas}; use iced_native::svg; use std::collections::{HashMap, HashSet}; +use crate::image::atlas::{self, Atlas}; + pub enum Svg { Loaded(usvg::Tree), NotFound, @@ -111,26 +112,13 @@ impl Cache { let width = img.width(); let height = img.height(); - let mut rgba = img.take().into_iter(); - - // TODO: Perform conversion in the GPU - let bgra: Vec = std::iter::from_fn(move || { - use std::iter::once; - - let r = rgba.next()?; - let g = rgba.next()?; - let b = rgba.next()?; - let a = rgba.next()?; - - Some(once(b).chain(once(g)).chain(once(r)).chain(once(a))) - }) - .flatten() - .collect(); + let mut rgba = img.take(); + rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2)); let allocation = texture_atlas.upload( width, height, - bytemuck::cast_slice(bgra.as_slice()), + bytemuck::cast_slice(rgba.as_slice()), device, encoder, )?; -- cgit From e6db43987072e62ae146e9b6fe4bc2ef0e519073 Mon Sep 17 00:00:00 2001 From: Downtime Date: Thu, 13 May 2021 16:46:20 +0800 Subject: Add a primary backend that can be set Add a primary backend that can be set --- wgpu/src/settings.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'wgpu/src') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index abc404dc..4a1bb322 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -78,6 +78,7 @@ fn backend_from_env() -> Option { "dx11" => wgpu::BackendBit::DX11, "gl" => wgpu::BackendBit::GL, "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + "primary" => wgpu::BackendBit::PRIMARY, other => panic!("Unknown backend: {}", other), } }) -- cgit From 88defb65caa70688c47a9d4d2d4f51dd97814e01 Mon Sep 17 00:00:00 2001 From: Downtime Date: Fri, 14 May 2021 21:21:25 +0800 Subject: update doc --- wgpu/src/settings.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'wgpu/src') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 4a1bb322..6c97d895 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -47,6 +47,7 @@ impl Settings { /// - `dx11` /// - `gl` /// - `webgpu` + /// - `primary` pub fn from_env() -> Self { Settings { internal_backend: backend_from_env() -- cgit From 8b7452a55def8620f2c91df40d3882c449f85420 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 19 May 2021 16:26:04 +0700 Subject: Fix formatting with `cargo fmt` --- wgpu/src/triangle.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 67f14e4d..21d0e0ab 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -263,8 +263,7 @@ impl Pipeline { Uniforms, >( ) - as - u64), + as u64), }, }], }); @@ -334,7 +333,6 @@ impl Pipeline { let uniforms = bytemuck::cast_slice(&uniforms); - if let Some(uniforms_size) = wgpu::BufferSize::new(uniforms.len() as u64) { -- cgit From cf6af4c2560f5996bc533402ac3e4289c0c94702 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Wed, 19 May 2021 17:11:51 +0700 Subject: Use latest `wgpu` releases instead of patched sources --- wgpu/src/image.rs | 12 +++++++----- wgpu/src/quad.rs | 4 ++-- wgpu/src/triangle.rs | 36 ++++++++++++++++++++---------------- 3 files changed, 29 insertions(+), 23 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index 78f70dd8..cd7b3d23 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -97,11 +97,13 @@ impl Pipeline { entries: &[ wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { - buffer: &uniforms_buffer, - offset: 0, - size: None, - }, + resource: wgpu::BindingResource::Buffer( + wgpu::BufferBinding { + buffer: &uniforms_buffer, + offset: 0, + size: None, + }, + ), }, wgpu::BindGroupEntry { binding: 1, diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 458679e4..0f9d7b99 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -47,11 +47,11 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { + resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { buffer: &constants_buffer, offset: 0, size: None, - }, + }), }], }); diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 21d0e0ab..8636b331 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -110,13 +110,17 @@ impl Pipeline { layout: &constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { - buffer: &constants_buffer.raw, - offset: 0, - size: wgpu::BufferSize::new( - std::mem::size_of::() as u64, - ), - }, + resource: wgpu::BindingResource::Buffer( + wgpu::BufferBinding { + buffer: &constants_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new(std::mem::size_of::< + Uniforms, + >( + ) + as u64), + }, + ), }], }); @@ -256,15 +260,15 @@ impl Pipeline { layout: &self.constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer { - buffer: &self.uniforms_buffer.raw, - offset: 0, - size: wgpu::BufferSize::new(std::mem::size_of::< - Uniforms, - >( - ) - as u64), - }, + resource: wgpu::BindingResource::Buffer( + wgpu::BufferBinding { + buffer: &self.uniforms_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new( + std::mem::size_of::() as u64, + ), + }, + ), }], }); } -- cgit From d91422e345d30f0d33d737a3be8ad1c90f5d14b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 08:09:03 -0700 Subject: temporary up --- wgpu/src/quad.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 0f9d7b99..9b87ef81 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -28,7 +28,7 @@ impl Pipeline { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new( - mem::size_of::() as u64, + mem::size_of::() as wgpu::BufferAddress, ), }, count: None, @@ -37,7 +37,7 @@ impl Pipeline { let constants_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: Some("iced_wgpu::quad uniforms buffer"), - size: mem::size_of::() as u64, + size: mem::size_of::() as wgpu::BufferAddress, usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, mapped_at_creation: false, }); @@ -47,11 +47,7 @@ impl Pipeline { layout: &constant_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { - buffer: &constants_buffer, - offset: 0, - size: None, - }), + resource: constants_buffer.as_entire_binding(), }], }); -- cgit From b40c44164646e853239d1b76fd8e4768eb21d9ac Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 21:04:47 -0700 Subject: Add padding to quad to fix alignment issue --- wgpu/src/quad.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 9b87ef81..b91e3e89 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -305,6 +305,9 @@ const MAX_INSTANCES: usize = 100_000; struct Uniforms { transform: [f32; 16], scale: f32, + // Uniforms must be aligned to their largest member, + // this uses a mat4x4 which aligns to 16, so align to that + _padding: [f32; 3], } impl Uniforms { @@ -312,6 +315,7 @@ impl Uniforms { Self { transform: *transformation.as_ref(), scale, + _padding: [0.0; 3] } } } @@ -321,6 +325,7 @@ impl Default for Uniforms { Self { transform: *Transformation::identity().as_ref(), scale: 1.0, + _padding: [0.0; 3] } } } -- cgit From 2d549d806cd9ff1d7b7b237d818cd24c84957c83 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 21:09:19 -0700 Subject: Remove padding from triangle --- wgpu/src/triangle.rs | 8 -------- 1 file changed, 8 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 8636b331..141fc9af 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -425,18 +425,12 @@ impl Pipeline { #[derive(Debug, Clone, Copy, Zeroable, Pod)] struct Uniforms { transform: [f32; 16], - // We need to align this to 256 bytes to please `wgpu`... - // TODO: Be smarter and stop wasting memory! - _padding_a: [f32; 32], - _padding_b: [f32; 16], } impl Default for Uniforms { fn default() -> Self { Self { transform: *Transformation::identity().as_ref(), - _padding_a: [0.0; 32], - _padding_b: [0.0; 16], } } } @@ -445,8 +439,6 @@ impl From for Uniforms { fn from(transformation: Transformation) -> Uniforms { Self { transform: transformation.into(), - _padding_a: [0.0; 32], - _padding_b: [0.0; 16], } } } -- cgit From a70715ad9e41bf133e8e37d43633ffa84ae211b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 22:07:27 -0700 Subject: run format --- wgpu/src/quad.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index b91e3e89..6f221ca3 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -315,7 +315,7 @@ impl Uniforms { Self { transform: *transformation.as_ref(), scale, - _padding: [0.0; 3] + _padding: [0.0; 3], } } } @@ -325,7 +325,7 @@ impl Default for Uniforms { Self { transform: *Transformation::identity().as_ref(), scale: 1.0, - _padding: [0.0; 3] + _padding: [0.0; 3], } } } -- cgit From 0772310c4f6ab1ff4b9771011c04b6ece0b84df3 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Thu, 20 May 2021 23:10:22 -0700 Subject: Fix duplicating fragment position --- wgpu/src/shader/quad.wgsl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/shader/quad.wgsl b/wgpu/src/shader/quad.wgsl index bae05a0c..80d733ab 100644 --- a/wgpu/src/shader/quad.wgsl +++ b/wgpu/src/shader/quad.wgsl @@ -80,8 +80,7 @@ fn distance_alg( [[stage(fragment)]] fn fs_main( - input: VertexOutput, - [[builtin(position)]] coord: vec4 + input: VertexOutput ) -> [[location(0)]] vec4 { var mixed_color: vec4 = input.color; @@ -92,7 +91,7 @@ fn fs_main( ); var internal_distance: f32 = distance_alg( - vec2(coord.x, coord.y), + vec2(input.position.x, input.position.y), input.pos + vec2(input.border_width, input.border_width), input.scale - vec2(input.border_width * 2.0, input.border_width * 2.0), internal_border @@ -108,7 +107,7 @@ fn fs_main( } var dist: f32 = distance_alg( - vec2(coord.x, coord.y), + vec2(input.position.x, input.position.y), input.pos, input.scale, input.border_radius -- cgit From ebec84ea7c54fffb5bc9645326782d84a30a8197 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Fri, 21 May 2021 20:29:17 +0700 Subject: Revert "Remove padding from triangle" This reverts commit 2d549d806cd9ff1d7b7b237d818cd24c84957c83. --- wgpu/src/triangle.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 141fc9af..8636b331 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -425,12 +425,18 @@ impl Pipeline { #[derive(Debug, Clone, Copy, Zeroable, Pod)] struct Uniforms { transform: [f32; 16], + // We need to align this to 256 bytes to please `wgpu`... + // TODO: Be smarter and stop wasting memory! + _padding_a: [f32; 32], + _padding_b: [f32; 16], } impl Default for Uniforms { fn default() -> Self { Self { transform: *Transformation::identity().as_ref(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], } } } @@ -439,6 +445,8 @@ impl From for Uniforms { fn from(transformation: Transformation) -> Uniforms { Self { transform: transformation.into(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], } } } -- cgit From 4cbc34524598756ce18cb25a664bc6f256d42851 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Date: Fri, 21 May 2021 20:34:08 +0700 Subject: Use `FilterMode::Nearest` in `triangle::msaa` --- wgpu/src/triangle/msaa.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index cc19539a..c099d518 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -20,9 +20,9 @@ impl Blit { address_mode_u: wgpu::AddressMode::ClampToEdge, address_mode_v: wgpu::AddressMode::ClampToEdge, address_mode_w: wgpu::AddressMode::ClampToEdge, - mag_filter: wgpu::FilterMode::Linear, - min_filter: wgpu::FilterMode::Linear, - mipmap_filter: wgpu::FilterMode::Linear, + mag_filter: wgpu::FilterMode::Nearest, + min_filter: wgpu::FilterMode::Nearest, + mipmap_filter: wgpu::FilterMode::Nearest, ..Default::default() }); -- cgit From 52a185fbab728b85cf414d4997567f52ebc66205 Mon Sep 17 00:00:00 2001 From: Kaiden42 Date: Sat, 19 Sep 2020 18:44:27 +0200 Subject: Implement `Toggler` widget for iced_native --- wgpu/src/widget.rs | 3 +++ wgpu/src/widget/toggler.rs | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 wgpu/src/widget/toggler.rs (limited to 'wgpu/src') diff --git a/wgpu/src/widget.rs b/wgpu/src/widget.rs index 304bb726..a575d036 100644 --- a/wgpu/src/widget.rs +++ b/wgpu/src/widget.rs @@ -20,6 +20,7 @@ pub mod rule; pub mod scrollable; pub mod slider; pub mod text_input; +pub mod toggler; pub mod tooltip; #[doc(no_inline)] @@ -45,6 +46,8 @@ pub use slider::Slider; #[doc(no_inline)] pub use text_input::TextInput; #[doc(no_inline)] +pub use toggler::Toggler; +#[doc(no_inline)] pub use tooltip::Tooltip; #[cfg(feature = "canvas")] diff --git a/wgpu/src/widget/toggler.rs b/wgpu/src/widget/toggler.rs new file mode 100644 index 00000000..dfcf759b --- /dev/null +++ b/wgpu/src/widget/toggler.rs @@ -0,0 +1,9 @@ +//! Show toggle controls using togglers. +use crate::Renderer; + +pub use iced_graphics::toggler::{Style, StyleSheet}; + +/// A toggler that can be toggled +/// +/// This is an alias of an `iced_native` toggler with an `iced_wgpu::Renderer`. +pub type Toggler = iced_native::Toggler; -- cgit From 6469e463cd1f99190c6eba4701d4c1059934d3ee Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 14 Jun 2021 18:06:28 +0300 Subject: feat: expose draw_cache_multithread --- wgpu/src/text.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 4d92d9e9..eed5de38 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -46,7 +46,9 @@ impl Pipeline { let draw_brush = wgpu_glyph::GlyphBrushBuilder::using_font(font.clone()) .initial_cache_size((2048, 2048)) - .draw_cache_multithread(false) // TODO: Expose as a configuration flag + .draw_cache_multithread(cfg!( + feature = "glyph_draw_cache_multithread" + )) .build(device, format); let measure_brush = -- cgit From 83d19689c80266874e0a26085f17a94fd3507e1e Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 14 Jun 2021 21:01:37 +0300 Subject: docs: update all 0.2 github links to 0.3 --- wgpu/src/widget/pane_grid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'wgpu/src') diff --git a/wgpu/src/widget/pane_grid.rs b/wgpu/src/widget/pane_grid.rs index 44f9201c..fc36862c 100644 --- a/wgpu/src/widget/pane_grid.rs +++ b/wgpu/src/widget/pane_grid.rs @@ -6,7 +6,7 @@ //! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing, //! drag and drop, and hotkey support. //! -//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid +//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.3/examples/pane_grid use crate::Renderer; pub use iced_graphics::pane_grid::{ -- cgit From a53e7559fe01ee072d4f0533ecf1facec741b9e4 Mon Sep 17 00:00:00 2001 From: Poly Date: Sun, 20 Jun 2021 11:29:23 +0200 Subject: Use vertex_attr_array macro --- wgpu/src/image.rs | 34 +++++++--------------------------- wgpu/src/quad.rs | 40 ++++++++-------------------------------- wgpu/src/triangle.rs | 16 ++++------------ 3 files changed, 19 insertions(+), 71 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs index cd7b3d23..85663bf5 100644 --- a/wgpu/src/image.rs +++ b/wgpu/src/image.rs @@ -165,33 +165,13 @@ impl Pipeline { wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, - attributes: &[ - wgpu::VertexAttribute { - shader_location: 1, - format: wgpu::VertexFormat::Float32x2, - offset: 0, - }, - wgpu::VertexAttribute { - shader_location: 2, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 2, - }, - wgpu::VertexAttribute { - shader_location: 3, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 4, - }, - wgpu::VertexAttribute { - shader_location: 4, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 6, - }, - wgpu::VertexAttribute { - shader_location: 5, - format: wgpu::VertexFormat::Sint32, - offset: 4 * 8, - }, - ], + attributes: &wgpu::vertex_attr_array!( + 1 => Float32x2, + 2 => Float32x2, + 3 => Float32x2, + 4 => Float32x2, + 5 => Sint32, + ), }, ], }, diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs index 6f221ca3..93942fba 100644 --- a/wgpu/src/quad.rs +++ b/wgpu/src/quad.rs @@ -87,38 +87,14 @@ impl Pipeline { wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Instance, - attributes: &[ - wgpu::VertexAttribute { - shader_location: 1, - format: wgpu::VertexFormat::Float32x2, - offset: 0, - }, - wgpu::VertexAttribute { - shader_location: 2, - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 2, - }, - wgpu::VertexAttribute { - shader_location: 3, - format: wgpu::VertexFormat::Float32x4, - offset: 4 * (2 + 2), - }, - wgpu::VertexAttribute { - shader_location: 4, - format: wgpu::VertexFormat::Float32x4, - offset: 4 * (2 + 2 + 4), - }, - wgpu::VertexAttribute { - shader_location: 5, - format: wgpu::VertexFormat::Float32, - offset: 4 * (2 + 2 + 4 + 4), - }, - wgpu::VertexAttribute { - shader_location: 6, - format: wgpu::VertexFormat::Float32, - offset: 4 * (2 + 2 + 4 + 4 + 1), - }, - ], + attributes: &wgpu::vertex_attr_array!( + 1 => Float32x2, + 2 => Float32x2, + 3 => Float32x4, + 4 => Float32x4, + 5 => Float32, + 6 => Float32, + ), }, ], }, diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 8636b331..65b2b7b0 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -150,20 +150,12 @@ impl Pipeline { buffers: &[wgpu::VertexBufferLayout { array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, - attributes: &[ + attributes: &wgpu::vertex_attr_array!( // Position - wgpu::VertexAttribute { - shader_location: 0, - format: wgpu::VertexFormat::Float32x2, - offset: 0, - }, + 0 => Float32x2, // Color - wgpu::VertexAttribute { - shader_location: 1, - format: wgpu::VertexFormat::Float32x4, - offset: 4 * 2, - }, - ], + 1 => Float32x4, + ), }], }, fragment: Some(wgpu::FragmentState { -- cgit From 665422e256b5eb8fed23f1a13900838e0e3bcb44 Mon Sep 17 00:00:00 2001 From: aentity Date: Tue, 13 Jul 2021 22:27:48 -0400 Subject: Use ceil on svg dimensions, fix svg memory usage Calls ceil() on dimension bounds as this appears fix svg memory unbounded usage because no longer cache miss. The height and width return from resvg seem to always be ceiling of float dimensions, so we try to match. --- wgpu/src/image/vector.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 8c7de617..cd511a45 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -75,8 +75,8 @@ impl Cache { let id = handle.id(); let (width, height) = ( - (scale * width).round() as u32, - (scale * height).round() as u32, + (scale * width).ceil() as u32, + (scale * height).ceil() as u32, ); // TODO: Optimize! @@ -122,6 +122,7 @@ impl Cache { device, encoder, )?; + log::debug!("allocating {} {}x{}", id, width, height); let _ = self.svg_hits.insert(id); let _ = self.rasterized_hits.insert((id, width, height)); -- cgit From 217f5be8272f48a5b043d066ed1788cc127e1164 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 18:21:50 +0700 Subject: Add `text_multithreading` to `Settings` in `iced_glow` and `iced_wgpu` --- wgpu/src/backend.rs | 9 +++++++-- wgpu/src/settings.rs | 5 +++++ wgpu/src/text.rs | 5 ++--- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'wgpu/src') diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 534c6cb7..783079f3 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -31,8 +31,13 @@ pub struct Backend { impl Backend { /// Creates a new [`Backend`]. pub fn new(device: &wgpu::Device, settings: Settings) -> Self { - let text_pipeline = - text::Pipeline::new(device, settings.format, settings.default_font); + let text_pipeline = text::Pipeline::new( + device, + settings.format, + settings.default_font, + settings.text_multithreading, + ); + let quad_pipeline = quad::Pipeline::new(device, settings.format); let triangle_pipeline = triangle::Pipeline::new( device, diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 6c97d895..b490e54e 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -29,6 +29,10 @@ pub struct Settings { /// By default, it will be set to 20. pub default_text_size: u16, + /// If enabled, spread text workload in multiple threads when multiple cores + /// are available. + pub text_multithreading: bool, + /// The antialiasing strategy that will be used for triangle primitives. pub antialiasing: Option, } @@ -65,6 +69,7 @@ impl Default for Settings { internal_backend: wgpu::BackendBit::PRIMARY, default_font: None, default_text_size: 20, + text_multithreading: false, antialiasing: None, } } diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index eed5de38..2b5b94c9 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -15,6 +15,7 @@ impl Pipeline { device: &wgpu::Device, format: wgpu::TextureFormat, default_font: Option<&[u8]>, + multithreading: bool, ) -> Self { let default_font = default_font.map(|slice| slice.to_vec()); @@ -46,9 +47,7 @@ impl Pipeline { let draw_brush = wgpu_glyph::GlyphBrushBuilder::using_font(font.clone()) .initial_cache_size((2048, 2048)) - .draw_cache_multithread(cfg!( - feature = "glyph_draw_cache_multithread" - )) + .draw_cache_multithread(multithreading) .build(device, format); let measure_brush = -- cgit From 357a8a95c9820651110fe4d80d8d33a2678827c0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 22 Jul 2021 18:27:33 +0700 Subject: Introduce `text_multithreading` to `Settings` --- wgpu/src/settings.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'wgpu/src') diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index b490e54e..9a7eed34 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -31,9 +31,13 @@ pub struct Settings { /// If enabled, spread text workload in multiple threads when multiple cores /// are available. + /// + /// By default, it is disabled. pub text_multithreading: bool, /// The antialiasing strategy that will be used for triangle primitives. + /// + /// By default, it is `None`. pub antialiasing: Option, } -- cgit