116e2eaa2c8e13a9c1576c5266049fc539368978
[mesa.git] / src / gallium / aux / cso_cache / cso_cache.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Zack Rusin <zack@tungstengraphics.com>
31 */
32
33 #ifndef CSO_CACHE_H
34 #define CSO_CACHE_H
35
36 #include "pipe/p_context.h"
37 #include "pipe/p_state.h"
38
39
40 struct cso_hash;
41
42 struct cso_cache {
43 struct cso_hash *blend_hash;
44 struct cso_hash *depth_stencil_hash;
45 struct cso_hash *fs_hash;
46 struct cso_hash *vs_hash;
47 struct cso_hash *rasterizer_hash;
48 struct cso_hash *sampler_hash;
49 };
50
51 struct cso_blend {
52 struct pipe_blend_state state;
53 void *data;
54 };
55
56 struct cso_depth_stencil_alpha {
57 struct pipe_depth_stencil_alpha_state state;
58 void *data;
59 };
60
61 struct cso_rasterizer {
62 struct pipe_rasterizer_state state;
63 void *data;
64 };
65
66 struct cso_fragment_shader {
67 struct pipe_shader_state state;
68 void *data;
69 };
70
71 struct cso_vertex_shader {
72 struct pipe_shader_state state;
73 void *data;
74 };
75
76 struct cso_sampler {
77 struct pipe_sampler_state state;
78 void *data;
79 };
80
81
82 enum cso_cache_type {
83 CSO_BLEND,
84 CSO_SAMPLER,
85 CSO_DEPTH_STENCIL_ALPHA,
86 CSO_RASTERIZER,
87 CSO_FRAGMENT_SHADER,
88 CSO_VERTEX_SHADER
89 };
90
91 unsigned cso_construct_key(void *item, int item_size);
92
93 struct cso_cache *cso_cache_create(void);
94 void cso_cache_delete(struct cso_cache *sc);
95
96 struct cso_hash_iter cso_insert_state(struct cso_cache *sc,
97 unsigned hash_key, enum cso_cache_type type,
98 void *state);
99 struct cso_hash_iter cso_find_state(struct cso_cache *sc,
100 unsigned hash_key, enum cso_cache_type type);
101 struct cso_hash_iter cso_find_state_template(struct cso_cache *sc,
102 unsigned hash_key, enum cso_cache_type type,
103 void *templ);
104 void * cso_take_state(struct cso_cache *sc, unsigned hash_key,
105 enum cso_cache_type type);
106
107 #endif