From 86f2664fcae24068da6182be1a3f53c484bb8be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Kocsis?= Date: Mon, 23 Aug 2021 17:49:20 +0200 Subject: [PATCH] fixed mip level count check for storage textures --- wgpu-core/src/binding_model.rs | 2 ++ wgpu-core/src/device/mod.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index b329629d4..63ac7e5d4 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -136,6 +136,8 @@ pub enum CreateBindGroupError { layout_format: wgt::TextureFormat, view_format: wgt::TextureFormat, }, + #[error("storage texture bindings must have a single mip level, but given a view with mip_level_count = {mip_level_count:?} at binding {binding}")] + InvalidStorageTextureMipLevelCount { binding: u32, mip_level_count: u32 }, #[error("sampler binding {binding} expects comparison = {layout_cmp}, but given a sampler with comparison = {sampler_cmp}")] WrongSamplerComparison { binding: u32, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index ac8ef0e1f..414bc973f 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -773,7 +773,7 @@ impl Device { } _ => hal::TextureUses::all(), }; - let mask_mip_level = if end_layer != desc.range.base_array_layer + 1 { + let mask_mip_level = if selector.levels.end - selector.levels.start != 1 { hal::TextureUses::RESOURCE } else { hal::TextureUses::all() @@ -1657,6 +1657,15 @@ impl Device { view_dimension: view.desc.dimension, }); } + + let mip_level_count = view.selector.levels.end - view.selector.levels.start; + if mip_level_count != 1 { + return Err(Error::InvalidStorageTextureMipLevelCount { + binding, + mip_level_count, + }); + } + let internal_use = match access { wgt::StorageTextureAccess::WriteOnly => hal::TextureUses::STORAGE_WRITE, wgt::StorageTextureAccess::ReadOnly => {