diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 2699878169..4936d97adc 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -642,7 +642,7 @@ impl Device { 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( + return Err(resource::CreateTextureError::InvalidDepthDimension( desc.dimension, desc.format, )); @@ -654,6 +654,14 @@ impl Device { desc.dimension, )); } + + // Compressed textures can only be 2D + if format_desc.is_compressed() { + return Err(resource::CreateTextureError::InvalidCompressedDimension( + desc.dimension, + desc.format, + )); + } } let format_features = self diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index f970cd1028..3f12aba0d5 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -299,8 +299,10 @@ pub enum CreateTextureError { EmptyUsage, #[error(transparent)] InvalidDimension(#[from] TextureDimensionError), - #[error("Depth texture kind {0:?} of format {0:?} can't be created")] - InvalidDepthKind(wgt::TextureDimension, wgt::TextureFormat), + #[error("Depth texture ({1:?}) can't be created as {0:?}")] + InvalidDepthDimension(wgt::TextureDimension, wgt::TextureFormat), + #[error("Compressed texture ({1:?}) can't be created as {0:?}")] + InvalidCompressedDimension(wgt::TextureDimension, wgt::TextureFormat), #[error( "Texture descriptor mip level count {requested} is invalid, maximum allowed is {maximum}" )] diff --git a/wgpu/tests/clear_texture.rs b/wgpu/tests/clear_texture.rs index 269c5da62c..9a15a41274 100644 --- a/wgpu/tests/clear_texture.rs +++ b/wgpu/tests/clear_texture.rs @@ -270,31 +270,29 @@ fn clear_texture_tests( }, wgpu::TextureDimension::D2, ); + // 2D array texture + single_texture_clear_test( + ctx, + format, + wgpu::Extent3d { + width: 64, + height: 64, + depth_or_array_layers: 4, + }, + wgpu::TextureDimension::D2, + ); if supports_3d { - // 2D array texture + // volume texture single_texture_clear_test( ctx, format, wgpu::Extent3d { - width: 64, - height: 64, - depth_or_array_layers: 4, + width: 16, + height: 16, + depth_or_array_layers: 16, }, - wgpu::TextureDimension::D2, + wgpu::TextureDimension::D3, ); - // volume texture - if format.describe().sample_type != wgt::TextureSampleType::Depth { - single_texture_clear_test( - ctx, - format, - wgpu::Extent3d { - width: 16, - height: 16, - depth_or_array_layers: 16, - }, - wgpu::TextureDimension::D3, - ); - } } } } @@ -305,7 +303,7 @@ fn clear_texture_2d_uncompressed() { TestParameters::default().features(wgpu::Features::CLEAR_TEXTURE), |ctx| { clear_texture_tests(&ctx, TEXTURE_FORMATS_UNCOMPRESSED, true, true); - clear_texture_tests(&ctx, TEXTURE_FORMATS_DEPTH, false, true); + clear_texture_tests(&ctx, TEXTURE_FORMATS_DEPTH, false, false); }, ) } @@ -317,7 +315,7 @@ fn clear_texture_2d_bc() { .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_BC) .specific_failure(Some(wgpu::Backends::GL), None, Some("ANGLE"), false), // https://bugs.chromium.org/p/angleproject/issues/detail?id=7056 |ctx| { - clear_texture_tests(&ctx, TEXTURE_FORMATS_BC, false, true); + clear_texture_tests(&ctx, TEXTURE_FORMATS_BC, false, false); }, ) } @@ -329,7 +327,7 @@ fn clear_texture_2d_astc() { .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) .specific_failure(Some(wgpu::Backends::GL), None, Some("ANGLE"), false), // https://bugs.chromium.org/p/angleproject/issues/detail?id=7056 |ctx| { - clear_texture_tests(&ctx, TEXTURE_FORMATS_ASTC, false, true); + clear_texture_tests(&ctx, TEXTURE_FORMATS_ASTC, false, false); }, ) } @@ -341,7 +339,7 @@ fn clear_texture_2d_etc2() { .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_ETC2) .specific_failure(Some(wgpu::Backends::GL), None, Some("ANGLE"), false), // https://bugs.chromium.org/p/angleproject/issues/detail?id=7056 |ctx| { - clear_texture_tests(&ctx, TEXTURE_FORMATS_ETC2, false, true); + clear_texture_tests(&ctx, TEXTURE_FORMATS_ETC2, false, false); }, ) }