diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index 7eab82fa..71aa484a 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -585,6 +585,36 @@ namespace compiler = std::make_unique(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: diff --git a/Source/Tests/Data/Expected/IncludeExist.glsl b/Source/Tests/Data/Expected/IncludeExist.glsl index 0faaf86c..ab109ce6 100644 --- a/Source/Tests/Data/Expected/IncludeExist.glsl +++ b/Source/Tests/Data/Expected/IncludeExist.glsl @@ -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); } diff --git a/Source/Tests/Data/Expected/PassThrough_PS.300.essl b/Source/Tests/Data/Expected/PassThrough_PS.300.essl index 682993fc..01fbd4a1 100644 --- a/Source/Tests/Data/Expected/PassThrough_PS.300.essl +++ b/Source/Tests/Data/Expected/PassThrough_PS.300.essl @@ -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; } diff --git a/Source/Tests/Data/Expected/PassThrough_PS.300.glsl b/Source/Tests/Data/Expected/PassThrough_PS.300.glsl index 0eb93082..c3822063 100644 --- a/Source/Tests/Data/Expected/PassThrough_PS.300.glsl +++ b/Source/Tests/Data/Expected/PassThrough_PS.300.glsl @@ -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; } diff --git a/Source/Tests/Data/Expected/PassThrough_VS.300.essl b/Source/Tests/Data/Expected/PassThrough_VS.300.essl index b2c7390b..c508ac1f 100644 --- a/Source/Tests/Data/Expected/PassThrough_VS.300.essl +++ b/Source/Tests/Data/Expected/PassThrough_VS.300.essl @@ -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; } diff --git a/Source/Tests/Data/Expected/PassThrough_VS.300.glsl b/Source/Tests/Data/Expected/PassThrough_VS.300.glsl index 880edc3b..c7f36518 100644 --- a/Source/Tests/Data/Expected/PassThrough_VS.300.glsl +++ b/Source/Tests/Data/Expected/PassThrough_VS.300.glsl @@ -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; } diff --git a/Source/Tests/Data/Expected/ToneMapping_PS.300.essl b/Source/Tests/Data/Expected/ToneMapping_PS.300.essl index 7a683c45..946904a7 100644 --- a/Source/Tests/Data/Expected/ToneMapping_PS.300.essl +++ b/Source/Tests/Data/Expected/ToneMapping_PS.300.essl @@ -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; diff --git a/Source/Tests/Data/Expected/ToneMapping_PS.300.glsl b/Source/Tests/Data/Expected/ToneMapping_PS.300.glsl index f0a4b0f4..bc44ac55 100644 --- a/Source/Tests/Data/Expected/ToneMapping_PS.300.glsl +++ b/Source/Tests/Data/Expected/ToneMapping_PS.300.glsl @@ -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; diff --git a/Source/Tests/ShaderConductorTest.cpp b/Source/Tests/ShaderConductorTest.cpp index 0f710f09..01a9400b 100644 --- a/Source/Tests/ShaderConductorTest.cpp +++ b/Source/Tests/ShaderConductorTest.cpp @@ -72,9 +72,9 @@ namespace std::ofstream actualFile(TEST_DATA_DIR "Result/" + compareName, mode); actualFile.write(reinterpret_cast(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,