Loading dom/webgpu/Adapter.cpp +11 −80 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/WebGPUBinding.h" #include "Adapter.h" Loading @@ -23,73 +22,6 @@ bool AdapterInfo::WrapObject(JSContext* const cx, return dom::GPUAdapterInfo_Binding::Wrap(cx, this, givenProto, reflector); } void AdapterInfo::GetWgpuName(nsString& s) const { s = mAboutSupportInfo->name; } size_t AdapterInfo::WgpuVendor() const { return mAboutSupportInfo->vendor; } size_t AdapterInfo::WgpuDevice() const { return mAboutSupportInfo->device; } void AdapterInfo::GetWgpuDeviceType(nsString& s) const { switch (mAboutSupportInfo->device_type) { case ffi::WGPUDeviceType_Cpu: s.AssignLiteral("Cpu"); return; case ffi::WGPUDeviceType_DiscreteGpu: s.AssignLiteral("DiscreteGpu"); return; case ffi::WGPUDeviceType_IntegratedGpu: s.AssignLiteral("IntegratedGpu"); return; case ffi::WGPUDeviceType_VirtualGpu: s.AssignLiteral("VirtualGpu"); return; case ffi::WGPUDeviceType_Other: s.AssignLiteral("Other"); return; case ffi::WGPUDeviceType_Sentinel: break; } MOZ_CRASH("Bad `ffi::WGPUDeviceType`"); } void AdapterInfo::GetWgpuDriver(nsString& s) const { s = mAboutSupportInfo->driver; } void AdapterInfo::GetWgpuDriverInfo(nsString& s) const { s = mAboutSupportInfo->driver_info; } void AdapterInfo::GetWgpuBackend(nsString& s) const { switch (mAboutSupportInfo->backend) { case ffi::WGPUBackend_Empty: s.AssignLiteral("Empty"); return; case ffi::WGPUBackend_Vulkan: s.AssignLiteral("Vulkan"); return; case ffi::WGPUBackend_Metal: s.AssignLiteral("Metal"); return; case ffi::WGPUBackend_Dx12: s.AssignLiteral("Dx12"); return; case ffi::WGPUBackend_Dx11: s.AssignLiteral("Dx11"); return; case ffi::WGPUBackend_Gl: s.AssignLiteral("Gl"); return; case ffi::WGPUBackend_BrowserWebGpu: // This should never happen, because // we _are_ the browser. case ffi::WGPUBackend_Sentinel: break; } MOZ_CRASH("Bad `ffi::WGPUBackend`"); } // - GPU_IMPL_CYCLE_COLLECTION(Adapter, mParent, mBridge, mFeatures, mLimits) Loading Loading @@ -119,25 +51,25 @@ Maybe<uint32_t> Adapter::MakeFeatureBits( } Adapter::Adapter(Instance* const aParent, WebGPUChild* const aBridge, const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo) const ffi::WGPUAdapterInformation& aInfo) : ChildOf(aParent), mBridge(aBridge), mId(aInfo->id), mId(aInfo.id), mFeatures(new SupportedFeatures(this)), mLimits(new SupportedLimits(this, MakeUnique<ffi::WGPULimits>(aInfo->limits))), mInfo(aInfo) { mLimits( new SupportedLimits(this, MakeUnique<ffi::WGPULimits>(aInfo.limits))), mIsFallbackAdapter(aInfo.ty == ffi::WGPUDeviceType_Cpu) { ErrorResult result; // TODO: should this come from outside // This list needs to match `AdapterRequestDevice` if (aInfo->features & WGPUFeatures_DEPTH_CLIP_CONTROL) { if (aInfo.features & WGPUFeatures_DEPTH_CLIP_CONTROL) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"depth-clip-control"_ns, result); } if (aInfo->features & WGPUFeatures_TEXTURE_COMPRESSION_BC) { if (aInfo.features & WGPUFeatures_TEXTURE_COMPRESSION_BC) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"texture-compression-bc"_ns, result); } if (aInfo->features & WGPUFeatures_INDIRECT_FIRST_INSTANCE) { if (aInfo.features & WGPUFeatures_INDIRECT_FIRST_INSTANCE) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"indirect-first-instance"_ns, result); } Loading @@ -158,9 +90,6 @@ void Adapter::Cleanup() { const RefPtr<SupportedFeatures>& Adapter::Features() const { return mFeatures; } const RefPtr<SupportedLimits>& Adapter::Limits() const { return mLimits; } bool Adapter::IsFallbackAdapter() const { return mInfo->device_type == ffi::WGPUDeviceType::WGPUDeviceType_Cpu; } already_AddRefed<dom::Promise> Adapter::RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv) { Loading Loading @@ -223,7 +152,9 @@ already_AddRefed<dom::Promise> Adapter::RequestAdapterInfo( RefPtr<dom::Promise> promise = dom::Promise::Create(GetParentObject(), aRv); if (!promise) return nullptr; auto rai = UniquePtr<AdapterInfo>{new AdapterInfo(mInfo)}; auto rai = UniquePtr<AdapterInfo>{new AdapterInfo}; // E.g. rai.mDevice = SanitizeRenderer(deviceName); promise->MaybeResolve(std::move(rai)); return promise.forget(); } Loading dom/webgpu/Adapter.h +12 −26 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ struct GPUDeviceDescriptor; struct GPUExtensions; struct GPUFeatures; enum class GPUFeatureName : uint8_t; enum class WgpuBackend : uint8_t; enum class WgpuDeviceType : uint8_t; template <typename T> class Sequence; } // namespace dom Loading @@ -37,27 +35,16 @@ struct WGPUAdapterInformation; } // namespace ffi class AdapterInfo final : public dom::NonRefcountedDOMObject { private: const std::shared_ptr<ffi::WGPUAdapterInformation> mAboutSupportInfo; public: AdapterInfo( const std::shared_ptr<ffi::WGPUAdapterInformation>& aAboutSupportInfo) : mAboutSupportInfo(aAboutSupportInfo) {} void GetVendor(nsString& s) const { s = nsString(); } void GetArchitecture(nsString& s) const { s = nsString(); } void GetDevice(nsString& s) const { s = nsString(); } void GetDescription(nsString& s) const { s = nsString(); } // Non-standard field getters; see also TODO BUGZILLA LINK void GetWgpuName(nsString&) const; size_t WgpuVendor() const; size_t WgpuDevice() const; void GetWgpuDeviceType(nsString&) const; void GetWgpuDriver(nsString&) const; void GetWgpuDriverInfo(nsString&) const; void GetWgpuBackend(nsString&) const; nsString mVendor; nsString mArchitecture; nsString mDevice; nsString mDescription; void GetVendor(nsString& s) const { s = mVendor; } void GetArchitecture(nsString& s) const { s = mArchitecture; } void GetDevice(nsString& s) const { s = mDevice; } void GetDescription(nsString& s) const { s = mDescription; } bool WrapObject(JSContext*, JS::Handle<JSObject*>, JS::MutableHandle<JSObject*>); Loading @@ -82,15 +69,14 @@ class Adapter final : public ObjectBase, public ChildOf<Instance> { // to unlink them in CC unlink. RefPtr<SupportedFeatures> mFeatures; RefPtr<SupportedLimits> mLimits; const std::shared_ptr<ffi::WGPUAdapterInformation> mInfo; const bool mIsFallbackAdapter = false; public: Adapter(Instance* const aParent, WebGPUChild* const aBridge, const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo); const ffi::WGPUAdapterInformation& aInfo); const RefPtr<SupportedFeatures>& Features() const; const RefPtr<SupportedLimits>& Limits() const; bool IsFallbackAdapter() const; bool IsFallbackAdapter() const { return mIsFallbackAdapter; } already_AddRefed<dom::Promise> RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv); Loading dom/webgpu/Instance.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -92,9 +92,9 @@ already_AddRefed<dom::Promise> Instance::RequestAdapter( bridge->InstanceRequestAdapter(aOptions)->Then( GetCurrentSerialEventTarget(), __func__, [promise, instance, bridge](ipc::ByteBuf aInfoBuf) { auto info = std::make_shared<ffi::WGPUAdapterInformation>(); ffi::wgpu_client_adapter_extract_info(ToFFI(&aInfoBuf), info.get()); MOZ_ASSERT(info->id != 0); ffi::WGPUAdapterInformation info = {}; ffi::wgpu_client_adapter_extract_info(ToFFI(&aInfoBuf), &info); MOZ_ASSERT(info.id != 0); RefPtr<Adapter> adapter = new Adapter(instance, bridge, info); promise->MaybeResolve(adapter); }, Loading dom/webgpu/ipc/WebGPUChild.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -380,7 +380,9 @@ RawId WebGPUChild::DeviceCreateBuffer(RawId aSelfId, RawId WebGPUChild::DeviceCreateTexture(RawId aSelfId, const dom::GPUTextureDescriptor& aDesc) { ffi::WGPUTextureDescriptor desc = {}; // Somehow cbindgen does not successfully rename this into // WGPUTextureDescriptor. See wgpu_bindings/cbindgen.toml. ffi::WGPUTextureDescriptor______nsACString__FfiSlice_TextureFormat desc = {}; webgpu::StringHelper label(aDesc.mLabel); desc.label = label.Get(); Loading dom/webidl/WebGPU.webidl +0 −9 Original line number Diff line number Diff line Loading @@ -89,15 +89,6 @@ interface GPUAdapterInfo { readonly attribute DOMString architecture; readonly attribute DOMString device; readonly attribute DOMString description; // Non-standard; see <https://bugzilla.mozilla.org/show_bug.cgi?id=1831994>. [ChromeOnly] readonly attribute DOMString wgpuName; [ChromeOnly] readonly attribute unsigned long wgpuVendor; [ChromeOnly] readonly attribute unsigned long wgpuDevice; [ChromeOnly] readonly attribute DOMString wgpuDeviceType; [ChromeOnly] readonly attribute DOMString wgpuDriver; [ChromeOnly] readonly attribute DOMString wgpuDriverInfo; [ChromeOnly] readonly attribute DOMString wgpuBackend; }; [Pref="dom.webgpu.enabled", Loading Loading
dom/webgpu/Adapter.cpp +11 −80 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/WebGPUBinding.h" #include "Adapter.h" Loading @@ -23,73 +22,6 @@ bool AdapterInfo::WrapObject(JSContext* const cx, return dom::GPUAdapterInfo_Binding::Wrap(cx, this, givenProto, reflector); } void AdapterInfo::GetWgpuName(nsString& s) const { s = mAboutSupportInfo->name; } size_t AdapterInfo::WgpuVendor() const { return mAboutSupportInfo->vendor; } size_t AdapterInfo::WgpuDevice() const { return mAboutSupportInfo->device; } void AdapterInfo::GetWgpuDeviceType(nsString& s) const { switch (mAboutSupportInfo->device_type) { case ffi::WGPUDeviceType_Cpu: s.AssignLiteral("Cpu"); return; case ffi::WGPUDeviceType_DiscreteGpu: s.AssignLiteral("DiscreteGpu"); return; case ffi::WGPUDeviceType_IntegratedGpu: s.AssignLiteral("IntegratedGpu"); return; case ffi::WGPUDeviceType_VirtualGpu: s.AssignLiteral("VirtualGpu"); return; case ffi::WGPUDeviceType_Other: s.AssignLiteral("Other"); return; case ffi::WGPUDeviceType_Sentinel: break; } MOZ_CRASH("Bad `ffi::WGPUDeviceType`"); } void AdapterInfo::GetWgpuDriver(nsString& s) const { s = mAboutSupportInfo->driver; } void AdapterInfo::GetWgpuDriverInfo(nsString& s) const { s = mAboutSupportInfo->driver_info; } void AdapterInfo::GetWgpuBackend(nsString& s) const { switch (mAboutSupportInfo->backend) { case ffi::WGPUBackend_Empty: s.AssignLiteral("Empty"); return; case ffi::WGPUBackend_Vulkan: s.AssignLiteral("Vulkan"); return; case ffi::WGPUBackend_Metal: s.AssignLiteral("Metal"); return; case ffi::WGPUBackend_Dx12: s.AssignLiteral("Dx12"); return; case ffi::WGPUBackend_Dx11: s.AssignLiteral("Dx11"); return; case ffi::WGPUBackend_Gl: s.AssignLiteral("Gl"); return; case ffi::WGPUBackend_BrowserWebGpu: // This should never happen, because // we _are_ the browser. case ffi::WGPUBackend_Sentinel: break; } MOZ_CRASH("Bad `ffi::WGPUBackend`"); } // - GPU_IMPL_CYCLE_COLLECTION(Adapter, mParent, mBridge, mFeatures, mLimits) Loading Loading @@ -119,25 +51,25 @@ Maybe<uint32_t> Adapter::MakeFeatureBits( } Adapter::Adapter(Instance* const aParent, WebGPUChild* const aBridge, const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo) const ffi::WGPUAdapterInformation& aInfo) : ChildOf(aParent), mBridge(aBridge), mId(aInfo->id), mId(aInfo.id), mFeatures(new SupportedFeatures(this)), mLimits(new SupportedLimits(this, MakeUnique<ffi::WGPULimits>(aInfo->limits))), mInfo(aInfo) { mLimits( new SupportedLimits(this, MakeUnique<ffi::WGPULimits>(aInfo.limits))), mIsFallbackAdapter(aInfo.ty == ffi::WGPUDeviceType_Cpu) { ErrorResult result; // TODO: should this come from outside // This list needs to match `AdapterRequestDevice` if (aInfo->features & WGPUFeatures_DEPTH_CLIP_CONTROL) { if (aInfo.features & WGPUFeatures_DEPTH_CLIP_CONTROL) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"depth-clip-control"_ns, result); } if (aInfo->features & WGPUFeatures_TEXTURE_COMPRESSION_BC) { if (aInfo.features & WGPUFeatures_TEXTURE_COMPRESSION_BC) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"texture-compression-bc"_ns, result); } if (aInfo->features & WGPUFeatures_INDIRECT_FIRST_INSTANCE) { if (aInfo.features & WGPUFeatures_INDIRECT_FIRST_INSTANCE) { dom::GPUSupportedFeatures_Binding::SetlikeHelpers::Add( mFeatures, u"indirect-first-instance"_ns, result); } Loading @@ -158,9 +90,6 @@ void Adapter::Cleanup() { const RefPtr<SupportedFeatures>& Adapter::Features() const { return mFeatures; } const RefPtr<SupportedLimits>& Adapter::Limits() const { return mLimits; } bool Adapter::IsFallbackAdapter() const { return mInfo->device_type == ffi::WGPUDeviceType::WGPUDeviceType_Cpu; } already_AddRefed<dom::Promise> Adapter::RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv) { Loading Loading @@ -223,7 +152,9 @@ already_AddRefed<dom::Promise> Adapter::RequestAdapterInfo( RefPtr<dom::Promise> promise = dom::Promise::Create(GetParentObject(), aRv); if (!promise) return nullptr; auto rai = UniquePtr<AdapterInfo>{new AdapterInfo(mInfo)}; auto rai = UniquePtr<AdapterInfo>{new AdapterInfo}; // E.g. rai.mDevice = SanitizeRenderer(deviceName); promise->MaybeResolve(std::move(rai)); return promise.forget(); } Loading
dom/webgpu/Adapter.h +12 −26 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ struct GPUDeviceDescriptor; struct GPUExtensions; struct GPUFeatures; enum class GPUFeatureName : uint8_t; enum class WgpuBackend : uint8_t; enum class WgpuDeviceType : uint8_t; template <typename T> class Sequence; } // namespace dom Loading @@ -37,27 +35,16 @@ struct WGPUAdapterInformation; } // namespace ffi class AdapterInfo final : public dom::NonRefcountedDOMObject { private: const std::shared_ptr<ffi::WGPUAdapterInformation> mAboutSupportInfo; public: AdapterInfo( const std::shared_ptr<ffi::WGPUAdapterInformation>& aAboutSupportInfo) : mAboutSupportInfo(aAboutSupportInfo) {} void GetVendor(nsString& s) const { s = nsString(); } void GetArchitecture(nsString& s) const { s = nsString(); } void GetDevice(nsString& s) const { s = nsString(); } void GetDescription(nsString& s) const { s = nsString(); } // Non-standard field getters; see also TODO BUGZILLA LINK void GetWgpuName(nsString&) const; size_t WgpuVendor() const; size_t WgpuDevice() const; void GetWgpuDeviceType(nsString&) const; void GetWgpuDriver(nsString&) const; void GetWgpuDriverInfo(nsString&) const; void GetWgpuBackend(nsString&) const; nsString mVendor; nsString mArchitecture; nsString mDevice; nsString mDescription; void GetVendor(nsString& s) const { s = mVendor; } void GetArchitecture(nsString& s) const { s = mArchitecture; } void GetDevice(nsString& s) const { s = mDevice; } void GetDescription(nsString& s) const { s = mDescription; } bool WrapObject(JSContext*, JS::Handle<JSObject*>, JS::MutableHandle<JSObject*>); Loading @@ -82,15 +69,14 @@ class Adapter final : public ObjectBase, public ChildOf<Instance> { // to unlink them in CC unlink. RefPtr<SupportedFeatures> mFeatures; RefPtr<SupportedLimits> mLimits; const std::shared_ptr<ffi::WGPUAdapterInformation> mInfo; const bool mIsFallbackAdapter = false; public: Adapter(Instance* const aParent, WebGPUChild* const aBridge, const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo); const ffi::WGPUAdapterInformation& aInfo); const RefPtr<SupportedFeatures>& Features() const; const RefPtr<SupportedLimits>& Limits() const; bool IsFallbackAdapter() const; bool IsFallbackAdapter() const { return mIsFallbackAdapter; } already_AddRefed<dom::Promise> RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv); Loading
dom/webgpu/Instance.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -92,9 +92,9 @@ already_AddRefed<dom::Promise> Instance::RequestAdapter( bridge->InstanceRequestAdapter(aOptions)->Then( GetCurrentSerialEventTarget(), __func__, [promise, instance, bridge](ipc::ByteBuf aInfoBuf) { auto info = std::make_shared<ffi::WGPUAdapterInformation>(); ffi::wgpu_client_adapter_extract_info(ToFFI(&aInfoBuf), info.get()); MOZ_ASSERT(info->id != 0); ffi::WGPUAdapterInformation info = {}; ffi::wgpu_client_adapter_extract_info(ToFFI(&aInfoBuf), &info); MOZ_ASSERT(info.id != 0); RefPtr<Adapter> adapter = new Adapter(instance, bridge, info); promise->MaybeResolve(adapter); }, Loading
dom/webgpu/ipc/WebGPUChild.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -380,7 +380,9 @@ RawId WebGPUChild::DeviceCreateBuffer(RawId aSelfId, RawId WebGPUChild::DeviceCreateTexture(RawId aSelfId, const dom::GPUTextureDescriptor& aDesc) { ffi::WGPUTextureDescriptor desc = {}; // Somehow cbindgen does not successfully rename this into // WGPUTextureDescriptor. See wgpu_bindings/cbindgen.toml. ffi::WGPUTextureDescriptor______nsACString__FfiSlice_TextureFormat desc = {}; webgpu::StringHelper label(aDesc.mLabel); desc.label = label.Get(); Loading
dom/webidl/WebGPU.webidl +0 −9 Original line number Diff line number Diff line Loading @@ -89,15 +89,6 @@ interface GPUAdapterInfo { readonly attribute DOMString architecture; readonly attribute DOMString device; readonly attribute DOMString description; // Non-standard; see <https://bugzilla.mozilla.org/show_bug.cgi?id=1831994>. [ChromeOnly] readonly attribute DOMString wgpuName; [ChromeOnly] readonly attribute unsigned long wgpuVendor; [ChromeOnly] readonly attribute unsigned long wgpuDevice; [ChromeOnly] readonly attribute DOMString wgpuDeviceType; [ChromeOnly] readonly attribute DOMString wgpuDriver; [ChromeOnly] readonly attribute DOMString wgpuDriverInfo; [ChromeOnly] readonly attribute DOMString wgpuBackend; }; [Pref="dom.webgpu.enabled", Loading