Commit 499173de by Jamie Madill Committed by Commit Bot

Pass #pragma optimize setting down to compilation.

This will allow us to disable optimizations in the back-end. This can be useful both for developers and for ANGLE to disable very slow shader compilation on D3D11. Also apply this pragma to VerifyMaxVertexUniformVectorsWithSamplers. Reduces compilation time by half in local testing. Bug: angleproject:5076 Change-Id: I64ad576e11b9cee5b41f8af0d3621570304d65c2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2420749 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent eed069b3
...@@ -743,6 +743,8 @@ int GetGeometryShaderInvocations(const ShHandle handle); ...@@ -743,6 +743,8 @@ int GetGeometryShaderInvocations(const ShHandle handle);
int GetGeometryShaderMaxVertices(const ShHandle handle); int GetGeometryShaderMaxVertices(const ShHandle handle);
unsigned int GetShaderSharedMemorySize(const ShHandle handle); unsigned int GetShaderSharedMemorySize(const ShHandle handle);
bool GetPragmaOptimize(const ShHandle handle);
// //
// Helper function to identify specs that are based on the WebGL spec. // Helper function to identify specs that are based on the WebGL spec.
// //
......
...@@ -1506,6 +1506,11 @@ bool TCompiler::isVaryingDefined(const char *varyingName) ...@@ -1506,6 +1506,11 @@ bool TCompiler::isVaryingDefined(const char *varyingName)
return false; return false;
} }
bool TCompiler::getPragmaOptimize() const
{
return mPragma.optimize;
}
void EmitEarlyFragmentTestsGLSL(const TCompiler &compiler, TInfoSinkBase &sink) void EmitEarlyFragmentTestsGLSL(const TCompiler &compiler, TInfoSinkBase &sink)
{ {
if (compiler.isEarlyFragmentTestsSpecified() || compiler.isEarlyFragmentTestsOptimized()) if (compiler.isEarlyFragmentTestsSpecified() || compiler.isEarlyFragmentTestsOptimized())
......
...@@ -144,13 +144,14 @@ class TCompiler : public TShHandleBase ...@@ -144,13 +144,14 @@ class TCompiler : public TShHandleBase
return mGeometryShaderOutputPrimitiveType; return mGeometryShaderOutputPrimitiveType;
} }
unsigned int getStructSize(const ShaderVariable &var) const;
unsigned int getSharedMemorySize() const; unsigned int getSharedMemorySize() const;
sh::GLenum getShaderType() const { return mShaderType; } sh::GLenum getShaderType() const { return mShaderType; }
bool validateAST(TIntermNode *root); bool validateAST(TIntermNode *root);
bool getPragmaOptimize() const;
protected: protected:
// Add emulated functions to the built-in function emulator. // Add emulated functions to the built-in function emulator.
virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu, virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu,
......
...@@ -716,6 +716,17 @@ unsigned int GetShaderSharedMemorySize(const ShHandle handle) ...@@ -716,6 +716,17 @@ unsigned int GetShaderSharedMemorySize(const ShHandle handle)
return sharedMemorySize; return sharedMemorySize;
} }
bool GetPragmaOptimize(const ShHandle handle)
{
ASSERT(handle);
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
TCompiler *compiler = base->getAsCompiler();
ASSERT(compiler);
return compiler->getPragmaOptimize();
}
// Can't prefix with just _ because then we might introduce a double underscore, which is not safe // Can't prefix with just _ because then we might introduce a double underscore, which is not safe
// in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for
// use by the underlying implementation). u is short for user-defined. // use by the underlying implementation). u is short for user-defined.
......
...@@ -1684,6 +1684,8 @@ void Program::updateLinkedShaderStages() ...@@ -1684,6 +1684,8 @@ void Program::updateLinkedShaderStages()
if (shader) if (shader)
{ {
mState.mExecutable->setLinkedShaderStages(shader->getType()); mState.mExecutable->setLinkedShaderStages(shader->getType());
mState.mExecutable->mShaderOptimizationEnabled[shader->getType()] =
shader->getState().isOptimizationEnabled();
} }
} }
......
...@@ -147,6 +147,8 @@ void ProgramExecutable::load(gl::BinaryInputStream *stream) ...@@ -147,6 +147,8 @@ void ProgramExecutable::load(gl::BinaryInputStream *stream)
mLinkedComputeShaderStages = ShaderBitSet(stream->readInt<uint8_t>()); mLinkedComputeShaderStages = ShaderBitSet(stream->readInt<uint8_t>());
mIsCompute = stream->readBool(); mIsCompute = stream->readBool();
mShaderOptimizationEnabled = ShaderBitSet(stream->readInt<uint8_t>());
mPipelineHasGraphicsUniformBuffers = stream->readBool(); mPipelineHasGraphicsUniformBuffers = stream->readBool();
mPipelineHasComputeUniformBuffers = stream->readBool(); mPipelineHasComputeUniformBuffers = stream->readBool();
mPipelineHasGraphicsStorageBuffers = stream->readBool(); mPipelineHasGraphicsStorageBuffers = stream->readBool();
...@@ -172,6 +174,8 @@ void ProgramExecutable::save(gl::BinaryOutputStream *stream) const ...@@ -172,6 +174,8 @@ void ProgramExecutable::save(gl::BinaryOutputStream *stream) const
stream->writeInt(mLinkedComputeShaderStages.bits()); stream->writeInt(mLinkedComputeShaderStages.bits());
stream->writeInt(static_cast<bool>(mIsCompute)); stream->writeInt(static_cast<bool>(mIsCompute));
stream->writeInt(mShaderOptimizationEnabled.bits());
stream->writeInt(static_cast<bool>(mPipelineHasGraphicsUniformBuffers)); stream->writeInt(static_cast<bool>(mPipelineHasGraphicsUniformBuffers));
stream->writeInt(static_cast<bool>(mPipelineHasComputeUniformBuffers)); stream->writeInt(static_cast<bool>(mPipelineHasComputeUniformBuffers));
stream->writeInt(static_cast<bool>(mPipelineHasGraphicsStorageBuffers)); stream->writeInt(static_cast<bool>(mPipelineHasGraphicsStorageBuffers));
......
...@@ -302,6 +302,11 @@ class ProgramExecutable final : public angle::Subject ...@@ -302,6 +302,11 @@ class ProgramExecutable final : public angle::Subject
} }
int getLinkedShaderVersion(ShaderType shaderType) { return mLinkedShaderVersions[shaderType]; } int getLinkedShaderVersion(ShaderType shaderType) { return mLinkedShaderVersions[shaderType]; }
bool isShaderOptimizationEnabled(ShaderType shaderType) const
{
return mShaderOptimizationEnabled[shaderType];
}
private: private:
// TODO(timvp): http://anglebug.com/3570: Investigate removing these friend // TODO(timvp): http://anglebug.com/3570: Investigate removing these friend
// class declarations and accessing the necessary members with getters/setters. // class declarations and accessing the necessary members with getters/setters.
...@@ -393,6 +398,8 @@ class ProgramExecutable final : public angle::Subject ...@@ -393,6 +398,8 @@ class ProgramExecutable final : public angle::Subject
bool mIsCompute; bool mIsCompute;
ShaderBitSet mShaderOptimizationEnabled;
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedOutputVaryings; ShaderMap<std::vector<sh::ShaderVariable>> mLinkedOutputVaryings;
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedInputVaryings; ShaderMap<std::vector<sh::ShaderVariable>> mLinkedInputVaryings;
ShaderMap<int> mLinkedShaderVersions; ShaderMap<int> mLinkedShaderVersions;
......
...@@ -416,6 +416,17 @@ void ProgramPipeline::updateExecutable() ...@@ -416,6 +416,17 @@ void ProgramPipeline::updateExecutable()
// Must be last, since it queries things updated by earlier functions // Must be last, since it queries things updated by earlier functions
updateHasBooleans(); updateHasBooleans();
for (const gl::ShaderType shaderType : kAllGraphicsShaderTypes)
{
const Program *shaderProgram = getShaderProgram(shaderType);
if (shaderProgram)
{
const ProgramExecutable &executable = shaderProgram->getExecutable();
mState.mExecutable->mShaderOptimizationEnabled[shaderType] =
executable.isShaderOptimizationEnabled(shaderType);
}
}
} }
ProgramMergedVaryings ProgramPipeline::getMergedVaryings() const ProgramMergedVaryings ProgramPipeline::getMergedVaryings() const
......
...@@ -118,6 +118,8 @@ ShaderState::ShaderState(ShaderType shaderType) ...@@ -118,6 +118,8 @@ ShaderState::ShaderState(ShaderType shaderType)
: mLabel(), : mLabel(),
mShaderType(shaderType), mShaderType(shaderType),
mShaderVersion(100), mShaderVersion(100),
mEarlyFragmentTestsOptimization(false),
mOptimizationEnabled(true),
mNumViews(-1), mNumViews(-1),
mGeometryShaderInvocations(1), mGeometryShaderInvocations(1),
mCompileStatus(CompileStatus::NOT_COMPILED) mCompileStatus(CompileStatus::NOT_COMPILED)
...@@ -427,7 +429,8 @@ void Shader::resolveCompile() ...@@ -427,7 +429,8 @@ void Shader::resolveCompile()
#endif // !defined(NDEBUG) #endif // !defined(NDEBUG)
// Gather the shader information // Gather the shader information
mState.mShaderVersion = sh::GetShaderVersion(compilerHandle); mState.mShaderVersion = sh::GetShaderVersion(compilerHandle);
mState.mOptimizationEnabled = sh::GetPragmaOptimize(compilerHandle);
mState.mUniforms = GetShaderVariables(sh::GetUniforms(compilerHandle)); mState.mUniforms = GetShaderVariables(sh::GetUniforms(compilerHandle));
mState.mUniformBlocks = GetShaderVariables(sh::GetUniformBlocks(compilerHandle)); mState.mUniformBlocks = GetShaderVariables(sh::GetUniformBlocks(compilerHandle));
......
...@@ -109,6 +109,8 @@ class ShaderState final : angle::NonCopyable ...@@ -109,6 +109,8 @@ class ShaderState final : angle::NonCopyable
CompileStatus getCompileStatus() const { return mCompileStatus; } CompileStatus getCompileStatus() const { return mCompileStatus; }
bool isOptimizationEnabled() const { return mOptimizationEnabled; }
private: private:
friend class Shader; friend class Shader;
...@@ -131,6 +133,7 @@ class ShaderState final : angle::NonCopyable ...@@ -131,6 +133,7 @@ class ShaderState final : angle::NonCopyable
std::vector<sh::ShaderVariable> mActiveOutputVariables; std::vector<sh::ShaderVariable> mActiveOutputVariables;
bool mEarlyFragmentTestsOptimization; bool mEarlyFragmentTestsOptimization;
bool mOptimizationEnabled;
// ANGLE_multiview. // ANGLE_multiview.
int mNumViews; int mNumViews;
......
...@@ -184,6 +184,10 @@ void ShaderD3D::generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds) ...@@ -184,6 +184,10 @@ void ShaderD3D::generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds)
// disabling optimization // disabling optimization
workarounds->skipOptimization = true; workarounds->skipOptimization = true;
} }
else if (!mState.isOptimizationEnabled())
{
workarounds->skipOptimization = true;
}
else if (mUsesNestedBreak) else if (mUsesNestedBreak)
{ {
// ANGLE issue 603: // ANGLE issue 603:
......
...@@ -2994,7 +2994,8 @@ angle::Result Renderer11::compileToExecutable(d3d::Context *context, ...@@ -2994,7 +2994,8 @@ angle::Result Renderer11::compileToExecutable(d3d::Context *context,
<< getShaderModelSuffix(); << getShaderModelSuffix();
std::string profile = profileStream.str(); std::string profile = profileStream.str();
UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2; UINT flags = workarounds.skipOptimization ? D3DCOMPILE_SKIP_OPTIMIZATION
: D3DCOMPILE_OPTIMIZATION_LEVEL2;
#if defined(ANGLE_ENABLE_DEBUG_TRACE) #if defined(ANGLE_ENABLE_DEBUG_TRACE)
# ifndef NDEBUG # ifndef NDEBUG
......
...@@ -368,7 +368,8 @@ class GLSLTest : public ANGLETest ...@@ -368,7 +368,8 @@ class GLSLTest : public ANGLETest
std::stringstream fragmentShader; std::stringstream fragmentShader;
// Generate the vertex shader // Generate the vertex shader
vertexShader << "precision mediump float;\n"; vertexShader << "#pragma optimize(off)\n"
<< "precision mediump float;\n";
for (int i = 0; i < vertexUniformCount; i++) for (int i = 0; i < vertexUniformCount; i++)
{ {
......
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