libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10.16k stars 1.86k forks source link

[GPU] MinGW build issues #10705

Closed sezero closed 2 months ago

sezero commented 2 months ago

I had build errors in SDL_gpu_d3d11 and SDL_gpu_d3d12 against mingw-w64 headers version 8.0.3, because :

/tmp/SDL3/src/gpu/d3d12/SDL_gpu_d3d12.c:536:5: error: unknown type name 'IDXGIInfoQueue'
     IDXGIInfoQueue *dxgiInfoQueue;
     ^~~~~~~~~~~~~~
/tmp/SDL3/src/gpu/d3d12/SDL_gpu_d3d12.c: In function 'D3D12_INTERNAL_AcquireFence':
/tmp/SDL3/src/gpu/d3d12/SDL_gpu_d3d12.c:6512:24: warning: implicit declaration of function 'CreateEventEx'; did you mean 'CreateEventW'? [-Wimplicit-function-declaration]
         fence->event = CreateEventEx(NULL, 0, 0, EVENT_ALL_ACCESS);
                        ^~~~~~~~~~~~~
                        CreateEventW
/tmp/SDL3/src/gpu/d3d12/SDL_gpu_d3d12.c:6512:22: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
         fence->event = CreateEventEx(NULL, 0, 0, EVENT_ALL_ACCESS);
                      ^
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:707:5: error: unknown type name 'IDXGIInfoQueue'
     IDXGIInfoQueue *dxgiInfoQueue;
     ^~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/SDL3-shared.dir/src/gpu/d3d12/SDL_gpu_d3d12.c.obj] Error 1
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c: In function 'D3D11_DestroyDevice':
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:985:9: warning: implicit declaration of function 'IDXGIInfoQueue_Release'; did you mean 'ID3D11InfoQueue_Release'? [-Wimplicit-function-declaration]
         IDXGIInfoQueue_Release(renderer->dxgiInfoQueue);
         ^~~~~~~~~~~~~~~~~~~~~~
         ID3D11InfoQueue_Release
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c: In function 'D3D11_CreateDevice':
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6054:9: error: unknown type name 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY'; did you mean 'D3D11_MESSAGE_SEVERITY'?
         DXGI_INFO_QUEUE_MESSAGE_SEVERITY sevList[] = {
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         D3D11_MESSAGE_SEVERITY
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6055:13: error: 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION' undeclared (first use in this function); did you mean 'D3D11_MESSAGE_SEVERITY_CORRUPTION'?
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             D3D11_MESSAGE_SEVERITY_CORRUPTION
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6055:13: note: each undeclared identifier is reported only once for each function it appears in
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6056:13: error: 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR' undeclared (first use in this function); did you mean 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION'?
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6057:13: error: 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING' undeclared (first use in this function); did you mean 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR'?
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_WARNING,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6059:13: error: 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_MESSAGE' undeclared (first use in this function); did you mean 'DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR'?
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_MESSAGE
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6061:9: error: unknown type name 'DXGI_INFO_QUEUE_FILTER'; did you mean 'D3D11_INFO_QUEUE_FILTER'?
         DXGI_INFO_QUEUE_FILTER filter = { 0 };
         ^~~~~~~~~~~~~~~~~~~~~~
         D3D11_INFO_QUEUE_FILTER
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6062:15: error: request for member 'AllowList' in something not a structure or union
         filter.AllowList.NumSeverities = SDL_arraysize(sevList);
               ^
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6062:25: error: request for member 'NumSeverities' in something not a structure or union
         filter.AllowList.NumSeverities = SDL_arraysize(sevList);
                         ^
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6062:9: warning: statement with no effect [-Wunused-value]
         filter.AllowList.NumSeverities = SDL_arraysize(sevList);
         ^~~~~~
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6063:15: error: request for member 'AllowList' in something not a structure or union
         filter.AllowList.pSeverityList = sevList;
               ^
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6063:25: error: request for member 'pSeverityList' in something not a structure or union
         filter.AllowList.pSeverityList = sevList;
                         ^
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6063:9: warning: statement with no effect [-Wunused-value]
         filter.AllowList.pSeverityList = sevList;
         ^~~~~~
/tmp/SDL3/src/gpu/d3d11/SDL_gpu_d3d11.c:6065:9: warning: implicit declaration of function 'IDXGIInfoQueue_PushStorageFilter'; did you mean 'ID3D11InfoQueue_PushStorageFilter'? [-Wimplicit-function-declaration]
         IDXGIInfoQueue_PushStorageFilter(
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ID3D11InfoQueue_PushStorageFilter
make[2]: *** [CMakeFiles/SDL3-shared.dir/src/gpu/d3d11/SDL_gpu_d3d11.c.obj] Error 1
make[2]: Target `CMakeFiles/SDL3-shared.dir/build' not remade because of errors.
make[1]: *** [CMakeFiles/SDL3-shared.dir/all] Error 2
make[1]: Target `all' not remade because of errors.
make: *** [all] Error 2
make: Target `default_target' not remade because of errors.

I generated the following patch, but not sure about it. Can you gpu guys please review? (I can make it into a pull request, too, if you guys are more comfortable with that.)

diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c
index b3acc4b..07498ae 100644
--- a/src/gpu/d3d11/SDL_gpu_d3d11.c
+++ b/src/gpu/d3d11/SDL_gpu_d3d11.c
@@ -36,7 +36,7 @@
 #include "../SDL_sysgpu.h"

 // MinGW doesn't implement this yet
-#ifdef _WIN32
+#ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
 #define HAVE_IDXGIINFOQUEUE
 #endif

diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index f8172a3..014948d 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -23,6 +23,7 @@

 #if SDL_GPU_D3D12

+#include "../../core/windows/SDL_windows.h"
 #include "../../video/directx/SDL_d3d12.h"
 #include "../SDL_sysgpu.h"
 #include "SDL_hashtable.h"
@@ -132,8 +133,10 @@ static const IID D3D_IID_IDXGIAdapter1 = { 0x29038f61, 0x3839, 0x4626, { 0x91, 0
 static const IID D3D_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
 #endif
 static const IID D3D_IID_IDXGISwapChain3 = { 0x94d99bdb, 0xf1f8, 0x4ab0, { 0xb2, 0x36, 0x7d, 0xa0, 0x17, 0x0e, 0xda, 0xb1 } };
+#ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
 static const IID D3D_IID_IDXGIDebug = { 0x119e7452, 0xde9e, 0x40fe, { 0x88, 0x06, 0x88, 0xf9, 0x0c, 0x12, 0xb4, 0x41 } };
 static const IID D3D_IID_IDXGIInfoQueue = { 0xd67441c7, 0x672a, 0x476f, { 0x9e, 0x82, 0xcd, 0x55, 0xb4, 0x49, 0x49, 0xce } };
+#endif
 static const GUID D3D_IID_DXGI_DEBUG_ALL = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x08 } };
 static const GUID D3D_IID_D3DDebugObjectName = { 0x429b8c22, 0x9188, 0x4b0c, { 0x87, 0x42, 0xac, 0xb0, 0xbf, 0x85, 0xc2, 0x00 } };

@@ -533,7 +536,9 @@ struct D3D12Renderer
 #if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
     IDXGIDebug *dxgiDebug;
     IDXGIFactory4 *factory;
+    #ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
     IDXGIInfoQueue *dxgiInfoQueue;
+    #endif
     IDXGIAdapter1 *adapter;
     void *dxgi_dll;
     void *dxgidebug_dll;
@@ -7635,7 +7640,7 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this)
 #endif
 }

-#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
+#if defined(__IDXGIInfoQueue_INTERFACE_DEFINED__) && !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
 static void D3D12_INTERNAL_TryInitializeDXGIDebug(D3D12Renderer *renderer)
 {
     PFN_DXGI_GET_DEBUG_INTERFACE DXGIGetDebugInterfaceFunc;
@@ -7757,10 +7762,12 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
         return NULL;
     }

+    #ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
     // Initialize the DXGI debug layer, if applicable
     if (debugMode) {
         D3D12_INTERNAL_TryInitializeDXGIDebug(renderer);
     }
+    #endif

     // Load the CreateDXGIFactory1 function
     CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY1)SDL_LoadFunction(
slouken commented 2 months ago

The d3d11 change looks good. Let's add a similar check at the top of the d3d12 file:

#ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
#define HAVE_IDXGIINFOQUEUE
#endif

and key off of that.

slouken commented 2 months ago

@sezero, can you implement this, since you have a build environment that is affected?

sezero commented 2 months ago

Created https://github.com/libsdl-org/SDL/pull/10717