Skip to content

Commit

Permalink
Validated render usages for 3D textures
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Feb 15, 2022
1 parent 210014e commit 0545e36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 16 additions & 9 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,21 @@ impl<A: HalApi> Device<A> {
) -> Result<resource::Texture<A>, resource::CreateTextureError> {
let format_desc = desc.format.describe();

// Depth textures can only be 2D
if format_desc.sample_type == wgt::TextureSampleType::Depth
&& desc.dimension != wgt::TextureDimension::D2
{
return Err(resource::CreateTextureError::InvalidDepthKind(
desc.dimension,
desc.format,
));
if desc.dimension != wgt::TextureDimension::D2 {
// Depth textures can only be 2D
if format_desc.sample_type == wgt::TextureSampleType::Depth {
return Err(resource::CreateTextureError::InvalidDepthKind(
desc.dimension,
desc.format,
));
}
// Renderable textures can only be 2D
if desc.usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) {
return Err(resource::CreateTextureError::InvalidDimensionUsages(
wgt::TextureUsages::RENDER_ATTACHMENT,
desc.dimension,
));
}
}

let format_features = self
Expand All @@ -659,7 +666,7 @@ impl<A: HalApi> Device<A> {

let missing_allowed_usages = desc.usage - format_features.allowed_usages;
if !missing_allowed_usages.is_empty() {
return Err(resource::CreateTextureError::InvalidUsages(
return Err(resource::CreateTextureError::InvalidFormatUsages(
missing_allowed_usages,
desc.format,
));
Expand Down
4 changes: 3 additions & 1 deletion wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ pub enum CreateTextureError {
)]
InvalidMipLevelCount { requested: u32, maximum: u32 },
#[error("Texture usages {0:?} are not allowed on a texture of type {1:?}")]
InvalidUsages(wgt::TextureUsages, wgt::TextureFormat),
InvalidFormatUsages(wgt::TextureUsages, wgt::TextureFormat),
#[error("Texture usages {0:?} are not allowed on a texture of dimensions {1:?}")]
InvalidDimensionUsages(wgt::TextureUsages, wgt::TextureDimension),
#[error("Texture format {0:?} can't be used")]
MissingFeatures(wgt::TextureFormat, #[source] MissingFeatures),
}
Expand Down

0 comments on commit 0545e36

Please sign in to comment.