postmerge: change how array initializers are emitted, plus tests for the behavior flip flag

This commit is contained in:
Aras Pranckevicius 2012-09-27 17:35:56 +03:00
Родитель 803cf678c6
Коммит 7ef842b61e
8 изменённых файлов: 107 добавлений и 28 удалений

Просмотреть файл

@ -298,7 +298,7 @@ TGlslOutputTraverser::TGlslOutputTraverser(TInfoSink& i, std::vector<GlslFunctio
, structList(sList)
, swizzleAssignTempCounter(0)
, m_UsePrecision(options & ETranslateOpUsePrecision)
, m_EmitSnowLeopardCompatibleArrayInitializers(options & ETranslateOpEmitSnowLeopardCompatibleArrayInitializers)
, emitGLSL120ArrayInitializers(options & ETranslateOpEmitGLSL120ArrayInitializers)
{
m_LastLineOutput.file = NULL;
m_LastLineOutput.line = -1;
@ -329,15 +329,14 @@ bool TGlslOutputTraverser::traverseDeclaration(bool preVisit, TIntermDeclaration
EGlslSymbolType symbol_type = translateType(decl->getTypePointer());
TType& type = *decl->getTypePointer();
bool emit_osx10_6_arrays = goit->m_EmitSnowLeopardCompatibleArrayInitializers
const bool emit_pre_glsl_120_arrays = !goit->emitGLSL120ArrayInitializers
&& decl->containsArrayInitialization();
if (emit_osx10_6_arrays) {
assert(decl->isSingleInitialization() && "Emission of multiple in-line array declarations isn't supported when running in OS X 10.6 compatible mode.");
if (emit_pre_glsl_120_arrays) {
assert(decl->isSingleInitialization() && "Emission of multiple in-line array declarations isn't supported when running in pre-GLSL1.20 compatible mode.");
current->indent(out);
out << "#if defined(OSX_SNOW_LEOPARD)" << std::endl;
out << "#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)" << std::endl;
current->increaseDepth();
TQualifier q = type.getQualifier();
@ -392,7 +391,7 @@ bool TGlslOutputTraverser::traverseDeclaration(bool preVisit, TIntermDeclaration
current->endStatement();
if (emit_osx10_6_arrays) {
if (emit_pre_glsl_120_arrays) {
current->decreaseDepth();
current->indent(out);
out << "#endif" << std::endl;

Просмотреть файл

@ -61,10 +61,10 @@ public:
// Persistent data for collecting indices
std::vector<int> indexList;
unsigned swizzleAssignTempCounter;
bool m_UsePrecision;
bool m_EmitSnowLeopardCompatibleArrayInitializers;
TSourceLoc m_LastLineOutput;
unsigned swizzleAssignTempCounter;
bool m_UsePrecision;
bool emitGLSL120ArrayInitializers;
};
#endif //GLSL_OUTPUT_H

Просмотреть файл

@ -129,9 +129,10 @@ enum TTranslateOptions
ETranslateOpIntermediate = (1<<0),
ETranslateOpUsePrecision = (1<<1),
/// Array initializers on OS X 10.6.X GLSL 1.20 are broken. Enabling this flag will tell the compiler
/// to emit two versions of all array initializations, one that is compatible with snow leopard and one that
/// is standard GLSL 1.20.
/// 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.
///
/// Example of emitted code for a simple array declaration:
/// (HLSL Source)
@ -141,15 +142,18 @@ enum TTranslateOptions
/// float2(1, 0.1)
/// };
/// (GLSL Emitted result)
/// #if defined(OSX_SNOW_LEOPARD)
/// vec2[] samples;
/// samples[0] = vec2(-1.0, 0.1);
/// samples[0] = vec2(0.0, 0.5);
/// samples[0] = vec2(1.0, 0.1);
/// #else
/// #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
/// vec2 samples[];
/// samples[0] = vec2(-1.0, 0.1);
/// samples[1] = vec2(0.0, 0.5);
/// samples[2] = vec2(1.0, 0.1);
/// #endif
ETranslateOpEmitSnowLeopardCompatibleArrayInitializers = (1<<2)
///
/// 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<<2)
};

Просмотреть файл

@ -0,0 +1,11 @@
half4 main () : COLOR0 {
float2 lut[] = {
float2(-1, 0.1),
float2(0, 0.5),
float2(1, 0.1)
};
half4 c = 0;
for (int i = 0; i < 3; ++i)
c.xy += lut[i];
return c;
}

Просмотреть файл

@ -0,0 +1,25 @@
vec4 xlat_main( );
#line 1
vec4 xlat_main( ) {
#line 2
#if !defined(HLSL2GLSL_ENABLE_ARRAY_INIT)
vec2[3] lut;
lut = vec2( float((-1)), 0.1);
lut = vec2( 0.0, 0.5);
lut = vec2( 1.0, 0.1);
#else
vec2 lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1))[3];
#endif
#line 7
vec4 c = vec4( 0.0);
int i = 0;
for ( ; (i < 3); (++i)) {
c.xy += lut[i];
}
return c;
}
void main() {
vec4 xl_retval;
xl_retval = xlat_main( );
gl_FragData[0] = vec4( xl_retval);
}

Просмотреть файл

@ -0,0 +1,15 @@
// "arrayglsl120" in the name will make hlsl2glsl test driver
// enable "full GLSL 1.20" array printing mode.
// This is a test to ensure it keeps on working.
half4 main () : COLOR0 {
float2 lut[] = {
float2(-1, 0.1),
float2(0, 0.5),
float2(1, 0.1)
};
half4 c = 0;
for (int i = 0; i < 3; ++i)
c.xy += lut[i];
return c;
}

Просмотреть файл

@ -0,0 +1,18 @@
vec4 xlat_main( );
#line 5
vec4 xlat_main( ) {
#line 6
vec2 lut = vec2[3]( vec2( float((-1)), 0.1), vec2( 0.0, 0.5), vec2( 1.0, 0.1))[3];
#line 11
vec4 c = vec4( 0.0);
int i = 0;
for ( ; (i < 3); (++i)) {
c.xy += lut[i];
}
return c;
}
void main() {
vec4 xl_retval;
xl_retval = xlat_main( );
gl_FragData[0] = vec4( xl_retval);
}

Просмотреть файл

@ -242,6 +242,7 @@ static bool TestFile (TestRun type,
const std::string& outputPath,
const char* entryPoint,
bool usePrecision,
bool useGLSL120Arrays,
bool doCheckGLSL)
{
std::string input;
@ -264,7 +265,11 @@ static bool TestFile (TestRun type,
if (usePrecision)
options |= ETranslateOpUsePrecision;
options |= ETranslateOpEmitSnowLeopardCompatibleArrayInitializers;
if (useGLSL120Arrays)
{
assert (!usePrecision); // GLES 1.0 can't do that
options |= ETranslateOpEmitGLSL120ArrayInitializers;
}
int parseOk = Hlsl2Glsl_Parse (parser, sourceStr, options);
const char* infoLog = Hlsl2Glsl_GetInfoLog( parser );
@ -410,14 +415,15 @@ static bool TestCombinedFile(const std::string& inputPath,
frag_out = outname + "-fragment-out.txt";
}
bool res = TestFile(VERTEX, inputPath, vert_out, "vs_main", usePrecision, !usePrecision && checkGL);
return res & TestFile(FRAGMENT, inputPath, frag_out, "ps_main", usePrecision, !usePrecision && checkGL);
bool res = TestFile(VERTEX, inputPath, vert_out, "vs_main", usePrecision, false, !usePrecision && checkGL);
return res & TestFile(FRAGMENT, inputPath, frag_out, "ps_main", usePrecision, false, !usePrecision && checkGL);
}
static bool TestFile (TestRun type,
const std::string& inputPath,
bool usePrecision,
bool useGLSL120Arrays,
bool checkGL)
{
std::string outname = inputPath.substr (0,inputPath.size()-7);
@ -426,9 +432,9 @@ static bool TestFile (TestRun type,
return TestFileFailure(type==VERTEX_FAILURES, inputPath, outname + "-out.txt");
} else {
if (usePrecision) {
return TestFile(type, inputPath, outname + "-outES.txt", "main", true, false);
return TestFile(type, inputPath, outname + "-outES.txt", "main", true, useGLSL120Arrays, false);
} else {
return TestFile(type, inputPath, outname + "-out.txt", "main", false, checkGL);
return TestFile(type, inputPath, outname + "-out.txt", "main", false, useGLSL120Arrays, checkGL);
}
}
return false;
@ -487,9 +493,10 @@ int main (int argc, const char** argv)
if (ok)
ok = TestCombinedFile(testFolder + "/" + inname, true, false);
} else {
ok = TestFile(TestRun(type), testFolder + "/" + inname, false, hasOpenGL);
if (ok)
ok = TestFile(TestRun(type), testFolder + "/" + inname, true, false);
const bool useGLSL120Arrays = (inname.find("arrayglsl120") != std::string::npos);
ok = TestFile(TestRun(type), testFolder + "/" + inname, false, useGLSL120Arrays, hasOpenGL);
if (ok && !useGLSL120Arrays)
ok = TestFile(TestRun(type), testFolder + "/" + inname, true, false, false);
}
if (!ok)