Add wgpu::Device::ValidateTextureDescriptor

Bug: chromium:1266549
Change-Id: Iaef63ca6f4e447450953dfb0633b43931d8c2552
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116294
Reviewed-by: Brandon Jones <bajones@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/dawn.json b/dawn.json
index a04ce3f..389808f 100644
--- a/dawn.json
+++ b/dawn.json
@@ -1229,6 +1229,13 @@
                 "args": [
                     {"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
                 ]
+            },
+            {
+                "name": "validate texture descriptor",
+                "tags": ["dawn"],
+                "args": [
+                    {"name": "descriptor", "type": "texture descriptor", "annotation": "const*"}
+                ]
             }
         ]
     },
diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp
index 23607a1..9761935 100644
--- a/src/dawn/native/Device.cpp
+++ b/src/dawn/native/Device.cpp
@@ -1386,6 +1386,10 @@
     HandleError(FromWGPUErrorType(type), message);
 }
 
+void DeviceBase::APIValidateTextureDescriptor(const TextureDescriptor* desc) {
+    ConsumedError(ValidateTextureDescriptor(this, desc));
+}
+
 QueueBase* DeviceBase::GetQueue() const {
     ASSERT(mQueue != nullptr);
     return mQueue.Get();
diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h
index bfba109..467a4f8 100644
--- a/src/dawn/native/Device.h
+++ b/src/dawn/native/Device.h
@@ -284,6 +284,7 @@
     size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
     void APIInjectError(wgpu::ErrorType type, const char* message);
     bool APITick();
+    void APIValidateTextureDescriptor(const TextureDescriptor* desc);
 
     void APISetDeviceLostCallback(wgpu::DeviceLostCallback callback, void* userdata);
     void APISetUncapturedErrorCallback(wgpu::ErrorCallback callback, void* userdata);
diff --git a/src/dawn/tests/unittests/validation/TextureValidationTests.cpp b/src/dawn/tests/unittests/validation/TextureValidationTests.cpp
index 9708ef4..9b25928 100644
--- a/src/dawn/tests/unittests/validation/TextureValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/TextureValidationTests.cpp
@@ -997,4 +997,19 @@
     CheckTextureMatchesDescriptor(tex, desc);
 }
 
+// A tiny test that Device::ValidateTextureDescriptor works, under the assumption that all the
+// texture validation logic is implemented through it (so there is no need to re-test every possible
+// failure case).
+TEST_F(TextureValidationTest, APIValidateTextureDescriptor) {
+    wgpu::TextureDescriptor desc;
+    desc.format = wgpu::TextureFormat::RGBA8Unorm;
+    desc.size = {1, 1, 1};
+    desc.usage = wgpu::TextureUsage::RenderAttachment;
+
+    device.ValidateTextureDescriptor(&desc);
+
+    desc.size.width = 0;
+    ASSERT_DEVICE_ERROR(device.ValidateTextureDescriptor(&desc));
+}
+
 }  // namespace