From 77dac7b23753a2ac9fa4ec598bb6e8fd6bf83b03 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 24 Feb 2023 18:29:40 +0100 Subject: [PATCH] allow copying of textures with copy-compatible formats --- CHANGELOG.md | 1 + wgpu-core/src/command/transfer.rs | 13 +++++++------ wgpu-hal/src/metal/command.rs | 10 +++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356bc2d80c7..47562177071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ By @teoxoy in [#3436](https://github.com/gfx-rs/wgpu/pull/3436) - Added `TextureFormatFeatureFlags::MULTISAMPLE_X16`. By @Dinnerbone in [#3454](https://github.com/gfx-rs/wgpu/pull/3454) - Support stencil-only views and copying to/from combined depth-stencil textures. By @teoxoy in [#3436](https://github.com/gfx-rs/wgpu/pull/3436) - Added `Features::SHADER_EARLY_DEPTH_TEST`. By @teoxoy in [#3494](https://github.com/gfx-rs/wgpu/pull/3494) +- Allow copying of textures with copy-compatible formats. By @teoxoy in [#3528](https://github.com/gfx-rs/wgpu/pull/3528) #### WebGPU diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index eca45ab70e3..3e709ed1970 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -1036,13 +1036,14 @@ impl Global { .get(destination.texture) .map_err(|_| TransferError::InvalidTexture(source.texture))?; - // src and dst texture format must be the same. - let src_format = src_texture.desc.format; - let dst_format = dst_texture.desc.format; - if src_format != dst_format { + // src and dst texture format must be copy-compatible + // https://gpuweb.github.io/gpuweb/#copy-compatible + if src_texture.desc.format.remove_srgb_suffix() + != dst_texture.desc.format.remove_srgb_suffix() + { return Err(TransferError::MismatchedTextureFormats { - src_format, - dst_format, + src_format: src_texture.desc.format, + dst_format: dst_texture.desc.format, } .into()); } diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index e94c8dae434..55ddb9e4a88 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -187,6 +187,14 @@ impl crate::CommandEncoder for super::CommandEncoder { ) where T: Iterator, { + let dst_texture = if src.format != dst.format { + let raw_format = self.shared.private_caps.map_format(src.format); + Cow::Owned(objc::rc::autoreleasepool(|| { + dst.raw.new_texture_view(raw_format) + })) + } else { + Cow::Borrowed(&dst.raw) + }; let encoder = self.enter_blit(); for copy in regions { let src_origin = conv::map_origin(©.src_base.origin); @@ -199,7 +207,7 @@ impl crate::CommandEncoder for super::CommandEncoder { copy.src_base.mip_level as u64, src_origin, extent, - &dst.raw, + &dst_texture, copy.dst_base.array_layer as u64, copy.dst_base.mip_level as u64, dst_origin,