From 07f744108eddb5cc680dca0db6769f75b42befad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Thulliez?= <43185161+grzi@users.noreply.github.com> Date: Thu, 3 Jun 2021 23:26:44 +0200 Subject: [PATCH] tech: Upgrade winit, wgpu, bytemuck and serde (#112) FIXES #96 FIXES #95 FIXES #94 --- Cargo.toml | 10 +++--- src/config/window_config.rs | 1 + .../bidimensional/gl_representations.rs | 8 ++--- src/rendering/bidimensional/scion2d.rs | 28 +++++++--------- src/rendering/renderer_state.rs | 2 +- src/rendering/shaders/pipeline.rs | 32 +++++++++++-------- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7d059f..3204251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,17 +16,17 @@ parallel = ["legion/parallel"] legion = { version = "0.4", default-features = false, features = ["codegen"] } # window & rendering -winit = "0.24.0" -wgpu = "0.7.0" +winit = "0.25" +wgpu = "0.8" futures = "0.3" # maths ultraviolet = "0.8" # serialization -serde = { version = "1.0.124", features = ["derive"] } +serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" -bytemuck = { version = "1.4", features = ["derive"] } +bytemuck = { version = "1.5", features = ["derive"] } image = { version = "0.23", default-features = false, features = ["png"] } # logging @@ -45,7 +45,7 @@ deflate = { opt-level = 3 } [build-dependencies] anyhow = "1.0" -fs_extra = "1.1" +fs_extra = "1.2" glob = "0.3" shaderc = "0.7" diff --git a/src/config/window_config.rs b/src/config/window_config.rs index e792e75..0cac679 100644 --- a/src/config/window_config.rs +++ b/src/config/window_config.rs @@ -98,6 +98,7 @@ impl Into for WindowConfig { maximized: self.maximized, resizable: self.resizable, transparent: self.transparent, + position: None }; builder } diff --git a/src/rendering/bidimensional/gl_representations.rs b/src/rendering/bidimensional/gl_representations.rs index 7608672..4683377 100644 --- a/src/rendering/bidimensional/gl_representations.rs +++ b/src/rendering/bidimensional/gl_representations.rs @@ -75,12 +75,12 @@ impl ColoredGlVertex { wgpu::VertexAttribute { offset: 0, shader_location: 0, - format: wgpu::VertexFormat::Float3, + format: wgpu::VertexFormat::Float32x3, }, wgpu::VertexAttribute { offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress, shader_location: 1, - format: wgpu::VertexFormat::Float3, + format: wgpu::VertexFormat::Float32x3, }, ], } @@ -104,12 +104,12 @@ impl TexturedGlVertex { wgpu::VertexAttribute { offset: 0, shader_location: 0, - format: wgpu::VertexFormat::Float3, + format: wgpu::VertexFormat::Float32x3, }, wgpu::VertexAttribute { offset: mem::size_of::<[f32; 3]>() as wgpu::BufferAddress, shader_location: 1, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, }, ], } diff --git a/src/rendering/bidimensional/scion2d.rs b/src/rendering/bidimensional/scion2d.rs index aa6bff7..03da725 100644 --- a/src/rendering/bidimensional/scion2d.rs +++ b/src/rendering/bidimensional/scion2d.rs @@ -1,11 +1,7 @@ use std::{collections::HashMap, ops::Range, path::Path}; use legion::{storage::Component, Entity, IntoQuery, Resources, World}; -use wgpu::{ - util::{BufferInitDescriptor, DeviceExt}, - BindGroup, BindGroupLayout, Buffer, CommandEncoder, Device, Queue, - RenderPassColorAttachmentDescriptor, RenderPipeline, SwapChainDescriptor, SwapChainTexture, -}; +use wgpu::{util::{BufferInitDescriptor, DeviceExt}, BindGroup, BindGroupLayout, Buffer, CommandEncoder, Device, Queue, RenderPipeline, SwapChainDescriptor, SwapChainTexture, RenderPassColorAttachment}; use crate::{ core::components::{ @@ -114,7 +110,7 @@ fn load_texture_to_queue( let texture_size = wgpu::Extent3d { width: texture.width as u32, height: texture.height as u32, - depth: 1, + depth_or_array_layers: 1 }; let diffuse_texture = device.create_texture(&wgpu::TextureDescriptor { @@ -127,16 +123,16 @@ fn load_texture_to_queue( label: Some("diffuse_texture"), }); queue.write_texture( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &diffuse_texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, }, &*texture.bytes, - wgpu::TextureDataLayout { + wgpu::ImageDataLayout { offset: 0, - bytes_per_row: (4 * texture.width) as u32, - rows_per_image: texture.height as u32, + bytes_per_row: std::num::NonZeroU32::new((4 * texture.width) as u32), + rows_per_image: std::num::NonZeroU32::new((texture.height as u32)), }, texture_size, ); @@ -242,9 +238,9 @@ fn create_transform_uniform_bind_group( ) } -fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachmentDescriptor { - wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, +fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachment { + RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -258,9 +254,9 @@ fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAtta } } -fn get_no_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachmentDescriptor { - wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, +fn get_no_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAttachment { + RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, diff --git a/src/rendering/renderer_state.rs b/src/rendering/renderer_state.rs index eede314..d50e586 100644 --- a/src/rendering/renderer_state.rs +++ b/src/rendering/renderer_state.rs @@ -40,7 +40,7 @@ impl RendererState { let sc_desc = wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::RENDER_ATTACHMENT, - format: adapter.get_swap_chain_preferred_format(&surface), + format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), width: size.width, height: size.height, present_mode: wgpu::PresentMode::Fifo, diff --git a/src/rendering/shaders/pipeline.rs b/src/rendering/shaders/pipeline.rs index a49f199..59542fe 100644 --- a/src/rendering/shaders/pipeline.rs +++ b/src/rendering/shaders/pipeline.rs @@ -1,6 +1,4 @@ -use wgpu::{ - BindGroupLayout, BlendFactor, BlendOperation, Device, RenderPipeline, SwapChainDescriptor, -}; +use wgpu::{BindGroupLayout, BlendFactor, BlendOperation, Device, RenderPipeline, SwapChainDescriptor, BlendComponent}; use crate::rendering::bidimensional::gl_representations::TexturedGlVertex; @@ -32,25 +30,31 @@ pub fn pipeline( entry_point: "main", targets: &[wgpu::ColorTargetState { format: sc_desc.format, - alpha_blend: wgpu::BlendState { - src_factor: BlendFactor::One, - dst_factor: BlendFactor::One, - operation: BlendOperation::Add, - }, - color_blend: wgpu::BlendState { - src_factor: BlendFactor::SrcAlpha, - dst_factor: BlendFactor::OneMinusSrcAlpha, - operation: BlendOperation::Add, - }, write_mask: wgpu::ColorWrite::ALL, + blend: Some( + wgpu::BlendState { + color: BlendComponent { + src_factor: BlendFactor::SrcAlpha, + dst_factor: BlendFactor::OneMinusSrcAlpha, + operation: BlendOperation::Add, + }, + alpha: BlendComponent { + src_factor: BlendFactor::One, + dst_factor: BlendFactor::One, + operation: BlendOperation::Add, + }, + } + ), }], }), primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: wgpu::CullMode::Back, + cull_mode: Some(wgpu::Face::Back), + clamp_depth: false, polygon_mode: wgpu::PolygonMode::Fill, + conservative: false, }, depth_stencil: None, multisample: wgpu::MultisampleState {