diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e5e61c0f02..bc08aee8dc 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -438,6 +438,10 @@ impl Device { } } + if desc.usage.is_empty() { + return Err(resource::CreateBufferError::EmptyUsage); + } + let mem_usage = { use gpu_alloc::UsageFlags as Uf; use wgt::BufferUsage as Bu; @@ -537,6 +541,10 @@ impl Device { _ => {} } + if desc.usage.is_empty() { + return Err(resource::CreateTextureError::EmptyUsage); + } + let kind = conv::map_texture_dimension_size(desc.dimension, desc.size, desc.sample_count)?; let format = conv::map_texture_format(desc.format, self.private_features); let aspects = format.surface_desc().aspects; diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 16319dd27e..6482575e4e 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -174,6 +174,8 @@ pub enum CreateBufferError { AccessError(#[from] BufferAccessError), #[error("buffers that are mapped at creation have to be aligned to `COPY_BUFFER_ALIGNMENT`")] UnalignedSize, + #[error("Buffers cannot have empty usage flags")] + EmptyUsage, #[error("`MAP` usage can only be combined with the opposite `COPY`, requested {0:?}")] UsageMismatch(wgt::BufferUsage), } @@ -230,6 +232,8 @@ pub enum CreateTextureError { Device(#[from] DeviceError), #[error("D24Plus textures cannot be copied")] CannotCopyD24Plus, + #[error("Textures cannot have empty usage flags")] + EmptyUsage, #[error(transparent)] InvalidDimension(#[from] TextureDimensionError), #[error("texture descriptor mip level count ({0}) is invalid")]