mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
This change vendors `wgpu` library in-tree and hooks up the initialization bits. It implements adapter and device initialization and adds a simple test. Complementary ecosystem tracker - https://github.com/gfx-rs/wgpu/issues/374 Current status: - [x] General - [x] figure out the IPC story - [ ] move wgpu crates into a dedicated folder (postponed as https://bugzilla.mozilla.org/show_bug.cgi?id=1594182) - [x] neko rebasing disaster - [x] Linux - [x] avoid depending on spirv_cross - [x] macOS - [x] due to cross-compiling shaders - [x] need the dependency update - [x] stop using gcc - [x] unexpected SSL header collision - https://phabricator.services.mozilla.com/D51148 - [x] undefined Metal symbols - [x] missing webrtc headers for IPDL magic - https://phabricator.services.mozilla.com/D51558 - [x] spirv-cross linking failure in ASAN - https://phabricator.services.mozilla.com/D52688 - [x] Windows - [x] due to "ipc-channel" not supporting Windows yet - [x] due to some exceptional stuff - [x] undefined symbol: `D3D12CreateDevice` - [x] d3d12.dll is not found, dxgi1_4 doesn't present - [x] d3d11.dll and dxgi.dll need to be explicitly loaded on win32 mingw - [x] libbacktrace fails to link on win32 mingw - [x] cc mislinking C++ standard library - [x] Android - [x] spirv-cross fails to build due to exceptions Update-1: We decided to go with IPDL mechanism instead of Rust based ipc-channel (or any alternatives), which unblocks Windows build. Update-2: It appears that WebGPUThreading isn't needed any more as the child thread (and its event loop) is now managed by IPDL infrastructure. This PR removes it 🎉 . Update-3: InstanceProvider is also removed. Update-4: All set, the try is green, waiting for dependent changes to go in. Differential Revision: https://phabricator.services.mozilla.com/D49458
79 lines
2.4 KiB
C++
79 lines
2.4 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 "Instance.h"
|
|
|
|
#include "Adapter.h"
|
|
#include "gfxConfig.h"
|
|
#include "nsIGlobalObject.h"
|
|
#include "ipc/WebGPUChild.h"
|
|
#include "ipc/WebGPUTypes.h"
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
|
|
|
namespace mozilla {
|
|
namespace webgpu {
|
|
|
|
GPU_IMPL_CYCLE_COLLECTION(Instance, mBridge, mOwner)
|
|
|
|
/*static*/
|
|
already_AddRefed<Instance> Instance::Create(nsIGlobalObject* aOwner) {
|
|
if (!gfx::gfxConfig::IsEnabled(gfx::Feature::WEBGPU)) {
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<WebGPUChild> bridge =
|
|
layers::CompositorBridgeChild::Get()->GetWebGPUChild();
|
|
if (NS_WARN_IF(!bridge)) {
|
|
MOZ_CRASH("Failed to create an IPDL bridge for WebGPU!");
|
|
}
|
|
|
|
RefPtr<Instance> result = new Instance(aOwner, bridge);
|
|
return result.forget();
|
|
}
|
|
|
|
Instance::Instance(nsIGlobalObject* aOwner, WebGPUChild* aBridge)
|
|
: mOwner(aOwner), mBridge(aBridge) {}
|
|
|
|
Instance::~Instance() = default;
|
|
|
|
JSObject* Instance::WrapObject(JSContext* cx,
|
|
JS::Handle<JSObject*> givenProto) {
|
|
return dom::GPU_Binding::Wrap(cx, this, givenProto);
|
|
}
|
|
|
|
WebGPUChild* Instance::GetBridge() const { return mBridge; }
|
|
|
|
already_AddRefed<dom::Promise> Instance::RequestAdapter(
|
|
const dom::GPURequestAdapterOptions& aOptions, ErrorResult& aRv) {
|
|
RefPtr<dom::Promise> promise = dom::Promise::Create(mOwner, aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<Instance> instance = this;
|
|
|
|
mBridge->InstanceRequestAdapter(aOptions)->Then(
|
|
GetMainThreadSerialEventTarget(), __func__,
|
|
[promise, instance](RawId id) {
|
|
MOZ_ASSERT(id != 0);
|
|
RefPtr<Adapter> adapter = new Adapter(instance, id);
|
|
promise->MaybeResolve(adapter);
|
|
},
|
|
[promise](const Maybe<ipc::ResponseRejectReason>& aRv) {
|
|
if (aRv.isSome()) {
|
|
promise->MaybeRejectWithDOMException(NS_ERROR_DOM_ABORT_ERR,
|
|
"Internal communication error!");
|
|
} else {
|
|
promise->MaybeRejectWithDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
|
|
"No matching adapter found!");
|
|
}
|
|
});
|
|
|
|
return promise.forget();
|
|
}
|
|
|
|
} // namespace webgpu
|
|
} // namespace mozilla
|