diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 289a4134f..0f5fcb8a9 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -414,6 +414,12 @@ impl Global { )?; let (block_width, _) = conv::texture_block_size(dst_texture.format); + if !conv::is_valid_copy_dst_texture_format(dst_texture.format) { + panic!( + "copying to textures with format {:?} is forbidden", + dst_texture.format + ); + } let buffer_width = (source.layout.bytes_per_row / bytes_per_block) * block_width; let region = hal::command::BufferImageCopy { @@ -521,6 +527,12 @@ impl Global { )?; let (block_width, _) = conv::texture_block_size(src_texture.format); + if !conv::is_valid_copy_src_texture_format(src_texture.format) { + panic!( + "copying from textures with format {:?} is forbidden", + src_texture.format + ); + } let buffer_width = (destination.layout.bytes_per_row / bytes_per_block) * block_width; let region = hal::command::BufferImageCopy { diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index d8cff595e..b75f823a3 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -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 { diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index d4416822a..20fd27c58 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -307,6 +307,12 @@ impl Global { size, )?; let (block_width, block_height) = conv::texture_block_size(texture_format); + if !conv::is_valid_copy_dst_texture_format(texture_format) { + panic!( + "copying to textures with format {:?} is forbidden", + texture_format + ); + } let width_blocks = size.width / block_width; let height_blocks = size.height / block_width;