Bug 1909121 - [wpt-sync] Update web-platform-tests to 5af3e9c2a2aba76ade00f0dbc3486e5...
[gecko.git] / dom / webgpu / ComputePipeline.cpp
blob759d8e16db46d2cf8560dd02e5a2733d9c94bfd3
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) {
37 return;
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();
64 ipc::ByteBuf bb;
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