Fix validation of mip map level
Mip map level starts with the size of texture image and halves the size until a 1x1 dimension. BUG=chromium:954769 Change-Id: I59e51af216d65c721a3d2c2023306883e524820d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7000 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Yizhou Jiang <yizhou.jiang@intel.com>
This commit is contained in:
parent
f8a1041e99
commit
8804bc541e
|
@ -14,6 +14,8 @@
|
|||
|
||||
#include "dawn_native/Texture.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/Assert.h"
|
||||
#include "common/Math.h"
|
||||
#include "dawn_native/Device.h"
|
||||
|
@ -174,8 +176,8 @@ namespace dawn_native {
|
|||
return DAWN_VALIDATION_ERROR("Cannot create an empty texture");
|
||||
}
|
||||
|
||||
if (Log2(descriptor->size.width) + 1 < descriptor->mipLevelCount ||
|
||||
Log2(descriptor->size.height) + 1 < descriptor->mipLevelCount) {
|
||||
if (Log2(std::max(descriptor->size.width, descriptor->size.height)) + 1 <
|
||||
descriptor->mipLevelCount) {
|
||||
return DAWN_VALIDATION_ERROR("Texture has too many mip levels");
|
||||
}
|
||||
|
||||
|
|
|
@ -135,8 +135,8 @@ TEST_F(TextureValidationTest, MipLevelCount) {
|
|||
dawn::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = 31;
|
||||
descriptor.size.height = 32;
|
||||
// Mip level width: 31, 15, 7, 3, 1
|
||||
descriptor.mipLevelCount = 6;
|
||||
// Mip level width: 31, 15, 7, 3, 1, 1
|
||||
descriptor.mipLevelCount = 7;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ TEST_F(TextureValidationTest, MipLevelCount) {
|
|||
dawn::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = 32;
|
||||
descriptor.size.height = 31;
|
||||
// Mip level height: 31, 15, 7, 3, 1
|
||||
descriptor.mipLevelCount = 6;
|
||||
// Mip level height: 31, 15, 7, 3, 1, 1
|
||||
descriptor.mipLevelCount = 7;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
|
@ -161,6 +161,17 @@ TEST_F(TextureValidationTest, MipLevelCount) {
|
|||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
|
||||
// Non square mip map halves the resolution until a 1x1 dimension.
|
||||
{
|
||||
dawn::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = 32;
|
||||
descriptor.size.height = 8;
|
||||
// Mip maps: 32 * 8, 16 * 4, 8 * 2, 4 * 1, 2 * 1, 1 * 1
|
||||
descriptor.mipLevelCount = 6;
|
||||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// Test that it is valid to destroy a texture
|
||||
|
|
Loading…
Reference in New Issue