mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-19 00:20:12 +00:00
D3DCommon: Load dxgi.lib dynamically
This commit is contained in:
parent
0195b2886e
commit
4ead72747b
@ -241,7 +241,7 @@ if(WIN32)
|
|||||||
xinput_source.h
|
xinput_source.h
|
||||||
)
|
)
|
||||||
target_link_libraries(util PRIVATE d3d12ma)
|
target_link_libraries(util PRIVATE d3d12ma)
|
||||||
target_link_libraries(util PRIVATE d3d12.lib dxgi.lib winmm.lib Dwmapi.lib winhttp.lib)
|
target_link_libraries(util PRIVATE d3d12.lib winmm.lib Dwmapi.lib winhttp.lib)
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE MATCHES "Debug|Devel")
|
if(CMAKE_BUILD_TYPE MATCHES "Debug|Devel")
|
||||||
target_link_libraries(util PRIVATE WinPixEventRuntime::WinPixEventRuntime)
|
target_link_libraries(util PRIVATE WinPixEventRuntime::WinPixEventRuntime)
|
||||||
|
@ -35,6 +35,8 @@ struct FeatureLevelTableEntry
|
|||||||
struct Libs
|
struct Libs
|
||||||
{
|
{
|
||||||
std::mutex load_mutex;
|
std::mutex load_mutex;
|
||||||
|
DynamicLibrary dxgi_library;
|
||||||
|
decltype(&CreateDXGIFactory2) CreateDXGIFactory2;
|
||||||
DynamicLibrary d3d11_library;
|
DynamicLibrary d3d11_library;
|
||||||
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice;
|
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice;
|
||||||
DynamicLibrary d3dcompiler_library;
|
DynamicLibrary d3dcompiler_library;
|
||||||
@ -127,12 +129,30 @@ D3D_FEATURE_LEVEL D3DCommon::GetDeviceMaxFeatureLevel(IDXGIAdapter1* adapter)
|
|||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIFactory5> D3DCommon::CreateFactory(bool debug, Error* error)
|
Microsoft::WRL::ComPtr<IDXGIFactory5> D3DCommon::CreateFactory(bool debug, Error* error)
|
||||||
{
|
{
|
||||||
|
if (!s_libs.dxgi_library.IsOpen())
|
||||||
|
{
|
||||||
|
// another thread may have opened it
|
||||||
|
const std::unique_lock lock(s_libs.load_mutex);
|
||||||
|
if (!s_libs.d3d11_library.IsOpen())
|
||||||
|
{
|
||||||
|
if (!s_libs.dxgi_library.Open("dxgi.dll", error))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (!s_libs.dxgi_library.GetSymbol("CreateDXGIFactory2", &s_libs.CreateDXGIFactory2))
|
||||||
|
{
|
||||||
|
Error::SetStringView(error, "Failed to load CreateDXGIFactory2 from dxgi.dll");
|
||||||
|
s_libs.dxgi_library.Close();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UINT flags = 0;
|
UINT flags = 0;
|
||||||
if (debug)
|
if (debug)
|
||||||
flags |= DXGI_CREATE_FACTORY_DEBUG;
|
flags |= DXGI_CREATE_FACTORY_DEBUG;
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIFactory5> factory;
|
Microsoft::WRL::ComPtr<IDXGIFactory5> factory;
|
||||||
const HRESULT hr = CreateDXGIFactory2(flags, IID_PPV_ARGS(factory.GetAddressOf()));
|
const HRESULT hr = s_libs.CreateDXGIFactory2(flags, IID_PPV_ARGS(factory.GetAddressOf()));
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
Error::SetHResult(error, "Failed to create DXGI factory: ", hr);
|
Error::SetHResult(error, "Failed to create DXGI factory: ", hr);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>%(AdditionalDependencies);d3d12.lib;dxgi.lib;Dwmapi.lib;winhttp.lib</AdditionalDependencies>
|
<AdditionalDependencies>%(AdditionalDependencies);d3d12.lib;Dwmapi.lib;winhttp.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user