From 890a32bd98c05e77c9134370ae3c988bcbde4ecb Mon Sep 17 00:00:00 2001 From: Triang3l Date: Sat, 3 Aug 2019 22:33:09 +0300 Subject: [PATCH] [App] Only start D3D12 if DLL exists --- src/xenia/app/xenia_main.cc | 10 ++++++---- src/xenia/gpu/d3d12/d3d12_graphics_system.cc | 4 ++++ src/xenia/gpu/d3d12/d3d12_graphics_system.h | 2 ++ src/xenia/ui/d3d12/d3d12_provider.cc | 10 ++++++++++ src/xenia/ui/d3d12/d3d12_provider.h | 2 ++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/xenia/app/xenia_main.cc b/src/xenia/app/xenia_main.cc index 887f1cb4f..7e779b460 100644 --- a/src/xenia/app/xenia_main.cc +++ b/src/xenia/app/xenia_main.cc @@ -105,10 +105,12 @@ std::unique_ptr CreateGraphicsSystem() { std::unique_ptr best; #if XE_PLATFORM_WIN32 - best = std::unique_ptr( - new xe::gpu::d3d12::D3D12GraphicsSystem()); - if (best) { - return best; + if (xe::gpu::d3d12::D3D12GraphicsSystem::IsD3D12APIAvailable()) { + best = std::unique_ptr( + new xe::gpu::d3d12::D3D12GraphicsSystem()); + if (best) { + return best; + } } #endif // XE_PLATFORM_WIN32 best = std::unique_ptr( diff --git a/src/xenia/gpu/d3d12/d3d12_graphics_system.cc b/src/xenia/gpu/d3d12/d3d12_graphics_system.cc index ef425a12f..87fa23445 100644 --- a/src/xenia/gpu/d3d12/d3d12_graphics_system.cc +++ b/src/xenia/gpu/d3d12/d3d12_graphics_system.cc @@ -27,6 +27,10 @@ D3D12GraphicsSystem::D3D12GraphicsSystem() {} D3D12GraphicsSystem::~D3D12GraphicsSystem() {} +bool D3D12GraphicsSystem::IsD3D12APIAvailable() { + return xe::ui::d3d12::D3D12Provider::IsD3D12APIAvailable(); +} + std::wstring D3D12GraphicsSystem::name() const { auto d3d12_command_processor = static_cast(command_processor()); diff --git a/src/xenia/gpu/d3d12/d3d12_graphics_system.h b/src/xenia/gpu/d3d12/d3d12_graphics_system.h index 47ea9a71d..812d63126 100644 --- a/src/xenia/gpu/d3d12/d3d12_graphics_system.h +++ b/src/xenia/gpu/d3d12/d3d12_graphics_system.h @@ -26,6 +26,8 @@ class D3D12GraphicsSystem : public GraphicsSystem { D3D12GraphicsSystem(); ~D3D12GraphicsSystem() override; + static bool IsD3D12APIAvailable(); + std::wstring name() const override; X_STATUS Setup(cpu::Processor* processor, kernel::KernelState* kernel_state, diff --git a/src/xenia/ui/d3d12/d3d12_provider.cc b/src/xenia/ui/d3d12/d3d12_provider.cc index 7031f4fb1..5779b7dd2 100644 --- a/src/xenia/ui/d3d12/d3d12_provider.cc +++ b/src/xenia/ui/d3d12/d3d12_provider.cc @@ -27,6 +27,15 @@ namespace xe { namespace ui { namespace d3d12 { +bool D3D12Provider::IsD3D12APIAvailable() { + HMODULE library_d3d12 = LoadLibrary(L"D3D12.dll"); + if (!library_d3d12) { + return false; + } + FreeLibrary(library_d3d12); + return true; +} + std::unique_ptr D3D12Provider::Create(Window* main_window) { std::unique_ptr provider(new D3D12Provider(main_window)); InitializationResult result = provider->Initialize(); @@ -81,6 +90,7 @@ D3D12Provider::InitializationResult D3D12Provider::Initialize() { library_d3dcompiler_ = LoadLibrary(L"D3DCompiler_47.dll"); if (library_dxgi_ == nullptr || library_d3d12_ == nullptr || library_d3dcompiler_ == nullptr) { + XELOGE("Failed to load dxgi.dll, D3D12.dll and D3DCompiler_47.dll."); return InitializationResult::kLibraryLoadFailed; } bool libraries_loaded = true; diff --git a/src/xenia/ui/d3d12/d3d12_provider.h b/src/xenia/ui/d3d12/d3d12_provider.h index 861405f38..b527189c0 100644 --- a/src/xenia/ui/d3d12/d3d12_provider.h +++ b/src/xenia/ui/d3d12/d3d12_provider.h @@ -23,6 +23,8 @@ class D3D12Provider : public GraphicsProvider { public: ~D3D12Provider() override; + static bool IsD3D12APIAvailable(); + static std::unique_ptr Create(Window* main_window); std::unique_ptr CreateContext(