From 4c0baf5603626b328e25c26b23b1e0ceda029178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Thu, 15 Sep 2022 22:13:34 -0700 Subject: [PATCH] D3D11: Enable compilation on Linux. --- include/bgfx/embedded_shader.h | 2 ++ src/bgfx.cpp | 10 ++++++---- src/config.h | 1 + src/dxgi.cpp | 25 +++++++++++++++++++------ src/dxgi.h | 9 +++------ src/renderer_d3d.h | 4 ++++ src/renderer_d3d11.cpp | 21 ++++++++++++++++----- src/renderer_d3d11.h | 3 +++ src/renderer_d3d12.cpp | 4 ---- src/renderer_d3d12.h | 7 ++----- 10 files changed, 56 insertions(+), 30 deletions(-) diff --git a/include/bgfx/embedded_shader.h b/include/bgfx/embedded_shader.h index ad29148b6..c4ddca0c3 100644 --- a/include/bgfx/embedded_shader.h +++ b/include/bgfx/embedded_shader.h @@ -19,9 +19,11 @@ #define BGFX_EMBEDDED_SHADER_SPIRV(...) #define BGFX_PLATFORM_SUPPORTS_DX9BC (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ ) #define BGFX_PLATFORM_SUPPORTS_DXBC (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ || BX_PLATFORM_XBOXONE \ diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 6e52f0284..1353bb131 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2692,10 +2692,12 @@ namespace bgfx } else if (BX_ENABLED(BX_PLATFORM_LINUX) ) { - score += RendererType::Vulkan == renderer ? 30 : 0; - score += RendererType::OpenGL == renderer ? 20 : 0; - score += RendererType::OpenGLES == renderer ? 10 : 0; - score += RendererType::Direct3D12 == renderer ? 5 : 0; + score += RendererType::Vulkan == renderer ? 50 : 0; + score += RendererType::OpenGL == renderer ? 40 : 0; + score += RendererType::OpenGLES == renderer ? 30 : 0; + score += RendererType::Direct3D12 == renderer ? 20 : 0; + score += RendererType::Direct3D11 == renderer ? 10 : 0; + score += RendererType::Direct3D9 == renderer ? 5 : 0; } else if (BX_ENABLED(BX_PLATFORM_OSX) ) { diff --git a/src/config.h b/src/config.h index cfaa24a55..09b90f983 100644 --- a/src/config.h +++ b/src/config.h @@ -45,6 +45,7 @@ # ifndef BGFX_CONFIG_RENDERER_DIRECT3D11 # define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ || BX_PLATFORM_XBOXONE \ diff --git a/src/dxgi.cpp b/src/dxgi.cpp index c323ccbfb..96f0cd7c4 100644 --- a/src/dxgi.cpp +++ b/src/dxgi.cpp @@ -128,15 +128,27 @@ namespace bgfx bool Dxgi::init(Caps& _caps) { -#if BX_PLATFORM_WINDOWS - m_dxgiDll = bx::dlopen("dxgi.dll"); +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS + + const char* dxgiDllName = +#if BX_PLATFORM_LINUX + "dxgi.so" +#else + "dxgi.dll" +#endif // BX_PLATFORM_LINUX + ; + m_dxgiDll = bx::dlopen(dxgiDllName); + if (NULL == m_dxgiDll) { - BX_TRACE("Init error: Failed to load dxgi.dll."); + BX_TRACE("Init error: Failed to load %s.", dxgiDllName); return false; } +# if BX_PLATFORM_WINDOWS m_dxgiDebugDll = bx::dlopen("dxgidebug.dll"); + + if (NULL != m_dxgiDebugDll) { DXGIGetDebugInterface = (PFN_GET_DEBUG_INTERFACE )bx::dlsym(m_dxgiDebugDll, "DXGIGetDebugInterface"); @@ -161,6 +173,7 @@ namespace bgfx BX_TRACE("Init error: Function CreateDXGIFactory not found."); return false; } +# endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS HRESULT hr = S_OK; @@ -273,7 +286,7 @@ namespace bgfx BX_TRACE("\t\t AttachedToDesktop: %d", outputDesc.AttachedToDesktop); BX_TRACE("\t\t Rotation: %d", outputDesc.Rotation); -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS IDXGIOutput6* output6; hr = output->QueryInterface(IID_IDXGIOutput6, (void**)&output6); if (SUCCEEDED(hr) ) @@ -381,7 +394,7 @@ namespace bgfx uint32_t scdFlags = _scd.flags; -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS IDXGIFactory5* factory5; hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); @@ -733,7 +746,7 @@ namespace bgfx uint32_t scdFlags = _scd.flags; -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS IDXGIFactory5* factory5; hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); diff --git a/src/dxgi.h b/src/dxgi.h index afbc943d0..cd01d6bf9 100644 --- a/src/dxgi.h +++ b/src/dxgi.h @@ -6,11 +6,8 @@ #ifndef BGFX_DXGI_H_HEADER_GUARD #define BGFX_DXGI_H_HEADER_GUARD -#if BX_PLATFORM_LINUX -# include -typedef void* HMODULE; -#define _Out_writes_bytes_to_(s,c) -#endif // BX_PLATFORM_LINUX +#include +#include #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include @@ -59,7 +56,7 @@ namespace bgfx /// struct Dxgi { -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS typedef ::IDXGIAdapter3 AdapterI; typedef ::IDXGIFactory5 FactoryI; typedef ::IDXGISwapChain3 SwapChainI; diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index b2733ee33..d0ec4ebda 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -19,6 +19,10 @@ # define DX_CHECK_EXTRA_ARGS #endif // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9 +#ifndef DXGI_ERROR_NOT_CURRENTLY_AVAILABLE +# define DXGI_ERROR_NOT_CURRENTLY_AVAILABLE HRESULT(0x887A0022) +#endif // DXGI_ERROR_NOT_CURRENTLY_AVAILABLE + #define DXGI_FORMAT_ASTC_4X4_TYPELESS DXGI_FORMAT(133) #define DXGI_FORMAT_ASTC_4X4_UNORM DXGI_FORMAT(134) #define DXGI_FORMAT_ASTC_4X4_UNORM_SRGB DXGI_FORMAT(135) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 166d1b51f..da42bcef3 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -811,11 +811,19 @@ namespace bgfx { namespace d3d11 m_nvapi.init(); #if USE_D3D11_DYNAMIC_LIB - m_d3d11Dll = bx::dlopen("d3d11.dll"); + const char* d3d11DllName = +#if BX_PLATFORM_LINUX + "d3d11.so" +#else + "d3d11.dll" +#endif // BX_PLATFORM_LINUX + ; + + m_d3d11Dll = bx::dlopen(d3d11DllName); if (NULL == m_d3d11Dll) { - BX_TRACE("Init error: Failed to load d3d11.dll."); + BX_TRACE("Init error: Failed to load %s.", d3d11DllName); goto error; } @@ -1004,11 +1012,11 @@ namespace bgfx { namespace d3d11 HRESULT hr = S_OK; m_swapEffect = -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS DXGI_SWAP_EFFECT_FLIP_DISCARD #else DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL -#endif // !BX_PLATFORM_WINDOWS +#endif // BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS ; m_swapBufferCount = bx::clamp(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); @@ -1040,7 +1048,10 @@ namespace bgfx { namespace d3d11 ; m_scd.swapEffect = m_swapEffect; - m_scd.alphaMode = (_init.resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE; + m_scd.alphaMode = (_init.resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) + ? DXGI_ALPHA_MODE_PREMULTIPLIED + : DXGI_ALPHA_MODE_IGNORE + ; m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index 4d5545661..276e478aa 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -18,7 +18,10 @@ BX_PRAGMA_DIAGNOSTIC_PUSH(); BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas" ); BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas"); BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition + #include +#include + #define D3D11_NO_HELPERS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS # include diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 8bcf53f6e..97207d7fa 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -541,10 +541,6 @@ namespace bgfx { namespace d3d12 return createCommittedResource(_device, _heapProperty, &resourceDesc, NULL); } -#ifndef DXGI_ERROR_NOT_CURRENTLY_AVAILABLE -# define DXGI_ERROR_NOT_CURRENTLY_AVAILABLE HRESULT(0x887A0022) -#endif // DXGI_ERROR_NOT_CURRENTLY_AVAILABLE - inline bool isLost(HRESULT _hr) { return false diff --git a/src/renderer_d3d12.h b/src/renderer_d3d12.h index cf30babd8..207c86925 100644 --- a/src/renderer_d3d12.h +++ b/src/renderer_d3d12.h @@ -8,11 +8,8 @@ #define USE_D3D12_DYNAMIC_LIB (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) -#if BX_PLATFORM_LINUX -# include -#else -# include -#endif // BX_PLATFORM_LINUX +#include +#include #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include