From b8a2b4f688e2bc79459e3c344f5a9c400115d4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tapani=20P=C3=A4lli?= Date: Mon, 3 Feb 2014 14:11:17 +0200 Subject: [PATCH] i965: fix crash with glXMakeContextCurrent(.., None, None, ...) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Piglit test glx-create-context-current-no-framebuffer started to crash after commit 11baad35088dfd4bdabc1710df650dbfb413e7a3. This patch adds some checking to Intel driver so that we survive even if we do not have attachments set to the framebuffer. This makes Piglit test to pass. Signed-off-by: Tapani Pälli --- src/mesa/drivers/dri/i965/brw_context.c | 27 +++++++++++++++++---------- src/mesa/drivers/dri/i965/intel_fbo.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index d9d1ae5..400b255 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -1009,10 +1009,10 @@ intel_process_dri2_buffer(struct brw_context *brw, struct intel_renderbuffer *rb, const char *buffer_name); -static void +static GLboolean intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable); -static void +static GLboolean intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable) { struct gl_framebuffer *fb = drawable->driverPrivate; @@ -1032,7 +1032,7 @@ intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable) intel_query_dri2_buffers(brw, drawable, &buffers, &count); if (buffers == NULL) - return; + return false; for (i = 0; i < count; i++) { switch (buffers[i].attachment) { @@ -1060,12 +1060,12 @@ intel_update_dri2_buffers(struct brw_context *brw, __DRIdrawable *drawable) fprintf(stderr, "unhandled buffer attach event, attachment type %d\n", buffers[i].attachment); - return; + return false; } intel_process_dri2_buffer(brw, drawable, &buffers[i], rb, region_name); } - + return true; } void @@ -1073,6 +1073,7 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable) { struct brw_context *brw = context->driverPrivate; __DRIscreen *screen = brw->intelScreen->driScrnPriv; + bool buffers = false; /* Set this up front, so that in case our buffers get invalidated * while we're getting new buffers, we don't clobber the stamp and @@ -1083,11 +1084,12 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable) fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable); if (screen->image.loader) - intel_update_image_buffers(brw, drawable); + buffers = intel_update_image_buffers(brw, drawable); else - intel_update_dri2_buffers(brw, drawable); + buffers = intel_update_dri2_buffers(brw, drawable); - driUpdateFramebufferSize(&brw->ctx, drawable); + if (buffers) + driUpdateFramebufferSize(&brw->ctx, drawable); } /** @@ -1212,6 +1214,10 @@ intel_query_dri2_buffers(struct brw_context *brw, assert(i <= ARRAY_SIZE(attachments)); + /* no attachments */ + if (i == 0) + return; + *buffers = screen->dri2.loader->getBuffersWithFormat(drawable, &drawable->w, &drawable->h, @@ -1346,7 +1352,7 @@ intel_update_image_buffer(struct brw_context *intel, region); } -static void +static GLboolean intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable) { struct gl_framebuffer *fb = drawable->driverPrivate; @@ -1365,7 +1371,7 @@ intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable) else if (front_rb) format = intel_rb_format(front_rb); else - return; + return false; if ((brw->is_front_buffer_rendering || brw->is_front_buffer_reading || !back_rb) && front_rb) buffer_mask |= __DRI_IMAGE_BUFFER_FRONT; @@ -1398,4 +1404,5 @@ intel_update_image_buffers(struct brw_context *brw, __DRIdrawable *drawable) images.back, __DRI_IMAGE_BUFFER_BACK); } + return true; } diff --git a/src/mesa/drivers/dri/i965/intel_fbo.h b/src/mesa/drivers/dri/i965/intel_fbo.h index 45e2cd8..75c01b5 100644 --- a/src/mesa/drivers/dri/i965/intel_fbo.h +++ b/src/mesa/drivers/dri/i965/intel_fbo.h @@ -118,7 +118,7 @@ intel_get_renderbuffer(struct gl_framebuffer *fb, gl_buffer_index attIndex) assert((unsigned)attIndex < ARRAY_SIZE(fb->Attachment)); rb = fb->Attachment[attIndex].Renderbuffer; - if (!rb) + if (!rb || fb->Attachment[attIndex].Type == GL_NONE) return NULL; return intel_renderbuffer(rb); -- 1.8.3.1