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 "pipe/p_state.h"
32 #include "util/u_dynarray.h"
34 #include "ilo_common.h"
39 #define ILO_MAX_DRAW_BUFFERS 8
40 #define ILO_MAX_CONST_BUFFERS (1 + 12)
41 #define ILO_MAX_SAMPLER_VIEWS 16
42 #define ILO_MAX_SAMPLERS 16
43 #define ILO_MAX_SO_BINDINGS 64
44 #define ILO_MAX_SO_BUFFERS 4
45 #define ILO_MAX_VIEWPORTS 1
47 #define ILO_MAX_SURFACES 256
50 * States that we track.
52 * XXX Do we want to count each sampler or vertex buffer as a state? If that
53 * is the case, there are simply not enough bits.
55 * XXX We want to treat primitive type and depth clear value as states, but
56 * there are not enough bits.
69 ILO_STATE_POLY_STIPPLE
,
70 ILO_STATE_SAMPLE_MASK
,
73 ILO_STATE_STENCIL_REF
,
75 ILO_STATE_BLEND_COLOR
,
90 ILO_STATE_CS_RESOURCE
,
91 ILO_STATE_GLOBAL_BINDING
,
97 * Dirty flags of the states.
99 enum ilo_dirty_flags
{
100 ILO_DIRTY_VB
= 1 << ILO_STATE_VB
,
101 ILO_DIRTY_VE
= 1 << ILO_STATE_VE
,
102 ILO_DIRTY_IB
= 1 << ILO_STATE_IB
,
103 ILO_DIRTY_VS
= 1 << ILO_STATE_VS
,
104 ILO_DIRTY_GS
= 1 << ILO_STATE_GS
,
105 ILO_DIRTY_SO
= 1 << ILO_STATE_SO
,
106 ILO_DIRTY_CLIP
= 1 << ILO_STATE_CLIP
,
107 ILO_DIRTY_VIEWPORT
= 1 << ILO_STATE_VIEWPORT
,
108 ILO_DIRTY_SCISSOR
= 1 << ILO_STATE_SCISSOR
,
109 ILO_DIRTY_RASTERIZER
= 1 << ILO_STATE_RASTERIZER
,
110 ILO_DIRTY_POLY_STIPPLE
= 1 << ILO_STATE_POLY_STIPPLE
,
111 ILO_DIRTY_SAMPLE_MASK
= 1 << ILO_STATE_SAMPLE_MASK
,
112 ILO_DIRTY_FS
= 1 << ILO_STATE_FS
,
113 ILO_DIRTY_DSA
= 1 << ILO_STATE_DSA
,
114 ILO_DIRTY_STENCIL_REF
= 1 << ILO_STATE_STENCIL_REF
,
115 ILO_DIRTY_BLEND
= 1 << ILO_STATE_BLEND
,
116 ILO_DIRTY_BLEND_COLOR
= 1 << ILO_STATE_BLEND_COLOR
,
117 ILO_DIRTY_FB
= 1 << ILO_STATE_FB
,
118 ILO_DIRTY_SAMPLER_VS
= 1 << ILO_STATE_SAMPLER_VS
,
119 ILO_DIRTY_SAMPLER_GS
= 1 << ILO_STATE_SAMPLER_GS
,
120 ILO_DIRTY_SAMPLER_FS
= 1 << ILO_STATE_SAMPLER_FS
,
121 ILO_DIRTY_SAMPLER_CS
= 1 << ILO_STATE_SAMPLER_CS
,
122 ILO_DIRTY_VIEW_VS
= 1 << ILO_STATE_VIEW_VS
,
123 ILO_DIRTY_VIEW_GS
= 1 << ILO_STATE_VIEW_GS
,
124 ILO_DIRTY_VIEW_FS
= 1 << ILO_STATE_VIEW_FS
,
125 ILO_DIRTY_VIEW_CS
= 1 << ILO_STATE_VIEW_CS
,
126 ILO_DIRTY_CBUF
= 1 << ILO_STATE_CBUF
,
127 ILO_DIRTY_RESOURCE
= 1 << ILO_STATE_RESOURCE
,
128 ILO_DIRTY_CS
= 1 << ILO_STATE_CS
,
129 ILO_DIRTY_CS_RESOURCE
= 1 << ILO_STATE_CS_RESOURCE
,
130 ILO_DIRTY_GLOBAL_BINDING
= 1 << ILO_STATE_GLOBAL_BINDING
,
131 ILO_DIRTY_ALL
= 0xffffffff,
137 struct ilo_shader_state
;
140 struct ilo_vb_state
{
141 struct pipe_vertex_buffer states
[PIPE_MAX_ATTRIBS
];
142 uint32_t enabled_mask
;
145 struct ilo_ib_state
{
146 struct pipe_resource
*buffer
;
147 const void *user_buffer
;
151 /* these are not valid until the state is finalized */
152 struct pipe_resource
*hw_resource
;
153 unsigned hw_index_size
;
154 /* an offset to be added to pipe_draw_info::start */
155 int64_t draw_start_offset
;
159 /* VERTEX_ELEMENT_STATE */
163 struct ilo_ve_state
{
164 struct ilo_ve_cso cso
[PIPE_MAX_ATTRIBS
];
167 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
168 unsigned vb_mapping
[PIPE_MAX_ATTRIBS
];
171 /* these are not valid until the state is finalized */
172 struct ilo_ve_cso edgeflag_cso
;
173 bool last_cso_edgeflag
;
175 struct ilo_ve_cso nosrc_cso
;
176 bool prepend_nosrc_cso
;
179 struct ilo_so_state
{
180 struct pipe_stream_output_target
*states
[ILO_MAX_SO_BUFFERS
];
182 unsigned append_bitmask
;
187 struct ilo_viewport_cso
{
189 float m00
, m11
, m22
, m30
, m31
, m32
;
191 /* guardband in NDC space */
192 float min_gbx
, min_gby
, max_gbx
, max_gby
;
194 /* viewport in screen space */
195 float min_x
, min_y
, min_z
;
196 float max_x
, max_y
, max_z
;
199 struct ilo_viewport_state
{
200 struct ilo_viewport_cso cso
[ILO_MAX_VIEWPORTS
];
203 struct pipe_viewport_state viewport0
;
206 struct ilo_scissor_state
{
208 uint32_t payload
[ILO_MAX_VIEWPORTS
* 2];
210 struct pipe_scissor_state scissor0
;
213 struct ilo_rasterizer_clip
{
217 uint32_t can_enable_guardband
;
220 struct ilo_rasterizer_sf
{
226 struct ilo_rasterizer_wm
{
229 uint32_t dw_msaa_rast
;
230 uint32_t dw_msaa_disp
;
233 struct ilo_rasterizer_state
{
234 struct pipe_rasterizer_state state
;
236 struct ilo_rasterizer_clip clip
;
237 struct ilo_rasterizer_sf sf
;
238 struct ilo_rasterizer_wm wm
;
241 struct ilo_dsa_state
{
242 /* DEPTH_STENCIL_STATE */
249 struct ilo_blend_cso
{
254 uint32_t dw_blend_dst_alpha_forced_one
;
257 uint32_t dw_alpha_mod
;
260 struct ilo_blend_state
{
261 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
263 bool independent_blend_enable
;
265 bool alpha_to_coverage
;
268 struct ilo_sampler_cso
{
269 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
270 uint32_t payload
[15];
273 uint32_t dw_filter_aniso
;
276 uint32_t dw_wrap_cube
;
284 struct ilo_sampler_state
{
285 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
288 struct ilo_view_surface
{
294 struct ilo_view_cso
{
295 struct pipe_sampler_view base
;
297 struct ilo_view_surface surface
;
300 struct ilo_view_state
{
301 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
305 struct ilo_cbuf_cso
{
306 struct pipe_resource
*resource
;
307 struct ilo_view_surface surface
;
310 * this CSO is not so constant because user buffer needs to be uploaded in
311 * finalize_constant_buffers()
313 const void *user_buffer
;
314 unsigned user_buffer_size
;
317 struct ilo_cbuf_state
{
318 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
319 uint32_t enabled_mask
;
322 struct ilo_resource_state
{
323 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
327 struct ilo_surface_cso
{
328 struct pipe_surface base
;
332 struct ilo_view_surface rt
;
333 struct ilo_zs_surface
{
334 uint32_t payload
[10];
335 uint32_t dw_aligned_8x4
;
338 struct intel_bo
*hiz_bo
;
339 struct intel_bo
*separate_s8_bo
;
344 struct ilo_fb_state
{
345 struct pipe_framebuffer_state state
;
347 struct ilo_view_surface null_rt
;
348 struct ilo_zs_surface null_zs
;
350 unsigned num_samples
;
353 struct ilo_global_binding_cso
{
354 struct pipe_resource
*resource
;
359 * In theory, we would like a "virtual" bo that serves as the global memory
360 * region. The virtual bo would reserve a region in the GTT aperture, but the
361 * pages of it would come from those of the global bindings.
363 * The virtual bo would be created in launch_grid(). The global bindings
364 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
365 * be created. The handles returned by set_global_binding() would be offsets
366 * into the virtual bo.
368 * But for now, we will create a SURFACE_STATE for each of the bindings. The
369 * handle of a global binding consists of the offset and the binding table
372 struct ilo_global_binding
{
373 struct util_dynarray bindings
;
377 struct ilo_shader_cso
{
381 struct ilo_state_vector
{
382 const struct pipe_draw_info
*draw
;
386 struct ilo_vb_state vb
;
387 struct ilo_ve_state
*ve
;
388 struct ilo_ib_state ib
;
390 struct ilo_shader_state
*vs
;
391 struct ilo_shader_state
*gs
;
393 struct ilo_so_state so
;
395 struct pipe_clip_state clip
;
396 struct ilo_viewport_state viewport
;
397 struct ilo_scissor_state scissor
;
399 const struct ilo_rasterizer_state
*rasterizer
;
400 struct pipe_poly_stipple poly_stipple
;
401 unsigned sample_mask
;
403 struct ilo_shader_state
*fs
;
405 const struct ilo_dsa_state
*dsa
;
406 struct pipe_stencil_ref stencil_ref
;
407 const struct ilo_blend_state
*blend
;
408 struct pipe_blend_color blend_color
;
409 struct ilo_fb_state fb
;
411 /* shader resources */
412 struct ilo_sampler_state sampler
[PIPE_SHADER_TYPES
];
413 struct ilo_view_state view
[PIPE_SHADER_TYPES
];
414 struct ilo_cbuf_state cbuf
[PIPE_SHADER_TYPES
];
415 struct ilo_resource_state resource
;
418 struct ilo_shader_state
*cs
;
419 struct ilo_resource_state cs_resource
;
420 struct ilo_global_binding global_binding
;
424 ilo_init_state_functions(struct ilo_context
*ilo
);
427 ilo_finalize_3d_states(struct ilo_context
*ilo
,
428 const struct pipe_draw_info
*draw
);
431 ilo_finalize_compute_states(struct ilo_context
*ilo
);
434 ilo_state_vector_init(const struct ilo_dev_info
*dev
,
435 struct ilo_state_vector
*vec
);
438 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
);
441 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
442 struct pipe_resource
*res
);
445 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
);
447 #endif /* ILO_STATE_H */