diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc | 169 |
1 files changed, 131 insertions, 38 deletions
diff --git a/chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc b/chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc index 438330e58cc..3afc4108da6 100644 --- a/chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc +++ b/chromium/third_party/blink/renderer/modules/webgpu/gpu_command_encoder.cc @@ -4,15 +4,18 @@ #include "third_party/blink/renderer/modules/webgpu/gpu_command_encoder.h" +#include "third_party/blink/renderer/bindings/modules/v8/double_sequence_or_gpu_color_dict.h" +#include "third_party/blink/renderer/bindings/modules/v8/unsigned_long_sequence_or_gpu_extent_3d_dict.h" +#include "third_party/blink/renderer/bindings/modules/v8/unsigned_long_sequence_or_gpu_origin_3d_dict.h" #include "third_party/blink/renderer/modules/webgpu/dawn_conversions.h" #include "third_party/blink/renderer/modules/webgpu/gpu_buffer.h" #include "third_party/blink/renderer/modules/webgpu/gpu_buffer_copy_view.h" #include "third_party/blink/renderer/modules/webgpu/gpu_command_buffer.h" +#include "third_party/blink/renderer/modules/webgpu/gpu_command_buffer_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_command_encoder_descriptor.h" +#include "third_party/blink/renderer/modules/webgpu/gpu_compute_pass_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_compute_pass_encoder.h" #include "third_party/blink/renderer/modules/webgpu/gpu_device.h" -#include "third_party/blink/renderer/modules/webgpu/gpu_extent_3d.h" -#include "third_party/blink/renderer/modules/webgpu/gpu_origin_3d.h" #include "third_party/blink/renderer/modules/webgpu/gpu_render_pass_color_attachment_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_render_pass_depth_stencil_attachment_descriptor.h" #include "third_party/blink/renderer/modules/webgpu/gpu_render_pass_descriptor.h" @@ -23,6 +26,31 @@ namespace blink { +bool ValidateCopySize(UnsignedLongSequenceOrGPUExtent3DDict& copy_size, + ExceptionState& exception_state) { + if (copy_size.IsUnsignedLongSequence() && + copy_size.GetAsUnsignedLongSequence().size() != 3) { + exception_state.ThrowRangeError("copySize length must be 3"); + return false; + } + return true; +} + +bool ValidateTextureCopyView(GPUTextureCopyView* texture_copy_view, + ExceptionState& exception_state) { + DCHECK(texture_copy_view); + + const UnsignedLongSequenceOrGPUOrigin3DDict origin = + texture_copy_view->origin(); + if (origin.IsUnsignedLongSequence() && + origin.GetAsUnsignedLongSequence().size() != 3) { + exception_state.ThrowRangeError( + "texture copy view origin length must be 3"); + return false; + } + return true; +} + DawnRenderPassColorAttachmentDescriptor AsDawnType( const GPURenderPassColorAttachmentDescriptor* webgpu_desc) { DCHECK(webgpu_desc); @@ -37,8 +65,14 @@ DawnRenderPassColorAttachmentDescriptor AsDawnType( const WTF::String& gpuLoadOp = webgpu_desc->loadValue().GetAsGPULoadOp(); dawn_desc.loadOp = AsDawnEnum<DawnLoadOp>(gpuLoadOp); - } else if (webgpu_desc->loadValue().IsGPUColor()) { - GPUColor* gpuColor = webgpu_desc->loadValue().GetAsGPUColor(); + } else if (webgpu_desc->loadValue().IsDoubleSequence()) { + const Vector<double>& gpuColor = + webgpu_desc->loadValue().GetAsDoubleSequence(); + dawn_desc.loadOp = DAWN_LOAD_OP_CLEAR; + dawn_desc.clearColor = AsDawnColor(gpuColor); + + } else if (webgpu_desc->loadValue().IsGPUColorDict()) { + const GPUColorDict* gpuColor = webgpu_desc->loadValue().GetAsGPUColorDict(); dawn_desc.loadOp = DAWN_LOAD_OP_CLEAR; dawn_desc.clearColor = AsDawnType(gpuColor); @@ -82,9 +116,10 @@ DawnRenderPassDepthStencilAttachmentDescriptor AsDawnType( dawn_desc.stencilLoadOp = AsDawnEnum<DawnLoadOp>(gpuLoadOp); dawn_desc.clearStencil = 0; - } else if (webgpu_desc->stencilLoadValue().IsLong()) { + } else if (webgpu_desc->stencilLoadValue().IsUnsignedLong()) { dawn_desc.stencilLoadOp = DAWN_LOAD_OP_CLEAR; - dawn_desc.clearStencil = webgpu_desc->stencilLoadValue().GetAsLong(); + dawn_desc.clearStencil = + webgpu_desc->stencilLoadValue().GetAsUnsignedLong(); } else { NOTREACHED(); @@ -119,7 +154,7 @@ DawnTextureCopyView AsDawnType(const GPUTextureCopyView* webgpu_view) { dawn_view.texture = webgpu_view->texture()->GetHandle(); dawn_view.mipLevel = webgpu_view->mipLevel(); dawn_view.arrayLayer = webgpu_view->arrayLayer(); - dawn_view.origin = AsDawnType(webgpu_view->origin()); + dawn_view.origin = AsDawnType(&webgpu_view->origin()); return dawn_view; } @@ -130,6 +165,9 @@ DawnCommandEncoderDescriptor AsDawnType( DawnCommandEncoderDescriptor dawn_desc = {}; dawn_desc.nextInChain = nullptr; + if (webgpu_desc->hasLabel()) { + dawn_desc.label = webgpu_desc->label().Utf8().data(); + } return dawn_desc; } @@ -168,33 +206,39 @@ GPUCommandEncoder::~GPUCommandEncoder() { } GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass( - const GPURenderPassDescriptor* descriptor) { + const GPURenderPassDescriptor* descriptor, + ExceptionState& exception_state) { DCHECK(descriptor); uint32_t color_attachment_count = static_cast<uint32_t>(descriptor->colorAttachments().size()); + // Check loadValue color is correctly formatted before further processing. + for (wtf_size_t i = 0; i < color_attachment_count; ++i) { + const GPURenderPassColorAttachmentDescriptor* color_attachment = + descriptor->colorAttachments()[i]; + const GPULoadOpOrDoubleSequenceOrGPUColorDict load_value = + color_attachment->loadValue(); + + if (load_value.IsDoubleSequence() && + load_value.GetAsDoubleSequence().size() != 4) { + exception_state.ThrowRangeError("loadValue color size must be 4"); + return nullptr; + } + } + DawnRenderPassDescriptor dawn_desc = {}; dawn_desc.colorAttachmentCount = color_attachment_count; dawn_desc.colorAttachments = nullptr; + if (descriptor->hasLabel()) { + dawn_desc.label = descriptor->label().Utf8().data(); + } - using DescriptorPtr = DawnRenderPassColorAttachmentDescriptor*; - using DescriptorArray = DawnRenderPassColorAttachmentDescriptor[]; - using DescriptorPtrArray = DescriptorPtr[]; - - std::unique_ptr<DescriptorArray> color_attachments; - std::unique_ptr<DescriptorPtrArray> color_attachment_ptrs; + std::unique_ptr<DawnRenderPassColorAttachmentDescriptor[]> color_attachments; if (color_attachment_count > 0) { color_attachments = AsDawnType(descriptor->colorAttachments()); - - color_attachment_ptrs = std::unique_ptr<DescriptorPtrArray>( - new DescriptorPtr[color_attachment_count]); - - for (uint32_t i = 0; i < color_attachment_count; ++i) { - color_attachment_ptrs[i] = color_attachments.get() + i; - } - dawn_desc.colorAttachments = color_attachment_ptrs.get(); + dawn_desc.colorAttachments = color_attachments.get(); } DawnRenderPassDepthStencilAttachmentDescriptor depthStencilAttachment = {}; @@ -210,9 +254,16 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass( GetProcs().commandEncoderBeginRenderPass(GetHandle(), &dawn_desc)); } -GPUComputePassEncoder* GPUCommandEncoder::beginComputePass() { +GPUComputePassEncoder* GPUCommandEncoder::beginComputePass( + const GPUComputePassDescriptor* descriptor) { + DawnComputePassDescriptor dawn_desc = {}; + if (descriptor->hasLabel()) { + dawn_desc.label = descriptor->label().Utf8().data(); + } + return GPUComputePassEncoder::Create( - device_, GetProcs().commandEncoderBeginComputePass(GetHandle(), nullptr)); + device_, + GetProcs().commandEncoderBeginComputePass(GetHandle(), &dawn_desc)); } void GPUCommandEncoder::copyBufferToBuffer(GPUBuffer* src, @@ -227,42 +278,84 @@ void GPUCommandEncoder::copyBufferToBuffer(GPUBuffer* src, dst_offset, size); } -void GPUCommandEncoder::copyBufferToTexture(GPUBufferCopyView* source, - GPUTextureCopyView* destination, - GPUExtent3D* copy_size) { +void GPUCommandEncoder::copyBufferToTexture( + GPUBufferCopyView* source, + GPUTextureCopyView* destination, + UnsignedLongSequenceOrGPUExtent3DDict& copy_size, + ExceptionState& exception_state) { + if (!ValidateCopySize(copy_size, exception_state) || + !ValidateTextureCopyView(destination, exception_state)) { + return; + } + DawnBufferCopyView dawn_source = AsDawnType(source); DawnTextureCopyView dawn_destination = AsDawnType(destination); - DawnExtent3D dawn_copy_size = AsDawnType(copy_size); + DawnExtent3D dawn_copy_size = AsDawnType(©_size); GetProcs().commandEncoderCopyBufferToTexture( GetHandle(), &dawn_source, &dawn_destination, &dawn_copy_size); } -void GPUCommandEncoder::copyTextureToBuffer(GPUTextureCopyView* source, - GPUBufferCopyView* destination, - GPUExtent3D* copy_size) { +void GPUCommandEncoder::copyTextureToBuffer( + GPUTextureCopyView* source, + GPUBufferCopyView* destination, + UnsignedLongSequenceOrGPUExtent3DDict& copy_size, + ExceptionState& exception_state) { + if (!ValidateCopySize(copy_size, exception_state) || + !ValidateTextureCopyView(source, exception_state)) { + return; + } + DawnTextureCopyView dawn_source = AsDawnType(source); DawnBufferCopyView dawn_destination = AsDawnType(destination); - DawnExtent3D dawn_copy_size = AsDawnType(copy_size); + DawnExtent3D dawn_copy_size = AsDawnType(©_size); GetProcs().commandEncoderCopyTextureToBuffer( GetHandle(), &dawn_source, &dawn_destination, &dawn_copy_size); } -void GPUCommandEncoder::copyTextureToTexture(GPUTextureCopyView* source, - GPUTextureCopyView* destination, - GPUExtent3D* copy_size) { +void GPUCommandEncoder::copyTextureToTexture( + GPUTextureCopyView* source, + GPUTextureCopyView* destination, + UnsignedLongSequenceOrGPUExtent3DDict& copy_size, + ExceptionState& exception_state) { + if (!ValidateCopySize(copy_size, exception_state) || + !ValidateTextureCopyView(source, exception_state) || + !ValidateTextureCopyView(destination, exception_state)) { + return; + } + DawnTextureCopyView dawn_source = AsDawnType(source); DawnTextureCopyView dawn_destination = AsDawnType(destination); - DawnExtent3D dawn_copy_size = AsDawnType(copy_size); + DawnExtent3D dawn_copy_size = AsDawnType(©_size); GetProcs().commandEncoderCopyTextureToTexture( GetHandle(), &dawn_source, &dawn_destination, &dawn_copy_size); } -GPUCommandBuffer* GPUCommandEncoder::finish() { +void GPUCommandEncoder::pushDebugGroup(String groupLabel) { + GetProcs().commandEncoderPushDebugGroup(GetHandle(), + groupLabel.Utf8().data()); +} + +void GPUCommandEncoder::popDebugGroup() { + GetProcs().commandEncoderPopDebugGroup(GetHandle()); +} + +void GPUCommandEncoder::insertDebugMarker(String markerLabel) { + GetProcs().commandEncoderInsertDebugMarker(GetHandle(), + markerLabel.Utf8().data()); +} + +GPUCommandBuffer* GPUCommandEncoder::finish( + const GPUCommandBufferDescriptor* descriptor) { + DawnCommandBufferDescriptor dawn_desc = {}; + if (descriptor->hasLabel()) { + dawn_desc.label = descriptor->label().Utf8().data(); + } + return GPUCommandBuffer::Create( - device_, GetProcs().commandEncoderFinish(GetHandle(), nullptr)); + device_, GetProcs().commandEncoderFinish(GetHandle(), &dawn_desc)); } } // namespace blink |