From 9c98502e10f7393bcc4164dbdb7e180a5a3f914f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 19 Apr 2020 21:55:33 +0200 Subject: [PATCH] Fix alignment in triangle pipeline of `iced_wgpu` --- wgpu/src/triangle.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 51a6f954..83d84bc4 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -224,11 +224,9 @@ impl Pipeline { // We upload everything upfront for (origin, mesh) in meshes { - let transform = Uniforms { - transform: (transformation - * Transformation::translate(origin.x, origin.y)) - .into(), - }; + let transform = (transformation + * Transformation::translate(origin.x, origin.y)) + .into(); let vertex_buffer = device .create_buffer_mapped( @@ -357,12 +355,28 @@ impl Pipeline { #[derive(Debug, Clone, Copy)] struct Uniforms { transform: [f32; 16], + // We need to align this to 256 bytes to please `wgpu`... + // TODO: Be smarter and stop wasting memory! + _padding_a: [f32; 32], + _padding_b: [f32; 16], } impl Default for Uniforms { fn default() -> Self { Self { transform: *Transformation::identity().as_ref(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], + } + } +} + +impl From for Uniforms { + fn from(transformation: Transformation) -> Uniforms { + Self { + transform: transformation.into(), + _padding_a: [0.0; 32], + _padding_b: [0.0; 16], } } }