Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ddf8196 committed Aug 11, 2023
1 parent 6621be0 commit 97a881b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
32 changes: 17 additions & 15 deletions src/bgfx_shader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -615,21 +615,21 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
# define atan2(_x, _y) atan(_x, _y)
# define mul(_a, _b) ( (_a) * (_b) )
# define saturate(_x) clamp(_x, 0.0, 1.0)
# define SAMPLER2D(_name, _reg) uniform sampler2D _name
# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name
# define SAMPLER3D(_name, _reg) uniform sampler3D _name
# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name
# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name
# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name
# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name
# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name
# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name
# define ISAMPLER2D(_name, _reg) uniform isampler2D _name
# define USAMPLER2D(_name, _reg) uniform usampler2D _name
# define ISAMPLER3D(_name, _reg) uniform isampler3D _name
# define USAMPLER3D(_name, _reg) uniform usampler3D _name
# define SAMPLER2D(_name, _reg) uniform lowp sampler2D _name
# define SAMPLER2DMS(_name, _reg) uniform highp sampler2DMS _name
# define SAMPLER3D(_name, _reg) uniform highp sampler3D _name
# define SAMPLERCUBE(_name, _reg) uniform lowp samplerCube _name
# define SAMPLER2DSHADOW(_name, _reg) uniform highp sampler2DShadow _name
# define SAMPLER2DARRAY(_name, _reg) uniform highp sampler2DArray _name
# define SAMPLER2DMSARRAY(_name, _reg) uniform highp sampler2DMSArray _name
# define SAMPLERCUBEARRAY(_name, _reg) uniform highp samplerCubeArray _name
# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform highp sampler2DArrayShadow _name
# define ISAMPLER2D(_name, _reg) uniform highp isampler2D _name
# define USAMPLER2D(_name, _reg) uniform highp usampler2D _name
# define ISAMPLER3D(_name, _reg) uniform highp isampler3D _name
# define USAMPLER3D(_name, _reg) uniform highp usampler3D _name
# if BGFX_SHADER_LANGUAGE_GLSL >= 130
# define texture2D(_sampler, _coord) texture(_sampler, _coord)
Expand All @@ -640,9 +640,11 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); }
# define texture2DLodOffset(_sampler, _coord, _lod, _offset) textureLodOffset(_sampler, _coord, _lod, _offset)
# define texture2DBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias)
# define textureCubeBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias)
# define shadow2DArray(_sampler, _coord) texture(_sampler, _coord)
# else
# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias)
# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias)
// define shadow2DArray(_sampler, _coord)
# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130
vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); }
Expand Down
47 changes: 32 additions & 15 deletions tools/shaderc/shaderc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,28 +2379,36 @@ namespace bgfx
bx::stringPrintf(code, "#define varying %s\n"
, 'f' == _options.shaderType ? "in" : "out"
);
bx::stringPrintf(code, "precision highp float;\n");
bx::stringPrintf(code, "precision highp int;\n");
}

if (glsl_profile >= 300 && usesTextureArray)
{
bx::stringPrintf(code, "precision highp sampler2DArray;\n");
}

// Pretend that all extensions are available.
// This will be stripped later.
if (usesTextureLod)
{
bx::stringPrintf(code
, "#extension GL_EXT_shader_texture_lod : enable\n"
"#define texture2DLod texture2DLodEXT\n"
"#define texture2DGrad texture2DGradEXT\n"
"#define texture2DProjLod texture2DProjLodEXT\n"
"#define texture2DProjGrad texture2DProjGradEXT\n"
"#define textureCubeLod textureCubeLodEXT\n"
"#define textureCubeGrad textureCubeGradEXT\n"
if (glsl_profile < 300)
{
bx::stringPrintf(code
, "#extension GL_EXT_shader_texture_lod : enable\n"
"#define texture2DLod texture2DLodEXT\n"
"#define texture2DGrad texture2DGradEXT\n"
"#define texture2DProjLod texture2DProjLodEXT\n"
"#define texture2DProjGrad texture2DProjGradEXT\n"
"#define textureCubeLod textureCubeLodEXT\n"
"#define textureCubeGrad textureCubeGradEXT\n"
);
}
else
{
bx::stringPrintf(code
, "#extension GL_EXT_shader_texture_lod : enable\n"
"#define texture2DLod textureLod\n"
"#define texture2DGrad textureGrad\n"
"#define texture2DProjLod textureProjLod\n"
"#define texture2DProjGrad textureProjGrad\n"
"#define textureCubeLod textureLod\n"
"#define textureCubeGrad textureGrad\n"
);
}
}

if (!bx::findIdentifierMatch(input, s_OES_standard_derivatives).isEmpty() )
Expand Down Expand Up @@ -2458,6 +2466,15 @@ namespace bgfx
);
}

if (glsl_profile > 100 && 'f' == _options.shaderType)
{
bx::stringPrintf(code, "#if GL_FRAGMENT_PRECISION_HIGH\n");
bx::stringPrintf(code, "precision highp float;\n");
bx::stringPrintf(code, "#else\n");
bx::stringPrintf(code, "precision mediump float;\n");
bx::stringPrintf(code, "#endif\n");
}

if (glsl_profile == 100)
{
code +=
Expand Down

0 comments on commit 97a881b

Please sign in to comment.