cso_cache.h File Reference

Constant State Object (CSO) cache. More...

Include dependency graph for cso_cache.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cso_blend
struct  cso_depth_stencil_alpha
struct  cso_rasterizer
struct  cso_fragment_shader
struct  cso_vertex_shader
struct  cso_sampler

Typedefs

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)

Enumerations

enum  cso_cache_type {
  CSO_BLEND, CSO_SAMPLER, CSO_DEPTH_STENCIL_ALPHA, CSO_RASTERIZER,
  CSO_FRAGMENT_SHADER, CSO_VERTEX_SHADER
}

Functions

unsigned cso_construct_key (void *item, int item_size)
struct cso_cachecso_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)
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_for_each_state (struct cso_cache *sc, enum cso_cache_type type, cso_state_callback func, void *user_data)
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)


Detailed Description

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:

Things that are not constant state objects include:

Author:
Zack Rusin <zack@tungstengraphics.com>

Definition in file cso_cache.h.


Typedef Documentation

typedef void(* cso_sanitize_callback)(struct cso_hash *hash, enum cso_cache_type type, int max_size, void *user_data)

Definition at line 98 of file cso_cache.h.

typedef void(* cso_state_callback)(void *ctx, void *obj)

Definition at line 96 of file cso_cache.h.


Enumeration Type Documentation

enum cso_cache_type

Enumerator:
CSO_BLEND 
CSO_SAMPLER 
CSO_DEPTH_STENCIL_ALPHA 
CSO_RASTERIZER 
CSO_FRAGMENT_SHADER 
CSO_VERTEX_SHADER 

Definition at line 87 of file cso_cache.h.

00087                     {
00088    CSO_BLEND,
00089    CSO_SAMPLER,
00090    CSO_DEPTH_STENCIL_ALPHA,
00091    CSO_RASTERIZER,
00092    CSO_FRAGMENT_SHADER,
00093    CSO_VERTEX_SHADER
00094 };


Function Documentation

struct cso_cache* cso_cache_create ( void   )  [read]

Definition at line 304 of file cso_cache.c.

References cso_cache::blend_hash, cso_hash_create(), cso_cache::depth_stencil_hash, cso_cache::fs_hash, MALLOC_STRUCT, cso_cache::max_size, cso_cache::rasterizer_hash, cso_cache::sampler_hash, sanitize_cb(), cso_cache::sanitize_cb, cso_cache::sanitize_data, and cso_cache::vs_hash.

00306 {
00307    struct cso_cache *sc = MALLOC_STRUCT(cso_cache);
00308    if (sc == NULL)
00309       return NULL;
00310 
00311    sc->max_size           = 4096;
00312    sc->blend_hash         = cso_hash_create();
00313    sc->sampler_hash       = cso_hash_create();
00314    sc->depth_stencil_hash = cso_hash_create();
00315    sc->rasterizer_hash    = cso_hash_create();
00316    sc->fs_hash            = cso_hash_create();
00317    sc->vs_hash            = cso_hash_create();
00318    sc->sanitize_cb        = sanitize_cb;
00319    sc->sanitize_data      = 0;
00320 
00321    return sc;

void cso_cache_delete ( struct cso_cache sc  ) 

Definition at line 360 of file cso_cache.c.

References assert, cso_cache::blend_hash, CSO_BLEND, CSO_DEPTH_STENCIL_ALPHA, cso_for_each_state(), CSO_FRAGMENT_SHADER, cso_hash_delete(), CSO_RASTERIZER, CSO_SAMPLER, CSO_VERTEX_SHADER, delete_blend_state(), delete_depth_stencil_state(), delete_fs_state(), delete_rasterizer_state(), delete_sampler_state(), delete_vs_state(), cso_cache::depth_stencil_hash, FREE, cso_cache::fs_hash, cso_cache::rasterizer_hash, cso_cache::sampler_hash, and cso_cache::vs_hash.

void cso_cache_set_sanitize_callback ( struct cso_cache sc,
cso_sanitize_callback  cb,
void *  user_data 
)

Definition at line 398 of file cso_cache.c.

References cso_cache::sanitize_cb, and cso_cache::sanitize_data.

00402 {
00403    sc->sanitize_cb   = cb;
00404    sc->sanitize_data = user_data;

unsigned cso_construct_key ( void *  item,
int  item_size 
)

Definition at line 82 of file cso_cache.c.

References hash_key().

00084 {
00085    return hash_key((item), item_size);

struct cso_hash_iter cso_find_state ( struct cso_cache sc,
unsigned  hash_key,
enum cso_cache_type  type 
) [read]

Definition at line 254 of file cso_cache.c.

References _cso_hash_for_type(), and cso_hash_find().

00257 {
00258    struct cso_hash *hash = _cso_hash_for_type(sc, type);
00259 
00260    return cso_hash_find(hash, hash_key);

struct cso_hash_iter cso_find_state_template ( struct cso_cache sc,
unsigned  hash_key,
enum cso_cache_type  type,
void *  templ 
) [read]

Definition at line 282 of file cso_cache.c.

References _cso_size_for_type(), cso_find_state(), cso_hash_iter_data(), cso_hash_iter_is_null(), and cso_hash_iter_next().

00286 {
00287    struct cso_hash_iter iter = cso_find_state(sc, hash_key, type);
00288    int size = _cso_size_for_type(type);
00289    while (!cso_hash_iter_is_null(iter)) {
00290       void *iter_data = cso_hash_iter_data(iter);
00291       if (!memcmp(iter_data, templ, size))
00292          return iter;
00293       iter = cso_hash_iter_next(iter);
00294    }
00295    return iter;

void cso_for_each_state ( struct cso_cache sc,
enum cso_cache_type  type,
cso_state_callback  func,
void *  user_data 
)

Definition at line 323 of file cso_cache.c.

References cso_cache::blend_hash, CSO_BLEND, CSO_DEPTH_STENCIL_ALPHA, CSO_FRAGMENT_SHADER, cso_hash_first_node(), cso_hash_iter_data(), cso_hash_iter_is_null(), cso_hash_iter_next(), CSO_RASTERIZER, CSO_SAMPLER, CSO_VERTEX_SHADER, cso_cache::depth_stencil_hash, cso_cache::fs_hash, cso_cache::rasterizer_hash, cso_cache::sampler_hash, and cso_cache::vs_hash.

00326 {
00327    struct cso_hash *hash = 0;
00328    struct cso_hash_iter iter;
00329 
00330    switch (type) {
00331    case CSO_BLEND:
00332       hash = sc->blend_hash;
00333       break;
00334    case CSO_SAMPLER:
00335       hash = sc->sampler_hash;
00336       break;
00337    case CSO_DEPTH_STENCIL_ALPHA:
00338       hash = sc->depth_stencil_hash;
00339       break;
00340    case CSO_RASTERIZER:
00341       hash = sc->rasterizer_hash;
00342       break;
00343    case CSO_FRAGMENT_SHADER:
00344       hash = sc->fs_hash;
00345       break;
00346    case CSO_VERTEX_SHADER:
00347       hash = sc->vs_hash;
00348       break;
00349    }
00350 
00351    iter = cso_hash_first_node(hash);
00352    while (!cso_hash_iter_is_null(iter)) {
00353       void *state = cso_hash_iter_data(iter);
00354       iter = cso_hash_iter_next(iter);
00355       if (state) {
00356          func(state, user_data);
00357       }
00358    }

struct cso_hash_iter cso_insert_state ( struct cso_cache sc,
unsigned  hash_key,
enum cso_cache_type  type,
void *  state 
) [read]

Definition at line 243 of file cso_cache.c.

References _cso_hash_for_type(), cso_hash_insert(), and sanitize_hash().

00247 {
00248    struct cso_hash *hash = _cso_hash_for_type(sc, type);
00249    sanitize_hash(sc, hash, type, sc->max_size);
00250 
00251    return cso_hash_insert(hash, hash_key, state);

int cso_maximum_cache_size ( const struct cso_cache sc  ) 

Definition at line 393 of file cso_cache.c.

References cso_cache::max_size.

00395 {
00396    return sc->max_size;

void cso_set_maximum_cache_size ( struct cso_cache sc,
int  number 
)

Definition at line 380 of file cso_cache.c.

References cso_cache::blend_hash, CSO_BLEND, CSO_DEPTH_STENCIL_ALPHA, CSO_FRAGMENT_SHADER, CSO_RASTERIZER, CSO_SAMPLER, CSO_VERTEX_SHADER, cso_cache::depth_stencil_hash, cso_cache::fs_hash, cso_cache::max_size, cso_cache::rasterizer_hash, cso_cache::sampler_hash, sanitize_hash(), and cso_cache::vs_hash.

void* cso_take_state ( struct cso_cache sc,
unsigned  hash_key,
enum cso_cache_type  type 
)

Definition at line 297 of file cso_cache.c.

References _cso_hash_for_type(), and cso_hash_take().

00300 {
00301    struct cso_hash *hash = _cso_hash_for_type(sc, type);
00302    return cso_hash_take(hash, hash_key);


Generated on Tue Sep 29 06:25:19 2009 for Gallium3D by  doxygen 1.5.4