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/. */
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/dom/NonRefcountedDOMObject.h"
13 #include "mozilla/webgpu/WebGPUTypes.h"
14 #include "nsPrintfCString.h"
16 #include "ObjectModel.h"
22 struct GPUDeviceDescriptor
;
25 enum class GPUFeatureName
: uint8_t;
26 enum class WgpuBackend
: uint8_t;
27 enum class WgpuDeviceType
: uint8_t;
35 class SupportedFeatures
;
36 class SupportedLimits
;
39 struct WGPUAdapterInformation
;
42 class AdapterInfo final
: public dom::NonRefcountedDOMObject
{
44 const std::shared_ptr
<ffi::WGPUAdapterInformation
> mAboutSupportInfo
;
48 const std::shared_ptr
<ffi::WGPUAdapterInformation
>& aAboutSupportInfo
)
49 : mAboutSupportInfo(aAboutSupportInfo
) {}
51 void GetVendor(nsString
& s
) const { s
= nsString(); }
52 void GetArchitecture(nsString
& s
) const { s
= nsString(); }
53 void GetDevice(nsString
& s
) const { s
= nsString(); }
54 void GetDescription(nsString
& s
) const { s
= nsString(); }
56 // Non-standard field getters; see also TODO BUGZILLA LINK
57 void GetWgpuName(nsString
&) const;
58 uint32_t WgpuVendor() const;
59 uint32_t WgpuDevice() const;
60 void GetWgpuDeviceType(nsString
&) const;
61 void GetWgpuDriver(nsString
&) const;
62 void GetWgpuDriverInfo(nsString
&) const;
63 void GetWgpuBackend(nsString
&) const;
65 bool WrapObject(JSContext
*, JS::Handle
<JSObject
*>,
66 JS::MutableHandle
<JSObject
*>);
69 inline auto ToHexCString(const uint64_t v
) {
70 return nsPrintfCString("0x%" PRIx64
, v
);
73 class Adapter final
: public ObjectBase
, public ChildOf
<Instance
> {
75 GPU_DECL_CYCLE_COLLECTION(Adapter
)
76 GPU_DECL_JS_WRAP(Adapter
)
78 RefPtr
<WebGPUChild
> mBridge
;
85 // Cant have them as `const` right now, since we wouldn't be able
86 // to unlink them in CC unlink.
87 RefPtr
<SupportedFeatures
> mFeatures
;
88 RefPtr
<SupportedLimits
> mLimits
;
90 const std::shared_ptr
<ffi::WGPUAdapterInformation
> mInfo
;
93 Adapter(Instance
* const aParent
, WebGPUChild
* const aBridge
,
94 const std::shared_ptr
<ffi::WGPUAdapterInformation
>& aInfo
);
95 const RefPtr
<SupportedFeatures
>& Features() const;
96 const RefPtr
<SupportedLimits
>& Limits() const;
97 bool IsFallbackAdapter() const;
99 nsCString
LabelOrId() const {
100 nsCString ret
= this->CLabel();
102 ret
= ToHexCString(mId
);
107 already_AddRefed
<dom::Promise
> RequestDevice(
108 const dom::GPUDeviceDescriptor
& aDesc
, ErrorResult
& aRv
);
110 already_AddRefed
<dom::Promise
> RequestAdapterInfo(
111 const dom::Sequence
<nsString
>& aUnmaskHints
, ErrorResult
& aRv
) const;
114 } // namespace webgpu
115 } // namespace mozilla
117 #endif // GPU_Adapter_H_