Commit 90d46d56 authored by François Beaufort's avatar François Beaufort Committed by Commit Bot

[WebGPU] Define GPUColor as (sequence<double> or GPUColorDict)

This CL redefines GPUColor as not only a GPUColorDict, but also a
sequence of double as specified in
https://gpuweb.github.io/gpuweb/#typedefdef-gpucolor

Bug: 877147
Change-Id: If375f0663bb93bf66bd14d2e3f5dd6847983db6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826883Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#701486}
parent 653a3ff3
......@@ -42,14 +42,16 @@ bindings_modules_generated_union_type_files = [
"$bindings_modules_v8_output_dir/dom_exception_or_overconstrained_error.h",
"$bindings_modules_v8_output_dir/double_or_constrain_double_range.cc",
"$bindings_modules_v8_output_dir/double_or_constrain_double_range.h",
"$bindings_modules_v8_output_dir/double_sequence_or_gpu_color_dict.cc",
"$bindings_modules_v8_output_dir/double_sequence_or_gpu_color_dict.h",
"$bindings_modules_v8_output_dir/worklet_animation_effect_or_worklet_group_effect.cc",
"$bindings_modules_v8_output_dir/worklet_animation_effect_or_worklet_group_effect.h",
"$bindings_modules_v8_output_dir/float32_array_or_float64_array_or_dom_matrix.cc",
"$bindings_modules_v8_output_dir/float32_array_or_float64_array_or_dom_matrix.h",
"$bindings_modules_v8_output_dir/gpu_out_of_memory_error_or_gpu_validation_error.cc",
"$bindings_modules_v8_output_dir/gpu_out_of_memory_error_or_gpu_validation_error.h",
"$bindings_modules_v8_output_dir/gpu_load_op_or_gpu_color.cc",
"$bindings_modules_v8_output_dir/gpu_load_op_or_gpu_color.h",
"$bindings_modules_v8_output_dir/gpu_load_op_or_double_sequence_or_gpu_color_dict.cc",
"$bindings_modules_v8_output_dir/gpu_load_op_or_double_sequence_or_gpu_color_dict.h",
"$bindings_modules_v8_output_dir/gpu_load_op_or_float.cc",
"$bindings_modules_v8_output_dir/gpu_load_op_or_float.h",
"$bindings_modules_v8_output_dir/gpu_load_op_or_unsigned_long.cc",
......
......@@ -842,7 +842,7 @@ modules_dictionary_idl_files =
"webgpu/gpu_command_buffer_descriptor.idl",
"webgpu/gpu_buffer_copy_view.idl",
"webgpu/gpu_buffer_descriptor.idl",
"webgpu/gpu_color.idl",
"webgpu/gpu_color_dict.idl",
"webgpu/gpu_color_state_descriptor.idl",
"webgpu/gpu_command_encoder_descriptor.idl",
"webgpu/gpu_compute_pipeline_descriptor.idl",
......
......@@ -6,7 +6,7 @@
#include <dawn/dawn.h>
#include "third_party/blink/renderer/modules/webgpu/gpu_color.h"
#include "third_party/blink/renderer/bindings/modules/v8/double_sequence_or_gpu_color_dict.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_pipeline_stage_descriptor.h"
......@@ -702,7 +702,19 @@ DawnErrorFilter AsDawnEnum<DawnErrorFilter>(const WTF::String& webgpu_enum) {
return DAWN_ERROR_FILTER_FORCE32;
}
DawnColor AsDawnType(const GPUColor* webgpu_color) {
DawnColor AsDawnColor(const Vector<double>& webgpu_color) {
DCHECK_EQ(webgpu_color.size(), 4UL);
DawnColor dawn_color = {};
dawn_color.r = webgpu_color[0];
dawn_color.g = webgpu_color[1];
dawn_color.b = webgpu_color[2];
dawn_color.a = webgpu_color[3];
return dawn_color;
}
DawnColor AsDawnType(const GPUColorDict* webgpu_color) {
DCHECK(webgpu_color);
DawnColor dawn_color = {};
......@@ -714,6 +726,19 @@ DawnColor AsDawnType(const GPUColor* webgpu_color) {
return dawn_color;
}
DawnColor AsDawnType(const DoubleSequenceOrGPUColorDict* webgpu_color) {
DCHECK(webgpu_color);
if (webgpu_color->IsDoubleSequence()) {
return AsDawnColor(webgpu_color->GetAsDoubleSequence());
} else if (webgpu_color->IsGPUColorDict()) {
return AsDawnType(webgpu_color->GetAsGPUColorDict());
}
NOTREACHED();
DawnColor dawn_color = {};
return dawn_color;
}
DawnExtent3D AsDawnType(const GPUExtent3D* webgpu_extent) {
DCHECK(webgpu_extent);
......
......@@ -19,7 +19,8 @@
namespace blink {
class GPUColor;
class DoubleSequenceOrGPUColorDict;
class GPUColorDict;
class GPUExtent3D;
class GPUOrigin3D;
class GPUPipelineStageDescriptor;
......@@ -37,7 +38,9 @@ DawnEnum AsDawnEnum(const WTF::String& webgpu_enum);
// These conversions are used multiple times and are declared here. Conversions
// used only once, for example for object construction, are defined
// individually.
DawnColor AsDawnType(const GPUColor*);
DawnColor AsDawnColor(const Vector<double>&);
DawnColor AsDawnType(const GPUColorDict*);
DawnColor AsDawnType(const DoubleSequenceOrGPUColorDict*);
DawnExtent3D AsDawnType(const GPUExtent3D*);
DawnOrigin3D AsDawnType(const GPUOrigin3D*);
......
......@@ -5,6 +5,7 @@
// https://gpuweb.github.io/gpuweb/
typedef unsigned long long GPUBufferSize;
typedef (sequence<double> or GPUColorDict) GPUColor;
[
RuntimeEnabled=WebGPU
......
......@@ -4,9 +4,9 @@
// https://gpuweb.github.io/gpuweb/
dictionary GPUColor {
required float r;
required float g;
required float b;
required float a;
dictionary GPUColorDict {
required double r;
required double g;
required double b;
required double a;
};
......@@ -4,6 +4,7 @@
#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/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"
......@@ -39,8 +40,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);
......@@ -171,12 +178,27 @@ 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;
......
......@@ -6,6 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_COMMAND_ENCODER_H_
#include "third_party/blink/renderer/modules/webgpu/dawn_object.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
namespace blink {
......@@ -34,7 +35,8 @@ class GPUCommandEncoder : public DawnObject<DawnCommandEncoder> {
// gpu_command_encoder.idl
GPURenderPassEncoder* beginRenderPass(
const GPURenderPassDescriptor* descriptor);
const GPURenderPassDescriptor* descriptor,
ExceptionState& exception_state);
GPUComputePassEncoder* beginComputePass(
const GPUComputePassDescriptor* descriptor);
void copyBufferToBuffer(GPUBuffer* src,
......
......@@ -7,7 +7,7 @@
[
RuntimeEnabled=WebGPU
] interface GPUCommandEncoder {
GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor);
[RaisesException] GPURenderPassEncoder beginRenderPass(GPURenderPassDescriptor descriptor);
GPUComputePassEncoder beginComputePass(optional GPUComputePassDescriptor descriptor);
void copyBufferToBuffer(
......
......@@ -7,7 +7,6 @@
#include "third_party/blink/renderer/modules/webgpu/dawn_conversions.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_bind_group.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_buffer.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_color.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_render_bundle.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_render_bundle_descriptor.h"
......
......@@ -4,10 +4,10 @@
#include "third_party/blink/renderer/modules/webgpu/gpu_render_pass_encoder.h"
#include "third_party/blink/renderer/bindings/modules/v8/double_sequence_or_gpu_color_dict.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_conversions.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_bind_group.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_buffer.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_color.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_device.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_render_bundle.h"
#include "third_party/blink/renderer/modules/webgpu/gpu_render_pipeline.h"
......@@ -61,8 +61,14 @@ void GPURenderPassEncoder::setPipeline(GPURenderPipeline* pipeline) {
GetProcs().renderPassEncoderSetPipeline(GetHandle(), pipeline->GetHandle());
}
void GPURenderPassEncoder::setBlendColor(GPUColor* color) {
DawnColor dawn_color = AsDawnType(color);
void GPURenderPassEncoder::setBlendColor(DoubleSequenceOrGPUColorDict& color,
ExceptionState& exception_state) {
if (color.IsDoubleSequence() && color.GetAsDoubleSequence().size() != 4) {
exception_state.ThrowRangeError("color size must be 4");
return;
}
DawnColor dawn_color = AsDawnType(&color);
GetProcs().renderPassEncoderSetBlendColor(GetHandle(), &dawn_color);
}
......
......@@ -12,7 +12,7 @@ namespace blink {
class GPUBindGroup;
class GPUBuffer;
class GPUColor;
class DoubleSequenceOrGPUColorDict;
class GPURenderBundle;
class GPURenderPipeline;
......@@ -36,7 +36,8 @@ class GPURenderPassEncoder : public DawnObject<DawnRenderPassEncoder> {
void insertDebugMarker(String markerLabel);
void setPipeline(GPURenderPipeline* pipeline);
void setBlendColor(GPUColor* color);
void setBlendColor(DoubleSequenceOrGPUColorDict& color,
ExceptionState& exception_state);
void setStencilReference(uint32_t reference);
void setViewport(float x,
float y,
......
......@@ -17,7 +17,7 @@
void setPipeline(GPURenderPipeline pipeline);
void setBlendColor(GPUColor color);
[RaisesException] void setBlendColor(GPUColor color);
void setStencilReference(unsigned long reference);
void setViewport(float x, float y,
float width, float height,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment