On Thu, Jul 30, 2009 at 07:09:06PM +0800, Chia-I Wu wrote:
> Since st_set_teximage changes a texture object, I want to mark the
> texture object incomplete, and mark the core mesa context with
> _NEW_TEXTURE.  I grepped the st source code, and no other functions
> change the state of the core mesa context.  Am I allowed to modify the
> state of core mesa context directly or is there a better way?
For this issue, I want to add

void
_mesa_notifyBindTexImage(GLcontext *ctx, struct gl_texture_object *texObj);

to mesa core.  It is called by driver and st to notify mesa that some
pixmap/pbuffer is bound to or released from the texture object.  Mesa
currently only marks the texture object incomplete and sets
_NEW_TEXTURE.

> My understanding to these paragraphs is that, a texture object may
> allocate private buffers or use the backing buffers of the bound
> pbuffers for the texels.  But they can not be mixed!  A BindTexImage
> causes the private buffers to be freed, and a TexImage* causes the bound
> pbuffers to be released.  And both functions should mark _NEW_TEXTURE
> and require the textre object in question to be tested for completeness.
> Is my understanding correct?
> If that's correct, I should make a texture object incomplete when a
> bound pixmap/pbuffer is released.  Currently, I set the texture image to
> have zero width and height so that it is tested incomplete when
> validated.  Is this the suggested way?
For these issues, I want to add _mesa_clear_texture_image and
_mesa_clear_texture_object.  The former "clears" a texture image by
freeing the texel buffer and reinitializes the texture image.  The
latter is called to "clear" every image of a texture object.

With these functions, state tracker can clear the texture object before
binding a pipe surface to it.  And it can notify mesa about the change.

The winsys api wants to create contexts/surfaces, make them current, and
swap buffers.  These are the basic functions and mesa has api to support
them.  What's lacking in mesa is a way to let winsys api bind a surface
to a texture, and the functions I add try to fulfill the need.  This is
the motivation.

The modifications can be found in the attachments.  I am still new to
mesa and I would like to hear some feedbacks before sending them as
patches.  Please let me know what you think, or let me know that I might
be doing something stupid :)

-- 
Regards,
olv
>From fb60b4ab356b888d6b7d9fdc5de89d3d39f64f83 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Mon, 3 Aug 2009 16:38:26 +0800
Subject: [PATCH 1/2] mesa: bind image notificaition

---
 src/mesa/main/teximage.c |   17 +++++++++++++++++
 src/mesa/main/teximage.h |    4 ++++
 src/mesa/main/texobj.c   |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/mesa/main/texobj.h   |    5 +++++
 4 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 825f5e2..5a1ea5a 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1216,6 +1216,23 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
 
 
 /**
+ * Free and clear fields of the gl_texture_image struct.
+ *
+ * \param ctx GL context.
+ * \param img texture image structure to be cleared.
+ *
+ * After the call, \p img will have no data associated with it.  Its fields
+ * are cleared so that its parent object will test incomplete.
+ */
+void
+_mesa_clear_texture_image(GLcontext *ctx, struct gl_texture_image *texImage)
+{
+   ctx->Driver.FreeTexImageData(ctx, texImage);
+   clear_teximage_fields(texImage);
+}
+
+
+/**
  * This is the fallback for Driver.TestProxyTexImage().  Test the texture
  * level, width, height and depth against the ctx->Const limits for textures.
  *
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index eb60a1f..b0d7c1c 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -73,6 +73,10 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
 
 
 extern void
+_mesa_clear_texture_image(GLcontext *ctx, struct gl_texture_image *texImage);
+
+
+extern void
 _mesa_set_tex_image(struct gl_texture_object *tObj,
                     GLenum target, GLint level,
                     struct gl_texture_image *texImage);
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 2082f94..8652d70 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -261,6 +261,32 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
 
 
 /**
+ * Clear all texture images of the given texture object.
+ *
+ * \param ctx GL context.
+ * \param t texture object.
+ *
+ * \sa _mesa_clear_texture_image().
+ */
+void
+_mesa_clear_texture_object(GLcontext *ctx, struct gl_texture_object *texObj)
+{
+   GLuint i, j;
+
+   if (texObj->Target == 0)
+      return;
+
+   for (i = 0; i < MAX_FACES; i++) {
+      for (j = 0; j < MAX_TEXTURE_LEVELS; j++) {
+         struct gl_texture_image *texImage = texObj->Image[i][j];
+         if (texImage)
+            _mesa_clear_texture_image(ctx, texImage);
+      }
+   }
+}
+
+
+/**
  * Check if the given texture object is valid by examining its Target field.
  * For debugging only.
  */
@@ -719,6 +745,23 @@ _mesa_get_fallback_texture(GLcontext *ctx)
 /*...@}*/
 
 
+/**
+ * Bind texture image notification callback.
+ *
+ * \param ctx GL context.
+ * \param t texture object.
+ *
+ * Called by window system after binding a renderbuffer to
+ * a texture object.
+ */
+void
+_mesa_notifyBindTexImage(GLcontext *ctx, struct gl_texture_object *texObj)
+{
+   texObj->_Complete = GL_FALSE;
+   ctx->NewState |= _NEW_TEXTURE;
+}
+
+
 /***********************************************************************/
 /** \name API functions */
 /*...@{*/
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 2599c08..d2274e6 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -58,6 +58,9 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
                            const struct gl_texture_object *src );
 
 extern void
+_mesa_clear_texture_object(GLcontext *ctx, struct gl_texture_object *obj);
+
+extern void
 _mesa_reference_texobj(struct gl_texture_object **ptr,
                        struct gl_texture_object *tex);
 
@@ -76,6 +79,8 @@ _mesa_lock_context_textures( GLcontext *ctx );
 
 /*...@}*/
 
+extern void
+_mesa_notifyBindTexImage(GLcontext *ctx, struct gl_texture_object *texObj);
 
 /**
  * \name API functions
-- 
1.6.2.4

>From a2b3cf08bd046aa930ae7f3fbdd8b5143b7b08c5 Mon Sep 17 00:00:00 2001
From: Chia-I Wu <[email protected]>
Date: Thu, 23 Jul 2009 18:57:49 +0800
Subject: [PATCH 2/2] st: st_set_teximage.

---
 src/mesa/state_tracker/st_cb_texture.c |    5 ++
 src/mesa/state_tracker/st_public.h     |    5 ++-
 src/mesa/state_tracker/st_texture.c    |   82 ++++++++++++++++++++++++++------
 src/mesa/state_tracker/st_texture.h    |    1 +
 4 files changed, 77 insertions(+), 16 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index e8d7f70..9ec04f4 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -523,6 +523,11 @@ st_TexImage(GLcontext * ctx,
    DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
 
+   if (stObj->surface_based) {
+      _mesa_clear_texture_object(ctx, texObj);
+      stObj->surface_based = GL_FALSE;
+   }
+
    /* gallium does not support texture borders, strip it off */
    if (border) {
       strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB);
diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h
index 04d3a3d..fe5893d 100644
--- a/src/mesa/state_tracker/st_public.h
+++ b/src/mesa/state_tracker/st_public.h
@@ -107,7 +107,10 @@ void st_swapbuffers(struct st_framebuffer *stfb,
                     struct pipe_surface **front_left,
                     struct pipe_surface **front_right);
 
-int st_set_teximage(struct pipe_texture *pt, int target);
+/** Bind a pipe surface for use as a texture image */
+int st_set_teximage(struct pipe_surface *ps, int target, int level,
+                    enum pipe_format format);
+int st_unset_teximage(struct pipe_surface *ps, int target, int level);
 
 /** Redirect rendering into stfb's surface to a texture image */
 int st_bind_teximage(struct st_framebuffer *stfb, uint surfIndex,
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 10faa63..9e3c062 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -32,6 +32,7 @@
 #include "st_cb_fbo.h"
 #include "st_inlines.h"
 #include "main/enums.h"
+#include "main/texobj.h"
 #include "main/teximage.h"
 #include "main/texstore.h"
 
@@ -353,25 +354,72 @@ st_texture_image_copy(struct pipe_context *pipe,
    }
 }
 
-/** Bind a pipe surface for use as a texture image */
 int
-st_set_teximage(struct pipe_texture *pt, int target)
+st_set_teximage(struct pipe_surface *ps, int target, int level,
+                enum pipe_format format)
 {
    GET_CURRENT_CONTEXT(ctx);
    const GLuint unit = ctx->Texture.CurrentUnit;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
    struct gl_texture_object *texObj;
    struct gl_texture_image *texImage;
+   struct st_texture_object *stObj;
    struct st_texture_image *stImage;
-   int internalFormat;
+   GLenum internalFormat;
 
-   switch (pt->format) {
-   case PIPE_FORMAT_A8R8G8B8_UNORM:
-      internalFormat = GL_RGBA8;
+   switch (target) {
+   case ST_TEXTURE_2D:
+      target = GL_TEXTURE_2D;
+      break;
+   case ST_TEXTURE_RECT:
+      target = GL_TEXTURE_RECTANGLE_ARB;
       break;
    default:
       return 0;
-   };
+   }
+
+   /* map pipe format to base format */
+   if (pf_get_component_bits(format, PIPE_FORMAT_COMP_A) > 0)
+      internalFormat = GL_RGBA;
+   else
+      internalFormat = GL_RGB;
+
+   texObj = _mesa_select_tex_object(ctx, texUnit, target);
+   _mesa_lock_texture(ctx, texObj);
+
+   stObj = st_texture_object(texObj);
+   if (!stObj->surface_based) {
+      _mesa_clear_texture_object(ctx, texObj);
+      stObj->surface_based = GL_TRUE;
+   }
+
+   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+   stImage = st_texture_image(texImage);
+
+   _mesa_init_teximage_fields(ctx, target, texImage,
+                              ps->width, ps->height, 1, 0, internalFormat);
+   texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
+                                                GL_RGBA, GL_UNSIGNED_BYTE);
+   _mesa_set_fetch_functions(texImage, 2);
+   pipe_texture_reference(&stImage->pt, ps->texture);
+
+   _mesa_notifyBindTexImage(ctx, texObj);
+   _mesa_unlock_texture(ctx, texObj);
+   
+   return 1;
+}
+
+/** Unbind a pipe surface for use as a texture image */
+int
+st_unset_teximage(struct pipe_surface *ps, int target, int level)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   const GLuint unit = ctx->Texture.CurrentUnit;
+   struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
+   struct gl_texture_object *texObj;
+   struct gl_texture_image *texImage;
+   struct st_texture_object *stObj;
+   struct st_texture_image *stImage;
 
    switch (target) {
    case ST_TEXTURE_2D:
@@ -385,18 +433,22 @@ st_set_teximage(struct pipe_texture *pt, int target)
    }
 
    texObj = _mesa_select_tex_object(ctx, texUnit, target);
-   texImage = _mesa_get_tex_image(ctx, texObj, target, 0);
+
+   _mesa_lock_texture(ctx, texObj);
+
+   texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+   stObj = st_texture_object(texObj);
    stImage = st_texture_image(texImage);
-   
-   _mesa_init_teximage_fields(ctx, GL_TEXTURE_2D, texImage, pt->width[0],
-                              pt->height[0], 1, 0, internalFormat);
 
-   texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat, GL_RGBA,
-                                                GL_UNSIGNED_BYTE);
-   _mesa_set_fetch_functions(texImage, 2);
+   if (stImage->pt == ps->texture) {
+      pipe_texture_reference(&stImage->pt, NULL);
+      _mesa_clear_texture_image(ctx, texImage);
 
-   pipe_texture_reference(&stImage->pt, pt);
+      _mesa_notifyBindTexImage(ctx, texObj);
+   }
 
+   _mesa_unlock_texture(ctx, texObj);
+   
    return 1;
 }
 
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index b9d447c..bc68ebe 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -68,6 +68,7 @@ struct st_texture_object
     */
    struct pipe_texture *pt;
 
+   GLboolean surface_based;
    GLboolean teximage_realloc;
 };
 
-- 
1.6.2.4

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to