[Mesa-dev] [PATCH 1/9] mesa: rework Driver.CopyImageSubData() and related code

Brian Paul brianp at vmware.com
Thu Aug 27 07:39:59 PDT 2015


On 08/27/2015 02:28 AM, Pohjolainen, Topi wrote:
> On Mon, Aug 24, 2015 at 05:04:22PM -0600, Brian Paul wrote:
>> Previously, core Mesa's _mesa_CopyImageSubData() created temporary textures
>> to wrap renderbuffer sources/destinations.  This caused a bit of a mess in
>> the Mesa/gallium state tracker because we had to basically undo that
>> wrapping.
>>
>> Instead, change ctx->Driver.CopyImageSubData() to take both gl_renderbuffer
>> and gl_texture_image src/dst pointers (one being null, the other non-null)
>> so the driver can handle renderbuffer vs. texture as needed.
>>
>> For the i965 driver, we basically moved the code that wrapped textures
>> around renderbuffers from copyimage.c down into the driver.  So that
>> approach is still used there as before.
>>
>> The old code in copyimage.c also made some questionable calls to
>> _mesa_BindTexture(), etc. which weren't undone at the end.
>> ---
>>   src/mesa/drivers/dri/i965/intel_copy_image.c |  83 +++++++-
>>   src/mesa/main/copyimage.c                    | 301 +++++++++++++++------------
>>   src/mesa/main/dd.h                           |  15 +-
>>   3 files changed, 259 insertions(+), 140 deletions(-)
>>
>> diff --git a/src/mesa/drivers/dri/i965/intel_copy_image.c b/src/mesa/drivers/dri/i965/intel_copy_image.c
>> index 3706704..8f765b4 100644
>> --- a/src/mesa/drivers/dri/i965/intel_copy_image.c
>> +++ b/src/mesa/drivers/dri/i965/intel_copy_image.c
>> @@ -29,6 +29,7 @@
>>   #include "intel_blit.h"
>>   #include "intel_mipmap_tree.h"
>>   #include "main/formats.h"
>> +#include "main/teximage.h"
>>   #include "drivers/common/meta.h"
>>
>>   static bool
>> @@ -213,29 +214,90 @@ copy_image_with_memcpy(struct brw_context *brw,
>>      }
>>   }
>>
>> +
>> +/**
>> + * Create a texture image that wraps a renderbuffer.
>> + */
>> +static struct intel_texture_image *
>> +wrap_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
>> +{
>> +   GLenum texTarget;
>> +   struct gl_texture_object *texObj;
>> +   struct gl_texture_image *texImage;
>> +
>> +   if (rb->NumSamples > 1)
>> +      texTarget = GL_TEXTURE_2D_MULTISAMPLE;
>> +   else
>> +      texTarget = GL_TEXTURE_2D;
>> +
>> +   /* Texture ID is not significant since it never goes into the hash table */
>> +   texObj = ctx->Driver.NewTextureObject(ctx, 0, texTarget);
>> +   assert(texObj);
>> +   if (!texObj)
>> +      return NULL;
>> +
>> +   texImage = _mesa_get_tex_image(ctx, texObj, texTarget, 0);
>> +   assert(texImage);
>> +   if (!texImage)
>> +      return NULL;
>> +
>> +   if (!ctx->Driver.BindRenderbufferTexImage(ctx, rb, texImage)) {
>> +      _mesa_problem(ctx, "Failed to create texture from renderbuffer");
>> +      return NULL;
>> +   }
>> +
>> +   if (ctx->Driver.FinishRenderTexture && !rb->NeedsFinishRenderTexture) {
>> +      rb->NeedsFinishRenderTexture = true;
>> +      ctx->Driver.FinishRenderTexture(ctx, rb);
>> +   }
>> +
>> +   return intel_texture_image(texImage);
>> +}
>> +
>> +
>>   static void
>>   intel_copy_image_sub_data(struct gl_context *ctx,
>>                             struct gl_texture_image *src_image,
>> +                          struct gl_renderbuffer *src_renderbuffer,
>>                             int src_x, int src_y, int src_z,
>>                             struct gl_texture_image *dst_image,
>> +                          struct gl_renderbuffer *dst_renderbuffer,
>>                             int dst_x, int dst_y, int dst_z,
>>                             int src_width, int src_height)
>>   {
>>      struct brw_context *brw = brw_context(ctx);
>> -   struct intel_texture_image *intel_src_image = intel_texture_image(src_image);
>> -   struct intel_texture_image *intel_dst_image = intel_texture_image(dst_image);
>> +   struct intel_texture_image *intel_src_image;
>> +   struct intel_texture_image *intel_dst_image;
>> +
>> +   if (src_renderbuffer) {
>
> If we don't take this branch, then 'intel_src_image' is left undefined, right?

Oops, yes.  I'll fix that.

I'll post a v2 of the series soon with assorted fixes and changes.

I can't test the Intel changes so it would be nice if someone could 
apply/test this patch on Intel HW.

-Brian




More information about the mesa-dev mailing list