• 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_GPUQUEUE_H_
16 #define DAWN_NODE_BINDING_GPUQUEUE_H_
17 
18 #include "dawn/webgpu_cpp.h"
19 #include "dawn_native/DawnNative.h"
20 #include "napi.h"
21 #include "src/dawn_node/binding/AsyncRunner.h"
22 #include "src/dawn_node/interop/WebGPU.h"
23 
24 namespace wgpu { namespace binding {
25 
26     // GPUQueue is an implementation of interop::GPUQueue that wraps a wgpu::Queue.
27     class GPUQueue final : public interop::GPUQueue {
28       public:
29         GPUQueue(wgpu::Queue queue, std::shared_ptr<AsyncRunner> async);
30 
31         // interop::GPUQueue interface compliance
32         void submit(
33             Napi::Env,
34             std::vector<interop::Interface<interop::GPUCommandBuffer>> commandBuffers) override;
35         interop::Promise<void> onSubmittedWorkDone(Napi::Env) override;
36         void writeBuffer(Napi::Env,
37                          interop::Interface<interop::GPUBuffer> buffer,
38                          interop::GPUSize64 bufferOffset,
39                          interop::BufferSource data,
40                          interop::GPUSize64 dataOffset,
41                          std::optional<interop::GPUSize64> size) override;
42         void writeTexture(Napi::Env,
43                           interop::GPUImageCopyTexture destination,
44                           interop::BufferSource data,
45                           interop::GPUImageDataLayout dataLayout,
46                           interop::GPUExtent3D size) override;
47         void copyExternalImageToTexture(Napi::Env,
48                                         interop::GPUImageCopyExternalImage source,
49                                         interop::GPUImageCopyTextureTagged destination,
50                                         interop::GPUExtent3D copySize) override;
51         std::optional<std::string> getLabel(Napi::Env) override;
52         void setLabel(Napi::Env, std::optional<std::string> value) override;
53 
54       private:
55         wgpu::Queue queue_;
56         std::shared_ptr<AsyncRunner> async_;
57     };
58 
59 }}  // namespace wgpu::binding
60 
61 #endif  // DAWN_NODE_BINDING_GPUQUEUE_H_
62