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() {
30 if (mValid
&& mParent
) {
32 auto bridge
= mParent
->GetBridge();
33 if (bridge
&& bridge
->IsOpen()) {
34 bridge
->SendComputePipelineDrop(mId
);
35 if (mImplicitPipelineLayoutId
) {
36 bridge
->SendImplicitLayoutDrop(mImplicitPipelineLayoutId
,
37 mImplicitBindGroupLayoutIds
);
43 already_AddRefed
<BindGroupLayout
> ComputePipeline::GetBindGroupLayout(
44 uint32_t aIndex
) const {
45 auto bridge
= mParent
->GetBridge();
46 auto* client
= bridge
->GetClient();
49 const RawId bglId
= ffi::wgpu_client_compute_pipeline_get_bind_group_layout(
50 client
, mId
, aIndex
, ToFFI(&bb
));
52 bridge
->SendDeviceAction(mParent
->GetId(), std::move(bb
));
54 RefPtr
<BindGroupLayout
> object
= new BindGroupLayout(mParent
, bglId
, false);
55 return object
.forget();
58 } // namespace mozilla::webgpu