Commit dfa75e87 by Olli Etuaho Committed by Commit Bot

Add support for 4-parameter functions to BuiltInFunctionEmulator

New entry points are needed to support built-ins with more parameters. Also, now that ops that are not function calls don't use the TIntermAggregate class any more, it's easier to exclude nodes that are not candidates for built-in emulation using a simple blacklist rather than to use a whitelist. Also includes function name style cleanup in BuiltInFunctionEmulator. This will make it possible to add necessary emulation for built-ins from ESSL 3.10. BUG=angleproject:1730 TEST=angle_unittests Change-Id: If267fc68f5cb9b2ee6703cbcbbe4d157da44a7e0 Reviewed-on: https://chromium-review.googlesource.com/431297 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 01d0ad08
...@@ -23,17 +23,17 @@ class BuiltInFunctionEmulator ...@@ -23,17 +23,17 @@ class BuiltInFunctionEmulator
public: public:
BuiltInFunctionEmulator(); BuiltInFunctionEmulator();
void MarkBuiltInFunctionsForEmulation(TIntermNode *root); void markBuiltInFunctionsForEmulation(TIntermNode *root);
void Cleanup(); void cleanup();
// "name" gets written as "webgl_name_emu". // "name" gets written as "webgl_name_emu".
static void WriteEmulatedFunctionName(TInfoSinkBase &out, const char *name); static void WriteEmulatedFunctionName(TInfoSinkBase &out, const char *name);
bool IsOutputEmpty() const; bool isOutputEmpty() const;
// Output function emulation definition. This should be before any other shader source. // Output function emulation definition. This should be before any other shader source.
void OutputEmulatedFunctions(TInfoSinkBase &out) const; void outputEmulatedFunctions(TInfoSinkBase &out) const;
class FunctionId class FunctionId
{ {
...@@ -42,6 +42,11 @@ class BuiltInFunctionEmulator ...@@ -42,6 +42,11 @@ class BuiltInFunctionEmulator
FunctionId(TOperator op, const TType *param); FunctionId(TOperator op, const TType *param);
FunctionId(TOperator op, const TType *param1, const TType *param2); FunctionId(TOperator op, const TType *param1, const TType *param2);
FunctionId(TOperator op, const TType *param1, const TType *param2, const TType *param3); FunctionId(TOperator op, const TType *param1, const TType *param2, const TType *param3);
FunctionId(TOperator op,
const TType *param1,
const TType *param2,
const TType *param3,
const TType *param4);
FunctionId(const FunctionId &) = default; FunctionId(const FunctionId &) = default;
FunctionId &operator=(const FunctionId &) = default; FunctionId &operator=(const FunctionId &) = default;
...@@ -60,6 +65,7 @@ class BuiltInFunctionEmulator ...@@ -60,6 +65,7 @@ class BuiltInFunctionEmulator
const TType *mParam1; const TType *mParam1;
const TType *mParam2; const TType *mParam2;
const TType *mParam3; const TType *mParam3;
const TType *mParam4;
}; };
// Add functions that need to be emulated. // Add functions that need to be emulated.
...@@ -75,12 +81,25 @@ class BuiltInFunctionEmulator ...@@ -75,12 +81,25 @@ class BuiltInFunctionEmulator
const TType *param2, const TType *param2,
const TType *param3, const TType *param3,
const char *emulatedFunctionDefinition); const char *emulatedFunctionDefinition);
FunctionId addEmulatedFunction(TOperator op,
const TType *param1,
const TType *param2,
const TType *param3,
const TType *param4,
const char *emulatedFunctionDefinition);
FunctionId addEmulatedFunctionWithDependency(FunctionId dependency, FunctionId addEmulatedFunctionWithDependency(FunctionId dependency,
TOperator op, TOperator op,
const TType *param1, const TType *param1,
const TType *param2, const TType *param2,
const char *emulatedFunctionDefinition); const char *emulatedFunctionDefinition);
FunctionId addEmulatedFunctionWithDependency(FunctionId dependency,
TOperator op,
const TType *param1,
const TType *param2,
const TType *param3,
const TType *param4,
const char *emulatedFunctionDefinition);
private: private:
class BuiltInFunctionEmulationMarker; class BuiltInFunctionEmulationMarker;
...@@ -88,14 +107,19 @@ class BuiltInFunctionEmulator ...@@ -88,14 +107,19 @@ class BuiltInFunctionEmulator
// Records that a function is called by the shader and might need to be emulated. If the // 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 // function is not in mEmulatedFunctions, this becomes a no-op. Returns true if the function
// call needs to be replaced with an emulated one. // call needs to be replaced with an emulated one.
bool SetFunctionCalled(TOperator op, const TType &param); 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);
bool SetFunctionCalled(TOperator op, bool setFunctionCalled(TOperator op,
const TType &param1, const TType &param1,
const TType &param2, const TType &param2,
const TType &param3); const TType &param3);
bool setFunctionCalled(TOperator op,
const TType &param1,
const TType &param2,
const TType &param3,
const TType &param4);
bool SetFunctionCalled(const FunctionId &functionId); bool setFunctionCalled(const FunctionId &functionId);
// Map from function id to emulated function definition // Map from function id to emulated function definition
std::map<FunctionId, std::string> mEmulatedFunctions; std::map<FunctionId, std::string> mEmulatedFunctions;
......
...@@ -394,7 +394,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -394,7 +394,7 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
GetGlobalPoolAllocator()->lock(); GetGlobalPoolAllocator()->lock();
initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions); initBuiltInFunctionEmulator(&builtInFunctionEmulator, compileOptions);
GetGlobalPoolAllocator()->unlock(); GetGlobalPoolAllocator()->unlock();
builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(root); builtInFunctionEmulator.markBuiltInFunctionsForEmulation(root);
} }
// Clamping uniform array bounds needs to happen after validateLimitations pass. // Clamping uniform array bounds needs to happen after validateLimitations pass.
...@@ -670,7 +670,7 @@ void TCompiler::clearResults() ...@@ -670,7 +670,7 @@ void TCompiler::clearResults()
mNumViews = -1; mNumViews = -1;
builtInFunctionEmulator.Cleanup(); builtInFunctionEmulator.cleanup();
nameMap.clear(); nameMap.clear();
......
...@@ -178,7 +178,7 @@ void OutputHLSL::output(TIntermNode *treeRoot, TInfoSinkBase &objSink) ...@@ -178,7 +178,7 @@ void OutputHLSL::output(TIntermNode *treeRoot, TInfoSinkBase &objSink)
mShaderVersion); mShaderVersion);
} }
builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(treeRoot); builtInFunctionEmulator.markBuiltInFunctionsForEmulation(treeRoot);
// Now that we are done changing the AST, do the analyses need for HLSL generation // Now that we are done changing the AST, do the analyses need for HLSL generation
CallDAG::InitResult success = mCallDag.init(treeRoot, nullptr); CallDAG::InitResult success = mCallDag.init(treeRoot, nullptr);
...@@ -201,7 +201,7 @@ void OutputHLSL::output(TIntermNode *treeRoot, TInfoSinkBase &objSink) ...@@ -201,7 +201,7 @@ void OutputHLSL::output(TIntermNode *treeRoot, TInfoSinkBase &objSink)
objSink << mBody.c_str(); objSink << mBody.c_str();
objSink << mFooter.c_str(); objSink << mFooter.c_str();
builtInFunctionEmulator.Cleanup(); builtInFunctionEmulator.cleanup();
} }
void OutputHLSL::makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs) void OutputHLSL::makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs)
...@@ -739,7 +739,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built ...@@ -739,7 +739,7 @@ void OutputHLSL::header(TInfoSinkBase &out, const BuiltInFunctionEmulator *built
"\n"; "\n";
} }
builtInFunctionEmulator->OutputEmulatedFunctions(out); builtInFunctionEmulator->outputEmulatedFunctions(out);
} }
void OutputHLSL::visitSymbol(TIntermSymbol *node) void OutputHLSL::visitSymbol(TIntermSymbol *node)
......
...@@ -60,7 +60,7 @@ void TranslatorESSL::translate(TIntermNode *root, ShCompileOptions compileOption ...@@ -60,7 +60,7 @@ void TranslatorESSL::translate(TIntermNode *root, ShCompileOptions compileOption
RecordConstantPrecision(root, getTemporaryIndex()); RecordConstantPrecision(root, getTemporaryIndex());
// Write emulated built-in functions if needed. // Write emulated built-in functions if needed.
if (!getBuiltInFunctionEmulator().IsOutputEmpty()) if (!getBuiltInFunctionEmulator().isOutputEmpty())
{ {
sink << "// BEGIN: Generated code for built-in function emulation\n\n"; sink << "// BEGIN: Generated code for built-in function emulation\n\n";
if (getShaderType() == GL_FRAGMENT_SHADER) if (getShaderType() == GL_FRAGMENT_SHADER)
...@@ -76,7 +76,7 @@ void TranslatorESSL::translate(TIntermNode *root, ShCompileOptions compileOption ...@@ -76,7 +76,7 @@ void TranslatorESSL::translate(TIntermNode *root, ShCompileOptions compileOption
sink << "#define webgl_emu_precision highp\n"; sink << "#define webgl_emu_precision highp\n";
} }
getBuiltInFunctionEmulator().OutputEmulatedFunctions(sink); getBuiltInFunctionEmulator().outputEmulatedFunctions(sink);
sink << "// END: Generated code for built-in function emulation\n\n"; sink << "// END: Generated code for built-in function emulation\n\n";
} }
......
...@@ -114,11 +114,11 @@ void TranslatorGLSL::translate(TIntermNode *root, ShCompileOptions compileOption ...@@ -114,11 +114,11 @@ void TranslatorGLSL::translate(TIntermNode *root, ShCompileOptions compileOption
} }
// Write emulated built-in functions if needed. // Write emulated built-in functions if needed.
if (!getBuiltInFunctionEmulator().IsOutputEmpty()) if (!getBuiltInFunctionEmulator().isOutputEmpty())
{ {
sink << "// BEGIN: Generated code for built-in function emulation\n\n"; sink << "// BEGIN: Generated code for built-in function emulation\n\n";
sink << "#define webgl_emu_precision\n\n"; sink << "#define webgl_emu_precision\n\n";
getBuiltInFunctionEmulator().OutputEmulatedFunctions(sink); getBuiltInFunctionEmulator().outputEmulatedFunctions(sink);
sink << "// END: Generated code for built-in function emulation\n\n"; sink << "// END: Generated code for built-in function emulation\n\n";
} }
......
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