Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / webgpu / ComputePipeline.cpp
blobecd43289f356741499246259af8da9a8295bc1db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ComputePipeline.h"
8 #include "Device.h"
9 #include "ipc/WebGPUChild.h"
10 #include "mozilla/dom/WebGPUBinding.h"
12 namespace mozilla::webgpu {
14 GPU_IMPL_CYCLE_COLLECTION(ComputePipeline, mParent)
15 GPU_IMPL_JS_WRAP(ComputePipeline)
17 ComputePipeline::ComputePipeline(Device* const aParent, RawId aId,
18 RawId aImplicitPipelineLayoutId,
19 nsTArray<RawId>&& aImplicitBindGroupLayoutIds)
20 : ChildOf(aParent),
21 mImplicitPipelineLayoutId(aImplicitPipelineLayoutId),
22 mImplicitBindGroupLayoutIds(std::move(aImplicitBindGroupLayoutIds)),
23 mId(aId) {
24 MOZ_RELEASE_ASSERT(aId);
27 ComputePipeline::~ComputePipeline() { Cleanup(); }
29 void ComputePipeline::Cleanup() {
30 if (mValid) {
31 return;
33 mValid = false;
35 auto bridge = mParent->GetBridge();
36 if (bridge->CanSend()) {
37 bridge->SendComputePipelineDrop(mId);
38 if (mImplicitPipelineLayoutId) {
39 bridge->SendImplicitLayoutDrop(mImplicitPipelineLayoutId,
40 mImplicitBindGroupLayoutIds);
44 if (mImplicitPipelineLayoutId) {
45 wgpu_client_free_pipeline_layout_id(bridge->GetClient(),
46 mImplicitPipelineLayoutId);
49 for (const auto& id : mImplicitBindGroupLayoutIds) {
50 wgpu_client_free_bind_group_layout_id(bridge->GetClient(), id);
54 already_AddRefed<BindGroupLayout> ComputePipeline::GetBindGroupLayout(
55 uint32_t aIndex) const {
56 auto bridge = mParent->GetBridge();
57 auto* client = bridge->GetClient();
59 ipc::ByteBuf bb;
60 const RawId bglId = ffi::wgpu_client_compute_pipeline_get_bind_group_layout(
61 client, mId, aIndex, ToFFI(&bb));
63 bridge->SendDeviceAction(mParent->GetId(), std::move(bb));
65 RefPtr<BindGroupLayout> object = new BindGroupLayout(mParent, bglId, false);
66 return object.forget();
69 } // namespace mozilla::webgpu