[Mesa-dev] [PATCH 2/3] llvmpipe: integrate memory allocation into llvmpipe_texture_layout

sroland at vmware.com sroland at vmware.com
Thu Jul 31 11:26:07 PDT 2014


From: Roland Scheidegger <sroland at vmware.com>

Seems pointless to just duplicate some of the calculations (the calculation
of actual memory used compared to what was predicted in llvmpipe_texture_layout
actually could have differed slightly in some cases due to different alignment
rules used though this should have been of no consequence).
---
 src/gallium/drivers/llvmpipe/lp_texture.c | 58 +++++++++----------------------
 1 file changed, 17 insertions(+), 41 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c
index 40e5815..3c87b28 100644
--- a/src/gallium/drivers/llvmpipe/lp_texture.c
+++ b/src/gallium/drivers/llvmpipe/lp_texture.c
@@ -59,16 +59,15 @@ static struct llvmpipe_resource resource_list;
 #endif
 static unsigned id_counter = 0;
 
-static void
-alloc_image_data(struct llvmpipe_resource *lpr);
 
 /**
  * Conventional allocation path for non-display textures:
- * Just compute row strides here.  Storage is allocated on demand later.
+ * Compute strides and allocate data (unless asked not to).
  */
 static boolean
 llvmpipe_texture_layout(struct llvmpipe_screen *screen,
-                        struct llvmpipe_resource *lpr)
+                        struct llvmpipe_resource *lpr,
+                        boolean allocate)
 {
    struct pipe_resource *pt = &lpr->base;
    unsigned level;
@@ -149,6 +148,8 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen,
          goto fail;
       }
 
+      lpr->mip_offsets[level] = total_size;
+
       total_size += (uint64_t) lpr->num_slices_faces[level]
                   * (uint64_t) lpr->img_stride[level];
       if (total_size > LP_MAX_TEXTURE_SIZE) {
@@ -161,6 +162,16 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen,
       depth = u_minify(depth, 1);
    }
 
+   if (allocate) {
+      lpr->tex_data = align_malloc(total_size, util_cpu_caps.cacheline);
+      if (!lpr->tex_data) {
+         return FALSE;
+      }
+      else {
+         memset(lpr->tex_data, 0, total_size);
+      }
+   }
+
    return TRUE;
 
 fail:
@@ -179,7 +190,7 @@ llvmpipe_can_create_resource(struct pipe_screen *screen,
    struct llvmpipe_resource lpr;
    memset(&lpr, 0, sizeof(lpr));
    lpr.base = *res;
-   return llvmpipe_texture_layout(llvmpipe_screen(screen), &lpr);
+   return llvmpipe_texture_layout(llvmpipe_screen(screen), &lpr, false);
 }
 
 
@@ -247,13 +258,8 @@ llvmpipe_resource_create(struct pipe_screen *_screen,
       }
       else {
          /* texture map */
-         if (!llvmpipe_texture_layout(screen, lpr))
-            goto fail;
-
-         alloc_image_data(lpr);
-         if (!lpr->tex_data) {
+         if (!llvmpipe_texture_layout(screen, lpr, true))
             goto fail;
-         }
       }
    }
    else {
@@ -747,36 +753,6 @@ llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
 
 
 /**
- * Allocate storage for a linear image
- * (all cube faces and all 3D slices, all levels).
- */
-static void
-alloc_image_data(struct llvmpipe_resource *lpr)
-{
-   uint alignment = MAX2(64, util_cpu_caps.cacheline);
-   uint level;
-   uint offset = 0;
-
-   assert(!lpr->dt);
-
-   /* not a display target - allocate regular memory */
-   /*
-    * Offset calculation for start of a specific mip/layer is always
-    * offset = lpr->linear_mip_offsets[level] + lpr->img_stride[level] * layer
-    */
-   for (level = 0; level <= lpr->base.last_level; level++) {
-      uint buffer_size = tex_image_size(lpr, level);
-      lpr->mip_offsets[level] = offset;
-      offset += align(buffer_size, alignment);
-   }
-   lpr->tex_data = align_malloc(offset, alignment);
-   if (lpr->tex_data) {
-      memset(lpr->tex_data, 0, offset);
-   }
-}
-
-
-/**
  * Return size of resource in bytes
  */
 unsigned
-- 
1.9.1


More information about the mesa-dev mailing list