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, ...@@ -1109,52 +1109,45 @@ angle::Result BlitGL::generateSRGBMipmap(const gl::Context *context,
angle::Result BlitGL::initializeResources(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) return angle::Result::Continue;
{
ANGLE_GL_TRY(context, mFunctions->genTextures(1, &mScratchTextures[i]));
}
} }
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->genFramebuffers(1, &mScratchFBO));
{
ANGLE_GL_TRY(context, mFunctions->genBuffers(1, &mVertexBuffer));
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
// Use a single, large triangle, to avoid arithmetic precision issues where fragments ANGLE_GL_TRY(context, mFunctions->genBuffers(1, &mVertexBuffer));
// with the same Y coordinate don't get exactly the same interpolated texcoord Y. mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
float vertexData[] = {
-0.5f, 0.0f, 1.5f, 0.0f, 0.5f, 2.0f,
};
ANGLE_GL_TRY(context, mFunctions->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData, // Use a single, large triangle, to avoid arithmetic precision issues where fragments
GL_STATIC_DRAW)); // 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->bufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, vertexData,
{ GL_STATIC_DRAW));
ANGLE_GL_TRY(context, mFunctions->genVertexArrays(1, &mVAO));
mStateManager->bindVertexArray(mVAO, 0); ANGLE_GL_TRY(context, mFunctions->genVertexArrays(1, &mVAO));
mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
// Enable all attributes with the same buffer so that it doesn't matter what location the mStateManager->bindVertexArray(mVAO, 0);
// texcoord attribute is assigned mStateManager->bindBuffer(gl::BufferBinding::Array, mVertexBuffer);
GLint maxAttributes = 0;
ANGLE_GL_TRY(context, mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes));
for (GLint i = 0; i < maxAttributes; i++) // Enable all attributes with the same buffer so that it doesn't matter what location the
{ // texcoord attribute is assigned
ANGLE_GL_TRY(context, mFunctions->enableVertexAttribArray(i)); GLint maxAttributes = 0;
ANGLE_GL_TRY(context, ANGLE_GL_TRY(context, mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxAttributes));
mFunctions->vertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
} 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[] = { constexpr GLenum potentialSRGBMipmapGenerationFormats[] = {
...@@ -1178,6 +1171,7 @@ angle::Result BlitGL::initializeResources(const gl::Context *context) ...@@ -1178,6 +1171,7 @@ angle::Result BlitGL::initializeResources(const gl::Context *context)
} }
ASSERT(mSRGBMipmapGenerationFormat.internalFormat != GL_NONE); ASSERT(mSRGBMipmapGenerationFormat.internalFormat != GL_NONE);
mResourcesInitialized = true;
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -189,6 +189,8 @@ class BlitGL : angle::NonCopyable ...@@ -189,6 +189,8 @@ class BlitGL : angle::NonCopyable
GLenum destComponentType, GLenum destComponentType,
BlitProgram **program); BlitProgram **program);
bool mResourcesInitialized = false;
// SourceType, SourceComponentType, DestComponentType // SourceType, SourceComponentType, DestComponentType
using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>; using BlitProgramType = std::tuple<gl::TextureType, GLenum, GLenum>;
std::map<BlitProgramType, BlitProgram> mBlitPrograms; 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