Roll WebGPU IDL, update dawn/node bindings.

Bug: dawn:1123
Bug: dawn:1286
Change-Id: I3ffeea82fda381905ee8f02f9f2768c81c7e6d6d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/79761
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2022-03-03 21:13:51 +00:00 committed by Dawn LUCI CQ
parent ba70fac14d
commit db8666fa71
43 changed files with 132 additions and 141 deletions

2
DEPS
View File

@ -162,7 +162,7 @@ deps = {
'condition': 'dawn_node',
},
'third_party/gpuweb': {
'url': '{github_git}/gpuweb/gpuweb.git@0aadaca4c53ca131aa19708c1d2b1bed56da1118',
'url': '{github_git}/gpuweb/gpuweb.git@881403b5fda2d9ac9ffc5daa24e34738205bf155',
'condition': 'dawn_node',
},

View File

@ -952,63 +952,24 @@ namespace wgpu::binding {
bool Converter::Convert(wgpu::RenderPassColorAttachment& out,
const interop::GPURenderPassColorAttachment& in) {
out = {};
if (auto* op = std::get_if<interop::GPULoadOp>(&in.loadValue)) {
if (!Convert(out.loadOp, *op)) {
return false;
}
} else if (auto* color = std::get_if<interop::GPUColor>(&in.loadValue)) {
out.loadOp = wgpu::LoadOp::Clear;
if (!Convert(out.clearColor, *color)) {
return false;
}
} else {
Napi::Error::New(env, "invalid value for GPURenderPassColorAttachment.loadValue")
.ThrowAsJavaScriptException();
return false;
}
return Convert(out.view, in.view) && Convert(out.resolveTarget, in.resolveTarget) &&
return Convert(out.view, in.view) && //
Convert(out.resolveTarget, in.resolveTarget) && //
Convert(out.clearColor, in.clearValue) && //
Convert(out.loadOp, in.loadOp) && //
Convert(out.storeOp, in.storeOp);
}
bool Converter::Convert(wgpu::RenderPassDepthStencilAttachment& out,
const interop::GPURenderPassDepthStencilAttachment& in) {
out = {};
if (auto* op = std::get_if<interop::GPULoadOp>(&in.depthLoadValue)) {
if (!Convert(out.depthLoadOp, *op)) {
return false;
}
} else if (auto* value = std::get_if<float>(&in.depthLoadValue)) {
out.stencilLoadOp = wgpu::LoadOp::Clear;
if (!Convert(out.clearDepth, *value)) {
return false;
}
} else {
Napi::Error::New(env,
"invalid value for GPURenderPassDepthStencilAttachment.depthLoadValue")
.ThrowAsJavaScriptException();
return false;
}
if (auto* op = std::get_if<interop::GPULoadOp>(&in.stencilLoadValue)) {
if (!Convert(out.stencilLoadOp, *op)) {
return false;
}
} else if (auto* value = std::get_if<interop::GPUStencilValue>(&in.stencilLoadValue)) {
if (!Convert(out.clearStencil, *value)) {
return false;
}
} else {
Napi::Error::New(env,
"invalid value for "
"GPURenderPassDepthStencilAttachment.stencilLoadValue")
.ThrowAsJavaScriptException();
return false;
}
return Convert(out.view, in.view) && Convert(out.depthStoreOp, in.depthStoreOp) &&
Convert(out.depthReadOnly, in.depthReadOnly) &&
Convert(out.stencilStoreOp, in.stencilStoreOp) &&
return Convert(out.view, in.view) && //
Convert(out.clearDepth, in.depthClearValue) && //
Convert(out.depthLoadOp, in.depthLoadOp) && //
Convert(out.depthStoreOp, in.depthStoreOp) && //
Convert(out.depthReadOnly, in.depthReadOnly) && //
Convert(out.clearStencil, in.stencilClearValue) && //
Convert(out.stencilLoadOp, in.stencilLoadOp) && //
Convert(out.stencilStoreOp, in.stencilStoreOp) && //
Convert(out.stencilReadOnly, in.stencilReadOnly);
}
@ -1018,6 +979,9 @@ namespace wgpu::binding {
case interop::GPULoadOp::kLoad:
out = wgpu::LoadOp::Load;
return true;
case interop::GPULoadOp::kClear:
out = wgpu::LoadOp::Clear;
return true;
}
Napi::Error::New(env, "invalid value for GPULoadOp").ThrowAsJavaScriptException();
return false;

View File

@ -24,11 +24,12 @@ namespace wgpu::binding {
GPUBindGroup::GPUBindGroup(wgpu::BindGroup group) : group_(std::move(group)) {
}
std::optional<std::string> GPUBindGroup::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUBindGroup::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUBindGroup::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUBindGroup::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -33,8 +33,8 @@ namespace wgpu::binding {
}
// interop::GPUBindGroup interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::BindGroup group_;

View File

@ -25,11 +25,12 @@ namespace wgpu::binding {
: layout_(std::move(layout)) {
}
std::optional<std::string> GPUBindGroupLayout::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUBindGroupLayout::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUBindGroupLayout::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUBindGroupLayout::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
}
// interop::GPUBindGroupLayout interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::BindGroupLayout layout_;

View File

@ -158,11 +158,11 @@ namespace wgpu::binding {
state_ = State::Destroyed;
}
std::optional<std::string> GPUBuffer::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUBuffer::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUBuffer::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUBuffer::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -51,8 +51,8 @@ namespace wgpu::binding {
std::optional<interop::GPUSize64> size) override;
void unmap(Napi::Env) override;
void destroy(Napi::Env) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
struct Mapping {

View File

@ -25,11 +25,12 @@ namespace wgpu::binding {
GPUCommandBuffer::GPUCommandBuffer(wgpu::CommandBuffer cmd_buf) : cmd_buf_(std::move(cmd_buf)) {
}
std::optional<std::string> GPUCommandBuffer::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUCommandBuffer::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUCommandBuffer::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUCommandBuffer::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
}
// interop::GPUCommandBuffer interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::CommandBuffer cmd_buf_;

View File

@ -204,11 +204,12 @@ namespace wgpu::binding {
return interop::GPUCommandBuffer::Create<GPUCommandBuffer>(env, enc_.Finish(&desc));
}
std::optional<std::string> GPUCommandEncoder::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUCommandEncoder::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUCommandEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUCommandEncoder::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -72,8 +72,8 @@ namespace wgpu::binding {
interop::Interface<interop::GPUCommandBuffer> finish(
Napi::Env env,
interop::GPUCommandBufferDescriptor descriptor) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::CommandEncoder enc_;

View File

@ -54,10 +54,6 @@ namespace wgpu::binding {
enc_.End();
}
void GPUComputePassEncoder::endPass(Napi::Env) {
enc_.EndPass();
}
void GPUComputePassEncoder::setBindGroup(
Napi::Env env,
interop::GPUIndex32 index,
@ -104,11 +100,12 @@ namespace wgpu::binding {
enc_.InsertDebugMarker(markerLabel.c_str());
}
std::optional<std::string> GPUComputePassEncoder::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUComputePassEncoder::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUComputePassEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUComputePassEncoder::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -44,7 +44,6 @@ namespace wgpu::binding {
interop::Interface<interop::GPUBuffer> indirectBuffer,
interop::GPUSize64 indirectOffset) override;
void end(Napi::Env) override;
void endPass(Napi::Env) override; // TODO(dawn:1286): Remove after deprecation period.
void setBindGroup(Napi::Env,
interop::GPUIndex32 index,
interop::Interface<interop::GPUBindGroup> bindGroup,
@ -58,8 +57,8 @@ namespace wgpu::binding {
void pushDebugGroup(Napi::Env, std::string groupLabel) override;
void popDebugGroup(Napi::Env) override;
void insertDebugMarker(Napi::Env, std::string markerLabel) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::ComputePassEncoder enc_;

View File

@ -34,11 +34,12 @@ namespace wgpu::binding {
env, pipeline_.GetBindGroupLayout(index));
}
std::optional<std::string> GPUComputePipeline::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUComputePipeline::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUComputePipeline::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUComputePipeline::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -36,8 +36,8 @@ namespace wgpu::binding {
// interop::GPUComputePipeline interface compliance
interop::Interface<interop::GPUBindGroupLayout> getBindGroupLayout(Napi::Env,
uint32_t index) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::ComputePipeline pipeline_;

View File

@ -44,7 +44,8 @@ namespace wgpu::binding {
DeviceLostInfo(interop::GPUDeviceLostReason reason, std::string message)
: reason_(reason), message_(message) {
}
std::variant<interop::GPUDeviceLostReason> getReason(Napi::Env env) override {
std::variant<interop::GPUDeviceLostReason, interop::UndefinedType> getReason(
Napi::Env env) override {
return reason_;
}
std::string getMessage(Napi::Env) override {
@ -488,11 +489,11 @@ namespace wgpu::binding {
return promise;
}
std::optional<std::string> GPUDevice::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUDevice::getLabel(Napi::Env) {
UNIMPLEMENTED();
};
void GPUDevice::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUDevice::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
};

View File

@ -81,8 +81,8 @@ namespace wgpu::binding {
Napi::Env env) override;
void pushErrorScope(Napi::Env, interop::GPUErrorFilter filter) override;
interop::Promise<std::optional<interop::GPUError>> popErrorScope(Napi::Env env) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
interop::Interface<interop::EventHandler> getOnuncapturederror(Napi::Env) override;
void setOnuncapturederror(Napi::Env,
interop::Interface<interop::EventHandler> value) override;

View File

@ -24,11 +24,12 @@ namespace wgpu::binding {
GPUPipelineLayout::GPUPipelineLayout(wgpu::PipelineLayout layout) : layout_(std::move(layout)) {
}
std::optional<std::string> GPUPipelineLayout::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUPipelineLayout::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUPipelineLayout::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUPipelineLayout::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
}
// interop::GPUPipelineLayout interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::PipelineLayout layout_;

View File

@ -28,11 +28,11 @@ namespace wgpu::binding {
query_set_.Destroy();
}
std::optional<std::string> GPUQuerySet::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUQuerySet::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUQuerySet::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUQuerySet::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
// interop::GPUQuerySet interface compliance
void destroy(Napi::Env) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::QuerySet query_set_;

View File

@ -121,11 +121,11 @@ namespace wgpu::binding {
UNIMPLEMENTED();
}
std::optional<std::string> GPUQueue::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUQueue::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUQueue::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUQueue::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -48,8 +48,8 @@ namespace wgpu::binding {
interop::GPUImageCopyExternalImage source,
interop::GPUImageCopyTextureTagged destination,
interop::GPUExtent3D copySize) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::Queue queue_;

View File

@ -28,11 +28,12 @@ namespace wgpu::binding {
GPURenderBundle::GPURenderBundle(wgpu::RenderBundle bundle) : bundle_(std::move(bundle)) {
}
std::optional<std::string> GPURenderBundle::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPURenderBundle::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPURenderBundle::setLabel(Napi::Env, std::optional<std::string> value) {
void GPURenderBundle::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
}
// interop::GPURenderBundle interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::RenderBundle bundle_;

View File

@ -181,11 +181,12 @@ namespace wgpu::binding {
enc_.DrawIndexedIndirect(b, o);
}
std::optional<std::string> GPURenderBundleEncoder::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPURenderBundleEncoder::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPURenderBundleEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
void GPURenderBundleEncoder::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -74,8 +74,8 @@ namespace wgpu::binding {
void drawIndexedIndirect(Napi::Env,
interop::Interface<interop::GPUBuffer> indirectBuffer,
interop::GPUSize64 indirectOffset) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::RenderBundleEncoder enc_;

View File

@ -89,10 +89,6 @@ namespace wgpu::binding {
enc_.End();
}
void GPURenderPassEncoder::endPass(Napi::Env) {
enc_.EndPass();
}
void GPURenderPassEncoder::setBindGroup(
Napi::Env env,
interop::GPUIndex32 index,
@ -231,11 +227,12 @@ namespace wgpu::binding {
enc_.DrawIndexedIndirect(b, o);
}
std::optional<std::string> GPURenderPassEncoder::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPURenderPassEncoder::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPURenderPassEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
void GPURenderPassEncoder::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -54,7 +54,6 @@ namespace wgpu::binding {
Napi::Env,
std::vector<interop::Interface<interop::GPURenderBundle>> bundles) override;
void end(Napi::Env) override;
void endPass(Napi::Env) override; // TODO(dawn:1286): Remove after deprecation period.
void setBindGroup(Napi::Env,
interop::GPUIndex32 index,
interop::Interface<interop::GPUBindGroup> bindGroup,
@ -97,8 +96,8 @@ namespace wgpu::binding {
void drawIndexedIndirect(Napi::Env,
interop::Interface<interop::GPUBuffer> indirectBuffer,
interop::GPUSize64 indirectOffset) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::RenderPassEncoder enc_;

View File

@ -34,11 +34,12 @@ namespace wgpu::binding {
env, pipeline_.GetBindGroupLayout(index));
}
std::optional<std::string> GPURenderPipeline::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPURenderPipeline::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPURenderPipeline::setLabel(Napi::Env, std::optional<std::string> value) {
void GPURenderPipeline::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -36,8 +36,8 @@ namespace wgpu::binding {
// interop::GPURenderPipeline interface compliance
interop::Interface<interop::GPUBindGroupLayout> getBindGroupLayout(Napi::Env,
uint32_t index) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::RenderPipeline pipeline_;

View File

@ -25,11 +25,11 @@ namespace wgpu::binding {
GPUSampler::GPUSampler(wgpu::Sampler sampler) : sampler_(std::move(sampler)) {
}
std::optional<std::string> GPUSampler::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUSampler::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUSampler::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUSampler::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -32,8 +32,8 @@ namespace wgpu::binding {
}
// interop::GPUSampler interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::Sampler sampler_;

View File

@ -114,11 +114,12 @@ namespace wgpu::binding {
return promise;
}
std::optional<std::string> GPUShaderModule::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUShaderModule::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUShaderModule::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUShaderModule::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -37,8 +37,8 @@ namespace wgpu::binding {
// interop::GPUShaderModule interface compliance
interop::Promise<interop::Interface<interop::GPUCompilationInfo>> compilationInfo(
Napi::Env) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::ShaderModule shader_;

View File

@ -53,11 +53,11 @@ namespace wgpu::binding {
texture_.Destroy();
}
std::optional<std::string> GPUTexture::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUTexture::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUTexture::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUTexture::setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
}

View File

@ -37,8 +37,8 @@ namespace wgpu::binding {
Napi::Env,
interop::GPUTextureViewDescriptor descriptor) override;
void destroy(Napi::Env) override;
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType>getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType>value) override;
private:
wgpu::Texture texture_;

View File

@ -24,11 +24,12 @@ namespace wgpu::binding {
GPUTextureView::GPUTextureView(wgpu::TextureView view) : view_(std::move(view)) {
}
std::optional<std::string> GPUTextureView::getLabel(Napi::Env) {
std::variant<std::string, interop::UndefinedType> GPUTextureView::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUTextureView::setLabel(Napi::Env, std::optional<std::string> value) {
void GPUTextureView::setLabel(Napi::Env,
std::variant<std::string, interop::UndefinedType> value) {
UNIMPLEMENTED();
};

View File

@ -34,8 +34,8 @@ namespace wgpu::binding {
}
// interop::GPUTextureView interface compliance
std::optional<std::string> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::optional<std::string> value) override;
std::variant<std::string, interop::UndefinedType> getLabel(Napi::Env) override;
void setLabel(Napi::Env, std::variant<std::string, interop::UndefinedType> value) override;
private:
wgpu::TextureView view_;

View File

@ -157,4 +157,14 @@ namespace wgpu::interop {
return Napi::Value::From(env, value);
}
Result Converter<UndefinedType>::FromJS(Napi::Env, Napi::Value value, UndefinedType&) {
if (value.IsUndefined()) {
return Success;
}
return Error("value is undefined");
}
Napi::Value Converter<UndefinedType>::ToJS(Napi::Env env, UndefinedType) {
return env.Undefined();
}
} // namespace wgpu::interop

View File

@ -62,6 +62,10 @@ namespace wgpu::interop {
using Float64Array = Napi::TypedArrayOf<double>;
using DataView = Napi::TypedArray;
// Datatype used for undefined values.
struct UndefinedType {};
static constexpr UndefinedType Undefined;
template <typename T>
using FrozenArray = std::vector<T>;
@ -439,6 +443,13 @@ namespace wgpu::interop {
static Napi::Value ToJS(Napi::Env, double);
};
template <>
class Converter<UndefinedType> {
public:
static Result FromJS(Napi::Env, Napi::Value, UndefinedType&);
static Napi::Value ToJS(Napi::Env, UndefinedType);
};
template <typename T>
class Converter<Interface<T>> {
public:

View File

@ -118,8 +118,10 @@ See:
*/ -}}
{{- define "VariantTypeList" -}}
{{- range $i, $ty := $}}
{{- if not (IsUndefinedType $ty)}}
{{- if $i }}, {{end}}
{{- if $i }}, {{end}}
{{- if IsUndefinedType $ty -}}
UndefinedType
{{- else}}
{{- template "Type" $ty}}
{{- end}}
{{- end}}