Validate texture view format is supported

Fixed: chromium:1312780
Change-Id: I29f13a2df3ef1db6961a5760a6c1bb05ab3fa89b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85680
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Austin Eng 2022-04-04 20:28:37 +00:00 committed by Dawn LUCI CQ
parent 2787a4c64c
commit e8498e7f04
2 changed files with 12 additions and 2 deletions

View File

@ -411,7 +411,8 @@ namespace dawn::native {
DAWN_TRY(ValidateTextureAspect(descriptor->aspect)); DAWN_TRY(ValidateTextureAspect(descriptor->aspect));
const Format& format = texture->GetFormat(); const Format& format = texture->GetFormat();
const Format& viewFormat = device->GetValidInternalFormat(descriptor->format); const Format* viewFormat;
DAWN_TRY_ASSIGN(viewFormat, device->GetInternalFormat(descriptor->format));
DAWN_INVALID_IF( DAWN_INVALID_IF(
SelectFormatAspects(format, descriptor->aspect) == Aspect::None, SelectFormatAspects(format, descriptor->aspect) == Aspect::None,
@ -436,7 +437,7 @@ namespace dawn::native {
"texture's mip level count (%u).", "texture's mip level count (%u).",
descriptor->baseMipLevel, descriptor->mipLevelCount, texture->GetNumMipLevels()); descriptor->baseMipLevel, descriptor->mipLevelCount, texture->GetNumMipLevels());
DAWN_TRY(ValidateCanViewTextureAs(device, texture, viewFormat, descriptor->aspect)); DAWN_TRY(ValidateCanViewTextureAs(device, texture, *viewFormat, descriptor->aspect));
DAWN_TRY(ValidateTextureViewDimensionCompatibility(texture, descriptor)); DAWN_TRY(ValidateTextureViewDimensionCompatibility(texture, descriptor));
return {}; return {};

View File

@ -729,6 +729,15 @@ namespace {
ASSERT_DEVICE_ERROR(texture.CreateView(&viewDesc)); ASSERT_DEVICE_ERROR(texture.CreateView(&viewDesc));
} }
// Regression test for crbug.com/1312780.
// viewFormat is not supported (Null backend does not support any optional features).
{
textureDesc.format = wgpu::TextureFormat::Depth24PlusStencil8;
viewDesc.format = wgpu::TextureFormat::Depth24UnormStencil8;
wgpu::Texture texture = device.CreateTexture(&textureDesc);
ASSERT_DEVICE_ERROR(texture.CreateView(&viewDesc), testing::HasSubstr("Unsupported"));
}
// It is valid to create a texture view with a depth format of a depth-stencil texture // It is valid to create a texture view with a depth format of a depth-stencil texture
// if the depth only aspect is selected. // if the depth only aspect is selected.
{ {