[dawn][native] Spanify TextureDescriptor and SurfaceConfiguration

Both have arrays for "viewFormats".

Bug: 515272358
Change-Id: Ib65a4da11f4ae40754e0d8c1b46debc86cc9583c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/320297
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/generator/templates/dawn/native/api_structs.cpp b/generator/templates/dawn/native/api_structs.cpp
index 44ed6f9..f7e9bd6 100644
--- a/generator/templates/dawn/native/api_structs.cpp
+++ b/generator/templates/dawn/native/api_structs.cpp
@@ -111,7 +111,9 @@
                 {% endif %}
                 {% for member in type.members %}
                     {% set memberName = member.name.camelCase() %}
-                    {% if member.requires_struct_defaulting %}
+                    {% if spanify and member.is_length %}
+                        //* Skip as the member is included in the span member.
+                    {% elif member.requires_struct_defaulting %}
                         {% if member.type.category == "structure" %}
                             copy.{{memberName}} = {{memberName}}.WithTrivialFrontendDefaults();
                         {% elif member.type.category == "enum" %}
diff --git a/src/dawn/dawn_native.json b/src/dawn/dawn_native.json
index 8f9ad26..0ca3a1c 100644
--- a/src/dawn/dawn_native.json
+++ b/src/dawn/dawn_native.json
@@ -71,8 +71,6 @@
             "SharedTextureMemoryDmaBufDescriptor",
             "SharedTextureMemoryEndAccessState",
             "SurfaceCapabilities",
-            "SurfaceConfiguration",
-            "TextureDescriptor",
             "VertexState"
         ],
         "structure_span_index_type_override": {
diff --git a/src/dawn/native/Surface.cpp b/src/dawn/native/Surface.cpp
index bdcbf45..9b449b8 100644
--- a/src/dawn/native/Surface.cpp
+++ b/src/dawn/native/Surface.cpp
@@ -255,7 +255,6 @@
     textureDesc.size = {config->width, config->height};
     textureDesc.format = config->format;
     textureDesc.dimension = wgpu::TextureDimension::e2D;
-    textureDesc.viewFormatCount = config->viewFormatCount;
     textureDesc.viewFormats = config->viewFormats;
 
     UnpackedPtr<TextureDescriptor> unpackedTextureDesc;
diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp
index 148bd41..b7e0192 100644
--- a/src/dawn/native/SwapChain.cpp
+++ b/src/dawn/native/SwapChain.cpp
@@ -47,8 +47,7 @@
     desc.dimension = wgpu::TextureDimension::e2D;
     desc.size = {swapChain->GetWidth(), swapChain->GetHeight(), 1};
     desc.format = swapChain->GetFormat();
-    desc.viewFormatCount = swapChain->GetViewFormats().size();
-    desc.viewFormats = swapChain->GetViewFormats().data();
+    desc.viewFormats = swapChain->GetViewFormats();
     desc.mipLevelCount = 1;
     desc.sampleCount = 1;
 
@@ -66,12 +65,12 @@
       mPresentMode(config->presentMode),
       mAlphaMode(config->alphaMode),
       mSurface(surface) {
-    for (uint32_t i = 0; i < config->viewFormatCount; ++i) {
-        if (DAWN_UNSAFE_TODO(config->viewFormats[i]) == config->format) {
+    for (wgpu::TextureFormat viewFormat : config->viewFormats) {
+        if (viewFormat == config->format) {
             // Skip our own format, like texture creations does.
             continue;
         }
-        mViewFormats.push_back(DAWN_UNSAFE_TODO(config->viewFormats[i]));
+        mViewFormats.push_back(viewFormat);
     }
 }
 
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index 25dbdbf..009de1d 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -33,6 +33,7 @@
 #include "absl/strings/str_format.h"
 #include "dawn/native/ValidationUtils_autogen.h"
 #include "src/dawn/common/Constants.h"
+#include "src/dawn/common/Enumerator.h"
 #include "src/dawn/common/HashUtils.h"
 #include "src/dawn/common/Math.h"
 #include "src/dawn/native/Adapter.h"
@@ -800,10 +801,9 @@
         }
     }
 
-    for (uint32_t i = 0; i < descriptor->viewFormatCount; ++i) {
-        DAWN_UNSAFE_TODO(DAWN_TRY_CONTEXT(
-            ValidateTextureViewFormatCompatibility(device, *format, descriptor->viewFormats[i]),
-            "validating viewFormats[%u]", i));
+    for (auto [i, viewFormat] : Enumerate(descriptor->viewFormats)) {
+        DAWN_TRY_CONTEXT(ValidateTextureViewFormatCompatibility(device, *format, viewFormat),
+                         "validating viewFormats[%u]", i);
     }
 
     DAWN_INVALID_IF(descriptor->usage == wgpu::TextureUsage::None,
@@ -816,7 +816,7 @@
             (descriptor->size.depthOrArrayLayers != 1 || descriptor->mipLevelCount != 1),
             "Transient textures must have depthOrArrayLayers (%u) = 1 and mipLevelCount (%u) = 1.",
             descriptor->size.depthOrArrayLayers, descriptor->mipLevelCount);
-        DAWN_INVALID_IF(descriptor->viewFormatCount > 0,
+        DAWN_INVALID_IF(!descriptor->viewFormats.empty(),
                         "Transient textures must not have any viewFormats");
     }
 
@@ -1075,14 +1075,13 @@
         mMipLevelCount * GetArrayLayers() * GetAspectCount(mFormat->aspects);
     mIsSubresourceContentInitializedAtIndex = std::vector<bool>(subresourceCount, false);
 
-    for (uint32_t i = 0; i < descriptor->viewFormatCount; ++i) {
-        if (DAWN_UNSAFE_TODO(descriptor->viewFormats[i]) == descriptor->format) {
+    for (wgpu::TextureFormat viewFormat : descriptor->viewFormats) {
+        if (viewFormat == descriptor->format) {
             // Skip our own format, so the backends don't allocate the texture for
             // reinterpretation if it's not needed.
             continue;
         }
-        mViewFormats[device->GetValidInternalFormat(DAWN_UNSAFE_TODO(descriptor->viewFormats[i]))] =
-            true;
+        mViewFormats[device->GetValidInternalFormat(viewFormat)] = true;
     }
 
     if (auto* internalUsageDesc = descriptor.Get<DawnTextureInternalUsageDescriptor>()) {
diff --git a/src/dawn/native/webgpu/CaptureContext.cpp b/src/dawn/native/webgpu/CaptureContext.cpp
index 72a35d4..178efaa 100644
--- a/src/dawn/native/webgpu/CaptureContext.cpp
+++ b/src/dawn/native/webgpu/CaptureContext.cpp
@@ -114,11 +114,8 @@
         return;
     }
 
-    std::vector<wgpu::TextureFormat> viewFormats;
-    for (uint32_t i = 0; i < config->viewFormatCount; ++i) {
-        viewFormats.push_back(DAWN_UNSAFE_TODO(config->viewFormats[i]));
-    }
-
+    std::vector<wgpu::TextureFormat> viewFormats{config->viewFormats.begin(),
+                                                 config->viewFormats.end()};
     schema::RootCommandSurfaceConfigureCmd cmd{{
         .data = {{
             .surfaceId = surfaceId,
diff --git a/src/dawn/native/webgpu/SwapChainWGPU.cpp b/src/dawn/native/webgpu/SwapChainWGPU.cpp
index 3d01dfd..c2d00f4 100644
--- a/src/dawn/native/webgpu/SwapChainWGPU.cpp
+++ b/src/dawn/native/webgpu/SwapChainWGPU.cpp
@@ -135,15 +135,16 @@
     }
     DAWN_ASSERT(innerSurface);
 
+    std::vector<WGPUTextureFormat> viewFormats;
+    for (wgpu::TextureFormat viewFormat : config->viewFormats) {
+        viewFormats.push_back(ToAPI(viewFormat));
+    }
+
     WGPUSurfaceConfiguration innerConfig = {};
     innerConfig.device = device->GetInnerHandle();
     innerConfig.format = ToAPI(config->format);
     innerConfig.usage = ToAPI(config->usage);
-    innerConfig.viewFormatCount = config->viewFormatCount;
-    std::vector<WGPUTextureFormat> viewFormats;
-    for (uint32_t i = 0; i < config->viewFormatCount; ++i) {
-        viewFormats.push_back(ToAPI(DAWN_UNSAFE_TODO(config->viewFormats[i])));
-    }
+    innerConfig.viewFormatCount = viewFormats.size();
     innerConfig.viewFormats = viewFormats.data();
     innerConfig.alphaMode = ToAPI(config->alphaMode);
     innerConfig.width = config->width;