2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
31 #include "core/ilo_state_3d.h"
32 #include "pipe/p_state.h"
33 #include "util/u_dynarray.h"
35 #include "ilo_common.h"
38 * States that we track.
40 * XXX Do we want to count each sampler or vertex buffer as a state? If that
41 * is the case, there are simply not enough bits.
43 * XXX We want to treat primitive type and depth clear value as states, but
44 * there are not enough bits.
57 ILO_STATE_POLY_STIPPLE
,
58 ILO_STATE_SAMPLE_MASK
,
61 ILO_STATE_STENCIL_REF
,
63 ILO_STATE_BLEND_COLOR
,
78 ILO_STATE_CS_RESOURCE
,
79 ILO_STATE_GLOBAL_BINDING
,
85 * Dirty flags of the states.
87 enum ilo_dirty_flags
{
88 ILO_DIRTY_VB
= 1 << ILO_STATE_VB
,
89 ILO_DIRTY_VE
= 1 << ILO_STATE_VE
,
90 ILO_DIRTY_IB
= 1 << ILO_STATE_IB
,
91 ILO_DIRTY_VS
= 1 << ILO_STATE_VS
,
92 ILO_DIRTY_GS
= 1 << ILO_STATE_GS
,
93 ILO_DIRTY_SO
= 1 << ILO_STATE_SO
,
94 ILO_DIRTY_CLIP
= 1 << ILO_STATE_CLIP
,
95 ILO_DIRTY_VIEWPORT
= 1 << ILO_STATE_VIEWPORT
,
96 ILO_DIRTY_SCISSOR
= 1 << ILO_STATE_SCISSOR
,
97 ILO_DIRTY_RASTERIZER
= 1 << ILO_STATE_RASTERIZER
,
98 ILO_DIRTY_POLY_STIPPLE
= 1 << ILO_STATE_POLY_STIPPLE
,
99 ILO_DIRTY_SAMPLE_MASK
= 1 << ILO_STATE_SAMPLE_MASK
,
100 ILO_DIRTY_FS
= 1 << ILO_STATE_FS
,
101 ILO_DIRTY_DSA
= 1 << ILO_STATE_DSA
,
102 ILO_DIRTY_STENCIL_REF
= 1 << ILO_STATE_STENCIL_REF
,
103 ILO_DIRTY_BLEND
= 1 << ILO_STATE_BLEND
,
104 ILO_DIRTY_BLEND_COLOR
= 1 << ILO_STATE_BLEND_COLOR
,
105 ILO_DIRTY_FB
= 1 << ILO_STATE_FB
,
106 ILO_DIRTY_SAMPLER_VS
= 1 << ILO_STATE_SAMPLER_VS
,
107 ILO_DIRTY_SAMPLER_GS
= 1 << ILO_STATE_SAMPLER_GS
,
108 ILO_DIRTY_SAMPLER_FS
= 1 << ILO_STATE_SAMPLER_FS
,
109 ILO_DIRTY_SAMPLER_CS
= 1 << ILO_STATE_SAMPLER_CS
,
110 ILO_DIRTY_VIEW_VS
= 1 << ILO_STATE_VIEW_VS
,
111 ILO_DIRTY_VIEW_GS
= 1 << ILO_STATE_VIEW_GS
,
112 ILO_DIRTY_VIEW_FS
= 1 << ILO_STATE_VIEW_FS
,
113 ILO_DIRTY_VIEW_CS
= 1 << ILO_STATE_VIEW_CS
,
114 ILO_DIRTY_CBUF
= 1 << ILO_STATE_CBUF
,
115 ILO_DIRTY_RESOURCE
= 1 << ILO_STATE_RESOURCE
,
116 ILO_DIRTY_CS
= 1 << ILO_STATE_CS
,
117 ILO_DIRTY_CS_RESOURCE
= 1 << ILO_STATE_CS_RESOURCE
,
118 ILO_DIRTY_GLOBAL_BINDING
= 1 << ILO_STATE_GLOBAL_BINDING
,
119 ILO_DIRTY_ALL
= 0xffffffff,
124 struct ilo_global_binding_cso
{
125 struct pipe_resource
*resource
;
130 * In theory, we would like a "virtual" bo that serves as the global memory
131 * region. The virtual bo would reserve a region in the GTT aperture, but the
132 * pages of it would come from those of the global bindings.
134 * The virtual bo would be created in launch_grid(). The global bindings
135 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
136 * be created. The handles returned by set_global_binding() would be offsets
137 * into the virtual bo.
139 * But for now, we will create a SURFACE_STATE for each of the bindings. The
140 * handle of a global binding consists of the offset and the binding table
143 struct ilo_global_binding
{
144 struct util_dynarray bindings
;
148 struct ilo_state_vector
{
149 const struct pipe_draw_info
*draw
;
153 struct ilo_vb_state vb
;
154 struct ilo_ve_state
*ve
;
155 struct ilo_ib_state ib
;
157 struct ilo_shader_state
*vs
;
158 struct ilo_shader_state
*gs
;
160 struct ilo_so_state so
;
162 struct pipe_clip_state clip
;
163 struct ilo_viewport_state viewport
;
164 struct ilo_scissor_state scissor
;
166 const struct ilo_rasterizer_state
*rasterizer
;
167 struct pipe_poly_stipple poly_stipple
;
168 unsigned sample_mask
;
170 struct ilo_shader_state
*fs
;
172 const struct ilo_dsa_state
*dsa
;
173 struct pipe_stencil_ref stencil_ref
;
174 const struct ilo_blend_state
*blend
;
175 struct pipe_blend_color blend_color
;
176 struct ilo_fb_state fb
;
178 /* shader resources */
179 struct ilo_sampler_state sampler
[PIPE_SHADER_TYPES
];
180 struct ilo_view_state view
[PIPE_SHADER_TYPES
];
181 struct ilo_cbuf_state cbuf
[PIPE_SHADER_TYPES
];
182 struct ilo_resource_state resource
;
185 struct ilo_shader_state
*cs
;
186 struct ilo_resource_state cs_resource
;
187 struct ilo_global_binding global_binding
;
191 ilo_init_state_functions(struct ilo_context
*ilo
);
194 ilo_finalize_3d_states(struct ilo_context
*ilo
,
195 const struct pipe_draw_info
*draw
);
198 ilo_finalize_compute_states(struct ilo_context
*ilo
);
201 ilo_state_vector_init(const struct ilo_dev
*dev
,
202 struct ilo_state_vector
*vec
);
205 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
);
208 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
209 struct pipe_resource
*res
);
212 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
);
214 #endif /* ILO_STATE_H */