2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2016-07-26 22:50:30 +03:00
|
|
|
* 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/. */
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
#include "DeviceManagerDx.h"
|
2016-07-26 23:22:13 +03:00
|
|
|
#include "D3D11Checks.h"
|
|
|
|
#include "gfxConfig.h"
|
|
|
|
#include "GfxDriverInfo.h"
|
2019-05-25 09:07:49 +03:00
|
|
|
#include "gfxPrefs.h"
|
2016-07-26 22:50:30 +03:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2016-07-26 23:22:13 +03:00
|
|
|
#include "mozilla/D3DMessageUtils.h"
|
2019-05-26 17:29:42 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2016-07-26 23:22:13 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/WindowsVersion.h"
|
2017-06-24 00:23:12 +03:00
|
|
|
#include "mozilla/gfx/GPUParent.h"
|
2016-07-26 23:22:13 +03:00
|
|
|
#include "mozilla/gfx/GraphicsMessages.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
2017-07-25 21:02:36 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2017-07-18 22:16:13 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
2016-08-24 01:18:55 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2017-04-30 21:38:59 +03:00
|
|
|
#include "mozilla/layers/DeviceAttachmentsD3D11.h"
|
2017-06-24 00:23:12 +03:00
|
|
|
#include "mozilla/layers/MLGDeviceD3D11.h"
|
2017-07-18 22:16:13 +03:00
|
|
|
#include "mozilla/layers/PaintThread.h"
|
2017-10-10 16:11:07 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2016-07-26 23:22:13 +03:00
|
|
|
#include "nsIGfxInfo.h"
|
2017-10-10 16:11:07 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2017-06-24 00:23:13 +03:00
|
|
|
#include "nsString.h"
|
2018-03-29 05:23:31 +03:00
|
|
|
|
|
|
|
#undef NTDDI_VERSION
|
|
|
|
#define NTDDI_VERSION NTDDI_WIN8
|
|
|
|
|
2016-07-26 22:50:30 +03:00
|
|
|
#include <d3d11.h>
|
2018-03-29 05:23:31 +03:00
|
|
|
#include <dcomp.h>
|
2016-08-24 01:18:55 +03:00
|
|
|
#include <ddraw.h>
|
2016-07-26 22:50:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
using namespace mozilla::widget;
|
2017-06-24 00:23:12 +03:00
|
|
|
using namespace mozilla::layers;
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
StaticAutoPtr<DeviceManagerDx> DeviceManagerDx::sInstance;
|
2016-07-26 22:50:30 +03:00
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
// We don't have access to the D3D11CreateDevice type in gfxWindowsPlatform.h,
|
|
|
|
// since it doesn't include d3d11.h, so we use a static here. It should only
|
|
|
|
// be used within InitializeD3D11.
|
|
|
|
decltype(D3D11CreateDevice)* sD3D11CreateDeviceFn = nullptr;
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
typedef HRESULT(WINAPI* PFN_DCOMPOSITION_CREATE_DEVICE)(
|
|
|
|
IDXGIDevice* dxgiDevice, REFIID iid, void** dcompositionDevice);
|
|
|
|
PFN_DCOMPOSITION_CREATE_DEVICE sDcompCreateDeviceFn = nullptr;
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
// We don't have access to the DirectDrawCreateEx type in gfxWindowsPlatform.h,
|
|
|
|
// since it doesn't include ddraw.h, so we use a static here. It should only
|
|
|
|
// be used within InitializeDirectDrawConfig.
|
|
|
|
decltype(DirectDrawCreateEx)* sDirectDrawCreateExFn = nullptr;
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void DeviceManagerDx::Init() { sInstance = new DeviceManagerDx(); }
|
2016-07-26 22:50:30 +03:00
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void DeviceManagerDx::Shutdown() { sInstance = nullptr; }
|
2016-07-26 22:50:30 +03:00
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
DeviceManagerDx::DeviceManagerDx()
|
2016-07-26 23:22:13 +03:00
|
|
|
: mDeviceLock("gfxWindowsPlatform.mDeviceLock"),
|
2016-08-02 09:46:27 +03:00
|
|
|
mCompositorDeviceSupportsVideo(false) {
|
2016-07-26 23:22:13 +03:00
|
|
|
// Set up the D3D11 feature levels we can ask for.
|
|
|
|
if (IsWin8OrLater()) {
|
|
|
|
mFeatureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1);
|
|
|
|
}
|
|
|
|
mFeatureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0);
|
|
|
|
mFeatureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1);
|
|
|
|
mFeatureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0);
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::LoadD3D11() {
|
2016-07-26 23:22:13 +03:00
|
|
|
FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);
|
|
|
|
MOZ_ASSERT(d3d11.IsEnabled());
|
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
if (sD3D11CreateDeviceFn) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsModuleHandle module(LoadLibrarySystem32(L"d3d11.dll"));
|
|
|
|
if (!module) {
|
|
|
|
d3d11.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"Direct3D11 not available on this computer",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_LIB"));
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
sD3D11CreateDeviceFn =
|
|
|
|
(decltype(D3D11CreateDevice)*)GetProcAddress(module, "D3D11CreateDevice");
|
2016-07-26 23:22:13 +03:00
|
|
|
if (!sD3D11CreateDeviceFn) {
|
|
|
|
// We should just be on Windows Vista or XP in this case.
|
|
|
|
d3d11.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"Direct3D11 not available on this computer",
|
2016-08-21 06:59:10 +03:00
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_FUNCPTR"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mD3D11Module.steal(module);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
bool DeviceManagerDx::LoadDcomp() {
|
2019-02-19 14:42:11 +03:00
|
|
|
MOZ_ASSERT(gfxConfig::GetFeature(Feature::D3D11_COMPOSITING).IsEnabled());
|
2018-03-29 05:23:31 +03:00
|
|
|
MOZ_ASSERT(gfxVars::UseWebRender());
|
|
|
|
MOZ_ASSERT(gfxVars::UseWebRenderANGLE());
|
|
|
|
MOZ_ASSERT(gfxVars::UseWebRenderDCompWin());
|
|
|
|
|
|
|
|
if (sDcompCreateDeviceFn) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsModuleHandle module(LoadLibrarySystem32(L"dcomp.dll"));
|
|
|
|
if (!module) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sDcompCreateDeviceFn = reinterpret_cast<PFN_DCOMPOSITION_CREATE_DEVICE>(
|
|
|
|
::GetProcAddress(module, "DCompositionCreateDevice"));
|
|
|
|
if (!sDcompCreateDeviceFn) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDcompModule.steal(module);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::ReleaseD3D11() {
|
2016-08-21 06:59:10 +03:00
|
|
|
MOZ_ASSERT(!mCompositorDevice);
|
|
|
|
MOZ_ASSERT(!mContentDevice);
|
2017-08-29 01:56:43 +03:00
|
|
|
MOZ_ASSERT(!mVRDevice);
|
2016-08-21 06:59:10 +03:00
|
|
|
MOZ_ASSERT(!mDecoderDevice);
|
|
|
|
|
|
|
|
mD3D11Module.reset();
|
|
|
|
sD3D11CreateDeviceFn = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-28 19:56:03 +03:00
|
|
|
nsTArray<DXGI_OUTPUT_DESC1> DeviceManagerDx::EnumerateOutputs() {
|
|
|
|
RefPtr<IDXGIAdapter> adapter = GetDXGIAdapter();
|
|
|
|
|
|
|
|
if (!adapter) {
|
|
|
|
NS_WARNING("Failed to acquire a DXGI adapter for enumerating outputs.");
|
|
|
|
return nsTArray<DXGI_OUTPUT_DESC1>();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<DXGI_OUTPUT_DESC1> outputs;
|
|
|
|
for (UINT i = 0;; ++i) {
|
|
|
|
RefPtr<IDXGIOutput> output = nullptr;
|
|
|
|
if (FAILED(adapter->EnumOutputs(i, getter_AddRefs(output)))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIOutput6> output6 = nullptr;
|
|
|
|
if (FAILED(output->QueryInterface(__uuidof(IDXGIOutput6),
|
|
|
|
getter_AddRefs(output6)))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DXGI_OUTPUT_DESC1 desc;
|
|
|
|
if (FAILED(output6->GetDesc1(&desc))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputs.AppendElement(desc);
|
|
|
|
}
|
|
|
|
return outputs;
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:42:11 +03:00
|
|
|
#ifdef DEBUG
|
2016-08-21 06:59:11 +03:00
|
|
|
static inline bool ProcessOwnsCompositor() {
|
|
|
|
return XRE_GetProcessType() == GeckoProcessType_GPU ||
|
2018-08-07 08:47:18 +03:00
|
|
|
XRE_GetProcessType() == GeckoProcessType_VR ||
|
2016-08-21 06:59:11 +03:00
|
|
|
(XRE_IsParentProcess() && !gfxConfig::IsEnabled(Feature::GPU_PROCESS));
|
|
|
|
}
|
2019-02-19 14:42:11 +03:00
|
|
|
#endif
|
2016-08-21 06:59:11 +03:00
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::CreateCompositorDevices() {
|
2016-08-21 06:59:11 +03:00
|
|
|
MOZ_ASSERT(ProcessOwnsCompositor());
|
2016-08-21 06:59:10 +03:00
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);
|
|
|
|
MOZ_ASSERT(d3d11.IsEnabled());
|
|
|
|
|
2019-05-25 09:07:49 +03:00
|
|
|
if (int32_t sleepSec = gfxPrefs::Direct3D11SleepOnCreateDevice()) {
|
2017-07-31 22:28:26 +03:00
|
|
|
printf_stderr("Attach to PID: %d\n", GetCurrentProcessId());
|
|
|
|
Sleep(sleepSec * 1000);
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
if (!LoadD3D11()) {
|
2016-08-21 06:59:10 +03:00
|
|
|
return false;
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
CreateCompositorDevice(d3d11);
|
2016-08-21 06:59:10 +03:00
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
if (!d3d11.IsEnabled()) {
|
|
|
|
MOZ_ASSERT(!mCompositorDevice);
|
|
|
|
ReleaseD3D11();
|
2017-06-24 00:23:12 +03:00
|
|
|
|
|
|
|
// Sync Advanced-Layers with D3D11.
|
|
|
|
if (gfxConfig::IsEnabled(Feature::ADVANCED_LAYERS)) {
|
|
|
|
gfxConfig::SetFailed(Feature::ADVANCED_LAYERS, FeatureStatus::Unavailable,
|
|
|
|
"Requires D3D11",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_D3D11"));
|
|
|
|
}
|
2016-08-21 06:59:10 +03:00
|
|
|
return false;
|
2016-08-21 06:59:10 +03:00
|
|
|
}
|
2016-08-21 06:59:10 +03:00
|
|
|
|
|
|
|
// We leak these everywhere and we need them our entire runtime anyway, let's
|
|
|
|
// leak it here as well. We keep the pointer to sD3D11CreateDeviceFn around
|
|
|
|
// as well for D2D1 and device resets.
|
|
|
|
mD3D11Module.disown();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCompositorDevice);
|
2017-05-05 11:04:19 +03:00
|
|
|
if (!d3d11.IsEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-13 07:23:38 +03:00
|
|
|
// When WR is used, do not preload attachments for D3D11 Non-WR compositor.
|
|
|
|
//
|
|
|
|
// Fallback from WR to D3D11 Non-WR compositor without re-creating gpu process
|
|
|
|
// could happen when WR causes error. In this case, the attachments are loaded
|
|
|
|
// synchronously.
|
|
|
|
if (!gfx::gfxVars::UseWebRender()) {
|
|
|
|
PreloadAttachmentsOnCompositorThread();
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:04:19 +03:00
|
|
|
return true;
|
2016-08-21 06:59:10 +03:00
|
|
|
}
|
|
|
|
|
2017-08-29 01:56:43 +03:00
|
|
|
bool DeviceManagerDx::CreateVRDevice() {
|
|
|
|
MOZ_ASSERT(ProcessOwnsCompositor());
|
|
|
|
|
|
|
|
if (mVRDevice) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING)) {
|
|
|
|
NS_WARNING("Direct3D11 Compositing required for VR");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LoadD3D11()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
|
|
|
|
if (!adapter) {
|
|
|
|
NS_WARNING("Failed to acquire a DXGI adapter for VR");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
if (!CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, flags, hr, mVRDevice)) {
|
|
|
|
gfxCriticalError() << "Crash during D3D11 device creation for VR";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr) || !mVRDevice) {
|
|
|
|
NS_WARNING("Failed to acquire a D3D11 device for VR");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
void DeviceManagerDx::CreateDirectCompositionDevice() {
|
|
|
|
if (!gfxVars::UseWebRenderDCompWin()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCompositorDevice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LoadDcomp()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIDevice> dxgiDevice;
|
|
|
|
if (mCompositorDevice->QueryInterface(
|
|
|
|
IID_PPV_ARGS((IDXGIDevice**)getter_AddRefs(dxgiDevice))) != S_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
RefPtr<IDCompositionDevice> compositionDevice;
|
|
|
|
MOZ_SEH_TRY {
|
|
|
|
hr = sDcompCreateDeviceFn(
|
|
|
|
dxgiDevice,
|
|
|
|
IID_PPV_ARGS((IDCompositionDevice**)getter_AddRefs(compositionDevice)));
|
|
|
|
}
|
2016-08-24 01:18:55 +03:00
|
|
|
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { return; }
|
2018-03-29 05:23:31 +03:00
|
|
|
|
|
|
|
if (!SUCCEEDED(hr)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDirectCompositionDevice = compositionDevice;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::ImportDeviceInfo(const D3D11DeviceStatus& aDeviceStatus) {
|
2016-08-21 06:59:11 +03:00
|
|
|
MOZ_ASSERT(!ProcessOwnsCompositor());
|
2016-08-21 06:59:10 +03:00
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
mDeviceStatus = Some(aDeviceStatus);
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::ExportDeviceInfo(D3D11DeviceStatus* aOut) {
|
2016-08-21 06:59:11 +03:00
|
|
|
if (mDeviceStatus) {
|
|
|
|
*aOut = mDeviceStatus.value();
|
|
|
|
}
|
2016-08-21 06:59:10 +03:00
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::CreateContentDevices() {
|
2016-08-21 06:59:10 +03:00
|
|
|
MOZ_ASSERT(gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING));
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-21 06:59:10 +03:00
|
|
|
if (!LoadD3D11()) {
|
|
|
|
return;
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
// We should have been assigned a DeviceStatus from the parent process,
|
|
|
|
// GPU process, or the same process if using in-process compositing.
|
|
|
|
MOZ_ASSERT(mDeviceStatus);
|
|
|
|
|
2016-08-21 06:59:09 +03:00
|
|
|
if (CreateContentDevice() == FeatureStatus::CrashedInHandler) {
|
2016-07-26 23:22:13 +03:00
|
|
|
DisableD3D11AfterCrash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
IDXGIAdapter1* DeviceManagerDx::GetDXGIAdapter() {
|
2016-07-26 23:22:13 +03:00
|
|
|
if (mAdapter) {
|
|
|
|
return mAdapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsModuleHandle dxgiModule(LoadLibrarySystem32(L"dxgi.dll"));
|
|
|
|
decltype(CreateDXGIFactory1)* createDXGIFactory1 =
|
|
|
|
(decltype(CreateDXGIFactory1)*)GetProcAddress(dxgiModule,
|
|
|
|
"CreateDXGIFactory1");
|
|
|
|
|
|
|
|
if (!createDXGIFactory1) {
|
2016-07-26 22:50:30 +03:00
|
|
|
return nullptr;
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to use a DXGI 1.1 adapter in order to share resources
|
|
|
|
// across processes.
|
|
|
|
RefPtr<IDXGIFactory1> factory1;
|
|
|
|
HRESULT hr =
|
|
|
|
createDXGIFactory1(__uuidof(IDXGIFactory1), getter_AddRefs(factory1));
|
|
|
|
if (FAILED(hr) || !factory1) {
|
|
|
|
// This seems to happen with some people running the iZ3D driver.
|
|
|
|
// They won't get acceleration.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
if (!mDeviceStatus) {
|
|
|
|
// If we haven't created a device yet, and have no existing device status,
|
|
|
|
// then this must be the compositor device. Pick the first adapter we can.
|
2016-07-26 23:22:13 +03:00
|
|
|
if (FAILED(factory1->EnumAdapters1(0, getter_AddRefs(mAdapter)))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
2016-08-21 06:59:11 +03:00
|
|
|
// In the UI and GPU process, we clear mDeviceStatus on device reset, so we
|
|
|
|
// should never reach here. Furthermore, the UI process does not create
|
|
|
|
// devices when using a GPU process.
|
|
|
|
//
|
|
|
|
// So, this should only ever get called on the content process.
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
2016-07-26 23:22:13 +03:00
|
|
|
|
|
|
|
// In the child process, we search for the adapter that matches the parent
|
|
|
|
// process. The first adapter can be mismatched on dual-GPU systems.
|
|
|
|
for (UINT index = 0;; index++) {
|
|
|
|
RefPtr<IDXGIAdapter1> adapter;
|
|
|
|
if (FAILED(factory1->EnumAdapters1(index, getter_AddRefs(adapter)))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
const DxgiAdapterDesc& preferred = mDeviceStatus->adapter();
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
if (SUCCEEDED(adapter->GetDesc(&desc)) &&
|
2016-08-21 06:59:11 +03:00
|
|
|
desc.AdapterLuid.HighPart == preferred.AdapterLuid.HighPart &&
|
|
|
|
desc.AdapterLuid.LowPart == preferred.AdapterLuid.LowPart &&
|
|
|
|
desc.VendorId == preferred.VendorId &&
|
|
|
|
desc.DeviceId == preferred.DeviceId) {
|
2016-07-26 23:22:13 +03:00
|
|
|
mAdapter = adapter.forget();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAdapter) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We leak this module everywhere, we might as well do so here as well.
|
|
|
|
dxgiModule.disown();
|
|
|
|
return mAdapter;
|
2016-07-26 22:50:30 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::CreateCompositorDeviceHelper(
|
2016-08-13 22:04:03 +03:00
|
|
|
FeatureState& aD3d11, IDXGIAdapter1* aAdapter, bool aAttemptVideoSupport,
|
|
|
|
RefPtr<ID3D11Device>& aOutDevice) {
|
2016-08-21 06:59:10 +03:00
|
|
|
// Check if a failure was injected for testing.
|
2019-05-26 17:29:42 +03:00
|
|
|
if (StaticPrefs::DeviceFailForTesting()) {
|
2016-08-21 06:59:10 +03:00
|
|
|
aD3d11.SetFailed(FeatureStatus::Failed,
|
|
|
|
"Direct3D11 device failure simulated by preference",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_SIM"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-02 09:46:27 +03:00
|
|
|
// Use D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
|
|
|
|
// to prevent bug 1092260. IE 11 also uses this flag.
|
|
|
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT |
|
|
|
|
D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS;
|
|
|
|
if (aAttemptVideoSupport) {
|
|
|
|
flags |= D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
RefPtr<ID3D11Device> device;
|
2016-08-13 22:04:03 +03:00
|
|
|
if (!CreateDevice(aAdapter, D3D_DRIVER_TYPE_UNKNOWN, flags, hr, device)) {
|
2016-08-02 09:46:27 +03:00
|
|
|
if (!aAttemptVideoSupport) {
|
|
|
|
gfxCriticalError() << "Crash during D3D11 device creation";
|
|
|
|
aD3d11.SetFailed(FeatureStatus::CrashedInHandler,
|
|
|
|
"Crashed trying to acquire a D3D11 device",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_DEVICE1"));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr) || !device) {
|
|
|
|
if (!aAttemptVideoSupport) {
|
|
|
|
aD3d11.SetFailed(FeatureStatus::Failed,
|
|
|
|
"Failed to acquire a D3D11 device",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_DEVICE2"));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!D3D11Checks::DoesDeviceWork()) {
|
|
|
|
if (!aAttemptVideoSupport) {
|
|
|
|
aD3d11.SetFailed(FeatureStatus::Broken,
|
|
|
|
"Direct3D11 device was determined to be broken",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_BROKEN"));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOutDevice = device;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-19 06:09:00 +03:00
|
|
|
// Note that it's enough for us to just use a counter for a unique ID,
|
|
|
|
// even though the counter isn't synchronized between processes. If we
|
|
|
|
// start in the GPU process and wind up in the parent process, the
|
|
|
|
// whole graphics stack is blown away anyway. But just in case, we
|
|
|
|
// make gpu process IDs negative and parent process IDs positive.
|
|
|
|
static inline int32_t GetNextDeviceCounter() {
|
|
|
|
static int32_t sDeviceCounter = 0;
|
|
|
|
return XRE_IsGPUProcess() ? --sDeviceCounter : ++sDeviceCounter;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::CreateCompositorDevice(FeatureState& d3d11) {
|
2019-05-25 09:07:49 +03:00
|
|
|
if (gfxPrefs::LayersD3D11ForceWARP()) {
|
2016-08-21 06:59:09 +03:00
|
|
|
CreateWARPCompositorDevice();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
|
|
|
|
if (!adapter) {
|
|
|
|
d3d11.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"Failed to acquire a DXGI adapter",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_DXGI"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-26 04:42:20 +03:00
|
|
|
if (XRE_IsGPUProcess() && !D3D11Checks::DoesRemotePresentWork(adapter)) {
|
|
|
|
d3d11.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"DXGI does not support out-of-process presentation",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_REMOTE_PRESENT"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:50:30 +03:00
|
|
|
RefPtr<ID3D11Device> device;
|
2016-08-21 06:59:09 +03:00
|
|
|
if (!CreateCompositorDeviceHelper(d3d11, adapter, true, device)) {
|
2016-08-02 09:46:27 +03:00
|
|
|
// Try again without video support and record that it failed.
|
|
|
|
mCompositorDeviceSupportsVideo = false;
|
2016-08-21 06:59:09 +03:00
|
|
|
if (!CreateCompositorDeviceHelper(d3d11, adapter, false, device)) {
|
2016-08-02 09:46:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCompositorDeviceSupportsVideo = true;
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only test this when not using WARP since it can fail and cause
|
|
|
|
// GetDeviceRemovedReason to return weird values.
|
2016-08-21 06:59:11 +03:00
|
|
|
bool textureSharingWorks = D3D11Checks::DoesTextureSharingWork(device);
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
PodZero(&desc);
|
|
|
|
adapter->GetDesc(&desc);
|
|
|
|
|
|
|
|
if (!textureSharingWorks) {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxConfig::SetFailed(Feature::D3D11_HW_ANGLE, FeatureStatus::Broken,
|
|
|
|
"Texture sharing doesn't work");
|
|
|
|
}
|
2016-08-21 06:59:11 +03:00
|
|
|
if (D3D11Checks::DoesRenderTargetViewNeedRecreating(device)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxConfig::SetFailed(Feature::D3D11_HW_ANGLE, FeatureStatus::Broken,
|
|
|
|
"RenderTargetViews need recreating");
|
|
|
|
}
|
2016-08-21 06:59:10 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// It seems like this may only happen when we're using the NVIDIA gpu
|
2016-08-21 06:59:11 +03:00
|
|
|
D3D11Checks::WarnOnAdapterMismatch(device);
|
2016-08-21 06:59:10 +03:00
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2017-07-19 06:09:00 +03:00
|
|
|
uint32_t featureLevel = device->GetFeatureLevel();
|
2018-10-11 01:14:51 +03:00
|
|
|
auto formatOptions = D3D11Checks::FormatOptions(device);
|
2016-08-21 06:59:11 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
mCompositorDevice = device;
|
2017-07-19 06:09:00 +03:00
|
|
|
|
|
|
|
int32_t sequenceNumber = GetNextDeviceCounter();
|
2018-10-11 01:14:51 +03:00
|
|
|
mDeviceStatus = Some(D3D11DeviceStatus(
|
|
|
|
false, textureSharingWorks, featureLevel, DxgiAdapterDesc::From(desc),
|
|
|
|
sequenceNumber, formatOptions));
|
2016-08-21 06:59:11 +03:00
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
mCompositorDevice->SetExceptionMode(0);
|
2016-07-26 22:50:30 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::CreateDevice(IDXGIAdapter* aAdapter,
|
2016-08-13 22:04:03 +03:00
|
|
|
D3D_DRIVER_TYPE aDriverType, UINT aFlags,
|
|
|
|
HRESULT& aResOut,
|
|
|
|
RefPtr<ID3D11Device>& aOutDevice) {
|
2019-05-25 09:07:49 +03:00
|
|
|
if (gfxPrefs::Direct3D11EnableDebugLayer() ||
|
|
|
|
gfxPrefs::Direct3D11BreakOnError()) {
|
2017-07-11 23:53:04 +03:00
|
|
|
aFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
|
|
|
}
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
MOZ_SEH_TRY {
|
2016-08-13 22:04:03 +03:00
|
|
|
aResOut = sD3D11CreateDeviceFn(
|
|
|
|
aAdapter, aDriverType, nullptr, aFlags, mFeatureLevels.Elements(),
|
|
|
|
mFeatureLevels.Length(), D3D11_SDK_VERSION, getter_AddRefs(aOutDevice),
|
|
|
|
nullptr, nullptr);
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
2016-08-24 01:18:55 +03:00
|
|
|
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { return false; }
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2019-05-25 09:07:49 +03:00
|
|
|
if (gfxPrefs::Direct3D11BreakOnError()) {
|
2017-07-11 23:53:04 +03:00
|
|
|
do {
|
|
|
|
if (!aOutDevice) break;
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2017-07-11 23:53:04 +03:00
|
|
|
RefPtr<ID3D11Debug> debug;
|
|
|
|
if (!SUCCEEDED(aOutDevice->QueryInterface(__uuidof(ID3D11Debug),
|
|
|
|
getter_AddRefs(debug))))
|
|
|
|
break;
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2017-07-11 23:53:04 +03:00
|
|
|
RefPtr<ID3D11InfoQueue> infoQueue;
|
|
|
|
if (!SUCCEEDED(debug->QueryInterface(__uuidof(ID3D11InfoQueue),
|
|
|
|
getter_AddRefs(infoQueue))))
|
|
|
|
break;
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2017-07-26 08:34:29 +03:00
|
|
|
D3D11_INFO_QUEUE_FILTER filter;
|
|
|
|
PodZero(&filter);
|
|
|
|
|
|
|
|
// Disable warnings caused by Advanced Layers that are known and not
|
|
|
|
// problematic.
|
|
|
|
D3D11_MESSAGE_ID blockIDs[] = {
|
|
|
|
D3D11_MESSAGE_ID_DEVICE_DRAW_CONSTANT_BUFFER_TOO_SMALL};
|
|
|
|
filter.DenyList.NumIDs = MOZ_ARRAY_LENGTH(blockIDs);
|
|
|
|
filter.DenyList.pIDList = blockIDs;
|
|
|
|
infoQueue->PushStorageFilter(&filter);
|
|
|
|
|
2017-07-11 23:53:04 +03:00
|
|
|
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
|
|
|
|
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
|
|
|
|
infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
|
|
|
|
} while (false);
|
|
|
|
}
|
2017-03-09 04:06:43 +03:00
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::CreateWARPCompositorDevice() {
|
2016-07-26 23:22:13 +03:00
|
|
|
ScopedGfxFeatureReporter reporterWARP("D3D11-WARP",
|
2019-05-25 09:07:49 +03:00
|
|
|
gfxPrefs::LayersD3D11ForceWARP());
|
2016-07-26 23:22:13 +03:00
|
|
|
FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
RefPtr<ID3D11Device> device;
|
2016-08-13 22:04:03 +03:00
|
|
|
|
|
|
|
// Use D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
|
|
|
|
// to prevent bug 1092260. IE 11 also uses this flag.
|
|
|
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
|
|
|
if (!CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, flags, hr, device)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxCriticalError() << "Exception occurred initializing WARP D3D11 device!";
|
|
|
|
d3d11.SetFailed(FeatureStatus::CrashedInHandler,
|
|
|
|
"Crashed creating a D3D11 WARP device",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_WARP_DEVICE"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr) || !device) {
|
|
|
|
// This should always succeed... in theory.
|
|
|
|
gfxCriticalError() << "Failed to initialize WARP D3D11 device! "
|
|
|
|
<< hexa(hr);
|
|
|
|
d3d11.SetFailed(FeatureStatus::Failed,
|
|
|
|
"Failed to create a D3D11 WARP device",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_WARP_DEVICE2"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only test for texture sharing on Windows 8 since it puts the device into
|
|
|
|
// an unusable state if used on Windows 7
|
2016-08-21 06:59:11 +03:00
|
|
|
bool textureSharingWorks = false;
|
2016-07-26 23:22:13 +03:00
|
|
|
if (IsWin8OrLater()) {
|
2016-08-21 06:59:11 +03:00
|
|
|
textureSharingWorks = D3D11Checks::DoesTextureSharingWork(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
DxgiAdapterDesc nullAdapter;
|
|
|
|
PodZero(&nullAdapter);
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
int featureLevel = device->GetFeatureLevel();
|
2017-09-10 18:54:31 +03:00
|
|
|
|
2018-10-11 01:14:51 +03:00
|
|
|
auto formatOptions = D3D11Checks::FormatOptions(device);
|
2016-08-21 06:59:11 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
mCompositorDevice = device;
|
2017-07-19 06:09:00 +03:00
|
|
|
|
|
|
|
int32_t sequenceNumber = GetNextDeviceCounter();
|
2018-10-11 01:14:51 +03:00
|
|
|
mDeviceStatus =
|
|
|
|
Some(D3D11DeviceStatus(true, textureSharingWorks, featureLevel,
|
|
|
|
nullAdapter, sequenceNumber, formatOptions));
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
mCompositorDevice->SetExceptionMode(0);
|
2016-08-21 06:59:11 +03:00
|
|
|
|
|
|
|
reporterWARP.SetSuccessful();
|
2016-07-26 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
FeatureStatus DeviceManagerDx::CreateContentDevice() {
|
2016-07-26 23:22:13 +03:00
|
|
|
RefPtr<IDXGIAdapter1> adapter;
|
2016-08-21 06:59:11 +03:00
|
|
|
if (!mDeviceStatus->isWARP()) {
|
2016-07-26 23:22:13 +03:00
|
|
|
adapter = GetDXGIAdapter();
|
|
|
|
if (!adapter) {
|
2016-08-21 06:59:11 +03:00
|
|
|
gfxCriticalNote << "Could not get a DXGI adapter";
|
2016-07-26 23:22:13 +03:00
|
|
|
return FeatureStatus::Unavailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
2016-08-03 06:28:18 +03:00
|
|
|
RefPtr<ID3D11Device> device;
|
2016-08-13 22:04:03 +03:00
|
|
|
|
|
|
|
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
|
2016-08-21 06:59:11 +03:00
|
|
|
D3D_DRIVER_TYPE type =
|
|
|
|
mDeviceStatus->isWARP() ? D3D_DRIVER_TYPE_WARP : D3D_DRIVER_TYPE_UNKNOWN;
|
2016-08-13 22:04:03 +03:00
|
|
|
if (!CreateDevice(adapter, type, flags, hr, device)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxCriticalNote
|
|
|
|
<< "Recovered from crash while creating a D3D11 content device";
|
|
|
|
gfxWindowsPlatform::RecordContentDeviceFailure(
|
|
|
|
TelemetryDeviceCode::Content);
|
|
|
|
return FeatureStatus::CrashedInHandler;
|
|
|
|
}
|
|
|
|
|
2016-08-03 06:28:18 +03:00
|
|
|
if (FAILED(hr) || !device) {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxCriticalNote << "Failed to create a D3D11 content device: " << hexa(hr);
|
|
|
|
gfxWindowsPlatform::RecordContentDeviceFailure(
|
|
|
|
TelemetryDeviceCode::Content);
|
|
|
|
return FeatureStatus::Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitializeD2D() will abort early if the compositor device did not support
|
|
|
|
// texture sharing. If we're in the content process, we can't rely on the
|
|
|
|
// parent device alone: some systems have dual GPUs that are capable of
|
|
|
|
// binding the parent and child processes to different GPUs. As a safety net,
|
|
|
|
// we re-check texture sharing against the newly created D3D11 content device.
|
|
|
|
// If it fails, we won't use Direct2D.
|
|
|
|
if (XRE_IsContentProcess()) {
|
2016-08-21 06:59:11 +03:00
|
|
|
if (!D3D11Checks::DoesTextureSharingWork(device)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
return FeatureStatus::Failed;
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
DebugOnly<bool> ok = ContentAdapterIsParentAdapter(device);
|
2016-07-26 23:22:13 +03:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
mContentDevice = device;
|
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
mContentDevice->SetExceptionMode(0);
|
|
|
|
|
2016-10-05 20:35:53 +03:00
|
|
|
RefPtr<ID3D10Multithread> multi;
|
|
|
|
hr = mContentDevice->QueryInterface(__uuidof(ID3D10Multithread),
|
|
|
|
getter_AddRefs(multi));
|
|
|
|
if (SUCCEEDED(hr) && multi) {
|
|
|
|
multi->SetMultithreadProtected(TRUE);
|
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
return FeatureStatus::Available;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
RefPtr<ID3D11Device> DeviceManagerDx::CreateDecoderDevice() {
|
2016-11-04 03:28:28 +03:00
|
|
|
bool isAMD = false;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
isAMD = mDeviceStatus->adapter().VendorId == 0x1002;
|
|
|
|
}
|
2016-10-05 20:35:53 +03:00
|
|
|
|
2016-11-04 03:28:28 +03:00
|
|
|
bool reuseDevice = false;
|
2019-05-26 17:29:42 +03:00
|
|
|
if (StaticPrefs::Direct3D11ReuseDecoderDevice() < 0) {
|
2016-11-04 03:28:28 +03:00
|
|
|
// Use the default logic, which is to allow reuse of devices on AMD, but
|
|
|
|
// create separate devices everywhere else.
|
|
|
|
if (isAMD) {
|
|
|
|
reuseDevice = true;
|
2016-10-05 20:35:53 +03:00
|
|
|
}
|
2019-05-26 17:29:42 +03:00
|
|
|
} else if (StaticPrefs::Direct3D11ReuseDecoderDevice() > 0) {
|
2016-11-04 03:28:28 +03:00
|
|
|
reuseDevice = true;
|
2016-08-02 09:46:27 +03:00
|
|
|
}
|
|
|
|
|
2016-11-04 03:28:28 +03:00
|
|
|
if (reuseDevice) {
|
|
|
|
if (mCompositorDevice && mCompositorDeviceSupportsVideo &&
|
|
|
|
!mDecoderDevice) {
|
|
|
|
mDecoderDevice = mCompositorDevice;
|
|
|
|
|
|
|
|
RefPtr<ID3D10Multithread> multi;
|
|
|
|
mDecoderDevice->QueryInterface(__uuidof(ID3D10Multithread),
|
|
|
|
getter_AddRefs(multi));
|
|
|
|
if (multi) {
|
|
|
|
multi->SetMultithreadProtected(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDecoderDevice) {
|
|
|
|
RefPtr<ID3D11Device> dev = mDecoderDevice;
|
|
|
|
return dev.forget();
|
|
|
|
}
|
2016-08-02 09:46:27 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
if (!sD3D11CreateDeviceFn) {
|
|
|
|
// We should just be on Windows Vista or XP in this case.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
|
|
|
|
if (!adapter) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-13 22:04:03 +03:00
|
|
|
HRESULT hr;
|
2016-07-26 22:50:30 +03:00
|
|
|
RefPtr<ID3D11Device> device;
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-08-13 22:04:03 +03:00
|
|
|
UINT flags = D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS |
|
|
|
|
D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
|
|
|
|
if (!CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, flags, hr, device)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (FAILED(hr) || !device || !D3D11Checks::DoesDeviceWork()) {
|
2016-07-26 22:50:30 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-07-26 23:22:13 +03:00
|
|
|
|
2016-10-05 20:35:53 +03:00
|
|
|
RefPtr<ID3D10Multithread> multi;
|
|
|
|
device->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
|
2017-06-21 12:53:38 +03:00
|
|
|
if (multi) {
|
|
|
|
multi->SetMultithreadProtected(TRUE);
|
|
|
|
}
|
2016-11-04 03:28:28 +03:00
|
|
|
if (reuseDevice) {
|
|
|
|
mDecoderDevice = device;
|
|
|
|
}
|
2016-07-26 22:50:30 +03:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:23:12 +03:00
|
|
|
RefPtr<MLGDevice> DeviceManagerDx::GetMLGDevice() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mMLGDevice) {
|
|
|
|
MutexAutoUnlock unlock(mDeviceLock);
|
|
|
|
CreateMLGDevice();
|
|
|
|
}
|
|
|
|
return mMLGDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DisableAdvancedLayers(FeatureStatus aStatus,
|
|
|
|
const nsCString aMessage,
|
|
|
|
const nsCString& aFailureId) {
|
|
|
|
if (!NS_IsMainThread()) {
|
2017-06-12 22:34:10 +03:00
|
|
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
|
|
|
"DisableAdvancedLayers", [aStatus, aMessage, aFailureId]() -> void {
|
2017-06-24 00:23:12 +03:00
|
|
|
DisableAdvancedLayers(aStatus, aMessage, aFailureId);
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
FeatureState& al = gfxConfig::GetFeature(Feature::ADVANCED_LAYERS);
|
|
|
|
if (!al.IsEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
al.SetFailed(aStatus, aMessage.get(), aFailureId);
|
|
|
|
|
|
|
|
FeatureFailure info(aStatus, aMessage, aFailureId);
|
|
|
|
if (GPUParent* gpu = GPUParent::GetSingleton()) {
|
2017-09-28 20:53:24 +03:00
|
|
|
Unused << gpu->SendUpdateFeature(Feature::ADVANCED_LAYERS, info);
|
2017-06-24 00:23:12 +03:00
|
|
|
}
|
2017-06-24 00:23:13 +03:00
|
|
|
|
|
|
|
if (aFailureId.Length()) {
|
|
|
|
nsString failureId = NS_ConvertUTF8toUTF16(aFailureId.get());
|
|
|
|
Telemetry::ScalarAdd(Telemetry::ScalarID::GFX_ADVANCED_LAYERS_FAILURE_ID,
|
|
|
|
failureId, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify TelemetryEnvironment.jsm.
|
|
|
|
if (RefPtr<nsIObserverService> obs =
|
|
|
|
mozilla::services::GetObserverService()) {
|
|
|
|
obs->NotifyObservers(nullptr, "gfx-features-ready", nullptr);
|
|
|
|
}
|
2017-06-24 00:23:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceManagerDx::CreateMLGDevice() {
|
|
|
|
MOZ_ASSERT(layers::CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> d3d11Device = GetCompositorDevice();
|
|
|
|
if (!d3d11Device) {
|
|
|
|
DisableAdvancedLayers(
|
|
|
|
FeatureStatus::Unavailable,
|
|
|
|
NS_LITERAL_CSTRING("Advanced-layers requires a D3D11 device"),
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_NEED_D3D11_DEVICE"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<MLGDeviceD3D11> device = new MLGDeviceD3D11(d3d11Device);
|
|
|
|
if (!device->Initialize()) {
|
|
|
|
DisableAdvancedLayers(FeatureStatus::Failed, device->GetFailureMessage(),
|
|
|
|
device->GetFailureId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// While the lock was unheld, we should not have created an MLGDevice, since
|
|
|
|
// this should only be called on the compositor thread.
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
MOZ_ASSERT(!mMLGDevice);
|
|
|
|
|
|
|
|
// Only set the MLGDevice if the compositor device is still the same.
|
|
|
|
// Otherwise we could possibly have a bad MLGDevice if a device reset
|
|
|
|
// just occurred.
|
|
|
|
if (mCompositorDevice == d3d11Device) {
|
|
|
|
mMLGDevice = device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::ResetDevices() {
|
2017-07-18 22:16:13 +03:00
|
|
|
// Flush the paint thread before revoking all these singletons. This
|
|
|
|
// should ensure that the paint thread doesn't start mixing and matching
|
|
|
|
// old and new objects together.
|
|
|
|
if (PaintThread::Get()) {
|
|
|
|
CompositorBridgeChild* cbc = CompositorBridgeChild::Get();
|
2018-01-24 18:01:33 +03:00
|
|
|
if (cbc) {
|
|
|
|
cbc->FlushAsyncPaints();
|
|
|
|
}
|
2017-07-18 22:16:13 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
|
2016-10-28 05:21:34 +03:00
|
|
|
mAdapter = nullptr;
|
2017-04-30 21:38:59 +03:00
|
|
|
mCompositorAttachments = nullptr;
|
2017-06-24 00:23:12 +03:00
|
|
|
mMLGDevice = nullptr;
|
2016-07-26 23:22:13 +03:00
|
|
|
mCompositorDevice = nullptr;
|
|
|
|
mContentDevice = nullptr;
|
2018-05-31 03:35:24 +03:00
|
|
|
mImageDevice = nullptr;
|
2016-08-21 06:59:11 +03:00
|
|
|
mDeviceStatus = Nothing();
|
2016-11-11 22:57:06 +03:00
|
|
|
mDeviceResetReason = Nothing();
|
2016-07-26 23:22:13 +03:00
|
|
|
Factory::SetDirect3D11Device(nullptr);
|
|
|
|
}
|
|
|
|
|
2016-11-06 22:01:52 +03:00
|
|
|
bool DeviceManagerDx::MaybeResetAndReacquireDevices() {
|
|
|
|
DeviceResetReason resetReason;
|
2016-11-11 22:58:51 +03:00
|
|
|
if (!HasDeviceReset(&resetReason)) {
|
2016-11-06 22:01:52 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:58:51 +03:00
|
|
|
if (resetReason != DeviceResetReason::FORCED_RESET) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DEVICE_RESET_REASON,
|
|
|
|
uint32_t(resetReason));
|
|
|
|
}
|
2016-11-06 22:01:52 +03:00
|
|
|
|
2017-05-12 08:44:28 +03:00
|
|
|
CrashReporter::AnnotateCrashReport(
|
Bug 1348273 - Convert crash annotations into a machine-readable list of constants; r=ted.mielczarek,njn,dholbert,mak,cpearce,mcmanus,froydnj,Dexter,jrmuizel,jchen,jimm,bz,surkov
This introduces the machinery needed to generate crash annotations from a YAML
file. The relevant C++ functions are updated to take a typed enum. JavaScript
calls are unaffected but they will throw if the string argument does not
correspond to one of the known entries in the C++ enum. The existing whitelists
and blacklists of annotations are also generated from the YAML file and all
duplicate code related to them has been consolidated. Once written out to the
.extra file the annotations are converted in string form and are no different
than the existing ones.
All existing annotations have been included in the list (and some obsolete ones
have been removed) and all call sites have been updated including tests where
appropriate.
--HG--
extra : source : 4f6c43f2830701ec5552e08e3f1b06fe6d045860
2018-07-05 16:42:11 +03:00
|
|
|
CrashReporter::Annotation::DeviceResetReason, int(resetReason));
|
2017-05-12 08:44:28 +03:00
|
|
|
|
2016-11-06 22:01:52 +03:00
|
|
|
bool createCompositorDevice = !!mCompositorDevice;
|
|
|
|
bool createContentDevice = !!mContentDevice;
|
|
|
|
|
|
|
|
ResetDevices();
|
|
|
|
|
|
|
|
if (createCompositorDevice && !CreateCompositorDevices()) {
|
|
|
|
// Just stop, don't try anything more
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (createContentDevice) {
|
|
|
|
CreateContentDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::ContentAdapterIsParentAdapter(ID3D11Device* device) {
|
2016-07-26 23:22:13 +03:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
if (!D3D11Checks::GetDxgiDesc(device, &desc)) {
|
|
|
|
gfxCriticalNote << "Could not query device DXGI adapter info";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-21 06:59:11 +03:00
|
|
|
const DxgiAdapterDesc& preferred = mDeviceStatus->adapter();
|
|
|
|
|
|
|
|
if (desc.VendorId != preferred.VendorId ||
|
|
|
|
desc.DeviceId != preferred.DeviceId ||
|
|
|
|
desc.SubSysId != preferred.SubSysId ||
|
|
|
|
desc.AdapterLuid.HighPart != preferred.AdapterLuid.HighPart ||
|
|
|
|
desc.AdapterLuid.LowPart != preferred.AdapterLuid.LowPart) {
|
|
|
|
gfxCriticalNote << "VendorIDMismatch P " << hexa(preferred.VendorId) << " "
|
|
|
|
<< hexa(desc.VendorId);
|
2016-07-26 23:22:13 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DeviceResetReason HResultToResetReason(HRESULT hr) {
|
|
|
|
switch (hr) {
|
|
|
|
case DXGI_ERROR_DEVICE_HUNG:
|
|
|
|
return DeviceResetReason::HUNG;
|
|
|
|
case DXGI_ERROR_DEVICE_REMOVED:
|
|
|
|
return DeviceResetReason::REMOVED;
|
|
|
|
case DXGI_ERROR_DEVICE_RESET:
|
|
|
|
return DeviceResetReason::RESET;
|
|
|
|
case DXGI_ERROR_DRIVER_INTERNAL_ERROR:
|
|
|
|
return DeviceResetReason::DRIVER_ERROR;
|
|
|
|
case DXGI_ERROR_INVALID_CALL:
|
|
|
|
return DeviceResetReason::INVALID_CALL;
|
|
|
|
case E_OUTOFMEMORY:
|
|
|
|
return DeviceResetReason::OUT_OF_MEMORY;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
}
|
|
|
|
return DeviceResetReason::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:57:06 +03:00
|
|
|
bool DeviceManagerDx::HasDeviceReset(DeviceResetReason* aOutReason) {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
|
|
|
|
if (mDeviceResetReason) {
|
2016-11-15 03:38:26 +03:00
|
|
|
if (aOutReason) {
|
|
|
|
*aOutReason = mDeviceResetReason.value();
|
|
|
|
}
|
2016-11-11 22:57:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceResetReason reason;
|
|
|
|
if (GetAnyDeviceRemovedReason(&reason)) {
|
|
|
|
mDeviceResetReason = Some(reason);
|
2016-11-15 03:38:26 +03:00
|
|
|
if (aOutReason) {
|
|
|
|
*aOutReason = reason;
|
|
|
|
}
|
2016-11-11 22:57:06 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool DidDeviceReset(const RefPtr<ID3D11Device>& aDevice,
|
|
|
|
DeviceResetReason* aOutReason) {
|
2016-07-26 23:22:13 +03:00
|
|
|
if (!aDevice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
HRESULT hr = aDevice->GetDeviceRemovedReason();
|
|
|
|
if (hr == S_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOutReason = HResultToResetReason(hr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::GetAnyDeviceRemovedReason(DeviceResetReason* aOutReason) {
|
2016-11-11 22:57:06 +03:00
|
|
|
// Caller must own the lock, since we access devices directly, and can be
|
|
|
|
// called from any thread.
|
|
|
|
mDeviceLock.AssertCurrentThreadOwns();
|
|
|
|
|
|
|
|
if (DidDeviceReset(mCompositorDevice, aOutReason) ||
|
|
|
|
DidDeviceReset(mContentDevice, aOutReason)) {
|
2016-07-26 23:22:13 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-11 22:57:06 +03:00
|
|
|
|
|
|
|
if (XRE_IsParentProcess() && NS_IsMainThread() &&
|
2019-05-26 17:29:42 +03:00
|
|
|
StaticPrefs::DeviceResetForTesting()) {
|
|
|
|
StaticPrefs::SetDeviceResetForTesting(0);
|
2016-11-11 22:57:06 +03:00
|
|
|
*aOutReason = DeviceResetReason::FORCED_RESET;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-26 23:22:13 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:57:06 +03:00
|
|
|
void DeviceManagerDx::ForceDeviceReset(ForcedDeviceResetReason aReason) {
|
|
|
|
Telemetry::Accumulate(Telemetry::FORCED_DEVICE_RESET_REASON,
|
|
|
|
uint32_t(aReason));
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
2017-07-11 05:30:58 +03:00
|
|
|
if (!mDeviceResetReason) {
|
|
|
|
mDeviceResetReason = Some(DeviceResetReason::FORCED_RESET);
|
|
|
|
}
|
2016-11-11 22:57:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::DisableD3D11AfterCrash() {
|
2016-07-26 23:22:13 +03:00
|
|
|
gfxConfig::Disable(Feature::D3D11_COMPOSITING,
|
|
|
|
FeatureStatus::CrashedInHandler,
|
|
|
|
"Crashed while acquiring a Direct3D11 device",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_CRASH"));
|
|
|
|
ResetDevices();
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
RefPtr<ID3D11Device> DeviceManagerDx::GetCompositorDevice() {
|
2016-07-26 23:22:13 +03:00
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
return mCompositorDevice;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
RefPtr<ID3D11Device> DeviceManagerDx::GetContentDevice() {
|
2018-12-18 08:54:28 +03:00
|
|
|
MOZ_ASSERT(XRE_IsGPUProcess() ||
|
|
|
|
gfxPlatform::GetPlatform()->DevicesInitialized());
|
|
|
|
|
2016-08-03 06:28:18 +03:00
|
|
|
MutexAutoLock lock(mDeviceLock);
|
2016-07-26 23:22:13 +03:00
|
|
|
return mContentDevice;
|
|
|
|
}
|
|
|
|
|
2018-05-31 03:35:24 +03:00
|
|
|
RefPtr<ID3D11Device> DeviceManagerDx::GetImageDevice() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (mImageDevice) {
|
|
|
|
return mImageDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11Device> device = mContentDevice;
|
|
|
|
if (!device) {
|
|
|
|
device = mCompositorDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!device) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D10Multithread> multi;
|
|
|
|
HRESULT hr =
|
|
|
|
device->QueryInterface((ID3D10Multithread**)getter_AddRefs(multi));
|
|
|
|
if (FAILED(hr) || !multi) {
|
|
|
|
gfxWarning() << "Multithread safety interface not supported. " << hr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
multi->SetMultithreadProtected(TRUE);
|
|
|
|
|
|
|
|
mImageDevice = device;
|
|
|
|
|
|
|
|
return mImageDevice;
|
|
|
|
}
|
|
|
|
|
2017-08-29 01:56:43 +03:00
|
|
|
RefPtr<ID3D11Device> DeviceManagerDx::GetVRDevice() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mVRDevice) {
|
|
|
|
CreateVRDevice();
|
|
|
|
}
|
|
|
|
return mVRDevice;
|
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
RefPtr<IDCompositionDevice> DeviceManagerDx::GetDirectCompositionDevice() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
return mDirectCompositionDevice;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
unsigned DeviceManagerDx::GetCompositorFeatureLevel() const {
|
2016-08-21 06:59:11 +03:00
|
|
|
if (!mDeviceStatus) {
|
2016-07-26 23:22:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2016-08-21 06:59:11 +03:00
|
|
|
return mDeviceStatus->featureLevel();
|
2016-07-26 22:50:30 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::TextureSharingWorks() {
|
2016-08-21 06:59:11 +03:00
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mDeviceStatus->textureSharingWorks();
|
2016-07-26 22:50:30 +03:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:32:55 +03:00
|
|
|
bool DeviceManagerDx::CanInitializeKeyedMutexTextures() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
2019-05-26 17:29:42 +03:00
|
|
|
return mDeviceStatus && StaticPrefs::Direct3D11AllowKeyedMutex() &&
|
2017-07-25 21:02:36 +03:00
|
|
|
gfxVars::AllowD3D11KeyedMutex();
|
2016-10-06 15:32:55 +03:00
|
|
|
}
|
|
|
|
|
2017-05-01 04:11:24 +03:00
|
|
|
bool DeviceManagerDx::HasCrashyInitData() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (mDeviceStatus->adapter().VendorId == 0x8086 && !IsWin10OrLater());
|
|
|
|
}
|
|
|
|
|
2016-10-28 05:21:34 +03:00
|
|
|
bool DeviceManagerDx::CheckRemotePresentSupport() {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
|
|
|
|
if (!adapter) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!D3D11Checks::DoesRemotePresentWork(adapter)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
bool DeviceManagerDx::IsWARP() {
|
2016-08-21 06:59:11 +03:00
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mDeviceStatus->isWARP();
|
2016-07-26 22:50:30 +03:00
|
|
|
}
|
|
|
|
|
2017-09-10 18:54:31 +03:00
|
|
|
bool DeviceManagerDx::CanUseNV12() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-11 01:14:51 +03:00
|
|
|
return mDeviceStatus->formatOptions().contains(
|
|
|
|
D3D11Checks::VideoFormatOption::NV12);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceManagerDx::CanUseP010() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mDeviceStatus->formatOptions().contains(
|
|
|
|
D3D11Checks::VideoFormatOption::P010);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceManagerDx::CanUseP016() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mDeviceStatus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mDeviceStatus->formatOptions().contains(
|
|
|
|
D3D11Checks::VideoFormatOption::P016);
|
2017-09-10 18:54:31 +03:00
|
|
|
}
|
|
|
|
|
2018-03-29 05:23:31 +03:00
|
|
|
bool DeviceManagerDx::CanUseDComp() {
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
return !!mDirectCompositionDevice;
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
void DeviceManagerDx::InitializeDirectDraw() {
|
|
|
|
MOZ_ASSERT(layers::CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
|
|
|
if (mDirectDraw) {
|
|
|
|
// Already initialized.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureState& ddraw = gfxConfig::GetFeature(Feature::DIRECT_DRAW);
|
|
|
|
if (!ddraw.IsEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if DirectDraw is available on this system.
|
|
|
|
mDirectDrawDLL.own(LoadLibrarySystem32(L"ddraw.dll"));
|
|
|
|
if (!mDirectDrawDLL) {
|
|
|
|
ddraw.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"DirectDraw not available on this computer",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_DDRAW_LIB"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sDirectDrawCreateExFn = (decltype(DirectDrawCreateEx)*)GetProcAddress(
|
|
|
|
mDirectDrawDLL, "DirectDrawCreateEx");
|
|
|
|
if (!sDirectDrawCreateExFn) {
|
|
|
|
ddraw.SetFailed(FeatureStatus::Unavailable,
|
|
|
|
"DirectDraw not available on this computer",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_DDRAW_LIB"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
MOZ_SEH_TRY {
|
|
|
|
hr = sDirectDrawCreateExFn(nullptr, getter_AddRefs(mDirectDraw),
|
|
|
|
IID_IDirectDraw7, nullptr);
|
|
|
|
}
|
|
|
|
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
ddraw.SetFailed(FeatureStatus::Failed, "Failed to create DirectDraw",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_DDRAW_LIB"));
|
|
|
|
gfxCriticalNote << "DoesCreatingDirectDrawFailed";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
ddraw.SetFailed(FeatureStatus::Failed, "Failed to create DirectDraw",
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_DDRAW_LIB"));
|
|
|
|
gfxCriticalNote << "DoesCreatingDirectDrawFailed " << hexa(hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectDraw7* DeviceManagerDx::GetDirectDraw() { return mDirectDraw; }
|
|
|
|
|
2017-04-30 21:38:59 +03:00
|
|
|
void DeviceManagerDx::GetCompositorDevices(
|
|
|
|
RefPtr<ID3D11Device>* aOutDevice,
|
|
|
|
RefPtr<layers::DeviceAttachmentsD3D11>* aOutAttachments) {
|
2017-04-30 21:38:59 +03:00
|
|
|
MOZ_ASSERT(layers::CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
2017-04-30 21:38:59 +03:00
|
|
|
RefPtr<ID3D11Device> device;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (!mCompositorDevice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mCompositorAttachments) {
|
|
|
|
*aOutDevice = mCompositorDevice;
|
|
|
|
*aOutAttachments = mCompositorAttachments;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we'll try to create attachments outside the lock.
|
|
|
|
device = mCompositorDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We save the attachments object even if it fails to initialize, so the
|
|
|
|
// compositor can grab the failure ID.
|
|
|
|
RefPtr<layers::DeviceAttachmentsD3D11> attachments =
|
|
|
|
layers::DeviceAttachmentsD3D11::Create(device);
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDeviceLock);
|
|
|
|
if (device != mCompositorDevice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCompositorAttachments = attachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOutDevice = device;
|
|
|
|
*aOutAttachments = attachments;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void DeviceManagerDx::PreloadAttachmentsOnCompositorThread() {
|
2017-04-30 21:38:59 +03:00
|
|
|
MessageLoop* loop = layers::CompositorThreadHolder::Loop();
|
|
|
|
if (!loop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:23:12 +03:00
|
|
|
bool enableAL = gfxConfig::IsEnabled(Feature::ADVANCED_LAYERS);
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
RefPtr<Runnable> task = NS_NewRunnableFunction(
|
|
|
|
"DeviceManagerDx::PreloadAttachmentsOnCompositorThread",
|
|
|
|
[enableAL]() -> void {
|
2017-04-30 21:38:59 +03:00
|
|
|
if (DeviceManagerDx* dm = DeviceManagerDx::Get()) {
|
2017-06-24 00:23:12 +03:00
|
|
|
if (enableAL) {
|
|
|
|
dm->GetMLGDevice();
|
|
|
|
} else {
|
|
|
|
RefPtr<ID3D11Device> device;
|
|
|
|
RefPtr<layers::DeviceAttachmentsD3D11> attachments;
|
|
|
|
dm->GetCompositorDevices(&device, &attachments);
|
|
|
|
}
|
2017-04-30 21:38:59 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
loop->PostTask(task.forget());
|
|
|
|
}
|
|
|
|
|
2016-07-26 22:50:30 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|