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
)),
25 ComputePipeline::~ComputePipeline() { Cleanup(); }
27 void ComputePipeline::Cleanup() {
28 if (mValid
&& mParent
) {
30 auto bridge
= mParent
->GetBridge();
31 if (bridge
&& bridge
->IsOpen()) {
32 bridge
->SendComputePipelineDestroy(mId
);
33 if (mImplicitPipelineLayoutId
) {
34 bridge
->SendImplicitLayoutDestroy(mImplicitPipelineLayoutId
,
35 mImplicitBindGroupLayoutIds
);
41 already_AddRefed
<BindGroupLayout
> ComputePipeline::GetBindGroupLayout(
42 uint32_t index
) const {
43 const RawId id
= index
< mImplicitBindGroupLayoutIds
.Length()
44 ? mImplicitBindGroupLayoutIds
[index
]
46 RefPtr
<BindGroupLayout
> object
= new BindGroupLayout(mParent
, id
, false);
47 return object
.forget();
50 } // namespace mozilla::webgpu