Skip to content

Commit

Permalink
[GLSL] Better legacy GLSL compatibility and update expected files
Browse files Browse the repository at this point in the history
Related work item: Github #42
  • Loading branch information
Minmin Gong committed Apr 11, 2020
1 parent 971319a commit f75d8c7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 18 deletions.
30 changes: 30 additions & 0 deletions Source/Core/ShaderConductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,36 @@ namespace
compiler = std::make_unique<spirv_cross::CompilerGLSL>(spirvIr, spirvSize);
combinedImageSamplers = true;
buildDummySampler = true;

// Legacy GLSL fixups
if (intVersion <= 300)
{
auto vars = compiler->get_active_interface_variables();
for (auto& var : vars)
{
auto varClass = compiler->get_storage_class(var);

// Make VS out and PS in variable names match
if ((source.stage == ShaderStage::VertexShader) && (varClass == spv::StorageClass::StorageClassOutput))
{
auto name = compiler->get_name(var);
if (name.find("out_var") == 0)
{
name.replace(0, 7, "varying");
compiler->set_name(var, name);
}
}
else if ((source.stage == ShaderStage::PixelShader) && (varClass == spv::StorageClass::StorageClassInput))
{
auto name = compiler->get_name(var);
if (name.find("in_var") == 0)
{
name.replace(0, 6, "varying");
compiler->set_name(var, name);
}
}
}
}
break;

case ShadingLanguage::Msl_macOS:
Expand Down
4 changes: 2 additions & 2 deletions Source/Tests/Data/Expected/IncludeExist.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
uniform sampler2D SPIRV_Cross_CombinedcolorTexpointSampler;
uniform sampler2D SPIRV_Cross_CombinedcolorTexlinearSampler;

varying vec2 in_var_TEXCOORD0;
varying vec2 varying_TEXCOORD0;

void main()
{
gl_FragData[0] = texture2D(SPIRV_Cross_CombinedcolorTexpointSampler, in_var_TEXCOORD0) + texture2D(SPIRV_Cross_CombinedcolorTexlinearSampler, in_var_TEXCOORD0);
gl_FragData[0] = texture2D(SPIRV_Cross_CombinedcolorTexpointSampler, varying_TEXCOORD0) + texture2D(SPIRV_Cross_CombinedcolorTexlinearSampler, varying_TEXCOORD0);
}

4 changes: 2 additions & 2 deletions Source/Tests/Data/Expected/PassThrough_PS.300.essl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
precision mediump float;
precision highp int;

in highp vec4 in_var_COLOR;
in highp vec4 varying_COLOR;
layout(location = 0) out highp vec4 out_var_SV_Target;

void main()
{
out_var_SV_Target = in_var_COLOR;
out_var_SV_Target = varying_COLOR;
}

4 changes: 2 additions & 2 deletions Source/Tests/Data/Expected/PassThrough_PS.300.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#version 300
#extension GL_ARB_separate_shader_objects : require

layout(location = 0) in vec4 in_var_COLOR;
layout(location = 0) in vec4 varying_COLOR;
out vec4 out_var_SV_Target;

void main()
{
out_var_SV_Target = in_var_COLOR;
out_var_SV_Target = varying_COLOR;
}

4 changes: 2 additions & 2 deletions Source/Tests/Data/Expected/PassThrough_VS.300.essl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

layout(location = 0) in vec4 in_var_POSITION;
layout(location = 1) in vec2 in_var_TEXCOORD0;
out vec2 out_var_TEXCOORD0;
out vec2 varying_TEXCOORD0;

void main()
{
out_var_TEXCOORD0 = in_var_TEXCOORD0;
varying_TEXCOORD0 = in_var_TEXCOORD0;
gl_Position = in_var_POSITION;
}

4 changes: 2 additions & 2 deletions Source/Tests/Data/Expected/PassThrough_VS.300.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ out gl_PerVertex

in vec4 in_var_POSITION;
in vec2 in_var_TEXCOORD0;
layout(location = 0) out vec2 out_var_TEXCOORD0;
layout(location = 0) out vec2 varying_TEXCOORD0;

void main()
{
out_var_TEXCOORD0 = in_var_TEXCOORD0;
varying_TEXCOORD0 = in_var_TEXCOORD0;
gl_Position = in_var_POSITION;
}

6 changes: 3 additions & 3 deletions Source/Tests/Data/Expected/ToneMapping_PS.300.essl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ uniform highp sampler2D SPIRV_Cross_CombinedcolorTexpointSampler;
uniform highp sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler;
uniform highp sampler2D SPIRV_Cross_CombinedlumTexpointSampler;

in highp vec2 in_var_TEXCOORD0;
in highp vec2 varying_TEXCOORD0;
layout(location = 0) out highp vec4 out_var_SV_Target;

void main()
{
highp vec4 _45 = texture(SPIRV_Cross_CombinedcolorTexpointSampler, in_var_TEXCOORD0);
highp vec4 _45 = texture(SPIRV_Cross_CombinedcolorTexpointSampler, varying_TEXCOORD0);
highp vec3 _62 = (_45.xyz * (0.7200000286102294921875 / ((texture(SPIRV_Cross_CombinedlumTexpointSampler, vec2(0.5)).x * cbPS.lumStrength) + 0.001000000047497451305389404296875))).xyz;
highp vec3 _66 = (_62 * (vec3(1.0) + (_62 * vec3(0.666666686534881591796875)))).xyz;
highp vec3 _71 = (_66 / (vec3(1.0) + _66)).xyz + (texture(SPIRV_Cross_CombinedbloomTexlinearSampler, in_var_TEXCOORD0).xyz * 0.60000002384185791015625);
highp vec3 _71 = (_66 / (vec3(1.0) + _66)).xyz + (texture(SPIRV_Cross_CombinedbloomTexlinearSampler, varying_TEXCOORD0).xyz * 0.60000002384185791015625);
highp vec4 _73 = vec4(_71.x, _71.y, _71.z, _45.w);
_73.w = 1.0;
out_var_SV_Target = _73;
Expand Down
6 changes: 3 additions & 3 deletions Source/Tests/Data/Expected/ToneMapping_PS.300.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ uniform sampler2D SPIRV_Cross_CombinedcolorTexpointSampler;
uniform sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler;
uniform sampler2D SPIRV_Cross_CombinedlumTexpointSampler;

layout(location = 0) in vec2 in_var_TEXCOORD0;
layout(location = 0) in vec2 varying_TEXCOORD0;
out vec4 out_var_SV_Target;

void main()
{
vec4 _45 = texture(SPIRV_Cross_CombinedcolorTexpointSampler, in_var_TEXCOORD0);
vec4 _45 = texture(SPIRV_Cross_CombinedcolorTexpointSampler, varying_TEXCOORD0);
vec3 _62 = (_45.xyz * (0.7200000286102294921875 / ((texture(SPIRV_Cross_CombinedlumTexpointSampler, vec2(0.5)).x * cbPS.lumStrength) + 0.001000000047497451305389404296875))).xyz;
vec3 _66 = (_62 * (vec3(1.0) + (_62 * vec3(0.666666686534881591796875)))).xyz;
vec3 _71 = (_66 / (vec3(1.0) + _66)).xyz + (texture(SPIRV_Cross_CombinedbloomTexlinearSampler, in_var_TEXCOORD0).xyz * 0.60000002384185791015625);
vec3 _71 = (_66 / (vec3(1.0) + _66)).xyz + (texture(SPIRV_Cross_CombinedbloomTexlinearSampler, varying_TEXCOORD0).xyz * 0.60000002384185791015625);
vec4 _73 = vec4(_71.x, _71.y, _71.z, _45.w);
_73.w = 1.0;
out_var_SV_Target = _73;
Expand Down
4 changes: 2 additions & 2 deletions Source/Tests/ShaderConductorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ namespace
std::ofstream actualFile(TEST_DATA_DIR "Result/" + compareName, mode);
actualFile.write(reinterpret_cast<const char*>(actual.data()), actual.size());
}

EXPECT_TRUE(false);
}

EXPECT_EQ(std::string(expected.begin(), expected.end()), std::string(actual.begin(), actual.end()));
}

void HlslToAnyTest(const std::string& name, const Compiler::SourceDesc& source, const Compiler::Options& options,
Expand Down

0 comments on commit f75d8c7

Please sign in to comment.