WebGPU error handling 4: CommandEncoder for wire tests

These were the last use of CommandBufferBuilder in Dawn except for its
implementation in dawn_native so it is removed from dawn.json.

Also removes an already disabled test that's obsoleted by the error
handling rework.

BUG=dawn:8

Change-Id: Id2b8a3d5afcd73cc77cfcb09c6a3f851b9483aea
Reviewed-on: https://dawn-review.googlesource.com/c/4761
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/dawn.json b/dawn.json
index 7f48ac5..4267240 100644
--- a/dawn.json
+++ b/dawn.json
@@ -271,55 +271,6 @@
     "command buffer": {
         "category": "object"
     },
-    "command buffer builder": {
-        "category": "object",
-        "methods": [
-            {
-                "name": "get result",
-                "returns": "command buffer"
-            },
-            {
-                "name": "begin compute pass",
-                "returns": "compute pass encoder"
-            },
-            {
-                "name": "begin render pass",
-                "args": [
-                    {"name": "info", "type": "render pass descriptor"}
-                ],
-                "returns": "render pass encoder"
-            },
-            {
-                "name": "copy buffer to buffer",
-                "args": [
-                    {"name": "source", "type": "buffer"},
-                    {"name": "source offset", "type": "uint32_t"},
-                    {"name": "destination", "type": "buffer"},
-                    {"name": "destination offset", "type": "uint32_t"},
-                    {"name": "size", "type": "uint32_t"}
-                ],
-                "TODO": [
-                    "Restrictions on the alignment of the copy? Cf Metal on OSX"
-                ]
-            },
-            {
-                "name": "copy buffer to texture",
-                "args": [
-                    {"name": "source", "type": "buffer copy view", "annotation": "const*"},
-                    {"name": "destination", "type": "texture copy view", "annotation": "const*"},
-                    {"name": "copy size", "type": "extent 3D", "annotation": "const*"}
-                ]
-            },
-            {
-                "name": "copy texture to buffer",
-                "args": [
-                    {"name": "source", "type": "texture copy view", "annotation": "const*"},
-                    {"name": "destination", "type": "buffer copy view", "annotation": "const*"},
-                    {"name": "copy size", "type": "extent 3D", "annotation": "const*"}
-                ]
-            }
-        ]
-    },
     "command encoder": {
         "category": "object",
         "methods": [
@@ -466,10 +417,6 @@
                 "returns": "buffer builder"
             },
             {
-                "name": "create command buffer builder",
-                "returns": "command buffer builder"
-            },
-            {
                 "name": "create command encoder",
                 "returns": "command encoder"
             },
diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp
index 20ce906..4108df0 100644
--- a/src/tests/unittests/wire/WireArgumentTests.cpp
+++ b/src/tests/unittests/wire/WireArgumentTests.cpp
@@ -28,19 +28,19 @@
 
 // Test that the wire is able to send numerical values
 TEST_F(WireArgumentTests, ValueArgument) {
-    dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
-    dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(builder);
+    dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
+    dawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder);
     dawnComputePassEncoderDispatch(pass, 1, 2, 3);
 
-    dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice)).WillOnce(Return(apiBuilder));
+    dawnCommandEncoder apiEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder));
 
     dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
-    EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiBuilder)).WillOnce(Return(apiPass));
+    EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass));
 
     EXPECT_CALL(api, ComputePassEncoderDispatch(apiPass, 1, 2, 3)).Times(1);
 
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiEncoder));
     EXPECT_CALL(api, ComputePassEncoderRelease(apiPass));
     FlushClient();
 }
@@ -58,21 +58,21 @@
 }
 
 TEST_F(WireArgumentTests, ValueArrayArgument) {
-    dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
-    dawnComputePassEncoder pass = dawnCommandBufferBuilderBeginComputePass(builder);
+    dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
+    dawnComputePassEncoder pass = dawnCommandEncoderBeginComputePass(encoder);
     dawnComputePassEncoderSetPushConstants(pass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4,
                                            testPushConstantValues);
 
-    dawnCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice)).WillOnce(Return(apiBuilder));
+    dawnCommandEncoder apiEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice)).WillOnce(Return(apiEncoder));
 
     dawnComputePassEncoder apiPass = api.GetNewComputePassEncoder();
-    EXPECT_CALL(api, CommandBufferBuilderBeginComputePass(apiBuilder)).WillOnce(Return(apiPass));
+    EXPECT_CALL(api, CommandEncoderBeginComputePass(apiEncoder)).WillOnce(Return(apiPass));
 
     EXPECT_CALL(api,
                 ComputePassEncoderSetPushConstants(apiPass, DAWN_SHADER_STAGE_BIT_VERTEX, 0, 4,
                                                    ResultOf(CheckPushConstantValues, Eq(true))));
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiEncoder));
     EXPECT_CALL(api, ComputePassEncoderRelease(apiPass));
 
     FlushClient();
@@ -193,17 +193,17 @@
     EXPECT_CALL(api, RenderPassDescriptorBuilderGetResult(apiRenderPassBuilder))
         .WillOnce(Return(apiRenderPass));
 
-    // Create command buffer builder, setting render pass descriptor
-    dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
-    dawnCommandBufferBuilderBeginRenderPass(cmdBufBuilder, renderPass);
+    // Create command buffer encoder, setting render pass descriptor
+    dawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device);
+    dawnCommandEncoderBeginRenderPass(cmdBufEncoder, renderPass);
 
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
+    dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
+        .WillOnce(Return(apiCmdBufEncoder));
 
-    EXPECT_CALL(api, CommandBufferBuilderBeginRenderPass(apiCmdBufBuilder, apiRenderPass)).Times(1);
+    EXPECT_CALL(api, CommandEncoderBeginRenderPass(apiCmdBufEncoder, apiRenderPass)).Times(1);
 
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
     EXPECT_CALL(api, RenderPassDescriptorBuilderRelease(apiRenderPassBuilder));
     EXPECT_CALL(api, RenderPassDescriptorRelease(apiRenderPass));
     FlushClient();
@@ -215,21 +215,21 @@
     dawnCommandBuffer apiCmdBufs[2];
 
     // Create two command buffers we need to use a GMock sequence otherwise the order of the
-    // CreateCommandBufferBuilder might be swapped since they are equivalent in term of matchers
+    // CreateCommandEncoder might be swapped since they are equivalent in term of matchers
     Sequence s;
     for (int i = 0; i < 2; ++i) {
-        dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
-        cmdBufs[i] = dawnCommandBufferBuilderGetResult(cmdBufBuilder);
+        dawnCommandEncoder cmdBufEncoder = dawnDeviceCreateCommandEncoder(device);
+        cmdBufs[i] = dawnCommandEncoderFinish(cmdBufEncoder);
 
-        dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-        EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
+        dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+        EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
             .InSequence(s)
-            .WillOnce(Return(apiCmdBufBuilder));
+            .WillOnce(Return(apiCmdBufEncoder));
 
         apiCmdBufs[i] = api.GetNewCommandBuffer();
-        EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
+        EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder))
             .WillOnce(Return(apiCmdBufs[i]));
-        EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+        EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
         EXPECT_CALL(api, CommandBufferRelease(apiCmdBufs[i]));
     }
 
diff --git a/src/tests/unittests/wire/WireBasicTests.cpp b/src/tests/unittests/wire/WireBasicTests.cpp
index bb214b3..5fa7cce 100644
--- a/src/tests/unittests/wire/WireBasicTests.cpp
+++ b/src/tests/unittests/wire/WireBasicTests.cpp
@@ -26,59 +26,59 @@
 
 // One call gets forwarded correctly.
 TEST_F(WireBasicTests, CallForwarded) {
-    dawnDeviceCreateCommandBufferBuilder(device);
+    dawnDeviceCreateCommandEncoder(device);
 
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
+    dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
+        .WillOnce(Return(apiCmdBufEncoder));
 
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
     FlushClient();
 }
 
 // Test that calling methods on a new object works as expected.
 TEST_F(WireBasicTests, CreateThenCall) {
-    dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
-    dawnCommandBufferBuilderGetResult(builder);
+    dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
+    dawnCommandEncoderFinish(encoder);
 
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
+    dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
+        .WillOnce(Return(apiCmdBufEncoder));
 
     dawnCommandBuffer apiCmdBuf = api.GetNewCommandBuffer();
-    EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder)).WillOnce(Return(apiCmdBuf));
+    EXPECT_CALL(api, CommandEncoderFinish(apiCmdBufEncoder)).WillOnce(Return(apiCmdBuf));
 
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
     EXPECT_CALL(api, CommandBufferRelease(apiCmdBuf));
     FlushClient();
 }
 
 // Test that client reference/release do not call the backend API.
 TEST_F(WireBasicTests, RefCountKeptInClient) {
-    dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
+    dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
 
-    dawnCommandBufferBuilderReference(builder);
-    dawnCommandBufferBuilderRelease(builder);
+    dawnCommandEncoderReference(encoder);
+    dawnCommandEncoderRelease(encoder);
 
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+    dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
+        .WillOnce(Return(apiCmdBufEncoder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
 
     FlushClient();
 }
 
 // Test that client reference/release do not call the backend API.
 TEST_F(WireBasicTests, ReleaseCalledOnRefCount0) {
-    dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
+    dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
 
-    dawnCommandBufferBuilderRelease(builder);
+    dawnCommandEncoderRelease(encoder);
 
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
+    dawnCommandEncoder apiCmdBufEncoder = api.GetNewCommandEncoder();
+    EXPECT_CALL(api, DeviceCreateCommandEncoder(apiDevice))
+        .WillOnce(Return(apiCmdBufEncoder));
 
-    EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
+    EXPECT_CALL(api, CommandEncoderRelease(apiCmdBufEncoder));
 
     FlushClient();
 }
diff --git a/src/tests/unittests/wire/WireCallbackTests.cpp b/src/tests/unittests/wire/WireCallbackTests.cpp
index 64b68ac..6dfe828 100644
--- a/src/tests/unittests/wire/WireCallbackTests.cpp
+++ b/src/tests/unittests/wire/WireCallbackTests.cpp
@@ -250,56 +250,3 @@
 
     FlushServer();
 }
-
-// Test that the server doesn't forward calls to error objects or with error objects
-// Also test that when GetResult is called on an error builder, the error callback is fired
-// TODO(cwallez@chromium.org): This test is disabled because the introduction of encoders breaks
-// the assumptions of the "builder error" handling that a builder is self-contained. We need to
-// revisit this once the new error handling is in place.
-TEST_F(WireCallbackTests, DISABLED_CallsSkippedAfterBuilderError) {
-    dawnCommandBufferBuilder cmdBufBuilder = dawnDeviceCreateCommandBufferBuilder(device);
-    dawnCommandBufferBuilderSetErrorCallback(cmdBufBuilder, ToMockBuilderErrorCallback, 1, 2);
-
-    dawnRenderPassEncoder pass = dawnCommandBufferBuilderBeginRenderPass(cmdBufBuilder, nullptr);
-
-    dawnBufferBuilder bufferBuilder = dawnDeviceCreateBufferBuilderForTesting(device);
-    dawnBufferBuilderSetErrorCallback(bufferBuilder, ToMockBuilderErrorCallback, 3, 4);
-    dawnBuffer buffer = dawnBufferBuilderGetResult(bufferBuilder);  // Hey look an error!
-
-    // These calls will be skipped because of the error
-    dawnBufferSetSubData(buffer, 0, 0, nullptr);
-    dawnRenderPassEncoderSetIndexBuffer(pass, buffer, 0);
-    dawnRenderPassEncoderEndPass(pass);
-    dawnCommandBufferBuilderGetResult(cmdBufBuilder);
-
-    dawnCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
-        .WillOnce(Return(apiCmdBufBuilder));
-
-    dawnRenderPassEncoder apiPass = api.GetNewRenderPassEncoder();
-    EXPECT_CALL(api, CommandBufferBuilderBeginRenderPass(apiCmdBufBuilder, _))
-        .WillOnce(Return(apiPass));
-
-    dawnBufferBuilder apiBufferBuilder = api.GetNewBufferBuilder();
-    EXPECT_CALL(api, DeviceCreateBufferBuilderForTesting(apiDevice))
-        .WillOnce(Return(apiBufferBuilder));
-
-    // Hey look an error!
-    EXPECT_CALL(api, BufferBuilderGetResult(apiBufferBuilder))
-        .WillOnce(InvokeWithoutArgs([&]() -> dawnBuffer {
-            api.CallBuilderErrorCallback(apiBufferBuilder, DAWN_BUILDER_ERROR_STATUS_ERROR,
-                                         "Error");
-            return nullptr;
-        }));
-
-    EXPECT_CALL(api, BufferSetSubData(_, _, _, _)).Times(0);
-    EXPECT_CALL(api, RenderPassEncoderSetIndexBuffer(_, _, _)).Times(0);
-    EXPECT_CALL(api, CommandBufferBuilderGetResult(_)).Times(0);
-
-    FlushClient();
-
-    EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_ERROR, _, 1, 2)).Times(1);
-    EXPECT_CALL(*mockBuilderErrorCallback, Call(DAWN_BUILDER_ERROR_STATUS_ERROR, _, 3, 4)).Times(1);
-
-    FlushServer();
-}