Commit 5055fba5 by jchen10 Committed by Commit Bot

Optimize Program::resolveLink

The method has to be extremely fast as it's very frequently called. It contributes about 2% cpu time in the DrawCall/gl_null benchmark. With this optimization it can be decreased to less than 1%. Bug: chromium:873724 Change-Id: I7fb376db73452dbdf6cb44c92815848e860867c9 Reviewed-on: https://chromium-review.googlesource.com/1179369Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
parent 458c654b
......@@ -890,6 +890,7 @@ Program::Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLui
: mProgram(factory->createProgram(mState)),
mValidated(false),
mLinked(false),
mLinkResolved(true),
mDeleteStatus(false),
mRefCount(0),
mResourceManager(manager),
......@@ -1254,6 +1255,7 @@ Error Program::link(const gl::Context *context)
mLinkingState->programHash = programHash;
mLinkingState->linkEvent = mProgram->link(context, *resources, mInfoLog);
mLinkingState->resources = std::move(resources);
mLinkResolved = false;
return NoError();
}
......@@ -1269,19 +1271,12 @@ bool Program::isLinked() const
return mLinked;
}
void Program::resolveLink() const
{
if (mLinkingState.get())
{
return const_cast<Program *>(this)->resolveLinkImpl();
}
}
void Program::resolveLinkImpl()
{
ASSERT(mLinkingState.get());
mLinked = mLinkingState->linkEvent->wait();
mLinkResolved = true;
auto linkingState = std::move(mLinkingState);
if (!mLinked)
{
......
......@@ -835,7 +835,15 @@ class Program final : angle::NonCopyable, public LabeledObject
bool validateSamplersImpl(InfoLog *infoLog, const Caps &caps);
// Try to resolve linking.
void resolveLink() const;
// Note: this method is frequently called in each draw call. Please make sure its overhead
// is as low as possible.
void resolveLink() const
{
if (!mLinkResolved)
{
return const_cast<Program *>(this)->resolveLinkImpl();
}
}
// Block until linking is finished and resolve it.
void resolveLinkImpl();
......@@ -854,6 +862,7 @@ class Program final : angle::NonCopyable, public LabeledObject
ProgramBindings mFragmentInputBindings;
bool mLinked;
bool mLinkResolved;
std::unique_ptr<LinkingState> mLinkingState;
bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
......
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