summaryrefslogtreecommitdiffstats
path: root/drivers/d3d12/rendering_context_driver_d3d12.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/d3d12/rendering_context_driver_d3d12.cpp')
-rw-r--r--drivers/d3d12/rendering_context_driver_d3d12.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/drivers/d3d12/rendering_context_driver_d3d12.cpp b/drivers/d3d12/rendering_context_driver_d3d12.cpp
index ad3b793305..726be064bd 100644
--- a/drivers/d3d12/rendering_context_driver_d3d12.cpp
+++ b/drivers/d3d12/rendering_context_driver_d3d12.cpp
@@ -58,9 +58,10 @@
#endif
// Note: symbols are not available in MinGW and old MSVC import libraries.
-const CLSID CLSID_D3D12DeviceFactoryGodot = __uuidof(ID3D12DeviceFactory);
-const CLSID CLSID_D3D12DebugGodot = __uuidof(ID3D12Debug);
-const CLSID CLSID_D3D12SDKConfigurationGodot = __uuidof(ID3D12SDKConfiguration);
+// GUID values from https://github.com/microsoft/DirectX-Headers/blob/7a9f4d06911d30eecb56a4956dab29dcca2709ed/include/directx/d3d12.idl#L5877-L5881
+const GUID CLSID_D3D12DeviceFactoryGodot = { 0x114863bf, 0xc386, 0x4aee, { 0xb3, 0x9d, 0x8f, 0x0b, 0xbb, 0x06, 0x29, 0x55 } };
+const GUID CLSID_D3D12DebugGodot = { 0xf2352aeb, 0xdd84, 0x49fe, { 0xb9, 0x7b, 0xa9, 0xdc, 0xfd, 0xcc, 0x1b, 0x4f } };
+const GUID CLSID_D3D12SDKConfigurationGodot = { 0x7cda6aca, 0xa03e, 0x49c8, { 0x94, 0x58, 0x03, 0x34, 0xd2, 0x0e, 0x07, 0xce } };
extern "C" {
char godot_nir_arch_name[32];
@@ -83,17 +84,28 @@ RenderingContextDriverD3D12::RenderingContextDriverD3D12() {
}
RenderingContextDriverD3D12::~RenderingContextDriverD3D12() {
+ if (lib_d3d12) {
+ FreeLibrary(lib_d3d12);
+ }
+ if (lib_dxgi) {
+ FreeLibrary(lib_dxgi);
+ }
}
Error RenderingContextDriverD3D12::_init_device_factory() {
uint32_t agility_sdk_version = GLOBAL_GET("rendering/rendering_device/d3d12/agility_sdk_version");
String agility_sdk_path = String(".\\") + Engine::get_singleton()->get_architecture_name();
+ lib_d3d12 = LoadLibraryW(L"D3D12.dll");
+ ERR_FAIL_NULL_V(lib_d3d12, ERR_CANT_CREATE);
+
+ lib_dxgi = LoadLibraryW(L"DXGI.dll");
+ ERR_FAIL_NULL_V(lib_dxgi, ERR_CANT_CREATE);
+
// Note: symbol is not available in MinGW import library.
- PFN_D3D12_GET_INTERFACE d3d_D3D12GetInterface = (PFN_D3D12_GET_INTERFACE)GetProcAddress(LoadLibraryW(L"D3D12.dll"), "D3D12GetInterface");
- if (d3d_D3D12GetInterface == nullptr) {
- // FIXME: Is it intended for this to silently return when it fails to find the symbol?
- return OK;
+ PFN_D3D12_GET_INTERFACE d3d_D3D12GetInterface = (PFN_D3D12_GET_INTERFACE)(void *)GetProcAddress(lib_d3d12, "D3D12GetInterface");
+ if (!d3d_D3D12GetInterface) {
+ return OK; // Fallback to the system loader.
}
ID3D12SDKConfiguration *sdk_config = nullptr;
@@ -109,18 +121,22 @@ Error RenderingContextDriverD3D12::_init_device_factory() {
}
sdk_config->Release();
}
-
return OK;
}
Error RenderingContextDriverD3D12::_initialize_debug_layers() {
ComPtr<ID3D12Debug> debug_controller;
HRESULT res;
+
if (device_factory) {
res = device_factory->GetConfigurationInterface(CLSID_D3D12DebugGodot, IID_PPV_ARGS(&debug_controller));
} else {
- res = D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller));
+ PFN_D3D12_GET_DEBUG_INTERFACE d3d_D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)(void *)GetProcAddress(lib_d3d12, "D3D12GetDebugInterface");
+ ERR_FAIL_NULL_V(d3d_D3D12GetDebugInterface, ERR_CANT_CREATE);
+
+ res = d3d_D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller));
}
+
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_QUERY_FAILED);
debug_controller->EnableDebugLayer();
return OK;
@@ -128,7 +144,12 @@ Error RenderingContextDriverD3D12::_initialize_debug_layers() {
Error RenderingContextDriverD3D12::_initialize_devices() {
const UINT dxgi_factory_flags = use_validation_layers() ? DXGI_CREATE_FACTORY_DEBUG : 0;
- HRESULT res = CreateDXGIFactory2(dxgi_factory_flags, IID_PPV_ARGS(&dxgi_factory));
+
+ typedef HRESULT(WINAPI * PFN_DXGI_CREATE_DXGI_FACTORY2)(UINT, REFIID, void **);
+ PFN_DXGI_CREATE_DXGI_FACTORY2 dxgi_CreateDXGIFactory2 = (PFN_DXGI_CREATE_DXGI_FACTORY2)(void *)GetProcAddress(lib_dxgi, "CreateDXGIFactory2");
+ ERR_FAIL_NULL_V(dxgi_CreateDXGIFactory2, ERR_CANT_CREATE);
+
+ HRESULT res = dxgi_CreateDXGIFactory2(dxgi_factory_flags, IID_PPV_ARGS(&dxgi_factory));
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE);
// Enumerate all possible adapters.