From 28c659f7db6ebfda6083921eee191e2204931d3b Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Sat, 25 Jun 2022 00:19:11 -0400 Subject: [PATCH] Force binding sizes to be multiples of 16 on webgl --- wgpu-core/src/device/mod.rs | 8 ++++++++ wgpu-hal/src/gles/adapter.rs | 4 ++++ wgpu-types/src/lib.rs | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index aa8b0991a9b..77cc584595c 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2807,6 +2807,14 @@ impl Device { self.require_features(wgt::Features::MULTIVIEW)?; } + for (_, size) in &shader_binding_sizes { + if size.get() % 16 != 0 { + self.require_downlevel_flags( + wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED, + )?; + } + } + let late_sized_buffer_groups = Device::make_late_sized_buffer_groups(&shader_binding_sizes, layout, &*bgl_guard); diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 3bd7bae5e26..ba91e0e4042 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -289,6 +289,10 @@ impl super::Adapter { wgt::DownlevelFlags::ANISOTROPIC_FILTERING, extensions.contains("EXT_texture_filter_anisotropic"), ); + downlevel_flags.set( + wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED, + !cfg!(target_arch = "wasm32"), + ); let is_ext_color_buffer_float_supported = extensions.contains("EXT_color_buffer_float"); diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 1737c9517cb..e846c684d22 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1039,6 +1039,11 @@ bitflags::bitflags! { /// Supports all the texture usages described in WebGPU. If this isn't supported, you /// should call `get_texture_format_features` to get how you can use textures of a given format const WEBGPU_TEXTURE_FORMAT_SUPPORT = 1 << 14; + + /// Supports buffer bindings with sizes that aren't a multiple of 16. + /// + /// WebGL doesn't support this. + const BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED = 1 << 15; } }