Make ProgramBinary a refcount object and use Binding pointers to maintain it's…

Make ProgramBinary a refcount object and use Binding pointers to maintain it's lifetime on context and program. Trac #21270 Bug=351 Signed-off-by: Nicolas Capens This fixes the underlying bug since it allows the context to keep the program binary alive, after a relink has occurred. git-svn-id: https://angleproject.googlecode.com/svn/trunk@1242 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 716056c7
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 1229
#define BUILD_REVISION 1242
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -141,7 +141,7 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext, boo
bindRenderbuffer(0);
mState.currentProgram = 0;
mCurrentProgramBinary = NULL;
mCurrentProgramBinary.set(NULL);
mState.packAlignment = 4;
mState.unpackAlignment = 4;
......@@ -186,7 +186,7 @@ Context::~Context()
}
mState.currentProgram = 0;
}
mCurrentProgramBinary = NULL;
mCurrentProgramBinary.set(NULL);
while (!mFramebufferMap.empty())
{
......@@ -1147,13 +1147,13 @@ void Context::useProgram(GLuint program)
{
Program *newProgram = mResourceManager->getProgram(program);
Program *oldProgram = mResourceManager->getProgram(priorProgram);
mCurrentProgramBinary = NULL;
mCurrentProgramBinary.set(NULL);
mDxUniformsDirty = true;
if (newProgram)
{
newProgram->addRef();
mCurrentProgramBinary = newProgram->getProgramBinary();
mCurrentProgramBinary.set(newProgram->getProgramBinary());
}
if (oldProgram)
......@@ -1173,7 +1173,7 @@ void Context::linkProgram(GLuint program)
// need to install the new executables
if (linked && program == mState.currentProgram)
{
mCurrentProgramBinary = programObject->getProgramBinary();
mCurrentProgramBinary.set(programObject->getProgramBinary());
mDxUniformsDirty = true;
}
}
......@@ -1188,7 +1188,7 @@ void Context::setProgramBinary(GLuint program, const void *binary, GLint length)
// need to install the new executables
if (loaded && program == mState.currentProgram)
{
mCurrentProgramBinary = programObject->getProgramBinary();
mCurrentProgramBinary.set(programObject->getProgramBinary());
mDxUniformsDirty = true;
}
......@@ -1358,7 +1358,7 @@ Buffer *Context::getElementArrayBuffer()
ProgramBinary *Context::getCurrentProgramBinary()
{
return mCurrentProgramBinary;
return mCurrentProgramBinary.get();
}
Texture2D *Context::getTexture2D()
......
......@@ -599,7 +599,7 @@ class Context
bool mRenderTargetDescInitialized;
D3DSURFACE_DESC mRenderTargetDesc;
bool mDxUniformsDirty;
ProgramBinary *mCurrentProgramBinary;
BindingPointer<ProgramBinary> mCurrentProgramBinary;
Framebuffer *mBoundDrawFramebuffer;
bool mSupportsShaderModel3;
......
......@@ -140,7 +140,7 @@ Program::Program(ResourceManager *manager, GLuint handle) : mResourceManager(man
{
mFragmentShader = NULL;
mVertexShader = NULL;
mProgramBinary = NULL;
mProgramBinary.set(NULL);
mDeleteStatus = false;
mLinked = false;
mRefCount = 0;
......@@ -247,7 +247,7 @@ bool Program::link()
mInfoLog.reset();
mProgramBinary = new ProgramBinary;
mProgramBinary.set(new ProgramBinary());
mLinked = mProgramBinary->link(mInfoLog, mAttributeBindings, mFragmentShader, mVertexShader);
return mLinked;
......@@ -284,11 +284,7 @@ void Program::unlink(bool destroy)
}
}
if (mProgramBinary)
{
delete mProgramBinary;
mProgramBinary = NULL;
}
mProgramBinary.set(NULL);
mLinked = false;
}
......@@ -299,7 +295,7 @@ bool Program::isLinked()
ProgramBinary* Program::getProgramBinary()
{
return mProgramBinary;
return mProgramBinary.get();
}
bool Program::setProgramBinary(const void *binary, GLsizei length)
......@@ -308,12 +304,11 @@ bool Program::setProgramBinary(const void *binary, GLsizei length)
mInfoLog.reset();
mProgramBinary = new ProgramBinary;
mProgramBinary.set(new ProgramBinary());
mLinked = mProgramBinary->load(mInfoLog, binary, length);
if (!mLinked)
{
delete mProgramBinary;
mProgramBinary = NULL;
mProgramBinary.set(NULL);
}
return mLinked;
......@@ -341,9 +336,10 @@ unsigned int Program::getRefCount() const
GLint Program::getProgramBinaryLength() const
{
if (mProgramBinary)
ProgramBinary *programBinary = mProgramBinary.get();
if (programBinary)
{
return mProgramBinary->getLength();
return programBinary->getLength();
}
else
{
......@@ -393,9 +389,10 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade
void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
mProgramBinary->getActiveAttribute(index, bufsize, length, size, type, name);
programBinary->getActiveAttribute(index, bufsize, length, size, type, name);
}
else
{
......@@ -416,9 +413,10 @@ void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length,
GLint Program::getActiveAttributeCount()
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
return mProgramBinary->getActiveAttributeCount();
return programBinary->getActiveAttributeCount();
}
else
{
......@@ -428,9 +426,10 @@ GLint Program::getActiveAttributeCount()
GLint Program::getActiveAttributeMaxLength()
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
return mProgramBinary->getActiveAttributeMaxLength();
return programBinary->getActiveAttributeMaxLength();
}
else
{
......@@ -440,9 +439,10 @@ GLint Program::getActiveAttributeMaxLength()
void Program::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
return mProgramBinary->getActiveUniform(index, bufsize, length, size, type, name);
return programBinary->getActiveUniform(index, bufsize, length, size, type, name);
}
else
{
......@@ -463,9 +463,10 @@ void Program::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, G
GLint Program::getActiveUniformCount()
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
return mProgramBinary->getActiveUniformCount();
return programBinary->getActiveUniformCount();
}
else
{
......@@ -475,9 +476,10 @@ GLint Program::getActiveUniformCount()
GLint Program::getActiveUniformMaxLength()
{
if (mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (programBinary)
{
return mProgramBinary->getActiveUniformMaxLength();
return programBinary->getActiveUniformMaxLength();
}
else
{
......@@ -499,9 +501,10 @@ void Program::validate()
{
mInfoLog.reset();
if (isLinked() && mProgramBinary)
ProgramBinary *programBinary = getProgramBinary();
if (isLinked() && programBinary)
{
mProgramBinary->validate(mInfoLog);
programBinary->validate(mInfoLog);
}
else
{
......@@ -511,9 +514,10 @@ void Program::validate()
bool Program::isValidated() const
{
if (mProgramBinary)
ProgramBinary *programBinary = mProgramBinary.get();
if (programBinary)
{
return mProgramBinary->isValidated();
return programBinary->isValidated();
}
else
{
......
......@@ -106,7 +106,7 @@ class Program
AttributeBindings mAttributeBindings;
ProgramBinary* mProgramBinary;
BindingPointer<ProgramBinary> mProgramBinary;
bool mLinked;
bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
......
......@@ -59,7 +59,7 @@ UniformLocation::UniformLocation(const std::string &_name, unsigned int element,
unsigned int ProgramBinary::mCurrentSerial = 1;
ProgramBinary::ProgramBinary() : mSerial(issueSerial())
ProgramBinary::ProgramBinary() : RefCountObject(0), mSerial(issueSerial())
{
mDevice = getDevice();
......
......@@ -94,7 +94,7 @@ struct UniformLocation
};
// This is the result of linking a program. It is the state that would be passed to ProgramBinary.
class ProgramBinary
class ProgramBinary : public RefCountObject
{
public:
ProgramBinary();
......
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