From f622c83a19856614fab7dff041599bf4ebd52f54 Mon Sep 17 00:00:00 2001 From: Samuel Hurel Date: Mon, 29 Nov 2021 18:32:48 +0100 Subject: [PATCH] Allows for depth texture copies --- wgpu-core/src/command/transfer.rs | 13 +++++++++++++ wgpu-core/src/device/mod.rs | 13 ------------- wgpu-core/src/resource.rs | 2 -- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 98e6ed8531..c4805e7e9f 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -95,6 +95,8 @@ pub enum TransferError { CopyFromForbiddenTextureFormat(wgt::TextureFormat), #[error("copying to textures with format {0:?} is forbidden")] CopyToForbiddenTextureFormat(wgt::TextureFormat), + #[error("the entire texture must be copied when copiying from depth texture")] + InvalidDepthTextureExtent, } impl PrettyError for TransferError { @@ -295,6 +297,17 @@ pub(crate) fn validate_texture_copy_range( // physical size can be larger than the virtual let extent = extent_virtual.physical_size(desc.format); + match desc.format { + wgt::TextureFormat::Depth32Float + | wgt::TextureFormat::Depth24Plus + | wgt::TextureFormat::Depth24PlusStencil8 => { + if *copy_size != extent { + return Err(TransferError::InvalidDepthTextureExtent); + } + } + _ => {} + } + let x_copy_max = texture_copy_view.origin.x + copy_size.width; if x_copy_max > extent.width { return Err(TransferError::TextureOverrun { diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e9366b7332..73ef684e4f 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -653,19 +653,6 @@ impl Device { .describe_format_features(adapter, desc.format) .map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error))?; - // Ensure `D24Plus` textures cannot be copied - match desc.format { - TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => { - if desc - .usage - .intersects(wgt::TextureUsages::COPY_SRC | wgt::TextureUsages::COPY_DST) - { - return Err(resource::CreateTextureError::CannotCopyD24Plus); - } - } - _ => {} - } - if desc.usage.is_empty() { return Err(resource::CreateTextureError::EmptyUsage); } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index b83553b0ea..270202df53 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -255,8 +255,6 @@ pub enum TextureDimensionError { pub enum CreateTextureError { #[error(transparent)] Device(#[from] DeviceError), - #[error("D24Plus textures cannot be copied")] - CannotCopyD24Plus, #[error("Textures cannot have empty usage flags")] EmptyUsage, #[error(transparent)]