i915g: Use slab allocator for transfers
authorJakob Bornecrantz <wallbraker@gmail.com>
Fri, 3 Dec 2010 18:42:45 +0000 (19:42 +0100)
committerJakob Bornecrantz <wallbraker@gmail.com>
Fri, 21 Jan 2011 19:53:29 +0000 (20:53 +0100)
Also remove unused i915_transfer struct

src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_resource_buffer.c
src/gallium/drivers/i915/i915_resource_texture.c
src/gallium/drivers/i915/i915_screen.h

index 9be316192547d929855ae214b1566ae4186e0b12..9d43381f7b39571e2d0c91a7ee8bb6866de49111 100644 (file)
@@ -140,6 +140,10 @@ i915_create_context(struct pipe_screen *screen, void *priv)
 
    i915->base.draw_vbo = i915_draw_vbo;
 
+   /* init this before draw */
+   util_slab_create(&i915->transfer_pool, sizeof(struct pipe_transfer),
+                    16, UTIL_SLAB_SINGLETHREADED);
+
    /*
     * Create drawing context and plug our rendering stage into it.
     */
index d15e1723d8379285f26a6462b3f72fe47962cb11..1bf9cde4d4de15b0b8e3922c0651d1c25623009d 100644 (file)
@@ -37,6 +37,8 @@
 
 #include "tgsi/tgsi_scan.h"
 
+#include "util/u_slab.h"
+
 
 struct i915_winsys;
 struct i915_winsys_buffer;
@@ -237,6 +239,8 @@ struct i915_context {
 
    struct i915_state current;
    unsigned hardware_dirty;
+
+   struct util_slab_mempool transfer_pool;
 };
 
 /* A flag for each state_tracker state object:
index 450203d60a9700e3a854675ceeda2bbcc5c747ff..6e2b490f535a49941688bd0bd57e7ae2ebfca7c0 100644 (file)
@@ -60,6 +60,38 @@ i915_buffer_destroy(struct pipe_screen *screen,
 }
 
 
+static struct pipe_transfer *
+i915_get_transfer(struct pipe_context *pipe,
+                  struct pipe_resource *resource,
+                  unsigned level,
+                  unsigned usage,
+                  const struct pipe_box *box)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   struct pipe_transfer *transfer = util_slab_alloc(&i915->transfer_pool);
+
+   if (transfer == NULL)
+      return NULL;
+
+   transfer->resource = resource;
+   transfer->level = level;
+   transfer->usage = usage;
+   transfer->box = *box;
+
+   /* Note strides are zero, this is ok for buffers, but not for
+    * textures 2d & higher at least. 
+    */
+   return transfer;
+}
+
+static void
+i915_transfer_destroy(struct pipe_context *pipe,
+                      struct pipe_transfer *transfer)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   util_slab_free(&i915->transfer_pool, transfer);
+}
+
 static void *
 i915_buffer_transfer_map( struct pipe_context *pipe,
                           struct pipe_transfer *transfer )
@@ -92,8 +124,8 @@ struct u_resource_vtbl i915_buffer_vtbl =
    i915_buffer_get_handle,          /* get_handle */
    i915_buffer_destroy,                     /* resource_destroy */
    NULL,                            /* is_resource_referenced */
-   u_default_get_transfer,          /* get_transfer */
-   u_default_transfer_destroy,      /* transfer_destroy */
+   i915_get_transfer,               /* get_transfer */
+   i915_transfer_destroy,           /* transfer_destroy */
    i915_buffer_transfer_map,        /* transfer_map */
    u_default_transfer_flush_region,  /* transfer_flush_region */
    u_default_transfer_unmap,        /* transfer_unmap */
index f19106f3414a65825ff7acf88ed22928ee9362e2..e793d126ade8b02a0631cb4f2a0b68e282010814 100644 (file)
@@ -716,14 +716,16 @@ i915_texture_destroy(struct pipe_screen *screen,
 }
 
 static struct pipe_transfer * 
-i915_texture_get_transfer(struct pipe_context *context,
+i915_texture_get_transfer(struct pipe_context *pipe,
                           struct pipe_resource *resource,
                           unsigned level,
                           unsigned usage,
                           const struct pipe_box *box)
 {
+   struct i915_context *i915 = i915_context(pipe);
    struct i915_texture *tex = i915_texture(resource);
-   struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer);
+   struct pipe_transfer *transfer = util_slab_alloc(&i915->transfer_pool);
+
    if (transfer == NULL)
       return NULL;
 
@@ -737,6 +739,14 @@ i915_texture_get_transfer(struct pipe_context *context,
    return transfer;
 }
 
+static void
+i915_transfer_destroy(struct pipe_context *pipe,
+                      struct pipe_transfer *transfer)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   util_slab_free(&i915->transfer_pool, transfer);
+}
+
 static void *
 i915_texture_transfer_map(struct pipe_context *pipe,
                           struct pipe_transfer *transfer)
@@ -781,7 +791,7 @@ struct u_resource_vtbl i915_texture_vtbl =
    i915_texture_destroy,             /* resource_destroy */
    NULL,                             /* is_resource_referenced */
    i915_texture_get_transfer,        /* get_transfer */
-   u_default_transfer_destroy,       /* transfer_destroy */
+   i915_transfer_destroy,            /* transfer_destroy */
    i915_texture_transfer_map,        /* transfer_map */
    u_default_transfer_flush_region,   /* transfer_flush_region */
    i915_texture_transfer_unmap,              /* transfer_unmap */
index 0c4186c68ee10c2a392dfa9316a77be82b41b7f7..bb4d255a3b39942060ff06171a08f50458776329 100644 (file)
@@ -47,16 +47,6 @@ struct i915_screen
    boolean is_i945;
 };
 
-/**
- * Subclass of pipe_transfer
- */
-struct i915_transfer
-{
-   struct pipe_transfer base;
-
-   unsigned offset;
-};
-
 
 /*
  * Cast wrappers
@@ -69,11 +59,5 @@ i915_screen(struct pipe_screen *pscreen)
    return (struct i915_screen *) pscreen;
 }
 
-static INLINE struct i915_transfer *
-i915_transfer(struct pipe_transfer *transfer)
-{
-   return (struct i915_transfer *)transfer;
-}
-
 
 #endif /* I915_SCREEN_H */