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);
int GetGeometryShaderMaxVertices(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.
//
......
......@@ -1506,6 +1506,11 @@ bool TCompiler::isVaryingDefined(const char *varyingName)
return false;
}
bool TCompiler::getPragmaOptimize() const
{
return mPragma.optimize;
}
void EmitEarlyFragmentTestsGLSL(const TCompiler &compiler, TInfoSinkBase &sink)
{
if (compiler.isEarlyFragmentTestsSpecified() || compiler.isEarlyFragmentTestsOptimized())
......
......@@ -144,13 +144,14 @@ class TCompiler : public TShHandleBase
return mGeometryShaderOutputPrimitiveType;
}
unsigned int getStructSize(const ShaderVariable &var) const;
unsigned int getSharedMemorySize() const;
sh::GLenum getShaderType() const { return mShaderType; }
bool validateAST(TIntermNode *root);
bool getPragmaOptimize() const;
protected:
// Add emulated functions to the built-in function emulator.
virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu,
......
......@@ -716,6 +716,17 @@ unsigned int GetShaderSharedMemorySize(const ShHandle handle)
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
// 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.
......
......@@ -1684,6 +1684,8 @@ void Program::updateLinkedShaderStages()
if (shader)
{
mState.mExecutable->setLinkedShaderStages(shader->getType());
mState.mExecutable->mShaderOptimizationEnabled[shader->getType()] =
shader->getState().isOptimizationEnabled();
}
}
......
......@@ -147,6 +147,8 @@ void ProgramExecutable::load(gl::BinaryInputStream *stream)
mLinkedComputeShaderStages = ShaderBitSet(stream->readInt<uint8_t>());
mIsCompute = stream->readBool();
mShaderOptimizationEnabled = ShaderBitSet(stream->readInt<uint8_t>());
mPipelineHasGraphicsUniformBuffers = stream->readBool();
mPipelineHasComputeUniformBuffers = stream->readBool();
mPipelineHasGraphicsStorageBuffers = stream->readBool();
......@@ -172,6 +174,8 @@ void ProgramExecutable::save(gl::BinaryOutputStream *stream) const
stream->writeInt(mLinkedComputeShaderStages.bits());
stream->writeInt(static_cast<bool>(mIsCompute));
stream->writeInt(mShaderOptimizationEnabled.bits());
stream->writeInt(static_cast<bool>(mPipelineHasGraphicsUniformBuffers));
stream->writeInt(static_cast<bool>(mPipelineHasComputeUniformBuffers));
stream->writeInt(static_cast<bool>(mPipelineHasGraphicsStorageBuffers));
......
......@@ -302,6 +302,11 @@ class ProgramExecutable final : public angle::Subject
}
int getLinkedShaderVersion(ShaderType shaderType) { return mLinkedShaderVersions[shaderType]; }
bool isShaderOptimizationEnabled(ShaderType shaderType) const
{
return mShaderOptimizationEnabled[shaderType];
}
private:
// TODO(timvp): http://anglebug.com/3570: Investigate removing these friend
// class declarations and accessing the necessary members with getters/setters.
......@@ -393,6 +398,8 @@ class ProgramExecutable final : public angle::Subject
bool mIsCompute;
ShaderBitSet mShaderOptimizationEnabled;
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedOutputVaryings;
ShaderMap<std::vector<sh::ShaderVariable>> mLinkedInputVaryings;
ShaderMap<int> mLinkedShaderVersions;
......
......@@ -416,6 +416,17 @@ void ProgramPipeline::updateExecutable()
// Must be last, since it queries things updated by earlier functions
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
......
......@@ -118,6 +118,8 @@ ShaderState::ShaderState(ShaderType shaderType)
: mLabel(),
mShaderType(shaderType),
mShaderVersion(100),
mEarlyFragmentTestsOptimization(false),
mOptimizationEnabled(true),
mNumViews(-1),
mGeometryShaderInvocations(1),
mCompileStatus(CompileStatus::NOT_COMPILED)
......@@ -427,7 +429,8 @@ void Shader::resolveCompile()
#endif // !defined(NDEBUG)
// 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.mUniformBlocks = GetShaderVariables(sh::GetUniformBlocks(compilerHandle));
......
......@@ -109,6 +109,8 @@ class ShaderState final : angle::NonCopyable
CompileStatus getCompileStatus() const { return mCompileStatus; }
bool isOptimizationEnabled() const { return mOptimizationEnabled; }
private:
friend class Shader;
......@@ -131,6 +133,7 @@ class ShaderState final : angle::NonCopyable
std::vector<sh::ShaderVariable> mActiveOutputVariables;
bool mEarlyFragmentTestsOptimization;
bool mOptimizationEnabled;
// ANGLE_multiview.
int mNumViews;
......
......@@ -184,6 +184,10 @@ void ShaderD3D::generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds)
// disabling optimization
workarounds->skipOptimization = true;
}
else if (!mState.isOptimizationEnabled())
{
workarounds->skipOptimization = true;
}
else if (mUsesNestedBreak)
{
// ANGLE issue 603:
......
......@@ -2994,7 +2994,8 @@ angle::Result Renderer11::compileToExecutable(d3d::Context *context,
<< getShaderModelSuffix();
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)
# ifndef NDEBUG
......
......@@ -368,7 +368,8 @@ class GLSLTest : public ANGLETest
std::stringstream fragmentShader;
// 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++)
{
......
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