Bug 1203135 - Terminate linking if maximum vertex attribute count is exceeded on Mesa. r=jgilbert

This commit is contained in:
Andrew Comminos 2015-10-23 21:35:16 -07:00 committed by Andrew Comminos
parent 097f7f5601
commit 35ea764551
5 changed files with 36 additions and 10 deletions

View File

@ -911,18 +911,26 @@ WebGLProgram::LinkProgram()
gl::GLContext* gl = mContext->gl;
gl->MakeCurrent();
// Bug 777028: Mesa can't handle more than 16 samplers per program,
// counting each array entry.
size_t numSamplerUniforms_upperBound = mVertShader->CalcNumSamplerUniforms() +
mFragShader->CalcNumSamplerUniforms();
if (gl->WorkAroundDriverBugs() &&
mContext->mIsMesa &&
numSamplerUniforms_upperBound > 16)
mContext->mIsMesa)
{
mLinkLog.AssignLiteral("Programs with more than 16 samplers are disallowed on"
" Mesa drivers to avoid crashing.");
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
return false;
// Bug 777028: Mesa can't handle more than 16 samplers per program,
// counting each array entry.
size_t numSamplerUniforms_upperBound = mVertShader->CalcNumSamplerUniforms() +
mFragShader->CalcNumSamplerUniforms();
if (numSamplerUniforms_upperBound > 16) {
mLinkLog.AssignLiteral("Programs with more than 16 samplers are disallowed on"
" Mesa drivers to avoid crashing.");
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
return false;
}
// Bug 1203135: Mesa crashes internally if we exceed the reported maximum attribute count.
if (mVertShader->NumAttributes() > mContext->MaxVertexAttribs()) {
mLinkLog.AssignLiteral("Number of attributes exceeds Mesa's reported max attribute count.");
mContext->GenerateWarning("linkProgram: %s", mLinkLog.BeginReading());
return false;
}
}
// Bind the attrib locations.

View File

@ -308,6 +308,16 @@ WebGLShader::CalcNumSamplerUniforms() const
return 0;
}
size_t
WebGLShader::NumAttributes() const
{
if (mValidator)
return mValidator->NumAttributes();
// TODO
return 0;
}
void
WebGLShader::BindAttribLocation(GLuint prog, const nsCString& userName,
GLuint index) const

View File

@ -50,6 +50,7 @@ public:
// Util funcs
bool CanLinkTo(const WebGLShader* prev, nsCString* const out_log) const;
size_t CalcNumSamplerUniforms() const;
size_t NumAttributes() const;
void BindAttribLocation(GLuint prog, const nsCString& userName, GLuint index) const;
bool FindAttribUserNameByMappedName(const nsACString& mappedName,
nsDependentCString* const out_userName) const;

View File

@ -329,6 +329,12 @@ ShaderValidator::CalcNumSamplerUniforms() const
return accum;
}
size_t
ShaderValidator::NumAttributes() const
{
return ShGetAttributes(mHandle)->size();
}
// Attribs cannot be structs or arrays, and neither can vertex inputs in ES3.
// Therefore, attrib names are always simple.
bool

View File

@ -43,6 +43,7 @@ public:
void GetOutput(nsACString* out) const;
bool CanLinkTo(const ShaderValidator* prev, nsCString* const out_log) const;
size_t CalcNumSamplerUniforms() const;
size_t NumAttributes() const;
bool FindAttribUserNameByMappedName(const std::string& mappedName,
const std::string** const out_userName) const;