diff --git a/src/dawn_node/binding/CMakeLists.txt b/src/dawn_node/binding/CMakeLists.txt index faad89440c..dd7ae4a859 100644 --- a/src/dawn_node/binding/CMakeLists.txt +++ b/src/dawn_node/binding/CMakeLists.txt @@ -17,6 +17,28 @@ add_library(dawn_node_binding STATIC "AsyncRunner.h" "Errors.cpp" "Errors.h" + "GPU.h" + "GPUAdapter.h" + "GPUBindGroup.h" + "GPUBindGroupLayout.h" + "GPUBuffer.h" + "GPUCommandBuffer.h" + "GPUCommandEncoder.h" + "GPUComputePassEncoder.h" + "GPUComputePipeline.h" + "GPUDevice.h" + "GPUPipelineLayout.h" + "GPUQuerySet.h" + "GPUQueue.h" + "GPURenderBundle.h" + "GPURenderBundleEncoder.h" + "GPURenderPassEncoder.h" + "GPURenderPipeline.h" + "GPUSampler.h" + "GPUShaderModule.h" + "GPUSupportedLimits.h" + "GPUTexture.h" + "GPUTextureView.h" ) target_include_directories(dawn_node_binding diff --git a/src/dawn_node/binding/GPU.h b/src/dawn_node/binding/GPU.h new file mode 100644 index 0000000000..55264b24f0 --- /dev/null +++ b/src/dawn_node/binding/GPU.h @@ -0,0 +1,41 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPU_H_ +#define DAWN_NODE_BINDING_GPU_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPU is an implementation of interop::GPU that wraps a dawn_native::Instance. + class GPU final : public interop::GPU { + public: + GPU(); + + // interop::GPU interface compliance + interop::Promise>> requestAdapter( + Napi::Env env, + std::optional options) override; + + private: + dawn_native::Instance instance_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPU_H_ diff --git a/src/dawn_node/binding/GPUAdapter.h b/src/dawn_node/binding/GPUAdapter.h new file mode 100644 index 0000000000..3140ff8718 --- /dev/null +++ b/src/dawn_node/binding/GPUAdapter.h @@ -0,0 +1,45 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUADAPTER_H_ +#define DAWN_NODE_BINDING_GPUADAPTER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUAdapter is an implementation of interop::GPUAdapter that wraps a dawn_native::Adapter. + class GPUAdapter final : public interop::GPUAdapter { + public: + GPUAdapter(dawn_native::Adapter a); + + // interop::GPUAdapter interface compliance + std::string getName(Napi::Env) override; + interop::Interface getFeatures(Napi::Env) override; + interop::Interface getLimits(Napi::Env) override; + bool getIsFallbackAdapter(Napi::Env) override; + interop::Promise> requestDevice( + Napi::Env env, + std::optional descriptor) override; + + private: + dawn_native::Adapter adapter_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUADAPTER_H_ diff --git a/src/dawn_node/binding/GPUBindGroup.h b/src/dawn_node/binding/GPUBindGroup.h new file mode 100644 index 0000000000..e71fc8be5c --- /dev/null +++ b/src/dawn_node/binding/GPUBindGroup.h @@ -0,0 +1,45 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUBINDGROUP_H_ +#define DAWN_NODE_BINDING_GPUBINDGROUP_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUBindGroup is an implementation of interop::GPUBindGroup that wraps a wgpu::BindGroup. + class GPUBindGroup final : public interop::GPUBindGroup { + public: + GPUBindGroup(wgpu::BindGroup group); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::BindGroup &() const { + return group_; + } + + // interop::GPUBindGroup interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::BindGroup group_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUBINDGROUP_H_ diff --git a/src/dawn_node/binding/GPUBindGroupLayout.h b/src/dawn_node/binding/GPUBindGroupLayout.h new file mode 100644 index 0000000000..34874bf1d9 --- /dev/null +++ b/src/dawn_node/binding/GPUBindGroupLayout.h @@ -0,0 +1,46 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUBINDGROUPLAYOUT_H_ +#define DAWN_NODE_BINDING_GPUBINDGROUPLAYOUT_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUBindGroupLayout is an implementation of interop::GPUBindGroupLayout that wraps a + // wgpu::BindGroupLayout. + class GPUBindGroupLayout final : public interop::GPUBindGroupLayout { + public: + GPUBindGroupLayout(wgpu::BindGroupLayout layout); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::BindGroupLayout &() const { + return layout_; + } + + // interop::GPUBindGroupLayout interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::BindGroupLayout layout_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUBINDGROUPLAYOUT_H_ diff --git a/src/dawn_node/binding/GPUBuffer.h b/src/dawn_node/binding/GPUBuffer.h new file mode 100644 index 0000000000..0c4d17c8c4 --- /dev/null +++ b/src/dawn_node/binding/GPUBuffer.h @@ -0,0 +1,86 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUBUFFER_H_ +#define DAWN_NODE_BINDING_GPUBUFFER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/binding/AsyncRunner.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUBuffer is an implementation of interop::GPUBuffer that wraps a wgpu::Buffer. + class GPUBuffer final : public interop::GPUBuffer { + public: + GPUBuffer(wgpu::Buffer buffer, + wgpu::BufferDescriptor desc, + wgpu::Device device, + std::shared_ptr async); + + // Desc() returns the wgpu::BufferDescriptor used to construct the buffer + const wgpu::BufferDescriptor& Desc() const { + return desc_; + } + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::Buffer &() const { + return buffer_; + } + + // interop::GPUBuffer interface compliance + interop::Promise mapAsync(Napi::Env env, + interop::GPUMapModeFlags mode, + std::optional offset, + std::optional size) override; + interop::ArrayBuffer getMappedRange(Napi::Env env, + std::optional offset, + std::optional size) override; + void unmap(Napi::Env) override; + void destroy(Napi::Env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + struct Mapping { + uint64_t start; + uint64_t end; + inline bool Intersects(uint64_t s, uint64_t e) const { + return s < end && e > start; + } + Napi::Reference buffer; + }; + + // https://www.w3.org/TR/webgpu/#buffer-interface + enum class State { + Unmapped, + Mapped, + MappedAtCreation, + MappingPending, + Destroyed, + }; + + wgpu::Buffer buffer_; + wgpu::BufferDescriptor const desc_; + wgpu::Device const device_; + std::shared_ptr async_; + State state_ = State::Unmapped; + std::vector mapped_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUBUFFER_H_ diff --git a/src/dawn_node/binding/GPUCommandBuffer.h b/src/dawn_node/binding/GPUCommandBuffer.h new file mode 100644 index 0000000000..b6fc3ba511 --- /dev/null +++ b/src/dawn_node/binding/GPUCommandBuffer.h @@ -0,0 +1,47 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUCOMMANDBUFFER_H_ +#define DAWN_NODE_BINDING_GPUCOMMANDBUFFER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUCommandBuffer is an implementation of interop::GPUCommandBuffer that wraps a + // wgpu::CommandBuffer. + class GPUCommandBuffer final : public interop::GPUCommandBuffer { + public: + GPUCommandBuffer(wgpu::CommandBuffer cmd_buf); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::CommandBuffer &() const { + return cmd_buf_; + } + + // interop::GPUCommandBuffer interface compliance + interop::Promise getExecutionTime(Napi::Env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::CommandBuffer cmd_buf_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUCOMMANDBUFFER_H_ diff --git a/src/dawn_node/binding/GPUCommandEncoder.h b/src/dawn_node/binding/GPUCommandEncoder.h new file mode 100644 index 0000000000..081032a154 --- /dev/null +++ b/src/dawn_node/binding/GPUCommandEncoder.h @@ -0,0 +1,80 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUCOMMANDENCODER_H_ +#define DAWN_NODE_BINDING_GPUCOMMANDENCODER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUCommandEncoder is an implementation of interop::GPUCommandEncoder that wraps a + // wgpu::CommandEncoder. + class GPUCommandEncoder final : public interop::GPUCommandEncoder { + public: + GPUCommandEncoder(wgpu::CommandEncoder enc); + + // interop::GPUCommandEncoder interface compliance + interop::Interface beginRenderPass( + Napi::Env, + interop::GPURenderPassDescriptor descriptor) override; + interop::Interface beginComputePass( + Napi::Env, + std::optional descriptor) override; + void copyBufferToBuffer(Napi::Env, + interop::Interface source, + interop::GPUSize64 sourceOffset, + interop::Interface destination, + interop::GPUSize64 destinationOffset, + interop::GPUSize64 size) override; + void copyBufferToTexture(Napi::Env, + interop::GPUImageCopyBuffer source, + interop::GPUImageCopyTexture destination, + interop::GPUExtent3D copySize) override; + void copyTextureToBuffer(Napi::Env, + interop::GPUImageCopyTexture source, + interop::GPUImageCopyBuffer destination, + interop::GPUExtent3D copySize) override; + void copyTextureToTexture(Napi::Env, + interop::GPUImageCopyTexture source, + interop::GPUImageCopyTexture destination, + interop::GPUExtent3D copySize) override; + void pushDebugGroup(Napi::Env, std::string groupLabel) override; + void popDebugGroup(Napi::Env) override; + void insertDebugMarker(Napi::Env, std::string markerLabel) override; + void writeTimestamp(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 queryIndex) override; + void resolveQuerySet(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 firstQuery, + interop::GPUSize32 queryCount, + interop::Interface destination, + interop::GPUSize64 destinationOffset) override; + interop::Interface finish( + Napi::Env env, + std::optional descriptor) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::CommandEncoder enc_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUCOMMANDENCODER_H_ diff --git a/src/dawn_node/binding/GPUComputePassEncoder.h b/src/dawn_node/binding/GPUComputePassEncoder.h new file mode 100644 index 0000000000..f387ca01f9 --- /dev/null +++ b/src/dawn_node/binding/GPUComputePassEncoder.h @@ -0,0 +1,77 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ +#define DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUComputePassEncoder is an implementation of interop::GPUComputePassEncoder that wraps a + // wgpu::ComputePassEncoder. + class GPUComputePassEncoder final : public interop::GPUComputePassEncoder { + public: + GPUComputePassEncoder(wgpu::ComputePassEncoder enc); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::ComputePassEncoder &() const { + return enc_; + } + + // interop::GPUComputePassEncoder interface compliance + void setPipeline(Napi::Env, + interop::Interface pipeline) override; + void dispatch(Napi::Env, + interop::GPUSize32 x, + std::optional y, + std::optional z) override; + void dispatchIndirect(Napi::Env, + interop::Interface indirectBuffer, + interop::GPUSize64 indirectOffset) override; + void beginPipelineStatisticsQuery(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 queryIndex) override; + void endPipelineStatisticsQuery(Napi::Env) override; + void writeTimestamp(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 queryIndex) override; + void endPass(Napi::Env) override; + void setBindGroup( + Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + std::optional> dynamicOffsets) override; + void setBindGroup(Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + interop::Uint32Array dynamicOffsetsData, + interop::GPUSize64 dynamicOffsetsDataStart, + interop::GPUSize32 dynamicOffsetsDataLength) override; + void pushDebugGroup(Napi::Env, std::string groupLabel) override; + void popDebugGroup(Napi::Env) override; + void insertDebugMarker(Napi::Env, std::string markerLabel) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::ComputePassEncoder enc_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ diff --git a/src/dawn_node/binding/GPUComputePipeline.h b/src/dawn_node/binding/GPUComputePipeline.h new file mode 100644 index 0000000000..e9dde76a6a --- /dev/null +++ b/src/dawn_node/binding/GPUComputePipeline.h @@ -0,0 +1,48 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUPIPELINE_H_ +#define DAWN_NODE_BINDING_GPUPIPELINE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUComputePipeline is an implementation of interop::GPUComputePipeline that wraps a + // wgpu::ComputePipeline. + class GPUComputePipeline final : public interop::GPUComputePipeline { + public: + GPUComputePipeline(wgpu::ComputePipeline pipeline); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::ComputePipeline &() const { + return pipeline_; + } + + // interop::GPUComputePipeline interface compliance + interop::Interface getBindGroupLayout(Napi::Env, + uint32_t index) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::ComputePipeline pipeline_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUPIPELINE_H_ diff --git a/src/dawn_node/binding/GPUDevice.h b/src/dawn_node/binding/GPUDevice.h new file mode 100644 index 0000000000..f04fba8def --- /dev/null +++ b/src/dawn_node/binding/GPUDevice.h @@ -0,0 +1,113 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUDEVICE_H_ +#define DAWN_NODE_BINDING_GPUDEVICE_H_ + +#include "dawn/webgpu_cpp.h" +#include "napi.h" +#include "src/dawn_node/binding/AsyncRunner.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + // GPUDevice is an implementation of interop::GPUDevice that wraps a wgpu::Device. + class GPUDevice final : public interop::GPUDevice { + public: + GPUDevice(Napi::Env env, wgpu::Device device); + ~GPUDevice(); + + // interop::GPUDevice interface compliance + interop::Interface getFeatures(Napi::Env) override; + interop::Interface getLimits(Napi::Env) override; + interop::Interface getQueue(Napi::Env env) override; + void destroy(Napi::Env) override; + interop::Interface createBuffer( + Napi::Env env, + interop::GPUBufferDescriptor descriptor) override; + interop::Interface createTexture( + Napi::Env, + interop::GPUTextureDescriptor descriptor) override; + interop::Interface createSampler( + Napi::Env, + std::optional descriptor) override; + interop::Interface importExternalTexture( + Napi::Env, + interop::GPUExternalTextureDescriptor descriptor) override; + interop::Interface createBindGroupLayout( + Napi::Env, + interop::GPUBindGroupLayoutDescriptor descriptor) override; + interop::Interface createPipelineLayout( + Napi::Env, + interop::GPUPipelineLayoutDescriptor descriptor) override; + interop::Interface createBindGroup( + Napi::Env, + interop::GPUBindGroupDescriptor descriptor) override; + interop::Interface createShaderModule( + Napi::Env, + interop::GPUShaderModuleDescriptor descriptor) override; + interop::Interface createComputePipeline( + Napi::Env, + interop::GPUComputePipelineDescriptor descriptor) override; + interop::Interface createRenderPipeline( + Napi::Env, + interop::GPURenderPipelineDescriptor descriptor) override; + interop::Promise> + createComputePipelineAsync(Napi::Env env, + interop::GPUComputePipelineDescriptor descriptor) override; + interop::Promise> createRenderPipelineAsync( + Napi::Env env, + interop::GPURenderPipelineDescriptor descriptor) override; + interop::Interface createCommandEncoder( + Napi::Env env, + std::optional descriptor) override; + interop::Interface createRenderBundleEncoder( + Napi::Env, + interop::GPURenderBundleEncoderDescriptor descriptor) override; + interop::Interface createQuerySet( + Napi::Env, + interop::GPUQuerySetDescriptor descriptor) override; + interop::Promise> getLost( + Napi::Env env) override; + void pushErrorScope(Napi::Env, interop::GPUErrorFilter filter) override; + interop::Promise> popErrorScope(Napi::Env env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + interop::Interface getOnuncapturederror(Napi::Env) override; + void setOnuncapturederror(Napi::Env, + interop::Interface value) override; + void addEventListener( + Napi::Env, + std::string type, + std::optional> callback, + std::optional> options) override; + void removeEventListener( + Napi::Env, + std::string type, + std::optional> callback, + std::optional> options) override; + bool dispatchEvent(Napi::Env, interop::Interface event) override; + + private: + void QueueTick(); + + Napi::Env env_; + wgpu::Device device_; + std::shared_ptr async_; + std::vector>> + lost_promises_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUDEVICE_H_ diff --git a/src/dawn_node/binding/GPUPipelineLayout.h b/src/dawn_node/binding/GPUPipelineLayout.h new file mode 100644 index 0000000000..a1d0b87bcd --- /dev/null +++ b/src/dawn_node/binding/GPUPipelineLayout.h @@ -0,0 +1,46 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUPIPELINELAYOUT_H_ +#define DAWN_NODE_BINDING_GPUPIPELINELAYOUT_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUPipelineLayout is an implementation of interop::GPUPipelineLayout that wraps a + // wgpu::PipelineLayout. + class GPUPipelineLayout final : public interop::GPUPipelineLayout { + public: + GPUPipelineLayout(wgpu::PipelineLayout layout); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::PipelineLayout &() const { + return layout_; + } + + // interop::GPUPipelineLayout interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::PipelineLayout layout_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUPIPELINELAYOUT_H_ diff --git a/src/dawn_node/binding/GPUQuerySet.h b/src/dawn_node/binding/GPUQuerySet.h new file mode 100644 index 0000000000..8669e16ac2 --- /dev/null +++ b/src/dawn_node/binding/GPUQuerySet.h @@ -0,0 +1,46 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUQUERYSET_H_ +#define DAWN_NODE_BINDING_GPUQUERYSET_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUQuerySet is an implementation of interop::GPUQuerySet that wraps a wgpu::QuerySet. + class GPUQuerySet final : public interop::GPUQuerySet { + public: + GPUQuerySet(wgpu::QuerySet query_set); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::QuerySet &() const { + return query_set_; + } + + // interop::GPUQuerySet interface compliance + void destroy(Napi::Env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::QuerySet query_set_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUQUERYSET_H_ diff --git a/src/dawn_node/binding/GPUQueue.h b/src/dawn_node/binding/GPUQueue.h new file mode 100644 index 0000000000..53751205d4 --- /dev/null +++ b/src/dawn_node/binding/GPUQueue.h @@ -0,0 +1,61 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUQUEUE_H_ +#define DAWN_NODE_BINDING_GPUQUEUE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/binding/AsyncRunner.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUQueue is an implementation of interop::GPUQueue that wraps a wgpu::Queue. + class GPUQueue final : public interop::GPUQueue { + public: + GPUQueue(wgpu::Queue queue, std::shared_ptr async); + + // interop::GPUQueue interface compliance + void submit( + Napi::Env, + std::vector> commandBuffers) override; + interop::Promise onSubmittedWorkDone(Napi::Env) override; + void writeBuffer(Napi::Env, + interop::Interface buffer, + interop::GPUSize64 bufferOffset, + interop::BufferSource data, + std::optional dataOffset, + std::optional size) override; + void writeTexture(Napi::Env, + interop::GPUImageCopyTexture destination, + interop::BufferSource data, + interop::GPUImageDataLayout dataLayout, + interop::GPUExtent3D size) override; + void copyExternalImageToTexture(Napi::Env, + interop::GPUImageCopyExternalImage source, + interop::GPUImageCopyTextureTagged destination, + interop::GPUExtent3D copySize) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::Queue queue_; + std::shared_ptr async_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUQUEUE_H_ diff --git a/src/dawn_node/binding/GPURenderBundle.h b/src/dawn_node/binding/GPURenderBundle.h new file mode 100644 index 0000000000..9f824f239e --- /dev/null +++ b/src/dawn_node/binding/GPURenderBundle.h @@ -0,0 +1,46 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPURENDERBUNDLE_H_ +#define DAWN_NODE_BINDING_GPURENDERBUNDLE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPURenderBundle is an implementation of interop::GPURenderBundle that wraps a + // wgpu::RenderBundle. + class GPURenderBundle final : public interop::GPURenderBundle { + public: + GPURenderBundle(wgpu::RenderBundle bundle); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::RenderBundle &() const { + return bundle_; + } + + // interop::GPURenderBundle interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::RenderBundle bundle_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPURENDERBUNDLE_H_ diff --git a/src/dawn_node/binding/GPURenderBundleEncoder.h b/src/dawn_node/binding/GPURenderBundleEncoder.h new file mode 100644 index 0000000000..e9ee6b2ae8 --- /dev/null +++ b/src/dawn_node/binding/GPURenderBundleEncoder.h @@ -0,0 +1,87 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPURENDERBUNDLEENCODER_H_ +#define DAWN_NODE_BINDING_GPURENDERBUNDLEENCODER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPURenderBundleEncoder is an implementation of interop::GPURenderBundleEncoder that wraps a + // wgpu::RenderBundleEncoder. + class GPURenderBundleEncoder final : public interop::GPURenderBundleEncoder { + public: + GPURenderBundleEncoder(wgpu::RenderBundleEncoder enc); + + // interop::GPURenderBundleEncoder interface compliance + interop::Interface finish( + Napi::Env, + std::optional descriptor) override; + void setBindGroup( + Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + std::optional> dynamicOffsets) override; + void setBindGroup(Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + interop::Uint32Array dynamicOffsetsData, + interop::GPUSize64 dynamicOffsetsDataStart, + interop::GPUSize32 dynamicOffsetsDataLength) override; + void pushDebugGroup(Napi::Env, std::string groupLabel) override; + void popDebugGroup(Napi::Env) override; + void insertDebugMarker(Napi::Env, std::string markerLabel) override; + void setPipeline(Napi::Env, + interop::Interface pipeline) override; + void setIndexBuffer(Napi::Env, + interop::Interface buffer, + interop::GPUIndexFormat indexFormat, + std::optional offset, + std::optional size) override; + void setVertexBuffer(Napi::Env, + interop::GPUIndex32 slot, + interop::Interface buffer, + std::optional offset, + std::optional size) override; + void draw(Napi::Env, + interop::GPUSize32 vertexCount, + std::optional instanceCount, + std::optional firstVertex, + std::optional firstInstance) override; + void drawIndexed(Napi::Env, + interop::GPUSize32 indexCount, + std::optional instanceCount, + std::optional firstIndex, + std::optional baseVertex, + std::optional firstInstance) override; + void drawIndirect(Napi::Env, + interop::Interface indirectBuffer, + interop::GPUSize64 indirectOffset) override; + void drawIndexedIndirect(Napi::Env, + interop::Interface indirectBuffer, + interop::GPUSize64 indirectOffset) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::RenderBundleEncoder enc_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPURENDERBUNDLEENCODER_H_ diff --git a/src/dawn_node/binding/GPURenderPassEncoder.h b/src/dawn_node/binding/GPURenderPassEncoder.h new file mode 100644 index 0000000000..adde06274f --- /dev/null +++ b/src/dawn_node/binding/GPURenderPassEncoder.h @@ -0,0 +1,116 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPURENDERPASSENCODER_H_ +#define DAWN_NODE_BINDING_GPURENDERPASSENCODER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPURenderPassEncoder is an implementation of interop::GPURenderPassEncoder that wraps a + // wgpu::RenderPassEncoder. + class GPURenderPassEncoder final : public interop::GPURenderPassEncoder { + public: + GPURenderPassEncoder(wgpu::RenderPassEncoder enc); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::RenderPassEncoder &() const { + return enc_; + } + + // interop::GPURenderPassEncoder interface compliance + void setViewport(Napi::Env, + float x, + float y, + float width, + float height, + float minDepth, + float maxDepth) override; + void setScissorRect(Napi::Env, + interop::GPUIntegerCoordinate x, + interop::GPUIntegerCoordinate y, + interop::GPUIntegerCoordinate width, + interop::GPUIntegerCoordinate height) override; + void setBlendConstant(Napi::Env, interop::GPUColor color) override; + void setStencilReference(Napi::Env, interop::GPUStencilValue reference) override; + void beginOcclusionQuery(Napi::Env, interop::GPUSize32 queryIndex) override; + void endOcclusionQuery(Napi::Env) override; + void beginPipelineStatisticsQuery(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 queryIndex) override; + void endPipelineStatisticsQuery(Napi::Env) override; + void writeTimestamp(Napi::Env, + interop::Interface querySet, + interop::GPUSize32 queryIndex) override; + void executeBundles( + Napi::Env, + std::vector> bundles) override; + void endPass(Napi::Env) override; + void setBindGroup( + Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + std::optional> dynamicOffsets) override; + void setBindGroup(Napi::Env, + interop::GPUIndex32 index, + interop::Interface bindGroup, + interop::Uint32Array dynamicOffsetsData, + interop::GPUSize64 dynamicOffsetsDataStart, + interop::GPUSize32 dynamicOffsetsDataLength) override; + void pushDebugGroup(Napi::Env, std::string groupLabel) override; + void popDebugGroup(Napi::Env) override; + void insertDebugMarker(Napi::Env, std::string markerLabel) override; + void setPipeline(Napi::Env, + interop::Interface pipeline) override; + void setIndexBuffer(Napi::Env, + interop::Interface buffer, + interop::GPUIndexFormat indexFormat, + std::optional offset, + std::optional size) override; + void setVertexBuffer(Napi::Env, + interop::GPUIndex32 slot, + interop::Interface buffer, + std::optional offset, + std::optional size) override; + void draw(Napi::Env, + interop::GPUSize32 vertexCount, + std::optional instanceCount, + std::optional firstVertex, + std::optional firstInstance) override; + void drawIndexed(Napi::Env, + interop::GPUSize32 indexCount, + std::optional instanceCount, + std::optional firstIndex, + std::optional baseVertex, + std::optional firstInstance) override; + void drawIndirect(Napi::Env, + interop::Interface indirectBuffer, + interop::GPUSize64 indirectOffset) override; + void drawIndexedIndirect(Napi::Env, + interop::Interface indirectBuffer, + interop::GPUSize64 indirectOffset) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::RenderPassEncoder enc_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPURENDERPASSENCODER_H_ diff --git a/src/dawn_node/binding/GPURenderPipeline.h b/src/dawn_node/binding/GPURenderPipeline.h new file mode 100644 index 0000000000..fc15fc6acb --- /dev/null +++ b/src/dawn_node/binding/GPURenderPipeline.h @@ -0,0 +1,48 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPURENDERPIPELINE_H_ +#define DAWN_NODE_BINDING_GPURENDERPIPELINE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPURenderPipeline is an implementation of interop::GPURenderPipeline that wraps a + // wgpu::RenderPipeline. + class GPURenderPipeline final : public interop::GPURenderPipeline { + public: + GPURenderPipeline(wgpu::RenderPipeline pipeline); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::RenderPipeline &() const { + return pipeline_; + } + + // interop::GPURenderPipeline interface compliance + interop::Interface getBindGroupLayout(Napi::Env, + uint32_t index) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::RenderPipeline pipeline_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPURENDERPIPELINE_H_ diff --git a/src/dawn_node/binding/GPUSampler.h b/src/dawn_node/binding/GPUSampler.h new file mode 100644 index 0000000000..24e77d2b5e --- /dev/null +++ b/src/dawn_node/binding/GPUSampler.h @@ -0,0 +1,44 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUSAMPLER_H_ +#define DAWN_NODE_BINDING_GPUSAMPLER_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + // GPUSampler is an implementation of interop::GPUSampler that wraps a wgpu::Sampler. + class GPUSampler final : public interop::GPUSampler { + public: + GPUSampler(wgpu::Sampler sampler); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::Sampler &() const { + return sampler_; + } + + // interop::GPUSampler interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::Sampler sampler_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUSAMPLER_H_ diff --git a/src/dawn_node/binding/GPUShaderModule.h b/src/dawn_node/binding/GPUShaderModule.h new file mode 100644 index 0000000000..2fcd140120 --- /dev/null +++ b/src/dawn_node/binding/GPUShaderModule.h @@ -0,0 +1,50 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUSHADERMODULE_H_ +#define DAWN_NODE_BINDING_GPUSHADERMODULE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/binding/AsyncRunner.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUShaderModule is an implementation of interop::GPUShaderModule that wraps a + // wgpu::ShaderModule. + class GPUShaderModule final : public interop::GPUShaderModule { + public: + GPUShaderModule(wgpu::ShaderModule shader, std::shared_ptr async); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::ShaderModule &() const { + return shader_; + } + + // interop::GPUShaderModule interface compliance + interop::Promise> compilationInfo( + Napi::Env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::ShaderModule shader_; + std::shared_ptr async_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUSHADERMODULE_H_ diff --git a/src/dawn_node/binding/GPUSupportedLimits.h b/src/dawn_node/binding/GPUSupportedLimits.h new file mode 100644 index 0000000000..b50753d822 --- /dev/null +++ b/src/dawn_node/binding/GPUSupportedLimits.h @@ -0,0 +1,59 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUSUPPORTEDLIMITS_H_ +#define DAWN_NODE_BINDING_GPUSUPPORTEDLIMITS_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUSupportedLimits is an implementation of interop::GPUSupportedLimits. + class GPUSupportedLimits final : public interop::GPUSupportedLimits { + public: + // interop::GPUSupportedLimits interface compliance + uint32_t getMaxTextureDimension1D(Napi::Env) override; + uint32_t getMaxTextureDimension2D(Napi::Env) override; + uint32_t getMaxTextureDimension3D(Napi::Env) override; + uint32_t getMaxTextureArrayLayers(Napi::Env) override; + uint32_t getMaxBindGroups(Napi::Env) override; + uint32_t getMaxDynamicUniformBuffersPerPipelineLayout(Napi::Env) override; + uint32_t getMaxDynamicStorageBuffersPerPipelineLayout(Napi::Env) override; + uint32_t getMaxSampledTexturesPerShaderStage(Napi::Env) override; + uint32_t getMaxSamplersPerShaderStage(Napi::Env) override; + uint32_t getMaxStorageBuffersPerShaderStage(Napi::Env) override; + uint32_t getMaxStorageTexturesPerShaderStage(Napi::Env) override; + uint32_t getMaxUniformBuffersPerShaderStage(Napi::Env) override; + uint64_t getMaxUniformBufferBindingSize(Napi::Env) override; + uint64_t getMaxStorageBufferBindingSize(Napi::Env) override; + uint32_t getMinUniformBufferOffsetAlignment(Napi::Env) override; + uint32_t getMinStorageBufferOffsetAlignment(Napi::Env) override; + uint32_t getMaxVertexBuffers(Napi::Env) override; + uint32_t getMaxVertexAttributes(Napi::Env) override; + uint32_t getMaxVertexBufferArrayStride(Napi::Env) override; + uint32_t getMaxInterStageShaderComponents(Napi::Env) override; + uint32_t getMaxComputeWorkgroupStorageSize(Napi::Env) override; + uint32_t getMaxComputeInvocationsPerWorkgroup(Napi::Env) override; + uint32_t getMaxComputeWorkgroupSizeX(Napi::Env) override; + uint32_t getMaxComputeWorkgroupSizeY(Napi::Env) override; + uint32_t getMaxComputeWorkgroupSizeZ(Napi::Env) override; + uint32_t getMaxComputeWorkgroupsPerDimension(Napi::Env) override; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUSUPPORTEDLIMITS_H_ diff --git a/src/dawn_node/binding/GPUTexture.h b/src/dawn_node/binding/GPUTexture.h new file mode 100644 index 0000000000..0058d878fb --- /dev/null +++ b/src/dawn_node/binding/GPUTexture.h @@ -0,0 +1,49 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUTEXTURE_H_ +#define DAWN_NODE_BINDING_GPUTEXTURE_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUTexture is an implementation of interop::GPUTexture that wraps a wgpu::Texture. + class GPUTexture final : public interop::GPUTexture { + public: + GPUTexture(wgpu::Texture texture); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::Texture &() const { + return texture_; + } + + // interop::GPUTexture interface compliance + interop::Interface createView( + Napi::Env, + std::optional descriptor) override; + void destroy(Napi::Env) override; + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::Texture texture_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUTEXTURE_H_ diff --git a/src/dawn_node/binding/GPUTextureView.h b/src/dawn_node/binding/GPUTextureView.h new file mode 100644 index 0000000000..8590735093 --- /dev/null +++ b/src/dawn_node/binding/GPUTextureView.h @@ -0,0 +1,46 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef DAWN_NODE_BINDING_GPUTEXTUREVIEW_H_ +#define DAWN_NODE_BINDING_GPUTEXTUREVIEW_H_ + +#include "dawn/webgpu_cpp.h" +#include "dawn_native/DawnNative.h" +#include "napi.h" +#include "src/dawn_node/interop/WebGPU.h" + +namespace wgpu { namespace binding { + + // GPUTextureView is an implementation of interop::GPUTextureView that wraps a + // wgpu::TextureView. + class GPUTextureView final : public interop::GPUTextureView { + public: + GPUTextureView(wgpu::TextureView view); + + // Implicit cast operator to Dawn GPU object + inline operator const wgpu::TextureView &() const { + return view_; + } + + // interop::GPUTextureView interface compliance + std::optional getLabel(Napi::Env) override; + void setLabel(Napi::Env, std::optional value) override; + + private: + wgpu::TextureView view_; + }; + +}} // namespace wgpu::binding + +#endif // DAWN_NODE_BINDING_GPUTEXTUREVIEW_H_