[Mesa-dev] [PATCH 1/2] mesa: Generalize TexStorage allocator between swrast and intel.

Eric Anholt eric at anholt.net
Fri Apr 19 11:29:36 PDT 2013


This should be reusable for other non-gallium drivers, so we can make the
extension always be available.
---
 src/mesa/drivers/common/driverfuncs.c  |    3 ++-
 src/mesa/drivers/dri/intel/intel_tex.c |   26 --------------------------
 src/mesa/main/texstorage.c             |   21 +++++++++++++++++++++
 src/mesa/main/texstorage.h             |    5 +++++
 src/mesa/swrast/s_texture.c            |   27 ---------------------------
 src/mesa/swrast/swrast.h               |    8 --------
 6 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index a98dfc6..9112eb0 100644
--- a/src/mesa/drivers/common/driverfuncs.c
+++ b/src/mesa/drivers/common/driverfuncs.c
@@ -40,6 +40,7 @@
 #include "main/texgetimage.h"
 #include "main/teximage.h"
 #include "main/texobj.h"
+#include "main/texstorage.h"
 #include "main/texstore.h"
 #include "main/bufferobj.h"
 #include "main/fbobject.h"
@@ -209,7 +210,7 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    driver->EndCallList = NULL;
 
    /* GL_ARB_texture_storage */
-   driver->AllocTextureStorage = _swrast_AllocTextureStorage;
+   driver->AllocTextureStorage = _mesa_alloc_texture_storage;
 
    /* GL_ARB_texture_multisample */
    driver->GetSamplePosition = NULL;
diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
index 9bba989..ee8db71 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.c
+++ b/src/mesa/drivers/dri/intel/intel_tex.c
@@ -127,31 +127,6 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
    return true;
 }
 
-/**
- * Called via ctx->Driver.AllocTextureStorage()
- * Just have to allocate memory for the texture images.
- */
-static GLboolean
-intel_alloc_texture_storage(struct gl_context *ctx,
-                            struct gl_texture_object *texObj,
-                            GLsizei levels, GLsizei width,
-                            GLsizei height, GLsizei depth)
-{
-   const int numFaces = _mesa_num_tex_faces(texObj->Target);
-   int face;
-   int level;
-
-   for (face = 0; face < numFaces; face++) {
-      for (level = 0; level < levels; level++) {
-         struct gl_texture_image *const texImage = texObj->Image[face][level];
-         if (!intel_alloc_texture_image_buffer(ctx, texImage))
-            return false;
-      }
-   }
-
-   return true;
-}
-
 static void
 intel_free_texture_image_buffer(struct gl_context * ctx,
 				struct gl_texture_image *texImage)
@@ -231,7 +206,6 @@ intelInitTextureFuncs(struct dd_function_table *functions)
    functions->DeleteTexture = intelDeleteTextureObject;
    functions->AllocTextureImageBuffer = intel_alloc_texture_image_buffer;
    functions->FreeTextureImageBuffer = intel_free_texture_image_buffer;
-   functions->AllocTextureStorage = intel_alloc_texture_storage;
    functions->MapTextureImage = intel_map_texture_image;
    functions->UnmapTextureImage = intel_unmap_texture_image;
 }
diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c
index 330d676..0a69442 100644
--- a/src/mesa/main/texstorage.c
+++ b/src/mesa/main/texstorage.c
@@ -244,6 +244,27 @@ _mesa_is_legal_tex_storage_format(struct gl_context *ctx, GLenum internalformat)
    }
 }
 
+GLboolean
+_mesa_alloc_texture_storage(struct gl_context *ctx,
+                            struct gl_texture_object *texObj,
+                            GLsizei levels, GLsizei width,
+                            GLsizei height, GLsizei depth)
+{
+   const int numFaces = _mesa_num_tex_faces(texObj->Target);
+   int face;
+   int level;
+
+   for (face = 0; face < numFaces; face++) {
+      for (level = 0; level < levels; level++) {
+         struct gl_texture_image *const texImage = texObj->Image[face][level];
+         if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage))
+            return GL_FALSE;
+      }
+   }
+
+   return GL_TRUE;
+}
+
 
 /**
  * Do error checking for calls to glTexStorage1/2/3D().
diff --git a/src/mesa/main/texstorage.h b/src/mesa/main/texstorage.h
index 9f172e1..0240ca3 100644
--- a/src/mesa/main/texstorage.h
+++ b/src/mesa/main/texstorage.h
@@ -60,5 +60,10 @@ _mesa_TextureStorage3DEXT(GLuint texture, GLenum target, GLsizei levels,
 extern GLboolean
 _mesa_is_legal_tex_storage_format(struct gl_context *ctx, GLenum internalformat);
 
+extern GLboolean
+_mesa_alloc_texture_storage(struct gl_context *ctx,
+                            struct gl_texture_object *texObj,
+                            GLsizei levels, GLsizei width,
+                            GLsizei height, GLsizei depth);
 
 #endif /* TEXSTORAGE_H */
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 8ae3d5b..51048be 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -322,30 +322,3 @@ _swrast_unmap_textures(struct gl_context *ctx)
       enabledUnits &= ~(1 << unit);
    }
 }
-
-
-/**
- * Called via ctx->Driver.AllocTextureStorage()
- * Just have to allocate memory for the texture images.
- */
-GLboolean
-_swrast_AllocTextureStorage(struct gl_context *ctx,
-                            struct gl_texture_object *texObj,
-                            GLsizei levels, GLsizei width,
-                            GLsizei height, GLsizei depth)
-{
-   const GLint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLint face, level;
-
-   for (face = 0; face < numFaces; face++) {
-      for (level = 0; level < levels; level++) {
-         struct gl_texture_image *texImage = texObj->Image[face][level];
-         if (!_swrast_alloc_texture_image_buffer(ctx, texImage)) {
-            return GL_FALSE;
-         }
-      }
-   }
-
-   return GL_TRUE;
-}
-
diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h
index 82555ae..0f74bb9 100644
--- a/src/mesa/swrast/swrast.h
+++ b/src/mesa/swrast/swrast.h
@@ -272,14 +272,6 @@ _swrast_finish_render_texture(struct gl_context *ctx,
                               struct gl_renderbuffer_attachment *att);
 
 
-
-extern GLboolean
-_swrast_AllocTextureStorage(struct gl_context *ctx,
-                            struct gl_texture_object *texObj,
-                            GLsizei levels, GLsizei width,
-                            GLsizei height, GLsizei depth);
-
-
 /**
  * The driver interface for the software rasterizer.
  * XXX this may go away.
-- 
1.7.10.4



More information about the mesa-dev mailing list