LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.1k stars 139 forks source link

Direct3D12 doesn't build with clang #123

Closed st0rmbtw closed 3 months ago

st0rmbtw commented 3 months ago

I get this errors when build Direct3D12 renderer with clang on Windows:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3179:27: error: invalid application of 'sizeof' to an incomplete type 'LLGL::D3D12RootSignature'
 3179 |         static_assert(0 < sizeof(_Ty), "can't delete an incomplete type");
      |                           ^~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3290:13: note: in instantiation of member function 'std::default_delete<LLGL::D3D12RootSignature>::operator()' requested here
 3290 |             _Mypair._Get_first()(_Mypair._Myval2);
      |             ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState\D3D12PipelineLayout.h:110:7: note: in instantiation of member function 'std::unique_ptr<LLGL::D3D12RootSignature>::~unique_ptr' requested here
  110 | class D3D12PipelineLayout final : public PipelineLayout
      |       ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState/D3D12PipelineState.cpp:35:27: note: in instantiation of function template specialization 'LLGL::ObjectCast<const LLGL::D3D12PipelineLayout *, const LLGL::PipelineLayout>' requested here
   35 |         pipelineLayout_ = LLGL_CAST(const D3D12PipelineLayout*, pipelineLayout);
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3179:27: error: invalid application of 'sizeof' to an incomplete type 'LLGL::D3D12RootSignature'
 3179 |         static_assert(0 < sizeof(_Ty), "can't delete an incomplete type");
      |                           ^~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3290:13: note: in instantiation of member function 'std::default_delete<LLGL::D3D12RootSignature>::operator()' requested here
 3290 |             _Mypair._Get_first()(_Mypair._Myval2);
      |             ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState\D3D12PipelineLayout.h:110:7: note: in instantiation of member function 'std::unique_ptr<LLGL::D3D12RootSignature>::~unique_ptr' requested here
  110 | class D3D12PipelineLayout final : public PipelineLayout
      |       ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState/D3D12ResourceHeap.cpp:40:30: note: in instantiation of function template specialization 'LLGL::ObjectCast<const LLGL::D3D12PipelineLayout *, LLGL::PipelineLayout>' requested here
   40 |     auto pipelineLayoutD3D = LLGL_CAST(const D3D12PipelineLayout*, desc.pipelineLayout);
LukasBanana commented 3 months ago

It looks like you are including MSVC headers in a Clang environment. If you are building on Windows, I recommend using MSYS2 as this is the officially supported environment to build Windows binaries with GCC and Clang ABI. Those MSYS2 packages should provide all headers. That being said, D3D12 was not supported so far, but I'm currently resolving the build issues I'm seeing when compiling with MSYS2/Clang64.

a6c6202 fixes the build issues I saw on my end and added --d3d12 argument to BuildMSYS2.sh script. Let me know if that changes anything for you.

st0rmbtw commented 3 months ago

Let me know if that changes anything for you.

Same kind of error in a new place now (the two previous errors disappeared):

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3179:27: error: invalid application of 'sizeof' to an incomplete type 'LLGL::D3D12RootSignature'
 3179 |         static_assert(0 < sizeof(_Ty), "can't delete an incomplete type");
      |                           ^~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\include\memory:3290:13: note: in instantiation of member function 'std::default_delete<LLGL::D3D12RootSignature>::operator()' requested here        
 3290 |             _Mypair._Get_first()(_Mypair._Myval2);
      |             ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState\D3D12PipelineLayout.h:110:7: note: in instantiation of member function 'std::unique_ptr<LLGL::D3D12RootSignature>::~unique_ptr' requested here
  110 | class D3D12PipelineLayout final : public PipelineLayout
      |       ^
D:/Libs/LLGL/sources/Renderer/Direct3D12/RenderState/D3D12GraphicsPSO.cpp:78:29: note: in instantiation of function template specialization 'LLGL::ObjectCast<const LLGL::D3D12PipelineLayout *, const LLGL::PipelineLayout>' requested here
   78 |         pipelineLayoutD3D = LLGL_CAST(const D3D12PipelineLayout*, desc.pipelineLayout);
LukasBanana commented 3 months ago

If you move the #include-directive for D3D12RootSignature.h into the header D3D12PipelineLayout.h, does that fix the issue for you?

st0rmbtw commented 3 months ago

Yes! It compiled successfully.