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"
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
)
21 mImplicitPipelineLayoutId(aImplicitPipelineLayoutId
),
22 mImplicitBindGroupLayoutIds(std::move(aImplicitBindGroupLayoutIds
)),
24 MOZ_RELEASE_ASSERT(aId
);
27 ComputePipeline::~ComputePipeline() { Cleanup(); }
29 void ComputePipeline::Cleanup() {
35 auto bridge
= mParent
->GetBridge();
40 if (bridge
->CanSend()) {
41 bridge
->SendComputePipelineDrop(mId
);
42 if (mImplicitPipelineLayoutId
) {
43 bridge
->SendImplicitLayoutDrop(mImplicitPipelineLayoutId
,
44 mImplicitBindGroupLayoutIds
);
48 if (mImplicitPipelineLayoutId
) {
49 wgpu_client_free_pipeline_layout_id(bridge
->GetClient(),
50 mImplicitPipelineLayoutId
);
53 for (const auto& id
: mImplicitBindGroupLayoutIds
) {
54 wgpu_client_free_bind_group_layout_id(bridge
->GetClient(), id
);
58 already_AddRefed
<BindGroupLayout
> ComputePipeline::GetBindGroupLayout(
59 uint32_t aIndex
) const {
60 auto bridge
= mParent
->GetBridge();
61 MOZ_ASSERT(bridge
&& bridge
->CanSend());
62 auto* client
= bridge
->GetClient();
65 const RawId bglId
= ffi::wgpu_client_compute_pipeline_get_bind_group_layout(
66 client
, mId
, aIndex
, ToFFI(&bb
));
68 bridge
->SendDeviceAction(mParent
->GetId(), std::move(bb
));
70 RefPtr
<BindGroupLayout
> object
= new BindGroupLayout(mParent
, bglId
, false);
71 return object
.forget();
74 } // namespace mozilla::webgpu