[dawn][native] Disallow viewFormats with TRANSIENT_ATTACHMENT

Without this, we hit "Failed to create MTLTexture view" in the Metal
backend when trying to create a view with a different format on a
transient texture. (This happens even without Metal validation layers so
it's not a vulnerability, it just loses the device.)

Bug: https://github.com/gpuweb/gpuweb/issues/6263
Test: https://github.com/gpuweb/cts/pull/4647
Change-Id: Ia4b33594b0d47822af34fc5d8294d22f996fdc38
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/310035
Reviewed-by: Fr <beaufort.francois@gmail.com>
Commit-Queue: Fr <beaufort.francois@gmail.com>
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index 4d69475..69e24ee 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -798,11 +798,14 @@
     DAWN_TRY(ValidateTextureUsageConstraints(device, descriptor->dimension, usage, format,
                                              std::move(allowedSharedTextureMemoryUsage)));
 
-    DAWN_INVALID_IF(
-        usage & wgpu::TextureUsage::TransientAttachment &&
+    if (usage & wgpu::TextureUsage::TransientAttachment) {
+        DAWN_INVALID_IF(
             (descriptor->size.depthOrArrayLayers != 1 || descriptor->mipLevelCount != 1),
-        "The texture size depthOrArrayLayers (%u) and mipLevelCount (%u) must be 1.",
-        descriptor->size.depthOrArrayLayers, descriptor->mipLevelCount);
+            "Transient textures must have depthOrArrayLayers (%u) = 1 and mipLevelCount (%u) = 1.",
+            descriptor->size.depthOrArrayLayers, descriptor->mipLevelCount);
+        DAWN_INVALID_IF(descriptor->viewFormatCount > 0,
+                        "Transient textures must not have any viewFormats");
+    }
 
     DAWN_TRY(ValidateTextureDimension(descriptor->dimension));
     if (!device->HasFlexibleTextureViews()) {
diff --git a/src/dawn/tests/unittests/native/MemoryInstrumentationTests.cpp b/src/dawn/tests/unittests/native/MemoryInstrumentationTests.cpp
index 6b95337..360e30f 100644
--- a/src/dawn/tests/unittests/native/MemoryInstrumentationTests.cpp
+++ b/src/dawn/tests/unittests/native/MemoryInstrumentationTests.cpp
@@ -193,8 +193,6 @@
         .usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::TransientAttachment,
         .size = {.width = 30, .height = 20},
         .format = kRGBA8UnormTextureFormat,
-        .viewFormatCount = 1,
-        .viewFormats = &kRGBA8UnormTextureFormat,
     };
     wgpu::Texture transientAttachmentTexture =
         device.CreateTexture(&kTransientAttachmentTextureDesc);