Skip to content

Commit 5b527b2

Browse files
committed
Merge pull request #111800 from Repiteo/scons/d3d12-cleanup
SCons: Clean up hardcoded D3D12 driver workarounds
2 parents 82e4493 + b93d82a commit 5b527b2

File tree

8 files changed

+83
-156
lines changed

8 files changed

+83
-156
lines changed

drivers/d3d12/SCsub

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,25 @@ from pathlib import Path
77
import methods
88

99
Import("env")
10-
1110
env_d3d12_rdd = env.Clone()
1211

13-
thirdparty_obj = []
14-
15-
16-
# DirectX Headers (must take precedence over Windows SDK's).
17-
18-
env.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
19-
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/directx"])
20-
env_d3d12_rdd.Prepend(CPPPATH=["#thirdparty/directx_headers/include/dxguids"])
21-
22-
23-
# Direct3D 12 Memory Allocator.
24-
25-
env.Append(CPPPATH=["#thirdparty/d3d12ma"])
26-
env_d3d12_rdd.Append(CPPPATH=["#thirdparty/d3d12ma"])
27-
28-
2912
# Agility SDK.
30-
3113
if env["agility_sdk_path"] != "" and os.path.exists(env["agility_sdk_path"]):
3214
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_ENABLED"])
3315
if env["agility_sdk_multiarch"]:
3416
env_d3d12_rdd.Append(CPPDEFINES=["AGILITY_SDK_MULTIARCH_ENABLED"])
3517

36-
3718
# PIX.
38-
3919
if env["use_pix"]:
4020
env_d3d12_rdd.Append(CPPDEFINES=["PIX_ENABLED"])
4121
env_d3d12_rdd.Append(CPPPATH=[env["pix_path"] + "/Include"])
4222

43-
4423
# Direct composition.
45-
4624
if "dcomp" in env.get("supported", []):
4725
env_d3d12_rdd.Append(CPPDEFINES=["DCOMP_ENABLED"])
4826
env.Append(CPPDEFINES=["DCOMP_ENABLED"]) # Used in header included in platform.
4927

50-
5128
# Mesa (SPIR-V to DXIL functionality).
52-
5329
mesa_libs = env["mesa_libs"]
5430
if env.msvc and os.path.exists(env["mesa_libs"] + "-" + env["arch"] + "-msvc"):
5531
mesa_libs = env["mesa_libs"] + "-" + env["arch"] + "-msvc"
@@ -137,6 +113,7 @@ extra_defines += [
137113
("PACKAGE_BUGREPORT", '\\"https://gitlab.freedesktop.org/mesa/mesa/-/issues\\"'),
138114
"PIPE_SUBSYSTEM_WINDOWS_USER",
139115
("_Static_assert", "static_assert"),
116+
"HAVE_STRUCT_TIMESPEC",
140117
]
141118

142119
if env.msvc:
@@ -148,29 +125,38 @@ if env.msvc:
148125
"_SCL_SECURE_NO_WARNINGS",
149126
"_SCL_SECURE_NO_DEPRECATE",
150127
"_ALLOW_KEYWORD_MACROS",
151-
("_HAS_EXCEPTIONS", 0),
152128
"NOMINMAX",
153-
"HAVE_STRUCT_TIMESPEC",
154129
]
155130
else:
156131
extra_defines += [
157-
"HAVE_STRUCT_TIMESPEC",
132+
# Match current version used by MinGW. MSVC and Direct3D 12 headers use 500.
133+
("__REQUIRED_RPCNDR_H_VERSION__", 475),
158134
]
159135
if methods.using_gcc(env) and methods.get_compiler_version(env)["major"] < 13:
160136
# `region` & `endregion` not recognized as valid pragmas.
161137
env_d3d12_rdd.Append(CCFLAGS=["-Wno-unknown-pragmas"])
162-
env.Append(CCFLAGS=["-Wno-unknown-pragmas"])
163138

164139
# This is needed since rendering_device_d3d12.cpp needs to include some Mesa internals.
165140
env_d3d12_rdd.Prepend(CPPPATH=mesa_private_inc_paths)
166141
# For the same reason as above, the defines must be the same as in the 3rd-party code itself.
167142
env_d3d12_rdd.Append(CPPDEFINES=extra_defines)
168143

144+
# Thirdparty.
145+
thirdparty_obj = []
169146

170-
# Add all.
147+
env_thirdparty = env_d3d12_rdd.Clone()
148+
env_thirdparty.disable_warnings()
171149

172-
env.drivers_sources += thirdparty_obj
150+
env_thirdparty.Prepend(
151+
CPPPATH=[
152+
"#thirdparty/directx_headers/include/directx",
153+
"#thirdparty/directx_headers/include/dxguids",
154+
"#thirdparty/d3d12ma",
155+
]
156+
)
173157

158+
env_thirdparty.add_source_files(thirdparty_obj, "#thirdparty/d3d12ma/D3D12MemAlloc.cpp")
159+
env.drivers_sources += thirdparty_obj
174160

175161
# Godot source files.
176162

drivers/d3d12/d3d12ma.cpp

Lines changed: 0 additions & 68 deletions
This file was deleted.

drivers/d3d12/rendering_context_driver_d3d12.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,19 @@ GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")
5151
GODOT_CLANG_WARNING_IGNORE("-Wswitch")
5252

5353
#include <dxcapi.h>
54+
#include <dxgi1_6.h>
5455

5556
GODOT_GCC_WARNING_POP
5657
GODOT_CLANG_WARNING_POP
5758

5859
#if !defined(_MSC_VER)
5960
#include <guiddef.h>
6061

61-
#include <dxguids.h>
62+
#include <thirdparty/directx_headers/include/dxguids/dxguids.h>
6263
#endif
6364

65+
using Microsoft::WRL::ComPtr;
66+
6467
// Note: symbols are not available in MinGW and old MSVC import libraries.
6568
// GUID values from https://github.com/microsoft/DirectX-Headers/blob/7a9f4d06911d30eecb56a4956dab29dcca2709ed/include/directx/d3d12.idl#L5877-L5881
6669
const GUID CLSID_D3D12DeviceFactoryGodot = { 0x114863bf, 0xc386, 0x4aee, { 0xb3, 0x9d, 0x8f, 0x0b, 0xbb, 0x06, 0x29, 0x55 } };
@@ -72,7 +75,7 @@ const GUID CLSID_D3D12SDKConfigurationGodot = { 0x7cda6aca, 0xa03e, 0x49c8, { 0x
7275
#define _MSC_VER 1800
7376
#endif
7477
#define USE_PIX
75-
#include "WinPixEventRuntime/pix3.h"
78+
#include <WinPixEventRuntime/pix3.h>
7679
#if defined(__GNUC__)
7780
#undef _MSC_VER
7881
#endif

drivers/d3d12/rendering_context_driver_d3d12.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include "servers/display/display_server.h"
3838
#include "servers/rendering/rendering_context_driver.h"
3939

40+
#if !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)
41+
// Match current version used by MinGW, MSVC and Direct3D 12 headers use 500.
42+
#define __REQUIRED_RPCNDR_H_VERSION__ 475
43+
#endif // !defined(_MSC_VER) && !defined(__REQUIRED_RPCNDR_H_VERSION__)
44+
4045
GODOT_GCC_WARNING_PUSH
4146
GODOT_GCC_WARNING_IGNORE("-Wimplicit-fallthrough")
4247
GODOT_GCC_WARNING_IGNORE("-Wmissing-field-initializers")
@@ -50,6 +55,11 @@ GODOT_CLANG_WARNING_IGNORE("-Wnon-virtual-dtor")
5055
GODOT_CLANG_WARNING_IGNORE("-Wstring-plus-int")
5156
GODOT_CLANG_WARNING_IGNORE("-Wswitch")
5257

58+
#include <thirdparty/directx_headers/include/directx/d3dx12.h>
59+
60+
GODOT_GCC_WARNING_POP
61+
GODOT_CLANG_WARNING_POP
62+
5363
#if defined(AS)
5464
#undef AS
5565
#endif
@@ -58,21 +68,13 @@ GODOT_CLANG_WARNING_IGNORE("-Wswitch")
5868
#include <dcomp.h>
5969
#endif
6070

61-
#include <d3dx12.h>
62-
#include <dxgi1_6.h>
63-
6471
#include <wrl/client.h>
6572

66-
GODOT_GCC_WARNING_POP
67-
GODOT_CLANG_WARNING_POP
68-
69-
using Microsoft::WRL::ComPtr;
70-
7173
#define ARRAY_SIZE(a) std_size(a)
7274

7375
class RenderingContextDriverD3D12 : public RenderingContextDriver {
74-
ComPtr<ID3D12DeviceFactory> device_factory;
75-
ComPtr<IDXGIFactory2> dxgi_factory;
76+
Microsoft::WRL::ComPtr<ID3D12DeviceFactory> device_factory;
77+
Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory;
7678
TightLocalVector<Device> driver_devices;
7779
bool tearing_supported = false;
7880

@@ -111,9 +113,9 @@ class RenderingContextDriverD3D12 : public RenderingContextDriver {
111113
DisplayServer::VSyncMode vsync_mode = DisplayServer::VSYNC_ENABLED;
112114
bool needs_resize = false;
113115
#ifdef DCOMP_ENABLED
114-
ComPtr<IDCompositionDevice> composition_device;
115-
ComPtr<IDCompositionTarget> composition_target;
116-
ComPtr<IDCompositionVisual> composition_visual;
116+
Microsoft::WRL::ComPtr<IDCompositionDevice> composition_device;
117+
Microsoft::WRL::ComPtr<IDCompositionTarget> composition_target;
118+
Microsoft::WRL::ComPtr<IDCompositionVisual> composition_visual;
117119
#endif
118120
};
119121

drivers/d3d12/rendering_device_driver_d3d12.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ GODOT_MSVC_WARNING_PUSH
5858
GODOT_MSVC_WARNING_IGNORE(4200) // "nonstandard extension used: zero-sized array in struct/union".
5959
GODOT_MSVC_WARNING_IGNORE(4806) // "'&': unsafe operation: no value of type 'bool' promoted to type 'uint32_t' can equal the given constant".
6060

61+
#include <dxgi1_6.h>
62+
#define D3D12MA_D3D12_HEADERS_ALREADY_INCLUDED
63+
#include <thirdparty/d3d12ma/D3D12MemAlloc.h>
64+
6165
#include <nir_spirv.h>
6266
#include <nir_to_dxil.h>
6367
#include <spirv_to_dxil.h>
@@ -72,9 +76,11 @@ GODOT_MSVC_WARNING_POP
7276
#if !defined(_MSC_VER)
7377
#include <guiddef.h>
7478

75-
#include <dxguids.h>
79+
#include <thirdparty/directx_headers/include/dxguids/dxguids.h>
7680
#endif
7781

82+
using Microsoft::WRL::ComPtr;
83+
7884
// Mesa may define this.
7985
#ifdef UNUSED
8086
#undef UNUSED
@@ -85,7 +91,7 @@ GODOT_MSVC_WARNING_POP
8591
#define _MSC_VER 1800
8692
#endif
8793
#define USE_PIX
88-
#include "WinPixEventRuntime/pix3.h"
94+
#include <WinPixEventRuntime/pix3.h>
8995
#if defined(__GNUC__)
9096
#undef _MSC_VER
9197
#endif
@@ -6611,6 +6617,7 @@ Error RenderingDeviceDriverD3D12::initialize(uint32_t p_device_index, uint32_t p
66116617
adapter.Attach(context_driver->create_adapter(p_device_index));
66126618
ERR_FAIL_NULL_V(adapter, ERR_CANT_CREATE);
66136619

6620+
DXGI_ADAPTER_DESC adapter_desc;
66146621
HRESULT res = adapter->GetDesc(&adapter_desc);
66156622
ERR_FAIL_COND_V(!SUCCEEDED(res), ERR_CANT_CREATE);
66166623

0 commit comments

Comments
 (0)