Commit 80a5a6c6 by Olli Etuaho

Clean up BuiltInFunctionEmulator public interface

This removes all language-specific bits from BuiltInFunctionEmulator parent class, and makes the public interface of BuiltInFunctionEmulator minimal. Writing comments around emulated function definitions is removed from OutputHLSL, they are not necessary as the emulated function definitions are just another part of the shader header. Change-Id: I9abf57d86f4e37b0674d7dfafe653298f205dd27 Reviewed-on: https://chromium-review.googlesource.com/240230Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent e39706d0
......@@ -8,11 +8,9 @@
#include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/SymbolTable.h"
namespace
class BuiltInFunctionEmulator::BuiltInFunctionEmulationMarker : public TIntermTraverser
{
class BuiltInFunctionEmulationMarker : public TIntermTraverser {
public:
public:
BuiltInFunctionEmulationMarker(BuiltInFunctionEmulator& emulator)
: mEmulator(emulator)
{
......@@ -95,12 +93,10 @@ public:
return true;
}
private:
private:
BuiltInFunctionEmulator& mEmulator;
};
} // anonymous namepsace
BuiltInFunctionEmulator::BuiltInFunctionEmulator()
{}
......@@ -128,17 +124,17 @@ void BuiltInFunctionEmulator::AddEmulatedFunction(
std::string(emulatedFunctionDefinition);
}
void BuiltInFunctionEmulator::OutputEmulatedFunctionDefinition(
TInfoSinkBase& out, bool withPrecision) const
bool BuiltInFunctionEmulator::IsOutputEmpty() const
{
return (mFunctions.size() == 0);
}
void BuiltInFunctionEmulator::OutputEmulatedFunctions(
TInfoSinkBase& out) const
{
if (mFunctions.size() == 0)
return;
out << "// BEGIN: Generated code for built-in function emulation\n\n";
OutputEmulatedFunctionHeader(out, withPrecision);
for (size_t i = 0; i < mFunctions.size(); ++i) {
out << mEmulatedFunctions.find(mFunctions[i])->second << "\n\n";
}
out << "// END: Generated code for built-in function emulation\n\n";
}
bool BuiltInFunctionEmulator::SetFunctionCalled(
......
......@@ -19,20 +19,6 @@
class BuiltInFunctionEmulator
{
public:
// Records that a function is called by the shader and might need to be
// emulated. If the function is not in mEmulatedFunctions, this becomes a
// no-op. Returns true if the function call needs to be replaced with an
// emulated one.
bool SetFunctionCalled(TOperator op, const TType& param);
bool SetFunctionCalled(
TOperator op, const TType& param1, const TType& param2);
bool SetFunctionCalled(
TOperator op, const TType& param1, const TType& param2, const TType& param3);
// Output function emulation definition. This should be before any other
// shader source.
void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
void MarkBuiltInFunctionsForEmulation(TIntermNode* root);
void Cleanup();
......@@ -43,14 +29,30 @@ class BuiltInFunctionEmulator
protected:
BuiltInFunctionEmulator();
bool IsOutputEmpty() const;
// Output function emulation definition. This should be before any other
// shader source.
void OutputEmulatedFunctions(TInfoSinkBase& out) const;
// Add functions that need to be emulated.
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 TType& param3, const char* emulatedFunctionDefinition);
// Override this to add source before emulated function definitions.
virtual void OutputEmulatedFunctionHeader(TInfoSinkBase& out, bool withPrecision) const {}
private:
class BuiltInFunctionEmulationMarker;
// Records that a function is called by the shader and might need to be
// emulated. If the function is not in mEmulatedFunctions, this becomes a
// no-op. Returns true if the function call needs to be replaced with an
// emulated one.
bool SetFunctionCalled(TOperator op, const TType& param);
bool SetFunctionCalled(
TOperator op, const TType& param1, const TType& param2);
bool SetFunctionCalled(
TOperator op, const TType& param1, const TType& param2, const TType& param3);
class FunctionId {
public:
FunctionId(TOperator op, const TType& param);
......
......@@ -38,9 +38,13 @@ BuiltInFunctionEmulatorGLSL::BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType)
#endif
}
void BuiltInFunctionEmulatorGLSL::OutputEmulatedFunctionHeader(
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"
......@@ -50,4 +54,6 @@ void BuiltInFunctionEmulatorGLSL::OutputEmulatedFunctionHeader(
} else {
out << "#define webgl_emu_precision\n\n";
}
OutputEmulatedFunctions(out);
out << "// END: Generated code for built-in function emulation\n\n";
}
......@@ -17,9 +17,7 @@ class BuiltInFunctionEmulatorGLSL : public BuiltInFunctionEmulator
public:
BuiltInFunctionEmulatorGLSL(sh::GLenum shaderType);
protected:
// Output function emulation definition header.
virtual void OutputEmulatedFunctionHeader(TInfoSinkBase& out, bool withPrecision) const override;
void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
};
#endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORGLSL_H_
......@@ -242,3 +242,8 @@ BuiltInFunctionEmulatorHLSL::BuiltInFunctionEmulatorHLSL()
"}\n");
}
void BuiltInFunctionEmulatorHLSL::OutputEmulatedFunctionDefinition(
TInfoSinkBase& out) const
{
OutputEmulatedFunctions(out);
}
......@@ -16,6 +16,8 @@ class BuiltInFunctionEmulatorHLSL : public BuiltInFunctionEmulator
{
public:
BuiltInFunctionEmulatorHLSL();
void OutputEmulatedFunctionDefinition(TInfoSinkBase& out) const;
};
#endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATORHLSL_H_
......@@ -1203,7 +1203,7 @@ void OutputHLSL::header(const BuiltInFunctionEmulatorHLSL *builtInFunctionEmulat
"\n";
}
builtInFunctionEmulator->OutputEmulatedFunctionDefinition(out, false);
builtInFunctionEmulator->OutputEmulatedFunctionDefinition(out);
}
void OutputHLSL::visitSymbol(TIntermSymbol *node)
......
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