Commit 95cd3c68 by Olli Etuaho

Move some output out of BuiltInFunctionEmulator subclasses

This paves the way for getting rid of the BuiltInFunctionEmulator subclasses in favor of initializing the BuiltInFunctionEmulator dynamically in Compiler subclasses. The eventual goal is getting rid of GLSL output specific functionality in Compiler, which should be language-agnostic. BUG=angle:865 Change-Id: Ibb114b905785c7343b2726c97699268c982536a0 Reviewed-on: https://chromium-review.googlesource.com/255470Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent c4ba3bef
...@@ -26,15 +26,15 @@ class BuiltInFunctionEmulator ...@@ -26,15 +26,15 @@ class BuiltInFunctionEmulator
// "name(" becomes "webgl_name_emu(". // "name(" becomes "webgl_name_emu(".
static TString GetEmulatedFunctionName(const TString& name); static TString GetEmulatedFunctionName(const TString& name);
protected:
BuiltInFunctionEmulator();
bool IsOutputEmpty() const; bool IsOutputEmpty() const;
// Output function emulation definition. This should be before any other // Output function emulation definition. This should be before any other
// shader source. // shader source.
void OutputEmulatedFunctions(TInfoSinkBase& out) const; void OutputEmulatedFunctions(TInfoSinkBase& out) const;
protected:
BuiltInFunctionEmulator();
// Add functions that need to be emulated. // Add functions that need to be emulated.
void AddEmulatedFunction(TOperator op, const TType& param, const char* emulatedFunctionDefinition); void AddEmulatedFunction(TOperator op, const TType& param, const char* emulatedFunctionDefinition);
void AddEmulatedFunction(TOperator op, const TType& param1, const TType& param2, const char* emulatedFunctionDefinition); void AddEmulatedFunction(TOperator op, const TType& param1, const TType& param2, const char* emulatedFunctionDefinition);
......
...@@ -37,23 +37,3 @@ BuiltInFunctionEmulatorGLSL::BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType) ...@@ -37,23 +37,3 @@ BuiltInFunctionEmulatorGLSL::BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType)
AddEmulatedFunction(EOpReflect, float1, float1, "#define webgl_reflect_emu(I, N) ((I) - 2.0 * (N) * (I) * (N))"); AddEmulatedFunction(EOpReflect, float1, float1, "#define webgl_reflect_emu(I, N) ((I) - 2.0 * (N) * (I) * (N))");
#endif #endif
} }
void BuiltInFunctionEmulatorGLSL::OutputEmulatedFunctionDefinition(
TInfoSinkBase& out, bool withPrecision) const
{
if (IsOutputEmpty())
return;
out << "// BEGIN: Generated code for built-in function emulation\n\n";
if (withPrecision) {
out << "#if defined(GL_FRAGMENT_PRECISION_HIGH)\n"
<< "#define webgl_emu_precision highp\n"
<< "#else\n"
<< "#define webgl_emu_precision mediump\n"
<< "#endif\n\n";
} else {
out << "#define webgl_emu_precision\n\n";
}
OutputEmulatedFunctions(out);
out << "// END: Generated code for built-in function emulation\n\n";
}
...@@ -16,8 +16,6 @@ class BuiltInFunctionEmulatorGLSL : public BuiltInFunctionEmulator ...@@ -16,8 +16,6 @@ class BuiltInFunctionEmulatorGLSL : public BuiltInFunctionEmulator
{ {
public: public:
BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType); BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType);
void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
}; };
#endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORGLSL_H_ #endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORGLSL_H_
...@@ -408,9 +408,3 @@ BuiltInFunctionEmulatorHLSL::BuiltInFunctionEmulatorHLSL() ...@@ -408,9 +408,3 @@ BuiltInFunctionEmulatorHLSL::BuiltInFunctionEmulatorHLSL()
" return cof / determinant(transpose(m));\n" " return cof / determinant(transpose(m));\n"
"}\n"); "}\n");
} }
void BuiltInFunctionEmulatorHLSL::OutputEmulatedFunctionDefinition(
TInfoSinkBase& out) const
{
OutputEmulatedFunctions(out);
}
...@@ -16,8 +16,6 @@ class BuiltInFunctionEmulatorHLSL : public BuiltInFunctionEmulator ...@@ -16,8 +16,6 @@ class BuiltInFunctionEmulatorHLSL : public BuiltInFunctionEmulator
{ {
public: public:
BuiltInFunctionEmulatorHLSL(); BuiltInFunctionEmulatorHLSL();
void OutputEmulatedFunctionDefinition(TInfoSinkBase& out) const;
}; };
#endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORHLSL_H_ #endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORHLSL_H_
...@@ -1266,7 +1266,7 @@ void OutputHLSL::header(const BuiltInFunctionEmulatorHLSL *builtInFunctionEmulat ...@@ -1266,7 +1266,7 @@ void OutputHLSL::header(const BuiltInFunctionEmulatorHLSL *builtInFunctionEmulat
"\n"; "\n";
} }
builtInFunctionEmulator->OutputEmulatedFunctionDefinition(out); builtInFunctionEmulator->OutputEmulatedFunctions(out);
} }
void OutputHLSL::visitSymbol(TIntermSymbol *node) void OutputHLSL::visitSymbol(TIntermSymbol *node)
......
...@@ -34,8 +34,25 @@ void TranslatorESSL::translate(TIntermNode *root, int) { ...@@ -34,8 +34,25 @@ void TranslatorESSL::translate(TIntermNode *root, int) {
} }
// Write emulated built-in functions if needed. // Write emulated built-in functions if needed.
getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition( if (!getBuiltInFunctionEmulator().IsOutputEmpty())
sink, getShaderType() == GL_FRAGMENT_SHADER); {
sink << "// BEGIN: Generated code for built-in function emulation\n\n";
if (getShaderType() == GL_FRAGMENT_SHADER)
{
sink << "#if defined(GL_FRAGMENT_PRECISION_HIGH)\n"
<< "#define webgl_emu_precision highp\n"
<< "#else\n"
<< "#define webgl_emu_precision mediump\n"
<< "#endif\n\n";
}
else
{
sink << "#define webgl_emu_precision highp\n";
}
getBuiltInFunctionEmulator().OutputEmulatedFunctions(sink);
sink << "// END: Generated code for built-in function emulation\n\n";
}
// Write array bounds clamping emulation if needed. // Write array bounds clamping emulation if needed.
getArrayBoundsClamper().OutputClampingFunctionDefinition(sink); getArrayBoundsClamper().OutputClampingFunctionDefinition(sink);
......
...@@ -83,8 +83,13 @@ void TranslatorGLSL::translate(TIntermNode *root, int) { ...@@ -83,8 +83,13 @@ void TranslatorGLSL::translate(TIntermNode *root, int) {
} }
// Write emulated built-in functions if needed. // Write emulated built-in functions if needed.
getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition( if (!getBuiltInFunctionEmulator().IsOutputEmpty())
sink, false); {
sink << "// BEGIN: Generated code for built-in function emulation\n\n";
sink << "#define webgl_emu_precision\n\n";
getBuiltInFunctionEmulator().OutputEmulatedFunctions(sink);
sink << "// END: Generated code for built-in function emulation\n\n";
}
// Write array bounds clamping emulation if needed. // Write array bounds clamping emulation if needed.
getArrayBoundsClamper().OutputClampingFunctionDefinition(sink); getArrayBoundsClamper().OutputClampingFunctionDefinition(sink);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment