Remove 0-value enums that aren't ever valid

Bug: 42241166
Change-Id: I01c387382cc8828ae738bfd9c5d8abe88671104e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/193360
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/common/WGSLFeatureMapping.h b/src/dawn/common/WGSLFeatureMapping.h
index 3c812dab..814e089 100644
--- a/src/dawn/common/WGSLFeatureMapping.h
+++ b/src/dawn/common/WGSLFeatureMapping.h
@@ -29,7 +29,6 @@
 #define SRC_DAWN_COMMON_WGSLFEATUREMAPPING_H_
 
 #define DAWN_FOREACH_WGSL_FEATURE(X)                                               \
-    X(kUndefined, Undefined)                                                       \
     /* ------------------------------------------------------------------------ */ \
     X(kPacked4X8IntegerDotProduct, Packed4x8IntegerDotProduct)                     \
     X(kPointerCompositeAccess, PointerCompositeAccess)                             \
diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json
index e73502e..0141ecd 100644
--- a/src/dawn/dawn.json
+++ b/src/dawn/dawn.json
@@ -2330,7 +2330,6 @@
         "category": "enum",
         "tags": ["dawn", "native"],
         "values": [
-            {"value": 0, "name": "undefined", "valid": false},
             {"value": 1, "name": "vk semaphore opaque FD"},
             {"value": 2, "name": "vk semaphore sync FD"},
             {"value": 3, "name": "vk semaphore zircon handle"},
@@ -2395,7 +2394,6 @@
     "feature name": {
         "category": "enum",
         "values": [
-            {"value": 0, "name": "undefined", "jsrepr": "undefined", "valid": false},
             {"value": 1, "name": "depth clip control"},
             {"value": 2, "name": "depth32 float stencil8"},
             {"value": 3, "name": "timestamp query"},
@@ -4320,7 +4318,6 @@
     "vertex format": {
         "category": "enum",
         "values": [
-            {"value": 0,  "name": "undefined", "jsrepr": "undefined", "valid": false},
             {"value": 1,  "name": "uint8x2"},
             {"value": 2,  "name": "uint8x4"},
             {"value": 3,  "name": "sint8x2"},
@@ -4357,7 +4354,6 @@
     "WGSL feature name": {
         "category": "enum",
         "values": [
-            {"value": 0, "name": "undefined", "valid": false, "jsrepr": "undefined"},
             {"value": 1, "name": "readonly and readwrite storage textures",  "jsrepr": "'readonly_and_readwrite_storage_textures'"},
             {"value": 2, "name": "packed 4x8 integer dot product", "jsrepr": "'packed_4x8_integer_dot_product'"},
             {"value": 3, "name": "unrestricted pointer parameters", "jsrepr": "'unrestricted_pointer_parameters'"},
@@ -4488,7 +4484,6 @@
         "category": "bitmask",
         "tags": ["dawn"],
         "values": [
-            {"value": 0, "name": "undefined", "valid": false},
             {"value": 1, "name": "device local"},
             {"value": 2, "name": "host visible"},
             {"value": 4, "name": "host coherent"},
diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp
index 614d394..efd7dfd 100644
--- a/src/dawn/native/Instance.cpp
+++ b/src/dawn/native/Instance.cpp
@@ -109,6 +109,8 @@
         return wgpu::WGSLFeatureName::WgpuName;
         DAWN_FOREACH_WGSL_FEATURE(CASE)
 #undef CASE
+        case tint::wgsl::LanguageFeature::kUndefined:
+            DAWN_UNREACHABLE();
     }
 }
 
@@ -651,7 +653,7 @@
                 break;
         }
 
-        if (enable) {
+        if (enable && wgslFeature != tint::wgsl::LanguageFeature::kUndefined) {
             mWGSLFeatures.emplace(ToWGPUFeature(wgslFeature));
             mTintLanguageFeatures.emplace(wgslFeature);
         }
@@ -662,15 +664,12 @@
         for (size_t i = 0; i < wgslBlocklist->blocklistedFeatureCount; i++) {
             const char* name = wgslBlocklist->blocklistedFeatures[i];
             tint::wgsl::LanguageFeature tintFeature = tint::wgsl::ParseLanguageFeature(name);
-            wgpu::WGSLFeatureName feature = ToWGPUFeature(tintFeature);
-
-            // Ignore unknown features in the blocklist.
-            if (feature == wgpu::WGSLFeatureName::Undefined) {
+            if (tintFeature == tint::wgsl::LanguageFeature::kUndefined) {
+                // Ignore unknown features in the blocklist.
                 continue;
             }
-
             mTintLanguageFeatures.erase(tintFeature);
-            mWGSLFeatures.erase(feature);
+            mWGSLFeatures.erase(ToWGPUFeature(tintFeature));
         }
     }
 }
diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp
index 89ad6ac..47590db 100644
--- a/src/dawn/native/RenderPipeline.cpp
+++ b/src/dawn/native/RenderPipeline.cpp
@@ -46,7 +46,7 @@
 
 static constexpr std::array<VertexFormatInfo, 32> sVertexFormatTable = {{
     //
-    {wgpu::VertexFormat::Undefined, 0, 0, VertexFormatBaseType::Float},
+    {wgpu::VertexFormat(0u), 0, 0, VertexFormatBaseType::Float},
 
     {wgpu::VertexFormat::Uint8x2, 2, 2, VertexFormatBaseType::Uint},
     {wgpu::VertexFormat::Uint8x4, 4, 4, VertexFormatBaseType::Uint},
@@ -85,8 +85,8 @@
 }};
 
 const VertexFormatInfo& GetVertexFormatInfo(wgpu::VertexFormat format) {
-    DAWN_ASSERT(format != wgpu::VertexFormat::Undefined);
     DAWN_ASSERT(static_cast<uint32_t>(format) < sVertexFormatTable.size());
+    DAWN_ASSERT(static_cast<uint32_t>(format) != 0u);
     DAWN_ASSERT(sVertexFormatTable[static_cast<uint32_t>(format)].format == format);
     return sVertexFormatTable[static_cast<uint32_t>(format)];
 }
diff --git a/src/dawn/native/SharedFence.cpp b/src/dawn/native/SharedFence.cpp
index db223c1..de53d1a 100644
--- a/src/dawn/native/SharedFence.cpp
+++ b/src/dawn/native/SharedFence.cpp
@@ -72,9 +72,9 @@
 void SharedFenceBase::DestroyImpl() {}
 
 MaybeError SharedFenceBase::ExportInfo(SharedFenceExportInfo* info) const {
-    // Set the type to undefined. It will be overwritten to the actual type
+    // Set the type to 0. It will be overwritten to the actual type
     // as long as no error occurs.
-    info->type = wgpu::SharedFenceType::Undefined;
+    info->type = wgpu::SharedFenceType(0);
 
     DAWN_TRY(GetDevice()->ValidateObject(this));
 
diff --git a/src/dawn/native/TintUtils.cpp b/src/dawn/native/TintUtils.cpp
index 1dd55f8..ff1cff9 100644
--- a/src/dawn/native/TintUtils.cpp
+++ b/src/dawn/native/TintUtils.cpp
@@ -119,9 +119,6 @@
             return tint::ast::transform::VertexFormat::kSint32x4;
         case wgpu::VertexFormat::Unorm10_10_10_2:
             return tint::ast::transform::VertexFormat::kUnorm10_10_10_2;
-
-        case wgpu::VertexFormat::Undefined:
-            break;
     }
     DAWN_UNREACHABLE();
 }
diff --git a/src/dawn/node/binding/Converter.cpp b/src/dawn/node/binding/Converter.cpp
index d562bd7..da9b847 100644
--- a/src/dawn/node/binding/Converter.cpp
+++ b/src/dawn/node/binding/Converter.cpp
@@ -191,7 +191,7 @@
 
 bool Converter::Convert(wgpu::TextureFormat& out, const interop::GPUTextureFormat& in) {
     out = wgpu::TextureFormat::Undefined;
-    wgpu::FeatureName requiredFeature = wgpu::FeatureName::Undefined;
+    wgpu::FeatureName requiredFeature = wgpu::FeatureName(0u);
     switch (in) {
         case interop::GPUTextureFormat::kR8Unorm:
             out = wgpu::TextureFormat::R8Unorm;
@@ -539,7 +539,7 @@
             return Throw(err.str());
     }
 
-    assert(requiredFeature != wgpu::FeatureName::Undefined);
+    assert(requiredFeature != wgpu::FeatureName(0u));
     if (!HasFeature(requiredFeature)) {
         std::stringstream err;
         err << "" << out << " requires feature '" << requiredFeature << "'";
@@ -1116,7 +1116,6 @@
 }
 
 bool Converter::Convert(wgpu::VertexFormat& out, const interop::GPUVertexFormat& in) {
-    out = wgpu::VertexFormat::Undefined;
     switch (in) {
         case interop::GPUVertexFormat::kUint8X2:
             out = wgpu::VertexFormat::Uint8x2;
@@ -1547,7 +1546,6 @@
         case wgpu::FeatureName::StaticSamplers:
         case wgpu::FeatureName::SurfaceCapabilities:
         case wgpu::FeatureName::TransientAttachments:
-        case wgpu::FeatureName::Undefined:
         case wgpu::FeatureName::YCbCrVulkanSamplers:
         case wgpu::FeatureName::DawnLoadResolveTexture:
             return false;
@@ -1588,7 +1586,6 @@
             out = interop::WGSLFeatureName::kPointerCompositeAccess;
             return true;
 
-        case wgpu::WGSLFeatureName::Undefined:
         case wgpu::WGSLFeatureName::ChromiumTestingUnimplemented:
         case wgpu::WGSLFeatureName::ChromiumTestingUnsafeExperimental:
         case wgpu::WGSLFeatureName::ChromiumTestingExperimental:
diff --git a/src/dawn/node/binding/GPUAdapter.cpp b/src/dawn/node/binding/GPUAdapter.cpp
index c63b1c6..a48f2fc 100644
--- a/src/dawn/node/binding/GPUAdapter.cpp
+++ b/src/dawn/node/binding/GPUAdapter.cpp
@@ -140,7 +140,7 @@
     Converter conv(env);
     std::vector<wgpu::FeatureName> requiredFeatures;
     for (auto required : descriptor.requiredFeatures) {
-        wgpu::FeatureName feature = wgpu::FeatureName::Undefined;
+        wgpu::FeatureName feature;
 
         // requiredFeatures is a "sequence<GPUFeatureName>" so a Javascript exception should be
         // thrown if one of the strings isn't one of the known features.
diff --git a/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp b/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp
index a9b4dac..7e62f5a 100644
--- a/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp
+++ b/src/dawn/tests/white_box/SharedTextureMemoryTests.cpp
@@ -835,7 +835,7 @@
 
     // Expect that exporting the fence info writes Undefined, and generates an error.
     ASSERT_DEVICE_ERROR(fence.ExportInfo(&exportInfo));
-    EXPECT_EQ(exportInfo.type, wgpu::SharedFenceType::Undefined);
+    EXPECT_EQ(exportInfo.type, wgpu::SharedFenceType(0));
 }
 
 // Test importing a shared texture memory when the device is destroyed
diff --git a/src/dawn/tests/white_box/SharedTextureMemoryTests_apple.mm b/src/dawn/tests/white_box/SharedTextureMemoryTests_apple.mm
index a9f6dbd..fa7cdcf 100644
--- a/src/dawn/tests/white_box/SharedTextureMemoryTests_apple.mm
+++ b/src/dawn/tests/white_box/SharedTextureMemoryTests_apple.mm
@@ -111,7 +111,7 @@
         struct IOSurfaceFormat {
             uint32_t format;
             uint32_t bytesPerElement;
-            wgpu::FeatureName requiredFeature = wgpu::FeatureName::Undefined;
+            wgpu::FeatureName requiredFeature = wgpu::FeatureName(0u);
         };
         const std::array<IOSurfaceFormat, 17> kFormats{
             {{kCVPixelFormatType_64RGBAHalf, 8},
@@ -163,7 +163,7 @@
 
                 std::vector<wgpu::SharedTextureMemory> perDeviceMemories;
                 for (auto& device : devices) {
-                    if (f.requiredFeature != wgpu::FeatureName::Undefined &&
+                    if (f.requiredFeature != wgpu::FeatureName(0u) &&
                         !device.HasFeature(f.requiredFeature)) {
                         continue;
                     }
diff --git a/src/dawn/tests/white_box/SharedTextureMemoryTests_win.cpp b/src/dawn/tests/white_box/SharedTextureMemoryTests_win.cpp
index 55be141..81dbede 100644
--- a/src/dawn/tests/white_box/SharedTextureMemoryTests_win.cpp
+++ b/src/dawn/tests/white_box/SharedTextureMemoryTests_win.cpp
@@ -204,7 +204,7 @@
 
         struct D3DFormat {
             DXGI_FORMAT format;
-            wgpu::FeatureName requiredFeature = wgpu::FeatureName::Undefined;
+            wgpu::FeatureName requiredFeature = wgpu::FeatureName(0u);
         };
         std::vector<D3DFormat> formats = {{
             {DXGI_FORMAT_R16G16B16A16_FLOAT},
@@ -255,7 +255,7 @@
                         desc.nextInChain = &texture2DDesc;
 
                         for (auto& device : devices) {
-                            if (f.requiredFeature != wgpu::FeatureName::Undefined &&
+                            if (f.requiredFeature != wgpu::FeatureName(0u) &&
                                 !device.HasFeature(f.requiredFeature)) {
                                 continue;
                             }
@@ -286,7 +286,7 @@
                         desc.label = label.c_str();
 
                         for (auto& device : devices) {
-                            if (f.requiredFeature != wgpu::FeatureName::Undefined &&
+                            if (f.requiredFeature != wgpu::FeatureName(0u) &&
                                 !device.HasFeature(f.requiredFeature)) {
                                 continue;
                             }
diff --git a/src/dawn/utils/TestUtils.cpp b/src/dawn/utils/TestUtils.cpp
index 3a4ece8..575a76c 100644
--- a/src/dawn/utils/TestUtils.cpp
+++ b/src/dawn/utils/TestUtils.cpp
@@ -201,8 +201,6 @@
         case wgpu::VertexFormat::Uint32x4:
         case wgpu::VertexFormat::Sint32x4:
             return 16;
-        case wgpu::VertexFormat::Undefined:
-            break;
     }
     DAWN_UNREACHABLE();
 }
diff --git a/src/dawn/wire/SupportedFeatures.cpp b/src/dawn/wire/SupportedFeatures.cpp
index dd0f06d..bf20f3d 100644
--- a/src/dawn/wire/SupportedFeatures.cpp
+++ b/src/dawn/wire/SupportedFeatures.cpp
@@ -33,7 +33,6 @@
 // of limit structs on Adapter/Device initialization.
 bool IsFeatureSupported(WGPUFeatureName feature) {
     switch (feature) {
-        case WGPUFeatureName_Undefined:
         case WGPUFeatureName_Force32:
         case WGPUFeatureName_DawnNative:
         case WGPUFeatureName_ImplicitDeviceSynchronization:
diff --git a/src/dawn/wire/client/Instance.cpp b/src/dawn/wire/client/Instance.cpp
index b63845b..e5ca6e9 100644
--- a/src/dawn/wire/client/Instance.cpp
+++ b/src/dawn/wire/client/Instance.cpp
@@ -137,6 +137,8 @@
         return WGPUWGSLFeatureName_##WgpuName;
         DAWN_FOREACH_WGSL_FEATURE(CASE)
 #undef CASE
+        case tint::wgsl::LanguageFeature::kUndefined:
+            DAWN_UNREACHABLE();
     }
 }
 
@@ -311,7 +313,7 @@
                 break;
         }
 
-        if (enable) {
+        if (enable && wgslFeature != tint::wgsl::LanguageFeature::kUndefined) {
             mWGSLFeatures.emplace(ToWGPUFeature(wgslFeature));
         }
     }
@@ -321,14 +323,11 @@
         for (size_t i = 0; i < wgslBlocklist->blocklistedFeatureCount; i++) {
             const char* name = wgslBlocklist->blocklistedFeatures[i];
             tint::wgsl::LanguageFeature tintFeature = tint::wgsl::ParseLanguageFeature(name);
-            WGPUWGSLFeatureName feature = ToWGPUFeature(tintFeature);
-
-            // Ignore unknown features in the blocklist.
-            if (feature == WGPUWGSLFeatureName_Undefined) {
+            if (tintFeature == tint::wgsl::LanguageFeature::kUndefined) {
+                // Ignore unknown features in the blocklist.
                 continue;
             }
-
-            mWGSLFeatures.erase(feature);
+            mWGSLFeatures.erase(ToWGPUFeature(tintFeature));
         }
     }
 }