Skip to content

Commit 3efaa6d

Browse files
committed
Fixed array arguments during conversion from HLSL to GLSL
1 parent be63583 commit 3efaa6d

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ void InitVariable(const String& Name, const String& InitValue, std::stringstream
27762776
OutSS << " " << Name << " = " << InitValue << ";\n";
27772777
}
27782778

2779-
void DefineInterfaceVar(int location, const char* interpolation, const char* inout, const String& ParamType, const String& ParamName, std::stringstream& OutSS)
2779+
void DefineInterfaceVar(int location, const char* interpolation, const char* inout, const String& ParamType, const String& ParamName, const String& ArraySize, std::stringstream& OutSS)
27802780
{
27812781
if (location >= 0)
27822782
{
@@ -2786,7 +2786,12 @@ void DefineInterfaceVar(int location, const char* interpolation, const char* ino
27862786
{
27872787
OutSS << interpolation << ' ';
27882788
}
2789-
OutSS << inout << ' ' << ParamType << ' ' << ParamName << ";\n";
2789+
OutSS << inout << ' ' << ParamType << ' ' << ParamName;
2790+
if (!ArraySize.empty())
2791+
{
2792+
OutSS << '[' << ArraySize << ']';
2793+
}
2794+
OutSS << ";\n";
27902795
}
27912796

27922797
String HLSL2GLSLConverterImpl::ConversionStream::BuildParameterName(
@@ -2944,7 +2949,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessFragmentShaderArguments(To
29442949
auto InputVarName = BuildParameterName(MemberStack, '_', m_bUseInOutLocationQualifiers ? "_psin_" : "_");
29452950
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? InLocation++ : -1,
29462951
GetInterpolationQualifier(Param), "in",
2947-
Param.Type, InputVarName, InterfaceVarsSS);
2952+
Param.Type, InputVarName, MemberStack.back()->ArraySize, InterfaceVarsSS);
29482953
InitVariable(FullParamName, InputVarName, PrologueSS);
29492954
}
29502955
} //
@@ -2986,7 +2991,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessFragmentShaderArguments(To
29862991
String OutVarName = BuildParameterName(MemberStack, '_', "_psout_");
29872992
// Fragment shader outputs can't have interpolation qualifiers
29882993
const char* Interpolation = nullptr;
2989-
DefineInterfaceVar(RTIndex, Interpolation, "out", Param.Type, OutVarName, GlobalVarsSS);
2994+
DefineInterfaceVar(RTIndex, Interpolation, "out", Param.Type, OutVarName, MemberStack.back()->ArraySize, GlobalVarsSS);
29902995
ReturnHandlerSS << OutVarName << " = " << FullParamName << ";\\\n";
29912996
}
29922997
else
@@ -3051,7 +3056,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessVertexShaderArguments(std:
30513056
// Interpolation qualifiers are not allowed on VS inputs.
30523057
const char* Interpolation = nullptr;
30533058
// Layout location qualifiers are allowed on VS inputs even in GLES3.0.
3054-
DefineInterfaceVar(InputLocation, Interpolation, "in", Param.Type, InputVarName, GlobalVarsSS);
3059+
DefineInterfaceVar(InputLocation, Interpolation, "in", Param.Type, InputVarName, MemberStack.back()->ArraySize, GlobalVarsSS);
30553060
InitVariable(FullParamName, InputVarName, PrologueSS);
30563061
AutoInputLocation++;
30573062
}
@@ -3073,7 +3078,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessVertexShaderArguments(std:
30733078
auto OutputVarName = BuildParameterName(MemberStack, '_', m_bUseInOutLocationQualifiers ? "_vsout_" : "_");
30743079
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? OutLocation++ : -1,
30753080
GetInterpolationQualifier(Param), "out",
3076-
Param.Type, OutputVarName, InterfaceVarsSS);
3081+
Param.Type, OutputVarName, MemberStack.back()->ArraySize, InterfaceVarsSS);
30773082
ReturnHandlerSS << OutputVarName << " = " << FullParamName << ";\\\n";
30783083
}
30793084
} //
@@ -3167,7 +3172,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessGeometryShaderArguments(To
31673172
auto InputVarName = VarName + "[i]";
31683173
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? inLocation++ : -1,
31693174
GetInterpolationQualifier(Param), "in",
3170-
Param.Type, VarName + "[]", InterfaceVarsInSS);
3175+
Param.Type, VarName + "[]", "", InterfaceVarsInSS);
31713176
InitVariable(FullIndexedParamName, InputVarName, PrologueSS);
31723177
}
31733178
} //
@@ -3211,7 +3216,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessGeometryShaderArguments(To
32113216
auto OutputVarName = BuildParameterName(MemberStack, '_', m_bUseInOutLocationQualifiers ? "_gsout_" : "_");
32123217
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? outLocation++ : -1,
32133218
GetInterpolationQualifier(Param), "out",
3214-
Param.Type, OutputVarName, InterfaceVarsOutSS);
3219+
Param.Type, OutputVarName, MemberStack.back()->ArraySize, InterfaceVarsOutSS);
32153220
EmitVertexDefineSS << OutputVarName << " = " << MacroArgumentName << ";\\\n";
32163221
}
32173222
} //
@@ -3724,7 +3729,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessHullShaderArguments(TokenL
37243729
// User-defined inputs can be declared as unbounded arrays
37253730
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? inLocation++ : -1,
37263731
GetInterpolationQualifier(Param), "in",
3727-
Param.Type, VarName + (IsPatch ? "[]" : ""), InterfaceVarsInSS);
3732+
Param.Type, VarName + (IsPatch ? "[]" : ""), "", InterfaceVarsInSS);
37283733
InitVariable(FullIndexedParamName, InputVarName, PrologueSS);
37293734
}
37303735
} //
@@ -3757,7 +3762,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessHullShaderArguments(TokenL
37573762
// https://www.khronos.org/opengl/wiki/Tessellation_Control_Shader#Outputs
37583763
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? outLocation++ : -1,
37593764
GetInterpolationQualifier(Param), "out",
3760-
Param.Type, OutputVarName + "[]", InterfaceVarsOutSS);
3765+
Param.Type, OutputVarName + "[]", "", InterfaceVarsOutSS);
37613766
// A TCS can only ever write to the per-vertex output variable that corresponds to their invocation,
37623767
// so writes to per-vertex outputs must be of the form vertexTexCoord[gl_InvocationID]
37633768
ReturnHandlerSS << OutputVarName << "[gl_InvocationID] = " << SrcParamName << ";\\\n";
@@ -3941,7 +3946,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessDomainShaderArguments(Toke
39413946
// User-defined inputs can be declared as unbounded arrays
39423947
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? inLocation++ : -1,
39433948
GetInterpolationQualifier(Param), "in",
3944-
Param.Type, VarName + (IsPatch ? "[]" : ""), InterfaceVarsInSS);
3949+
Param.Type, VarName + (IsPatch ? "[]" : ""), "", InterfaceVarsInSS);
39453950
InitVariable(FullIndexedParamName, InputVarName, PrologueSS);
39463951
}
39473952
else
@@ -3969,7 +3974,7 @@ void HLSL2GLSLConverterImpl::ConversionStream::ProcessDomainShaderArguments(Toke
39693974
// https://www.khronos.org/opengl/wiki/Tessellation_Control_Shader#Outputs
39703975
DefineInterfaceVar(m_bUseInOutLocationQualifiers ? outLocation++ : -1,
39713976
GetInterpolationQualifier(Param), "out",
3972-
Param.Type, OutputVarName, InterfaceVarsOutSS);
3977+
Param.Type, OutputVarName, MemberStack.back()->ArraySize, InterfaceVarsOutSS);
39733978
// A TCS can only ever write to the per-vertex output variable that corresponds to their invocation,
39743979
// so writes to per-vertex outputs must be of the form vertexTexCoord[gl_InvocationID]
39753980
ReturnHandlerSS << OutputVarName << " = " << SrcParamName << ";\\\n";

0 commit comments

Comments
 (0)