This commit is contained in:
Branimir Karadžić 2016-09-30 18:16:04 -07:00
Родитель 43eb37b939
Коммит ece1a0e49b
8 изменённых файлов: 109 добавлений и 34 удалений

Просмотреть файл

@ -20,7 +20,8 @@ all:
@echo " TARGET=2 (glsl - nacl)"
@echo " TARGET=3 (glsl - android)"
@echo " TARGET=4 (glsl - linux)"
@echo " TARGET=5 (metal - OSX/iOS)"
@echo " TARGET=5 (metal - osx/ios)"
@echo " TARGET=6 (pssl - ps4)"
@echo " VERBOSE=1 show build commands."
else
@ -57,6 +58,13 @@ VS_FLAGS=--platform osx -p metal
FS_FLAGS=--platform osx -p metal
CS_FLAGS=--platform osx -p metal
SHADER_PATH=shaders/metal
else
ifeq ($(TARGET), 6)
VS_FLAGS=--platform orbis -p pssl
FS_FLAGS=--platform orbis -p pssl
CS_FLAGS=--platform orbis -p pssl
SHADER_PATH=shaders/pssl
endif
endif
endif
endif

Просмотреть файл

@ -114,4 +114,8 @@ project "shaderc"
path.join(GLSL_OPTIMIZER, "src/glsl/builtin_stubs.cpp"),
}
overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-ext"), {
path.join(BGFX_DIR, "tools/shaderc/shaderc_pssl.cpp"),
})
strip()

Просмотреть файл

@ -28,7 +28,7 @@
# define EARLY_DEPTH_STENCIL
#endif // BGFX_SHADER_LANGUAGE_HLSL > 3 && BGFX_SHADER_TYPE_FRAGMENT
#if BGFX_SHADER_LANGUAGE_HLSL
#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL
# define CONST(_x) static const _x
# define dFdx(_x) ddx(_x)
# define dFdy(_y) ddy(-_y)
@ -39,18 +39,20 @@
# define bvec3 bool3
# define bvec4 bool4
# if BGFX_SHADER_LANGUAGE_HLSL > 3
# if BGFX_SHADER_LANGUAGE_HLSL > 4
# if BGFX_SHADER_LANGUAGE_HLSL > 3 || BGFX_SHADER_LANGUAGE_PSSL
# if BGFX_SHADER_LANGUAGE_HLSL > 4 || BGFX_SHADER_LANGUAGE_PSSL
# define dFdxCoarse(_x) ddx_coarse(_x)
# define dFdxFine(_x) ddx_fine(_x)
# define dFdyCoarse(_y) ddy_coarse(-_y)
# define dFdyFine(_y) ddy_fine(-_y)
# endif // BGFX_SHADER_LANGUAGE_HLSL > 4
# if BGFX_SHADER_LANGUAGE_HLSL
float intBitsToFloat(int _x) { return asfloat(_x); }
vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); }
vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); }
vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); }
# endif // BGFX_SHADER_LANGUAGE_HLSL
float uintBitsToFloat(uint _x) { return asfloat(_x); }
vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); }
@ -192,7 +194,7 @@ vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level)
ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord)
{
ivec3 size;
uvec3 size;
_sampler.m_texture.GetDimensions(size.x, size.y, size.z);
return _sampler.m_texture.Load(ivec4(_coord * size, 0) );
}
@ -201,7 +203,7 @@ uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord)
{
uvec3 size;
_sampler.m_texture.GetDimensions(size.x, size.y, size.z);
return _sampler.m_texture.Load(uvec4(_coord * size, 0) );
return _sampler.m_texture.Load(ivec4(_coord * size, 0) );
}
vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord)
@ -441,11 +443,11 @@ vec2 vec2_splat(float _x) { return vec2(_x, _x); }
vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); }
vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); }
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL
#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL
uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); }
uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); }
uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); }
#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL
#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL
uniform vec4 u_viewRect;
uniform vec4 u_viewTexel;

Просмотреть файл

@ -409,7 +409,7 @@ namespace bgfx
struct Preprocessor
{
Preprocessor(const char* _filePath, bool _gles, const char* _includeDir = NULL)
Preprocessor(const char* _filePath, bool _essl, const char* _includeDir = NULL)
: m_tagptr(m_tags)
, m_scratchPos(0)
, m_fgetsPos(0)
@ -451,7 +451,7 @@ namespace bgfx
addInclude(_includeDir);
}
if (!_gles)
if (!_essl)
{
m_default = "#define lowp\n#define mediump\n#define highp\n";
}
@ -779,9 +779,10 @@ namespace bgfx
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;
const char* profile = cmdLine.findOption('p', "profile");
if (NULL != profile)
{
@ -806,6 +807,10 @@ namespace bgfx
{
metal = 1;
}
else if (0 == strcmp(profile, "pssl") )
{
pssl = 1;
}
else
{
glsl = atoi(profile);
@ -881,12 +886,14 @@ 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("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");
@ -939,6 +946,11 @@ namespace bgfx
preprocessor.setDefine("BX_PLATFORM_XBOX360=1");
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_HLSL=3");
}
else if (0 == bx::stricmp(platform, "orbis") )
{
preprocessor.setDefine("BX_PLATFORM_PS4=1");
preprocessor.setDefine("BGFX_SHADER_LANGUAGE_PSSL=1");
}
else
{
fprintf(stderr, "Unknown platform %s?!", platform);
@ -1193,6 +1205,10 @@ namespace bgfx
compiled = true;
}
else if (0 != pssl)
{
compiled = compilePSSLShader(cmdLine, 0, input, writer);
}
else
{
compiled = compileHLSLShader(cmdLine, d3d, input, writer);
@ -1354,6 +1370,10 @@ namespace bgfx
compiled = compileGLSLShader(cmdLine, essl, code, writer);
#endif // 0
}
else if (0 != pssl)
{
compiled = compilePSSLShader(cmdLine, 0, preprocessor.m_preprocessed, writer);
}
else
{
compiled = compileHLSLShader(cmdLine, d3d, preprocessor.m_preprocessed, writer);
@ -1467,7 +1487,8 @@ namespace bgfx
"#define mat4 float4x4\n"
);
if (hlsl < 4)
if (hlsl != 0
&& hlsl < 4)
{
preprocessor.writef(
"#define centroid\n"
@ -1690,7 +1711,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"
@ -1922,18 +1944,26 @@ namespace bgfx
code += preprocessor.m_preprocessed;
compiled = compileGLSLShader(cmdLine
, metal ? BX_MAKEFOURCC('M', 'T', 'L', 0) : essl
, code
, writer
);
, 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);

Просмотреть файл

@ -129,8 +129,9 @@ namespace bgfx
int32_t writef(bx::WriterI* _writer, const char* _format, ...);
void writeFile(const char* _filePath, const void* _data, int32_t _size);
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool firstPass = true);
bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _gles, const std::string& _code, bx::WriterI* _writer);
bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
bool compilePSSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer);
} // namespace bgfx

Просмотреть файл

@ -6,9 +6,9 @@
#include "shaderc.h"
#include "glsl_optimizer.h"
namespace bgfx
namespace bgfx { namespace glsl
{
bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _gles, const std::string& _code, bx::WriterI* _writer)
static bool compile(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer)
{
char ch = char(tolower(_cmdLine.findOption('\0', "type")[0]) );
const glslopt_shader_type type = ch == 'f'
@ -16,7 +16,7 @@ namespace bgfx
: (ch == 'c' ? kGlslOptShaderCompute : kGlslOptShaderVertex);
glslopt_target target = kGlslTargetOpenGL;
switch (_gles)
switch (_version)
{
case BX_MAKEFOURCC('M', 'T', 'L', 0):
target = kGlslTargetMetal;
@ -69,7 +69,7 @@ namespace bgfx
optimizedShader = bx::strnl(optimizedShader);
}
if (0 != _gles)
if (0 != _version)
{
char* code = const_cast<char*>(optimizedShader);
strReplace(code, "gl_FragDepthEXT", "gl_FragDepth");
@ -220,4 +220,11 @@ namespace bgfx
return true;
}
} // namespace glsl
bool compileGLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer)
{
return glsl::compile(_cmdLine, _version, _code, _writer);
}
} // namespace bgfx

Просмотреть файл

@ -21,7 +21,7 @@
# define D3D_SVF_USED 2
#endif // D3D_SVF_USED
namespace bgfx
namespace bgfx { namespace hlsl
{
typedef HRESULT(WINAPI* PFN_D3D_COMPILE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData
, _In_ SIZE_T SrcDataSize
@ -536,7 +536,7 @@ namespace bgfx
return true;
}
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass)
static bool compile(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass)
{
const char* profile = _cmdLine.findOption('p', "profile");
if (NULL == profile)
@ -687,7 +687,7 @@ namespace bgfx
}
// recompile with the unused uniforms converted to statics
return compileHLSLShader(_cmdLine, _d3d, output.c_str(), _writer, false);
return compileHLSLShader(_cmdLine, _d3d, output.c_str(), _writer);
}
}
@ -783,16 +783,22 @@ namespace bgfx
return result;
}
} // namespace hlsl
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer)
{
return hlsl::compile(_cmdLine, _version, _code, _writer, true);
}
} // namespace bgfx
#else
namespace bgfx
{
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass)
bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer)
{
BX_UNUSED(_cmdLine, _d3d, _code, _writer, _firstPass);
BX_UNUSED(_cmdLine, _version, _code, _writer);
fprintf(stderr, "HLSL compiler is not supported on this platform.\n");
return false;
}

Просмотреть файл

@ -0,0 +1,17 @@
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "shaderc.h"
namespace bgfx
{
bool compilePSSLShader(bx::CommandLine& _cmdLine, uint32_t _version, const std::string& _code, bx::WriterI* _writer)
{
BX_UNUSED(_cmdLine, _version, _code, _writer);
fprintf(stderr, "PSSL compiler is not supported.\n");
return false;
}
} // namespace bgfx