glamor: Error out on out-of-memory when allocating PBO for FBO access

Packed buffer allocation (which happens at glBufferData time with the
buffer bound) can fail when there is no GL memory left.

Pick up the error when it happens, print a proper error message, do
some cleanup and bail.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
(cherry picked from commit bc2e12239f)
This commit is contained in:
Paul Kocialkowski 2020-02-10 10:20:04 +01:00 committed by Michel Dänzer
parent 428b5ce4da
commit a7b165d994
2 changed files with 18 additions and 0 deletions

View File

@ -88,10 +88,27 @@ glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
gl_usage = GL_STREAM_READ;
glamor_priv->suppress_gl_out_of_memory_logging = true;
glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->pbo);
glBufferData(GL_PIXEL_PACK_BUFFER,
pixmap->devKind * pixmap->drawable.height, NULL,
gl_usage);
glamor_priv->suppress_gl_out_of_memory_logging = false;
if (glGetError() == GL_OUT_OF_MEMORY) {
if (!glamor_priv->logged_any_pbo_allocation_failure) {
LogMessageVerb(X_WARNING, 0, "glamor: Failed to allocate %d "
"bytes PBO due to GL_OUT_OF_MEMORY.\n",
pixmap->devKind * pixmap->drawable.height);
glamor_priv->logged_any_pbo_allocation_failure = true;
}
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glDeleteBuffers(1, &priv->pbo);
priv->pbo = 0;
return FALSE;
}
} else {
pixmap->devPrivate.ptr = xallocarray(pixmap->devKind,
pixmap->drawable.height);

View File

@ -289,6 +289,7 @@ typedef struct glamor_screen_private {
Bool suppress_gl_out_of_memory_logging;
Bool logged_any_fbo_allocation_failure;
Bool logged_any_pbo_allocation_failure;
/* xv */
glamor_program xv_prog;