softpipe: implement the new can_create_resource() function
authorBrian Paul <brianp@vmware.com>
Mon, 17 Sep 2012 01:44:07 +0000 (19:44 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 18 Sep 2012 01:49:27 +0000 (19:49 -0600)
And define a SP_MAX_TEXTURE_SIZE value as we do in llvmpipe.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/drivers/softpipe/sp_limits.h
src/gallium/drivers/softpipe/sp_texture.c

index 0df683bc4cb7a51dc3b15c6aadb4d78c306e655c..9dd2be1a9c512ff8af889be1d01e0e67037251bb 100644 (file)
@@ -29,7 +29,7 @@
 #define SP_LIMITS_H
 
 
-
+#define SP_MAX_TEXTURE_SIZE (1 * 1024 * 1024 * 1024ULL)  /* 1GB for now */
 #define SP_MAX_TEXTURE_2D_LEVELS 15  /* 16K x 16K */
 #define SP_MAX_TEXTURE_3D_LEVELS 9   /* 256 x 256 x 256 */
 #define SP_MAX_TEXTURE_CUBE_LEVELS 13  /* 4K x 4K */
index 978fbe1fe6791038b272321da94022351a2bde8b..50137fe6227cd489bdd3c57a9a87bf58717725f3 100644 (file)
@@ -52,7 +52,8 @@
  */
 static boolean
 softpipe_resource_layout(struct pipe_screen *screen,
-                         struct softpipe_resource *spr)
+                         struct softpipe_resource *spr,
+                         boolean allocate)
 {
    struct pipe_resource *pt = &spr->base;
    unsigned level;
@@ -83,9 +84,31 @@ softpipe_resource_layout(struct pipe_screen *screen,
       depth = u_minify(depth, 1);
    }
 
-   spr->data = align_malloc(buffer_size, 16);
+   if (buffer_size > SP_MAX_TEXTURE_SIZE)
+      return FALSE;
+
+   if (allocate) {
+      spr->data = align_malloc(buffer_size, 16);
+      return spr->data != NULL;
+   }
+   else {
+      return TRUE;
+   }
+}
 
-   return spr->data != NULL;
+
+/**
+ * Check the size of the texture specified by 'res'.
+ * \return TRUE if OK, FALSE if too large.
+ */
+static boolean
+softpipe_can_create_resource(struct pipe_screen *screen,
+                             const struct pipe_resource *res)
+{
+   struct softpipe_resource spr;
+   memset(&spr, 0, sizeof(spr));
+   spr.base = *res;
+   return softpipe_resource_layout(screen, &spr, FALSE);
 }
 
 
@@ -140,7 +163,7 @@ softpipe_resource_create(struct pipe_screen *screen,
          goto fail;
    }
    else {
-      if (!softpipe_resource_layout(screen, spr))
+      if (!softpipe_resource_layout(screen, spr, TRUE))
          goto fail;
    }
     
@@ -506,4 +529,5 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
    screen->resource_destroy = softpipe_resource_destroy;
    screen->resource_from_handle = softpipe_resource_from_handle;
    screen->resource_get_handle = softpipe_resource_get_handle;
+   screen->can_create_resource = softpipe_can_create_resource;
 }