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 "core/ilo_state_sampler.h"
33 #include "core/ilo_state_surface.h"
34 #include "core/ilo_state_viewport.h"
35 #include "core/ilo_state_zs.h"
36 #include "pipe/p_state.h"
37 #include "util/u_dynarray.h"
39 #include "ilo_common.h"
42 * States that we track.
44 * XXX Do we want to count each sampler or vertex buffer as a state? If that
45 * is the case, there are simply not enough bits.
47 * XXX We want to treat primitive type and depth clear value as states, but
48 * there are not enough bits.
61 ILO_STATE_POLY_STIPPLE
,
62 ILO_STATE_SAMPLE_MASK
,
65 ILO_STATE_STENCIL_REF
,
67 ILO_STATE_BLEND_COLOR
,
82 ILO_STATE_CS_RESOURCE
,
83 ILO_STATE_GLOBAL_BINDING
,
89 * Dirty flags of the states.
91 enum ilo_dirty_flags
{
92 ILO_DIRTY_VB
= 1 << ILO_STATE_VB
,
93 ILO_DIRTY_VE
= 1 << ILO_STATE_VE
,
94 ILO_DIRTY_IB
= 1 << ILO_STATE_IB
,
95 ILO_DIRTY_VS
= 1 << ILO_STATE_VS
,
96 ILO_DIRTY_GS
= 1 << ILO_STATE_GS
,
97 ILO_DIRTY_SO
= 1 << ILO_STATE_SO
,
98 ILO_DIRTY_CLIP
= 1 << ILO_STATE_CLIP
,
99 ILO_DIRTY_VIEWPORT
= 1 << ILO_STATE_VIEWPORT
,
100 ILO_DIRTY_SCISSOR
= 1 << ILO_STATE_SCISSOR
,
101 ILO_DIRTY_RASTERIZER
= 1 << ILO_STATE_RASTERIZER
,
102 ILO_DIRTY_POLY_STIPPLE
= 1 << ILO_STATE_POLY_STIPPLE
,
103 ILO_DIRTY_SAMPLE_MASK
= 1 << ILO_STATE_SAMPLE_MASK
,
104 ILO_DIRTY_FS
= 1 << ILO_STATE_FS
,
105 ILO_DIRTY_DSA
= 1 << ILO_STATE_DSA
,
106 ILO_DIRTY_STENCIL_REF
= 1 << ILO_STATE_STENCIL_REF
,
107 ILO_DIRTY_BLEND
= 1 << ILO_STATE_BLEND
,
108 ILO_DIRTY_BLEND_COLOR
= 1 << ILO_STATE_BLEND_COLOR
,
109 ILO_DIRTY_FB
= 1 << ILO_STATE_FB
,
110 ILO_DIRTY_SAMPLER_VS
= 1 << ILO_STATE_SAMPLER_VS
,
111 ILO_DIRTY_SAMPLER_GS
= 1 << ILO_STATE_SAMPLER_GS
,
112 ILO_DIRTY_SAMPLER_FS
= 1 << ILO_STATE_SAMPLER_FS
,
113 ILO_DIRTY_SAMPLER_CS
= 1 << ILO_STATE_SAMPLER_CS
,
114 ILO_DIRTY_VIEW_VS
= 1 << ILO_STATE_VIEW_VS
,
115 ILO_DIRTY_VIEW_GS
= 1 << ILO_STATE_VIEW_GS
,
116 ILO_DIRTY_VIEW_FS
= 1 << ILO_STATE_VIEW_FS
,
117 ILO_DIRTY_VIEW_CS
= 1 << ILO_STATE_VIEW_CS
,
118 ILO_DIRTY_CBUF
= 1 << ILO_STATE_CBUF
,
119 ILO_DIRTY_RESOURCE
= 1 << ILO_STATE_RESOURCE
,
120 ILO_DIRTY_CS
= 1 << ILO_STATE_CS
,
121 ILO_DIRTY_CS_RESOURCE
= 1 << ILO_STATE_CS_RESOURCE
,
122 ILO_DIRTY_GLOBAL_BINDING
= 1 << ILO_STATE_GLOBAL_BINDING
,
123 ILO_DIRTY_ALL
= 0xffffffff,
128 struct ilo_cbuf_cso
{
129 struct pipe_resource
*resource
;
130 struct ilo_state_surface_buffer_info info
;
131 struct ilo_state_surface surface
;
134 * this CSO is not so constant because user buffer needs to be uploaded in
135 * finalize_constant_buffers()
137 const void *user_buffer
;
140 struct ilo_sampler_cso
{
141 struct ilo_state_sampler sampler
;
142 struct ilo_state_sampler_border border
;
148 struct ilo_sampler_state
{
149 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
152 struct ilo_cbuf_state
{
153 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
154 uint32_t enabled_mask
;
157 struct ilo_resource_state
{
158 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
162 struct ilo_view_cso
{
163 struct pipe_sampler_view base
;
165 struct ilo_state_surface surface
;
168 struct ilo_view_state
{
169 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
173 struct ilo_viewport_state
{
174 struct ilo_state_viewport_matrix_info matrices
[ILO_MAX_VIEWPORTS
];
175 struct ilo_state_viewport_scissor_info scissors
[ILO_MAX_VIEWPORTS
];
176 struct ilo_state_viewport_params_info params
;
178 struct pipe_viewport_state viewport0
;
179 struct pipe_scissor_state scissor0
;
181 struct ilo_state_viewport vp
;
182 uint32_t vp_data
[20 * ILO_MAX_VIEWPORTS
];
185 struct ilo_global_binding_cso
{
186 struct pipe_resource
*resource
;
191 * In theory, we would like a "virtual" bo that serves as the global memory
192 * region. The virtual bo would reserve a region in the GTT aperture, but the
193 * pages of it would come from those of the global bindings.
195 * The virtual bo would be created in launch_grid(). The global bindings
196 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
197 * be created. The handles returned by set_global_binding() would be offsets
198 * into the virtual bo.
200 * But for now, we will create a SURFACE_STATE for each of the bindings. The
201 * handle of a global binding consists of the offset and the binding table
204 struct ilo_global_binding
{
205 struct util_dynarray bindings
;
209 struct ilo_state_vector
{
210 const struct pipe_draw_info
*draw
;
214 struct ilo_vb_state vb
;
215 struct ilo_ve_state
*ve
;
216 struct ilo_ib_state ib
;
218 struct ilo_shader_state
*vs
;
219 struct ilo_shader_state
*gs
;
221 struct ilo_so_state so
;
223 struct pipe_clip_state clip
;
225 struct ilo_viewport_state viewport
;
227 const struct ilo_rasterizer_state
*rasterizer
;
228 struct pipe_poly_stipple poly_stipple
;
229 unsigned sample_mask
;
231 struct ilo_shader_state
*fs
;
233 const struct ilo_dsa_state
*dsa
;
234 struct pipe_stencil_ref stencil_ref
;
235 const struct ilo_blend_state
*blend
;
236 struct pipe_blend_color blend_color
;
237 struct ilo_fb_state fb
;
239 /* shader resources */
240 struct ilo_sampler_state sampler
[PIPE_SHADER_TYPES
];
241 struct ilo_view_state view
[PIPE_SHADER_TYPES
];
242 struct ilo_cbuf_state cbuf
[PIPE_SHADER_TYPES
];
243 struct ilo_resource_state resource
;
245 struct ilo_state_sampler disabled_sampler
;
248 struct ilo_shader_state
*cs
;
249 struct ilo_resource_state cs_resource
;
250 struct ilo_global_binding global_binding
;
254 ilo_init_state_functions(struct ilo_context
*ilo
);
257 ilo_finalize_3d_states(struct ilo_context
*ilo
,
258 const struct pipe_draw_info
*draw
);
261 ilo_finalize_compute_states(struct ilo_context
*ilo
);
264 ilo_state_vector_init(const struct ilo_dev
*dev
,
265 struct ilo_state_vector
*vec
);
268 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
);
271 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
272 struct pipe_resource
*res
);
275 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
);
277 #endif /* ILO_STATE_H */