by default emit GLSL1.20 array initializers; the flag optionally kicks in the workaround
This commit is contained in:
Родитель
f865749129
Коммит
67f5b0ea56
|
@ -299,7 +299,7 @@ TGlslOutputTraverser::TGlslOutputTraverser(TInfoSink& i, std::vector<GlslFunctio
|
|||
, swizzleAssignTempCounter(0)
|
||||
, m_TargetVersion(version)
|
||||
, m_UsePrecision(Hlsl2Glsl_VersionUsesPrecision(version))
|
||||
, emitGLSL120ArrayInitializers(options & ETranslateOpEmitGLSL120ArrayInitializers)
|
||||
, m_ArrayInitWorkaround(options & ETranslateOpEmitGLSL120ArrayInitWorkaround)
|
||||
{
|
||||
m_LastLineOutput.file = NULL;
|
||||
m_LastLineOutput.line = -1;
|
||||
|
@ -335,13 +335,13 @@ void TGlslOutputTraverser::traverseArrayDeclarationWithInit(TIntermDeclaration*
|
|||
EGlslSymbolType symbol_type = translateType(decl->getTypePointer());
|
||||
|
||||
const bool emit_120_arrays = (m_TargetVersion >= ETargetGLSL_120);
|
||||
const bool emit_old_arrays = !emit_120_arrays || !this->emitGLSL120ArrayInitializers;
|
||||
const bool emit_old_arrays = !emit_120_arrays || m_ArrayInitWorkaround;
|
||||
const bool emit_both = emit_120_arrays && emit_old_arrays;
|
||||
|
||||
if (emit_both)
|
||||
{
|
||||
current->indent(out);
|
||||
out << "#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)" << std::endl;
|
||||
out << "#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)" << std::endl;
|
||||
current->increaseDepth();
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
unsigned swizzleAssignTempCounter;
|
||||
ETargetVersion m_TargetVersion;
|
||||
bool m_UsePrecision;
|
||||
bool emitGLSL120ArrayInitializers;
|
||||
bool m_ArrayInitWorkaround;
|
||||
};
|
||||
|
||||
#endif //GLSL_OUTPUT_H
|
||||
|
|
|
@ -140,11 +140,11 @@ enum TTranslateOptions
|
|||
{
|
||||
ETranslateOpNone = 0,
|
||||
ETranslateOpIntermediate = (1<<0),
|
||||
|
||||
/// Array initializers do not exist on GLSL ES 1.0, and are broken on
|
||||
/// OS X 10.6.x with GLSL 1.20 as well. By default we'll emit code
|
||||
/// that can handle both cases, with "real" initialization path
|
||||
/// kicking in only when you've defined HLSL2GLSL_ENABLE_ARRAY_INIT.
|
||||
|
||||
/// Some drivers (e.g. OS X 10.6.x) have bugs with GLSL 1.20 array
|
||||
/// initializer syntax. If you need to support this configuration,
|
||||
/// use this flag to generate compatible syntax. You'll need
|
||||
/// to prepend HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND to the shader.
|
||||
///
|
||||
/// Example of emitted code for a simple array declaration:
|
||||
/// (HLSL Source)
|
||||
|
@ -154,18 +154,15 @@ enum TTranslateOptions
|
|||
/// float2(1, 0.1)
|
||||
/// };
|
||||
/// (GLSL Emitted result)
|
||||
/// #if defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
|
||||
/// const vec2 samples[] = vec2[](vec2(-1.0, 0.1), vec2(0.0, 0.5), vec2(1.0, 0.1));
|
||||
/// #else
|
||||
/// #if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)
|
||||
/// vec2 samples[];
|
||||
/// samples[0] = vec2(-1.0, 0.1);
|
||||
/// samples[1] = vec2(0.0, 0.5);
|
||||
/// samples[2] = vec2(1.0, 0.1);
|
||||
/// #else
|
||||
/// const vec2 samples[] = vec2[](vec2(-1.0, 0.1), vec2(0.0, 0.5), vec2(1.0, 0.1));
|
||||
/// #endif
|
||||
///
|
||||
/// If you don't need GLSL ES 1.0 support, or OS X 10.6.x support,
|
||||
/// then pass this flag to always use "real" array initializers.
|
||||
ETranslateOpEmitGLSL120ArrayInitializers = (1<<1),
|
||||
ETranslateOpEmitGLSL120ArrayInitWorkaround = (1<<1),
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,26 +1,8 @@
|
|||
#version 120
|
||||
#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
|
||||
float lut1[3];
|
||||
lut1[0] = 0.1;
|
||||
lut1[1] = 0.2;
|
||||
lut1[2] = 0.3;
|
||||
#else
|
||||
const float[3] lut1 = float[3]( 0.1, 0.2, 0.3);
|
||||
#endif
|
||||
#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
|
||||
vec2 lut2[2];
|
||||
lut2[0] = vec2( 0.1, 0.2);
|
||||
lut2[1] = vec2( 0.2, 0.3);
|
||||
#else
|
||||
const vec2[2] lut2 = vec2[2]( vec2( 0.1, 0.2), vec2( 0.2, 0.3));
|
||||
#endif
|
||||
const float[3] lut1 = float[3]( 0.1, 0.2, 0.3);
|
||||
const vec2[2] lut2 = vec2[2]( vec2( 0.1, 0.2), vec2( 0.2, 0.3));
|
||||
#line 3
|
||||
#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
|
||||
vec4 lut4[1];
|
||||
lut4[0] = vec4( 0.1, 0.2, 0.3, 0.4);
|
||||
#else
|
||||
const vec4[1] lut4 = vec4[1]( vec4( 0.1, 0.2, 0.3, 0.4));
|
||||
#endif
|
||||
const vec4[1] lut4 = vec4[1]( vec4( 0.1, 0.2, 0.3, 0.4));
|
||||
vec4 xlat_main( );
|
||||
#line 5
|
||||
vec4 xlat_main( ) {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#version 120
|
||||
#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)
|
||||
float lut1[3];
|
||||
lut1[0] = 0.1;
|
||||
lut1[1] = 0.2;
|
||||
lut1[2] = 0.3;
|
||||
#else
|
||||
const float[3] lut1 = float[3]( 0.1, 0.2, 0.3);
|
||||
#endif
|
||||
#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)
|
||||
vec2 lut2[2];
|
||||
lut2[0] = vec2( 0.1, 0.2);
|
||||
lut2[1] = vec2( 0.2, 0.3);
|
||||
#else
|
||||
const vec2[2] lut2 = vec2[2]( vec2( 0.1, 0.2), vec2( 0.2, 0.3));
|
||||
#endif
|
||||
#line 3
|
||||
#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)
|
||||
vec4 lut4[1];
|
||||
lut4[0] = vec4( 0.1, 0.2, 0.3, 0.4);
|
||||
#else
|
||||
const vec4[1] lut4 = vec4[1]( vec4( 0.1, 0.2, 0.3, 0.4));
|
||||
#endif
|
||||
vec4 xlat_main( );
|
||||
#line 5
|
||||
vec4 xlat_main( ) {
|
||||
#line 7
|
||||
vec4 c = vec4( 0.0);
|
||||
int i = 0;
|
||||
for ( ; (i < 3); (++i)) {
|
||||
c.x += lut1[i];
|
||||
}
|
||||
int i_1 = 0;
|
||||
for ( ; (i_1 < 2); (++i_1)) {
|
||||
c.xy += lut2[i_1];
|
||||
}
|
||||
#line 12
|
||||
c += lut4[0];
|
||||
return c;
|
||||
}
|
||||
void main() {
|
||||
vec4 xl_retval;
|
||||
xl_retval = xlat_main( );
|
||||
gl_FragData[0] = vec4(xl_retval);
|
||||
}
|
|
@ -3,14 +3,7 @@ vec4 xlat_main( );
|
|||
#line 5
|
||||
vec4 xlat_main( ) {
|
||||
#line 6
|
||||
#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
|
||||
vec2 lut[3];
|
||||
lut[0] = vec2( float((-1)), 0.1);
|
||||
lut[1] = vec2( 0.0, 0.5);
|
||||
lut[2] = vec2( 1.0, 0.1);
|
||||
#else
|
||||
vec2[3] lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1));
|
||||
#endif
|
||||
vec2[3] lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1));
|
||||
#line 11
|
||||
vec4 c = vec4( 0.0);
|
||||
int i = 0;
|
||||
|
|
|
@ -3,7 +3,14 @@ vec4 xlat_main( );
|
|||
#line 5
|
||||
vec4 xlat_main( ) {
|
||||
#line 6
|
||||
vec2[3] lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1));
|
||||
#if defined(HLSL2GLSL_ENABLE_ARRAY_120_WORKAROUND)
|
||||
vec2 lut[3];
|
||||
lut[0] = vec2( float((-1)), 0.1);
|
||||
lut[1] = vec2( 0.0, 0.5);
|
||||
lut[2] = vec2( 1.0, 0.1);
|
||||
#else
|
||||
vec2[3] lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1));
|
||||
#endif
|
||||
#line 11
|
||||
vec4 c = vec4( 0.0);
|
||||
int i = 0;
|
||||
|
|
|
@ -517,7 +517,7 @@ static bool TestFile (TestRun type,
|
|||
const char* suffix = "-out.txt";
|
||||
if (version == ETargetGLSL_ES_100)
|
||||
suffix = "-outES.txt";
|
||||
else if (options & ETranslateOpEmitGLSL120ArrayInitializers)
|
||||
else if (options & ETranslateOpEmitGLSL120ArrayInitWorkaround)
|
||||
suffix = "-out120arr.txt";
|
||||
|
||||
if (type == VERTEX_FAILURES || type == FRAGMENT_FAILURES) {
|
||||
|
@ -586,7 +586,7 @@ int main (int argc, const char** argv)
|
|||
} else {
|
||||
ok = TestFile(TestRun(type), testFolder + "/" + inname, version1, 0, hasOpenGL);
|
||||
if (ok && version2 != ETargetVersionCount)
|
||||
ok = TestFile(TestRun(type), testFolder + "/" + inname, version2, ETranslateOpEmitGLSL120ArrayInitializers, hasOpenGL);
|
||||
ok = TestFile(TestRun(type), testFolder + "/" + inname, version2, ETranslateOpEmitGLSL120ArrayInitWorkaround, hasOpenGL);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
|
|
Загрузка…
Ссылка в новой задаче