glamor: Handle GL_OUT_OF_MEMORY when allocating texture images.

The spec allows general undefined behavior when GL_OOM is thrown.  But
if the driver happens to throw the error at this point, it probably
means the pixmap was just too big, so we should delete that texture
and have this pixmap fall back to software.

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
This commit is contained in:
Eric Anholt 2015-11-05 14:47:42 -08:00
parent 74be466d40
commit de959ec939
3 changed files with 28 additions and 0 deletions

View File

@ -379,6 +379,13 @@ glamor_debug_output_callback(GLenum source,
const void *userParam) const void *userParam)
{ {
ScreenPtr screen = (void *)userParam; ScreenPtr screen = (void *)userParam;
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
if (glamor_priv->suppress_gl_out_of_memory_logging &&
source == GL_DEBUG_SOURCE_API && type == GL_DEBUG_TYPE_ERROR) {
return;
}
LogMessageVerb(X_ERROR, 0, "glamor%d: GL error: %*s\n", LogMessageVerb(X_ERROR, 0, "glamor%d: GL error: %*s\n",
screen->myNum, length, message); screen->myNum, length, message);
} }

View File

@ -347,9 +347,25 @@ _glamor_create_tex(glamor_screen_private *glamor_priv,
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glamor_priv->suppress_gl_out_of_memory_logging = true;
glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0,
format, GL_UNSIGNED_BYTE, NULL); format, GL_UNSIGNED_BYTE, NULL);
glamor_priv->suppress_gl_out_of_memory_logging = false;
} }
if (glGetError() == GL_OUT_OF_MEMORY) {
if (!glamor_priv->logged_any_fbo_allocation_failure) {
LogMessageVerb(X_WARNING, 0, "glamor: Failed to allocate %dx%d "
"FBO due to GL_OUT_OF_MEMORY.\n", w, h);
LogMessageVerb(X_WARNING, 0,
"glamor: Expect reduced performance.\n");
glamor_priv->logged_any_fbo_allocation_failure = true;
}
glDeleteTextures(1, &tex);
return 0;
}
return tex; return tex;
} }
@ -368,6 +384,8 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
return fbo; return fbo;
new_fbo: new_fbo:
tex = _glamor_create_tex(glamor_priv, w, h, format, flag == CREATE_PIXMAP_USAGE_SHARED); tex = _glamor_create_tex(glamor_priv, w, h, format, flag == CREATE_PIXMAP_USAGE_SHARED);
if (!tex)
return NULL;
fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, format, tex, flag); fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, format, tex, flag);
return fbo; return fbo;

View File

@ -293,6 +293,9 @@ typedef struct glamor_screen_private {
ScreenPtr screen; ScreenPtr screen;
int dri3_enabled; int dri3_enabled;
Bool suppress_gl_out_of_memory_logging;
Bool logged_any_fbo_allocation_failure;
/* xv */ /* xv */
GLint xv_prog; GLint xv_prog;