Commit 956ab4d9 by Jamie Madill Committed by Commit Bot

Optimize several functions for the Program perf test.

This gives the same or slightly better performance in the ProgramDraw perf test. Also only set the Program object as dirty when there are dirty bits set in the Program itself. Bug: angleproject:2877 Change-Id: I07b428b40d3e3c24e0a42c970524756b6dc3a30e Reviewed-on: https://chromium-review.googlesource.com/c/1271475Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a139f01a
......@@ -135,10 +135,10 @@ gl::Error GetQueryObjectParameter(const gl::Context *context,
}
}
void MarkTransformFeedbackBufferUsage(const gl::Context *context,
gl::TransformFeedback *transformFeedback,
GLsizei count,
GLsizei instanceCount)
ANGLE_INLINE void MarkTransformFeedbackBufferUsage(const gl::Context *context,
gl::TransformFeedback *transformFeedback,
GLsizei count,
GLsizei instanceCount)
{
if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
{
......@@ -6428,6 +6428,7 @@ void Context::uniformBlockBinding(GLuint program,
Program *programObject = getProgramResolveLink(program);
programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
// Note: If the Program is shared between Contexts we would be better using Observer/Subject.
if (programObject->isInUse())
{
mGLState.setObjectDirty(GL_PROGRAM);
......@@ -7812,16 +7813,6 @@ bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned
return false;
}
Program *Context::getProgramResolveLink(GLuint handle) const
{
Program *program = mState.mShaderPrograms->getProgram(handle);
if (program)
{
program->resolveLink(this);
}
return program;
}
Program *Context::getProgramNoResolveLink(GLuint handle) const
{
return mState.mShaderPrograms->getProgram(handle);
......
......@@ -1650,7 +1650,16 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams);
Program *getProgramResolveLink(GLuint handle) const;
ANGLE_INLINE Program *getProgramResolveLink(GLuint handle) const
{
Program *program = mState.mShaderPrograms->getProgram(handle);
if (program)
{
program->resolveLink(this);
}
return program;
}
Program *getProgramNoResolveLink(GLuint handle) const;
Shader *getShader(GLuint handle) const;
......
......@@ -118,11 +118,6 @@ void ObserverBinding::bind(Subject *subject)
}
}
void ObserverBinding::reset()
{
bind(nullptr);
}
void ObserverBinding::onStateChange(const gl::Context *context, SubjectMessage message) const
{
mObserver->onSubjectStateChange(context, mIndex, message);
......
......@@ -81,7 +81,9 @@ class ObserverBinding final
ObserverBinding &operator=(const ObserverBinding &other);
void bind(Subject *subject);
void reset();
ANGLE_INLINE void reset() { bind(nullptr); }
void onStateChange(const gl::Context *context, SubjectMessage message) const;
void onSubjectReset();
......
......@@ -955,11 +955,6 @@ const std::string &Program::getLabel() const
ASSERT(mLinkResolved);
return mState.mLabel;
}
rx::ProgramImpl *Program::getImplementation() const
{
ASSERT(mLinkResolved);
return mProgram;
}
void Program::attachShader(Shader *shader)
{
......@@ -1567,21 +1562,10 @@ bool Program::isSeparable() const
return mState.mSeparable;
}
void Program::release(const Context *context)
void Program::deleteSelf(const Context *context)
{
ASSERT(mLinkResolved);
mRefCount--;
if (mRefCount == 0 && mDeleteStatus)
{
mResourceManager->deleteProgram(context, mHandle);
}
}
void Program::addRef()
{
ASSERT(mLinkResolved);
mRefCount++;
ASSERT(mRefCount == 0 && mDeleteStatus);
mResourceManager->deleteProgram(context, mHandle);
}
unsigned int Program::getRefCount() const
......@@ -2375,18 +2359,6 @@ bool Program::isValidated() const
return mValidated;
}
GLuint Program::getActiveAtomicCounterBufferCount() const
{
ASSERT(mLinkResolved);
return static_cast<GLuint>(mState.mAtomicCounterBuffers.size());
}
GLuint Program::getActiveShaderStorageBlockCount() const
{
ASSERT(mLinkResolved);
return static_cast<GLuint>(mState.mShaderStorageBlocks.size());
}
void Program::getActiveUniformBlockName(const GLuint blockIndex,
GLsizei bufSize,
GLsizei *length,
......
......@@ -497,7 +497,11 @@ class Program final : angle::NonCopyable, public LabeledObject
void setLabel(const std::string &label) override;
const std::string &getLabel() const override;
rx::ProgramImpl *getImplementation() const;
ANGLE_INLINE rx::ProgramImpl *getImplementation() const
{
ASSERT(mLinkResolved);
return mProgram;
}
void attachShader(Shader *shader);
void detachShader(const Context *context, Shader *shader);
......@@ -675,13 +679,25 @@ class Program final : angle::NonCopyable, public LabeledObject
GLsizei bufSize,
GLsizei *length,
GLchar *blockName) const;
GLuint getActiveUniformBlockCount() const
ANGLE_INLINE GLuint getActiveUniformBlockCount() const
{
ASSERT(mLinkResolved);
return static_cast<GLuint>(mState.mUniformBlocks.size());
}
GLuint getActiveAtomicCounterBufferCount() const;
GLuint getActiveShaderStorageBlockCount() const;
ANGLE_INLINE GLuint getActiveAtomicCounterBufferCount() const
{
ASSERT(mLinkResolved);
return static_cast<GLuint>(mState.mAtomicCounterBuffers.size());
}
ANGLE_INLINE GLuint getActiveShaderStorageBlockCount() const
{
ASSERT(mLinkResolved);
return static_cast<GLuint>(mState.mShaderStorageBlocks.size());
}
GLint getActiveUniformBlockMaxNameLength() const;
GLint getActiveShaderStorageBlockMaxNameLength() const;
......@@ -710,8 +726,23 @@ class Program final : angle::NonCopyable, public LabeledObject
GLuint getTransformFeedbackVaryingResourceIndex(const GLchar *name) const;
const TransformFeedbackVarying &getTransformFeedbackVaryingResource(GLuint index) const;
void addRef();
void release(const Context *context);
ANGLE_INLINE void addRef()
{
ASSERT(mLinkResolved);
mRefCount++;
}
ANGLE_INLINE void release(const Context *context)
{
ASSERT(mLinkResolved);
mRefCount--;
if (mRefCount == 0 && mDeleteStatus)
{
deleteSelf(context);
}
}
unsigned int getRefCount() const;
bool isInUse() const { return getRefCount() != 0; }
void flagForDeletion();
......@@ -820,12 +851,15 @@ class Program final : angle::NonCopyable, public LabeledObject
}
}
ANGLE_INLINE bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
private:
struct LinkingState;
~Program() override;
void unlink();
void deleteSelf(const Context *context);
bool linkValidateShaders(InfoLog &infoLog);
bool linkAttributes(const Caps &caps, InfoLog &infoLog);
......
......@@ -191,11 +191,6 @@ void ShaderProgramManager::deleteProgram(const gl::Context *context, GLuint prog
deleteObject(context, &mPrograms, program);
}
Program *ShaderProgramManager::getProgram(GLuint handle) const
{
return mPrograms.query(handle);
}
template <typename ObjectType>
void ShaderProgramManager::deleteObject(const Context *context,
ResourceMap<ObjectType> *objectMap,
......
......@@ -147,7 +147,8 @@ class ShaderProgramManager : public ResourceManagerBase<HandleAllocator>
GLuint createProgram(rx::GLImplFactory *factory);
void deleteProgram(const Context *context, GLuint program);
Program *getProgram(GLuint handle) const;
ANGLE_INLINE Program *getProgram(GLuint handle) const { return mPrograms.query(handle); }
protected:
~ShaderProgramManager() override;
......
......@@ -1423,13 +1423,6 @@ void State::setTransformFeedbackBinding(const Context *context,
mDirtyBits.set(DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING);
}
bool State::isTransformFeedbackActiveUnpaused() const
{
TransformFeedback *curTransformFeedback = mTransformFeedback.get();
return curTransformFeedback && curTransformFeedback->isActive() &&
!curTransformFeedback->isPaused();
}
bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback)
{
if (mTransformFeedback.id() == transformFeedback)
......@@ -2913,7 +2906,11 @@ angle::Result State::onProgramExecutableChange(const Context *context, Program *
ASSERT(program->isLinked());
mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE);
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM);
if (program->hasAnyDirtyBit())
{
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM);
}
// Set any bound textures.
const ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes();
......
......@@ -247,7 +247,13 @@ class State : angle::NonCopyable
void setTransformFeedbackBinding(const Context *context, TransformFeedback *transformFeedback);
TransformFeedback *getCurrentTransformFeedback() const { return mTransformFeedback.get(); }
bool isTransformFeedbackActiveUnpaused() const;
ANGLE_INLINE bool isTransformFeedbackActiveUnpaused() const
{
TransformFeedback *curTransformFeedback = mTransformFeedback.get();
return curTransformFeedback && curTransformFeedback->isActive() &&
!curTransformFeedback->isPaused();
}
bool removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback);
// Query binding manipulation
......
......@@ -658,11 +658,6 @@ void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformB
}
}
GLuint ProgramGL::getProgramID() const
{
return mProgramID;
}
bool ProgramGL::getUniformBlockSize(const std::string & /* blockName */,
const std::string &blockMappedName,
size_t *sizeOut) const
......
......@@ -78,7 +78,7 @@ class ProgramGL : public ProgramImpl
std::vector<gl::SamplerBinding> *samplerBindings,
std::vector<gl::ImageBinding> *imageBindings) override;
GLuint getProgramID() const;
ANGLE_INLINE GLuint getProgramID() const { return mProgramID; }
void enableSideBySideRenderingPath() const;
void enableLayeredRenderingPath(int baseViewIndex) const;
......
......@@ -2122,19 +2122,6 @@ bool ValidateUniform1ivValue(Context *context,
return false;
}
bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType)
{
// Check that the value type is compatible with uniform type.
// Do the cheaper test first, for a little extra speed.
if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType)
{
return true;
}
ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch);
return false;
}
bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType)
{
// Check that the value type is compatible with uniform type.
......
......@@ -11,7 +11,9 @@
#include "common/PackedEnums.h"
#include "common/mathutil.h"
#include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/ErrorStrings.h"
#include "libANGLE/Framebuffer.h"
#include <GLES2/gl2.h>
......@@ -219,7 +221,19 @@ bool ValidateUniform1ivValue(Context *context,
GLenum uniformType,
GLsizei count,
const GLint *value);
bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType);
ANGLE_INLINE bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType)
{
// Check that the value type is compatible with uniform type.
// Do the cheaper test first, for a little extra speed.
if (valueType != uniformType && VariableBoolVectorType(valueType) != uniformType)
{
context->validationError(GL_INVALID_OPERATION, kErrorUniformSizeMismatch);
return false;
}
return true;
}
bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType);
bool ValidateUniform(Context *context, GLenum uniformType, GLint location, GLsizei count);
bool ValidateUniformMatrix(Context *context,
......
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