From dfa303f7c450868ecb2a379c09d23dffffc5ca20 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 26 Jan 2024 19:02:06 +0200 Subject: [PATCH] [D3D12] Add support for building with pre-11.0.0 MinGW versions, make PIX runtime opt-in. --- drivers/d3d12/SCsub | 2 +- drivers/d3d12/d3d12_context.cpp | 6 ++++-- platform/windows/SCsub | 4 ++-- platform/windows/detect.py | 29 ++++++++++++++++++----------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/d3d12/SCsub b/drivers/d3d12/SCsub index 6b23e1bad05..35227ebe08b 100644 --- a/drivers/d3d12/SCsub +++ b/drivers/d3d12/SCsub @@ -33,7 +33,7 @@ if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]): # PIX. -if env["pix_path"] != "" and os.path.exists(env["pix_path"]): +if env["use_pix"]: env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"]) env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"]) diff --git a/drivers/d3d12/d3d12_context.cpp b/drivers/d3d12/d3d12_context.cpp index 0ba3f591198..03bde5b2d96 100644 --- a/drivers/d3d12/d3d12_context.cpp +++ b/drivers/d3d12/d3d12_context.cpp @@ -59,6 +59,8 @@ // Note: symbol is 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); extern "C" { char godot_nir_arch_name[32]; @@ -285,7 +287,7 @@ Error D3D12Context::_initialize_debug_layers() { ComPtr debug_controller; HRESULT res; if (device_factory) { - res = device_factory->GetConfigurationInterface(CLSID_D3D12Debug, IID_PPV_ARGS(&debug_controller)); + res = device_factory->GetConfigurationInterface(CLSID_D3D12DebugGodot, IID_PPV_ARGS(&debug_controller)); } else { res = D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller)); } @@ -820,7 +822,7 @@ void D3D12Context::_init_device_factory() { ERR_FAIL_COND(!d3d_D3D12GetInterface); ID3D12SDKConfiguration *sdk_config = nullptr; - if (SUCCEEDED(d3d_D3D12GetInterface(CLSID_D3D12SDKConfiguration, IID_PPV_ARGS(&sdk_config)))) { + if (SUCCEEDED(d3d_D3D12GetInterface(CLSID_D3D12SDKConfigurationGodot, IID_PPV_ARGS(&sdk_config)))) { ID3D12SDKConfiguration1 *sdk_config1 = nullptr; if (SUCCEEDED(sdk_config->QueryInterface(&sdk_config1))) { if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, agility_sdk_path.ascii().get_data(), IID_PPV_ARGS(device_factory.GetAddressOf())))) { diff --git a/platform/windows/SCsub b/platform/windows/SCsub index 2df644136b3..7aaf70e6256 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -97,7 +97,7 @@ if env["d3d12"]: arch_bin_dir = "#bin/" + env["arch"] # DXC - if env["dxc_path"] != "": + if env["dxc_path"] != "" and os.path.exists(env["dxc_path"]): dxc_dll = "dxil.dll" # Whether this one is loaded from arch-specific directory or not can be determined at runtime. # Let's copy to both and let the user decide the distribution model. @@ -121,7 +121,7 @@ if env["d3d12"]: ) # PIX - if env["pix_path"] != "" and os.path.exists(env["pix_path"]): + if env["use_pix"]: pix_dll = "WinPixEventRuntime.dll" env.Command( "#bin/" + pix_dll, diff --git a/platform/windows/detect.py b/platform/windows/detect.py index b1dd66ca487..e5e0a07f82c 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -224,6 +224,7 @@ def get_opts(): "Whether the Agility SDK DLLs will be stored in arch-specific subdirectories", False, ), + BoolVariable("use_pix", "Use PIX (Performance tuning and debugging for DirectX 12) runtime", False), ( "pix_path", "Path to the PIX runtime distribution (optional for D3D12)", @@ -474,7 +475,7 @@ def configure_msvc(env, vcvars_msvc_config): if env["d3d12"]: # Check whether we have d3d12 dependencies installed. - if not os.path.exists(env["mesa_libs"]) or not os.path.exists(env["dxc_path"]): + if not os.path.exists(env["mesa_libs"]): print("The Direct3D 12 rendering driver requires dependencies to be installed.") print("You can install them by running `python misc\scripts\install_d3d12_sdk_windows.py`.") print("See the documentation for more information:") @@ -491,10 +492,13 @@ def configure_msvc(env, vcvars_msvc_config): if env["target"] == "release_debug": env.Append(CXXFLAGS=["/bigobj"]) - arch_subdir = "arm64" if env["arch"] == "arm64" else "x64" - # PIX - if env["pix_path"] != "" and os.path.exists(env["pix_path"]): + if not env["arch"] in ["x86_64", "arm64"] or env["pix_path"] == "" or not os.path.exists(env["pix_path"]): + env["use_pix"] = False + + if env["use_pix"]: + arch_subdir = "arm64" if env["arch"] == "arm64" else "x64" + env.Append(LIBPATH=[env["pix_path"] + "/bin/" + arch_subdir]) LIBS += ["WinPixEventRuntime"] @@ -695,13 +699,8 @@ def configure_mingw(env): env.Append(LIBS=["vulkan"]) if env["d3d12"]: - env.AppendUnique(CPPDEFINES=["D3D12_ENABLED", "RD_ENABLED"]) - env.Append(LIBS=["d3d12", "dxgi", "dxguid"]) - - arch_subdir = "arm64" if env["arch"] == "arm64" else "x64" - # Check whether we have d3d12 dependencies installed. - if not os.path.exists(env["mesa_libs"]) or not os.path.exists(env["dxc_path"]): + if not os.path.exists(env["mesa_libs"]): print("The Direct3D 12 rendering driver requires dependencies to be installed.") print("You can install them by running `python misc\scripts\install_d3d12_sdk_windows.py`.") print("See the documentation for more information:") @@ -710,8 +709,16 @@ def configure_mingw(env): ) sys.exit(255) + env.AppendUnique(CPPDEFINES=["D3D12_ENABLED", "RD_ENABLED"]) + env.Append(LIBS=["d3d12", "dxgi", "dxguid"]) + # PIX - if env["pix_path"] != "" and os.path.exists(env["pix_path"]): + if not env["arch"] in ["x86_64", "arm64"] or env["pix_path"] == "" or not os.path.exists(env["pix_path"]): + env["use_pix"] = False + + if env["use_pix"]: + arch_subdir = "arm64" if env["arch"] == "arm64" else "x64" + env.Append(LIBPATH=[env["pix_path"] + "/bin/" + arch_subdir]) env.Append(LIBS=["WinPixEventRuntime"])