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"
33 #include "ilo_common.h"
38 #define ILO_MAX_DRAW_BUFFERS 8
39 #define ILO_MAX_CONST_BUFFERS (1 + 12)
40 #define ILO_MAX_SAMPLER_VIEWS 16
41 #define ILO_MAX_SAMPLERS 16
42 #define ILO_MAX_SO_BINDINGS 64
43 #define ILO_MAX_SO_BUFFERS 4
44 #define ILO_MAX_VIEWPORTS 1
46 #define ILO_MAX_VS_SURFACES (ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
47 #define ILO_VS_CONST_SURFACE(i) (i)
48 #define ILO_VS_TEXTURE_SURFACE(i) (ILO_MAX_CONST_BUFFERS + i)
50 #define ILO_MAX_GS_SURFACES (ILO_MAX_SO_BINDINGS)
51 #define ILO_GS_SO_SURFACE(i) (i)
53 #define ILO_MAX_WM_SURFACES (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
54 #define ILO_WM_DRAW_SURFACE(i) (i)
55 #define ILO_WM_CONST_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + i)
56 #define ILO_WM_TEXTURE_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + i)
59 * States that we track.
61 * XXX Do we want to count each sampler or vertex buffer as a state? If that
62 * is the case, there are simply not enough bits.
64 * XXX We want to treat primitive type and depth clear value as states, but
65 * there are not enough bits.
78 ILO_STATE_POLY_STIPPLE
,
79 ILO_STATE_SAMPLE_MASK
,
82 ILO_STATE_STENCIL_REF
,
84 ILO_STATE_BLEND_COLOR
,
99 ILO_STATE_CS_RESOURCE
,
100 ILO_STATE_GLOBAL_BINDING
,
106 * Dirty flags of the states.
108 enum ilo_dirty_flags
{
109 ILO_DIRTY_VB
= 1 << ILO_STATE_VB
,
110 ILO_DIRTY_VE
= 1 << ILO_STATE_VE
,
111 ILO_DIRTY_IB
= 1 << ILO_STATE_IB
,
112 ILO_DIRTY_VS
= 1 << ILO_STATE_VS
,
113 ILO_DIRTY_GS
= 1 << ILO_STATE_GS
,
114 ILO_DIRTY_SO
= 1 << ILO_STATE_SO
,
115 ILO_DIRTY_CLIP
= 1 << ILO_STATE_CLIP
,
116 ILO_DIRTY_VIEWPORT
= 1 << ILO_STATE_VIEWPORT
,
117 ILO_DIRTY_SCISSOR
= 1 << ILO_STATE_SCISSOR
,
118 ILO_DIRTY_RASTERIZER
= 1 << ILO_STATE_RASTERIZER
,
119 ILO_DIRTY_POLY_STIPPLE
= 1 << ILO_STATE_POLY_STIPPLE
,
120 ILO_DIRTY_SAMPLE_MASK
= 1 << ILO_STATE_SAMPLE_MASK
,
121 ILO_DIRTY_FS
= 1 << ILO_STATE_FS
,
122 ILO_DIRTY_DSA
= 1 << ILO_STATE_DSA
,
123 ILO_DIRTY_STENCIL_REF
= 1 << ILO_STATE_STENCIL_REF
,
124 ILO_DIRTY_BLEND
= 1 << ILO_STATE_BLEND
,
125 ILO_DIRTY_BLEND_COLOR
= 1 << ILO_STATE_BLEND_COLOR
,
126 ILO_DIRTY_FB
= 1 << ILO_STATE_FB
,
127 ILO_DIRTY_SAMPLER_VS
= 1 << ILO_STATE_SAMPLER_VS
,
128 ILO_DIRTY_SAMPLER_GS
= 1 << ILO_STATE_SAMPLER_GS
,
129 ILO_DIRTY_SAMPLER_FS
= 1 << ILO_STATE_SAMPLER_FS
,
130 ILO_DIRTY_SAMPLER_CS
= 1 << ILO_STATE_SAMPLER_CS
,
131 ILO_DIRTY_VIEW_VS
= 1 << ILO_STATE_VIEW_VS
,
132 ILO_DIRTY_VIEW_GS
= 1 << ILO_STATE_VIEW_GS
,
133 ILO_DIRTY_VIEW_FS
= 1 << ILO_STATE_VIEW_FS
,
134 ILO_DIRTY_VIEW_CS
= 1 << ILO_STATE_VIEW_CS
,
135 ILO_DIRTY_CBUF
= 1 << ILO_STATE_CBUF
,
136 ILO_DIRTY_RESOURCE
= 1 << ILO_STATE_RESOURCE
,
137 ILO_DIRTY_CS
= 1 << ILO_STATE_CS
,
138 ILO_DIRTY_CS_RESOURCE
= 1 << ILO_STATE_CS_RESOURCE
,
139 ILO_DIRTY_GLOBAL_BINDING
= 1 << ILO_STATE_GLOBAL_BINDING
,
140 ILO_DIRTY_ALL
= 0xffffffff,
146 struct ilo_shader_state
;
149 struct ilo_vb_state
{
150 struct pipe_vertex_buffer states
[PIPE_MAX_ATTRIBS
];
151 uint32_t enabled_mask
;
154 struct ilo_ib_state
{
155 struct pipe_resource
*buffer
;
156 const void *user_buffer
;
160 /* these are not valid until the state is finalized */
161 struct pipe_resource
*hw_resource
;
162 unsigned hw_index_size
;
163 /* an offset to be added to pipe_draw_info::start */
164 int64_t draw_start_offset
;
168 /* VERTEX_ELEMENT_STATE */
172 struct ilo_ve_state
{
173 struct ilo_ve_cso cso
[PIPE_MAX_ATTRIBS
];
176 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
177 unsigned vb_mapping
[PIPE_MAX_ATTRIBS
];
180 /* these are not valid until the state is finalized */
181 struct ilo_ve_cso edgeflag_cso
;
182 bool last_cso_edgeflag
;
184 struct ilo_ve_cso nosrc_cso
;
185 bool prepend_nosrc_cso
;
188 struct ilo_so_state
{
189 struct pipe_stream_output_target
*states
[ILO_MAX_SO_BUFFERS
];
191 unsigned append_bitmask
;
196 struct ilo_viewport_cso
{
198 float m00
, m11
, m22
, m30
, m31
, m32
;
200 /* guardband in NDC space */
201 float min_gbx
, min_gby
, max_gbx
, max_gby
;
203 /* viewport in screen space */
204 float min_x
, min_y
, min_z
;
205 float max_x
, max_y
, max_z
;
208 struct ilo_viewport_state
{
209 struct ilo_viewport_cso cso
[ILO_MAX_VIEWPORTS
];
212 struct pipe_viewport_state viewport0
;
215 struct ilo_scissor_state
{
217 uint32_t payload
[ILO_MAX_VIEWPORTS
* 2];
219 struct pipe_scissor_state scissor0
;
222 struct ilo_rasterizer_clip
{
226 uint32_t can_enable_guardband
;
229 struct ilo_rasterizer_sf
{
235 struct ilo_rasterizer_wm
{
238 uint32_t dw_msaa_rast
;
239 uint32_t dw_msaa_disp
;
242 struct ilo_rasterizer_state
{
243 struct pipe_rasterizer_state state
;
245 struct ilo_rasterizer_clip clip
;
246 struct ilo_rasterizer_sf sf
;
247 struct ilo_rasterizer_wm wm
;
250 struct ilo_dsa_state
{
251 /* DEPTH_STENCIL_STATE */
258 struct ilo_blend_cso
{
263 uint32_t dw_blend_dst_alpha_forced_one
;
266 uint32_t dw_alpha_mod
;
269 struct ilo_blend_state
{
270 struct ilo_blend_cso cso
[ILO_MAX_DRAW_BUFFERS
];
272 bool independent_blend_enable
;
274 bool alpha_to_coverage
;
277 struct ilo_sampler_cso
{
278 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
279 uint32_t payload
[15];
282 uint32_t dw_filter_aniso
;
285 uint32_t dw_wrap_cube
;
293 struct ilo_sampler_state
{
294 const struct ilo_sampler_cso
*cso
[ILO_MAX_SAMPLERS
];
298 struct ilo_view_surface
{
304 struct ilo_view_cso
{
305 struct pipe_sampler_view base
;
307 struct ilo_view_surface surface
;
310 struct ilo_view_state
{
311 struct pipe_sampler_view
*states
[ILO_MAX_SAMPLER_VIEWS
];
315 struct ilo_cbuf_cso
{
316 struct pipe_resource
*resource
;
317 struct ilo_view_surface surface
;
320 * this CSO is not so constant because user buffer needs to be uploaded in
321 * finalize_constant_buffers()
323 const void *user_buffer
;
324 unsigned user_buffer_size
;
327 struct ilo_cbuf_state
{
328 struct ilo_cbuf_cso cso
[ILO_MAX_CONST_BUFFERS
];
329 uint32_t enabled_mask
;
332 struct ilo_resource_state
{
333 struct pipe_surface
*states
[PIPE_MAX_SHADER_RESOURCES
];
337 struct ilo_surface_cso
{
338 struct pipe_surface base
;
342 struct ilo_view_surface rt
;
343 struct ilo_zs_surface
{
344 uint32_t payload
[10];
345 uint32_t dw_aligned_8x4
;
348 struct intel_bo
*hiz_bo
;
349 struct intel_bo
*separate_s8_bo
;
354 struct ilo_fb_state
{
355 struct pipe_framebuffer_state state
;
357 struct ilo_view_surface null_rt
;
358 struct ilo_zs_surface null_zs
;
360 unsigned num_samples
;
363 struct ilo_global_binding
{
365 * XXX These should not be treated as real resources (and there could be
366 * thousands of them). They should be treated as regions in GLOBAL
367 * resource, which is the only real resource.
369 * That is, a resource here should instead be
371 * struct ilo_global_region {
372 * struct pipe_resource base;
377 * and it describes the region [offset, offset + size) in GLOBAL
380 struct pipe_resource
*resources
[PIPE_MAX_SHADER_RESOURCES
];
381 uint32_t *handles
[PIPE_MAX_SHADER_RESOURCES
];
385 struct ilo_shader_cso
{
389 struct ilo_state_vector
{
390 const struct pipe_draw_info
*draw
;
394 struct ilo_vb_state vb
;
395 struct ilo_ve_state
*ve
;
396 struct ilo_ib_state ib
;
398 struct ilo_shader_state
*vs
;
399 struct ilo_shader_state
*gs
;
401 struct ilo_so_state so
;
403 struct pipe_clip_state clip
;
404 struct ilo_viewport_state viewport
;
405 struct ilo_scissor_state scissor
;
407 const struct ilo_rasterizer_state
*rasterizer
;
408 struct pipe_poly_stipple poly_stipple
;
409 unsigned sample_mask
;
411 struct ilo_shader_state
*fs
;
413 const struct ilo_dsa_state
*dsa
;
414 struct pipe_stencil_ref stencil_ref
;
415 const struct ilo_blend_state
*blend
;
416 struct pipe_blend_color blend_color
;
417 struct ilo_fb_state fb
;
419 /* shader resources */
420 struct ilo_sampler_state sampler
[PIPE_SHADER_TYPES
];
421 struct ilo_view_state view
[PIPE_SHADER_TYPES
];
422 struct ilo_cbuf_state cbuf
[PIPE_SHADER_TYPES
];
423 struct ilo_resource_state resource
;
426 struct ilo_shader_state
*cs
;
427 struct ilo_resource_state cs_resource
;
428 struct ilo_global_binding global_binding
;
432 ilo_init_state_functions(struct ilo_context
*ilo
);
435 ilo_finalize_3d_states(struct ilo_context
*ilo
,
436 const struct pipe_draw_info
*draw
);
439 ilo_state_vector_init(const struct ilo_dev_info
*dev
,
440 struct ilo_state_vector
*vec
);
443 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
);
446 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
447 struct pipe_resource
*res
);
450 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
);
452 #endif /* ILO_STATE_H */