[D3D12] Add support for building with pre-11.0.0 MinGW versions, make PIX runtime opt-in.

This commit is contained in:
bruvzg 2024-01-26 19:02:06 +02:00
parent 17e7f85c06
commit dfa303f7c4
No known key found for this signature in database
GPG key ID: 7960FCF39844EC38
4 changed files with 25 additions and 16 deletions

View file

@ -33,7 +33,7 @@ if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
# PIX. # 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(CPPDEFINES=["PIX_ENABLED"])
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"]) env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])

View file

@ -59,6 +59,8 @@
// Note: symbol is not available in MinGW and old MSVC import libraries. // Note: symbol is not available in MinGW and old MSVC import libraries.
const CLSID CLSID_D3D12DeviceFactoryGodot = __uuidof(ID3D12DeviceFactory); const CLSID CLSID_D3D12DeviceFactoryGodot = __uuidof(ID3D12DeviceFactory);
const CLSID CLSID_D3D12DebugGodot = __uuidof(ID3D12Debug);
const CLSID CLSID_D3D12SDKConfigurationGodot = __uuidof(ID3D12SDKConfiguration);
extern "C" { extern "C" {
char godot_nir_arch_name[32]; char godot_nir_arch_name[32];
@ -285,7 +287,7 @@ Error D3D12Context::_initialize_debug_layers() {
ComPtr<ID3D12Debug> debug_controller; ComPtr<ID3D12Debug> debug_controller;
HRESULT res; HRESULT res;
if (device_factory) { 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 { } else {
res = D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller)); res = D3D12GetDebugInterface(IID_PPV_ARGS(&debug_controller));
} }
@ -820,7 +822,7 @@ void D3D12Context::_init_device_factory() {
ERR_FAIL_COND(!d3d_D3D12GetInterface); ERR_FAIL_COND(!d3d_D3D12GetInterface);
ID3D12SDKConfiguration *sdk_config = nullptr; 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; ID3D12SDKConfiguration1 *sdk_config1 = nullptr;
if (SUCCEEDED(sdk_config->QueryInterface(&sdk_config1))) { 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())))) { if (SUCCEEDED(sdk_config1->CreateDeviceFactory(agility_sdk_version, agility_sdk_path.ascii().get_data(), IID_PPV_ARGS(device_factory.GetAddressOf())))) {

View file

@ -97,7 +97,7 @@ if env["d3d12"]:
arch_bin_dir = "#bin/" + env["arch"] arch_bin_dir = "#bin/" + env["arch"]
# DXC # DXC
if env["dxc_path"] != "": if env["dxc_path"] != "" and os.path.exists(env["dxc_path"]):
dxc_dll = "dxil.dll" dxc_dll = "dxil.dll"
# Whether this one is loaded from arch-specific directory or not can be determined at runtime. # 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. # Let's copy to both and let the user decide the distribution model.
@ -121,7 +121,7 @@ if env["d3d12"]:
) )
# PIX # PIX
if env["pix_path"] != "" and os.path.exists(env["pix_path"]): if env["use_pix"]:
pix_dll = "WinPixEventRuntime.dll" pix_dll = "WinPixEventRuntime.dll"
env.Command( env.Command(
"#bin/" + pix_dll, "#bin/" + pix_dll,

View file

@ -224,6 +224,7 @@ def get_opts():
"Whether the Agility SDK DLLs will be stored in arch-specific subdirectories", "Whether the Agility SDK DLLs will be stored in arch-specific subdirectories",
False, False,
), ),
BoolVariable("use_pix", "Use PIX (Performance tuning and debugging for DirectX 12) runtime", False),
( (
"pix_path", "pix_path",
"Path to the PIX runtime distribution (optional for D3D12)", "Path to the PIX runtime distribution (optional for D3D12)",
@ -474,7 +475,7 @@ def configure_msvc(env, vcvars_msvc_config):
if env["d3d12"]: if env["d3d12"]:
# Check whether we have d3d12 dependencies installed. # 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("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("You can install them by running `python misc\scripts\install_d3d12_sdk_windows.py`.")
print("See the documentation for more information:") print("See the documentation for more information:")
@ -491,10 +492,13 @@ def configure_msvc(env, vcvars_msvc_config):
if env["target"] == "release_debug": if env["target"] == "release_debug":
env.Append(CXXFLAGS=["/bigobj"]) env.Append(CXXFLAGS=["/bigobj"])
arch_subdir = "arm64" if env["arch"] == "arm64" else "x64"
# PIX # 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(LIBPATH=[env["pix_path"] + "/bin/" + arch_subdir])
LIBS += ["WinPixEventRuntime"] LIBS += ["WinPixEventRuntime"]
@ -695,13 +699,8 @@ def configure_mingw(env):
env.Append(LIBS=["vulkan"]) env.Append(LIBS=["vulkan"])
if env["d3d12"]: 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. # 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("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("You can install them by running `python misc\scripts\install_d3d12_sdk_windows.py`.")
print("See the documentation for more information:") print("See the documentation for more information:")
@ -710,8 +709,16 @@ def configure_mingw(env):
) )
sys.exit(255) sys.exit(255)
env.AppendUnique(CPPDEFINES=["D3D12_ENABLED", "RD_ENABLED"])
env.Append(LIBS=["d3d12", "dxgi", "dxguid"])
# PIX # 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(LIBPATH=[env["pix_path"] + "/bin/" + arch_subdir])
env.Append(LIBS=["WinPixEventRuntime"]) env.Append(LIBS=["WinPixEventRuntime"])