D3DBase: Upgrade to DXGI 1.2.

This effectively drops for Vista and Windows 7 without the Platform Update in this backend.
This commit is contained in:
Jules Blok 2017-06-25 20:57:46 +02:00
parent 421a2c5776
commit c399e2bc40
2 changed files with 27 additions and 72 deletions

View File

@ -26,13 +26,7 @@ CREATEDXGIFACTORY PCreateDXGIFactory = nullptr;
HINSTANCE hDXGIDll = nullptr; HINSTANCE hDXGIDll = nullptr;
int dxgi_dll_ref = 0; int dxgi_dll_ref = 0;
typedef HRESULT(WINAPI* D3D11CREATEDEVICEANDSWAPCHAIN)(IDXGIAdapter*, D3D_DRIVER_TYPE, HMODULE,
UINT, CONST D3D_FEATURE_LEVEL*, UINT, UINT,
CONST DXGI_SWAP_CHAIN_DESC*,
IDXGISwapChain**, ID3D11Device**,
D3D_FEATURE_LEVEL*, ID3D11DeviceContext**);
static D3D11CREATEDEVICE PD3D11CreateDevice = nullptr; static D3D11CREATEDEVICE PD3D11CreateDevice = nullptr;
D3D11CREATEDEVICEANDSWAPCHAIN PD3D11CreateDeviceAndSwapChain = nullptr;
HINSTANCE hD3DDll = nullptr; HINSTANCE hD3DDll = nullptr;
int d3d_dll_ref = 0; int d3d_dll_ref = 0;
@ -40,7 +34,7 @@ namespace D3D
{ {
ID3D11Device* device = nullptr; ID3D11Device* device = nullptr;
ID3D11DeviceContext* context = nullptr; ID3D11DeviceContext* context = nullptr;
static IDXGISwapChain* swapchain = nullptr; static IDXGISwapChain1* swapchain = nullptr;
static ID3D11Debug* debug = nullptr; static ID3D11Debug* debug = nullptr;
D3D_FEATURE_LEVEL featlevel; D3D_FEATURE_LEVEL featlevel;
D3DTexture2D* backbuf = nullptr; D3DTexture2D* backbuf = nullptr;
@ -99,12 +93,6 @@ HRESULT LoadD3D()
MessageBoxA(nullptr, "GetProcAddress failed for D3D11CreateDevice!", "Critical error", MessageBoxA(nullptr, "GetProcAddress failed for D3D11CreateDevice!", "Critical error",
MB_OK | MB_ICONERROR); MB_OK | MB_ICONERROR);
PD3D11CreateDeviceAndSwapChain =
(D3D11CREATEDEVICEANDSWAPCHAIN)GetProcAddress(hD3DDll, "D3D11CreateDeviceAndSwapChain");
if (PD3D11CreateDeviceAndSwapChain == nullptr)
MessageBoxA(nullptr, "GetProcAddress failed for D3D11CreateDeviceAndSwapChain!",
"Critical error", MB_OK | MB_ICONERROR);
return S_OK; return S_OK;
} }
@ -172,7 +160,6 @@ void UnloadD3D()
FreeLibrary(hD3DDll); FreeLibrary(hD3DDll);
hD3DDll = nullptr; hD3DDll = nullptr;
PD3D11CreateDevice = nullptr; PD3D11CreateDevice = nullptr;
PD3D11CreateDeviceAndSwapChain = nullptr;
} }
void UnloadD3DCompiler() void UnloadD3DCompiler()
@ -276,14 +263,13 @@ HRESULT Create(HWND wnd)
return hr; return hr;
} }
IDXGIFactory* factory; IDXGIFactory2* factory;
IDXGIAdapter* adapter;
IDXGIOutput* output;
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(hr)) if (FAILED(hr))
MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 backend"), MessageBox(wnd, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 backend"),
MB_OK | MB_ICONERROR); MB_OK | MB_ICONERROR);
IDXGIAdapter* adapter;
hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter); hr = factory->EnumAdapters(g_ActiveConfig.iAdapter, &adapter);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -294,25 +280,6 @@ HRESULT Create(HWND wnd)
MB_OK | MB_ICONERROR); MB_OK | MB_ICONERROR);
} }
// TODO: Make this configurable
hr = adapter->EnumOutputs(0, &output);
if (FAILED(hr))
{
// try using the first one
IDXGIAdapter* firstadapter;
hr = factory->EnumAdapters(0, &firstadapter);
if (!FAILED(hr))
hr = firstadapter->EnumOutputs(0, &output);
if (FAILED(hr))
MessageBox(wnd, _T("Failed to enumerate outputs!\n")
_T("This usually happens when you've set your video adapter to the Nvidia ")
_T("GPU in an Optimus-equipped system.\n")
_T("Set Dolphin to use the high-performance graphics in Nvidia's drivers ")
_T("instead and leave Dolphin's video adapter set to the Intel GPU."),
_T("Dolphin Direct3D 11 backend"), MB_OK | MB_ICONERROR);
SAFE_RELEASE(firstadapter);
}
// get supported AA modes // get supported AA modes
aa_modes = EnumAAModes(adapter); aa_modes = EnumAAModes(adapter);
@ -324,45 +291,30 @@ HRESULT Create(HWND wnd)
UpdateActiveConfig(); UpdateActiveConfig();
} }
DXGI_SWAP_CHAIN_DESC swap_chain_desc = {}; DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = {};
swap_chain_desc.BufferCount = 1; swap_chain_desc.BufferCount = 1;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.OutputWindow = wnd;
swap_chain_desc.SampleDesc.Count = 1; swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0; swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.Windowed = swap_chain_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
!SConfig::GetInstance().bFullscreen || g_ActiveConfig.bBorderlessFullscreen; swap_chain_desc.Scaling = DXGI_SCALING_STRETCH;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
DXGI_OUTPUT_DESC out_desc = {}; swap_chain_desc.Width = xres;
output->GetDesc(&out_desc); swap_chain_desc.Height = yres;
DXGI_MODE_DESC mode_desc = {};
mode_desc.Width = out_desc.DesktopCoordinates.right - out_desc.DesktopCoordinates.left;
mode_desc.Height = out_desc.DesktopCoordinates.bottom - out_desc.DesktopCoordinates.top;
mode_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
mode_desc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
hr = output->FindClosestMatchingMode(&mode_desc, &swap_chain_desc.BufferDesc, nullptr);
if (FAILED(hr))
MessageBox(wnd, _T("Failed to find a supported video mode"), _T("Dolphin Direct3D 11 backend"),
MB_OK | MB_ICONERROR);
if (swap_chain_desc.Windowed)
{
// forcing buffer resolution to xres and yres..
// this is not a problem as long as we're in windowed mode
swap_chain_desc.BufferDesc.Width = xres;
swap_chain_desc.BufferDesc.Height = yres;
}
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
// Creating debug devices can sometimes fail if the user doesn't have the correct // Creating debug devices can sometimes fail if the user doesn't have the correct
// version of the DirectX SDK. If it does, simply fallback to a non-debug device. // version of the DirectX SDK. If it does, simply fallback to a non-debug device.
{ {
hr = PD3D11CreateDeviceAndSwapChain( hr = PD3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_DEBUG,
D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_DEBUG, supported_feature_levels, supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS,
NUM_SUPPORTED_FEATURE_LEVELS, D3D11_SDK_VERSION, &swap_chain_desc, &swapchain, &device, D3D11_SDK_VERSION, &device, &featlevel, &context);
&featlevel, &context);
if (SUCCEEDED(hr))
hr = factory->CreateSwapChainForHwnd(device, hWnd, &swap_chain_desc, nullptr, nullptr,
&swapchain);
// Debugbreak on D3D error // Debugbreak on D3D error
if (SUCCEEDED(hr) && SUCCEEDED(device->QueryInterface(__uuidof(ID3D11Debug), (void**)&debug))) if (SUCCEEDED(hr) && SUCCEEDED(device->QueryInterface(__uuidof(ID3D11Debug), (void**)&debug)))
{ {
@ -386,10 +338,14 @@ HRESULT Create(HWND wnd)
if (FAILED(hr)) if (FAILED(hr))
#endif #endif
{ {
hr = PD3D11CreateDeviceAndSwapChain( hr = PD3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_SINGLETHREADED, D3D11_CREATE_DEVICE_SINGLETHREADED, supported_feature_levels,
supported_feature_levels, NUM_SUPPORTED_FEATURE_LEVELS, D3D11_SDK_VERSION, &swap_chain_desc, NUM_SUPPORTED_FEATURE_LEVELS, D3D11_SDK_VERSION, &device, &featlevel,
&swapchain, &device, &featlevel, &context); &context);
if (SUCCEEDED(hr))
hr = factory->CreateSwapChainForHwnd(device, hWnd, &swap_chain_desc, nullptr, nullptr,
&swapchain);
} }
if (FAILED(hr)) if (FAILED(hr))
@ -414,7 +370,6 @@ HRESULT Create(HWND wnd)
SetDebugObjectName((ID3D11DeviceChild*)context, "device context"); SetDebugObjectName((ID3D11DeviceChild*)context, "device context");
SAFE_RELEASE(factory); SAFE_RELEASE(factory);
SAFE_RELEASE(output);
SAFE_RELEASE(adapter); SAFE_RELEASE(adapter);
ID3D11Texture2D* buf; ID3D11Texture2D* buf;

View File

@ -6,7 +6,7 @@
#include <d3d11.h> #include <d3d11.h>
#include <d3dcompiler.h> #include <d3dcompiler.h>
#include <dxgi.h> #include <dxgi1_2.h>
#include <vector> #include <vector>
#include "Common/Common.h" #include "Common/Common.h"