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
{
225 /* Global Depth Offset Constant/Scale/Clamp */
226 uint32_t dw_depth_offset_const
;
227 uint32_t dw_depth_offset_scale
;
228 uint32_t dw_depth_offset_clamp
;
230 /* Gen8+ 3DSTATE_RASTER */
234 struct ilo_rasterizer_wm
{
237 uint32_t dw_msaa_rast
;
238 uint32_t dw_msaa_disp
;
241 struct ilo_rasterizer_state
{
242 struct pipe_rasterizer_state state
;
244 struct ilo_rasterizer_clip clip
;
245 struct ilo_rasterizer_sf sf
;
246 struct ilo_rasterizer_wm wm
;
249 struct ilo_dsa_state
{
250 /* DEPTH_STENCIL_STATE or Gen8+ 3DSTATE_WM_DEPTH_STENCIL */
253 uint32_t dw_blend_alpha
;
254 uint32_t dw_ps_blend_alpha
;
258 struct ilo_blend_cso
{
263 uint32_t dw_blend_dst_alpha_forced_one
;
266 struct ilo_blend_state
{
267 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
270 bool alpha_to_coverage
;
273 uint32_t dw_alpha_mod
;
276 /* a part of 3DSTATE_PS_BLEND */
277 uint32_t dw_ps_blend
;
278 uint32_t dw_ps_blend_dst_alpha_forced_one
;
281 struct ilo_sampler_cso
{
282 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
283 uint32_t payload
[15];
286 uint32_t dw_filter_aniso
;
289 uint32_t dw_wrap_cube
;
297 struct ilo_sampler_state
{
298 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
301 struct ilo_view_surface
{
303 uint32_t payload
[13];
307 struct ilo_view_cso
{
308 struct pipe_sampler_view base
;
310 struct ilo_view_surface surface
;
313 struct ilo_view_state
{
314 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
318 struct ilo_cbuf_cso
{
319 struct pipe_resource
*resource
;
320 struct ilo_view_surface surface
;
323 * this CSO is not so constant because user buffer needs to be uploaded in
324 * finalize_constant_buffers()
326 const void *user_buffer
;
327 unsigned user_buffer_size
;
330 struct ilo_cbuf_state
{
331 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
332 uint32_t enabled_mask
;
335 struct ilo_resource_state
{
336 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
340 struct ilo_surface_cso
{
341 struct pipe_surface base
;
345 struct ilo_view_surface rt
;
346 struct ilo_zs_surface
{
347 uint32_t payload
[12];
348 uint32_t dw_aligned_8x4
;
351 struct intel_bo
*hiz_bo
;
352 struct intel_bo
*separate_s8_bo
;
357 struct ilo_fb_state
{
358 struct pipe_framebuffer_state state
;
360 struct ilo_view_surface null_rt
;
361 struct ilo_zs_surface null_zs
;
363 struct ilo_fb_blend_caps
{
367 bool dst_alpha_forced_one
;
368 } blend_caps
[PIPE_MAX_COLOR_BUFS
];
370 unsigned num_samples
;
373 struct ilo_global_binding_cso
{
374 struct pipe_resource
*resource
;
379 * In theory, we would like a "virtual" bo that serves as the global memory
380 * region. The virtual bo would reserve a region in the GTT aperture, but the
381 * pages of it would come from those of the global bindings.
383 * The virtual bo would be created in launch_grid(). The global bindings
384 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
385 * be created. The handles returned by set_global_binding() would be offsets
386 * into the virtual bo.
388 * But for now, we will create a SURFACE_STATE for each of the bindings. The
389 * handle of a global binding consists of the offset and the binding table
392 struct ilo_global_binding
{
393 struct util_dynarray bindings
;
397 struct ilo_shader_cso
{
401 struct ilo_state_vector
{
402 const struct pipe_draw_info
*draw
;
406 struct ilo_vb_state vb
;
407 struct ilo_ve_state
*ve
;
408 struct ilo_ib_state ib
;
410 struct ilo_shader_state
*vs
;
411 struct ilo_shader_state
*gs
;
413 struct ilo_so_state so
;
415 struct pipe_clip_state clip
;
416 struct ilo_viewport_state viewport
;
417 struct ilo_scissor_state scissor
;
419 const struct ilo_rasterizer_state
*rasterizer
;
420 struct pipe_poly_stipple poly_stipple
;
421 unsigned sample_mask
;
423 struct ilo_shader_state
*fs
;
425 const struct ilo_dsa_state
*dsa
;
426 struct pipe_stencil_ref stencil_ref
;
427 const struct ilo_blend_state
*blend
;
428 struct pipe_blend_color blend_color
;
429 struct ilo_fb_state fb
;
431 /* shader resources */
432 struct ilo_sampler_state sampler
[PIPE_SHADER_TYPES
];
433 struct ilo_view_state view
[PIPE_SHADER_TYPES
];
434 struct ilo_cbuf_state cbuf
[PIPE_SHADER_TYPES
];
435 struct ilo_resource_state resource
;
438 struct ilo_shader_state
*cs
;
439 struct ilo_resource_state cs_resource
;
440 struct ilo_global_binding global_binding
;
444 ilo_init_state_functions(struct ilo_context
*ilo
);
447 ilo_finalize_3d_states(struct ilo_context
*ilo
,
448 const struct pipe_draw_info
*draw
);
451 ilo_finalize_compute_states(struct ilo_context
*ilo
);
454 ilo_state_vector_init(const struct ilo_dev_info
*dev
,
455 struct ilo_state_vector
*vec
);
458 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
);
461 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
462 struct pipe_resource
*res
);
465 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
);
467 #endif /* ILO_STATE_H */