Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying of textures with copy-compatible formats #3528

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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

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(|| {
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
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