webgpu.h: Reserve 0 for enums, in a few more possibly-breaking cases

These enums should be required to be set explicitly, so 0 is now
supposed to be invalid (where previously zero-init would just give you
the 0th enum value).

- AlphaMode is used in CopyTextureForBrowser. Since Chromium tests run
  on CQ, any breakage here should be caught (except it's known that the
  reftests aren't running on CQ and could hit this. I've run those
  locally.)
  - It is also reordered to sort-of mirror GPUCanvasAlphaMode even
    though it is not the same thing.
- QueryType is used in QuerySetDescriptor. Since there's no reasonable
  default here it's less likely anyone has written code that's using
  zero-init to get occlusion queries, but there could be.

Bug: dawn:2224
Change-Id: I0e74b37baa7b164ee6f3ad4fe05e91d91e25f104
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/166388
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
diff --git a/dawn.json b/dawn.json
index 2123021..befb134 100644
--- a/dawn.json
+++ b/dawn.json
@@ -1022,9 +1022,9 @@
         "category": "enum",
         "tags": ["dawn"],
         "values": [
-            {"value": 0, "name": "premultiplied"},
-            {"value": 1, "name": "unpremultiplied"},
-            {"value": 2, "name": "opaque"}
+            {"value": 1, "name": "opaque"},
+            {"value": 2, "name": "premultiplied"},
+            {"value": 3, "name": "unpremultiplied"}
         ]
     },
     "copy texture for browser options": {
@@ -2086,6 +2086,7 @@
     "callback mode": {
         "category": "enum",
         "emscripten_no_enum_table": true,
+        "_comment": "TODO(crbug.com/dawn/2224): Should this be renumbered to reserve 0?",
         "values": [
             {"value": 0, "name": "wait any only"},
             {"value": 1, "name": "allow process events"},
@@ -2278,6 +2279,7 @@
     "present mode": {
         "category": "enum",
         "emscripten_no_enum_table": true,
+        "_comment": "TODO(crbug.com/dawn/2224): Should this be renumbered to reserve 0?",
         "values": [
             {"value": 0, "name": "fifo"},
             {"value": 1, "name": "fifo relaxed", "tags": ["upstream"]},
@@ -2340,8 +2342,8 @@
     "query type": {
         "category": "enum",
         "values": [
-            {"value": 0, "name": "occlusion"},
-            {"value": 1, "name": "timestamp"}
+            {"value": 1, "name": "occlusion"},
+            {"value": 2, "name": "timestamp"}
         ]
     },
     "queue": {
diff --git a/src/dawn/tests/end2end/CopyTextureForBrowserTests.cpp b/src/dawn/tests/end2end/CopyTextureForBrowserTests.cpp
index 7319827..cac8c7e 100644
--- a/src/dawn/tests/end2end/CopyTextureForBrowserTests.cpp
+++ b/src/dawn/tests/end2end/CopyTextureForBrowserTests.cpp
@@ -25,6 +25,7 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#include <string>
 #include <vector>
 
 #include "dawn/common/Constants.h"
@@ -245,9 +246,9 @@
             0,
             0,  // uvec2, subrect copy dst origin
             0,
-            0,  // uvec2, subrect copy size
-            0,  // srcAlphaMode, wgpu::AlphaMode::Premultiplied
-            0   // dstAlphaMode, wgpu::AlphaMode::Premultiplied
+            0,                                                      // uvec2, subrect copy size
+            static_cast<uint32_t>(wgpu::AlphaMode::Premultiplied),  // srcAlphaMode
+            static_cast<uint32_t>(wgpu::AlphaMode::Premultiplied),  // dstAlphaMode
         };
 
         wgpu::BufferDescriptor uniformBufferDesc = {};
@@ -260,7 +261,8 @@
     // shader) instead of CPU after executing CopyTextureForBrowser() to avoid the errors caused by
     // comparing a value generated on CPU to the one generated on GPU.
     wgpu::ComputePipeline MakeTestPipeline() {
-        wgpu::ShaderModule csModule = utils::CreateShaderModule(this->device, R"(
+        std::string shader =
+            R"(
             struct Uniforms {
                 dstTextureFlipY : u32,
                 channelCount    : u32,
@@ -311,9 +313,12 @@
 
                     // Expect the dst texture channels should be all equal to alpha value
                     // after premultiply.
-                    let premultiplied = 0u;
-                    let unpremultiplied = 1u;
-                    let opaque = 2u;
+                    let premultiplied = )" +
+            std::to_string(static_cast<uint32_t>(wgpu::AlphaMode::Premultiplied)) + R"(u;
+                    let unpremultiplied = )" +
+            std::to_string(static_cast<uint32_t>(wgpu::AlphaMode::Unpremultiplied)) + R"(u;
+                    let opaque = )" +
+            std::to_string(static_cast<uint32_t>(wgpu::AlphaMode::Opaque)) + R"(u;
                     if (uniforms.srcAlphaMode == opaque) {
                         srcColor.a = 1.0;
                     }
@@ -361,7 +366,8 @@
                     output.result[outputIndex] = 0u;
                 }
             }
-         )");
+         )";
+        wgpu::ShaderModule csModule = utils::CreateShaderModule(this->device, shader.c_str());
 
         wgpu::ComputePipelineDescriptor csDesc;
         csDesc.compute.module = csModule;