diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 6a823010d..33accfd86 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1107,22 +1107,19 @@ impl Global { let (format, view_kind, range) = match desc { Some(desc) => { let kind = conv::map_texture_view_dimension(desc.dimension); - let required_level_count = desc.base_mip_level + desc.level_count.unwrap_or(1); + let required_level_count = + desc.base_mip_level + desc.level_count.map_or(1, |count| count.get()); let required_layer_count = - desc.base_array_layer + desc.array_layer_count.unwrap_or(1); + desc.base_array_layer + desc.array_layer_count.map_or(1, |count| count.get()); let level_end = texture.full_range.levels.end; let layer_end = texture.full_range.layers.end; - if required_level_count > level_end as u32 - || required_level_count == desc.base_mip_level - { + if required_level_count > level_end as u32 { return Err(resource::CreateTextureViewError::InvalidMipLevelCount { requested: required_level_count, total: level_end, }); } - if required_layer_count > layer_end as u32 - || required_layer_count == desc.base_array_layer - { + if required_layer_count > layer_end as u32 { return Err(resource::CreateTextureViewError::InvalidArrayLayerCount { requested: required_layer_count, total: layer_end, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index ec69a4074..edf2f54a0 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -10,7 +10,7 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::{borrow::Cow, ops::Range}; +use std::{borrow::Cow, num::NonZeroU32, ops::Range}; pub use into_cow::IntoCow; mod into_cow; @@ -1750,13 +1750,13 @@ pub struct TextureViewDescriptor { /// Mip level count. /// If `Some(count)`, `base_mip_level + count` must be less or equal to underlying texture mip count. /// If `None`, considered to include the rest of the mipmap levels, but at least 1 in total. - pub level_count: Option, + pub level_count: Option, /// Base array layer. pub base_array_layer: u32, /// Layer count. /// If `Some(count)`, `base_array_layer + count` must be less or equal to the underlying array count. /// If `None`, considered to include the rest of the array layers, but at least 1 in total. - pub array_layer_count: Option, + pub array_layer_count: Option, } impl<'a> TextureViewDescriptor>> { @@ -1786,7 +1786,7 @@ impl TextureViewDescriptor { } pub fn level_count(&mut self, level_count: u32) -> &mut Self { - self.level_count = Some(level_count); + self.level_count = Some(NonZeroU32::new(level_count).unwrap()); self } @@ -1796,7 +1796,7 @@ impl TextureViewDescriptor { } pub fn array_layer_count(&mut self, array_layer_count: u32) -> &mut Self { - self.array_layer_count = Some(array_layer_count); + self.array_layer_count = Some(NonZeroU32::new(array_layer_count).unwrap()); self }