1 /**************************************************************************
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Constant State Object (CSO) cache.
32 * The basic idea is that the states are created via the
33 * create_state/bind_state/delete_state semantics. The driver is expected to
34 * perform as much of the Gallium state translation to whatever its internal
35 * representation is during the create call. Gallium then has a caching
36 * mechanism where it stores the created states. When the pipeline needs an
37 * actual state change, a bind call is issued. In the bind call the driver
38 * gets its already translated representation.
40 * Those semantics mean that the driver doesn't do the repeated translations
41 * of states on every frame, but only once, when a new state is actually
44 * Even on hardware that doesn't do any kind of state cache, it makes the
45 * driver look a lot neater, plus it avoids all the redundant state
46 * translations on every frame.
48 * Currently our constant state objects are:
53 * - rasterizer (old setup)
58 * Things that are not constant state objects include:
70 * @author Zack Rusin <zack@tungstengraphics.com>
76 #include "pipe/p_context.h"
77 #include "pipe/p_state.h"
79 /* cso_hash.h is necessary for cso_hash_iter, as MSVC requires structures
80 * returned by value to be fully defined */
91 CSO_DEPTH_STENCIL_ALPHA
,
99 typedef void (*cso_state_callback
)(void *ctx
, void *obj
);
101 typedef void (*cso_sanitize_callback
)(struct cso_hash
*hash
,
102 enum cso_cache_type type
,
109 struct pipe_blend_state state
;
111 cso_state_callback delete_state
;
112 struct pipe_context
*context
;
115 struct cso_depth_stencil_alpha
{
116 struct pipe_depth_stencil_alpha_state state
;
118 cso_state_callback delete_state
;
119 struct pipe_context
*context
;
122 struct cso_rasterizer
{
123 struct pipe_rasterizer_state state
;
125 cso_state_callback delete_state
;
126 struct pipe_context
*context
;
129 struct cso_fragment_shader
{
130 struct pipe_shader_state state
;
132 cso_state_callback delete_state
;
133 struct pipe_context
*context
;
136 struct cso_vertex_shader
{
137 struct pipe_shader_state state
;
139 cso_state_callback delete_state
;
140 struct pipe_context
*context
;
144 struct pipe_sampler_state state
;
146 cso_state_callback delete_state
;
147 struct pipe_context
*context
;
150 struct cso_velems_state
{
152 struct pipe_vertex_element velems
[PIPE_MAX_ATTRIBS
];
155 struct cso_velements
{
156 struct cso_velems_state state
;
158 cso_state_callback delete_state
;
159 struct pipe_context
*context
;
162 unsigned cso_construct_key(void *item
, int item_size
);
164 struct cso_cache
*cso_cache_create(void);
165 void cso_cache_delete(struct cso_cache
*sc
);
167 void cso_cache_set_sanitize_callback(struct cso_cache
*sc
,
168 cso_sanitize_callback cb
,
171 struct cso_hash_iter
cso_insert_state(struct cso_cache
*sc
,
172 unsigned hash_key
, enum cso_cache_type type
,
174 struct cso_hash_iter
cso_find_state(struct cso_cache
*sc
,
175 unsigned hash_key
, enum cso_cache_type type
);
176 struct cso_hash_iter
cso_find_state_template(struct cso_cache
*sc
,
177 unsigned hash_key
, enum cso_cache_type type
,
178 void *templ
, unsigned size
);
179 void cso_for_each_state(struct cso_cache
*sc
, enum cso_cache_type type
,
180 cso_state_callback func
, void *user_data
);
181 void * cso_take_state(struct cso_cache
*sc
, unsigned hash_key
,
182 enum cso_cache_type type
);
184 void cso_set_maximum_cache_size(struct cso_cache
*sc
, int number
);
185 int cso_maximum_cache_size(const struct cso_cache
*sc
);