Capture: Emit Commands from CommandBufferWGPU - copyX2X
Note, resources collected in the command buffer will be handles
to WGPU objects and need to be translated to native objects.
TextureWGPU has not yet be implemented so that part is currently
nullptr.
Testing will eventually happen by running end2end tests with a
wGPU backend on top of some other backend.
Bug: 440123094
Change-Id: I065d82a92046568fbe5183daf1832c37d532e405
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/258374
Auto-Submit: Gregg Tavares <gman@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/webgpu/CommandBufferWGPU.cpp b/src/dawn/native/webgpu/CommandBufferWGPU.cpp
index 0ff5213..b2ffdd8 100644
--- a/src/dawn/native/webgpu/CommandBufferWGPU.cpp
+++ b/src/dawn/native/webgpu/CommandBufferWGPU.cpp
@@ -41,6 +41,65 @@
CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor)
: CommandBufferBase(encoder, descriptor) {}
+namespace {
+
+WGPUExtent3D ToWGPU(const Extent3D& extent) {
+ return {
+ .width = extent.width,
+ .height = extent.height,
+ .depthOrArrayLayers = extent.depthOrArrayLayers,
+ };
+}
+
+WGPUOrigin3D ToWGPU(const Origin3D& origin) {
+ return {
+ .x = origin.x,
+ .y = origin.y,
+ .z = origin.z,
+ };
+}
+
+WGPUTexelCopyBufferInfo ToWGPU(const BufferCopy& copy) {
+ return {
+ .layout =
+ {
+ .offset = copy.offset,
+ .bytesPerRow = copy.bytesPerRow,
+ .rowsPerImage = copy.rowsPerImage,
+ },
+ .buffer = ToBackend(copy.buffer)->GetInnerHandle(),
+ };
+}
+
+WGPUTextureAspect ToWGPU(const Aspect aspect) {
+ switch (aspect) {
+ case Aspect::Depth:
+ return WGPUTextureAspect_DepthOnly;
+ case Aspect::Stencil:
+ return WGPUTextureAspect_StencilOnly;
+ case Aspect::Plane0:
+ return WGPUTextureAspect_Plane0Only;
+ case Aspect::Plane1:
+ return WGPUTextureAspect_Plane1Only;
+ case Aspect::Plane2:
+ return WGPUTextureAspect_Plane2Only;
+ default:
+ return WGPUTextureAspect_All;
+ }
+}
+
+WGPUTexelCopyTextureInfo ToWGPU(const TextureCopy& copy) {
+ return {
+ // TODO(crbug.com/440123094): Do this when GetInnerHandle is implemented for TextureWGPU
+ .texture = nullptr, // ToBackend(copy.texture)->GetInnerHandle(),
+ .mipLevel = copy.mipLevel,
+ .origin = ToWGPU(copy.origin),
+ .aspect = ToWGPU(copy.aspect),
+ };
+}
+
+} // anonymous namespace
+
WGPUCommandBuffer CommandBuffer::Encode() {
auto& wgpu = ToBackend(GetDevice())->wgpu;
@@ -52,13 +111,37 @@
while (mCommands.NextCommandId(&type)) {
switch (type) {
case Command::CopyBufferToBuffer: {
- CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
+ auto copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
wgpu.commandEncoderCopyBufferToBuffer(
innerEncoder, ToBackend(copy->source)->GetInnerHandle(), copy->sourceOffset,
ToBackend(copy->destination)->GetInnerHandle(), copy->destinationOffset,
copy->size);
break;
}
+ case Command::CopyBufferToTexture: {
+ auto cmd = mCommands.NextCommand<CopyBufferToTextureCmd>();
+ WGPUTexelCopyBufferInfo source = ToWGPU(cmd->source);
+ WGPUTexelCopyTextureInfo destination = ToWGPU(cmd->destination);
+ WGPUExtent3D size = ToWGPU(cmd->copySize);
+ wgpu.commandEncoderCopyBufferToTexture(innerEncoder, &source, &destination, &size);
+ break;
+ }
+ case Command::CopyTextureToBuffer: {
+ auto cmd = mCommands.NextCommand<CopyTextureToBufferCmd>();
+ WGPUTexelCopyTextureInfo source = ToWGPU(cmd->source);
+ WGPUTexelCopyBufferInfo destination = ToWGPU(cmd->destination);
+ WGPUExtent3D size = ToWGPU(cmd->copySize);
+ wgpu.commandEncoderCopyTextureToBuffer(innerEncoder, &source, &destination, &size);
+ break;
+ }
+ case Command::CopyTextureToTexture: {
+ auto cmd = mCommands.NextCommand<CopyTextureToTextureCmd>();
+ WGPUTexelCopyTextureInfo source = ToWGPU(cmd->source);
+ WGPUTexelCopyTextureInfo destination = ToWGPU(cmd->destination);
+ WGPUExtent3D size = ToWGPU(cmd->copySize);
+ wgpu.commandEncoderCopyTextureToTexture(innerEncoder, &source, &destination, &size);
+ break;
+ }
default:
DAWN_UNREACHABLE();
}