i965: Add a driver hook for binding renderbuffers to textures.
authorEric Anholt <eric@anholt.net>
Tue, 4 Feb 2014 20:51:11 +0000 (12:51 -0800)
committerEric Anholt <eric@anholt.net>
Thu, 13 Feb 2014 00:17:11 +0000 (16:17 -0800)
This will let us use meta's acceleration from renderbuffers without having
to do a CopyTexImage first.

This is like what we do for TFP, but just taking an existing renderbuffer
and binding it to a texture with whatever its format was.  The
implementation won't work for stencil renderbuffers, and it only does
non-texture renderbuffers (but then, if you're using a texture
renderbuffer, you can just pull the texture object/level/slice out of the
renderbuffer, anyway).

v2: Don't forget to propagate NumSamples to the teximage.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/intel_tex_image.c
src/mesa/main/dd.h

index 02b3ba5a5696e30a2619e45a4826025adf58989e..ee02e6897829ceec05e9d2dd59dfd466708c67b9 100644 (file)
@@ -322,6 +322,41 @@ intelSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
    _mesa_unlock_texture(&brw->ctx, texObj);
 }
 
+static GLboolean
+intel_bind_renderbuffer_tex_image(struct gl_context *ctx,
+                                  struct gl_renderbuffer *rb,
+                                  struct gl_texture_image *image)
+{
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+   struct intel_texture_image *intel_image = intel_texture_image(image);
+   struct gl_texture_object *texobj = image->TexObject;
+   struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
+
+   /* We can only handle RB allocated with AllocRenderbufferStorage, or
+    * window-system renderbuffers.
+    */
+   assert(!rb->TexImage);
+
+   if (!irb->mt)
+      return false;
+
+   _mesa_lock_texture(ctx, texobj);
+   _mesa_init_teximage_fields(ctx, image,
+                             rb->Width, rb->Height, 1,
+                             0, rb->InternalFormat, rb->Format);
+   image->NumSamples = rb->NumSamples;
+
+   intel_miptree_reference(&intel_image->mt, irb->mt);
+
+   /* Immediately validate the image to the object. */
+   intel_miptree_reference(&intel_texobj->mt, intel_image->mt);
+
+   intel_texobj->needs_validate = true;
+   _mesa_unlock_texture(ctx, texobj);
+
+   return true;
+}
+
 void
 intelSetTexBuffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv)
 {
@@ -385,4 +420,5 @@ intelInitTextureImageFuncs(struct dd_function_table *functions)
 {
    functions->TexImage = intelTexImage;
    functions->EGLImageTargetTexture2D = intel_image_target_texture_2d;
+   functions->BindRenderbufferTexImage = intel_bind_renderbuffer_tex_image;
 }
index ac317e39950a262decb5ff6ff5f0b731c702a08e..ccd44948860bab9ff2efb8d72e02d684265c233b 100644 (file)
@@ -399,6 +399,13 @@ struct dd_function_table {
    void (*UnmapRenderbuffer)(struct gl_context *ctx,
                             struct gl_renderbuffer *rb);
 
+   /**
+    * Optional driver entrypoint that binds a non-texture renderbuffer's
+    * contents to a texture image.
+    */
+   GLboolean (*BindRenderbufferTexImage)(struct gl_context *ctx,
+                                         struct gl_renderbuffer *rb,
+                                         struct gl_texture_image *texImage);
    /*@}*/