Allow copying from Depth32Float textures

Backport of #901
This commit is contained in:
Maximilian Lupke 2020-08-28 16:58:48 +02:00 committed by Dzmitry Malyshau
parent 6455b634e4
commit 8e9b5e38ce
3 changed files with 38 additions and 5 deletions

View File

@ -414,6 +414,12 @@ 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) {
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<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) {
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 {

View File

@ -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 {

View File

@ -307,6 +307,12 @@ 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) {
panic!(
"copying to textures with format {:?} is forbidden",
texture_format
);
}
let width_blocks = size.width / block_width;
let height_blocks = size.height / block_width;