ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.23k stars 10.32k forks source link

Compilation of imgui_impl_dx12.cpp fails with GCC 11 #4594

Open yh-sb opened 3 years ago

yh-sb commented 3 years ago

Version/Branch of Dear ImGui:

Version: 1.85 WIP (18417) Branch: master

Dear ImGui 1.85 WIP (18417)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: _WIN32
define: _WIN64
define: __MINGW32__
define: __MINGW64__
define: __GNUC__=11
--------------------------------

io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------

io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,512
io.DisplaySize: 1800.00,1350.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 18.00,18.00
style.WindowBorderSize: 1.00
style.FramePadding: 9.00,6.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 18.00,9.00
style.ItemInnerSpacing: 9.00,9.00

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx12.cpp + imgui_impl_glfw.cpp Compiler: GCC 11.2 Operating System: Windows 10

My Issue/Question:

I have found that backends\imgui_impl_dx12.cpp compilation fails with GCC 11.2 on Windows 10 with the following log:

In file included from D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.cpp:41:
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.h:25:6: error: use of enum 'DXGI_FORMAT' without previous declaration
   25 | enum DXGI_FORMAT;
      |      ^~~~~~~~~~~
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.h:36:93: error: 'DXGI_FORMAT' has not been declared
   36 | IMGUI_IMPL_API bool     ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
      |                                                                                             ^~~~~~~~~~~
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.cpp: In function 'bool ImGui_ImplDX12_CreateDeviceObjects()':
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.cpp:517:9: error: 'PFN_D3D12_SERIALIZE_ROOT_SIGNATURE' was not declared in this scope; did you mean 'PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE'?
  517 |         PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignatureFn = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)::GetProcAddress(d3d12_dll, "D3D12SerializeRootSignature");
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.cpp:518:13: error: 'D3D12SerializeRootSignatureFn' was not declared in this scope; did you mean 'D3D12SerializeRootSignature'?
  518 |         if (D3D12SerializeRootSignatureFn == NULL)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |             D3D12SerializeRootSignature
D:\dev\software\x86\c++\projects\opengl\opengl-example\third_party\imgui\backends\imgui_impl_dx12.cpp:522:13: error: 'D3D12SerializeRootSignatureFn' was not declared in this scope; did you mean 'D3D12SerializeRootSignature'?
  522 |         if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, NULL) != S_OK)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ImGui already has the following hack in backends\imgui_impl_dx12.h:20 for MSVC:

#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable: 4471) // a forward declaration of an unscoped enumeration must have an underlying type
#endif

It would be great to add similar for GCC.

ocornut commented 3 years ago

Hello, Thanks for reporting. A pull request to fix those would be appreciated.

yh-sb commented 3 years ago

Unfortunately I have no idea how to fix this. I have spent a lot of time trying to solve it.

The only solution I can suggest is it add #include <dxgiformat.h> to backends\imgui_impl_dx12.h. dxgiformat.h provides only DXGI_FORMAT type.

If anyone has something working, please share your idea or create pull request.

ocornut commented 3 years ago

I am ok to add the #include <dxgiformat.h> in there but would that solve the second issue in the CPP file?

yh-sb commented 3 years ago

This is the root cause of imgui_impl_dx12.cpp compilation issue: https://docs.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-d3d12serializerootsignature#remarks

This function has been superceded by D3D12SerializeVersionedRootSignature as of the Windows 10 Anniversary Update (14393).

I already have solution for this and will push both fixes in PR soon.