Program: Make LinkResult use gl::ErrorOrResult.

This simplifies the error handling code, and allows the use of the
ANGLE_TRY macro (and friends).

BUG=angleproject:1576

Change-Id: I3142388b10d0dd67a7f49a5c8c3d11102996be93
Reviewed-on: https://chromium-review.googlesource.com/411201
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
Jamie Madill 2016-11-13 20:02:12 -05:00 коммит произвёл Commit Bot
Родитель 9863a3ef18
Коммит b0a838bff5
7 изменённых файлов: 54 добавлений и 88 удалений

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

@ -141,7 +141,7 @@ def generate_impl_definition(impl_stub, typed_impl):
elif return_type == 'egl::Error':
return_statement = ' return egl::Error(EGL_BAD_ACCESS);\n'
elif return_type == 'LinkResult':
return_statement = ' return LinkResult(false, gl::Error(GL_INVALID_OPERATION));\n'
return_statement = ' return gl::Error(GL_INVALID_OPERATION);\n'
elif re.search(r'\*$', return_type):
return_statement = ' return static_cast<' + return_type + '>(0);\n'
elif re.search(r'const ([^ \&]+) \&$', return_type):

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

@ -597,11 +597,10 @@ Error Program::link(const ContextState &data)
return NoError();
}
rx::LinkResult result = mProgram->link(data, mInfoLog);
if (result.error.isError() || !result.linkSuccess)
ANGLE_TRY_RESULT(mProgram->link(data, mInfoLog), mLinked);
if (!mLinked)
{
return result.error;
return NoError();
}
}
else
@ -654,10 +653,10 @@ Error Program::link(const ContextState &data)
linkOutputVariables();
rx::LinkResult result = mProgram->link(data, mInfoLog);
if (result.error.isError() || !result.linkSuccess)
ANGLE_TRY_RESULT(mProgram->link(data, mInfoLog), mLinked);
if (!mLinked)
{
return result.error;
return NoError();
}
gatherTransformFeedbackVaryings(mergedVaryings);
@ -665,7 +664,6 @@ Error Program::link(const ContextState &data)
gatherInterfaceBlockInfo();
mLinked = true;
return NoError();
}
@ -845,14 +843,9 @@ Error Program::loadBinary(GLenum binaryFormat, const void *binary, GLsizei lengt
stream.readInt(&mSamplerUniformRange.start);
stream.readInt(&mSamplerUniformRange.end);
rx::LinkResult result = mProgram->load(mInfoLog, &stream);
if (result.error.isError() || !result.linkSuccess)
{
return result.error;
}
ANGLE_TRY_RESULT(mProgram->load(mInfoLog, &stream), mLinked);
mLinked = true;
return Error(GL_NO_ERROR);
return NoError();
#endif // #if ANGLE_PROGRAM_BINARY_LOAD == ANGLE_ENABLED
}

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

@ -24,14 +24,7 @@ struct BlockMemberInfo;
namespace rx
{
struct LinkResult
{
LinkResult(bool linkSuccess, const gl::Error &error) : linkSuccess(linkSuccess), error(error) {}
bool linkSuccess;
gl::Error error;
};
using LinkResult = gl::ErrorOrResult<bool>;
class ProgramImpl : angle::NonCopyable
{

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

@ -739,14 +739,14 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
if (memcmp(&identifier, &binaryDeviceIdentifier, sizeof(DeviceIdentifier)) != 0)
{
infoLog << "Invalid program binary, device configuration has changed.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
int compileFlags = stream->readInt<int>();
if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
{
infoLog << "Mismatched compilation flags.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
for (int &index : mAttribLocationToD3DSemantic)
@ -780,7 +780,7 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
if (stream->error())
{
infoLog << "Invalid program binary.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
const auto &linkedUniforms = mState.getUniforms();
@ -804,7 +804,7 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
if (stream->error())
{
infoLog << "Invalid program binary.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
ASSERT(mD3DUniformBlocks.empty());
@ -853,6 +853,8 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
const unsigned char *binary = reinterpret_cast<const unsigned char *>(stream->data());
bool separateAttribs = (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS);
const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount;
vertexShaderIndex++)
@ -870,18 +872,14 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
ShaderExecutableD3D *shaderExecutable = nullptr;
gl::Error error = mRenderer->loadExecutable(
vertexShaderFunction, vertexShaderSize, SHADER_VERTEX, mStreamOutVaryings,
(mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), &shaderExecutable);
if (error.isError())
{
return LinkResult(false, error);
}
ANGLE_TRY(mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize, SHADER_VERTEX,
mStreamOutVaryings, separateAttribs,
&shaderExecutable));
if (!shaderExecutable)
{
infoLog << "Could not create vertex shader.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
// generated converted input layout
@ -909,18 +907,14 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
const unsigned char *pixelShaderFunction = binary + stream->offset();
ShaderExecutableD3D *shaderExecutable = nullptr;
gl::Error error = mRenderer->loadExecutable(
pixelShaderFunction, pixelShaderSize, SHADER_PIXEL, mStreamOutVaryings,
(mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS), &shaderExecutable);
if (error.isError())
{
return LinkResult(false, error);
}
ANGLE_TRY(mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL,
mStreamOutVaryings, separateAttribs,
&shaderExecutable));
if (!shaderExecutable)
{
infoLog << "Could not create pixel shader.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
// add new binary
@ -940,27 +934,22 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
}
const unsigned char *geometryShaderFunction = binary + stream->offset();
bool splitAttribs = (mState.getTransformFeedbackBufferMode() == GL_SEPARATE_ATTRIBS);
gl::Error error = mRenderer->loadExecutable(
geometryShaderFunction, geometryShaderSize, SHADER_GEOMETRY, mStreamOutVaryings,
splitAttribs, &mGeometryExecutables[geometryExeIndex]);
if (error.isError())
{
return LinkResult(false, error);
}
ANGLE_TRY(mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize,
SHADER_GEOMETRY, mStreamOutVaryings, separateAttribs,
&mGeometryExecutables[geometryExeIndex]));
if (!mGeometryExecutables[geometryExeIndex])
{
infoLog << "Could not create geometry shader.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
stream->skip(geometryShaderSize);
}
initializeUniformStorage();
return LinkResult(true, gl::Error(GL_NO_ERROR));
return true;
}
gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
@ -1289,22 +1278,14 @@ LinkResult ProgramD3D::compileProgramExecutables(const gl::ContextState &data, g
{
const gl::InputLayout &defaultInputLayout =
GetDefaultInputLayoutFromShader(mState.getAttachedVertexShader());
ShaderExecutableD3D *defaultVertexExecutable = NULL;
gl::Error error =
getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog);
if (error.isError())
{
return LinkResult(false, error);
}
ShaderExecutableD3D *defaultVertexExecutable = nullptr;
ANGLE_TRY(
getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog));
std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
ShaderExecutableD3D *defaultPixelExecutable = NULL;
error =
getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog);
if (error.isError())
{
return LinkResult(false, error);
}
ShaderExecutableD3D *defaultPixelExecutable = nullptr;
ANGLE_TRY(
getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog));
// Auto-generate the geometry shader here, if we expect to be using point rendering in D3D11.
ShaderExecutableD3D *pointGS = nullptr;
@ -1337,9 +1318,8 @@ LinkResult ProgramD3D::compileProgramExecutables(const gl::ContextState &data, g
fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo());
}
bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable &&
(!usesGeometryShader(GL_POINTS) || pointGS));
return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR));
return (defaultVertexExecutable && defaultPixelExecutable &&
(!usesGeometryShader(GL_POINTS) || pointGS));
}
LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
@ -1363,7 +1343,7 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
if (fragmentShaderD3D->usesFrontFacing())
{
infoLog << "The current renderer doesn't support gl_FrontFacing";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
}
@ -1375,7 +1355,7 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
if (!varyingPacking.packVaryings(infoLog, packedVaryings,
mState.getTransformFeedbackVaryingNames()))
{
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
ProgramD3DMetadata metadata(mRenderer, vertexShaderD3D, fragmentShaderD3D);
@ -1386,7 +1366,7 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
if (static_cast<GLuint>(varyingPacking.getRegisterCount()) > data.getCaps().maxVaryingVectors)
{
infoLog << "No varying registers left to support gl_FragCoord/gl_PointCoord";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
// TODO(jmadill): Implement more sophisticated component packing in D3D9.
@ -1396,13 +1376,13 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
varyingPacking.getMaxSemanticIndex() > data.getCaps().maxVaryingVectors)
{
infoLog << "Cannot pack these varyings on D3D9.";
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
if (!mDynamicHLSL->generateShaderLinkHLSL(data, mState, metadata, varyingPacking, &mPixelHLSL,
&mVertexHLSL))
{
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
mUsesPointSize = vertexShaderD3D->usesPointSize();
@ -1433,12 +1413,12 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
gatherTransformFeedbackVaryings(varyingPacking);
LinkResult result = compileProgramExecutables(data, infoLog);
if (result.error.isError())
if (result.isError())
{
infoLog << result.error.getMessage();
infoLog << result.getError().getMessage();
return result;
}
else if (!result.linkSuccess)
else if (!result.getResult())
{
infoLog << "Failed to create D3D shaders.";
return result;
@ -1446,7 +1426,7 @@ LinkResult ProgramD3D::link(const gl::ContextState &data, gl::InfoLog &infoLog)
initUniformBlockInfo();
return LinkResult(true, gl::Error(GL_NO_ERROR));
return true;
}
GLboolean ProgramD3D::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)

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

@ -62,12 +62,12 @@ LinkResult ProgramGL::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
// Verify that the program linked
if (!checkLinkStatus(infoLog))
{
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
postLink();
return LinkResult(true, gl::Error(GL_NO_ERROR));
return true;
}
gl::Error ProgramGL::save(gl::BinaryOutputStream *stream)
@ -167,7 +167,7 @@ LinkResult ProgramGL::link(const gl::ContextState &data, gl::InfoLog &infoLog)
// Verify the link
if (!checkLinkStatus(infoLog))
{
return LinkResult(false, gl::Error(GL_NO_ERROR));
return false;
}
if (mWorkarounds.alwaysCallUseProgramAfterLink)
@ -177,7 +177,7 @@ LinkResult ProgramGL::link(const gl::ContextState &data, gl::InfoLog &infoLog)
postLink();
return LinkResult(true, gl::Error(GL_NO_ERROR));
return true;
}
GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)

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

@ -25,7 +25,7 @@ ProgramNULL::~ProgramNULL()
LinkResult ProgramNULL::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
return gl::Error(GL_INVALID_OPERATION);
}
gl::Error ProgramNULL::save(gl::BinaryOutputStream *stream)
@ -42,7 +42,7 @@ void ProgramNULL::setBinaryRetrievableHint(bool retrievable)
LinkResult ProgramNULL::link(const gl::ContextState &data, gl::InfoLog &infoLog)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
return gl::Error(GL_INVALID_OPERATION);
}
GLboolean ProgramNULL::validate(const gl::Caps &caps, gl::InfoLog *infoLog)

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

@ -25,7 +25,7 @@ ProgramVk::~ProgramVk()
LinkResult ProgramVk::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
return gl::Error(GL_INVALID_OPERATION);
}
gl::Error ProgramVk::save(gl::BinaryOutputStream *stream)
@ -42,7 +42,7 @@ void ProgramVk::setBinaryRetrievableHint(bool retrievable)
LinkResult ProgramVk::link(const gl::ContextState &data, gl::InfoLog &infoLog)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
return gl::Error(GL_INVALID_OPERATION);
}
GLboolean ProgramVk::validate(const gl::Caps &caps, gl::InfoLog *infoLog)