Skip to content

Commit b71e8f7

Browse files
committed
DX8 and DX9 GUIDs cannot live within the same translation unit,
have to split them up into separate files
1 parent 16e1dca commit b71e8f7

5 files changed

Lines changed: 78 additions & 8 deletions

File tree

Makefile.common

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,16 @@ ifneq ($(findstring Win32,$(OS)),)
25492549
gfx/display_servers/dispserv_win32.o \
25502550
gfx/common/dx_guids.o
25512551

2552+
# Legacy pre-DXGI GUID storage in their own TUs to avoid clashes
2553+
# between system <d3d8types.h> / <d3d9types.h> and the bundled
2554+
# <dxsdk/dxgitype.h>. See dx_guids.c header comment.
2555+
ifeq ($(HAVE_D3D9), 1)
2556+
OBJ += gfx/common/dx_guids_d3d9.o
2557+
endif
2558+
ifeq ($(HAVE_D3D8), 1)
2559+
OBJ += gfx/common/dx_guids_d3d8.o
2560+
endif
2561+
25522562
ifeq ($(HAVE_GDI), 1)
25532563
OBJ += gfx/drivers/gdi_gfx.o
25542564
LIBS += -lmsimg32

gfx/common/dx_guids.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55
* The Windows 7.x Platform SDK (bundled with MSVC 2010 and earlier)
66
* does not ship dxguid.lib. Rather than require the legacy June 2010
77
* DirectX SDK just to pick up a handful of IID_* / CLSID_* constants,
8-
* we define them ourselves in this single translation unit.
8+
* we define them ourselves.
99
*
1010
* Including <initguid.h> before any DX header causes DEFINE_GUID() to
1111
* expand to actual storage rather than extern references. Every other
1212
* TU in the program continues to see the default extern declarations
1313
* and resolves the GUIDs to the storage defined here at link time.
1414
*
15+
* GUID storage for the modern (DXGI-based) DX stack lives in this file
16+
* (D3D10/11/12, DXGI, D3DCompiler, DInput, XAudio). The legacy pre-DXGI
17+
* stack lives in two separate TUs:
18+
* * gfx/common/dx_guids_d3d9.c
19+
* * gfx/common/dx_guids_d3d8.c
20+
* because <d3d8.h> / <d3d9.h> and <d3d11.h> / <dxgi.h> cannot share a
21+
* single TU portably -- system <d3d8types.h> / <d3d9types.h> headers
22+
* (notably mingw-w64) do not honor the D3DCOLORVALUE_DEFINED guard
23+
* used by the bundled gfx/include/dxsdk headers, and redefine
24+
* D3DCOLORVALUE / D3DVECTOR / D3DMATRIX. Splitting per header family
25+
* sidesteps that altogether.
26+
*
1527
* IMPORTANT: no other TU in the program may include <initguid.h>
1628
* before DirectX headers, or the linker will report duplicate symbols
1729
* for IID_* / CLSID_* constants.
@@ -42,12 +54,8 @@
4254
#ifdef HAVE_D3D10
4355
#include <d3d10.h>
4456
#endif
45-
#ifdef HAVE_D3D9
46-
#include <d3d9.h>
47-
#endif
48-
#ifdef HAVE_D3D8
49-
#include <d3d8.h>
50-
#endif
57+
/* HAVE_D3D9: emitted in gfx/common/dx_guids_d3d9.c */
58+
/* HAVE_D3D8: emitted in gfx/common/dx_guids_d3d8.c */
5159

5260
#if defined(HAVE_D3D10) || defined(HAVE_D3D11) || defined(HAVE_D3D12) \
5361
|| (defined(HAVE_D3D9) && defined(HAVE_HLSL))

gfx/common/dx_guids_d3d8.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* dx_guids_d3d8.c
2+
*
3+
* Emits Direct3D 8 COM GUID storage in lieu of linking dxguid.lib.
4+
*
5+
* Split out from dx_guids.c because the legacy <d3d8.h> header family
6+
* (pre-DXGI) and the modern <dxgi.h>/<d3d11.h> header family cannot
7+
* coexist in a single translation unit on every toolchain. The bundled
8+
* gfx/include/dxsdk headers and the bundled gfx/include/d3d8 headers
9+
* cooperate via shared D3DCOLORVALUE_DEFINED / D3DVECTOR_DEFINED /
10+
* D3DMATRIX_DEFINED guards, but a system <d3d8types.h> (e.g. mingw-w64)
11+
* will not honor those guards, redefining D3DCOLORVALUE et al. and
12+
* breaking the build.
13+
*
14+
* Including <initguid.h> before <d3d8.h> causes DEFINE_GUID() in
15+
* gfx/include/d3d8/d3d8.h (or in the system d3d8.h) to expand to actual
16+
* storage. See dx_guids.c for the rest of the design rationale.
17+
*/
18+
19+
#if defined(_WIN32) && !defined(_XBOX) && !defined(HAVE_GRIFFIN) \
20+
&& defined(HAVE_D3D8) \
21+
&& (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
22+
23+
#include <initguid.h>
24+
#include <d3d8.h>
25+
26+
#endif /* _WIN32 && !_XBOX && !HAVE_GRIFFIN && HAVE_D3D8 && desktop */

gfx/common/dx_guids_d3d9.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* dx_guids_d3d9.c
2+
*
3+
* Emits Direct3D 9 COM GUID storage in lieu of linking dxguid.lib.
4+
*
5+
* Split out from dx_guids.c because the legacy <d3d9.h> header family
6+
* (pre-DXGI) and the modern <dxgi.h>/<d3d11.h> header family cannot
7+
* coexist in a single translation unit on every toolchain. The bundled
8+
* gfx/include/dxsdk headers and the bundled gfx/include/d3d9 headers
9+
* cooperate via shared D3DCOLORVALUE_DEFINED / D3DVECTOR_DEFINED /
10+
* D3DMATRIX_DEFINED guards, but a system <d3d9types.h> (e.g. mingw-w64)
11+
* will not honor those guards, redefining D3DCOLORVALUE et al. and
12+
* breaking the build.
13+
*
14+
* Including <initguid.h> before <d3d9.h> causes DEFINE_GUID() in
15+
* gfx/include/d3d9/d3d9.h (or in the system d3d9.h) to expand to actual
16+
* storage. See dx_guids.c for the rest of the design rationale.
17+
*/
18+
19+
#if defined(_WIN32) && !defined(_XBOX) && !defined(HAVE_GRIFFIN) \
20+
&& defined(HAVE_D3D9) \
21+
&& (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP))
22+
23+
#include <initguid.h>
24+
#include <d3d9.h>
25+
26+
#endif /* _WIN32 && !_XBOX && !HAVE_GRIFFIN && HAVE_D3D9 && desktop */

gfx/drivers/d3d8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ static void d3d8_overlay_render(d3d8_video_t *d3d,
825825
struct video_viewport vp;
826826
unsigned i;
827827
Vertex vert[4];
828-
enum D3DTEXTUREFILTERTYPE filter_type = D3DTEXF_LINEAR;
828+
D3DTEXTUREFILTERTYPE filter_type = D3DTEXF_LINEAR;
829829

830830
if (!d3d || !overlay || !overlay->tex)
831831
return;

0 commit comments

Comments
 (0)