1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 07:08:50 +01:00
dxvk/src/dxgi/dxgi_factory.cpp

270 lines
8.0 KiB
C++
Raw Normal View History

2017-10-11 03:09:04 +02:00
#include "dxgi_factory.h"
#include "dxgi_swapchain.h"
namespace dxvk {
DxgiFactory::DxgiFactory()
2017-10-11 15:31:36 +02:00
: m_instance(new DxvkInstance()),
m_adapters(m_instance->enumAdapters()) {
2018-03-07 00:23:06 +01:00
for (const auto& adapter : m_adapters)
adapter->logAdapterInfo();
2017-10-11 03:09:04 +02:00
}
DxgiFactory::~DxgiFactory() {
2017-11-26 14:01:41 +01:00
2017-10-11 03:09:04 +02:00
}
HRESULT STDMETHODCALLTYPE DxgiFactory::QueryInterface(REFIID riid, void** ppvObject) {
*ppvObject = nullptr;
if (riid == __uuidof(IUnknown)
|| riid == __uuidof(IDXGIObject)
|| riid == __uuidof(IDXGIFactory)
2018-05-22 23:52:03 +02:00
|| riid == __uuidof(IDXGIFactory1)
|| riid == __uuidof(IDXGIFactory2)) {
*ppvObject = ref(this);
return S_OK;
}
2017-10-11 03:09:04 +02:00
Logger::warn("DxgiFactory::QueryInterface: Unknown interface query");
Logger::warn(str::format(riid));
2017-10-11 03:09:04 +02:00
return E_NOINTERFACE;
}
2018-04-14 12:02:55 +02:00
HRESULT STDMETHODCALLTYPE DxgiFactory::GetParent(REFIID riid, void** ppParent) {
InitReturnPtr(ppParent);
2017-10-11 03:09:04 +02:00
Logger::warn("DxgiFactory::GetParent: Unknown interface query");
return E_NOINTERFACE;
}
2018-05-22 23:52:03 +02:00
BOOL STDMETHODCALLTYPE DxgiFactory::IsWindowedStereoEnabled() {
// We don't support Stereo 3D at the moment
return FALSE;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSoftwareAdapter(
2017-10-11 03:09:04 +02:00
HMODULE Module,
IDXGIAdapter** ppAdapter) {
InitReturnPtr(ppAdapter);
if (ppAdapter == nullptr)
return DXGI_ERROR_INVALID_CALL;
2018-04-14 12:02:55 +02:00
Logger::err("DXGI: CreateSoftwareAdapter: Software adapters not supported");
2017-10-11 03:09:04 +02:00
return DXGI_ERROR_UNSUPPORTED;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSwapChain(
2017-10-11 03:09:04 +02:00
IUnknown* pDevice,
DXGI_SWAP_CHAIN_DESC* pDesc,
IDXGISwapChain** ppSwapChain) {
2018-05-23 01:06:34 +02:00
if (ppSwapChain == nullptr || pDesc == nullptr || pDevice == nullptr)
return DXGI_ERROR_INVALID_CALL;
2018-05-23 01:06:34 +02:00
DXGI_SWAP_CHAIN_DESC1 desc;
desc.Width = pDesc->BufferDesc.Width;
desc.Height = pDesc->BufferDesc.Height;
desc.Format = pDesc->BufferDesc.Format;
desc.Stereo = FALSE;
desc.SampleDesc = pDesc->SampleDesc;
desc.BufferUsage = pDesc->BufferUsage;
desc.BufferCount = pDesc->BufferCount;
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = pDesc->SwapEffect;
desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
desc.Flags = pDesc->Flags;
2017-10-11 16:22:13 +02:00
2018-05-23 01:06:34 +02:00
DXGI_SWAP_CHAIN_FULLSCREEN_DESC descFs;
descFs.RefreshRate = pDesc->BufferDesc.RefreshRate;
descFs.ScanlineOrdering = pDesc->BufferDesc.ScanlineOrdering;
descFs.Scaling = pDesc->BufferDesc.Scaling;
descFs.Windowed = pDesc->Windowed;
IDXGISwapChain1* swapChain = nullptr;
HRESULT hr = CreateSwapChainForHwnd(
pDevice, pDesc->OutputWindow,
&desc, &descFs, nullptr,
&swapChain);
*ppSwapChain = swapChain;
return hr;
2017-10-11 03:09:04 +02:00
}
2018-05-22 23:52:03 +02:00
HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSwapChainForHwnd(
IUnknown* pDevice,
HWND hWnd,
const DXGI_SWAP_CHAIN_DESC1* pDesc,
const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc,
IDXGIOutput* pRestrictToOutput,
IDXGISwapChain1** ppSwapChain) {
InitReturnPtr(ppSwapChain);
2018-05-23 01:06:34 +02:00
if (ppSwapChain == nullptr || pDesc == nullptr || hWnd == nullptr || pDevice == nullptr)
return DXGI_ERROR_INVALID_CALL;
// If necessary, set up a default set of
// fullscreen parameters for the swap chain
DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreenDesc;
if (pFullscreenDesc != nullptr) {
fullscreenDesc = *pFullscreenDesc;
} else {
fullscreenDesc.RefreshRate = { 0, 0 };
fullscreenDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
fullscreenDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
fullscreenDesc.Windowed = TRUE;
}
try {
*ppSwapChain = ref(new DxgiSwapChain(this,
pDevice, hWnd, pDesc, &fullscreenDesc));
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
return E_FAIL;
}
2018-05-22 23:52:03 +02:00
}
HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSwapChainForCoreWindow(
IUnknown* pDevice,
IUnknown* pWindow,
const DXGI_SWAP_CHAIN_DESC1* pDesc,
IDXGIOutput* pRestrictToOutput,
IDXGISwapChain1** ppSwapChain) {
InitReturnPtr(ppSwapChain);
Logger::err("DxgiFactory::CreateSwapChainForCoreWindow: Not implemented");
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSwapChainForComposition(
IUnknown* pDevice,
const DXGI_SWAP_CHAIN_DESC1* pDesc,
IDXGIOutput* pRestrictToOutput,
IDXGISwapChain1** ppSwapChain) {
InitReturnPtr(ppSwapChain);
Logger::err("DxgiFactory::CreateSwapChainForComposition: Not implemented");
return E_NOTIMPL;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::EnumAdapters(
2017-10-11 03:09:04 +02:00
UINT Adapter,
IDXGIAdapter** ppAdapter) {
InitReturnPtr(ppAdapter);
2017-10-11 03:09:04 +02:00
if (ppAdapter == nullptr)
return DXGI_ERROR_INVALID_CALL;
IDXGIAdapter1* handle = nullptr;
HRESULT hr = this->EnumAdapters1(Adapter, &handle);
*ppAdapter = handle;
return hr;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::EnumAdapters1(
UINT Adapter,
IDXGIAdapter1** ppAdapter) {
InitReturnPtr(ppAdapter);
if (ppAdapter == nullptr)
return DXGI_ERROR_INVALID_CALL;
if (Adapter >= m_adapters.size())
2017-10-11 03:09:04 +02:00
return DXGI_ERROR_NOT_FOUND;
2017-10-11 15:31:36 +02:00
*ppAdapter = ref(new DxgiAdapter(
this, m_adapters.at(Adapter)));
2017-10-11 03:09:04 +02:00
return S_OK;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::GetWindowAssociation(HWND *pWindowHandle) {
2017-10-11 03:09:04 +02:00
if (pWindowHandle == nullptr)
return DXGI_ERROR_INVALID_CALL;
*pWindowHandle = m_associatedWindow;
return S_OK;
}
2018-05-22 23:52:03 +02:00
HRESULT STDMETHODCALLTYPE DxgiFactory::GetSharedResourceAdapterLuid(
HANDLE hResource,
LUID* pLuid) {
Logger::err("DxgiFactory::GetSharedResourceAdapterLuid: Not implemented");
return E_NOTIMPL;
}
2017-12-12 12:50:52 +01:00
HRESULT STDMETHODCALLTYPE DxgiFactory::MakeWindowAssociation(HWND WindowHandle, UINT Flags) {
2018-04-14 12:02:55 +02:00
Logger::warn("DXGI: MakeWindowAssociation: Ignoring flags");
2017-10-11 03:09:04 +02:00
m_associatedWindow = WindowHandle;
return S_OK;
}
2017-12-12 12:50:52 +01:00
BOOL STDMETHODCALLTYPE DxgiFactory::IsCurrent() {
Logger::warn("DxgiFactory::IsCurrent: Stub");
return TRUE;
}
2018-05-22 23:52:03 +02:00
HRESULT STDMETHODCALLTYPE DxgiFactory::RegisterOcclusionStatusWindow(
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie) {
Logger::err("DxgiFactory::RegisterOcclusionStatusWindow: Not implemented");
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE DxgiFactory::RegisterStereoStatusEvent(
HANDLE hEvent,
DWORD* pdwCookie) {
Logger::err("DxgiFactory::RegisterStereoStatusEvent: Not implemented");
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE DxgiFactory::RegisterStereoStatusWindow(
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie) {
Logger::err("DxgiFactory::RegisterStereoStatusWindow: Not implemented");
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE DxgiFactory::RegisterOcclusionStatusEvent(
HANDLE hEvent,
DWORD* pdwCookie) {
Logger::err("DxgiFactory::RegisterOcclusionStatusEvent: Not implemented");
return E_NOTIMPL;
}
void STDMETHODCALLTYPE DxgiFactory::UnregisterStereoStatus(
DWORD dwCookie) {
Logger::err("DxgiFactory::UnregisterStereoStatus: Not implemented");
}
void STDMETHODCALLTYPE DxgiFactory::UnregisterOcclusionStatus(
DWORD dwCookie) {
Logger::err("DxgiFactory::UnregisterOcclusionStatus: Not implemented");
}
2017-10-11 03:09:04 +02:00
}