Re: [Mesa-dev] [PATCH 2/4] st/mesa: implement AllocTextureImageBuffer() driver hook

2011-09-30 Thread Eric Anholt
On Thu, 29 Sep 2011 20:54:42 -0600, Brian Paul bri...@vmware.com wrote:
 On 09/29/2011 08:37 PM, Eric Anholt wrote:
  On Thu, 29 Sep 2011 14:24:46 -0600, Brian Paulbrian.e.p...@gmail.com  
  wrote:
  From: Brian Paulbri...@vmware.com
 
  This hasn't been needed so far since none of the core Mesa code paths
  that call ctx-Driver.AllocTextureImageBuffer() are used with the
  state tracker.  That will change in upcoming patches.
  Note that this function duplicates some code seen in the st_TexImage()
  function.  That can be cleaned up later.
 
  I'll note that I found it useful within our driver to have
  AllocTextureImageBuffer succeed even if there was data that hadn't been
  Free()d.
 
  If in general Alloc just freed existing memory (or reused it if it was
  well-sized already), we wouldn't need to be so careful about
  FreeTextureImageBuffer()ing in mipmap gen or teximage.  Just a thought.
 
 I'd rather leave it as-is for now.  I'll revisit this in the future, 
 no doubt.
 
 BTW, one thing I have in the back of my mind is to someday try to 
 remove the Alloc/FreeTextureImageBuffer() hooks and instead use a 
 (de)allocator system based on complete mipmaps (see 
 GL_EXT_texture_storage).  I have a patch for that extension that I'm 
 sitting on until after the current batch of changes is finished.

I'm very interested!


pgphmxJd9Jf5C.pgp
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/4] st/mesa: implement AllocTextureImageBuffer() driver hook

2011-09-29 Thread Brian Paul
From: Brian Paul bri...@vmware.com

This hasn't been needed so far since none of the core Mesa code paths
that call ctx-Driver.AllocTextureImageBuffer() are used with the
state tracker.  That will change in upcoming patches.
Note that this function duplicates some code seen in the st_TexImage()
function.  That can be cleaned up later.
---
 src/mesa/state_tracker/st_cb_texture.c |   86 
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_texture.c 
b/src/mesa/state_tracker/st_cb_texture.c
index 260df09..a69ed05 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -460,6 +460,91 @@ guess_and_alloc_texture(struct st_context *st,
 
 
 /**
+ * Called via ctx-Driver.AllocTextureImageBuffer().
+ * If the texture object/buffer already has space for the indicated image,
+ * we're done.  Otherwise, allocate memory for the new texture image.
+ * XXX This function and st_TexImage() have some duplicated code.  That
+ * can be cleaned up in the future.
+ */
+static GLboolean
+st_AllocTextureImageBuffer(struct gl_context *ctx,
+   struct gl_texture_image *texImage,
+   gl_format format, GLsizei width,
+   GLsizei height, GLsizei depth)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_texture_image *stImage = st_texture_image(texImage);
+   struct st_texture_object *stObj = st_texture_object(texImage-TexObject);
+   const GLuint level = texImage-Level;
+
+   DBG(%s\n, __FUNCTION__);
+
+   assert(width  0);
+   assert(height  0);
+   assert(depth  0);
+   assert(!texImage-Data);
+   assert(!stImage-pt); /* xxx this might be wrong */
+
+   /* Look if the parent texture object has space for this image */
+   if (stObj-pt 
+   level = stObj-pt-last_level 
+   st_texture_match_image(stObj-pt, texImage)) {
+  /* this image will fit in the existing texture object's memory */
+  pipe_resource_reference(stImage-pt, stObj-pt);
+  return GL_TRUE;
+   }
+
+   /* The parent texture object does not have space for this image */
+
+   pipe_resource_reference(stObj-pt, NULL);
+   pipe_sampler_view_reference(stObj-sampler_view, NULL);
+
+   if (!guess_and_alloc_texture(st, stObj, stImage)) {
+  /* Probably out of memory.
+   * Try flushing any pending rendering, then retry.
+   */
+  st_finish(st);
+  if (!guess_and_alloc_texture(st, stObj, stImage)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, glTexImage);
+ return GL_FALSE;
+  }
+   }
+
+   if (stObj-pt 
+   st_texture_match_image(stObj-pt, texImage)) {
+  /* The image will live in the object's mipmap memory */
+  pipe_resource_reference(stImage-pt, stObj-pt);
+  assert(stImage-pt);
+  return GL_TRUE;
+   }
+   else {
+  /* Create a new, temporary texture/resource/buffer to hold this
+   * one texture image.
+   */
+  enum pipe_format format =
+ st_mesa_format_to_pipe_format(texImage-TexFormat);
+  GLuint bindings = default_bindings(st, format);
+  GLuint ptWidth, ptHeight, ptDepth, ptLayers;
+
+  st_gl_texture_dims_to_pipe_dims(stObj-base.Target,
+  width, height, depth,
+  ptWidth, ptHeight, ptDepth, 
ptLayers);
+
+  stImage-pt = st_texture_create(st,
+  gl_target_to_pipe(stObj-base.Target),
+  format,
+  0, /* lastLevel */
+  ptWidth,
+  ptHeight,
+  ptDepth,
+  ptLayers,
+  bindings);
+  return stImage-pt != NULL;
+   }
+}
+
+
+/**
  * Adjust pixel unpack params and image dimensions to strip off the
  * texture border.
  * Gallium doesn't support texture borders.  They've seldem been used
@@ -1841,6 +1926,7 @@ st_init_texture_functions(struct dd_function_table 
*functions)
functions-NewTextureImage = st_NewTextureImage;
functions-DeleteTextureImage = st_DeleteTextureImage;
functions-DeleteTexture = st_DeleteTextureObject;
+   functions-AllocTextureImageBuffer = st_AllocTextureImageBuffer;
functions-FreeTextureImageBuffer = st_FreeTextureImageBuffer;
functions-MapTextureImage = st_MapTextureImage;
functions-UnmapTextureImage = st_UnmapTextureImage;
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev