Skip to content

Commit 7303131

Browse files
Merge #923
923: Fix invalid mip level count check r=kvark a=benfrankel **Connections** Fixes #894 Continues from #893 **Description** Invalid mip level counts are allowed through `Device::create_texture`, triggering Vulkan validation errors. A fix was applied in #893, but the fix needs a minor correction to work properly. Also added back the `MAX_MIP_LEVELS` check, because it's technically possible for `MAX_MIP_LEVELS` to be less than `kind.compute_num_levels()`, e.g. if one of the given dimensions is very big (2^16). Error message is updated to reflect the change in behavior: there are now three ways for a mip level count to be invalid: it's equal to zero; it's greater than `MAX_MIP_LEVELS`; or it's greater than the largest mip level count allowed for the given size. **Testing** Tested by manually modifying the `mipmap` example in `wgpu-rs` to pass various edge case values for `size` and `mip_level_count`. Co-authored-by: Ben Frankel <ben.frankel7@gmail.com>
2 parents 68bf10a + 2ee07a2 commit 7303131

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

wgpu-core/src/device/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,10 @@ impl<B: GfxBackend> Device<B> {
515515
let usage = conv::map_texture_usage(desc.usage, aspects);
516516

517517
let mip_level_count = desc.mip_level_count;
518-
if mip_level_count == 0 && mip_level_count > kind.compute_num_levels() as u32 {
518+
if mip_level_count == 0
519+
|| mip_level_count > MAX_MIP_LEVELS
520+
|| mip_level_count > kind.compute_num_levels() as u32
521+
{
519522
return Err(resource::CreateTextureError::InvalidMipLevelCount(
520523
mip_level_count,
521524
));

wgpu-core/src/resource.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub enum CreateTextureError {
239239
CannotCopyD24Plus,
240240
#[error(transparent)]
241241
InvalidDimension(#[from] TextureDimensionError),
242-
#[error("texture descriptor mip level count ({0}) must be less than `MAX_MIP_LEVELS`")]
242+
#[error("texture descriptor mip level count ({0}) is invalid")]
243243
InvalidMipLevelCount(u32),
244244
#[error("Feature {0:?} must be enabled to create a texture of type {1:?}")]
245245
MissingFeature(wgt::Features, wgt::TextureFormat),

0 commit comments

Comments
 (0)