Skip to content

Commit

Permalink
Sync depth/stencil copy restrictions with the spec (#3314)
Browse files Browse the repository at this point in the history
* sync depth/stencil copy restrictions with the spec

* add changelog entry
  • Loading branch information
teoxoy committed Dec 20, 2022
1 parent 8ca6e38 commit 14886ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Additionally `Surface::get_default_config` now returns an Option and returns Non
#### WebGPU

- Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098)
- Sync depth/stencil copy restrictions with the spec by @teoxoy in [#3314](https://github.com/gfx-rs/wgpu/pull/3314)

#### GLES

Expand Down
34 changes: 22 additions & 12 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ 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("copying from textures with format {format:?} and aspect {aspect:?} is forbidden")]
CopyFromForbiddenTextureFormat {
format: wgt::TextureFormat,
aspect: wgt::TextureAspect,
},
#[error("copying to textures with format {format:?} and aspect {aspect:?} is forbidden")]
CopyToForbiddenTextureFormat {
format: wgt::TextureFormat,
aspect: wgt::TextureAspect,
},
#[error("the entire texture must be copied when copying from depth texture")]
InvalidDepthTextureExtent,
#[error(
Expand Down Expand Up @@ -771,10 +777,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
true,
)?;

if !conv::is_valid_copy_dst_texture_format(dst_texture.desc.format) {
return Err(
TransferError::CopyToForbiddenTextureFormat(dst_texture.desc.format).into(),
);
if !conv::is_valid_copy_dst_texture_format(dst_texture.desc.format, destination.aspect) {
return Err(TransferError::CopyToForbiddenTextureFormat {
format: dst_texture.desc.format,
aspect: destination.aspect,
}
.into());
}

cmd_buf
Expand Down Expand Up @@ -917,10 +925,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
true,
)?;

if !conv::is_valid_copy_src_texture_format(src_texture.desc.format) {
return Err(
TransferError::CopyFromForbiddenTextureFormat(src_texture.desc.format).into(),
);
if !conv::is_valid_copy_src_texture_format(src_texture.desc.format, source.aspect) {
return Err(TransferError::CopyFromForbiddenTextureFormat {
format: src_texture.desc.format,
aspect: source.aspect,
}
.into());
}

if format_desc.sample_type == wgt::TextureSampleType::Depth
Expand Down
26 changes: 15 additions & 11 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ pub fn is_power_of_two_u32(val: u32) -> bool {
val != 0 && (val & (val - 1)) == 0
}

pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool {
pub fn is_valid_copy_src_texture_format(
format: wgt::TextureFormat,
aspect: wgt::TextureAspect,
) -> bool {
use wgt::TextureAspect as Ta;
use wgt::TextureFormat as Tf;
match format {
Tf::Depth24Plus | Tf::Depth24PlusStencil8 => false,
match (format, aspect) {
(Tf::Depth24Plus, _) | (Tf::Depth24PlusStencil8, Ta::DepthOnly) => false,
_ => true,
}
}

pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool {
pub fn is_valid_copy_dst_texture_format(
format: wgt::TextureFormat,
aspect: wgt::TextureAspect,
) -> bool {
use wgt::TextureAspect as Ta;
use wgt::TextureFormat as Tf;
match format {
//Tf::Stencil8 |
Tf::Depth16Unorm
| Tf::Depth32Float
| Tf::Depth32FloatStencil8
| Tf::Depth24Plus
| Tf::Depth24PlusStencil8 => false,
match (format, aspect) {
(Tf::Depth24Plus | Tf::Depth32Float, _)
| (Tf::Depth24PlusStencil8 | Tf::Depth32FloatStencil8, Ta::DepthOnly) => false,
_ => true,
}
}
Expand Down
8 changes: 6 additions & 2 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
false,
)?;

if !conv::is_valid_copy_dst_texture_format(texture_format) {
return Err(TransferError::CopyToForbiddenTextureFormat(texture_format).into());
if !conv::is_valid_copy_dst_texture_format(texture_format, destination.aspect) {
return Err(TransferError::CopyToForbiddenTextureFormat {
format: texture_format,
aspect: destination.aspect,
}
.into());
}
let (block_width, block_height) = format_desc.block_dimensions;
let width_blocks = size.width / block_width as u32;
Expand Down

0 comments on commit 14886ee

Please sign in to comment.