mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-19 13:32:59 +01:00
[shaderc] Make SPIRV, HLSL, DXIL, Metal backends optional to allow for leaner builds. (#3594)
* Make SPIRV, HLSL, DXIL, Metal backends optional to allow for leaner builds. * New and automatic detection of available compilers to enable backends. * Forgot to fixup Metal. * Cleanup. Check for glsl-optimizer likewise.
This commit is contained in:
committed by
GitHub
parent
c85fa25266
commit
b03bd2d698
@@ -11,28 +11,63 @@ namespace bgfx
|
||||
extern bool g_verbose;
|
||||
}
|
||||
|
||||
#include <bx/bx.h>
|
||||
|
||||
// HLSL compilation support:
|
||||
// - Windows: Native D3DCompiler DLL
|
||||
// - Linux/macOS: d3d4linux (Wine-based D3DCompiler via IPC)
|
||||
#ifndef SHADERC_CONFIG_HLSL
|
||||
# define SHADERC_CONFIG_HLSL (0 \
|
||||
|| BX_PLATFORM_WINDOWS \
|
||||
|| BX_PLATFORM_LINUX \
|
||||
)
|
||||
#endif // SHADERC_CONFIG_HLSL
|
||||
#ifndef SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
# if BX_PLATFORM_WINDOWS
|
||||
# if __has_include(<d3dcompiler.h>)
|
||||
# define SHADERC_CONFIG_HAS_D3DCOMPILER 1
|
||||
# endif
|
||||
# elif BX_PLATFORM_LINUX
|
||||
# if __has_include(<d3d4linux.h>)
|
||||
# define SHADERC_CONFIG_HAS_D3DCOMPILER 1
|
||||
# endif
|
||||
# endif
|
||||
// Still not?
|
||||
# ifndef SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
# define SHADERC_CONFIG_HAS_D3DCOMPILER 0
|
||||
# endif
|
||||
#endif // SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
|
||||
// DXIL compilation support (Shader Model 6.0+):
|
||||
// - Windows: Native DXC (dxcompiler.dll)
|
||||
// - Linux: DXC (libdxcompiler.so) via directx-headers
|
||||
// - macOS: Not supported (no DXC dynamic library available)
|
||||
#ifndef SHADERC_CONFIG_DXIL
|
||||
# define SHADERC_CONFIG_DXIL (0 \
|
||||
#ifndef SHADERC_CONFIG_HAS_DXC
|
||||
# define SHADERC_CONFIG_HAS_DXC (0 \
|
||||
|| BX_PLATFORM_WINDOWS \
|
||||
|| BX_PLATFORM_LINUX \
|
||||
)
|
||||
#endif // SHADERC_CONFIG_DXIL
|
||||
#endif // SHADERC_CONFIG_HAS_DXC
|
||||
|
||||
#ifndef SHADERC_CONFIG_HAS_TINT
|
||||
# if __has_include(<tint/api/tint.h>)
|
||||
# define SHADERC_CONFIG_HAS_TINT 1
|
||||
# else
|
||||
# define SHADERC_CONFIG_HAS_TINT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SHADERC_CONFIG_HAS_GLSLANG
|
||||
# if __has_include(<ShaderLang.h>) \
|
||||
&& __has_include(<SPIRV/SpvTools.h>)
|
||||
# define SHADERC_CONFIG_HAS_GLSLANG 1
|
||||
# else
|
||||
# define SHADERC_CONFIG_HAS_GLSLANG 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef SHADERC_CONFIG_HAS_GLSL_OPTIMIZER
|
||||
# if __has_include("glsl_optimizer.h")
|
||||
# define SHADERC_CONFIG_HAS_GLSL_OPTIMIZER 1
|
||||
# else
|
||||
# define SHADERC_CONFIG_HAS_GLSL_OPTIMIZER 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <bx/bx.h>
|
||||
#include <bx/debug.h>
|
||||
#include <bx/commandline.h>
|
||||
#include <bx/endian.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "shaderc.h"
|
||||
#include <bx/os.h>
|
||||
|
||||
#if SHADERC_CONFIG_DXIL
|
||||
#if SHADERC_CONFIG_HAS_DXC
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
# include <windows.h>
|
||||
@@ -682,7 +682,7 @@ namespace bgfx { namespace dxil
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else
|
||||
#else // SHADERC_CONFIG_HAS_DXC
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
@@ -690,10 +690,10 @@ namespace bgfx
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
bx::write(_messageWriter, &messageErr, "DXIL compiler is not supported on this platform.\n");
|
||||
bx::write(_messageWriter, &messageErr, "DXIL compiler is not compiled in or not supported on this platform.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_CONFIG_DXIL
|
||||
#endif // SHADERC_CONFIG_HAS_DXC
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
#if SHADERC_CONFIG_HAS_GLSL_OPTIMIZER
|
||||
#include "glsl_optimizer.h"
|
||||
|
||||
namespace bgfx { namespace glsl
|
||||
@@ -402,3 +404,18 @@ namespace bgfx { namespace glsl
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else // SHADERC_CONFIG_HAS_GLSL_OPTIMIZER
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
bool compileSPIRVShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _shaderWriter, bx::WriterI* _messageWriter)
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
bx::write(_messageWriter, &messageErr, "GLSL optimizer compiler is not compiled in.\n");
|
||||
return false;
|
||||
}
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_CONFIG_HAS_GLSL_OPTIMIZER
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
#if SHADERC_CONFIG_HLSL
|
||||
#if SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
# define __REQUIRED_RPCNDR_H_VERSION__ 475
|
||||
@@ -757,7 +757,7 @@ namespace bgfx { namespace hlsl
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else
|
||||
#else // SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
@@ -765,10 +765,16 @@ namespace bgfx
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
bx::write(_messageWriter, &messageErr, "HLSL compiler support is not compiled in.\n");
|
||||
#elif BX_PLATFORM_LINUX
|
||||
bx::write(_messageWriter, &messageErr, "HLSL compiler support through D3D4Linux is not compiled in.\n");
|
||||
#else
|
||||
bx::write(_messageWriter, &messageErr, "HLSL compiler is not supported on this platform.\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_CONFIG_HLSL
|
||||
#endif // SHADERC_CONFIG_HAS_D3DCOMPILER
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
#if SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
#include <iostream> // std::cout
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_PUSH()
|
||||
@@ -818,3 +820,18 @@ namespace bgfx { namespace metal
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else // SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
bool compileMetalShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _shaderWriter, bx::WriterI* _messageWriter)
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
bx::write(_messageWriter, &messageErr, "Metal compiler (glslang) is not compiled in.\n");
|
||||
return false;
|
||||
}
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
#if SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
#include <iostream> // std::cout
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_PUSH()
|
||||
@@ -900,3 +902,18 @@ namespace bgfx { namespace spirv
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else // SHADERC_HAS_GLSLANG
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
bool compileSPIRVShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _shaderWriter, bx::WriterI* _messageWriter)
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
bx::write(_messageWriter, &messageErr, "SPIRV compiler (glslang, spirv-cross and spirv-tools) is not compiled in.\n");
|
||||
return false;
|
||||
}
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_HAS_GLSLANG
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
#if SHADERC_CONFIG_HAS_TINT && SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
#include <iostream> // std::cout
|
||||
|
||||
BX_PRAGMA_DIAGNOSTIC_PUSH()
|
||||
@@ -939,3 +941,18 @@ namespace bgfx { namespace wgsl
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else // SHADERC_CONFIG_HAS_TINT && SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
namespace bgfx
|
||||
{
|
||||
bool compileWgslShader(const Options& _options, uint32_t _version, const std::string& _code, bx::WriterI* _shaderWriter, bx::WriterI* _messageWriter)
|
||||
{
|
||||
BX_UNUSED(_options, _version, _code, _shaderWriter);
|
||||
bx::Error messageErr;
|
||||
bx::write(_messageWriter, &messageErr, "WGSL compiler (tint) is not compiled in.\n");
|
||||
return false;
|
||||
}
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // SHADERC_CONFIG_HAS_TINT && SHADERC_CONFIG_HAS_GLSLANG
|
||||
|
||||
Reference in New Issue
Block a user