• 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 #include "src/dawn_node/binding/GPUComputePassEncoder.h"
16 
17 #include "src/dawn_node/binding/Converter.h"
18 #include "src/dawn_node/binding/GPUBindGroup.h"
19 #include "src/dawn_node/binding/GPUBuffer.h"
20 #include "src/dawn_node/binding/GPUComputePipeline.h"
21 #include "src/dawn_node/binding/GPUQuerySet.h"
22 #include "src/dawn_node/utils/Debug.h"
23 
24 namespace wgpu { namespace binding {
25 
26     ////////////////////////////////////////////////////////////////////////////////
27     // wgpu::bindings::GPUComputePassEncoder
28     ////////////////////////////////////////////////////////////////////////////////
GPUComputePassEncoder(wgpu::ComputePassEncoder enc)29     GPUComputePassEncoder::GPUComputePassEncoder(wgpu::ComputePassEncoder enc)
30         : enc_(std::move(enc)) {
31     }
32 
setPipeline(Napi::Env,interop::Interface<interop::GPUComputePipeline> pipeline)33     void GPUComputePassEncoder::setPipeline(
34         Napi::Env,
35         interop::Interface<interop::GPUComputePipeline> pipeline) {
36         enc_.SetPipeline(*pipeline.As<GPUComputePipeline>());
37     }
38 
dispatch(Napi::Env,interop::GPUSize32 x,interop::GPUSize32 y,interop::GPUSize32 z)39     void GPUComputePassEncoder::dispatch(Napi::Env,
40                                          interop::GPUSize32 x,
41                                          interop::GPUSize32 y,
42                                          interop::GPUSize32 z) {
43         enc_.Dispatch(x, y, z);
44     }
45 
dispatchIndirect(Napi::Env,interop::Interface<interop::GPUBuffer> indirectBuffer,interop::GPUSize64 indirectOffset)46     void GPUComputePassEncoder::dispatchIndirect(
47         Napi::Env,
48         interop::Interface<interop::GPUBuffer> indirectBuffer,
49         interop::GPUSize64 indirectOffset) {
50         enc_.DispatchIndirect(*indirectBuffer.As<GPUBuffer>(), indirectOffset);
51     }
52 
beginPipelineStatisticsQuery(Napi::Env,interop::Interface<interop::GPUQuerySet> querySet,interop::GPUSize32 queryIndex)53     void GPUComputePassEncoder::beginPipelineStatisticsQuery(
54         Napi::Env,
55         interop::Interface<interop::GPUQuerySet> querySet,
56         interop::GPUSize32 queryIndex) {
57         UNIMPLEMENTED();
58     }
59 
endPipelineStatisticsQuery(Napi::Env)60     void GPUComputePassEncoder::endPipelineStatisticsQuery(Napi::Env) {
61         UNIMPLEMENTED();
62     }
63 
writeTimestamp(Napi::Env env,interop::Interface<interop::GPUQuerySet> querySet,interop::GPUSize32 queryIndex)64     void GPUComputePassEncoder::writeTimestamp(Napi::Env env,
65                                                interop::Interface<interop::GPUQuerySet> querySet,
66                                                interop::GPUSize32 queryIndex) {
67         Converter conv(env);
68 
69         wgpu::QuerySet q{};
70         if (!conv(q, querySet)) {
71             return;
72         }
73 
74         enc_.WriteTimestamp(q, queryIndex);
75     }
76 
endPass(Napi::Env)77     void GPUComputePassEncoder::endPass(Napi::Env) {
78         enc_.EndPass();
79     }
80 
setBindGroup(Napi::Env env,interop::GPUIndex32 index,interop::Interface<interop::GPUBindGroup> bindGroup,std::vector<interop::GPUBufferDynamicOffset> dynamicOffsets)81     void GPUComputePassEncoder::setBindGroup(
82         Napi::Env env,
83         interop::GPUIndex32 index,
84         interop::Interface<interop::GPUBindGroup> bindGroup,
85         std::vector<interop::GPUBufferDynamicOffset> dynamicOffsets) {
86         Converter conv(env);
87 
88         wgpu::BindGroup bg{};
89         uint32_t* offsets = nullptr;
90         uint32_t num_offsets = 0;
91         if (!conv(bg, bindGroup) || !conv(offsets, num_offsets, dynamicOffsets)) {
92             return;
93         }
94 
95         enc_.SetBindGroup(index, bg, num_offsets, offsets);
96     }
97 
setBindGroup(Napi::Env env,interop::GPUIndex32 index,interop::Interface<interop::GPUBindGroup> bindGroup,interop::Uint32Array dynamicOffsetsData,interop::GPUSize64 dynamicOffsetsDataStart,interop::GPUSize32 dynamicOffsetsDataLength)98     void GPUComputePassEncoder::setBindGroup(Napi::Env env,
99                                              interop::GPUIndex32 index,
100                                              interop::Interface<interop::GPUBindGroup> bindGroup,
101                                              interop::Uint32Array dynamicOffsetsData,
102                                              interop::GPUSize64 dynamicOffsetsDataStart,
103                                              interop::GPUSize32 dynamicOffsetsDataLength) {
104         Converter conv(env);
105 
106         wgpu::BindGroup bg{};
107         if (!conv(bg, bindGroup)) {
108             return;
109         }
110 
111         enc_.SetBindGroup(index, bg, dynamicOffsetsDataLength,
112                           dynamicOffsetsData.Data() + dynamicOffsetsDataStart);
113     }
114 
pushDebugGroup(Napi::Env,std::string groupLabel)115     void GPUComputePassEncoder::pushDebugGroup(Napi::Env, std::string groupLabel) {
116         enc_.PushDebugGroup(groupLabel.c_str());
117     }
118 
popDebugGroup(Napi::Env)119     void GPUComputePassEncoder::popDebugGroup(Napi::Env) {
120         enc_.PopDebugGroup();
121     }
122 
insertDebugMarker(Napi::Env,std::string markerLabel)123     void GPUComputePassEncoder::insertDebugMarker(Napi::Env, std::string markerLabel) {
124         enc_.InsertDebugMarker(markerLabel.c_str());
125     }
126 
getLabel(Napi::Env)127     std::optional<std::string> GPUComputePassEncoder::getLabel(Napi::Env) {
128         UNIMPLEMENTED();
129     }
130 
setLabel(Napi::Env,std::optional<std::string> value)131     void GPUComputePassEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
132         UNIMPLEMENTED();
133     }
134 
135 }}  // namespace wgpu::binding
136