summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/tools/shaderc/shaderc.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/tools/shaderc/shaderc.cpp')
-rw-r--r--3rdparty/bgfx/tools/shaderc/shaderc.cpp139
1 files changed, 110 insertions, 29 deletions
diff --git a/3rdparty/bgfx/tools/shaderc/shaderc.cpp b/3rdparty/bgfx/tools/shaderc/shaderc.cpp
index 08f3b4efd26..8a6ff4848de 100644
--- a/3rdparty/bgfx/tools/shaderc/shaderc.cpp
+++ b/3rdparty/bgfx/tools/shaderc/shaderc.cpp
@@ -138,7 +138,13 @@ namespace bgfx
const char* getUniformTypeName(UniformType::Enum _enum)
{
- return s_uniformTypeName[_enum];
+ uint32_t idx = _enum & ~(BGFX_UNIFORM_FRAGMENTBIT|BGFX_UNIFORM_SAMPLERBIT);
+ if (idx < UniformType::Count)
+ {
+ return s_uniformTypeName[idx];
+ }
+
+ return "Unknown uniform type?!";
}
UniformType::Enum nameToUniformTypeEnum(const char* _name)
@@ -371,7 +377,7 @@ namespace bgfx
strReplace(_str, "\r", "\n");
}
- void printCode(const char* _code, int32_t _line, int32_t _start, int32_t _end)
+ void printCode(const char* _code, int32_t _line, int32_t _start, int32_t _end, int32_t _column)
{
fprintf(stderr, "Code:\n---\n");
@@ -380,7 +386,20 @@ namespace bgfx
{
if (line >= _start)
{
- fprintf(stderr, "%s%3d: %s", _line == line ? ">>> " : " ", line, lr.getLine().c_str() );
+ if (_line == line)
+ {
+ fprintf(stderr, "\n");
+ fprintf(stderr, ">>> %3d: %s", line, lr.getLine().c_str() );
+ if (-1 != _column)
+ {
+ fprintf(stderr, ">>> %3d: %*s\n", _column, _column, "^");
+ }
+ fprintf(stderr, "\n");
+ }
+ else
+ {
+ fprintf(stderr, " %3d: %s", line, lr.getLine().c_str() );
+ }
}
else
{
@@ -403,7 +422,7 @@ namespace bgfx
struct Preprocessor
{
- Preprocessor(const char* _filePath, bool _gles, const char* _includeDir = NULL)
+ Preprocessor(const char* _filePath, bool _essl)
: m_tagptr(m_tags)
, m_scratchPos(0)
, m_fgetsPos(0)
@@ -440,12 +459,7 @@ namespace bgfx
m_tagptr->data = scratch(_filePath);
m_tagptr++;
- if (NULL != _includeDir)
- {
- addInclude(_includeDir);
- }
-
- if (!_gles)
+ if (!_essl)
{
m_default = "#define lowp\n#define mediump\n#define highp\n";
}
@@ -765,17 +779,18 @@ namespace bgfx
const char* platform = cmdLine.findOption('\0', "platform");
if (NULL == platform)
{
- help("Must specify platform.");
- return EXIT_FAILURE;
+ platform = "";
}
bool raw = cmdLine.hasArg('\0', "raw");
uint32_t glsl = 0;
uint32_t essl = 0;
- uint32_t hlsl = 2;
+ uint32_t hlsl = 0;
uint32_t d3d = 11;
uint32_t metal = 0;
+ uint32_t pssl = 0;
+ uint32_t spirv = 0;
const char* profile = cmdLine.findOption('p', "profile");
if (NULL != profile)
{
@@ -800,6 +815,14 @@ namespace bgfx
{
metal = 1;
}
+ else if (0 == strcmp(profile, "pssl") )
+ {
+ pssl = 1;
+ }
+ else if (0 == strcmp(profile, "spirv") )
+ {
+ spirv = 1;
+ }
else
{
glsl = atoi(profile);
@@ -841,7 +864,13 @@ namespace bgfx
bool preprocessOnly = cmdLine.hasArg("preprocess");
const char* includeDir = cmdLine.findOption('i');
- Preprocessor preprocessor(filePath, 0 != essl, includeDir);
+ Preprocessor preprocessor(filePath, 0 != essl);
+
+ for (int ii = 1; NULL != includeDir; ++ii)
+ {
+ preprocessor.addInclude(includeDir);
+ includeDir = cmdLine.findOption(ii, 'i');
+ }
std::string dir;
{
@@ -875,18 +904,28 @@ namespace bgfx
preprocessor.setDefaultDefine("BX_PLATFORM_LINUX");
preprocessor.setDefaultDefine("BX_PLATFORM_NACL");
preprocessor.setDefaultDefine("BX_PLATFORM_OSX");
+ preprocessor.setDefaultDefine("BX_PLATFORM_PS4");
preprocessor.setDefaultDefine("BX_PLATFORM_WINDOWS");
preprocessor.setDefaultDefine("BX_PLATFORM_XBOX360");
- // preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_ESSL");
+ preprocessor.setDefaultDefine("BX_PLATFORM_XBOXONE");
+
+// preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_ESSL");
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_GLSL");
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_HLSL");
preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_METAL");
+ preprocessor.setDefaultDefine("BGFX_SHADER_LANGUAGE_PSSL");
+
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_COMPUTE");
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_FRAGMENT");
preprocessor.setDefaultDefine("BGFX_SHADER_TYPE_VERTEX");
char glslDefine[128];
- bx::snprintf(glslDefine, BX_COUNTOF(glslDefine), "BGFX_SHADER_LANGUAGE_GLSL=%d", essl ? 1 : glsl);
+ bx::snprintf(glslDefine, BX_COUNTOF(glslDefine)
+ , "BGFX_SHADER_LANGUAGE_GLSL=%d"
+ , essl ? 1
+ : spirv ? 130
+ : glsl
+ );
if (0 == bx::stricmp(platform, "android") )
{
@@ -933,10 +972,11 @@ namespace bgfx
preprocessor.setDefine("BX_PLATFORM_XBOX360=1");
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_HLSL=3");
}
- else
+ else if (0 == bx::stricmp(platform, "orbis") )
{
- fprintf(stderr, "Unknown platform %s?!", platform);
- return EXIT_FAILURE;
+ preprocessor.setDefine("BX_PLATFORM_PS4=1");
+ preprocessor.setDefine("BGFX_SHADER_LANGUAGE_PSSL=1");
+ preprocessor.setDefine("lit=lit_reserved");
}
preprocessor.setDefine("M_PI=3.1415926535897932384626433832795");
@@ -1187,6 +1227,10 @@ namespace bgfx
compiled = true;
}
+ else if (0 != pssl)
+ {
+ compiled = compilePSSLShader(cmdLine, 0, input, writer);
+ }
else
{
compiled = compileHLSLShader(cmdLine, d3d, input, writer);
@@ -1206,7 +1250,8 @@ namespace bgfx
{
if (0 != glsl
|| 0 != essl
- || 0 != metal)
+ || 0 != metal
+ || 0 != spirv)
{
}
else
@@ -1348,6 +1393,14 @@ namespace bgfx
compiled = compileGLSLShader(cmdLine, essl, code, writer);
#endif // 0
}
+ else if (0 != spirv)
+ {
+ compiled = compileSPIRVShader(cmdLine, 0, preprocessor.m_preprocessed, writer);
+ }
+ else if (0 != pssl)
+ {
+ compiled = compilePSSLShader(cmdLine, 0, preprocessor.m_preprocessed, writer);
+ }
else
{
compiled = compileHLSLShader(cmdLine, d3d, preprocessor.m_preprocessed, writer);
@@ -1385,7 +1438,8 @@ namespace bgfx
{
if (0 != glsl
|| 0 != essl
- || 0 != metal)
+ || 0 != metal
+ || 0 != spirv)
{
if (0 == essl)
{
@@ -1461,7 +1515,8 @@ namespace bgfx
"#define mat4 float4x4\n"
);
- if (hlsl < 4)
+ if (hlsl != 0
+ && hlsl < 4)
{
preprocessor.writef(
"#define centroid\n"
@@ -1684,7 +1739,8 @@ namespace bgfx
"\t} \\\n"
);
- if (hlsl <= 3)
+ if (hlsl != 0
+ && hlsl <= 3)
{
// preprocessor.writef(
// "\tgl_Position.xy += u_viewTexel.xy * gl_Position.w; \\\n"
@@ -1765,7 +1821,8 @@ namespace bgfx
if (0 != glsl
|| 0 != essl
- || 0 != metal)
+ || 0 != metal
+ || 0 != spirv )
{
std::string code;
@@ -1787,6 +1844,10 @@ namespace bgfx
{
bx::stringPrintf(code, "#version 120\n");
}
+ else if (0 != spirv)
+ {
+ bx::stringPrintf(code, "#version 130\n");
+ }
else
{
bx::stringPrintf(code, "#version %s\n", need130 ? "130" : profile);
@@ -1915,19 +1976,39 @@ namespace bgfx
}
code += preprocessor.m_preprocessed;
- compiled = compileGLSLShader(cmdLine
+
+ if (0 != spirv)
+ {
+ compiled = compileSPIRVShader(cmdLine
+ , 0
+ , code
+ , writer
+ );
+ }
+ else
+ {
+ compiled = compileGLSLShader(cmdLine
, metal ? BX_MAKEFOURCC('M', 'T', 'L', 0) : essl
, code
, writer
);
+ }
+ }
+ else if (0 != pssl)
+ {
+ compiled = compilePSSLShader(cmdLine
+ , 0
+ , preprocessor.m_preprocessed
+ , writer
+ );
}
else
{
compiled = compileHLSLShader(cmdLine
- , d3d
- , preprocessor.m_preprocessed
- , writer
- );
+ , d3d
+ , preprocessor.m_preprocessed
+ , writer
+ );
}
bx::close(writer);