diff --git a/tools/shaderc/shaderc.h b/tools/shaderc/shaderc.h index f68398265..017c446c2 100644 --- a/tools/shaderc/shaderc.h +++ b/tools/shaderc/shaderc.h @@ -11,28 +11,63 @@ namespace bgfx extern bool g_verbose; } +#include + // 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() +# define SHADERC_CONFIG_HAS_D3DCOMPILER 1 +# endif +# elif BX_PLATFORM_LINUX +# if __has_include() +# 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() +# define SHADERC_CONFIG_HAS_TINT 1 +# else +# define SHADERC_CONFIG_HAS_TINT 0 +# endif +#endif + +#ifndef SHADERC_CONFIG_HAS_GLSLANG +# if __has_include() \ + && __has_include() +# 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 #include #include #include diff --git a/tools/shaderc/shaderc_dxil.cpp b/tools/shaderc/shaderc_dxil.cpp index 0c47f6eef..59e018e9b 100644 --- a/tools/shaderc/shaderc_dxil.cpp +++ b/tools/shaderc/shaderc_dxil.cpp @@ -6,7 +6,7 @@ #include "shaderc.h" #include -#if SHADERC_CONFIG_DXIL +#if SHADERC_CONFIG_HAS_DXC #if BX_PLATFORM_WINDOWS # include @@ -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 diff --git a/tools/shaderc/shaderc_glsl.cpp b/tools/shaderc/shaderc_glsl.cpp index e57051576..a17ea0c3d 100644 --- a/tools/shaderc/shaderc_glsl.cpp +++ b/tools/shaderc/shaderc_glsl.cpp @@ -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 diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index 99cb5f36a..52211a5d0 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -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 diff --git a/tools/shaderc/shaderc_metal.cpp b/tools/shaderc/shaderc_metal.cpp index 033f6d49a..95e230be8 100644 --- a/tools/shaderc/shaderc_metal.cpp +++ b/tools/shaderc/shaderc_metal.cpp @@ -5,6 +5,8 @@ #include "shaderc.h" +#if SHADERC_CONFIG_HAS_GLSLANG + #include // 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 diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index ef56e26cc..148271a10 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -5,6 +5,8 @@ #include "shaderc.h" +#if SHADERC_CONFIG_HAS_GLSLANG + #include // 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 diff --git a/tools/shaderc/shaderc_wgsl.cpp b/tools/shaderc/shaderc_wgsl.cpp index 484157285..849e6337b 100644 --- a/tools/shaderc/shaderc_wgsl.cpp +++ b/tools/shaderc/shaderc_wgsl.cpp @@ -5,6 +5,8 @@ #include "shaderc.h" +#if SHADERC_CONFIG_HAS_TINT && SHADERC_CONFIG_HAS_GLSLANG + #include // 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