[headers] Remove the Flags enums and make them 64-bit

Force32 values are kept since some clients still use them.

Also fix up some MapMode bitmasks that should have been BufferUsage
bitmasks. Fortuantely the actual values are the same.

Bug: 42241186
Change-Id: Ic41e547e1610d234cfd1bcfa363dc284842111a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/196194
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 2419bbc..5f344d3 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -911,14 +911,6 @@
     else:
         return c_prefix + name.CamelCase()
 
-
-def as_cReturnType(c_prefix, typ):
-    if typ.category != 'bitmask':
-        return as_cType(c_prefix, typ.name)
-    else:
-        return as_cType(c_prefix, typ.name) + 'Flags'
-
-
 def as_cppType(name):
     # Special case for 'bool' because it has a typedef for compatibility.
     if name.native and name.get() != 'bool':
@@ -1085,8 +1077,6 @@
     c_prefix = metadata.c_prefix
 
     def as_cTypeEnumSpecialCase(typ):
-        if typ.category == 'bitmask':
-            return as_cType(c_prefix, typ.name) + 'Flags'
         return as_cType(c_prefix, typ.name)
 
     def as_cEnum(type_name, value_name):
@@ -1130,7 +1120,6 @@
             'as_CppMethodSuffix': as_CppMethodSuffix,
             'as_cProc': as_cProc,
             'as_cType': lambda name: as_cType(c_prefix, name),
-            'as_cReturnType': lambda typ: as_cReturnType(c_prefix, typ),
             'as_cppType': as_cppType,
             'as_jsEnumValue': as_jsEnumValue,
             'convert_cType_to_cppType': convert_cType_to_cppType,
diff --git a/generator/templates/api.h b/generator/templates/api.h
index c6c80fb..16f5166 100644
--- a/generator/templates/api.h
+++ b/generator/templates/api.h
@@ -89,7 +89,7 @@
     #define {{API}}_{{constant.name.SNAKE_CASE()}} {{constant.value}}
 {% endfor %}
 
-typedef uint32_t {{API}}Flags;
+typedef uint64_t {{API}}Flags;
 typedef uint32_t {{API}}Bool;
 
 {% for type in by_category["object"] %}
@@ -101,18 +101,27 @@
     struct {{as_cType(type.name)}};
 {% endfor %}
 
-{% for type in by_category["enum"] + by_category["bitmask"] %}
+{% for type in by_category["enum"] %}
     typedef enum {{as_cType(type.name)}} {
         {% for value in type.values %}
             {{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "08X")}},
         {% endfor %}
         {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF
     } {{as_cType(type.name)}} {{API}}_ENUM_ATTRIBUTE;
-    {% if type.category == "bitmask" %}
-        typedef {{API}}Flags {{as_cType(type.name)}}Flags {{API}}_ENUM_ATTRIBUTE;
-    {% endif %}
+{% endfor %}
 
+{% for type in by_category["bitmask"] %}
+    //* TODO(crbug.com/42241186): Remove one of these, based on resolution of what the name is:
+    //* https://github.com/webgpu-native/webgpu-headers/issues/273#issuecomment-2195951806
+    typedef {{API}}Flags {{as_cType(type.name)}};
+    typedef {{API}}Flags {{as_cType(type.name)}}Flags;
+    {% for value in type.values %}
+        static const {{as_cType(type.name)}} {{as_cEnum(type.name, value.name)}} = 0x{{format(value.value, "016X")}};
+    {% endfor %}
+    //* TODO(crbug.com/42241186): Remove Force32 values
+    static const {{as_cType(type.name)}} {{as_cEnum(type.name, Name("force32"))}} = 0x7FFFFFFF;
 {% endfor -%}
+
 {% for type in by_category["function pointer"] %}
     typedef {{as_cType(type.return_type.name)}} (*{{as_cType(type.name)}})(
         {%- if type.arguments == [] -%}
@@ -245,7 +254,7 @@
 {% for type in by_category["object"] if len(c_methods(type)) > 0 %}
     // Procs of {{type.name.CamelCase()}}
     {% for method in c_methods(type) %}
-        typedef {{as_cReturnType(method.return_type)}} (*{{as_cProc(type.name, method.name)}})(
+        typedef {{as_cType(method.return_type.name)}} (*{{as_cProc(type.name, method.name)}})(
             {{-as_cType(type.name)}} {{as_varName(type.name)}}
             {%- for arg in method.arguments -%}
                 ,{{" "}}
@@ -274,7 +283,7 @@
 {% for type in by_category["object"] if len(c_methods(type)) > 0 %}
     // Methods of {{type.name.CamelCase()}}
     {% for method in c_methods(type) %}
-        {{API}}_EXPORT {{as_cReturnType(method.return_type)}} {{as_cMethod(type.name, method.name)}}(
+        {{API}}_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
             {{-as_cType(type.name)}} {{as_varName(type.name)}}
             {%- for arg in method.arguments -%}
                 ,{{" "}}
diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h
index 116873f..fbd6f8e 100644
--- a/generator/templates/api_cpp.h
+++ b/generator/templates/api_cpp.h
@@ -107,8 +107,8 @@
 
 {% for type in by_category["bitmask"] %}
     {% set CppType = as_cppType(type.name) %}
-    {% set CType = as_cType(type.name) + "Flags" %}
-    enum class {{CppType}} : uint32_t {
+    {% set CType = as_cType(type.name) %}
+    enum class {{CppType}} : uint64_t {
         {% for value in type.values %}
             {{as_cppEnum(value.name)}} = {{as_cEnum(type.name, value.name)}},
         {% endfor %}
diff --git a/generator/templates/dawn/native/ProcTable.cpp b/generator/templates/dawn/native/ProcTable.cpp
index dcc7370..0a37751 100644
--- a/generator/templates/dawn/native/ProcTable.cpp
+++ b/generator/templates/dawn/native/ProcTable.cpp
@@ -49,7 +49,7 @@
         {% for method in c_methods(type) %}
             {% set suffix = as_MethodSuffix(type.name, method.name) %}
 
-            {{as_cReturnType(method.return_type)}} Native{{suffix}}(
+            {{as_cType(method.return_type.name)}} Native{{suffix}}(
                 {{-as_cType(type.name)}} cSelf
                 {%- for arg in method.arguments -%}
                     , {{as_annotated_cType(arg)}}
diff --git a/generator/templates/dawn/native/api_dawn_native_proc.cpp b/generator/templates/dawn/native/api_dawn_native_proc.cpp
index f39e023..e399cd6 100644
--- a/generator/templates/dawn/native/api_dawn_native_proc.cpp
+++ b/generator/templates/dawn/native/api_dawn_native_proc.cpp
@@ -40,7 +40,7 @@
 {% endfor %}
 {% for type in by_category["object"] %}
     {% for method in c_methods(type) %}
-        extern {{as_cReturnType(method.return_type)}} Native{{as_MethodSuffix(type.name, method.name)}}(
+        extern {{as_cType(method.return_type.name)}} Native{{as_MethodSuffix(type.name, method.name)}}(
             {{-as_cType(type.name)}} cSelf
             {%- for arg in method.arguments -%}
                 , {{as_annotated_cType(arg)}}
@@ -70,7 +70,7 @@
 
     {% for type in by_category["object"] %}
         {% for method in c_methods(type) %}
-            {{as_cReturnType(method.return_type)}} {{metadata.namespace}}{{as_MethodSuffix(type.name, method.name)}}(
+            {{as_cType(method.return_type.name)}} {{metadata.namespace}}{{as_MethodSuffix(type.name, method.name)}}(
                 {{-as_cType(type.name)}} cSelf
                 {%- for arg in method.arguments -%}
                     , {{as_annotated_cType(arg)}}
diff --git a/generator/templates/dawn/native/dawn_platform.h b/generator/templates/dawn/native/dawn_platform.h
index af0d1aa..6855f96 100644
--- a/generator/templates/dawn/native/dawn_platform.h
+++ b/generator/templates/dawn/native/dawn_platform.h
@@ -112,7 +112,9 @@
         inline {{as_cType(type.name)}} ToAPI({{namespace}}::{{as_cppType(type.name)}} rhs) {
             return static_cast<{{as_cType(type.name)}}>(rhs);
         }
+    {% endfor %}
 
+    {% for type in by_category["enum"] %}
         inline {{namespace}}::{{as_cppType(type.name)}} FromAPI({{as_cType(type.name)}} rhs) {
             return static_cast<{{namespace}}::{{as_cppType(type.name)}}>(rhs);
         }
diff --git a/generator/templates/dawn/wire/WireCmd.cpp b/generator/templates/dawn/wire/WireCmd.cpp
index efcfe0e..dd92f2e 100644
--- a/generator/templates/dawn/wire/WireCmd.cpp
+++ b/generator/templates/dawn/wire/WireCmd.cpp
@@ -59,8 +59,6 @@
         ObjectId
     {%- elif member.type.category == "structure" -%}
         {{as_cType(member.type.name)}}Transfer
-    {%- elif member.type.category == "bitmask" -%}
-        {{as_cType(member.type.name)}}Flags
     {%- elif as_cType(member.type.name) == "size_t" -%}
         {{as_cType(types["uint64_t"].name)}}
     {%- else -%}
diff --git a/generator/templates/dawn/wire/client/ApiProcs.cpp b/generator/templates/dawn/wire/client/ApiProcs.cpp
index 623d228..45a8510 100644
--- a/generator/templates/dawn/wire/client/ApiProcs.cpp
+++ b/generator/templates/dawn/wire/client/ApiProcs.cpp
@@ -62,7 +62,7 @@
     {% for method in type.methods %}
         {% set Suffix = as_MethodSuffix(type.name, method.name) %}
 
-        DAWN_WIRE_EXPORT {{as_cReturnType(method.return_type)}} {{as_cMethodNamespaced(type.name, method.name, Name('dawn wire client'))}}(
+        DAWN_WIRE_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethodNamespaced(type.name, method.name, Name('dawn wire client'))}}(
             {{-cType}} cSelf
             {%- for arg in method.arguments -%}
                 , {{as_annotated_cType(arg)}}
diff --git a/generator/templates/dawn/wire/client/api.h b/generator/templates/dawn/wire/client/api.h
index d287001..30c77f7 100644
--- a/generator/templates/dawn/wire/client/api.h
+++ b/generator/templates/dawn/wire/client/api.h
@@ -51,7 +51,7 @@
 {% for type in by_category["object"] if len(c_methods(type)) > 0 %}
     // Methods of {{type.name.CamelCase()}}
     {% for method in c_methods(type) %}
-        DAWN_WIRE_EXPORT {{as_cReturnType(method.return_type)}} {{as_cMethodNamespaced(type.name, method.name, Name('dawn wire client'))}}(
+        DAWN_WIRE_EXPORT {{as_cType(method.return_type.name)}} {{as_cMethodNamespaced(type.name, method.name, Name('dawn wire client'))}}(
             {{-as_cType(type.name)}} {{as_varName(type.name)}}
             {%- for arg in method.arguments -%}
                 ,{{" "}}
diff --git a/generator/templates/dawn_proc.cpp b/generator/templates/dawn_proc.cpp
index 57c52d9..9a2981b 100644
--- a/generator/templates/dawn_proc.cpp
+++ b/generator/templates/dawn_proc.cpp
@@ -81,7 +81,7 @@
 {% for type in by_category["object"] %}
     {% for method in c_methods(type) %}
         DAWN_NO_SANITIZE("cfi-icall")
-        {{as_cReturnType(method.return_type)}} {{as_cMethod(type.name, method.name)}}(
+        {{as_cType(method.return_type.name)}} {{as_cMethod(type.name, method.name)}}(
             {{-as_cType(type.name)}} {{as_varName(type.name)}}
             {%- for arg in method.arguments -%}
                 , {{as_annotated_cType(arg)}}
diff --git a/generator/templates/dawn_thread_dispatch_proc.cpp b/generator/templates/dawn_thread_dispatch_proc.cpp
index da8947b..2d77212 100644
--- a/generator/templates/dawn_thread_dispatch_proc.cpp
+++ b/generator/templates/dawn_thread_dispatch_proc.cpp
@@ -45,7 +45,7 @@
 
 {% for type in by_category["object"] %}
     {% for method in c_methods(type) %}
-        static {{as_cReturnType(method.return_type)}} ThreadDispatch{{as_MethodSuffix(type.name, method.name)}}(
+        static {{as_cType(method.return_type.name)}} ThreadDispatch{{as_MethodSuffix(type.name, method.name)}}(
             {{-as_cType(type.name)}} {{as_varName(type.name)}}
             {%- for arg in method.arguments -%}
                 , {{as_annotated_cType(arg)}}
diff --git a/src/dawn/tests/unittests/validation/ErrorScopeValidationTests.cpp b/src/dawn/tests/unittests/validation/ErrorScopeValidationTests.cpp
index 60ad2ac..e3c0587 100644
--- a/src/dawn/tests/unittests/validation/ErrorScopeValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/ErrorScopeValidationTests.cpp
@@ -63,7 +63,7 @@
     device.PushErrorScope(wgpu::ErrorFilter::Validation);
 
     wgpu::BufferDescriptor desc = {};
-    desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
+    desc.usage = static_cast<wgpu::BufferUsage>(UINT64_MAX);
     device.CreateBuffer(&desc);
 
     EXPECT_CALL(mPopErrorScopeCb,
@@ -79,7 +79,7 @@
     device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
 
     wgpu::BufferDescriptor desc = {};
-    desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
+    desc.usage = static_cast<wgpu::BufferUsage>(UINT64_MAX);
     device.CreateBuffer(&desc);
 
     // OutOfMemory does not match Validation error.
@@ -103,7 +103,7 @@
     device.PushErrorScope(wgpu::ErrorFilter::Validation);
 
     wgpu::BufferDescriptor desc = {};
-    desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
+    desc.usage = static_cast<wgpu::BufferUsage>(UINT64_MAX);
     device.CreateBuffer(&desc);
 
     // Inner scope catches the error.
@@ -126,7 +126,7 @@
     device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
 
     wgpu::BufferDescriptor desc = {};
-    desc.usage = static_cast<wgpu::BufferUsage>(WGPUBufferUsage_Force32);
+    desc.usage = static_cast<wgpu::BufferUsage>(UINT64_MAX);
     ASSERT_DEVICE_ERROR(device.CreateBuffer(&desc));
 
     EXPECT_CALL(mPopErrorScopeCb,
diff --git a/src/dawn/tests/unittests/wire/WireBufferMappingTests.cpp b/src/dawn/tests/unittests/wire/WireBufferMappingTests.cpp
index a6d14b4..41d50bf 100644
--- a/src/dawn/tests/unittests/wire/WireBufferMappingTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireBufferMappingTests.cpp
@@ -93,7 +93,7 @@
     }
 
     void SetupBuffer(WGPUMapMode mapMode) {
-        WGPUBufferUsageFlags usage = WGPUBufferUsage_MapRead;
+        WGPUBufferUsage usage = WGPUBufferUsage_MapRead;
         if (mapMode == WGPUMapMode_Read) {
             usage = WGPUBufferUsage_MapRead;
         } else if (mapMode == WGPUMapMode_Write) {
diff --git a/src/dawn/wire/client/Buffer.cpp b/src/dawn/wire/client/Buffer.cpp
index 3b3412d..c73a236 100644
--- a/src/dawn/wire/client/Buffer.cpp
+++ b/src/dawn/wire/client/Buffer.cpp
@@ -479,7 +479,7 @@
     }
 }
 
-void Buffer::MapAsync(WGPUMapModeFlags mode,
+void Buffer::MapAsync(WGPUMapMode mode,
                       size_t offset,
                       size_t size,
                       WGPUBufferMapCallback callback,
@@ -491,7 +491,7 @@
     MapAsyncF(mode, offset, size, callbackInfo);
 }
 
-WGPUFuture Buffer::MapAsyncF(WGPUMapModeFlags mode,
+WGPUFuture Buffer::MapAsyncF(WGPUMapMode mode,
                              size_t offset,
                              size_t size,
                              const WGPUBufferMapCallbackInfo& callbackInfo) {
@@ -539,7 +539,7 @@
     return {futureIDInternal};
 }
 
-WGPUFuture Buffer::MapAsync2(WGPUMapModeFlags mode,
+WGPUFuture Buffer::MapAsync2(WGPUMapMode mode,
                              size_t offset,
                              size_t size,
                              const WGPUBufferMapCallbackInfo2& callbackInfo) {
diff --git a/src/dawn/wire/client/Buffer.h b/src/dawn/wire/client/Buffer.h
index c82b286..2462f7d 100644
--- a/src/dawn/wire/client/Buffer.h
+++ b/src/dawn/wire/client/Buffer.h
@@ -54,16 +54,16 @@
 
     ObjectType GetObjectType() const override;
 
-    void MapAsync(WGPUMapModeFlags mode,
+    void MapAsync(WGPUMapMode mode,
                   size_t offset,
                   size_t size,
                   WGPUBufferMapCallback callback,
                   void* userdata);
-    WGPUFuture MapAsyncF(WGPUMapModeFlags mode,
+    WGPUFuture MapAsyncF(WGPUMapMode mode,
                          size_t offset,
                          size_t size,
                          const WGPUBufferMapCallbackInfo& callbackInfo);
-    WGPUFuture MapAsync2(WGPUMapModeFlags mode,
+    WGPUFuture MapAsync2(WGPUMapMode mode,
                          size_t offset,
                          size_t size,
                          const WGPUBufferMapCallbackInfo2& callbackInfo);
diff --git a/src/dawn/wire/server/ObjectStorage.h b/src/dawn/wire/server/ObjectStorage.h
index 4cff98d..3b49c39 100644
--- a/src/dawn/wire/server/ObjectStorage.h
+++ b/src/dawn/wire/server/ObjectStorage.h
@@ -70,7 +70,7 @@
     std::unique_ptr<MemoryTransferService::ReadHandle> readHandle;
     std::unique_ptr<MemoryTransferService::WriteHandle> writeHandle;
     BufferMapWriteState mapWriteState = BufferMapWriteState::Unmapped;
-    WGPUBufferUsageFlags usage = WGPUBufferUsage_None;
+    WGPUBufferUsage usage = WGPUBufferUsage_None;
     // Indicate if writeHandle needs to be destroyed on unmap
     bool mappedAtCreation = false;
 };
diff --git a/src/dawn/wire/server/Server.h b/src/dawn/wire/server/Server.h
index 207c519..7b69099 100644
--- a/src/dawn/wire/server/Server.h
+++ b/src/dawn/wire/server/Server.h
@@ -128,7 +128,7 @@
     WGPUFuture future;
     uint64_t offset;
     uint64_t size;
-    WGPUMapModeFlags mode;
+    WGPUMapMode mode;
     uint8_t userdataCount;
 };
 
diff --git a/src/dawn/wire/server/ServerBuffer.cpp b/src/dawn/wire/server/ServerBuffer.cpp
index 73f1963..233fc03 100644
--- a/src/dawn/wire/server/ServerBuffer.cpp
+++ b/src/dawn/wire/server/ServerBuffer.cpp
@@ -40,7 +40,7 @@
     Known<WGPUBuffer> buffer;
     WIRE_TRY(Objects<WGPUBuffer>().Get(cmd.selfId, &buffer));
 
-    if (buffer->mappedAtCreation && !(buffer->usage & WGPUMapMode_Write)) {
+    if (buffer->mappedAtCreation && !(buffer->usage & WGPUBufferUsage_MapWrite)) {
         // This indicates the writeHandle is for mappedAtCreation only. Destroy on unmap
         // writeHandle could have possibly been deleted if buffer is already destroyed so we
         // don't assert it's non-null
@@ -68,7 +68,7 @@
 WireResult Server::DoBufferMapAsync(Known<WGPUBuffer> buffer,
                                     ObjectHandle eventManager,
                                     WGPUFuture future,
-                                    WGPUMapModeFlags mode,
+                                    WGPUMapMode mode,
                                     uint64_t offset64,
                                     uint64_t size64,
                                     uint8_t userdataCount) {
@@ -131,9 +131,9 @@
     buffer->mappedAtCreation = descriptor->mappedAtCreation;
 
     // isReadMode and isWriteMode could be true at the same time if usage contains
-    // WGPUMapMode_Read and buffer is mappedAtCreation
-    bool isReadMode = descriptor->usage & WGPUMapMode_Read;
-    bool isWriteMode = descriptor->usage & WGPUMapMode_Write || descriptor->mappedAtCreation;
+    // WGPUBufferUsage_MapRead and buffer is mappedAtCreation
+    bool isReadMode = descriptor->usage & WGPUBufferUsage_MapRead;
+    bool isWriteMode = descriptor->usage & WGPUBufferUsage_MapWrite || descriptor->mappedAtCreation;
 
     // This is the size of data deserialized from the command stream to create the read/write
     // handle, which must be CPU-addressable.