WebGPU error handling 2: CommandEncoder for samples and end2end tests
CommandEncoder is the replacement for CommandBufferBuilder. This commit
adds the dawn.json definition for it and an initial implementation that
wraps CommandBufferBuilder. This is done so that the code can be ported
to CommandEncoder gradually, otherwise the commit would be too big and
would risk many merge conflicts.
This converts all samples and end2end tests to use CommandEncoder.
BUG=dawn:8
Change-Id: If4ce86e6fb39ba4e0c2af6328d40e63be17d18c1
Reviewed-on: https://dawn-review.googlesource.com/c/4741
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp
index 187c663..5d2e281 100644
--- a/examples/Animometer.cpp
+++ b/examples/Animometer.cpp
@@ -140,9 +140,9 @@
size_t i = 0;
- dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
{
- dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
+ dawn::RenderPassEncoder pass = encoder.BeginRenderPass(renderPass);
pass.SetPipeline(pipeline);
for (int k = 0; k < 10000; k++) {
@@ -155,7 +155,7 @@
pass.EndPass();
}
- dawn::CommandBuffer commands = builder.GetResult();
+ dawn::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
swapchain.Present(backbuffer);
DoFlush();
diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp
index 8f2a2e6..5dd38b7 100644
--- a/examples/CHelloTriangle.cpp
+++ b/examples/CHelloTriangle.cpp
@@ -131,16 +131,16 @@
}
dawnCommandBuffer commands;
{
- dawnCommandBufferBuilder builder = dawnDeviceCreateCommandBufferBuilder(device);
+ dawnCommandEncoder encoder = dawnDeviceCreateCommandEncoder(device);
- dawnRenderPassEncoder pass = dawnCommandBufferBuilderBeginRenderPass(builder, renderpassInfo);
+ dawnRenderPassEncoder pass = dawnCommandEncoderBeginRenderPass(encoder, renderpassInfo);
dawnRenderPassEncoderSetPipeline(pass, pipeline);
dawnRenderPassEncoderDraw(pass, 3, 1, 0, 0);
dawnRenderPassEncoderEndPass(pass);
dawnRenderPassEncoderRelease(pass);
- commands = dawnCommandBufferBuilderGetResult(builder);
- dawnCommandBufferBuilderRelease(builder);
+ commands = dawnCommandEncoderFinish(encoder);
+ dawnCommandEncoderRelease(encoder);
}
dawnQueueSubmit(queue, 1, &commands);
diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp
index 9776402..8e2dd0c 100644
--- a/examples/ComputeBoids.cpp
+++ b/examples/ComputeBoids.cpp
@@ -280,10 +280,10 @@
dawn::CommandBuffer createCommandBuffer(const dawn::RenderPassDescriptor& renderPass, size_t i) {
static const uint32_t zeroOffsets[1] = {0};
auto& bufferDst = particleBuffers[(i + 1) % 2];
- dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
{
- dawn::ComputePassEncoder pass = builder.BeginComputePass();
+ dawn::ComputePassEncoder pass = encoder.BeginComputePass();
pass.SetPipeline(updatePipeline);
pass.SetBindGroup(0, updateBGs[i]);
pass.Dispatch(kNumParticles, 1, 1);
@@ -291,7 +291,7 @@
}
{
- dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
+ dawn::RenderPassEncoder pass = encoder.BeginRenderPass(renderPass);
pass.SetPipeline(renderPipeline);
pass.SetVertexBuffers(0, 1, &bufferDst, zeroOffsets);
pass.SetVertexBuffers(1, 1, &modelBuffer, zeroOffsets);
@@ -299,7 +299,7 @@
pass.EndPass();
}
- return builder.GetResult();
+ return encoder.Finish();
}
void init() {
diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp
index c1bd437..8f837d1 100644
--- a/examples/CppHelloTriangle.cpp
+++ b/examples/CppHelloTriangle.cpp
@@ -74,11 +74,11 @@
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {1024, 1024, 1};
- dawn::CommandBuffer copy =
- device.CreateCommandBufferBuilder()
- .CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size)
- .GetResult();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
+ encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size);
+
+ dawn::CommandBuffer copy = encoder.Finish();
queue.Submit(1, ©);
}
@@ -165,9 +165,9 @@
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
static const uint32_t vertexBufferOffsets[1] = {0};
- dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
{
- dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
+ dawn::RenderPassEncoder pass = encoder.BeginRenderPass(renderPass);
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup);
pass.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets);
@@ -176,7 +176,7 @@
pass.EndPass();
}
- dawn::CommandBuffer commands = builder.GetResult();
+ dawn::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
swapchain.Present(backbuffer);
DoFlush();
diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp
index b35cd3c..833c40b 100644
--- a/examples/CubeReflection.cpp
+++ b/examples/CubeReflection.cpp
@@ -276,9 +276,9 @@
dawn::RenderPassDescriptor renderPass;
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
- dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
{
- dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
+ dawn::RenderPassEncoder pass = encoder.BeginRenderPass(renderPass);
pass.SetPipeline(pipeline);
pass.SetBindGroup(0, bindGroup[0]);
pass.SetVertexBuffers(0, 1, &vertexBuffer, vertexBufferOffsets);
@@ -299,7 +299,7 @@
pass.EndPass();
}
- dawn::CommandBuffer commands = builder.GetResult();
+ dawn::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
swapchain.Present(backbuffer);
DoFlush();
diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp
index 2203a32..d0ec863 100644
--- a/examples/glTFViewer/glTFViewer.cpp
+++ b/examples/glTFViewer/glTFViewer.cpp
@@ -471,9 +471,11 @@
dawn::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(oTexture, 0, 0, {0, 0, 0});
dawn::Extent3D copySize = {iImage.width, iImage.height, 1};
- auto cmdbuf = device.CreateCommandBufferBuilder()
- .CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size)
- .GetResult();
+
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
+ encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size);
+
+ dawn::CommandBuffer cmdbuf = encoder.Finish();
queue.Submit(1, &cmdbuf);
textures[iTextureID] = oTexture.CreateDefaultTextureView();
@@ -603,9 +605,9 @@
GetNextRenderPassDescriptor(device, swapchain, depthStencilView, &backbuffer, &renderPass);
const auto& defaultSceneNodes = scene.scenes.at(scene.defaultScene);
- dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
+ dawn::CommandEncoder encoder = device.CreateCommandEncoder();
{
- dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass);
+ dawn::RenderPassEncoder pass = encoder.BeginRenderPass(renderPass);
for (const auto& n : defaultSceneNodes) {
const auto& node = scene.nodes.at(n);
drawNode(pass, node);
@@ -613,7 +615,7 @@
pass.EndPass();
}
- dawn::CommandBuffer commands = builder.GetResult();
+ dawn::CommandBuffer commands = encoder.Finish();
queue.Submit(1, &commands);
swapchain.Present(backbuffer);