From 9a2c78c4059d2be37d10adda397fb6e64f38ac02 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Sun, 11 Apr 2021 18:55:57 -0700 Subject: [PATCH 01/13] 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 zcmYk3Pfx-?5XA>d0R{OZ3WA9Ny%P^=OpIJOaN&mFu_2)c60oKM@$>nqyqNfYOPh4a zF#F!Vo!Phb@^>Y(oR#(K+A*4z7h_hjqN|hXY&!hft%eVe_b6)SIU$<5m8_sjZkOv1 zHcpgnWkWi64baL{SF;}-^2KKLV9rFrINC(9_I;}g?}NASd$*56t>GGun=QAWn=p1< z!Ob}Y^MjyGl0G*81(-g!O75ECfz||=p6nAT&hFzQ?bnh6JPe#0bL+O&MR9#)NB!^$ z#$R9mWmR4a{w2Y9h3m@osVe%MG8-wTM18{dRMn}|)z#Irt>)HT2#s)pzek~3OQ8u9!hGnKcCfRz)1MRv{l`xps8|TC zQmAH;eXch6Hq3JUlVAmGf);;G>>tD(RI@r`wd4JdKQZLH<-V_@{ZHv(ksiIz57Hy~ zPPjxqGaP;%rL{J}qTNjoD>)$*xa{6-4bwDP;s$1s2b^}h0{t8|fn}Ahz@bG19E+O_M)yhAwW8X*a0`Vzq0$kg5 z?Ag{_BR-9Fubg@LGr-m3uI3hioQRr5{1A>`Ma@|v^YW2fs^eMiT+ONN@g;fwGVly* zxJO@|zIQl}O+cfxZMe#p_s+(?QOsY&w{L4Zqsw(H=M1l6y{Ge!Gx5FM?@X>?&C9Lh zCD^#foUrZ&);TA@K8!bkoOSJQ3%KIku9wmA?>M6y#B#GUx>R9rQ;+i>nz zZ(iS->D!+_e0#C?r@W=#OdGi5|H5>z_U_F5y*i^9`@I{#sPD3h@0?$ajbO*Ki2Xb?-FZm, 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 zcmZ9JOHTqp5QJNn1r+5W3ZjVtyb}&+OpIPUaN&lJtz#T zlcuL?YPzOpgTh7GY{x44buEjg6~vfTt>kqwolS=ytC!*Ua)hF0feX>pt!zbAayfr} zV`Ep@RyL%Amw{G+x|)6IP$>4V9?Y2}x=$8Ks{PRRh1bzT{JC1EvDR=6=VtTe`yx)A zE4t4ndfW)wWZUN)pa9cnpyaMO?rTke>B&BkWA<}BbL9P6nt&PlK8^Xht#wIUPuWpF zW(6}}PyZEFUJL$ai!qC-VX`A8{tf zLsk5^=aDMD+=H{ns(8cW0cLi%E4@8)GZVp?Z!w|jtyp>Ot&(3vb?au!H_ruv|pMA@;4YWJA%XR4Y+9j*owTW@A)8+hLSXx~gX|~>tjE-H! zW53IIM|=*rF0b#_-;d?E2G}FnC)qFQmK>EtlFO1sNk+dm?Z1>D>vrq+FBVLEy|lKi z&D+VfT`Ja_9_M`CxHQ|UmYb#3x8-WZ^I3nE@pzMqv*XfI`E#WqoOP!?e%2`0n(yn4 zkKQNpT#|_x>Wow8EeL<8mWq|edZp2-d=gY=at@w_t=^1ValIzC-ShOu^Kq@U8h@e0 z9UFI-ZLS(`&d1GGx%RfQW23X!wyM<~TUPy|Z!GG2ti4dJzbRLnipzP7ZL5^NSH>+v zY866H`xEFfJxycY3d~#J&%1%C2TUKq*?^;fxeIoBhMjva$jf@uDaOem# zEvG$_^va*SVC<1_N6_IX17?n~WQQiKO{SO^AZ;R^bQ+2v9q6(u*`o@ zy2U4cSijB;>m<$|mJovsh273(o`~&J?t*sW$=5H9*|Pg!L#XMYcKVH-JmBR2P13VR z!jZ&k0xwBe{fcBhxIej`Xy>iq$OUFb?EQ*CH~$S`&Ze$$%_M&GmIeP?4D(7Zdd>f# zcFB}5GtedB{S6<9L1|*RrFX4RhpOwHD!<(NEoV`1{#b1yf zNd_ere^ENT#b1(647}yAevF8_EU|lBkq*Z)?y7XS^gnpwu( zkPb%<<36I$S#6oxr8@ zO$9EUZ(1DvU|GHy>2T?McLSHsHyb$e*?ZlSP7moBJ)$ROo0CpIxIg#herB7O&fT~R zwNtCv?n|dm>bfi8Tx@)c4iKyPJb!} z`!fkX@HTU6()n(!SL@Q@SjIh<4oCm&4lktRi_K>4htA>u$4d!k;X}O}+FwZ)CDhBe M2gdJ@vQ9|;0$=o)3jhEB 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 519f5f01679be972c5585ee081f5825c4586d435..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4212 zcmZvdXOmP#6o#9yOIng7F~A}!D6*1+NLH{)l&~u1VPI$3(P3wu9ag~v0*Z=&SwRu= zfAFJ!%21`{^W3>dE>qm9Q~katcAq{yGiLO{aVd>T35QKpe^R0qBJ^*73gONZ+9Mqf+Ug>I-m zTy0kC*`CZj8QpO8c!edaHHEcN?yDXhZpBQ8R|f|xjZ(|Y+;h=2>qDhlrN0S8)0yV8 z9;`Q;^&_Q5_3%KhAD0#ud`q$EEM|OK)E0BSy(2BbUI@wR*vFC5HqKOO?63AU2eMq9 zX&-BKuvuvgmTRShnK|>f=i$Ha|8tE?PZ#|QMLdglbhuX9LHoA1y4UKB_cl`6Q>QiL z9-H0aNU8TwxmL-zdl@P>%13hh%Wb^Y#`U}A-;svkt*w`iR9|cL|2R5GrH_lO)f-tI z=Vqj|J?EX-48<8+T4Tqg)A(`qSr~G_Efv`F85u?eNA%DD)*E7UgW+rx%I<7gDmD* zkiDQ*&e`Bjblu1t{C!_?{kq}fS=A}>2|3nh0osYIV*Nt&S%R5w4_0#81G##w&-MjI(AkHTDtq1oG2imyrv}mstxbeQzu*-d?!H}B=)8-Hzk zkarOKB#t~!fSse@PlC;RioDi&3eiV>7due5AMsunBigOGiJJCYo4MTUi-@Wm`j_voV_aI zyV#9~J}>1u^?shyvkkCn6FV#JQ(R*;Z|u!KRr{dLnUSyOSHr&5k*SEe%weoP`Z}N5 zBhM>f^Ta(2gVi;VxCj4W;~uno4-tP9Y`lH7_6VZR`0#lZY~8MWfBfBK`IfVq+ZcV^ zpYyKWSo`({;(HJN7TEV5x!(pGvxlzge*#fg6zgg`iFl44#JuJ@fmqjfrTs7F)|qyG zo#Uu`3hX|@S6=irCVbxo7w`H#xH`qpJ($P0s?9iO;(f$9*5g zna>HV-y!;6LE_w3!Rmv554KLc`yaqp5%qiXIsXxCEx*wH1XgFw(EXh2+(XRhFJR;K z*KU5#c8OKnKV(>k`2XYmdVhWsk+t}ZXPs2QT?ITj$DVZx;v7$7_5aGa>4>uyd~O?` z-^LfV@kMQXNzUz^d2d48L-cY6*nI?_ne+JloCViM{dvx7jyZ_>*+~4R-V8RkHhbkc z)J5G}!1f{P+zKw%y)EZa_jb5G>f=9Q9@sqEtYL4|MU8H-y5I}I?jz#w0CywmjklNT z!v9WiG5#*N_ZVlq8?29d2Hr2=f!3wZ5ZY|@rhiw%&Z2GN4BKI1w^;aWNe=S&j_^bn4zv#0bu0Co! z0FD~QYY*Fof=xf`$DKb2c7OWVA7@ux)ZPeIS3LVBxcczfd;^~?=+wvW#a6I!Tabv` z1~zx`T-)L5!{?zJ_&khGedOK&HctJ?{P$re*qYk9xK;1<5yT!jAKL%rcR-!LEB^t| Cz-KoA 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 zcmZXVYjYG;5Qc|j6A%!Dgo}!p0A4{r1w;@M5;Rd!13^H%Y&K+pfh7}nH;8zHvaIrx zRr-_sRerI`=b1gdnZiT8IsLxf)7|H`3=ZsHpJnT^joF6man>8#vH_GV+msEL^UQ_$ z3x_-1rNhULA2ni2HdqE4vo#wj?HYgYHS%T2Ch#m62iL%L@D=zPEPzGO1b4t)&;bv@ zApZuK|0eNJR^#7VPWe;tmHJ#^yxcl@g>Qw=w2H+>t3&6*^wt}z^~>$Xa_45zzK1$g z>h```pTE&)HBkn$Z7J5gyRldLzFN7Kyw8WT7xCxysiM8qY+q_D<*PI_L}u6fe|;!B zQtE3xSi^lO>eEH5XqRhokMcerF88ZQHF{CK8t!4#Skr6ez800eaF2^h&+d2RtM=>} zgnl(&>fVOC7SAQ>RP}GsZ?)=k&GwaMyW4yKC3-khcjzlRc{eYXQP-EcdtK`Ja(6y| zXe)i6=Z$Z=m9L!7JKe_ejb`8HEz`H!YW01dmFMqpAH6sC)4FHUo!EU+NOVc;Ib`T3?Cp;=$eIW%jkSt~Sc zwO)UNWxnXmGqRRrgdI^I=WD;w-ic)&V_+8gMwfc)n^o;M|_2dUiw#Hw9uSx;b>&*JBtzW(XB3{0jxbaKLj{TMU9wJ`udk8*;eHU1758tma`>lJt7t6O{?`ryl zb=u74&~IOIf1A|YyY0+f;4prb*?Z!-81FsyZCLjNd#kSo9On23#rJBgZ@~ZmVh`lI zE8IKg|4ZTb4jf7R4BxA72ELPXWF2MR0leqlWn*05PN4orI_q87ey4txuIxcAaz2Oc zU5}j4V?UX551M-9d;#0<)XnKS)S`!d*yF&QW6UoBYa9R(^K#N7=G7GAnMKTN*y@{E zy=!|NxYy?Md;PytL*F5w-**)8Z(v8fJsD%a?z28?yYEMVYpC}3X3`(0{BOh6d|Pw$ z<9#{~)O~A#$awM2;zJ*X9Uq8e7dAp`B0KKt+2$Y2N>c`vBW@IYOJkR;%Wl zOiE+nm*?~|le^L>iuemElEXV_}hd~->w=DV0Q^Tpm? z!kz-tz&&zL!Z(lYez<-xfX8QZnF7JIkX@O_SLpY~-R*45{4(G_4#bDP6h@43Gp z`n*5h*Dt|!pzm7Z;rj;eZ?-;v%jI$J8ra@DeGAO;@ZG@np6gp=mh1CP-UPli-^3{M zEwBxYfQY%B^xx9`&EbBhZq6pNTEw@o?}EsA5BtfS%V_G6v%vN{b#vZfRx`&c^L=2B zF0hV!`W;XY{s7zk{EKh&e-DgNH^%q)19%AH4*i%kroQ%5(!5u3wm)MVtM3@_E&fRz c&+HdqEo1EWD)S@I0ru;9; + 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 zcmYk1%MQU%5Qayql)6U3PAc||1tJkP7B<~^0Fl@@} z)vRPy3$1CN*ELU!S!5NLx9KiTZues{olS7G%y&jSZFQEFiSr@5Ak-9*q9Y%?7O3(y z)$F0BKer^D>H`X^) v<}cuv1?C1g^t!T6{pnzK!p(Id`yGLf2sx#ycP5vbT=qyDKR{T+>>+250X>{= z4|65lt6;>=+_{A9eHlBi*f}=nYTq7bsM~mpsEzMp+nlEkvGZ*5Ucz@V*W()dx7lwO zd<}2CT!+Z{Qx9`mm%8itbXPBH?Dv-QoRwHt_4OR_D(2b&dpGt~SBG8Rk(|A6;+;j# z-eT`f&it)9w%!@H@oG-_9b)H^cfZ(sl~aqgcQIGOyAl0*WB(qpbEwb#;(pDU-zTTu6P%-PI&2jYL6_yYS6q!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({ From c719091c3d7b5f71899530437fde9b512bc2b0f3 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 22:06:16 -0700 Subject: [PATCH 02/13] Add staging belt fix --- Cargo.toml | 12 ++++++++++++ wgpu/Cargo.toml | 4 ++-- wgpu/src/triangle.rs | 27 +++++++++++++-------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d894eba..19f25d9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,18 @@ readme = "README.md" keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] +[patch."https://github.com/gfx-rs/wgpu"] +wgpu-types = { git = "https://github.com/Dispersia/wgpu" } +wgpu-core = { git = "https://github.com/Dispersia/wgpu" } + +[patch."https://github.com/gfx-rs/wgpu-rs"] +wgpu = { git = "https://github.com/Dispersia/wgpu-rs" } + +[patch.crates-io] +wgpu-types = { git = "https://github.com/Dispersia/wgpu" } +wgpu-core = { git = "https://github.com/Dispersia/wgpu" } +wgpu = { git = "https://github.com/Dispersia/wgpu-rs" } + [features] default = ["wgpu", "default_system_font"] # Enables the `iced_wgpu` renderer diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 28927638..f44b3874 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 = {git = "https://github.com/gfx-rs/wgpu-rs", rev = "53600ecd834893ef3e90458c48b84f2582d6c343"} -wgpu_glyph = {git = "https://github.com/Dispersia/wgpu_glyph", branch = "update-wgpu"} +wgpu = {git="https://github.com/Dispersia/wgpu-rs"} +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/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, }); From 0722d5e3ec307fd82a1cc76593d17d83cf828943 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:07:58 -0700 Subject: [PATCH 03/13] 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(-) 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 +} From 983aa1b3665c6b546700767d21d73de72372ddad Mon Sep 17 00:00:00 2001 From: Dispersia Date: Mon, 12 Apr 2021 23:23:47 -0700 Subject: [PATCH 04/13] Run cargo fmt --- examples/pokedex/src/main.rs | 5 ++++- examples/styling/src/main.rs | 2 +- futures/src/subscription.rs | 3 ++- native/src/widget/pane_grid.rs | 9 ++++---- native/src/widget/text_input/cursor.rs | 4 ++-- native/src/widget/text_input/editor.rs | 4 ++-- src/window/icon.rs | 18 +++++++++------- wgpu/src/image.rs | 29 +++++++++++++------------- wgpu/src/shader/quad.wgsl | 2 +- wgpu/src/triangle/msaa.rs | 29 +++++++++++++------------- 10 files changed, 57 insertions(+), 48 deletions(-) diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index d2f1bb62..da1d5d5d 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -213,7 +213,10 @@ impl Pokemon { } async fn fetch_image(id: u16) -> Result { - let url = format!("https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", id); + let url = format!( + "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/{}.png", + id + ); #[cfg(not(target_arch = "wasm32"))] { diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 8975fd9a..4d7dfc48 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -44,7 +44,7 @@ impl Sandbox for Styling { match message { Message::ThemeChanged(theme) => self.theme = theme, Message::InputChanged(value) => self.input_value = value, - Message::ButtonPressed => (), + Message::ButtonPressed => {} Message::SliderChanged(value) => self.slider_value = value, Message::CheckboxToggled(value) => self.toggle_value = value, } diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 27d2d295..aa81f844 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -78,7 +78,8 @@ where .drain(..) .map(|recipe| { Box::new(With::new(recipe, value.clone())) - as Box> + as + Box> }) .collect(), } diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 44028f5e..3df7b156 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -209,10 +209,11 @@ where cursor_position: Point, messages: &mut Vec, ) { - let mut clicked_region = - self.elements.iter().zip(layout.children()).filter( - |(_, layout)| layout.bounds().contains(cursor_position), - ); + let mut clicked_region = self + .elements + .iter() + .zip(layout.children()) + .filter(|(_, layout)| layout.bounds().contains(cursor_position)); if let Some(((pane, content), layout)) = clicked_region.next() { if let Some(on_click) = &self.on_click { diff --git a/native/src/widget/text_input/cursor.rs b/native/src/widget/text_input/cursor.rs index 1e7aee83..4f3b159b 100644 --- a/native/src/widget/text_input/cursor.rs +++ b/native/src/widget/text_input/cursor.rs @@ -113,7 +113,7 @@ impl Cursor { State::Selection { start, end } if end > 0 => { self.select_range(start, end - 1) } - _ => (), + _ => {} } } @@ -125,7 +125,7 @@ impl Cursor { State::Selection { start, end } if end < value.len() => { self.select_range(start, end + 1) } - _ => (), + _ => {} } } diff --git a/native/src/widget/text_input/editor.rs b/native/src/widget/text_input/editor.rs index 20e42567..0b50a382 100644 --- a/native/src/widget/text_input/editor.rs +++ b/native/src/widget/text_input/editor.rs @@ -20,7 +20,7 @@ impl<'a> Editor<'a> { self.cursor.move_left(self.value); self.value.remove_many(left, right); } - _ => (), + _ => {} } self.value.insert(self.cursor.end(self.value), character); @@ -35,7 +35,7 @@ impl<'a> Editor<'a> { self.cursor.move_left(self.value); self.value.remove_many(left, right); } - _ => (), + _ => {} } self.value.insert_many(self.cursor.end(self.value), content); diff --git a/src/window/icon.rs b/src/window/icon.rs index 0d27b00e..287538b1 100644 --- a/src/window/icon.rs +++ b/src/window/icon.rs @@ -97,23 +97,25 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::InvalidData { byte_count } => { - write!(f, - "The provided RGBA data (with length {:?}) isn't divisble by \ + write!( + f, + "The provided RGBA data (with length {:?}) isn't divisble by \ 4. Therefore, it cannot be safely interpreted as 32bpp RGBA \ pixels.", - byte_count, - ) + byte_count, + ) } Error::DimensionsMismatch { width, height, pixel_count, } => { - write!(f, - "The number of RGBA pixels ({:?}) does not match the provided \ + write!( + f, + "The number of RGBA pixels ({:?}) does not match the provided \ dimensions ({:?}x{:?}).", - pixel_count, width, height, - ) + pixel_count, width, height, + ) } Error::OsError(e) => write!( f, 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, }); From 8b7452a55def8620f2c91df40d3882c449f85420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Wed, 19 May 2021 16:26:04 +0700 Subject: [PATCH 05/13] Fix formatting with `cargo fmt` --- futures/src/subscription.rs | 3 +-- native/src/widget/pane_grid.rs | 9 ++++----- wgpu/src/triangle.rs | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index aa81f844..27d2d295 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -78,8 +78,7 @@ where .drain(..) .map(|recipe| { Box::new(With::new(recipe, value.clone())) - as - Box> + as Box> }) .collect(), } diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 3df7b156..44028f5e 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -209,11 +209,10 @@ where cursor_position: Point, messages: &mut Vec, ) { - let mut clicked_region = self - .elements - .iter() - .zip(layout.children()) - .filter(|(_, layout)| layout.bounds().contains(cursor_position)); + let mut clicked_region = + self.elements.iter().zip(layout.children()).filter( + |(_, layout)| layout.bounds().contains(cursor_position), + ); if let Some(((pane, content), layout)) = clicked_region.next() { if let Some(on_click) = &self.on_click { 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) { From cf6af4c2560f5996bc533402ac3e4289c0c94702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Wed, 19 May 2021 17:11:51 +0700 Subject: [PATCH 06/13] Use latest `wgpu` releases instead of patched sources --- Cargo.toml | 12 ------------ wgpu/Cargo.toml | 4 ++-- wgpu/src/image.rs | 12 +++++++----- wgpu/src/quad.rs | 4 ++-- wgpu/src/triangle.rs | 36 ++++++++++++++++++++---------------- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19f25d9d..6d894eba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,18 +11,6 @@ readme = "README.md" keywords = ["gui", "ui", "graphics", "interface", "widgets"] categories = ["gui"] -[patch."https://github.com/gfx-rs/wgpu"] -wgpu-types = { git = "https://github.com/Dispersia/wgpu" } -wgpu-core = { git = "https://github.com/Dispersia/wgpu" } - -[patch."https://github.com/gfx-rs/wgpu-rs"] -wgpu = { git = "https://github.com/Dispersia/wgpu-rs" } - -[patch.crates-io] -wgpu-types = { git = "https://github.com/Dispersia/wgpu" } -wgpu-core = { git = "https://github.com/Dispersia/wgpu" } -wgpu = { git = "https://github.com/Dispersia/wgpu-rs" } - [features] default = ["wgpu", "default_system_font"] # Enables the `iced_wgpu` renderer diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index f44b3874..3eacdd0f 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 = {git="https://github.com/Dispersia/wgpu-rs"} -wgpu_glyph = {git="https://github.com/Dispersia/wgpu_glyph", branch = "update-wgpu"} +wgpu = "0.8" +wgpu_glyph = "0.12" 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 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, + ), + }, + ), }], }); } From d91422e345d30f0d33d737a3be8ad1c90f5d14b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 08:09:03 -0700 Subject: [PATCH 07/13] temporary up --- wgpu/src/quad.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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(), }], }); From b40c44164646e853239d1b76fd8e4768eb21d9ac Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 21:04:47 -0700 Subject: [PATCH 08/13] Add padding to quad to fix alignment issue --- wgpu/src/quad.rs | 5 +++++ 1 file changed, 5 insertions(+) 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] } } } From 2d549d806cd9ff1d7b7b237d818cd24c84957c83 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 21:09:19 -0700 Subject: [PATCH 09/13] Remove padding from triangle --- wgpu/src/triangle.rs | 8 -------- 1 file changed, 8 deletions(-) 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], } } } From a70715ad9e41bf133e8e37d43633ffa84ae211b9 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Wed, 19 May 2021 22:07:27 -0700 Subject: [PATCH 10/13] run format --- wgpu/src/quad.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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], } } } From 0772310c4f6ab1ff4b9771011c04b6ece0b84df3 Mon Sep 17 00:00:00 2001 From: Dispersia Date: Thu, 20 May 2021 23:10:22 -0700 Subject: [PATCH 11/13] Fix duplicating fragment position --- wgpu/src/shader/quad.wgsl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 From ebec84ea7c54fffb5bc9645326782d84a30a8197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Fri, 21 May 2021 20:29:17 +0700 Subject: [PATCH 12/13] Revert "Remove padding from triangle" This reverts commit 2d549d806cd9ff1d7b7b237d818cd24c84957c83. --- wgpu/src/triangle.rs | 8 ++++++++ 1 file changed, 8 insertions(+) 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], } } } From 4cbc34524598756ce18cb25a664bc6f256d42851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n?= Date: Fri, 21 May 2021 20:34:08 +0700 Subject: [PATCH 13/13] Use `FilterMode::Nearest` in `triangle::msaa` --- wgpu/src/triangle/msaa.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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() });