From 9a2c78c4059d2be37d10adda397fb6e64f38ac02 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Sun, 11 Apr 2021 18:55:57 -0700 Subject: [PATCH] Upgrade wgpu --- examples/integration/src/scene.rs | 11 +-- wgpu/Cargo.toml | 4 +- 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 +- 28 files changed, 386 insertions(+), 353 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 diff --git a/examples/integration/src/scene.rs b/examples/integration/src/scene.rs index 36c0a41d..3e8277c8 100644 --- a/examples/integration/src/scene.rs +++ b/examples/integration/src/scene.rs @@ -20,8 +20,8 @@ impl Scene { ) -> wgpu::RenderPass<'a> { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: target, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear({ @@ -75,15 +75,16 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline { entry_point: "main", targets: &[wgpu::ColorTargetState { format: wgpu::TextureFormat::Bgra8UnormSrgb, - color_blend: wgpu::BlendState::REPLACE, - alpha_blend: wgpu::BlendState::REPLACE, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent::REPLACE, + alpha: wgpu::BlendComponent::REPLACE, + }), write_mask: wgpu::ColorWrite::ALL, }], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, front_face: wgpu::FrontFace::Ccw, - cull_mode: wgpu::CullMode::None, ..Default::default() }, depth_stencil: None, diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index fe41d9c0..28927638 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -26,8 +26,8 @@ qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] [dependencies] -wgpu = "0.7" -wgpu_glyph = "0.11" +wgpu = {git = "https://github.com/gfx-rs/wgpu-rs", rev = "53600ecd834893ef3e90458c48b84f2582d6c343"} +wgpu_glyph = {git = "https://github.com/Dispersia/wgpu_glyph", branch = "update-wgpu"} glyph_brush = "0.7" raw-window-handle = "0.3" log = "0.4" 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 2c5638b5dd682be63a5eb64d225284d399e85418..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 684 zcmZQ(Qf6mhU}WH6;9!tsfB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!NS3_J`B45jfQsTC!qMX3xRJ**4@V6ouD+=86cBCr?>*q*ZZ&@zy{ z?hGspAamqE90mpk5FccY5(CJG2)-hcJjhItJV*$n9>hnM2l)eLo-hLw*bjFNG3;-G@Aol;uK3j+f~ZenI0h{MUiz#zuJz@Wsyz`)GF%)rFJz;K9>fq|8Qg#lR|h!0YmA0Ju< z(#Oic2G*CJ6CajZRFYcZnU|7U0n*3HAj!bMkO|@@Cgr3ufW+7s6c`v7(sSYiQi~wU zL1wTqK*T|8kX(LoW=Up#9s?T#J6Ju)UtsafyprI|Dv(idIgmTkbK;$IG7DTXi%Syo zl2hSwARmL|N^^4Ha;yx@U_XNFVr5`u&_Z*gI|B;?$bWJm1q=)fAU-HuxEUD0YCRZO z!EORcgTz2IObp~skQj)DiGkb)5(BvfCI(`I#6aQd&cF;d52Q|*fe9S$ir^Sv0JFsy zm>Jj@7{F@88CV$D85qEPka`6M7H~|0%mayAL-`>0gTzD`SQxmVdO_~ghVnsngUpm+ zU}4~4U;vv55(CMD#CbuA85kIJ7+Aq_d<+Z>ATbbzso@8!X|RW>5rC=ziNnMM85kHq zd=Q3-2|>j`X6Z0+g6$V(U|;~*0Wt%m2gC-c1F=DV5P|vu6s{mYi!y*xKLZ0u9OP#Z z9~4J0c?qbWKz;+MmxA&^VFU_8S!fu7!XM-xP#A&Y8>Al;Ch|~ukeD1aZNl_`3?Tg=^&oi=8x&?BHpqRTj1Ni&Ah(+_u!7SQ$j=}rfW&_=Ffp()Fff4J z4hl0+eg%aQj1S5iAigaF3plLBp=E>}12Z^pgW}DRft3LizS0Z~U@?#ykb00l83qOh zkT^&^C{2R+AURODXd;;fvIpcBm|5D;yarMOQV%jqhXE9Z3=Dw`pc03HK^L4pK|Vo< z=|ROn@fg6s&H(baJ_AH8NDh?dK;aCs2NX7j(DDuxM<6$X_#pLv85kKX7#JA<0hm$_ 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 65b08aa3283c32125f7ce7ba1866b51823c1b802..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 684 zcmZQ(Qf6mhU}WH6;9!tsfB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!NS3_J`B45jfQsTC!qMX3xRJ**4@V6ouD+=86cBCr?>*q*ZZ&@zy{ z?hGspAamqE90mpk5FccY5(CJG2)-hcJjhItJV*$n9>fR9gZvNTgZu$APndxT><2}# zZy3OAF$QJ^HUP6C0|Ns{4M-fM24s&oG@XPqu!6%!f`Nenqz)u*$G{AZ POOV)K21W)821W(|9fKhH 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 21f5db2d2f3104a67387dbd296d65d1763bfd727..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2504 zcmZQ(Qf6mhU}WH6;9!VhfB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!N(z~IHez`)GF%)rFJ zz;K9>fq|8Qg#lSFh!4`AA0JuLx$$ZeTWlR$bv?#x88 z&x3)1Aw4HPAhjqgwWuVu0^}|>1~vweIEW3B%P-C>$;{7VU}Inhi-W=sES{NH5}a8D zaw1#~w{5)^URf1_lP07)Tx@2BKkNATvN>AiH2xv@)C$I%D}=P0(A?>$sqGY89=$10W1#E58{L3 z45S`pzYNrVPe@ z!r%^dJIFjaXubov9b_g*4unB&@`T0#C|`oi0r4T_4Fdxx%)Fst1~M1qCJ^5T>?Q^V zIR;4j0QnzemLCHo-a+XIWEO}IN;9zd3xLYQ)JH+>2D!_Offbx)Kw%3q9+U=tFfcKI z(ksX;P*{V?Ay9bRGO#d!(g3Iw1;sy%&krp>TNzlv@}M*fQUel)sS$#fuZ>VO!qBu1 z5(lXP#eq1q{4HQ$0jEC+1_lO@SRex{m@mn|zyQ(*awkko3MvK)rvPxt#K0iUz`y`f z3z7qwVaLD>E>l3_jtr~}p!5LBf1or2N+%%uLGh!)z`y_!4}iwG8Uq6ZNDLI$FbvbL z0gWF}Jj3*BGB7ZJ#9{iiplJpq4$}`(3kpL$XdMIdhdu)X14sOHqRC+hHRc40|NsnJdn+^hl(Ma z=KvK$HqQ|%1~Ly8Urr1R44^Osg&8P}Kw$!tb7o**0EGw0{~-T@{0EbBVPIeY`3>Y3 zklR6Sg~_=xFff4J333<69Uyx_a-h8E#=yV;vJ+%B$P9>DW^la^k^`kRP~Ht>U;x*T zp!^R?KOnt93=9k)aTq_CfdQ;<5(6u^ybNJrU;wEBiG$RD(p)ICtpkhSFa`z&kQj3K zg+s+a;RkXjsEmkUU|;~L1; +}; + +[[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 519f5f01679be972c5585ee081f5825c4586d435..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4212 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 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 fa71ba1e0a7ad7b811e3d52bb1c7013051410aa8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3604 zcmZQ(Qf6mhU}WH8;9zKEfB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!NvVez>vhiz>vzo zz>vkjz>v+rz);Mfq|8Qg#p=25TBEQfuSHiARnY2#0S}v ziNxn;U|?|1$xlkmDP~|}U}FIBLGCGy4=GB_D^ANV%4J|z!YC8YX9I^6f!#KSXFN;1GKs7nih&ty7RbFIdqC+$32Fw64@&PKArK#w{z2}5sRzk{_^e>FSit!L z#D}Q|#XpD-@-s+3D8GRCAUA;cpm+!IL3ski2jwFWA7(x%zCnDLeo!ET_%QXLcn0xd z_Ji^rh|dP~FDRZsZUKcKi1uJ$g~uI84CD@&7|2eL7|1S|7>ErLgV@Im)(cVxaw{l~ zKz4!56=q-p=W#`FZf5|q#Tb|wK<-drU|$tP1V{{I2gp27oP+EFl@}oM zKzvaAg2Y4_SQvyD7#Kiq1DUT4<%3E+5FeypgaP6Yka-~eAoqacA0`j-JIJjdd60UT zSs*@0J%|rVA0YK0`#@<9BnApEkbNM&3W&qNzyRZ`L&E^X2brS{k#_)@uLlh;kRM_4 zMqv2{dl=sY%x7TGVPFS`jTHj}14s;nL25xXOsx$>t-THdD>xo(85kHqVjv8%FC1KU zL&6y39}pi@zJbyNNInwkR!|&(`px83QXgFM!f0NDIh}9}G+kp!^C_3(5na`VSTcAU>#`g7HCV3{)?{_@FcZs&_zq zTWFr*0oUma42}$}44^bC%D@1w_dsbGqz2?aF$M+(ka!<7uEiM`7(n_!;&u$o3?Mgv z#6apnW=lcqdYGBgSj?1RU|;}=!_1UrU|<001Brvo1o;Cb1~L=m22i;Q$`2qjL2;uB zwF8s~U~1GD7#Kj}Ff|%bHJ~_ysnKL$U;v5pFtCHm11)Ge1nC3m2g!FZu!7}u7#J8p z@}PVKQ?HAp9^@vF8jyQI;S7=k*$oPJP@@Rs2W0mdGB7ZJ#2caJ8#6F4fW$y~D*&43 zOc@v$K;odh2E#Bj%@`OMKxQKQ$DDzI0VEDH(}ID40VIZOrX@5VgXCalg2Dq7SJn&+ z;P`8X#;qL#0|Q75l%E5k?zCrMU;v4O(jZI>RR4j*K(D1_n?Vg2D_GMxZc($pteoFo41Xiug)lHMfcysX3&`ytx5DH?85kHq z?gY6DskJV*{yzJvHMxj1P1 z9wY}U%RzjQ94Or-Lem{c4peS~_%OL-XgUYUfy!_YA0!7V2htcAz-?_%o&c3s=~&7Z zP~>nG6gJAblWlkeQ%zA0!4dGY8t|fSH+##Y|8q1|$wMGoOKh0i+Kk4l)x| zcYwq|W`N4{GN>7#vL0j)C``*47#Kj}Fg~cE3<}Rl46NYxNF@UU14s=>9Ha&mPSwzU z5G)PVFfcHH#6T$vCRPg-1Enia{DI=7j)8#zq!uIx%Zn2kSi$vrJp%&+$S#l?kb6OO ZZ3DE=1#&OQKOjCx-CqVq1`7s81^`CS0)+qo 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 11201872ec63d8b77e22fbee6a8731f2f5ed96a2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 372 zcmZQ(Qf6mhU}Rut;9%fofB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!N}8U}U@%wV^J_fq|8Qg#lSDD+3z? zHv$;{7VU}Inhs|UFcES{NH5}a9;3Q`A? z1KE|H6YrdpS>TdcT#}fVoC?2R349sBjKKFDljKFGfy zKFA-!3{2oOpa@P43}Chx12Y2~0|SEs0|SFN0}BJl9Uwl)KcWmQ3>;87kQLfcJ}9+; z%#&eYVc=q50P6>d$wAW#%nXnm2rDqKFz|rWASgXEFjzzRp!f!bAIKg)s68NaLH2<7 z{2)si7#JiNSioTeG8g17IcOMx!V6@!5Cg<7ps)m)4dR2s4HSkTc@d~QNIl4p;!rok z}s!AbAz2 z`7n799~3Vj^UWAo!SMj{7syDEo*xWM44^dQ$iT_~a=R!412`Rk!owCC7Gewx3?Ok3 zALJh?Xnqf50Oe)|23ZCM29OxYOqdub9e~6@_69JpgX3DB0iqTp2l6AxUlSQv!E&H9 z0kQ|A2ILlyzd&gb6mKB6*fB6OfcPMFAa{WLrv@!=Kysik0P+7aFfv#$FfsrDq!LXn 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({