From b01657b455c080d3d095b3bb97da62fbdc3d51c9 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 30 Apr 2023 12:52:41 -0700 Subject: [PATCH] Add padding to fix alignment --- cubeway/src/compute.wgsl | 4 ++-- cubeway/src/lib.rs | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/cubeway/src/compute.wgsl b/cubeway/src/compute.wgsl index 6933bcd..3432357 100644 --- a/cubeway/src/compute.wgsl +++ b/cubeway/src/compute.wgsl @@ -4,6 +4,7 @@ struct SimParams { struct Instance { position: vec3, + unused: f32, rotation: vec4, } @@ -17,9 +18,8 @@ struct Instances { fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3) { var index = GlobalInvocationID.x; - instanceBuffer[index * 7u].position.y -= 0.001; if index < 100u { - let bufferIndex = u32(f32(index) * 7.0); + instanceBuffer[index].position.y -= 0.001; } } diff --git a/cubeway/src/lib.rs b/cubeway/src/lib.rs index b5257ae..6d3fc2c 100644 --- a/cubeway/src/lib.rs +++ b/cubeway/src/lib.rs @@ -57,6 +57,7 @@ impl Vertex { #[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] struct Instance { position: [f32; 3], + _pad: f32, rotation: [f32; 4], } @@ -75,7 +76,7 @@ impl Instance { format: wgpu::VertexFormat::Float32x3, }, wgpu::VertexAttribute { - offset: mem::size_of::<[f32; 3]>() as wgpu::BufferAddress, + offset: 16 as wgpu::BufferAddress, shader_location: 3, format: wgpu::VertexFormat::Float32x4, }, @@ -195,20 +196,12 @@ impl State { z: z as f32, } - INSTANCE_DISPLACEMENT; - let rotation = if position.is_zero() { - // this is needed so an object at (0, 0, 0) won't get scaled to zero - // as Quaternions can effect scale if they're not created correctly - cgmath::Quaternion::from_axis_angle( - cgmath::Vector3::unit_z(), - cgmath::Deg(0.0), - ) - } else { - cgmath::Quaternion::from_axis_angle(position.normalize(), cgmath::Deg(45.0)) - }; + // let rotation = cgmath::Quaternion::zero(); Instance { position: position.into(), - rotation: rotation.into(), + _pad: 0.0, + rotation: [1., 0., 0., 0.], } }) })