Skip to content

Commit

Permalink
Allow copying of textures with copy-compatible formats (#3528)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
  • Loading branch information
teoxoy and cwfitzgerald committed Mar 3, 2023
1 parent 710fc55 commit 7e72f30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ By @teoxoy in [#3534](https://github.com/gfx-rs/wgpu/pull/3534)
- 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)
- Improve attachment related errors. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549)
- Make error descriptions all upper case. By @cwfitzgerald in [#3549](https://github.com/gfx-rs/wgpu/pull/3549)

Expand Down
19 changes: 10 additions & 9 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ pub enum TransferError {
#[error("The entire texture must be copied when copying from depth texture")]
InvalidDepthTextureExtent,
#[error(
"Source format ({src_format:?}) and destination format ({dst_format:?}) are not copy-compatible"
"Source format ({src_format:?}) and destination format ({dst_format:?}) are not copy-compatible (they may only differ in srgb-ness)"
)]
MismatchedTextureFormats {
TextureFormatsNotCopyCompatible {
src_format: wgt::TextureFormat,
dst_format: wgt::TextureFormat,
},
Expand Down Expand Up @@ -1036,13 +1036,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.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 {
return Err(TransferError::MismatchedTextureFormats {
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::TextureFormatsNotCopyCompatible {
src_format: src_texture.desc.format,
dst_format: dst_texture.desc.format,
}
.into());
}
Expand Down
12 changes: 10 additions & 2 deletions wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{conv, AsNative};
use std::{mem, ops::Range};
use std::{borrow::Cow, mem, ops::Range};

// has to match `Temp::binding_sizes`
const WORD_SIZE: usize = 4;
Expand Down Expand Up @@ -187,6 +187,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
) where
T: Iterator<Item = crate::TextureCopy>,
{
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(&copy.src_base.origin);
Expand All @@ -199,7 +207,7 @@ impl crate::CommandEncoder<super::Api> 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,
Expand Down

0 comments on commit 7e72f30

Please sign in to comment.