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_GPURENDERPASSENCODER_H_ 16 #define DAWN_NODE_BINDING_GPURENDERPASSENCODER_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 // GPURenderPassEncoder is an implementation of interop::GPURenderPassEncoder that wraps a 26 // wgpu::RenderPassEncoder. 27 class GPURenderPassEncoder final : public interop::GPURenderPassEncoder { 28 public: 29 GPURenderPassEncoder(wgpu::RenderPassEncoder enc); 30 31 // Implicit cast operator to Dawn GPU object 32 inline operator const wgpu::RenderPassEncoder &() const { 33 return enc_; 34 } 35 36 // interop::GPURenderPassEncoder interface compliance 37 void setViewport(Napi::Env, 38 float x, 39 float y, 40 float width, 41 float height, 42 float minDepth, 43 float maxDepth) override; 44 void setScissorRect(Napi::Env, 45 interop::GPUIntegerCoordinate x, 46 interop::GPUIntegerCoordinate y, 47 interop::GPUIntegerCoordinate width, 48 interop::GPUIntegerCoordinate height) override; 49 void setBlendConstant(Napi::Env, interop::GPUColor color) override; 50 void setStencilReference(Napi::Env, interop::GPUStencilValue reference) override; 51 void beginOcclusionQuery(Napi::Env, interop::GPUSize32 queryIndex) override; 52 void endOcclusionQuery(Napi::Env) override; 53 void beginPipelineStatisticsQuery(Napi::Env, 54 interop::Interface<interop::GPUQuerySet> querySet, 55 interop::GPUSize32 queryIndex) override; 56 void endPipelineStatisticsQuery(Napi::Env) override; 57 void writeTimestamp(Napi::Env, 58 interop::Interface<interop::GPUQuerySet> querySet, 59 interop::GPUSize32 queryIndex) override; 60 void executeBundles( 61 Napi::Env, 62 std::vector<interop::Interface<interop::GPURenderBundle>> bundles) override; 63 void endPass(Napi::Env) override; 64 void setBindGroup(Napi::Env, 65 interop::GPUIndex32 index, 66 interop::Interface<interop::GPUBindGroup> bindGroup, 67 std::vector<interop::GPUBufferDynamicOffset> dynamicOffsets) override; 68 void setBindGroup(Napi::Env, 69 interop::GPUIndex32 index, 70 interop::Interface<interop::GPUBindGroup> bindGroup, 71 interop::Uint32Array dynamicOffsetsData, 72 interop::GPUSize64 dynamicOffsetsDataStart, 73 interop::GPUSize32 dynamicOffsetsDataLength) override; 74 void pushDebugGroup(Napi::Env, std::string groupLabel) override; 75 void popDebugGroup(Napi::Env) override; 76 void insertDebugMarker(Napi::Env, std::string markerLabel) override; 77 void setPipeline(Napi::Env, 78 interop::Interface<interop::GPURenderPipeline> pipeline) override; 79 void setIndexBuffer(Napi::Env, 80 interop::Interface<interop::GPUBuffer> buffer, 81 interop::GPUIndexFormat indexFormat, 82 interop::GPUSize64 offset, 83 std::optional<interop::GPUSize64> size) override; 84 void setVertexBuffer(Napi::Env, 85 interop::GPUIndex32 slot, 86 interop::Interface<interop::GPUBuffer> buffer, 87 interop::GPUSize64 offset, 88 std::optional<interop::GPUSize64> size) override; 89 void draw(Napi::Env, 90 interop::GPUSize32 vertexCount, 91 interop::GPUSize32 instanceCount, 92 interop::GPUSize32 firstVertex, 93 interop::GPUSize32 firstInstance) override; 94 void drawIndexed(Napi::Env, 95 interop::GPUSize32 indexCount, 96 interop::GPUSize32 instanceCount, 97 interop::GPUSize32 firstIndex, 98 interop::GPUSignedOffset32 baseVertex, 99 interop::GPUSize32 firstInstance) override; 100 void drawIndirect(Napi::Env, 101 interop::Interface<interop::GPUBuffer> indirectBuffer, 102 interop::GPUSize64 indirectOffset) override; 103 void drawIndexedIndirect(Napi::Env, 104 interop::Interface<interop::GPUBuffer> indirectBuffer, 105 interop::GPUSize64 indirectOffset) override; 106 std::optional<std::string> getLabel(Napi::Env) override; 107 void setLabel(Napi::Env, std::optional<std::string> value) override; 108 109 private: 110 wgpu::RenderPassEncoder enc_; 111 }; 112 113 }} // namespace wgpu::binding 114 115 #endif // DAWN_NODE_BINDING_GPURENDERPASSENCODER_H_ 116