diff --git a/CHANGELOG.md b/CHANGELOG.md index e0eb3aa..ebeb1b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed - Updated `wgpu` to `0.7`. [#50] +- Replaced `zerocopy` with `bytemuck`. [#51] [#50]: https://github.com/hecrj/wgpu_glyph/pull/50 +[#51]: https://github.com/hecrj/wgpu_glyph/pull/51 ## [0.10.0] - 2020-08-27 diff --git a/Cargo.toml b/Cargo.toml index da863e1..58633ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,10 @@ readme = "README.md" wgpu = "0.7" glyph_brush = "0.7" log = "0.4" -zerocopy = "0.3" + +[dependencies.bytemuck] +version = "1.4" +features = ["derive"] [dev-dependencies] env_logger = "0.7" diff --git a/src/pipeline.rs b/src/pipeline.rs index e540f20..0401a53 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -3,11 +3,11 @@ mod cache; use crate::Region; use cache::Cache; +use bytemuck::{Pod, Zeroable}; use core::num::NonZeroU64; use glyph_brush::ab_glyph::{point, Rect}; use std::marker::PhantomData; use std::mem; -use zerocopy::AsBytes; pub struct Pipeline { transform: wgpu::Buffer, @@ -160,7 +160,7 @@ impl Pipeline { self.supported_instances = instances.len(); } - let instances_bytes = instances.as_bytes(); + let instances_bytes = bytemuck::cast_slice(instances); if let Some(size) = NonZeroU64::new(instances_bytes.len() as u64) { let mut instances_view = staging_belt.write_buffer( @@ -200,7 +200,7 @@ fn build( let transform = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: None, - contents: IDENTITY_MATRIX.as_bytes(), + contents: bytemuck::cast_slice(&IDENTITY_MATRIX), usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, }); @@ -388,7 +388,7 @@ fn draw( device, ); - transform_view.copy_from_slice(transform.as_bytes()); + transform_view.copy_from_slice(bytemuck::cast_slice(&transform)); pipeline.current_transform = transform; } @@ -455,7 +455,7 @@ fn create_uniforms( } #[repr(C)] -#[derive(Debug, Clone, Copy, AsBytes)] +#[derive(Debug, Clone, Copy, Zeroable, Pod)] pub struct Instance { left_top: [f32; 3], right_bottom: [f32; 2],