diff --git a/crates/bevy_pbr/src/render/mesh_view_types.wgsl b/crates/bevy_pbr/src/render/mesh_view_types.wgsl index 7db9af72f64816..ab595b9e01f9ca 100644 --- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl @@ -95,4 +95,8 @@ struct Globals { // Frame count since the start of the app. // It wraps to zero when it reaches the maximum value of a u32. frame_count: u32, +#ifdef SIXTEEN_BYTE_ALIGNMENT + // WebGL2 structs must be 16 byte aligned. + _wasm_padding: f32 +#endif } diff --git a/crates/bevy_render/src/globals.rs b/crates/bevy_render/src/globals.rs index c910e13768d851..eea40342e10464 100644 --- a/crates/bevy_render/src/globals.rs +++ b/crates/bevy_render/src/globals.rs @@ -41,6 +41,9 @@ pub struct GlobalsUniform { /// Frame count since the start of the app. /// It wraps to zero when it reaches the maximum value of a u32. frame_count: u32, + /// WebGL2 structs must be 16 byte aligned. + #[cfg(feature = "webgl")] + _wasm_padding: f32, } /// The buffer containing the [`GlobalsUniform`] diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 48603edefe7a24..e03857e788a8e0 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -151,7 +151,10 @@ impl ShaderCache { Entry::Vacant(entry) => { let mut shader_defs = shader_defs.to_vec(); #[cfg(feature = "webgl")] - shader_defs.push(String::from("NO_ARRAY_TEXTURES_SUPPORT")); + { + shader_defs.push(String::from("NO_ARRAY_TEXTURES_SUPPORT")); + shader_defs.push(String::from("SIXTEEN_BYTE_ALIGNMENT")); + } // TODO: 3 is the value from CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT declared in bevy_pbr // consider exposing this in shaders in a more generally useful way, such as: