1 // Copyright 2021 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ 16 #define DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ 17 18 #include "dawn/webgpu_cpp.h" 19 #include "dawn_native/DawnNative.h" 20 #include "napi.h" 21 #include "src/dawn_node/interop/WebGPU.h" 22 23 namespace wgpu { namespace binding { 24 25 // GPUComputePassEncoder is an implementation of interop::GPUComputePassEncoder that wraps a 26 // wgpu::ComputePassEncoder. 27 class GPUComputePassEncoder final : public interop::GPUComputePassEncoder { 28 public: 29 GPUComputePassEncoder(wgpu::ComputePassEncoder enc); 30 31 // Implicit cast operator to Dawn GPU object 32 inline operator const wgpu::ComputePassEncoder &() const { 33 return enc_; 34 } 35 36 // interop::GPUComputePassEncoder interface compliance 37 void setPipeline(Napi::Env, 38 interop::Interface<interop::GPUComputePipeline> pipeline) override; 39 void dispatch(Napi::Env, 40 interop::GPUSize32 x, 41 interop::GPUSize32 y, 42 interop::GPUSize32 z) override; 43 void dispatchIndirect(Napi::Env, 44 interop::Interface<interop::GPUBuffer> indirectBuffer, 45 interop::GPUSize64 indirectOffset) override; 46 void beginPipelineStatisticsQuery(Napi::Env, 47 interop::Interface<interop::GPUQuerySet> querySet, 48 interop::GPUSize32 queryIndex) override; 49 void endPipelineStatisticsQuery(Napi::Env) override; 50 void writeTimestamp(Napi::Env, 51 interop::Interface<interop::GPUQuerySet> querySet, 52 interop::GPUSize32 queryIndex) override; 53 void endPass(Napi::Env) override; 54 void setBindGroup(Napi::Env, 55 interop::GPUIndex32 index, 56 interop::Interface<interop::GPUBindGroup> bindGroup, 57 std::vector<interop::GPUBufferDynamicOffset> dynamicOffsets) override; 58 void setBindGroup(Napi::Env, 59 interop::GPUIndex32 index, 60 interop::Interface<interop::GPUBindGroup> bindGroup, 61 interop::Uint32Array dynamicOffsetsData, 62 interop::GPUSize64 dynamicOffsetsDataStart, 63 interop::GPUSize32 dynamicOffsetsDataLength) override; 64 void pushDebugGroup(Napi::Env, std::string groupLabel) override; 65 void popDebugGroup(Napi::Env) override; 66 void insertDebugMarker(Napi::Env, std::string markerLabel) override; 67 std::optional<std::string> getLabel(Napi::Env) override; 68 void setLabel(Napi::Env, std::optional<std::string> value) override; 69 70 private: 71 wgpu::ComputePassEncoder enc_; 72 }; 73 74 }} // namespace wgpu::binding 75 76 #endif // DAWN_NODE_BINDING_GPUCOMPUTEPASSENCODER_H_ 77