2019-10-02 19:46:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2020-01-22 10:31:51 +03:00
|
|
|
#include "mozilla/dom/WebGPUBinding.h"
|
2019-10-02 19:46:03 +03:00
|
|
|
#include "ComputePassEncoder.h"
|
2020-01-24 19:27:09 +03:00
|
|
|
#include "BindGroup.h"
|
|
|
|
#include "ComputePipeline.h"
|
2020-11-16 22:57:04 +03:00
|
|
|
#include "CommandEncoder.h"
|
2019-10-02 19:46:03 +03:00
|
|
|
|
2020-01-22 10:31:51 +03:00
|
|
|
#include "mozilla/webgpu/ffi/wgpu.h"
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace webgpu {
|
|
|
|
|
2020-03-18 20:29:51 +03:00
|
|
|
GPU_IMPL_CYCLE_COLLECTION(ComputePassEncoder, mParent, mUsedBindGroups,
|
|
|
|
mUsedPipelines)
|
2019-10-02 19:46:03 +03:00
|
|
|
GPU_IMPL_JS_WRAP(ComputePassEncoder)
|
|
|
|
|
2020-11-07 17:42:28 +03:00
|
|
|
ffi::WGPUComputePass* ScopedFfiComputeTraits::empty() { return nullptr; }
|
|
|
|
|
|
|
|
void ScopedFfiComputeTraits::release(ffi::WGPUComputePass* raw) {
|
|
|
|
if (raw) {
|
|
|
|
ffi::wgpu_compute_pass_destroy(raw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 05:43:09 +03:00
|
|
|
ffi::WGPUComputePass* BeginComputePass(
|
|
|
|
RawId aEncoderId, const dom::GPUComputePassDescriptor& aDesc) {
|
2020-01-22 10:31:51 +03:00
|
|
|
ffi::WGPUComputePassDescriptor desc = {};
|
|
|
|
Unused << aDesc; // no useful fields
|
|
|
|
return ffi::wgpu_command_encoder_begin_compute_pass(aEncoderId, &desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputePassEncoder::ComputePassEncoder(
|
|
|
|
CommandEncoder* const aParent, const dom::GPUComputePassDescriptor& aDesc)
|
2020-11-07 17:42:28 +03:00
|
|
|
: ChildOf(aParent), mPass(BeginComputePass(aParent->mId, aDesc)) {}
|
2020-01-22 10:31:51 +03:00
|
|
|
|
|
|
|
ComputePassEncoder::~ComputePassEncoder() {
|
|
|
|
if (mValid) {
|
|
|
|
mValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-24 19:27:09 +03:00
|
|
|
void ComputePassEncoder::SetBindGroup(
|
|
|
|
uint32_t aSlot, const BindGroup& aBindGroup,
|
|
|
|
const dom::Sequence<uint32_t>& aDynamicOffsets) {
|
|
|
|
if (mValid) {
|
2020-03-18 20:29:51 +03:00
|
|
|
mUsedBindGroups.AppendElement(&aBindGroup);
|
2020-11-07 17:42:28 +03:00
|
|
|
ffi::wgpu_compute_pass_set_bind_group(mPass, aSlot, aBindGroup.mId,
|
2020-01-24 19:27:09 +03:00
|
|
|
aDynamicOffsets.Elements(),
|
|
|
|
aDynamicOffsets.Length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputePassEncoder::SetPipeline(const ComputePipeline& aPipeline) {
|
|
|
|
if (mValid) {
|
2020-03-18 20:29:51 +03:00
|
|
|
mUsedPipelines.AppendElement(&aPipeline);
|
2020-11-07 17:42:28 +03:00
|
|
|
ffi::wgpu_compute_pass_set_pipeline(mPass, aPipeline.mId);
|
2020-01-24 19:27:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 10:31:51 +03:00
|
|
|
void ComputePassEncoder::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
|
|
|
|
if (mValid) {
|
2020-11-07 17:42:28 +03:00
|
|
|
ffi::wgpu_compute_pass_dispatch(mPass, x, y, z);
|
2020-01-22 10:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 16:20:18 +03:00
|
|
|
void ComputePassEncoder::DispatchIndirect(const Buffer& aIndirectBuffer,
|
|
|
|
uint64_t aIndirectOffset) {
|
|
|
|
if (mValid) {
|
2020-11-07 17:42:28 +03:00
|
|
|
ffi::wgpu_compute_pass_dispatch_indirect(mPass, aIndirectBuffer.mId,
|
2020-07-21 16:20:18 +03:00
|
|
|
aIndirectOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 10:31:51 +03:00
|
|
|
void ComputePassEncoder::EndPass(ErrorResult& aRv) {
|
|
|
|
if (mValid) {
|
|
|
|
mValid = false;
|
2020-11-07 17:42:28 +03:00
|
|
|
auto* pass = mPass.forget();
|
|
|
|
MOZ_ASSERT(pass);
|
|
|
|
mParent->EndComputePass(*pass, aRv);
|
2020-01-22 10:31:51 +03:00
|
|
|
}
|
|
|
|
}
|
2019-10-02 19:46:03 +03:00
|
|
|
|
|
|
|
} // namespace webgpu
|
|
|
|
} // namespace mozilla
|