From c8d0b553c5f9635d3de628ab466fa55175b623b5 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 | 5 +++++ crates/re_renderer/shader/point_cloud.wgsl | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/crates/re_renderer/shader/lines.wgsl b/crates/re_renderer/shader/lines.wgsl index e214d302f558..afe22189f9c4 100644 --- a/crates/re_renderer/shader/lines.wgsl +++ b/crates/re_renderer/shader/lines.wgsl @@ -13,6 +13,11 @@ var position_data_texture: texture_2d; struct DrawDataUniformBuffer { size_boost_in_points: f32, + // In actuality there is way more padding than this since we align all our uniform buffers to + // 256bytes in order to allow them to be buffer-suballocations. + // However, wgpu doesn't know this at this point 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..6984ce45d6b6 100644 --- a/crates/re_renderer/shader/point_cloud.wgsl +++ b/crates/re_renderer/shader/point_cloud.wgsl @@ -12,6 +12,11 @@ var color_texture: texture_2d; struct DrawDataUniformBuffer { size_boost_in_points: f32, + // In actuality there is way more padding than this since we align all our uniform buffers to + // 256bytes in order to allow them to be buffer-suballocations. + // However, wgpu doesn't know this at this point 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;