Skip to content

Commit

Permalink
more checks
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Dec 17, 2024
1 parent 945673f commit c748f90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,25 @@ impl Device {
}
};

let allowed_format_usages = resolved_format
.guaranteed_format_features(self.features)
.allowed_usages;
if resolved_usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT)
&& !allowed_format_usages.contains(wgt::TextureUsages::RENDER_ATTACHMENT)
{
return Err(
resource::CreateTextureViewError::TextureViewFormatNotRenderable(resolved_format),
);
}

if resolved_usage.contains(wgt::TextureUsages::STORAGE_BINDING)
&& !allowed_format_usages.contains(wgt::TextureUsages::STORAGE_BINDING)
{
return Err(
resource::CreateTextureViewError::TextureViewFormatNotStorage(resolved_format),
);
}

// validate TextureViewDescriptor

let aspects = hal::FormatAspects::new(texture.desc.format, desc.range.aspect);
Expand Down
4 changes: 4 additions & 0 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,10 @@ pub enum CreateTextureViewError {
view: wgt::TextureViewDimension,
texture: wgt::TextureDimension,
},
#[error("Texture view format `{0:?}` is not renderable")]
TextureViewFormatNotRenderable(wgt::TextureFormat),
#[error("Texture view format `{0:?}` is not storage bindable")]
TextureViewFormatNotStorage(wgt::TextureFormat),
#[error("Invalid texture view usage `{view:?}` with texture of usage `{texture:?}`")]
InvalidTextureViewUsage {
view: wgt::TextureUsages,
Expand Down

0 comments on commit c748f90

Please sign in to comment.