mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 14:31:08 +01:00
Allow copying of textures with copy-compatible formats (#3528)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
1 parent
710fc553d5
commit
7e72f30179
3 files changed
+21
-11
No files matched your search
@@ -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)
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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(©.src_base.origin);
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user