diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 0f7e5551be..469e28ec36 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -56,7 +56,7 @@ log = "0.4" png = "0.16" winit = { version = "0.22.1", features = ["web-sys"] } rand = { version = "0.7.2", features = ["wasm-bindgen"] } -bytemuck = "1" +bytemuck = { version = "1.4", features = ["derive"] } noise = "0.6" ddsfile = "0.4" futures = { version = "0.3", default-features = false, features = ["std", "executor"] } diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index 0c603c78f9..ffcb19caff 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -5,15 +5,12 @@ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct Vertex { _pos: [f32; 4], _tex_coord: [f32; 2], } -unsafe impl Pod for Vertex {} -unsafe impl Zeroable for Vertex {} - fn vertex(pos: [i8; 3], tc: [i8; 2]) -> Vertex { Vertex { _pos: [pos[0] as f32, pos[1] as f32, pos[2] as f32, 1.0], diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index 3fe0ea9bc2..39fd568b0b 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -8,15 +8,12 @@ use wgpu::util::DeviceExt; const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct Vertex { #[allow(dead_code)] pos: [f32; 4], } -unsafe impl Pod for Vertex {} -unsafe impl Zeroable for Vertex {} - fn create_vertices() -> Vec { vec![ Vertex { diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 331b2ee227..6b0bfde5c9 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -16,15 +16,12 @@ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct Vertex { _pos: [f32; 2], _color: [f32; 4], } -unsafe impl Pod for Vertex {} -unsafe impl Zeroable for Vertex {} - struct Example { bundle: wgpu::RenderBundle, vs_module: wgpu::ShaderModule, diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index c0e8dabb6c..11fe586bfe 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -7,16 +7,12 @@ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt; #[repr(C)] -#[derive(Clone, Copy)] - +#[derive(Clone, Copy, Pod, Zeroable)] struct Vertex { _pos: [i8; 4], _normal: [i8; 4], } -unsafe impl Pod for Vertex {} -unsafe impl Zeroable for Vertex {} - fn vertex(pos: [i8; 3], nor: [i8; 3]) -> Vertex { Vertex { _pos: [pos[0], pos[1], pos[2], 1], @@ -102,16 +98,13 @@ struct Light { } #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct LightRaw { proj: [[f32; 4]; 4], pos: [f32; 4], color: [f32; 4], } -unsafe impl Pod for LightRaw {} -unsafe impl Zeroable for LightRaw {} - impl Light { fn to_raw(&self) -> LightRaw { use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3}; @@ -140,25 +133,19 @@ impl Light { } #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct ForwardUniforms { proj: [[f32; 4]; 4], num_lights: [u32; 4], } -unsafe impl Pod for ForwardUniforms {} -unsafe impl Zeroable for ForwardUniforms {} - #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct EntityUniforms { model: [[f32; 4]; 4], color: [f32; 4], } -unsafe impl Pod for EntityUniforms {} -unsafe impl Zeroable for EntityUniforms {} - #[repr(C)] struct ShadowUniforms { proj: [[f32; 4]; 4], diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index b0178dc4bc..788ea30d53 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -6,25 +6,19 @@ use bytemuck::{Pod, Zeroable}; use wgpu::util::DeviceExt; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct Vertex { _pos: [f32; 2], _tex_coord: [f32; 2], _index: u32, } -unsafe impl Pod for Vertex {} -unsafe impl Zeroable for Vertex {} - #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Pod, Zeroable)] struct Uniform { index: u32, } -unsafe impl Pod for Uniform {} -unsafe impl Zeroable for Uniform {} - fn vertex(pos: [i8; 2], tc: [i8; 2], index: i8) -> Vertex { Vertex { _pos: [pos[0] as f32, pos[1] as f32], diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index 8b57f050ae..0b82e11b22 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -6,6 +6,7 @@ mod point_gen; use cgmath::Point3; use std::{iter, mem}; use wgpu::util::DeviceExt; +use bytemuck::{Pod, Zeroable}; /// /// Radius of the terrain. @@ -34,17 +35,14 @@ struct Matrices { } #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] struct TerrainUniforms { view_projection: [f32; 16], clipping_plane: [f32; 4], } -unsafe impl bytemuck::Zeroable for TerrainUniforms {} -unsafe impl bytemuck::Pod for TerrainUniforms {} - #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] struct WaterUniforms { view: [f32; 16], projection: [f32; 16], @@ -58,9 +56,6 @@ struct Uniforms { water: WaterUniforms, } -unsafe impl bytemuck::Zeroable for WaterUniforms {} -unsafe impl bytemuck::Pod for WaterUniforms {} - struct Example { water_vertex_buf: wgpu::Buffer, water_vertex_count: usize, diff --git a/wgpu/examples/water/point_gen.rs b/wgpu/examples/water/point_gen.rs index 7b380175e0..54d74d2450 100644 --- a/wgpu/examples/water/point_gen.rs +++ b/wgpu/examples/water/point_gen.rs @@ -3,6 +3,7 @@ //! use cgmath::{InnerSpace, Point3, Vector3}; +use bytemuck::{Pod, Zeroable}; use std::collections::HashMap; // The following constants are used in calculations. @@ -32,28 +33,20 @@ const C45: f32 = S45; const SQRT_3: f32 = 1.73205080757; #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] pub struct TerrainVertexAttributes { position: [f32; 3], normal: [f32; 3], colour: [u8; 4], } -unsafe impl bytemuck::Pod for TerrainVertexAttributes {} - -unsafe impl bytemuck::Zeroable for TerrainVertexAttributes {} - #[repr(C)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] pub struct WaterVertexAttributes { position: [i16; 2], offsets: [i8; 4], } -unsafe impl bytemuck::Pod for WaterVertexAttributes {} - -unsafe impl bytemuck::Zeroable for WaterVertexAttributes {} - /// /// Represents the center of a single hexagon. ///