Commit 54b45adb authored by Brandon Jones's avatar Brandon Jones Committed by Commit Bot

Allow new WebGPU setIndexBuffer semantics, deprecate old variant

Blink counterpart to
https://bugs.chromium.org/p/dawn/issues/detail?id=502

Due to an issue with Blink's bindings generation this CL needed to be a
bit sneaky about handling the method overloading, which resulted in some
annoying manual validation. The alternative, however, would be exposing
a different method name which would add several more steps to the whole
deprecation process, so this feels worthwhile.

Bug: 1121762
Change-Id: I3f4ac324c6d91a27bfd5fabb17b1b142f7021598
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376456
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802857}
parent 6275c6b3
...@@ -376,6 +376,9 @@ WGPULoadOp AsDawnEnum<WGPULoadOp>(const WTF::String& webgpu_enum) { ...@@ -376,6 +376,9 @@ WGPULoadOp AsDawnEnum<WGPULoadOp>(const WTF::String& webgpu_enum) {
template <> template <>
WGPUIndexFormat AsDawnEnum<WGPUIndexFormat>(const WTF::String& webgpu_enum) { WGPUIndexFormat AsDawnEnum<WGPUIndexFormat>(const WTF::String& webgpu_enum) {
if (webgpu_enum.IsNull()) {
return WGPUIndexFormat_Undefined;
}
if (webgpu_enum == "uint16") { if (webgpu_enum == "uint16") {
return WGPUIndexFormat_Uint16; return WGPUIndexFormat_Uint16;
} }
......
...@@ -112,10 +112,28 @@ void GPURenderBundleEncoder::setPipeline(GPURenderPipeline* pipeline) { ...@@ -112,10 +112,28 @@ void GPURenderBundleEncoder::setPipeline(GPURenderPipeline* pipeline) {
void GPURenderBundleEncoder::setIndexBuffer(GPUBuffer* buffer, void GPURenderBundleEncoder::setIndexBuffer(GPUBuffer* buffer,
uint64_t offset, uint64_t offset,
uint64_t size) { uint64_t size) {
device_->AddConsoleWarning(
"Calling setIndexBuffer without a GPUIndexFormat is deprecated.");
GetProcs().renderBundleEncoderSetIndexBuffer(GetHandle(), buffer->GetHandle(), GetProcs().renderBundleEncoderSetIndexBuffer(GetHandle(), buffer->GetHandle(),
offset, size); offset, size);
} }
void GPURenderBundleEncoder::setIndexBuffer(GPUBuffer* buffer,
const WTF::String& format,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state) {
if (format != "uint16" && format != "uint32") {
exception_state.ThrowTypeError(
"The provided value '" + format +
"' is not a valid enum value of type GPUIndexFormat.");
return;
}
GetProcs().renderBundleEncoderSetIndexBufferWithFormat(
GetHandle(), buffer->GetHandle(), AsDawnEnum<WGPUIndexFormat>(format),
offset, size);
}
void GPURenderBundleEncoder::setVertexBuffer(uint32_t slot, void GPURenderBundleEncoder::setVertexBuffer(uint32_t slot,
const GPUBuffer* buffer, const GPUBuffer* buffer,
uint64_t offset, uint64_t offset,
...@@ -169,4 +187,9 @@ GPURenderBundle* GPURenderBundleEncoder::finish( ...@@ -169,4 +187,9 @@ GPURenderBundle* GPURenderBundleEncoder::finish(
return MakeGarbageCollected<GPURenderBundle>(device_, render_bundle); return MakeGarbageCollected<GPURenderBundle>(device_, render_bundle);
} }
void GPURenderBundleEncoder::Trace(Visitor* visitor) const {
visitor->Trace(device_);
DawnObject::Trace(visitor);
}
} // namespace blink } // namespace blink
...@@ -47,6 +47,11 @@ class GPURenderBundleEncoder : public DawnObject<WGPURenderBundleEncoder>, ...@@ -47,6 +47,11 @@ class GPURenderBundleEncoder : public DawnObject<WGPURenderBundleEncoder>,
void setPipeline(GPURenderPipeline* pipeline); void setPipeline(GPURenderPipeline* pipeline);
void setIndexBuffer(GPUBuffer* buffer, uint64_t offset, uint64_t size); void setIndexBuffer(GPUBuffer* buffer, uint64_t offset, uint64_t size);
void setIndexBuffer(GPUBuffer* buffer,
const WTF::String& format,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state);
void setVertexBuffer(uint32_t slot, void setVertexBuffer(uint32_t slot,
const GPUBuffer* buffer, const GPUBuffer* buffer,
uint64_t offset, uint64_t offset,
...@@ -65,6 +70,8 @@ class GPURenderBundleEncoder : public DawnObject<WGPURenderBundleEncoder>, ...@@ -65,6 +70,8 @@ class GPURenderBundleEncoder : public DawnObject<WGPURenderBundleEncoder>,
GPURenderBundle* finish(const GPURenderBundleDescriptor* webgpu_desc); GPURenderBundle* finish(const GPURenderBundleDescriptor* webgpu_desc);
void Trace(Visitor*) const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(GPURenderBundleEncoder); DISALLOW_COPY_AND_ASSIGN(GPURenderBundleEncoder);
}; };
......
...@@ -12,6 +12,18 @@ ...@@ -12,6 +12,18 @@
void setIndexBuffer(GPUBuffer buffer, void setIndexBuffer(GPUBuffer buffer,
optional GPUSize64 offset = 0, optional GPUSize64 offset = 0,
optional GPUSize64 size = 0); optional GPUSize64 size = 0);
// TODO: the format argument here should be a GPUIndexFormat enum, but that
// is causing problems with the bindings generator when paired with the
// overload. The above overload is deprecated and will be removed soon,
// which will allow us to use the correct type here. In the meantime we'll
// validate that the given string is one of the expected enum values
// manually.
[RaisesException]
void setIndexBuffer(GPUBuffer buffer,
DOMString format,
optional GPUSize64 offset = 0,
optional GPUSize64 size = 0);
void setVertexBuffer(GPUIndex32 slot, void setVertexBuffer(GPUIndex32 slot,
GPUBuffer buffer, GPUBuffer buffer,
optional GPUSize64 offset = 0, optional GPUSize64 offset = 0,
......
...@@ -110,10 +110,28 @@ void GPURenderPassEncoder::setScissorRect(uint32_t x, ...@@ -110,10 +110,28 @@ void GPURenderPassEncoder::setScissorRect(uint32_t x,
void GPURenderPassEncoder::setIndexBuffer(GPUBuffer* buffer, void GPURenderPassEncoder::setIndexBuffer(GPUBuffer* buffer,
uint64_t offset, uint64_t offset,
uint64_t size) { uint64_t size) {
device_->AddConsoleWarning(
"Calling setIndexBuffer without a GPUIndexFormat is deprecated.");
GetProcs().renderPassEncoderSetIndexBuffer(GetHandle(), buffer->GetHandle(), GetProcs().renderPassEncoderSetIndexBuffer(GetHandle(), buffer->GetHandle(),
offset, size); offset, size);
} }
void GPURenderPassEncoder::setIndexBuffer(GPUBuffer* buffer,
const WTF::String& format,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state) {
if (format != "uint16" && format != "uint32") {
exception_state.ThrowTypeError(
"The provided value '" + format +
"' is not a valid enum value of type GPUIndexFormat.");
return;
}
GetProcs().renderPassEncoderSetIndexBufferWithFormat(
GetHandle(), buffer->GetHandle(), AsDawnEnum<WGPUIndexFormat>(format),
offset, size);
}
void GPURenderPassEncoder::setVertexBuffer(uint32_t slot, void GPURenderPassEncoder::setVertexBuffer(uint32_t slot,
const GPUBuffer* buffer, const GPUBuffer* buffer,
const uint64_t offset, const uint64_t offset,
...@@ -164,4 +182,9 @@ void GPURenderPassEncoder::endPass() { ...@@ -164,4 +182,9 @@ void GPURenderPassEncoder::endPass() {
GetProcs().renderPassEncoderEndPass(GetHandle()); GetProcs().renderPassEncoderEndPass(GetHandle());
} }
void GPURenderPassEncoder::Trace(Visitor* visitor) const {
visitor->Trace(device_);
DawnObject::Trace(visitor);
}
} // namespace blink } // namespace blink
...@@ -52,6 +52,11 @@ class GPURenderPassEncoder : public DawnObject<WGPURenderPassEncoder>, ...@@ -52,6 +52,11 @@ class GPURenderPassEncoder : public DawnObject<WGPURenderPassEncoder>,
float maxDepth); float maxDepth);
void setScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height); void setScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
void setIndexBuffer(GPUBuffer* buffer, uint64_t offset, uint64_t size); void setIndexBuffer(GPUBuffer* buffer, uint64_t offset, uint64_t size);
void setIndexBuffer(GPUBuffer* buffer,
const WTF::String& format,
uint64_t offset,
uint64_t size,
ExceptionState& exception_state);
void setVertexBuffer(uint32_t slot, void setVertexBuffer(uint32_t slot,
const GPUBuffer* buffer, const GPUBuffer* buffer,
const uint64_t offset, const uint64_t offset,
...@@ -70,6 +75,8 @@ class GPURenderPassEncoder : public DawnObject<WGPURenderPassEncoder>, ...@@ -70,6 +75,8 @@ class GPURenderPassEncoder : public DawnObject<WGPURenderPassEncoder>,
void executeBundles(const HeapVector<Member<GPURenderBundle>>& bundles); void executeBundles(const HeapVector<Member<GPURenderBundle>>& bundles);
void endPass(); void endPass();
void Trace(Visitor*) const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(GPURenderPassEncoder); DISALLOW_COPY_AND_ASSIGN(GPURenderPassEncoder);
}; };
......
...@@ -236,20 +236,44 @@ GPURenderPipeline* GPURenderPipeline::Create( ...@@ -236,20 +236,44 @@ GPURenderPipeline* GPURenderPipeline::Create(
dawn_desc.fragmentStage = nullptr; dawn_desc.fragmentStage = nullptr;
} }
dawn_desc.primitiveTopology =
AsDawnEnum<WGPUPrimitiveTopology>(webgpu_desc->primitiveTopology());
v8::Isolate* isolate = script_state->GetIsolate(); v8::Isolate* isolate = script_state->GetIsolate();
ExceptionState exception_state(isolate, ExceptionState::kConstructionContext, ExceptionState exception_state(isolate, ExceptionState::kConstructionContext,
"GPUVertexStateDescriptor"); "GPUVertexStateDescriptor");
WGPUVertexStateInfo vertex_state_info = GPUVertexStateAsWGPUVertexState( WGPUVertexStateInfo vertex_state_info = GPUVertexStateAsWGPUVertexState(
isolate, webgpu_desc->vertexState(), exception_state); isolate, webgpu_desc->vertexState(), exception_state);
dawn_desc.vertexState = &std::get<0>(vertex_state_info); WGPUVertexStateDescriptor dawn_vertex_state = std::get<0>(vertex_state_info);
// TODO(crbug.com/1121762): Remove these checks after a deprecation period.
if (dawn_vertex_state.indexFormat == WGPUIndexFormat_Undefined) {
dawn_vertex_state.indexFormat = WGPUIndexFormat_Uint32;
if (dawn_desc.primitiveTopology == WGPUPrimitiveTopology_LineStrip ||
dawn_desc.primitiveTopology == WGPUPrimitiveTopology_TriangleStrip) {
device->AddConsoleWarning(
"Creating a GPUVertexStateDescriptor with a default indexFormat is "
"deprecated: Specify an explicit GPUIndexFormat when using "
"'line-strip' or 'triangle-strip' primitive topologies.");
}
} else if (dawn_desc.primitiveTopology == WGPUPrimitiveTopology_PointList ||
dawn_desc.primitiveTopology == WGPUPrimitiveTopology_LineList ||
dawn_desc.primitiveTopology ==
WGPUPrimitiveTopology_TriangleList) {
device->AddConsoleWarning(
"Creating a GPUVertexStateDescriptor with an explicit indexFormat is "
"deprecated when using 'point-list', 'line-list', or 'triangle-list' "
"primitive topologies: Specify the GPUIndexFormat when calling "
"setIndexBuffer() instead.");
}
dawn_desc.vertexState = &dawn_vertex_state;
if (exception_state.HadException()) { if (exception_state.HadException()) {
return nullptr; return nullptr;
} }
dawn_desc.primitiveTopology =
AsDawnEnum<WGPUPrimitiveTopology>(webgpu_desc->primitiveTopology());
WGPURasterizationStateDescriptor rasterization_state; WGPURasterizationStateDescriptor rasterization_state;
rasterization_state = AsDawnType(webgpu_desc->rasterizationState()); rasterization_state = AsDawnType(webgpu_desc->rasterizationState());
dawn_desc.rasterizationState = &rasterization_state; dawn_desc.rasterizationState = &rasterization_state;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// https://gpuweb.github.io/gpuweb/ // https://gpuweb.github.io/gpuweb/
dictionary GPUVertexStateDescriptor { dictionary GPUVertexStateDescriptor {
GPUIndexFormat indexFormat = "uint32"; GPUIndexFormat indexFormat;
// TODO(crbug.com/951629): Make this a sequence of nullables. // TODO(crbug.com/951629): Make this a sequence of nullables.
object vertexBuffers; // We validate this is an array of nullable GPUVertexBufferLayoutDescriptor object vertexBuffers; // We validate this is an array of nullable GPUVertexBufferLayoutDescriptor
}; };
......
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