Update createView default logic to match spec

Textures with more than one arrayLayer will now default to 2DArray
rather than 2D.

Change-Id: I34dd58aae27c4add65166343641777b3ac4dabcb
Bug: dawn:1380
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87306
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Brandon Jones 2022-05-24 14:57:43 +00:00 committed by Dawn LUCI CQ
parent 20a4bd8377
commit 7aeac5e67f
3 changed files with 15 additions and 4 deletions

View File

@ -537,6 +537,7 @@ MaybeError DoCopyTextureForBrowser(DeviceBase* device,
// Prepare binding 2 resource: sampled texture
TextureViewDescriptor srcTextureViewDesc = {};
srcTextureViewDesc.dimension = wgpu::TextureViewDimension::e2D;
srcTextureViewDesc.baseMipLevel = source->mipLevel;
srcTextureViewDesc.mipLevelCount = 1;
srcTextureViewDesc.arrayLayerCount = 1;
@ -556,6 +557,7 @@ MaybeError DoCopyTextureForBrowser(DeviceBase* device,
// Prepare dst texture view as color Attachment.
TextureViewDescriptor dstTextureViewDesc;
dstTextureViewDesc.dimension = wgpu::TextureViewDimension::e2D;
dstTextureViewDesc.baseMipLevel = destination->mipLevel;
dstTextureViewDesc.mipLevelCount = 1;
dstTextureViewDesc.baseArrayLayer = destination->origin.z;

View File

@ -441,7 +441,7 @@ ResultOrError<TextureViewDescriptor> GetTextureViewDescriptorWithDefaults(
}
// The default value for the view dimension depends on the texture's dimension with a
// special case for 2DArray being chosen automatically if arrayLayerCount is unspecified.
// special case for 2DArray being chosen if texture is 2D but has more than one array layer.
if (desc.dimension == wgpu::TextureViewDimension::Undefined) {
switch (texture->GetDimension()) {
case wgpu::TextureDimension::e1D:
@ -449,7 +449,11 @@ ResultOrError<TextureViewDescriptor> GetTextureViewDescriptorWithDefaults(
break;
case wgpu::TextureDimension::e2D:
desc.dimension = wgpu::TextureViewDimension::e2D;
if (texture->GetArrayLayers() == 1) {
desc.dimension = wgpu::TextureViewDimension::e2D;
} else {
desc.dimension = wgpu::TextureViewDimension::e2DArray;
}
break;
case wgpu::TextureDimension::e3D:

View File

@ -487,10 +487,15 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaults2DArray) {
{
wgpu::TextureViewDescriptor descriptor;
// Setting array layers to non-0 means the dimensionality will
// default to 2D so by itself it causes an error.
// Setting array layers to > 1 with an explicit dimensionality of 2D will
// causes an error.
descriptor.arrayLayerCount = kDefaultArrayLayers;
descriptor.dimension = wgpu::TextureViewDimension::e2D;
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
// Setting view dimension to Undefined will result in a dimension of 2DArray because the
// underlying texture has > 1 array layers.
descriptor.dimension = wgpu::TextureViewDimension::Undefined;
texture.CreateView(&descriptor);
descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
texture.CreateView(&descriptor);