Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 3609e52

Browse files
committed
Fix generic bounds on buffer mapping
1 parent 95787f1 commit 3609e52

File tree

7 files changed

+74
-60
lines changed

7 files changed

+74
-60
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ version = "0.4"
2828
git = "https://github.com/gfx-rs/wgpu"
2929
rev = "73b33ea76e2f91b3114aa7640b1d60518d39f915"
3030

31-
[dependencies.core]
31+
[dependencies.wgc]
3232
package = "wgpu-core"
3333
version = "0.1"
3434
git = "https://github.com/gfx-rs/wgpu"

examples/cube/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#[path = "../framework.rs"]
22
mod framework;
33

4-
#[derive(Clone, Copy)]
4+
#[repr(C)]
5+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
56
struct Vertex {
67
_pos: [f32; 4],
78
_tex_coord: [f32; 2],

examples/mipmap/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ mod framework;
33

44
const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
55

6-
#[derive(Clone, Copy)]
6+
#[repr(C)]
7+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
78
struct Vertex {
89
#[allow(dead_code)]
910
pos: [f32; 4],

examples/msaa-line/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#[path = "../framework.rs"]
1111
mod framework;
1212

13-
#[derive(Clone, Copy)]
13+
#[repr(C)]
14+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
1415
struct Vertex {
1516
_pos: [f32; 2],
1617
_color: [f32; 4],

examples/shadow/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::{mem, ops::Range, rc::Rc};
33
#[path = "../framework.rs"]
44
mod framework;
55

6-
#[derive(Clone, Copy)]
6+
#[repr(C)]
7+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
8+
79
struct Vertex {
810
_pos: [i8; 4],
911
_normal: [i8; 4],
@@ -95,7 +97,7 @@ struct Light {
9597
}
9698

9799
#[repr(C)]
98-
#[derive(Clone, Copy)]
100+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
99101
struct LightRaw {
100102
proj: [[f32; 4]; 4],
101103
pos: [f32; 4],
@@ -124,16 +126,16 @@ impl Light {
124126
}
125127

126128
#[repr(C)]
127-
#[derive(Clone, Copy)]
129+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
128130
struct ForwardUniforms {
129131
proj: [[f32; 4]; 4],
130132
num_lights: [u32; 4],
131133
}
132134

133135
#[repr(C)]
134-
#[derive(Clone, Copy)]
136+
#[derive(Clone, Copy, zerocopy::AsBytes, zerocopy::FromBytes)]
135137
struct EntityUniforms {
136-
model: cgmath::Matrix4<f32>,
138+
model: [[f32; 4]; 4],
137139
color: [f32; 4],
138140
}
139141

@@ -700,7 +702,7 @@ impl framework::Example for Example {
700702
entity.mx_world = entity.mx_world * rotation;
701703
}
702704
temp_buf_data.data[i] = EntityUniforms {
703-
model: entity.mx_world.clone(),
705+
model: entity.mx_world.into(),
704706
color: [
705707
entity.color.r as f32,
706708
entity.color.g as f32,

examples/skybox/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ impl framework::Example for Skybox {
7272
let aspect = sc_desc.width as f32 / sc_desc.height as f32;
7373
let uniforms = Self::generate_uniforms(aspect);
7474
let uniform_buf = device
75-
.create_buffer_mapped(
75+
.create_buffer_mapped::<[[f32; 4]; 4]>(
7676
uniforms.len(),
7777
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
7878
)
79-
.fill_from_slice(&uniforms);
79+
.fill_from_slice(&[
80+
uniforms[0].into(),
81+
uniforms[1].into(),
82+
]);
8083
let uniform_buf_size = std::mem::size_of::<Uniforms>();
8184

8285
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
@@ -276,8 +279,14 @@ impl framework::Example for Skybox {
276279
self.uniforms[1] = self.uniforms[1] * rotation;
277280
let uniform_buf_size = std::mem::size_of::<Uniforms>();
278281
let temp_buf = device
279-
.create_buffer_mapped(2, wgpu::BufferUsage::COPY_SRC)
280-
.fill_from_slice(&self.uniforms);
282+
.create_buffer_mapped::<[[f32; 4]; 4]>(
283+
self.uniforms.len(),
284+
wgpu::BufferUsage::COPY_SRC,
285+
)
286+
.fill_from_slice(&[
287+
self.uniforms[0].into(),
288+
self.uniforms[1].into(),
289+
]);
281290

282291
init_encoder.copy_buffer_to_buffer(
283292
&temp_buf,

0 commit comments

Comments
 (0)