From 92fcbf6e7bc622dcace226bb70ff6d5cdbdbaecb Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 15 Feb 2008 20:07:18 +0900 Subject: Code reorganization: s/aux/auxiliary/. "aux" is a reserved name on Windows (X_X) --- src/gallium/auxiliary/cso_cache/cso_cache.h | 107 ++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/gallium/auxiliary/cso_cache/cso_cache.h (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h new file mode 100644 index 0000000000..116e2eaa2c --- /dev/null +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -0,0 +1,107 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + /* + * Authors: + * Zack Rusin + */ + +#ifndef CSO_CACHE_H +#define CSO_CACHE_H + +#include "pipe/p_context.h" +#include "pipe/p_state.h" + + +struct cso_hash; + +struct cso_cache { + struct cso_hash *blend_hash; + struct cso_hash *depth_stencil_hash; + struct cso_hash *fs_hash; + struct cso_hash *vs_hash; + struct cso_hash *rasterizer_hash; + struct cso_hash *sampler_hash; +}; + +struct cso_blend { + struct pipe_blend_state state; + void *data; +}; + +struct cso_depth_stencil_alpha { + struct pipe_depth_stencil_alpha_state state; + void *data; +}; + +struct cso_rasterizer { + struct pipe_rasterizer_state state; + void *data; +}; + +struct cso_fragment_shader { + struct pipe_shader_state state; + void *data; +}; + +struct cso_vertex_shader { + struct pipe_shader_state state; + void *data; +}; + +struct cso_sampler { + struct pipe_sampler_state state; + void *data; +}; + + +enum cso_cache_type { + CSO_BLEND, + CSO_SAMPLER, + CSO_DEPTH_STENCIL_ALPHA, + CSO_RASTERIZER, + CSO_FRAGMENT_SHADER, + CSO_VERTEX_SHADER +}; + +unsigned cso_construct_key(void *item, int item_size); + +struct cso_cache *cso_cache_create(void); +void cso_cache_delete(struct cso_cache *sc); + +struct cso_hash_iter cso_insert_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *state); +struct cso_hash_iter cso_find_state(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type); +struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, + unsigned hash_key, enum cso_cache_type type, + void *templ); +void * cso_take_state(struct cso_cache *sc, unsigned hash_key, + enum cso_cache_type type); + +#endif -- cgit v1.2.3 From 901b03e84dce21f4241375da179b2199a3162e0c Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 22 Feb 2008 18:28:30 +0900 Subject: gallium: Wrap decls in extern "C". --- src/gallium/auxiliary/cso_cache/cso_cache.h | 12 ++++++++++++ src/gallium/auxiliary/cso_cache/cso_hash.h | 10 ++++++++++ 2 files changed, 22 insertions(+) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 116e2eaa2c..58664cdd94 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -37,8 +37,15 @@ #include "pipe/p_state.h" +#ifdef __cplusplus +extern "C" { +#endif + + struct cso_hash; +struct cso_hash_iter; + struct cso_cache { struct cso_hash *blend_hash; struct cso_hash *depth_stencil_hash; @@ -104,4 +111,9 @@ struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, void * cso_take_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h index ffd99beba9..2e8b69675c 100644 --- a/src/gallium/auxiliary/cso_cache/cso_hash.h +++ b/src/gallium/auxiliary/cso_cache/cso_hash.h @@ -33,6 +33,12 @@ #ifndef CSO_HASH_H #define CSO_HASH_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct cso_hash; struct cso_node; @@ -68,4 +74,8 @@ void *cso_hash_find_data_from_template( struct cso_hash *hash, int size ); +#ifdef __cplusplus +} +#endif + #endif -- cgit v1.2.3 From f1bef2cba2e6e4c0988b05306dd1435b8c0df3d5 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 22 Feb 2008 18:45:20 +0900 Subject: gallium: Countour MSVC's pickyness for structures returned by value. --- src/gallium/auxiliary/cso_cache/cso_cache.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 58664cdd94..b4f4f3ae41 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -36,16 +36,14 @@ #include "pipe/p_context.h" #include "pipe/p_state.h" +#include "cso_hash.h" /* for cso_hash_iter, as MSVC requires structures returned by value to be fully defined */ + #ifdef __cplusplus extern "C" { #endif -struct cso_hash; - -struct cso_hash_iter; - struct cso_cache { struct cso_hash *blend_hash; struct cso_hash *depth_stencil_hash; -- cgit v1.2.3 From b75706764b4cf18f3b41bf4a97d82b3c528064d8 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 25 Feb 2008 15:18:33 +0900 Subject: Add Zack's comments about CSOs. --- src/gallium/auxiliary/cso_cache/cso_cache.h | 51 ++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index b4f4f3ae41..3a005a376e 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -25,9 +25,48 @@ * **************************************************************************/ - /* - * Authors: - * Zack Rusin + /** + * @file + * Constant State Object (CSO) cache. + * + * The basic idea is that the states are created via the + * create_state/bind_state/delete_state semantics. The driver is expected to + * perform as much of the Gallium state translation to whatever its internal + * representation is during the create call. Gallium then has a caching + * mechanism where it stores the created states. When the pipeline needs an + * actual state change, a bind call is issued. In the bind call the driver + * gets its already translated representation. + * + * Those semantics mean that the driver doesn't do the repeated translations + * of states on every frame, but only once, when a new state is actually + * created. + * + * Even on hardware that doesn't do any kind of state cache, it makes the + * driver look a lot neater, plus it avoids all the redundant state + * translations on every frame. + * + * Currently our constant state objects are: + * - alpha test + * - blend + * - depth stencil + * - fragment shader + * - rasterizer (old setup) + * - sampler + * - vertex shader + * + * Things that are not constant state objects include: + * - blend_color + * - clip_state + * - clear_color_state + * - constant_buffer + * - feedback_state + * - framebuffer_state + * - polygon_stipple + * - scissor_state + * - texture_state + * - viewport_state + * + * @author Zack Rusin */ #ifndef CSO_CACHE_H @@ -36,7 +75,9 @@ #include "pipe/p_context.h" #include "pipe/p_state.h" -#include "cso_hash.h" /* for cso_hash_iter, as MSVC requires structures returned by value to be fully defined */ +/* cso_hash.h is necessary for cso_hash_iter, as MSVC requires structures + * returned by value to be fully defined */ +#include "cso_hash.h" #ifdef __cplusplus -- cgit v1.2.3 From 6abb82da7e676384e7e2c9732307b23f8ed7157d Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 25 Feb 2008 22:03:58 -0500 Subject: implement deleting of driver side cached state in cso's --- src/gallium/auxiliary/cso_cache/cso_cache.c | 88 +++++++++++++++++++++++++++++ src/gallium/auxiliary/cso_cache/cso_cache.h | 14 +++++ src/gallium/auxiliary/cso_cache/cso_hash.h | 1 - src/mesa/state_tracker/st_cache.c | 13 ++++- 4 files changed, 114 insertions(+), 2 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 9c32e94124..9aa1a64272 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -190,9 +190,96 @@ struct cso_cache *cso_cache_create(void) return sc; } +void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, + void (*func)(void *state, void *user_data), void *user_data) +{ + struct cso_hash *hash = 0; + struct cso_hash_iter iter; + + switch (type) { + case CSO_BLEND: + hash = sc->blend_hash; + break; + case CSO_SAMPLER: + hash = sc->sampler_hash; + break; + case CSO_DEPTH_STENCIL_ALPHA: + hash = sc->depth_stencil_hash; + break; + case CSO_RASTERIZER: + hash = sc->rasterizer_hash; + break; + case CSO_FRAGMENT_SHADER: + hash = sc->fs_hash; + break; + case CSO_VERTEX_SHADER: + hash = sc->vs_hash; + break; + } + + iter = cso_hash_first_node(hash); + while (!cso_hash_iter_is_null(iter)) { + void *state = cso_hash_iter_data(iter); + if (state) { + func(state, user_data); + } + iter = cso_hash_iter_next(iter); + } +} + +static void delete_blend_state(void *state, void *user_data) +{ + struct cso_blend *cso = (struct cso_blend *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + +static void delete_depth_stencil_state(void *state, void *pipe) +{ + struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + +static void delete_sampler_state(void *state, void *pipe) +{ + struct cso_sampler *cso = (struct cso_sampler *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + +static void delete_rasterizer_state(void *state, void *pipe) +{ + struct cso_rasterizer *cso = (struct cso_rasterizer *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + +static void delete_fs_state(void *state, void *pipe) +{ + struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + +static void delete_vs_state(void *state, void *pipe) +{ + struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state; + if (cso->delete_state && cso->data != &cso->state) + cso->delete_state(cso->context, cso->data); +} + void cso_cache_delete(struct cso_cache *sc) { assert(sc); + /* delete driver data */ + cso_for_each_state(sc, CSO_BLEND, delete_blend_state, 0); + cso_for_each_state(sc, CSO_DEPTH_STENCIL_ALPHA, delete_depth_stencil_state, 0); + cso_for_each_state(sc, CSO_FRAGMENT_SHADER, delete_fs_state, 0); + cso_for_each_state(sc, CSO_VERTEX_SHADER, delete_vs_state, 0); + cso_for_each_state(sc, CSO_RASTERIZER, delete_rasterizer_state, 0); + cso_for_each_state(sc, CSO_SAMPLER, delete_sampler_state, 0); + cso_hash_delete(sc->blend_hash); cso_hash_delete(sc->sampler_hash); cso_hash_delete(sc->depth_stencil_hash); @@ -201,3 +288,4 @@ void cso_cache_delete(struct cso_cache *sc) cso_hash_delete(sc->vs_hash); FREE(sc); } + diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 3a005a376e..f3bd4623c9 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -97,31 +97,43 @@ struct cso_cache { struct cso_blend { struct pipe_blend_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; struct cso_depth_stencil_alpha { struct pipe_depth_stencil_alpha_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; struct cso_rasterizer { struct pipe_rasterizer_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; struct cso_fragment_shader { struct pipe_shader_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; struct cso_vertex_shader { struct pipe_shader_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; struct cso_sampler { struct pipe_sampler_state state; void *data; + void (*delete_state)(void *, void *); + void *context; }; @@ -147,6 +159,8 @@ struct cso_hash_iter cso_find_state(struct cso_cache *sc, struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type, void *templ); +void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, + void (*func)(void *state, void *user_data), void *user_data); void * cso_take_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type); diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h index 2e8b69675c..86c62c027a 100644 --- a/src/gallium/auxiliary/cso_cache/cso_hash.h +++ b/src/gallium/auxiliary/cso_cache/cso_hash.h @@ -38,7 +38,6 @@ extern "C" { #endif - struct cso_hash; struct cso_node; diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 2979e7fae5..78f282302e 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -63,6 +63,8 @@ const struct cso_blend * st_cached_blend_state(struct st_context *st, cso->data = st->pipe->create_blend_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_blend_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_BLEND, cso); } return ((struct cso_blend *)cso_hash_iter_data(iter)); @@ -82,6 +84,8 @@ st_cached_sampler_state(struct st_context *st, cso->data = st->pipe->create_sampler_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_sampler_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, cso); } return (struct cso_sampler*)(cso_hash_iter_data(iter)); @@ -103,6 +107,8 @@ st_cached_depth_stencil_alpha_state(struct st_context *st, cso->data = st->pipe->create_depth_stencil_alpha_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_depth_stencil_alpha_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso); } return (struct cso_depth_stencil_alpha*)(cso_hash_iter_data(iter)); @@ -123,6 +129,8 @@ const struct cso_rasterizer* st_cached_rasterizer_state( cso->data = st->pipe->create_rasterizer_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_rasterizer_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_RASTERIZER, cso); } return (struct cso_rasterizer*)(cso_hash_iter_data(iter)); @@ -143,6 +151,8 @@ st_cached_fs_state(struct st_context *st, cso->data = st->pipe->create_fs_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_fs_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, cso); } return (struct cso_fragment_shader*)(cso_hash_iter_data(iter)); @@ -163,8 +173,9 @@ st_cached_vs_state(struct st_context *st, cso->data = st->pipe->create_vs_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; + cso->delete_state = st->pipe->delete_vs_state; + cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, cso); } return (struct cso_vertex_shader*)(cso_hash_iter_data(iter)); } - -- cgit v1.2.3 From bf1c2f3602038440ffacf7ae494cb4e9bacc9bb9 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 26 Feb 2008 00:15:55 -0500 Subject: hide cso cache definition and add some initial code for size limiting the caches --- src/gallium/auxiliary/cso_cache/cso_cache.c | 22 ++++++++++++++++++++++ src/gallium/auxiliary/cso_cache/cso_cache.h | 28 +++++++++++----------------- 2 files changed, 33 insertions(+), 17 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 9aa1a64272..1b870c8e41 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -33,6 +33,17 @@ #include "cso_cache.h" #include "cso_hash.h" + +struct cso_cache { + struct cso_hash *blend_hash; + struct cso_hash *depth_stencil_hash; + struct cso_hash *fs_hash; + struct cso_hash *vs_hash; + struct cso_hash *rasterizer_hash; + struct cso_hash *sampler_hash; + int max_size; +}; + #if 1 static unsigned hash_key(const void *key, unsigned key_size) { @@ -180,6 +191,7 @@ struct cso_cache *cso_cache_create(void) { struct cso_cache *sc = MALLOC_STRUCT(cso_cache); + sc->max_size = 4096; sc->blend_hash = cso_hash_create(); sc->sampler_hash = cso_hash_create(); sc->depth_stencil_hash = cso_hash_create(); @@ -289,3 +301,13 @@ void cso_cache_delete(struct cso_cache *sc) FREE(sc); } +void cso_set_maximum_cache_size(struct cso_cache *sc, int number) +{ + sc->max_size = number; +} + +int cso_maximum_cache_size(const struct cso_cache *sc) +{ + return sc->max_size; +} + diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index f3bd4623c9..72a6b9d488 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -28,7 +28,7 @@ /** * @file * Constant State Object (CSO) cache. - * + * * The basic idea is that the states are created via the * create_state/bind_state/delete_state semantics. The driver is expected to * perform as much of the Gallium state translation to whatever its internal @@ -36,15 +36,15 @@ * mechanism where it stores the created states. When the pipeline needs an * actual state change, a bind call is issued. In the bind call the driver * gets its already translated representation. - * + * * Those semantics mean that the driver doesn't do the repeated translations * of states on every frame, but only once, when a new state is actually * created. - * + * * Even on hardware that doesn't do any kind of state cache, it makes the * driver look a lot neater, plus it avoids all the redundant state * translations on every frame. - * + * * Currently our constant state objects are: * - alpha test * - blend @@ -53,7 +53,7 @@ * - rasterizer (old setup) * - sampler * - vertex shader - * + * * Things that are not constant state objects include: * - blend_color * - clip_state @@ -65,7 +65,7 @@ * - scissor_state * - texture_state * - viewport_state - * + * * @author Zack Rusin */ @@ -75,24 +75,16 @@ #include "pipe/p_context.h" #include "pipe/p_state.h" -/* cso_hash.h is necessary for cso_hash_iter, as MSVC requires structures +/* cso_hash.h is necessary for cso_hash_iter, as MSVC requires structures * returned by value to be fully defined */ -#include "cso_hash.h" +#include "cso_hash.h" #ifdef __cplusplus extern "C" { #endif - -struct cso_cache { - struct cso_hash *blend_hash; - struct cso_hash *depth_stencil_hash; - struct cso_hash *fs_hash; - struct cso_hash *vs_hash; - struct cso_hash *rasterizer_hash; - struct cso_hash *sampler_hash; -}; +struct cso_cache; struct cso_blend { struct pipe_blend_state state; @@ -164,6 +156,8 @@ void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, void * cso_take_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type); +void cso_set_maximum_cache_size(struct cso_cache *sc, int number); +int cso_maximum_cache_size(const struct cso_cache *sc); #ifdef __cplusplus } -- cgit v1.2.3 From e7985105695a18c29c13deb2b8f40c15eef72ee6 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 26 Feb 2008 00:18:54 -0500 Subject: add an explicit callback decleration and use it to silence warnings --- src/gallium/auxiliary/cso_cache/cso_cache.c | 2 +- src/gallium/auxiliary/cso_cache/cso_cache.h | 4 +++- src/mesa/state_tracker/st_cache.c | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 1b870c8e41..f31042bce1 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -203,7 +203,7 @@ struct cso_cache *cso_cache_create(void) } void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, - void (*func)(void *state, void *user_data), void *user_data) + cso_state_callback func, void *user_data) { struct cso_hash *hash = 0; struct cso_hash_iter iter; diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 72a6b9d488..3b0fe100b8 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -138,6 +138,8 @@ enum cso_cache_type { CSO_VERTEX_SHADER }; +typedef void (*cso_state_callback)(void *, void *); + unsigned cso_construct_key(void *item, int item_size); struct cso_cache *cso_cache_create(void); @@ -152,7 +154,7 @@ struct cso_hash_iter cso_find_state_template(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type, void *templ); void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, - void (*func)(void *state, void *user_data), void *user_data); + cso_state_callback func, void *user_data); void * cso_take_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type); diff --git a/src/mesa/state_tracker/st_cache.c b/src/mesa/state_tracker/st_cache.c index 78f282302e..7ee4fadc37 100644 --- a/src/mesa/state_tracker/st_cache.c +++ b/src/mesa/state_tracker/st_cache.c @@ -63,7 +63,7 @@ const struct cso_blend * st_cached_blend_state(struct st_context *st, cso->data = st->pipe->create_blend_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_blend_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_blend_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_BLEND, cso); } @@ -84,7 +84,7 @@ st_cached_sampler_state(struct st_context *st, cso->data = st->pipe->create_sampler_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_sampler_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_sampler_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_SAMPLER, cso); } @@ -107,7 +107,7 @@ st_cached_depth_stencil_alpha_state(struct st_context *st, cso->data = st->pipe->create_depth_stencil_alpha_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_depth_stencil_alpha_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_depth_stencil_alpha_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_DEPTH_STENCIL_ALPHA, cso); } @@ -129,7 +129,7 @@ const struct cso_rasterizer* st_cached_rasterizer_state( cso->data = st->pipe->create_rasterizer_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_rasterizer_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_rasterizer_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_RASTERIZER, cso); } @@ -151,7 +151,7 @@ st_cached_fs_state(struct st_context *st, cso->data = st->pipe->create_fs_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_fs_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_fs_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_FRAGMENT_SHADER, cso); } @@ -173,7 +173,7 @@ st_cached_vs_state(struct st_context *st, cso->data = st->pipe->create_vs_state(st->pipe, &cso->state); if (!cso->data) cso->data = &cso->state; - cso->delete_state = st->pipe->delete_vs_state; + cso->delete_state = (cso_state_callback)st->pipe->delete_vs_state; cso->context = st->pipe; iter = cso_insert_state(st->cache, hash_key, CSO_VERTEX_SHADER, cso); } -- cgit v1.2.3 From 8902ce06e85f48a436ee3794c77f7abf59f56594 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 27 Feb 2008 14:06:07 +0900 Subject: gallium: Use stricter types. VC++ won't silently convert a pointer to a function with typed pointer arguments to one with void pointer arguments. --- src/gallium/auxiliary/cso_cache/cso_cache.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 3b0fe100b8..44ee128a4a 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -88,44 +88,44 @@ struct cso_cache; struct cso_blend { struct pipe_blend_state state; - void *data; - void (*delete_state)(void *, void *); - void *context; + void *data; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; struct cso_depth_stencil_alpha { struct pipe_depth_stencil_alpha_state state; void *data; - void (*delete_state)(void *, void *); - void *context; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; struct cso_rasterizer { struct pipe_rasterizer_state state; void *data; - void (*delete_state)(void *, void *); - void *context; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; struct cso_fragment_shader { struct pipe_shader_state state; void *data; - void (*delete_state)(void *, void *); - void *context; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; struct cso_vertex_shader { struct pipe_shader_state state; void *data; - void (*delete_state)(void *, void *); - void *context; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; struct cso_sampler { struct pipe_sampler_state state; void *data; - void (*delete_state)(void *, void *); - void *context; + void (*delete_state)(struct pipe_context *, void *); + struct pipe_context *context; }; -- cgit v1.2.3 From 34a0ac7f2b93d6d0f3fc85106e7dacb38c4229b6 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 11 Mar 2008 15:01:52 -0600 Subject: gallium: fix some cso_state_callback cast warnings --- src/gallium/auxiliary/cso_cache/cso_cache.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 44ee128a4a..e5edbbb556 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -84,47 +84,49 @@ extern "C" { #endif +typedef void (*cso_state_callback)(void *ctx, void *obj); + struct cso_cache; struct cso_blend { struct pipe_blend_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; struct cso_depth_stencil_alpha { struct pipe_depth_stencil_alpha_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; struct cso_rasterizer { struct pipe_rasterizer_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; struct cso_fragment_shader { struct pipe_shader_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; struct cso_vertex_shader { struct pipe_shader_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; struct cso_sampler { struct pipe_sampler_state state; void *data; - void (*delete_state)(struct pipe_context *, void *); + cso_state_callback delete_state; struct pipe_context *context; }; @@ -138,8 +140,6 @@ enum cso_cache_type { CSO_VERTEX_SHADER }; -typedef void (*cso_state_callback)(void *, void *); - unsigned cso_construct_key(void *item, int item_size); struct cso_cache *cso_cache_create(void); -- cgit v1.2.3 From 026e31a068981724fb0c98f6d1fc87d086fd2da6 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Wed, 30 Apr 2008 02:04:28 -0400 Subject: try to fix the deleting of the bound cso during cleanup of the hash --- src/gallium/auxiliary/cso_cache/cso_cache.c | 40 ++++++-- src/gallium/auxiliary/cso_cache/cso_cache.h | 28 ++++-- src/gallium/auxiliary/cso_cache/cso_context.c | 128 ++++++++++++++++++++++++++ 3 files changed, 178 insertions(+), 18 deletions(-) (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.h') diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 096875807b..36dc46ff80 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -43,6 +43,9 @@ struct cso_cache { struct cso_hash *rasterizer_hash; struct cso_hash *sampler_hash; int max_size; + + cso_sanitize_callback sanitize_cb; + void *sanitize_data; }; #if 1 @@ -205,8 +208,19 @@ static INLINE void delete_cso(void *state, enum cso_cache_type type) } } -static INLINE void sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, + +static INLINE void sanitize_hash(struct cso_cache *sc, + struct cso_hash *hash, + enum cso_cache_type type, int max_size) +{ + if (sc->sanitize_cb) + sc->sanitize_cb(hash, type, max_size, sc->sanitize_data); +} + + +static INLINE void sanitize_cb(struct cso_hash *hash, enum cso_cache_type type, + int max_size, void *user_data) { /* if we're approach the maximum size, remove fourth of the entries * otherwise every subsequent call will go through the same */ @@ -231,7 +245,7 @@ cso_insert_state(struct cso_cache *sc, void *state) { struct cso_hash *hash = _cso_hash_for_type(sc, type); - sanitize_hash(hash, type, sc->max_size); + sanitize_hash(sc, hash, type, sc->max_size); return cso_hash_insert(hash, hash_key, state); } @@ -300,6 +314,8 @@ struct cso_cache *cso_cache_create(void) sc->rasterizer_hash = cso_hash_create(); sc->fs_hash = cso_hash_create(); sc->vs_hash = cso_hash_create(); + sc->sanitize_cb = sanitize_cb; + sc->sanitize_data = 0; return sc; } @@ -365,13 +381,13 @@ void cso_set_maximum_cache_size(struct cso_cache *sc, int number) { sc->max_size = number; - sanitize_hash(sc->blend_hash, CSO_BLEND, sc->max_size); - sanitize_hash(sc->depth_stencil_hash, CSO_DEPTH_STENCIL_ALPHA, + sanitize_hash(sc, sc->blend_hash, CSO_BLEND, sc->max_size); + sanitize_hash(sc, sc->depth_stencil_hash, CSO_DEPTH_STENCIL_ALPHA, sc->max_size); - sanitize_hash(sc->fs_hash, CSO_FRAGMENT_SHADER, sc->max_size); - sanitize_hash(sc->vs_hash, CSO_VERTEX_SHADER, sc->max_size); - sanitize_hash(sc->rasterizer_hash, CSO_RASTERIZER, sc->max_size); - sanitize_hash(sc->sampler_hash, CSO_SAMPLER, sc->max_size); + sanitize_hash(sc, sc->fs_hash, CSO_FRAGMENT_SHADER, sc->max_size); + sanitize_hash(sc, sc->vs_hash, CSO_VERTEX_SHADER, sc->max_size); + sanitize_hash(sc, sc->rasterizer_hash, CSO_RASTERIZER, sc->max_size); + sanitize_hash(sc, sc->sampler_hash, CSO_SAMPLER, sc->max_size); } int cso_maximum_cache_size(const struct cso_cache *sc) @@ -379,3 +395,11 @@ int cso_maximum_cache_size(const struct cso_cache *sc) return sc->max_size; } +void cso_cache_set_sanitize_callback(struct cso_cache *sc, + cso_sanitize_callback cb, + void *user_data) +{ + sc->sanitize_cb = cb; + sc->sanitize_data = user_data; +} + diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index e5edbbb556..6b5c230e8f 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -84,8 +84,22 @@ extern "C" { #endif +enum cso_cache_type { + CSO_BLEND, + CSO_SAMPLER, + CSO_DEPTH_STENCIL_ALPHA, + CSO_RASTERIZER, + CSO_FRAGMENT_SHADER, + CSO_VERTEX_SHADER +}; + typedef void (*cso_state_callback)(void *ctx, void *obj); +typedef void (*cso_sanitize_callback)(struct cso_hash *hash, + enum cso_cache_type type, + int max_size, + void *user_data); + struct cso_cache; struct cso_blend { @@ -130,21 +144,15 @@ struct cso_sampler { struct pipe_context *context; }; - -enum cso_cache_type { - CSO_BLEND, - CSO_SAMPLER, - CSO_DEPTH_STENCIL_ALPHA, - CSO_RASTERIZER, - CSO_FRAGMENT_SHADER, - CSO_VERTEX_SHADER -}; - unsigned cso_construct_key(void *item, int item_size); struct cso_cache *cso_cache_create(void); void cso_cache_delete(struct cso_cache *sc); +void cso_cache_set_sanitize_callback(struct cso_cache *sc, + cso_sanitize_callback cb, + void *user_data); + struct cso_hash_iter cso_insert_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type, void *state); diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index b4609e999b..eef898f486 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -80,6 +80,131 @@ struct cso_context { }; +static boolean delete_blend_state(struct cso_context *ctx, void *state) +{ + struct cso_blend *cso = (struct cso_blend *)state; + + if (ctx->blend == state) + return FALSE; + + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_depth_stencil_state(struct cso_context *ctx, void *state) +{ + struct cso_depth_stencil_alpha *cso = (struct cso_depth_stencil_alpha *)state; + + if (ctx->depth_stencil == cso->data) + return FALSE; + + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + + return TRUE; +} + +static boolean delete_sampler_state(struct cso_context *ctx, void *state) +{ + struct cso_sampler *cso = (struct cso_sampler *)state; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_rasterizer_state(struct cso_context *ctx, void *state) +{ + struct cso_rasterizer *cso = (struct cso_rasterizer *)state; + + if (ctx->rasterizer == cso->data) + return FALSE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_fs_state(struct cso_context *ctx, void *state) +{ + struct cso_fragment_shader *cso = (struct cso_fragment_shader *)state; + if (ctx->fragment_shader == cso->data) + return FALSE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return TRUE; +} + +static boolean delete_vs_state(struct cso_context *ctx, void *state) +{ + struct cso_vertex_shader *cso = (struct cso_vertex_shader *)state; + if (ctx->vertex_shader == cso->data) + return TRUE; + if (cso->delete_state) + cso->delete_state(cso->context, cso->data); + FREE(state); + return FALSE; +} + + +static INLINE boolean delete_cso(struct cso_context *ctx, + void *state, enum cso_cache_type type) +{ + switch (type) { + case CSO_BLEND: + return delete_blend_state(ctx, state); + break; + case CSO_SAMPLER: + return delete_sampler_state(ctx, state); + break; + case CSO_DEPTH_STENCIL_ALPHA: + return delete_depth_stencil_state(ctx, state); + break; + case CSO_RASTERIZER: + return delete_rasterizer_state(ctx, state); + break; + case CSO_FRAGMENT_SHADER: + return delete_fs_state(ctx, state); + break; + case CSO_VERTEX_SHADER: + return delete_vs_state(ctx, state); + break; + default: + assert(0); + FREE(state); + } + return FALSE; +} + +static INLINE void sanitize_hash(struct cso_hash *hash, enum cso_cache_type type, + int max_size, void *user_data) +{ + struct cso_context *ctx = (struct cso_context *)user_data; + /* if we're approach the maximum size, remove fourth of the entries + * otherwise every subsequent call will go through the same */ + int hash_size = cso_hash_size(hash); + int max_entries = (max_size > hash_size) ? max_size : hash_size; + int to_remove = (max_size < max_entries) * max_entries/4; + struct cso_hash_iter iter = cso_hash_first_node(hash); + if (hash_size > max_size) + to_remove += hash_size - max_size; + while (to_remove) { + /*remove elements until we're good */ + /*fixme: currently we pick the nodes to remove at random*/ + void *cso = cso_hash_iter_data(iter); + if (delete_cso(ctx, cso, type)) { + iter = cso_hash_erase(hash, iter); + --to_remove; + } else + iter = cso_hash_iter_next(iter); + } +} + + struct cso_context *cso_create_context( struct pipe_context *pipe ) { struct cso_context *ctx = CALLOC_STRUCT(cso_context); @@ -89,6 +214,9 @@ struct cso_context *cso_create_context( struct pipe_context *pipe ) ctx->cache = cso_cache_create(); if (ctx->cache == NULL) goto out; + cso_cache_set_sanitize_callback(ctx->cache, + sanitize_hash, + ctx); ctx->pipe = pipe; -- cgit v1.2.3