Match WebGPU's TextureViewDescriptor.dimension defaults.
This matches the choice made in https://github.com/gpuweb/gpuweb/pull/424 BUG=dawn:214 Change-Id: I9913f2c9c2f40b1ccc40c51cf79f50c171a48b3d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10861 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
c6c7a42e6e
commit
a560104617
|
@ -139,22 +139,6 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
dawn::TextureViewDimension GetDefaultViewDimension(const TextureBase* texture) {
|
||||
// TODO(jiawei.shao@intel.com): support all texture dimensions.
|
||||
switch (texture->GetDimension()) {
|
||||
case dawn::TextureDimension::e2D:
|
||||
ASSERT(texture->GetArrayLayers() != 0);
|
||||
if (texture->GetArrayLayers() == 1u) {
|
||||
return dawn::TextureViewDimension::e2D;
|
||||
} else {
|
||||
return dawn::TextureViewDimension::e2DArray;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return dawn::TextureViewDimension::e1D;
|
||||
}
|
||||
}
|
||||
|
||||
MaybeError ValidateTextureSize(const TextureDescriptor* descriptor, const Format* format) {
|
||||
ASSERT(descriptor->size.width != 0 && descriptor->size.height != 0);
|
||||
|
||||
|
@ -282,12 +266,34 @@ namespace dawn_native {
|
|||
desc = *descriptor;
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (desc.dimension == dawn::TextureViewDimension::Undefined) {
|
||||
switch (texture->GetDimension()) {
|
||||
case dawn::TextureDimension::e1D:
|
||||
desc.dimension = dawn::TextureViewDimension::e1D;
|
||||
break;
|
||||
|
||||
case dawn::TextureDimension::e2D:
|
||||
if (texture->GetArrayLayers() > 1u && desc.arrayLayerCount == 0) {
|
||||
desc.dimension = dawn::TextureViewDimension::e2DArray;
|
||||
} else {
|
||||
desc.dimension = dawn::TextureViewDimension::e2D;
|
||||
}
|
||||
break;
|
||||
|
||||
case dawn::TextureDimension::e3D:
|
||||
desc.dimension = dawn::TextureViewDimension::e3D;
|
||||
break;
|
||||
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
if (desc.format == dawn::TextureFormat::Undefined) {
|
||||
desc.format = texture->GetFormat().format;
|
||||
}
|
||||
if (desc.dimension == dawn::TextureViewDimension::Undefined) {
|
||||
desc.dimension = GetDefaultViewDimension(texture);
|
||||
}
|
||||
if (desc.arrayLayerCount == 0) {
|
||||
desc.arrayLayerCount = texture->GetArrayLayers() - desc.baseArrayLayer;
|
||||
}
|
||||
|
|
|
@ -181,10 +181,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
|
|||
constexpr uint32_t kDefaultArrayLayers = 6;
|
||||
dawn::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
|
||||
|
||||
{
|
||||
dawn::TextureViewDescriptor descriptor;
|
||||
texture.CreateView(&descriptor);
|
||||
}
|
||||
{ texture.CreateView(); }
|
||||
{
|
||||
dawn::TextureViewDescriptor descriptor;
|
||||
descriptor.format = dawn::TextureFormat::Undefined;
|
||||
|
@ -205,8 +202,14 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
|
|||
}
|
||||
{
|
||||
dawn::TextureViewDescriptor descriptor;
|
||||
|
||||
// Setting array layers to non-0 means the dimensionality will
|
||||
// default to 2D so by itself it causes an error.
|
||||
descriptor.arrayLayerCount = kDefaultArrayLayers;
|
||||
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
|
||||
descriptor.dimension = dawn::TextureViewDimension::e2DArray;
|
||||
texture.CreateView(&descriptor);
|
||||
|
||||
descriptor.mipLevelCount = kDefaultMipLevels;
|
||||
texture.CreateView(&descriptor);
|
||||
}
|
||||
|
@ -219,10 +222,7 @@ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
|
|||
constexpr uint32_t kDefaultArrayLayers = 1;
|
||||
dawn::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
|
||||
|
||||
{
|
||||
dawn::TextureViewDescriptor descriptor;
|
||||
texture.CreateView(&descriptor);
|
||||
}
|
||||
{ texture.CreateView(); }
|
||||
{
|
||||
dawn::TextureViewDescriptor descriptor;
|
||||
descriptor.format = dawn::TextureFormat::Undefined;
|
||||
|
|
Loading…
Reference in New Issue