dawn_node: Add binding/GPUComputePassEncoder.cpp
Bug: dawn:1123 Change-Id: Ied735455b04f52ba214b3ef9ef41edb78d9ed6fd Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64914 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
c5d9650308
commit
334714b312
|
@ -30,6 +30,7 @@ add_library(dawn_node_binding STATIC
|
||||||
"GPUCommandBuffer.cpp"
|
"GPUCommandBuffer.cpp"
|
||||||
"GPUCommandBuffer.h"
|
"GPUCommandBuffer.h"
|
||||||
"GPUCommandEncoder.h"
|
"GPUCommandEncoder.h"
|
||||||
|
"GPUComputePassEncoder.cpp"
|
||||||
"GPUComputePassEncoder.h"
|
"GPUComputePassEncoder.h"
|
||||||
"GPUComputePipeline.cpp"
|
"GPUComputePipeline.cpp"
|
||||||
"GPUComputePipeline.h"
|
"GPUComputePipeline.h"
|
||||||
|
|
|
@ -0,0 +1,147 @@
|
||||||
|
// Copyright 2021 The Dawn Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "src/dawn_node/binding/GPUComputePassEncoder.h"
|
||||||
|
|
||||||
|
#include "src/dawn_node/binding/Converter.h"
|
||||||
|
#include "src/dawn_node/binding/GPUBindGroup.h"
|
||||||
|
#include "src/dawn_node/binding/GPUBuffer.h"
|
||||||
|
#include "src/dawn_node/binding/GPUComputePipeline.h"
|
||||||
|
#include "src/dawn_node/binding/GPUQuerySet.h"
|
||||||
|
#include "src/dawn_node/utils/Debug.h"
|
||||||
|
|
||||||
|
namespace wgpu { namespace binding {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// wgpu::bindings::GPUComputePassEncoder
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
GPUComputePassEncoder::GPUComputePassEncoder(wgpu::ComputePassEncoder enc)
|
||||||
|
: enc_(std::move(enc)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::setPipeline(
|
||||||
|
Napi::Env,
|
||||||
|
interop::Interface<interop::GPUComputePipeline> pipeline) {
|
||||||
|
enc_.SetPipeline(*pipeline.As<GPUComputePipeline>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::dispatch(Napi::Env,
|
||||||
|
interop::GPUSize32 x,
|
||||||
|
std::optional<interop::GPUSize32> y,
|
||||||
|
std::optional<interop::GPUSize32> z) {
|
||||||
|
enc_.Dispatch(x, y.value_or(1), z.value_or(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::dispatchIndirect(
|
||||||
|
Napi::Env,
|
||||||
|
interop::Interface<interop::GPUBuffer> indirectBuffer,
|
||||||
|
interop::GPUSize64 indirectOffset) {
|
||||||
|
enc_.DispatchIndirect(*indirectBuffer.As<GPUBuffer>(), indirectOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::beginPipelineStatisticsQuery(
|
||||||
|
Napi::Env,
|
||||||
|
interop::Interface<interop::GPUQuerySet> querySet,
|
||||||
|
interop::GPUSize32 queryIndex) {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::endPipelineStatisticsQuery(Napi::Env) {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::writeTimestamp(Napi::Env env,
|
||||||
|
interop::Interface<interop::GPUQuerySet> querySet,
|
||||||
|
interop::GPUSize32 queryIndex) {
|
||||||
|
Converter conv(env);
|
||||||
|
|
||||||
|
wgpu::QuerySet q{};
|
||||||
|
if (!conv(q, querySet)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enc_.WriteTimestamp(q, queryIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::endPass(Napi::Env) {
|
||||||
|
enc_.EndPass();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::setBindGroup(
|
||||||
|
Napi::Env env,
|
||||||
|
interop::GPUIndex32 index,
|
||||||
|
interop::Interface<interop::GPUBindGroup> bindGroup,
|
||||||
|
std::optional<std::vector<interop::GPUBufferDynamicOffset>> dynamicOffsets) {
|
||||||
|
Converter conv(env);
|
||||||
|
|
||||||
|
wgpu::BindGroup bg{};
|
||||||
|
if (!conv(bg, bindGroup)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::vector<uint32_t> offsets;
|
||||||
|
if (dynamicOffsets.has_value() && dynamicOffsets->size() > 0) {
|
||||||
|
offsets.resize(dynamicOffsets->size());
|
||||||
|
for (size_t i = 0; i < offsets.size(); i++) {
|
||||||
|
if (!conv(offsets[i], dynamicOffsets.value()[i])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32_t offsets_size;
|
||||||
|
if (!conv(offsets_size, offsets.size())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
enc_.SetBindGroup(index, bg, offsets_size, offsets.data());
|
||||||
|
} else {
|
||||||
|
enc_.SetBindGroup(index, bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::setBindGroup(Napi::Env env,
|
||||||
|
interop::GPUIndex32 index,
|
||||||
|
interop::Interface<interop::GPUBindGroup> bindGroup,
|
||||||
|
interop::Uint32Array dynamicOffsetsData,
|
||||||
|
interop::GPUSize64 dynamicOffsetsDataStart,
|
||||||
|
interop::GPUSize32 dynamicOffsetsDataLength) {
|
||||||
|
Converter conv(env);
|
||||||
|
|
||||||
|
wgpu::BindGroup bg{};
|
||||||
|
if (!conv(bg, bindGroup)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enc_.SetBindGroup(index, bg, dynamicOffsetsDataLength,
|
||||||
|
dynamicOffsetsData.Data() + dynamicOffsetsDataStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::pushDebugGroup(Napi::Env, std::string groupLabel) {
|
||||||
|
enc_.PushDebugGroup(groupLabel.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::popDebugGroup(Napi::Env) {
|
||||||
|
enc_.PopDebugGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::insertDebugMarker(Napi::Env, std::string markerLabel) {
|
||||||
|
enc_.InsertDebugMarker(markerLabel.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> GPUComputePassEncoder::getLabel(Napi::Env) {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPUComputePassEncoder::setLabel(Napi::Env, std::optional<std::string> value) {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
|
|
||||||
|
}} // namespace wgpu::binding
|
Loading…
Reference in New Issue