diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 99d994d60b..29a2a67bce 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -639,14 +639,21 @@ impl Device { ) -> Result, resource::CreateTextureError> { let format_desc = desc.format.describe(); - // Depth textures can only be 2D - if format_desc.sample_type == wgt::TextureSampleType::Depth - && desc.dimension != wgt::TextureDimension::D2 - { - return Err(resource::CreateTextureError::InvalidDepthKind( - desc.dimension, - desc.format, - )); + if desc.dimension != wgt::TextureDimension::D2 { + // Depth textures can only be 2D + if format_desc.sample_type == wgt::TextureSampleType::Depth { + return Err(resource::CreateTextureError::InvalidDepthKind( + desc.dimension, + desc.format, + )); + } + // Renderable textures can only be 2D + if desc.usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) { + return Err(resource::CreateTextureError::InvalidDimensionUsages( + wgt::TextureUsages::RENDER_ATTACHMENT, + desc.dimension, + )); + } } let format_features = self @@ -659,7 +666,7 @@ impl Device { let missing_allowed_usages = desc.usage - format_features.allowed_usages; if !missing_allowed_usages.is_empty() { - return Err(resource::CreateTextureError::InvalidUsages( + return Err(resource::CreateTextureError::InvalidFormatUsages( missing_allowed_usages, desc.format, )); diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 3315162c0f..95bf121833 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -306,7 +306,9 @@ pub enum CreateTextureError { )] InvalidMipLevelCount { requested: u32, maximum: u32 }, #[error("Texture usages {0:?} are not allowed on a texture of type {1:?}")] - InvalidUsages(wgt::TextureUsages, wgt::TextureFormat), + InvalidFormatUsages(wgt::TextureUsages, wgt::TextureFormat), + #[error("Texture usages {0:?} are not allowed on a texture of dimensions {1:?}")] + InvalidDimensionUsages(wgt::TextureUsages, wgt::TextureDimension), #[error("Texture format {0:?} can't be used")] MissingFeatures(wgt::TextureFormat, #[source] MissingFeatures), }