mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Allow copying from depth textures (#901)
* Allow copying from depth textures * Rename TextureFormat::is_depth_format to just is_depth * Only allow Depth32Float format for copying, and only as source
This commit is contained in:
parent
4de1d24bc6
commit
5d50b2ac24
@ -84,6 +84,10 @@ pub enum TransferError {
|
||||
InvalidRowsPerImage,
|
||||
#[error("source and destination layers have different aspects")]
|
||||
MismatchedAspects,
|
||||
#[error("copying from textures with format {0:?} is forbidden")]
|
||||
CopyFromForbiddenTextureFormat(wgt::TextureFormat),
|
||||
#[error("copying to textures with format {0:?} is forbidden")]
|
||||
CopyToForbiddenTextureFormat(wgt::TextureFormat),
|
||||
}
|
||||
|
||||
/// Error encountered while attempting to do a copy on a command encoder.
|
||||
@ -480,6 +484,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
)?;
|
||||
|
||||
let (block_width, _) = conv::texture_block_size(dst_texture.format);
|
||||
if !conv::is_valid_copy_dst_texture_format(dst_texture.format) {
|
||||
Err(TransferError::CopyToForbiddenTextureFormat(
|
||||
dst_texture.format,
|
||||
))?
|
||||
}
|
||||
|
||||
let buffer_width = (source.layout.bytes_per_row / bytes_per_block) * block_width;
|
||||
let region = hal::command::BufferImageCopy {
|
||||
@ -594,6 +603,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
)?;
|
||||
|
||||
let (block_width, _) = conv::texture_block_size(src_texture.format);
|
||||
if !conv::is_valid_copy_src_texture_format(src_texture.format) {
|
||||
Err(TransferError::CopyFromForbiddenTextureFormat(
|
||||
src_texture.format,
|
||||
))?
|
||||
}
|
||||
|
||||
let buffer_width = (destination.layout.bytes_per_row / bytes_per_block) * block_width;
|
||||
let region = hal::command::BufferImageCopy {
|
||||
|
||||
@ -439,11 +439,10 @@ pub fn texture_block_size(format: wgt::TextureFormat) -> (u32, u32) {
|
||||
| Tf::Rgba16Float
|
||||
| Tf::Rgba32Uint
|
||||
| Tf::Rgba32Sint
|
||||
| Tf::Rgba32Float => (1, 1),
|
||||
|
||||
Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => {
|
||||
unreachable!("unexpected depth format")
|
||||
}
|
||||
| Tf::Rgba32Float
|
||||
| Tf::Depth32Float
|
||||
| Tf::Depth24Plus
|
||||
| Tf::Depth24PlusStencil8 => (1, 1),
|
||||
|
||||
Tf::Bc1RgbaUnorm
|
||||
| Tf::Bc1RgbaUnormSrgb
|
||||
@ -562,6 +561,22 @@ pub fn is_power_of_two(val: u32) -> bool {
|
||||
val != 0 && (val & (val - 1)) == 0
|
||||
}
|
||||
|
||||
pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
|
||||
use wgt::TextureFormat as Tf;
|
||||
match format {
|
||||
Tf::Depth24Plus | Tf::Depth24PlusStencil8 => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
|
||||
use wgt::TextureFormat as Tf;
|
||||
match format {
|
||||
Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_texture_dimension_size(
|
||||
dimension: wgt::TextureDimension,
|
||||
wgt::Extent3d {
|
||||
|
||||
@ -313,6 +313,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
size,
|
||||
)?;
|
||||
let (block_width, block_height) = conv::texture_block_size(texture_format);
|
||||
if !conv::is_valid_copy_dst_texture_format(texture_format) {
|
||||
Err(TransferError::CopyToForbiddenTextureFormat(texture_format))?
|
||||
}
|
||||
let width_blocks = size.width / block_width;
|
||||
let height_blocks = size.height / block_width;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user