Commit 253b8d20 by apatrick@chromium.org

Refactor program info log out of ProgramBinary and in to Program.

Tested by setting breakpoint in esLoadProgram with the broken program. Review URL: https://codereview.appspot.com/6305114 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1164 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2979ed2c
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 1162
#define BUILD_REVISION 1164
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -2996,7 +2996,7 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
applyShaders();
applyTextures();
if (!getCurrentProgram()->getProgramBinary()->validateSamplers(false))
if (!getCurrentProgram()->getProgramBinary()->validateSamplers(NULL))
{
return error(GL_INVALID_OPERATION);
}
......
......@@ -20,6 +20,8 @@
namespace gl
{
const char * const g_fakepath = "C:\\fakepath";
unsigned int Program::mCurrentSerial = 1;
AttributeBindings::AttributeBindings()
......@@ -30,6 +32,112 @@ AttributeBindings::~AttributeBindings()
{
}
InfoLog::InfoLog() : mInfoLog(NULL)
{
}
InfoLog::~InfoLog()
{
delete[] mInfoLog;
}
int InfoLog::getLength() const
{
if (!mInfoLog)
{
return 0;
}
else
{
return strlen(mInfoLog) + 1;
}
}
void InfoLog::getLog(GLsizei bufSize, GLsizei *length, char *infoLog)
{
int index = 0;
if (bufSize > 0)
{
if (mInfoLog)
{
index = std::min(bufSize - 1, (int)strlen(mInfoLog));
memcpy(infoLog, mInfoLog, index);
}
infoLog[index] = '\0';
}
if (length)
{
*length = index;
}
}
// append a santized message to the program info log.
// The D3D compiler includes a fake file path in some of the warning or error
// messages, so lets remove all occurrences of this fake file path from the log.
void InfoLog::appendSanitized(const char *message)
{
std::string msg(message);
size_t found;
do
{
found = msg.find(g_fakepath);
if (found != std::string::npos)
{
msg.erase(found, strlen(g_fakepath));
}
}
while (found != std::string::npos);
append("%s\n", msg.c_str());
}
void InfoLog::append(const char *format, ...)
{
if (!format)
{
return;
}
char info[1024];
va_list vararg;
va_start(vararg, format);
vsnprintf(info, sizeof(info), format, vararg);
va_end(vararg);
size_t infoLength = strlen(info);
if (!mInfoLog)
{
mInfoLog = new char[infoLength + 1];
strcpy(mInfoLog, info);
}
else
{
size_t logLength = strlen(mInfoLog);
char *newLog = new char[logLength + infoLength + 1];
strcpy(newLog, mInfoLog);
strcpy(newLog + logLength, info);
delete[] mInfoLog;
mInfoLog = newLog;
}
}
void InfoLog::reset()
{
if (mInfoLog)
{
delete [] mInfoLog;
mInfoLog = NULL;
}
}
Program::Program(ResourceManager *manager, GLuint handle) : mResourceManager(manager), mHandle(handle), mSerial(issueSerial())
{
mFragmentShader = NULL;
......@@ -138,8 +246,10 @@ void Program::link()
{
unlink(false);
mInfoLog.reset();
mProgramBinary = new ProgramBinary;
if (!mProgramBinary->link(mAttributeBindings, mFragmentShader, mVertexShader))
if (!mProgramBinary->link(mInfoLog, mAttributeBindings, mFragmentShader, mVertexShader))
{
unlink(false);
}
......@@ -226,34 +336,12 @@ unsigned int Program::issueSerial()
int Program::getInfoLogLength() const
{
if (mProgramBinary)
{
return mProgramBinary->getInfoLogLength();
}
else
{
return 0;
}
return mInfoLog.getLength();
}
void Program::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog)
{
if (mProgramBinary)
{
return mProgramBinary->getInfoLog(bufSize, length, infoLog);
}
else
{
if (bufSize > 0)
{
infoLog[0] = '\0';
}
if (length)
{
*length = 0;
}
}
return mInfoLog.getLog(bufSize, length, infoLog);
}
void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders)
......@@ -390,6 +478,20 @@ bool Program::isFlaggedForDeletion() const
return mDeleteStatus;
}
void Program::validate()
{
mInfoLog.reset();
if (mProgramBinary)
{
mProgramBinary->validate(mInfoLog);
}
else
{
mInfoLog.append("Program has not been successfully linked.");
}
}
bool Program::isValidated() const
{
if (mProgramBinary)
......
......@@ -23,6 +23,8 @@ class ResourceManager;
class FragmentShader;
class VertexShader;
extern const char * const g_fakepath;
class AttributeBindings
{
public:
......@@ -36,6 +38,23 @@ class AttributeBindings
std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
};
class InfoLog
{
public:
InfoLog();
~InfoLog();
int getLength() const;
void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
void appendSanitized(const char *message);
void append(const char *info, ...);
void reset();
private:
DISALLOW_COPY_AND_ASSIGN(InfoLog);
char *mInfoLog;
};
class Program
{
public:
......@@ -71,6 +90,7 @@ class Program
void flagForDeletion();
bool isFlaggedForDeletion() const;
void validate();
bool isValidated() const;
unsigned int getSerial() const;
......@@ -98,6 +118,8 @@ class Program
ResourceManager *mResourceManager;
const GLuint mHandle;
InfoLog mInfoLog;
};
}
......
......@@ -128,9 +128,7 @@ class ProgramBinary
void dirtyAllUniforms();
void applyUniforms();
bool link(const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
......@@ -141,8 +139,8 @@ class ProgramBinary
GLint getActiveUniformCount();
GLint getActiveUniformMaxLength();
void validate();
bool validateSamplers(bool logErrors);
void validate(InfoLog &infoLog);
bool validateSamplers(InfoLog *infoLog);
bool isValidated() const;
static std::string decorateAttribute(const std::string &name); // Prepend an underscore
......@@ -151,15 +149,15 @@ class ProgramBinary
private:
DISALLOW_COPY_AND_ASSIGN(ProgramBinary);
ID3D10Blob *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
ID3D10Blob *compileToBinary(InfoLog &infoLog, const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
int packVaryings(const Varying *packing[][4], FragmentShader *fragmentShader);
bool linkVaryings(std::string& pixelHLSL, std::string& vertexHLSL, FragmentShader *fragmentShader, VertexShader *vertexShader);
int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader);
bool linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::string& vertexHLSL, FragmentShader *fragmentShader, VertexShader *vertexShader);
bool linkAttributes(const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
bool linkUniforms(GLenum shader, ID3DXConstantTable *constantTable);
bool defineUniform(GLenum shader, const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
bool linkUniforms(InfoLog &infoLog, GLenum shader, ID3DXConstantTable *constantTable);
bool defineUniform(InfoLog &infoLog, GLenum shader, const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
bool defineUniform(GLenum shader, const D3DXCONSTANT_DESC &constantDescription, const std::string &name);
Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, const std::string &name);
bool applyUniformnfv(Uniform *targetUniform, const GLfloat *v);
......@@ -170,12 +168,6 @@ class ProgramBinary
void applyUniformniv(Uniform *targetUniform, GLsizei count, const D3DXVECTOR4 *vector);
void applyUniformnbv(Uniform *targetUniform, GLsizei count, int width, const GLboolean *v);
void appendToInfoLogSanitized(const char *message);
void appendToInfoLog(const char *info, ...);
void resetInfoLog();
static unsigned int issueSerial();
IDirect3DDevice9 *mDevice;
IDirect3DPixelShader9 *mPixelExecutable;
......@@ -212,7 +204,6 @@ class ProgramBinary
GLint mDxFrontCCWLocation;
GLint mDxPointsOrLinesLocation;
char *mInfoLog;
bool mValidated;
};
}
......
......@@ -6444,13 +6444,7 @@ void __stdcall glValidateProgram(GLuint program)
}
}
gl::ProgramBinary *programBinary = programObject->getProgramBinary();
if (!programBinary)
{
return;
}
programBinary->validate();
programObject->validate();
}
}
catch(std::bad_alloc&)
......
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