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 "mozilla/dom/WebGPUBinding.h"
7 #include "mozilla/dom/Promise.h"
8 #include "ShaderModule.h"
9 #include "CompilationInfo.h"
10 #include "ipc/WebGPUChild.h"
14 namespace mozilla::webgpu
{
16 GPU_IMPL_CYCLE_COLLECTION(ShaderModule
, mParent
, mCompilationInfo
)
17 GPU_IMPL_JS_WRAP(ShaderModule
)
19 ShaderModule::ShaderModule(Device
* const aParent
, RawId aId
,
20 const RefPtr
<dom::Promise
>& aCompilationInfo
)
21 : ChildOf(aParent
), mId(aId
), mCompilationInfo(aCompilationInfo
) {
22 MOZ_RELEASE_ASSERT(aId
);
25 ShaderModule::~ShaderModule() { Cleanup(); }
27 void ShaderModule::Cleanup() {
33 auto bridge
= mParent
->GetBridge();
38 if (bridge
->CanSend()) {
39 bridge
->SendShaderModuleDrop(mId
);
42 wgpu_client_free_shader_module_id(bridge
->GetClient(), mId
);
45 already_AddRefed
<dom::Promise
> ShaderModule::CompilationInfo(ErrorResult
& aRv
) {
46 return GetCompilationInfo(aRv
);
49 already_AddRefed
<dom::Promise
> ShaderModule::GetCompilationInfo(
51 RefPtr
<dom::Promise
> tmp
= mCompilationInfo
;
55 } // namespace mozilla::webgpu