Skip to content

Commit

Permalink
Merge pull request #51 from hecrj/use-bytemuck
Browse files Browse the repository at this point in the history
Replace `zerocopy` with `bytemuck`
  • Loading branch information
hecrj authored Feb 3, 2021
2 parents 830215f + 6d5a95a commit ce34776
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Depth> {
transform: wgpu::Buffer,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<Depth> Pipeline<Depth> {
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(
Expand Down Expand Up @@ -200,7 +200,7 @@ fn build<D>(
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,
});

Expand Down Expand Up @@ -388,7 +388,7 @@ fn draw<D>(
device,
);

transform_view.copy_from_slice(transform.as_bytes());
transform_view.copy_from_slice(bytemuck::cast_slice(&transform));

pipeline.current_transform = transform;
}
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit ce34776

Please sign in to comment.