Commit 266f4429 by Geoff Lang Committed by Commit Bot

Cache BlitGL initialization state with a single bool.

We used to cache initializatin per-resource and check each one for every operation. This was slower and more error prone, the mSRGBMipmapGenerationFormat was computed every time. Found when diagnosing crbug.com/1136613 Bug: chromium:1136613 Change-Id: Ifd804fe1dc8e26e1a9b444cc1d0c6f73954da895 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2477037Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 8eaf72a8
......@@ -1109,52 +1109,45 @@ angle::Result BlitGL::generateSRGBMipmap(const gl::Context *context,
angle::Result BlitGL::initializeResources(const gl::Context *context)
{
for (size_t i = 0; i < ArraySize(mScratchTextures); i++)
if (mResourcesInitialized)
{
if (mScratchTextures[i] == 0)
{
ANGLE_GL_TRY(context, mFunctions->genTextures(1, &mScratchTextures[i]));
}
return angle::Result::Continue;
}
if (mScratchFBO == 0)
for (size_t i = 0; i < ArraySize(mScratchTextures); i++)
{
ANGLE_GL_TRY(context, mFunctions->genFramebuffers(1, &mScratchFBO));
ANGLE_GL_TRY(context, mFunctions->genTextures(1, &mScratchTextures[i]));
}
if (mVertexBuffer == 0)
{
ANGLE_GL_TRY(context, mFunctions->genBuffers(1, &mVertexBuffer));
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
ANGLE_GL_TRY(context, mFunctions->genFramebuffers(1, &mScratchFBO));
// Use a single, large triangle, to avoid arithmetic precision issues where fragments
// with the same Y coordinate don't get exactly the same interpolated texcoord Y.
float vertexData[] = {
-0.5f, 0.0f, 1.5f, 0.0f, 0.5f, 2.0f,
};
ANGLE_GL_TRY(context, mFunctions->genBuffers(1, &mVertexBuffer));
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
ANGLE_GL_TRY(context, mFunctions->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData,
GL_STATIC_DRAW));
}
// Use a single, large triangle, to avoid arithmetic precision issues where fragments
// with the same Y coordinate don't get exactly the same interpolated texcoord Y.
float vertexData[] = {
-0.5f, 0.0f, 1.5f, 0.0f, 0.5f, 2.0f,
};
if (mVAO == 0)
{
ANGLE_GL_TRY(context, mFunctions->genVertexArrays(1, &mVAO));
ANGLE_GL_TRY(context, mFunctions->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData,
GL_STATIC_DRAW));
mStateManager->bindVertexArray(mVAO, 0);
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
ANGLE_GL_TRY(context, mFunctions->genVertexArrays(1, &mVAO));
// Enable all attributes with the same buffer so that it doesn't matter what location the
// texcoord attribute is assigned
GLint maxAttributes = 0;
ANGLE_GL_TRY(context, mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes));
mStateManager->bindVertexArray(mVAO, 0);
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
for (GLint i = 0; i < maxAttributes; i++)
{
ANGLE_GL_TRY(context, mFunctions->enableVertexAttribArray(i));
ANGLE_GL_TRY(context,
mFunctions->vertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
}
// Enable all attributes with the same buffer so that it doesn't matter what location the
// texcoord attribute is assigned
GLint maxAttributes = 0;
ANGLE_GL_TRY(context, mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes));
for (GLint i = 0; i < maxAttributes; i++)
{
ANGLE_GL_TRY(context, mFunctions->enableVertexAttribArray(i));
ANGLE_GL_TRY(context,
mFunctions->vertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
}
constexpr GLenum potentialSRGBMipmapGenerationFormats[] = {
......@@ -1178,6 +1171,7 @@ angle::Result BlitGL::initializeResources(const gl::Context *context)
}
ASSERT(mSRGBMipmapGenerationFormat.internalFormat != GL_NONE);
mResourcesInitialized = true;
return angle::Result::Continue;
}
......
......@@ -189,6 +189,8 @@ class BlitGL : angle::NonCopyable
GLenum destComponentType,
BlitProgram **program);
bool mResourcesInitialized = false;
// SourceType, SourceComponentType, DestComponentType
using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
std::map<BlitProgramType, BlitProgram> mBlitPrograms;
......
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