Make texture view default format robust against invalid aspects

Computation of the default depends on the aspect, but the aspect
may be invalid. Make the default computation robust such that it
picks some valid aspect if a valid one is not provided. This will
make computing the default OK, but still fail validation of the
aspect later.

Bug: chromium:1314049
Change-Id: I2dcfe7962c7e30ac627605b6d0f1c269b3a6af6e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86020
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2022-04-07 20:20:14 +00:00 committed by Dawn LUCI CQ
parent afbe161cd4
commit f02bf9e76d
4 changed files with 25 additions and 3 deletions

View File

@ -1630,7 +1630,10 @@ namespace dawn::native {
const TextureViewDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
DAWN_TRY(ValidateObject(texture));
TextureViewDescriptor desc = GetTextureViewDescriptorWithDefaults(texture, descriptor);
TextureViewDescriptor desc;
DAWN_TRY_ASSIGN(desc, GetTextureViewDescriptorWithDefaults(texture, descriptor));
if (IsValidationEnabled()) {
DAWN_TRY_CONTEXT(ValidateTextureViewDescriptor(this, texture, &desc),
"validating %s against %s.", &desc, texture);

View File

@ -443,7 +443,7 @@ namespace dawn::native {
return {};
}
TextureViewDescriptor GetTextureViewDescriptorWithDefaults(
ResultOrError<TextureViewDescriptor> GetTextureViewDescriptorWithDefaults(
const TextureBase* texture,
const TextureViewDescriptor* descriptor) {
ASSERT(texture);
@ -473,6 +473,11 @@ namespace dawn::native {
if (desc.format == wgpu::TextureFormat::Undefined) {
const Format& format = texture->GetFormat();
// Check the aspect since |SelectFormatAspects| assumes a valid aspect.
// Creation would have failed validation later since the aspect is invalid.
DAWN_TRY(ValidateTextureAspect(desc.aspect));
Aspect aspects = SelectFormatAspects(format, desc.aspect);
if (HasOneBit(aspects)) {
desc.format = format.GetAspectInfo(aspects).format;

View File

@ -34,7 +34,7 @@ namespace dawn::native {
MaybeError ValidateTextureViewDescriptor(const DeviceBase* device,
const TextureBase* texture,
const TextureViewDescriptor* descriptor);
TextureViewDescriptor GetTextureViewDescriptorWithDefaults(
ResultOrError<TextureViewDescriptor> GetTextureViewDescriptorWithDefaults(
const TextureBase* texture,
const TextureViewDescriptor* descriptor);

View File

@ -590,6 +590,20 @@ namespace {
}
}
// Regression test for crbug.com/1314049. Format default depends on the aspect.
// Test that computing the default does not crash if the aspect is invalid.
TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsInvalidAspect) {
wgpu::Texture texture =
CreateDepthStencilTexture(device, wgpu::TextureFormat::Depth24PlusStencil8);
wgpu::TextureViewDescriptor viewDesc = {};
viewDesc.aspect = static_cast<wgpu::TextureAspect>(-1);
// Validation should catch the invalid aspect.
ASSERT_DEVICE_ERROR(texture.CreateView(&viewDesc),
testing::HasSubstr("Invalid value for WGPUTextureAspect"));
}
// Test creating cube map texture view
TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) {
constexpr uint32_t kDefaultArrayLayers = 16;