• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GPUCOMMANDENCODER_H_
16 #define DAWN_NODE_BINDING_GPUCOMMANDENCODER_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     // GPUCommandEncoder is an implementation of interop::GPUCommandEncoder that wraps a
26     // wgpu::CommandEncoder.
27     class GPUCommandEncoder final : public interop::GPUCommandEncoder {
28       public:
29         GPUCommandEncoder(wgpu::CommandEncoder enc);
30 
31         // interop::GPUCommandEncoder interface compliance
32         interop::Interface<interop::GPURenderPassEncoder> beginRenderPass(
33             Napi::Env,
34             interop::GPURenderPassDescriptor descriptor) override;
35         interop::Interface<interop::GPUComputePassEncoder> beginComputePass(
36             Napi::Env,
37             interop::GPUComputePassDescriptor descriptor) override;
38         void copyBufferToBuffer(Napi::Env,
39                                 interop::Interface<interop::GPUBuffer> source,
40                                 interop::GPUSize64 sourceOffset,
41                                 interop::Interface<interop::GPUBuffer> destination,
42                                 interop::GPUSize64 destinationOffset,
43                                 interop::GPUSize64 size) override;
44         void copyBufferToTexture(Napi::Env,
45                                  interop::GPUImageCopyBuffer source,
46                                  interop::GPUImageCopyTexture destination,
47                                  interop::GPUExtent3D copySize) override;
48         void copyTextureToBuffer(Napi::Env,
49                                  interop::GPUImageCopyTexture source,
50                                  interop::GPUImageCopyBuffer destination,
51                                  interop::GPUExtent3D copySize) override;
52         void copyTextureToTexture(Napi::Env,
53                                   interop::GPUImageCopyTexture source,
54                                   interop::GPUImageCopyTexture destination,
55                                   interop::GPUExtent3D copySize) override;
56         void pushDebugGroup(Napi::Env, std::string groupLabel) override;
57         void popDebugGroup(Napi::Env) override;
58         void insertDebugMarker(Napi::Env, std::string markerLabel) override;
59         void writeTimestamp(Napi::Env,
60                             interop::Interface<interop::GPUQuerySet> querySet,
61                             interop::GPUSize32 queryIndex) override;
62         void resolveQuerySet(Napi::Env,
63                              interop::Interface<interop::GPUQuerySet> querySet,
64                              interop::GPUSize32 firstQuery,
65                              interop::GPUSize32 queryCount,
66                              interop::Interface<interop::GPUBuffer> destination,
67                              interop::GPUSize64 destinationOffset) override;
68         interop::Interface<interop::GPUCommandBuffer> finish(
69             Napi::Env env,
70             interop::GPUCommandBufferDescriptor descriptor) override;
71         std::optional<std::string> getLabel(Napi::Env) override;
72         void setLabel(Napi::Env, std::optional<std::string> value) override;
73 
74       private:
75         wgpu::CommandEncoder enc_;
76     };
77 
78 }}  // namespace wgpu::binding
79 
80 #endif  // DAWN_NODE_BINDING_GPUCOMMANDENCODER_H_
81