From: Jakob Bornecrantz Date: Fri, 3 Dec 2010 18:42:45 +0000 (+0100) Subject: i915g: Use slab allocator for transfers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7287964f944d7e2bcf409b758163ab75c61b0f8e;p=mesa.git i915g: Use slab allocator for transfers Also remove unused i915_transfer struct --- diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c index 9be31619254..9d43381f7b3 100644 --- a/src/gallium/drivers/i915/i915_context.c +++ b/src/gallium/drivers/i915/i915_context.c @@ -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. */ diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index d15e1723d83..1bf9cde4d4d 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -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: diff --git a/src/gallium/drivers/i915/i915_resource_buffer.c b/src/gallium/drivers/i915/i915_resource_buffer.c index 450203d60a9..6e2b490f535 100644 --- a/src/gallium/drivers/i915/i915_resource_buffer.c +++ b/src/gallium/drivers/i915/i915_resource_buffer.c @@ -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 */ diff --git a/src/gallium/drivers/i915/i915_resource_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c index f19106f3414..e793d126ade 100644 --- a/src/gallium/drivers/i915/i915_resource_texture.c +++ b/src/gallium/drivers/i915/i915_resource_texture.c @@ -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 */ diff --git a/src/gallium/drivers/i915/i915_screen.h b/src/gallium/drivers/i915/i915_screen.h index 0c4186c68ee..bb4d255a3b3 100644 --- a/src/gallium/drivers/i915/i915_screen.h +++ b/src/gallium/drivers/i915/i915_screen.h @@ -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 */