Bug 1080266 - Simplify WebGLContext::LinkProgram. - r=kamidphish

This commit is contained in:
jdashg 2014-10-03 14:47:00 -07:00
Родитель 8d30cdc7be
Коммит 1d871dfa7e
1 изменённых файлов: 45 добавлений и 45 удалений

Просмотреть файл

@ -1893,6 +1893,25 @@ bool WebGLContext::BindArrayAttribToLocation0(WebGLProgram *program)
return false; return false;
} }
static void
LinkAndUpdateProgram(GLContext* gl, WebGLProgram* prog)
{
GLuint name = prog->GLName();
gl->fLinkProgram(name);
prog->SetLinkStatus(false);
GLint ok = 0;
gl->fGetProgramiv(name, LOCAL_GL_LINK_STATUS, &ok);
if (!ok)
return;
if (!prog->UpdateInfo())
return;
prog->SetLinkStatus(true);
}
void void
WebGLContext::LinkProgram(WebGLProgram *program) WebGLContext::LinkProgram(WebGLProgram *program)
{ {
@ -1905,16 +1924,20 @@ WebGLContext::LinkProgram(WebGLProgram *program)
InvalidateBufferFetching(); // we do it early in this function InvalidateBufferFetching(); // we do it early in this function
// as some of the validation below changes program state // as some of the validation below changes program state
GLuint progname = program->GLName();
if (!program->NextGeneration()) { if (!program->NextGeneration()) {
// XXX throw? // XXX throw?
return; return;
} }
if (!program->HasBothShaderTypesAttached()) { if (!program->HasBothShaderTypesAttached()) {
GenerateWarning("linkProgram: this program doesn't have both a vertex shader" GenerateWarning("linkProgram: this program doesn't have both a vertex"
" and a fragment shader"); " shader and a fragment shader");
program->SetLinkStatus(false);
return;
}
if (program->HasBadShaderAttached()) {
GenerateWarning("linkProgram: The program has bad shaders attached.");
program->SetLinkStatus(false); program->SetLinkStatus(false);
return; return;
} }
@ -1925,56 +1948,25 @@ WebGLContext::LinkProgram(WebGLProgram *program)
mIsMesa && mIsMesa &&
program->UpperBoundNumSamplerUniforms() > 16) program->UpperBoundNumSamplerUniforms() > 16)
{ {
GenerateWarning("Programs with more than 16 samplers are disallowed on Mesa drivers " "to avoid a Mesa crasher."); GenerateWarning("Programs with more than 16 samplers are disallowed on"
" Mesa drivers to avoid a Mesa crasher.");
program->SetLinkStatus(false); program->SetLinkStatus(false);
return; return;
} }
bool updateInfoSucceeded = false; MakeContextCurrent();
GLint ok = 0; LinkAndUpdateProgram(gl, program);
if (gl->WorkAroundDriverBugs() &&
program->HasBadShaderAttached())
{
// it's a common driver bug, caught by program-test.html, that linkProgram doesn't
// correctly preserve the state of an in-use program that has been attached a bad shader
// see bug 777883
ok = false;
} else {
MakeContextCurrent();
gl->fLinkProgram(progname);
gl->fGetProgramiv(progname, LOCAL_GL_LINK_STATUS, &ok);
if (ok) { if (program->LinkStatus()) {
updateInfoSucceeded = program->UpdateInfo(); if (BindArrayAttribToLocation0(program)) {
program->SetLinkStatus(updateInfoSucceeded); GenerateWarning("linkProgram: Relinking program to make attrib0 an"
" array.");
if (BindArrayAttribToLocation0(program)) { LinkAndUpdateProgram(gl, program);
GenerateWarning("linkProgram: relinking program to make attrib0 an "
"array.");
gl->fLinkProgram(progname);
gl->fGetProgramiv(progname, LOCAL_GL_LINK_STATUS, &ok);
if (ok) {
updateInfoSucceeded = program->UpdateInfo();
program->SetLinkStatus(updateInfoSucceeded);
}
}
} }
} }
if (ok) { if (!program->LinkStatus()) {
// Bug 750527
if (gl->WorkAroundDriverBugs() &&
updateInfoSucceeded &&
gl->Vendor() == gl::GLVendor::NVIDIA)
{
if (program == mCurrentProgram)
gl->fUseProgram(progname);
}
} else {
program->SetLinkStatus(false);
if (ShouldGenerateWarnings()) { if (ShouldGenerateWarnings()) {
// report shader/program infoLogs as warnings. // report shader/program infoLogs as warnings.
// note that shader compilation errors can be deferred to linkProgram, // note that shader compilation errors can be deferred to linkProgram,
// which is why we can't do anything in compileShader. In practice we could // which is why we can't do anything in compileShader. In practice we could
@ -2020,6 +2012,14 @@ WebGLContext::LinkProgram(WebGLProgram *program)
} }
} }
} }
return;
}
if (gl->WorkAroundDriverBugs() &&
gl->Vendor() == gl::GLVendor::NVIDIA)
{
if (program == mCurrentProgram)
gl->fUseProgram(program->GLName());
} }
} }