D3D11: Enable compilation on Linux.

This commit is contained in:
Бранимир Караџић 2022-09-15 22:13:34 -07:00
parent 1fa7570ef8
commit 4c0baf5603
10 changed files with 56 additions and 30 deletions

View File

@ -19,9 +19,11 @@
#define BGFX_EMBEDDED_SHADER_SPIRV(...) #define BGFX_EMBEDDED_SHADER_SPIRV(...)
#define BGFX_PLATFORM_SUPPORTS_DX9BC (0 \ #define BGFX_PLATFORM_SUPPORTS_DX9BC (0 \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINDOWS \
) )
#define BGFX_PLATFORM_SUPPORTS_DXBC (0 \ #define BGFX_PLATFORM_SUPPORTS_DXBC (0 \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \ || BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOXONE \ || BX_PLATFORM_XBOXONE \

View File

@ -2692,10 +2692,12 @@ namespace bgfx
} }
else if (BX_ENABLED(BX_PLATFORM_LINUX) ) else if (BX_ENABLED(BX_PLATFORM_LINUX) )
{ {
score += RendererType::Vulkan == renderer ? 30 : 0; score += RendererType::Vulkan == renderer ? 50 : 0;
score += RendererType::OpenGL == renderer ? 20 : 0; score += RendererType::OpenGL == renderer ? 40 : 0;
score += RendererType::OpenGLES == renderer ? 10 : 0; score += RendererType::OpenGLES == renderer ? 30 : 0;
score += RendererType::Direct3D12 == renderer ? 5 : 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) ) else if (BX_ENABLED(BX_PLATFORM_OSX) )
{ {

View File

@ -45,6 +45,7 @@
# ifndef BGFX_CONFIG_RENDERER_DIRECT3D11 # ifndef BGFX_CONFIG_RENDERER_DIRECT3D11
# define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \ # define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINDOWS \
|| BX_PLATFORM_WINRT \ || BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOXONE \ || BX_PLATFORM_XBOXONE \

View File

@ -128,15 +128,27 @@ namespace bgfx
bool Dxgi::init(Caps& _caps) bool Dxgi::init(Caps& _caps)
{ {
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
m_dxgiDll = bx::dlopen("dxgi.dll");
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) if (NULL == m_dxgiDll)
{ {
BX_TRACE("Init error: Failed to load dxgi.dll."); BX_TRACE("Init error: Failed to load %s.", dxgiDllName);
return false; return false;
} }
# if BX_PLATFORM_WINDOWS
m_dxgiDebugDll = bx::dlopen("dxgidebug.dll"); m_dxgiDebugDll = bx::dlopen("dxgidebug.dll");
if (NULL != m_dxgiDebugDll) if (NULL != m_dxgiDebugDll)
{ {
DXGIGetDebugInterface = (PFN_GET_DEBUG_INTERFACE )bx::dlsym(m_dxgiDebugDll, "DXGIGetDebugInterface"); DXGIGetDebugInterface = (PFN_GET_DEBUG_INTERFACE )bx::dlsym(m_dxgiDebugDll, "DXGIGetDebugInterface");
@ -161,6 +173,7 @@ namespace bgfx
BX_TRACE("Init error: Function CreateDXGIFactory not found."); BX_TRACE("Init error: Function CreateDXGIFactory not found.");
return false; return false;
} }
# endif // BX_PLATFORM_WINDOWS
#endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS
HRESULT hr = S_OK; HRESULT hr = S_OK;
@ -273,7 +286,7 @@ namespace bgfx
BX_TRACE("\t\t AttachedToDesktop: %d", outputDesc.AttachedToDesktop); BX_TRACE("\t\t AttachedToDesktop: %d", outputDesc.AttachedToDesktop);
BX_TRACE("\t\t Rotation: %d", outputDesc.Rotation); BX_TRACE("\t\t Rotation: %d", outputDesc.Rotation);
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
IDXGIOutput6* output6; IDXGIOutput6* output6;
hr = output->QueryInterface(IID_IDXGIOutput6, (void**)&output6); hr = output->QueryInterface(IID_IDXGIOutput6, (void**)&output6);
if (SUCCEEDED(hr) ) if (SUCCEEDED(hr) )
@ -381,7 +394,7 @@ namespace bgfx
uint32_t scdFlags = _scd.flags; uint32_t scdFlags = _scd.flags;
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
IDXGIFactory5* factory5; IDXGIFactory5* factory5;
hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5);
@ -733,7 +746,7 @@ namespace bgfx
uint32_t scdFlags = _scd.flags; uint32_t scdFlags = _scd.flags;
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
IDXGIFactory5* factory5; IDXGIFactory5* factory5;
hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5);

View File

@ -6,11 +6,8 @@
#ifndef BGFX_DXGI_H_HEADER_GUARD #ifndef BGFX_DXGI_H_HEADER_GUARD
#define BGFX_DXGI_H_HEADER_GUARD #define BGFX_DXGI_H_HEADER_GUARD
#if BX_PLATFORM_LINUX #include <sal.h>
# include <unknwn.h> #include <unknwn.h>
typedef void* HMODULE;
#define _Out_writes_bytes_to_(s,c)
#endif // BX_PLATFORM_LINUX
#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
# include <d3dcommon.h> # include <d3dcommon.h>
@ -59,7 +56,7 @@ namespace bgfx
/// ///
struct Dxgi struct Dxgi
{ {
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
typedef ::IDXGIAdapter3 AdapterI; typedef ::IDXGIAdapter3 AdapterI;
typedef ::IDXGIFactory5 FactoryI; typedef ::IDXGIFactory5 FactoryI;
typedef ::IDXGISwapChain3 SwapChainI; typedef ::IDXGISwapChain3 SwapChainI;

View File

@ -19,6 +19,10 @@
# define DX_CHECK_EXTRA_ARGS # define DX_CHECK_EXTRA_ARGS
#endif // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9 #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_TYPELESS DXGI_FORMAT(133)
#define DXGI_FORMAT_ASTC_4X4_UNORM DXGI_FORMAT(134) #define DXGI_FORMAT_ASTC_4X4_UNORM DXGI_FORMAT(134)
#define DXGI_FORMAT_ASTC_4X4_UNORM_SRGB DXGI_FORMAT(135) #define DXGI_FORMAT_ASTC_4X4_UNORM_SRGB DXGI_FORMAT(135)

View File

@ -811,11 +811,19 @@ namespace bgfx { namespace d3d11
m_nvapi.init(); m_nvapi.init();
#if USE_D3D11_DYNAMIC_LIB #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) if (NULL == m_d3d11Dll)
{ {
BX_TRACE("Init error: Failed to load d3d11.dll."); BX_TRACE("Init error: Failed to load %s.", d3d11DllName);
goto error; goto error;
} }
@ -1004,11 +1012,11 @@ namespace bgfx { namespace d3d11
HRESULT hr = S_OK; HRESULT hr = S_OK;
m_swapEffect = m_swapEffect =
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
DXGI_SWAP_EFFECT_FLIP_DISCARD DXGI_SWAP_EFFECT_FLIP_DISCARD
#else #else
DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL
#endif // !BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
; ;
m_swapBufferCount = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); m_swapBufferCount = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS);
@ -1040,7 +1048,10 @@ namespace bgfx { namespace d3d11
; ;
m_scd.swapEffect = m_swapEffect; 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; m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

View File

@ -18,7 +18,10 @@ BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas" ); BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas" );
BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas"); BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas");
BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition
#include <sal.h> #include <sal.h>
#include <unknwn.h>
#define D3D11_NO_HELPERS #define D3D11_NO_HELPERS
#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS
# include <d3d11_3.h> # include <d3d11_3.h>

View File

@ -541,10 +541,6 @@ namespace bgfx { namespace d3d12
return createCommittedResource(_device, _heapProperty, &resourceDesc, NULL); 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) inline bool isLost(HRESULT _hr)
{ {
return false return false

View File

@ -8,11 +8,8 @@
#define USE_D3D12_DYNAMIC_LIB (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) #define USE_D3D12_DYNAMIC_LIB (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
#if BX_PLATFORM_LINUX #include <sal.h>
# include <unknwn.h> #include <unknwn.h>
#else
# include <sal.h>
#endif // BX_PLATFORM_LINUX
#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT #if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
# include <d3d12.h> # include <d3d12.h>