From 0f48b098fdbb527bf723f701722dfe7563b647af Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Thu, 23 Mar 2023 19:52:49 +0100 Subject: [PATCH] Fix web crash on missing uniform buffer padding The alignment is actually already there, but wgpu/Naga doesn't see it at this point. --- crates/re_renderer/shader/lines.wgsl | 4 ++++ crates/re_renderer/shader/point_cloud.wgsl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/crates/re_renderer/shader/lines.wgsl b/crates/re_renderer/shader/lines.wgsl index e214d302f558..6b0a58fc2c72 100644 --- a/crates/re_renderer/shader/lines.wgsl +++ b/crates/re_renderer/shader/lines.wgsl @@ -13,6 +13,10 @@ var position_data_texture: texture_2d; struct DrawDataUniformBuffer { size_boost_in_points: f32, + // In actuality there is way more padding than this since we size all uniform buffers are 256bytes aligned in order to be sub-allocatable. + // But wgpu doesn't know this and therefore requires `DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED` if we wouldn't add padding here, + // which isn't available on WebGL. + _padding: Vec4, }; @group(1) @binding(2) var draw_data: DrawDataUniformBuffer; diff --git a/crates/re_renderer/shader/point_cloud.wgsl b/crates/re_renderer/shader/point_cloud.wgsl index 86b12cfd2214..87de2921757a 100644 --- a/crates/re_renderer/shader/point_cloud.wgsl +++ b/crates/re_renderer/shader/point_cloud.wgsl @@ -12,6 +12,10 @@ var color_texture: texture_2d; struct DrawDataUniformBuffer { size_boost_in_points: f32, + // In actuality there is way more padding than this since we size all uniform buffers are 256bytes aligned in order to be sub-allocatable. + // But wgpu doesn't know this and therefore requires `DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED` if we wouldn't add padding here, + // which isn't available on WebGL. + _padding: Vec4, }; @group(1) @binding(2) var draw_data: DrawDataUniformBuffer;