Validate texture max size
Bug: dawn:294 Change-Id: I966dd87bfc0584fdcfa734193d083fcaa6b50898 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14283 Commit-Queue: Natasha Lee <natlee@microsoft.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
dc3317da6c
commit
792ff476ce
|
@ -141,6 +141,10 @@ namespace dawn_native {
|
|||
|
||||
MaybeError ValidateTextureSize(const TextureDescriptor* descriptor, const Format* format) {
|
||||
ASSERT(descriptor->size.width != 0 && descriptor->size.height != 0);
|
||||
if (descriptor->size.width > kMaxTextureSize ||
|
||||
descriptor->size.height > kMaxTextureSize) {
|
||||
return DAWN_VALIDATION_ERROR("Texture max size exceeded");
|
||||
}
|
||||
|
||||
if (Log2(std::max(descriptor->size.width, descriptor->size.height)) + 1 <
|
||||
descriptor->mipLevelCount) {
|
||||
|
@ -153,6 +157,13 @@ namespace dawn_native {
|
|||
"The size of the texture is incompatible with the texture format");
|
||||
}
|
||||
|
||||
if (descriptor->arrayLayerCount > kMaxTexture2DArrayLayers) {
|
||||
return DAWN_VALIDATION_ERROR("Texture 2D array layer count exceeded");
|
||||
}
|
||||
if (descriptor->mipLevelCount > kMaxTexture2DMipLevels) {
|
||||
return DAWN_VALIDATION_ERROR("Max texture 2D mip level exceeded");
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -172,6 +172,76 @@ TEST_F(TextureValidationTest, MipLevelCount) {
|
|||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
|
||||
// Mip level exceeding kMaxTexture2DMipLevels not allowed
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = 1 >> kMaxTexture2DMipLevels;
|
||||
descriptor.size.height = 1 >> kMaxTexture2DMipLevels;
|
||||
descriptor.mipLevelCount = kMaxTexture2DMipLevels + 1u;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
}
|
||||
// Test the validation of array layer count
|
||||
TEST_F(TextureValidationTest, ArrayLayerCount) {
|
||||
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
|
||||
|
||||
// Array layer count exceeding kMaxTexture2DArrayLayers is not allowed
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.arrayLayerCount = kMaxTexture2DArrayLayers + 1u;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
|
||||
// Array layer count less than kMaxTexture2DArrayLayers is allowed;
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.arrayLayerCount = kMaxTexture2DArrayLayers >> 1;
|
||||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
|
||||
// Array layer count equal to kMaxTexture2DArrayLayers is allowed;
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.arrayLayerCount = kMaxTexture2DArrayLayers;
|
||||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// Test the validation of texture size
|
||||
TEST_F(TextureValidationTest, TextureSize) {
|
||||
wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
|
||||
|
||||
// Texture size exceeding kMaxTextureSize is not allowed
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = kMaxTextureSize + 1u;
|
||||
descriptor.size.height = kMaxTextureSize + 1u;
|
||||
|
||||
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
|
||||
}
|
||||
|
||||
// Texture size less than kMaxTextureSize is allowed
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = kMaxTextureSize >> 1;
|
||||
descriptor.size.height = kMaxTextureSize >> 1;
|
||||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
|
||||
// Texture equal to kMaxTextureSize is allowed
|
||||
{
|
||||
wgpu::TextureDescriptor descriptor = defaultDescriptor;
|
||||
descriptor.size.width = kMaxTextureSize;
|
||||
descriptor.size.height = kMaxTextureSize;
|
||||
|
||||
device.CreateTexture(&descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// Test that it is valid to destroy a texture
|
||||
|
|
Loading…
Reference in New Issue