2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2016-07-26 23:19:48 +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/. */
|
|
|
|
|
|
|
|
#include "D3D11Checks.h"
|
2017-09-10 18:54:31 +03:00
|
|
|
#include "DXVA2Manager.h"
|
2016-07-26 23:19:48 +03:00
|
|
|
#include "gfxConfig.h"
|
|
|
|
#include "GfxDriverInfo.h"
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2019-05-26 17:29:42 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2018-05-17 06:07:20 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2016-07-26 23:19:48 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2016-11-07 08:48:00 +03:00
|
|
|
#include "mozilla/layers/TextureD3D11.h"
|
2016-07-26 23:19:48 +03:00
|
|
|
#include "nsIGfxInfo.h"
|
|
|
|
#include <dxgi.h>
|
2016-10-26 04:42:20 +03:00
|
|
|
#include <dxgi1_2.h>
|
2016-07-26 23:19:48 +03:00
|
|
|
#include <d3d10_1.h>
|
|
|
|
#include <d3d11.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
using namespace mozilla::widget;
|
2016-11-07 08:48:00 +03:00
|
|
|
using mozilla::layers::AutoTextureLock;
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::DoesRenderTargetViewNeedRecreating(ID3D11Device* aDevice) {
|
2016-07-26 23:19:48 +03:00
|
|
|
bool result = false;
|
|
|
|
// CreateTexture2D is known to crash on lower feature levels, see bugs
|
|
|
|
// 1170211 and 1089413.
|
|
|
|
if (aDevice->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11DeviceContext> deviceContext;
|
|
|
|
aDevice->GetImmediateContext(getter_AddRefs(deviceContext));
|
|
|
|
int backbufferWidth = 32;
|
|
|
|
int backbufferHeight = 32;
|
|
|
|
RefPtr<ID3D11Texture2D> offscreenTexture;
|
|
|
|
RefPtr<IDXGIKeyedMutex> keyedMutex;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-26 23:19:48 +03:00
|
|
|
D3D11_TEXTURE2D_DESC offscreenTextureDesc = {0};
|
|
|
|
offscreenTextureDesc.Width = backbufferWidth;
|
|
|
|
offscreenTextureDesc.Height = backbufferHeight;
|
|
|
|
offscreenTextureDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
offscreenTextureDesc.MipLevels = 0;
|
|
|
|
offscreenTextureDesc.ArraySize = 1;
|
|
|
|
offscreenTextureDesc.SampleDesc.Count = 1;
|
|
|
|
offscreenTextureDesc.SampleDesc.Quality = 0;
|
|
|
|
offscreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
offscreenTextureDesc.BindFlags =
|
|
|
|
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
|
|
|
offscreenTextureDesc.CPUAccessFlags = 0;
|
|
|
|
offscreenTextureDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-26 23:19:48 +03:00
|
|
|
HRESULT hr = aDevice->CreateTexture2D(&offscreenTextureDesc, NULL,
|
|
|
|
getter_AddRefs(offscreenTexture));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "DoesRecreatingCreateTexture2DFail";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = offscreenTexture->QueryInterface(__uuidof(IDXGIKeyedMutex),
|
|
|
|
(void**)getter_AddRefs(keyedMutex));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "DoesRecreatingKeyedMutexFailed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
D3D11_RENDER_TARGET_VIEW_DESC offscreenRTVDesc;
|
|
|
|
offscreenRTVDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
offscreenRTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
|
|
offscreenRTVDesc.Texture2D.MipSlice = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-26 23:19:48 +03:00
|
|
|
RefPtr<ID3D11RenderTargetView> offscreenRTView;
|
|
|
|
hr = aDevice->CreateRenderTargetView(offscreenTexture, &offscreenRTVDesc,
|
|
|
|
getter_AddRefs(offscreenRTView));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "DoesRecreatingCreateRenderTargetViewFailed";
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
{
|
2016-07-26 23:19:48 +03:00
|
|
|
// Acquire and clear
|
|
|
|
HRESULT hr;
|
|
|
|
AutoTextureLock lock(keyedMutex, hr, INFINITE);
|
|
|
|
FLOAT color1[4] = {1, 1, 0.5, 1};
|
|
|
|
deviceContext->ClearRenderTargetView(offscreenRTView, color1);
|
|
|
|
}
|
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
AutoTextureLock lock(keyedMutex, hr, INFINITE);
|
|
|
|
FLOAT color2[4] = {1, 1, 0, 1};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
deviceContext->ClearRenderTargetView(offscreenRTView, color2);
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
offscreenTexture->GetDesc(&desc);
|
|
|
|
desc.Usage = D3D11_USAGE_STAGING;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.BindFlags = 0;
|
|
|
|
RefPtr<ID3D11Texture2D> cpuTexture;
|
|
|
|
hr = aDevice->CreateTexture2D(&desc, NULL, getter_AddRefs(cpuTexture));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "DoesRecreatingCreateCPUTextureFailed";
|
|
|
|
return false;
|
2016-07-26 23:19:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
deviceContext->CopyResource(cpuTexture, offscreenTexture);
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped;
|
|
|
|
hr = deviceContext->Map(cpuTexture, 0, D3D11_MAP_READ, 0, &mapped);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalNote << "DoesRecreatingMapFailed " << hexa(hr);
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-11-07 08:48:00 +03:00
|
|
|
int resultColor = *(int*)mapped.pData;
|
|
|
|
deviceContext->Unmap(cpuTexture, 0);
|
|
|
|
cpuTexture = nullptr;
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
// XXX on some drivers resultColor will not have changed to
|
|
|
|
// match the clear
|
|
|
|
if (resultColor != 0xffffff00) {
|
|
|
|
gfxCriticalNote << "RenderTargetViewNeedsRecreating";
|
|
|
|
result = true;
|
2016-07-26 23:19:48 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-26 23:19:48 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::DoesDeviceWork() {
|
2016-07-26 23:19:48 +03:00
|
|
|
static bool checked = false;
|
|
|
|
static bool result = false;
|
|
|
|
|
|
|
|
if (checked) return result;
|
|
|
|
checked = true;
|
|
|
|
|
2019-05-26 17:30:14 +03:00
|
|
|
if (StaticPrefs::Direct2DForceEnabled() ||
|
2016-07-26 23:19:48 +03:00
|
|
|
gfxConfig::IsForcedOnByUser(Feature::HW_COMPOSITING)) {
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetModuleHandleW(L"igd10umd32.dll")) {
|
|
|
|
const wchar_t* checkModules[] = {L"dlumd32.dll", L"dlumd11.dll",
|
|
|
|
L"dlumd10.dll"};
|
|
|
|
for (int i = 0; i < PR_ARRAY_SIZE(checkModules); i += 1) {
|
|
|
|
if (GetModuleHandleW(checkModules[i])) {
|
|
|
|
nsString displayLinkModuleVersionString;
|
|
|
|
gfxWindowsPlatform::GetDLLVersion(checkModules[i],
|
|
|
|
displayLinkModuleVersionString);
|
|
|
|
uint64_t displayLinkModuleVersion;
|
|
|
|
if (!ParseDriverVersion(displayLinkModuleVersionString,
|
|
|
|
&displayLinkModuleVersion)) {
|
|
|
|
gfxCriticalError()
|
|
|
|
<< "DisplayLink: could not parse version " << checkModules[i];
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (displayLinkModuleVersion <= V(8, 6, 1, 36484)) {
|
2017-06-13 02:20:48 +03:00
|
|
|
NS_ConvertUTF16toUTF8 version(displayLinkModuleVersionString);
|
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(false))
|
|
|
|
<< "DisplayLink: too old version " << version.get();
|
2016-07-26 23:19:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool TryCreateTexture2D(ID3D11Device* device, D3D11_TEXTURE2D_DESC* desc,
|
|
|
|
D3D11_SUBRESOURCE_DATA* data,
|
|
|
|
RefPtr<ID3D11Texture2D>& texture) {
|
|
|
|
// Older Intel driver version (see bug 1221348 for version #s) crash when
|
|
|
|
// creating a texture with shared keyed mutex and data.
|
|
|
|
MOZ_SEH_TRY {
|
|
|
|
return !FAILED(
|
|
|
|
device->CreateTexture2D(desc, data, getter_AddRefs(texture)));
|
|
|
|
}
|
|
|
|
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
// For now we want to aggregrate all the crash signature to a known crash.
|
|
|
|
gfxDevCrash(LogReason::TextureCreation)
|
|
|
|
<< "Crash creating texture. See bug 1221348.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See bug 1083071. On some drivers, Direct3D 11 CreateShaderResourceView fails
|
|
|
|
// with E_OUTOFMEMORY.
|
|
|
|
static bool DoesTextureSharingWorkInternal(ID3D11Device* device,
|
|
|
|
DXGI_FORMAT format, UINT bindflags) {
|
|
|
|
// CreateTexture2D is known to crash on lower feature levels, see bugs
|
|
|
|
// 1170211 and 1089413.
|
|
|
|
if (device->GetFeatureLevel() < D3D_FEATURE_LEVEL_10_0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-26 17:30:14 +03:00
|
|
|
if (StaticPrefs::Direct2DForceEnabled() ||
|
2016-07-26 23:19:48 +03:00
|
|
|
gfxConfig::IsForcedOnByUser(Feature::HW_COMPOSITING)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetModuleHandleW(L"atidxx32.dll")) {
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
if (gfxInfo) {
|
|
|
|
nsString vendorID, vendorID2;
|
|
|
|
gfxInfo->GetAdapterVendorID(vendorID);
|
|
|
|
gfxInfo->GetAdapterVendorID2(vendorID2);
|
|
|
|
if (vendorID.EqualsLiteral("0x8086") && vendorID2.IsEmpty()) {
|
2019-05-26 17:30:14 +03:00
|
|
|
if (!StaticPrefs::LayersAMDSwitchableGfxEnabled()) {
|
2016-07-26 23:19:48 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(false))
|
|
|
|
<< "PossiblyBrokenSurfaceSharing_UnexpectedAMDGPU";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11Texture2D> texture;
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
const int texture_size = 32;
|
|
|
|
desc.Width = texture_size;
|
|
|
|
desc.Height = texture_size;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.Format = format;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
|
|
|
desc.BindFlags = bindflags;
|
|
|
|
|
|
|
|
uint32_t color[texture_size * texture_size];
|
|
|
|
for (size_t i = 0; i < sizeof(color) / sizeof(color[0]); i++) {
|
|
|
|
color[i] = 0xff00ffff;
|
|
|
|
}
|
|
|
|
// XXX If we pass the data directly at texture creation time we
|
|
|
|
// get a crash on Intel 8.5.10.[18xx-1994] drivers.
|
|
|
|
// We can work around this issue by doing UpdateSubresource.
|
|
|
|
if (!TryCreateTexture2D(device, &desc, nullptr, texture)) {
|
|
|
|
gfxCriticalNote << "DoesD3D11TextureSharingWork_TryCreateTextureFailure";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIKeyedMutex> sourceSharedMutex;
|
|
|
|
texture->QueryInterface(__uuidof(IDXGIKeyedMutex),
|
|
|
|
(void**)getter_AddRefs(sourceSharedMutex));
|
|
|
|
if (FAILED(sourceSharedMutex->AcquireSync(0, 30 * 1000))) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_SourceMutexTimeout";
|
|
|
|
// only wait for 30 seconds
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11DeviceContext> deviceContext;
|
|
|
|
device->GetImmediateContext(getter_AddRefs(deviceContext));
|
|
|
|
|
|
|
|
int stride = texture_size * 4;
|
|
|
|
deviceContext->UpdateSubresource(texture, 0, nullptr, color, stride,
|
|
|
|
stride * texture_size);
|
|
|
|
|
|
|
|
if (FAILED(sourceSharedMutex->ReleaseSync(0))) {
|
|
|
|
gfxCriticalError()
|
|
|
|
<< "DoesD3D11TextureSharingWork_SourceReleaseSyncTimeout";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE shareHandle;
|
|
|
|
RefPtr<IDXGIResource> otherResource;
|
|
|
|
if (FAILED(texture->QueryInterface(__uuidof(IDXGIResource),
|
|
|
|
getter_AddRefs(otherResource)))) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetResourceFailure";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(otherResource->GetSharedHandle(&shareHandle))) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetSharedTextureFailure";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11Resource> sharedResource;
|
|
|
|
RefPtr<ID3D11Texture2D> sharedTexture;
|
|
|
|
if (FAILED(device->OpenSharedResource(shareHandle, __uuidof(ID3D11Resource),
|
|
|
|
getter_AddRefs(sharedResource)))) {
|
|
|
|
gfxCriticalError(CriticalLog::DefaultOptions(false))
|
|
|
|
<< "OpenSharedResource failed for format " << format;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(sharedResource->QueryInterface(__uuidof(ID3D11Texture2D),
|
|
|
|
getter_AddRefs(sharedTexture)))) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetSharedTextureFailure";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a staging texture for readback
|
|
|
|
RefPtr<ID3D11Texture2D> cpuTexture;
|
|
|
|
desc.Usage = D3D11_USAGE_STAGING;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.BindFlags = 0;
|
|
|
|
if (FAILED(device->CreateTexture2D(&desc, nullptr,
|
|
|
|
getter_AddRefs(cpuTexture)))) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_CreateTextureFailure";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIKeyedMutex> sharedMutex;
|
|
|
|
sharedResource->QueryInterface(__uuidof(IDXGIKeyedMutex),
|
|
|
|
(void**)getter_AddRefs(sharedMutex));
|
2016-11-07 08:48:00 +03:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
AutoTextureLock lock(sharedMutex, hr, 30 * 1000);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_AcquireSyncTimeout";
|
|
|
|
// only wait for 30 seconds
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
// Copy to the cpu texture so that we can readback
|
|
|
|
deviceContext->CopyResource(cpuTexture, sharedTexture);
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2016-11-07 08:48:00 +03:00
|
|
|
// We only need to hold on to the mutex during the copy.
|
|
|
|
sharedMutex->ReleaseSync(0);
|
|
|
|
}
|
2016-07-17 23:54:23 +03:00
|
|
|
|
2016-07-26 23:19:48 +03:00
|
|
|
D3D11_MAPPED_SUBRESOURCE mapped;
|
2016-07-17 23:54:23 +03:00
|
|
|
uint32_t resultColor = 0;
|
2016-07-26 23:19:48 +03:00
|
|
|
if (SUCCEEDED(
|
|
|
|
deviceContext->Map(cpuTexture, 0, D3D11_MAP_READ, 0, &mapped))) {
|
|
|
|
// read the texture
|
2016-07-17 23:54:23 +03:00
|
|
|
resultColor = *(uint32_t*)mapped.pData;
|
2016-07-26 23:19:48 +03:00
|
|
|
deviceContext->Unmap(cpuTexture, 0);
|
|
|
|
} else {
|
|
|
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_MapFailed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that the color we put in is the color we get out
|
|
|
|
if (resultColor != color[0]) {
|
|
|
|
// Shared surfaces seem to be broken on dual AMD & Intel HW when using the
|
|
|
|
// AMD GPU
|
|
|
|
gfxCriticalNote << "DoesD3D11TextureSharingWork_ColorMismatch";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ID3D11ShaderResourceView> sharedView;
|
|
|
|
|
|
|
|
// This if(FAILED()) is the one that actually fails on systems affected by bug
|
|
|
|
// 1083071.
|
|
|
|
if (FAILED(device->CreateShaderResourceView(sharedTexture, NULL,
|
|
|
|
getter_AddRefs(sharedView)))) {
|
|
|
|
gfxCriticalNote << "CreateShaderResourceView failed for format" << format;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::DoesTextureSharingWork(ID3D11Device* device) {
|
2016-07-26 23:19:48 +03:00
|
|
|
return DoesTextureSharingWorkInternal(
|
|
|
|
device, DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::DoesAlphaTextureSharingWork(ID3D11Device* device) {
|
2016-07-26 23:19:48 +03:00
|
|
|
return DoesTextureSharingWorkInternal(device, DXGI_FORMAT_R8_UNORM,
|
|
|
|
D3D11_BIND_SHADER_RESOURCE);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::GetDxgiDesc(ID3D11Device* device, DXGI_ADAPTER_DESC* out) {
|
2016-07-26 23:19:48 +03:00
|
|
|
RefPtr<IDXGIDevice> dxgiDevice;
|
|
|
|
HRESULT hr =
|
|
|
|
device->QueryInterface(__uuidof(IDXGIDevice), getter_AddRefs(dxgiDevice));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IDXGIAdapter> dxgiAdapter;
|
|
|
|
if (FAILED(dxgiDevice->GetAdapter(getter_AddRefs(dxgiAdapter)))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SUCCEEDED(dxgiAdapter->GetDesc(out));
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void D3D11Checks::WarnOnAdapterMismatch(ID3D11Device* device) {
|
2016-07-26 23:19:48 +03:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
PodZero(&desc);
|
|
|
|
GetDxgiDesc(device, &desc);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
nsString vendorID;
|
|
|
|
gfxInfo->GetAdapterVendorID(vendorID);
|
|
|
|
nsresult ec;
|
|
|
|
int32_t vendor = vendorID.ToInteger(&ec, 16);
|
|
|
|
if (vendor != desc.VendorId) {
|
|
|
|
gfxCriticalNote << "VendorIDMismatch V " << hexa(vendor) << " "
|
|
|
|
<< hexa(desc.VendorId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
bool D3D11Checks::DoesRemotePresentWork(IDXGIAdapter* adapter) {
|
2016-10-26 04:42:20 +03:00
|
|
|
// Remote presentation was added in DXGI 1.2, for Windows 8 and the Platform
|
|
|
|
// Update to Windows 7.
|
|
|
|
RefPtr<IDXGIAdapter2> check;
|
|
|
|
HRESULT hr =
|
|
|
|
adapter->QueryInterface(__uuidof(IDXGIAdapter2), getter_AddRefs(check));
|
|
|
|
return SUCCEEDED(hr) && check;
|
|
|
|
}
|
2016-07-26 23:19:48 +03:00
|
|
|
|
2018-10-11 01:14:51 +03:00
|
|
|
/* static */ D3D11Checks::VideoFormatOptionSet D3D11Checks::FormatOptions(
|
|
|
|
ID3D11Device* device) {
|
|
|
|
auto doesNV12Work = [&]() {
|
|
|
|
if (gfxVars::DXNV12Blocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-17 06:07:20 +03:00
|
|
|
|
2018-10-11 01:14:51 +03:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
PodZero(&desc);
|
|
|
|
if (!GetDxgiDesc(device, &desc)) {
|
|
|
|
// Failed to retrieve device information, assume it doesn't work
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-10 18:54:31 +03:00
|
|
|
|
2018-10-11 01:14:51 +03:00
|
|
|
UINT formatSupport;
|
|
|
|
HRESULT hr = device->CheckFormatSupport(DXGI_FORMAT_NV12, &formatSupport);
|
|
|
|
if (FAILED(hr) || !(formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-01 12:00:09 +03:00
|
|
|
|
2018-10-11 01:14:51 +03:00
|
|
|
nsString version;
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
|
|
|
|
if (gfxInfo) {
|
|
|
|
gfxInfo->GetAdapterDriverVersion(version);
|
|
|
|
}
|
|
|
|
return DXVA2Manager::IsNV12Supported(desc.VendorId, desc.DeviceId, version);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto doesP010Work = [&]() {
|
2019-05-26 17:29:42 +03:00
|
|
|
if (gfxVars::DXP010Blocked() &&
|
|
|
|
!StaticPrefs::PDMWMFForceAllowP010Format()) {
|
2018-10-11 10:32:35 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-11 01:14:51 +03:00
|
|
|
UINT formatSupport;
|
|
|
|
HRESULT hr = device->CheckFormatSupport(DXGI_FORMAT_P010, &formatSupport);
|
|
|
|
return (SUCCEEDED(hr) && (formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D));
|
|
|
|
};
|
|
|
|
|
|
|
|
auto doesP016Work = [&]() {
|
2019-05-26 17:29:42 +03:00
|
|
|
if (gfxVars::DXP016Blocked() &&
|
|
|
|
!StaticPrefs::PDMWMFForceAllowP010Format()) {
|
2018-10-11 10:32:35 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-10-11 01:14:51 +03:00
|
|
|
UINT formatSupport;
|
|
|
|
HRESULT hr = device->CheckFormatSupport(DXGI_FORMAT_P016, &formatSupport);
|
|
|
|
return (SUCCEEDED(hr) && (formatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D));
|
|
|
|
};
|
|
|
|
|
|
|
|
VideoFormatOptionSet options;
|
|
|
|
if (!doesNV12Work()) {
|
|
|
|
// If the device doesn't support NV12, there's really no point testing for
|
|
|
|
// P010 and P016.
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
options += VideoFormatOption::NV12;
|
|
|
|
if (doesP010Work()) {
|
|
|
|
options += VideoFormatOption::P010;
|
|
|
|
}
|
|
|
|
if (doesP016Work()) {
|
|
|
|
options += VideoFormatOption::P016;
|
2017-09-10 18:54:31 +03:00
|
|
|
}
|
2018-10-11 01:14:51 +03:00
|
|
|
return options;
|
2017-09-10 18:54:31 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 23:19:48 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|