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