From f2c3d428181dad61f48661b92e262c2ec3c2f93d Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Wed, 15 Jun 2022 16:43:02 +0800 Subject: [PATCH] Add InvalidGroupIndex validation at create_shader_module --- wgpu-core/src/device/mod.rs | 12 ++++++++++++ wgpu-core/src/pipeline.rs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 7021cc462e..55c9697151 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1189,6 +1189,18 @@ impl Device { } pipeline::ShaderModuleSource::Naga(module) => (module, String::new()), }; + for (_, var) in module.global_variables.iter() { + match var.binding { + Some(ref br) if br.group >= self.limits.max_bind_groups => { + return Err(pipeline::CreateShaderModuleError::InvalidGroupIndex { + bind: br.clone(), + group: br.group, + limit: self.limits.max_bind_groups, + }); + } + _ => continue, + }; + } use naga::valid::Capabilities as Caps; profiling::scope!("naga::validate"); diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 9996f7840f..199f4ef973 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -124,6 +124,14 @@ pub enum CreateShaderModuleError { Validation(#[from] ShaderError>), #[error(transparent)] MissingFeatures(#[from] MissingFeatures), + #[error( + "shader global {bind:?} uses a group index {group} that exceeds the max_bind_groups limit of {limit}." + )] + InvalidGroupIndex { + bind: naga::ResourceBinding, + group: u32, + limit: u32, + }, } impl CreateShaderModuleError {