1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2012-2013 LunarG, Inc. 5 * 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: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 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. 23 * 24 * Authors: 25 * Chia-I Wu <olv (at) lunarg.com> 26 */ 27 28 #ifndef ILO_STATE_H 29 #define ILO_STATE_H 30 31 #include "core/ilo_builder_3d.h" /* for gen6_3dprimitive_info */ 32 #include "core/ilo_state_cc.h" 33 #include "core/ilo_state_compute.h" 34 #include "core/ilo_state_raster.h" 35 #include "core/ilo_state_sampler.h" 36 #include "core/ilo_state_sbe.h" 37 #include "core/ilo_state_shader.h" 38 #include "core/ilo_state_sol.h" 39 #include "core/ilo_state_surface.h" 40 #include "core/ilo_state_urb.h" 41 #include "core/ilo_state_vf.h" 42 #include "core/ilo_state_viewport.h" 43 #include "core/ilo_state_zs.h" 44 #include "pipe/p_state.h" 45 #include "util/u_dynarray.h" 46 47 #include "ilo_common.h" 48 49 /** 50 * \see brw_context.h 51 */ 52 #define ILO_MAX_DRAW_BUFFERS 8 53 #define ILO_MAX_CONST_BUFFERS (1 + 12) 54 #define ILO_MAX_SAMPLER_VIEWS 16 55 #define ILO_MAX_SAMPLERS 16 56 #define ILO_MAX_SO_BINDINGS 64 57 #define ILO_MAX_SO_BUFFERS 4 58 #define ILO_MAX_VIEWPORTS 1 59 60 #define ILO_MAX_SURFACES 256 61 62 /** 63 * States that we track. 64 * 65 * XXX Do we want to count each sampler or vertex buffer as a state? If that 66 * is the case, there are simply not enough bits. 67 * 68 * XXX We want to treat primitive type and depth clear value as states, but 69 * there are not enough bits. 70 */ 71 enum ilo_state { 72 ILO_STATE_VB, 73 ILO_STATE_VE, 74 ILO_STATE_IB, 75 ILO_STATE_VS, 76 ILO_STATE_GS, 77 ILO_STATE_SO, 78 ILO_STATE_CLIP, 79 ILO_STATE_VIEWPORT, 80 ILO_STATE_SCISSOR, 81 ILO_STATE_RASTERIZER, 82 ILO_STATE_POLY_STIPPLE, 83 ILO_STATE_SAMPLE_MASK, 84 ILO_STATE_FS, 85 ILO_STATE_DSA, 86 ILO_STATE_STENCIL_REF, 87 ILO_STATE_BLEND, 88 ILO_STATE_BLEND_COLOR, 89 ILO_STATE_FB, 90 91 ILO_STATE_SAMPLER_VS, 92 ILO_STATE_SAMPLER_GS, 93 ILO_STATE_SAMPLER_FS, 94 ILO_STATE_SAMPLER_CS, 95 ILO_STATE_VIEW_VS, 96 ILO_STATE_VIEW_GS, 97 ILO_STATE_VIEW_FS, 98 ILO_STATE_VIEW_CS, 99 ILO_STATE_CBUF, 100 ILO_STATE_RESOURCE, 101 102 ILO_STATE_CS, 103 ILO_STATE_CS_RESOURCE, 104 ILO_STATE_GLOBAL_BINDING, 105 106 ILO_STATE_COUNT, 107 }; 108 109 /** 110 * Dirty flags of the states. 111 */ 112 enum ilo_dirty_flags { 113 ILO_DIRTY_VB = 1 << ILO_STATE_VB, 114 ILO_DIRTY_VE = 1 << ILO_STATE_VE, 115 ILO_DIRTY_IB = 1 << ILO_STATE_IB, 116 ILO_DIRTY_VS = 1 << ILO_STATE_VS, 117 ILO_DIRTY_GS = 1 << ILO_STATE_GS, 118 ILO_DIRTY_SO = 1 << ILO_STATE_SO, 119 ILO_DIRTY_CLIP = 1 << ILO_STATE_CLIP, 120 ILO_DIRTY_VIEWPORT = 1 << ILO_STATE_VIEWPORT, 121 ILO_DIRTY_SCISSOR = 1 << ILO_STATE_SCISSOR, 122 ILO_DIRTY_RASTERIZER = 1 << ILO_STATE_RASTERIZER, 123 ILO_DIRTY_POLY_STIPPLE = 1 << ILO_STATE_POLY_STIPPLE, 124 ILO_DIRTY_SAMPLE_MASK = 1 << ILO_STATE_SAMPLE_MASK, 125 ILO_DIRTY_FS = 1 << ILO_STATE_FS, 126 ILO_DIRTY_DSA = 1 << ILO_STATE_DSA, 127 ILO_DIRTY_STENCIL_REF = 1 << ILO_STATE_STENCIL_REF, 128 ILO_DIRTY_BLEND = 1 << ILO_STATE_BLEND, 129 ILO_DIRTY_BLEND_COLOR = 1 << ILO_STATE_BLEND_COLOR, 130 ILO_DIRTY_FB = 1 << ILO_STATE_FB, 131 ILO_DIRTY_SAMPLER_VS = 1 << ILO_STATE_SAMPLER_VS, 132 ILO_DIRTY_SAMPLER_GS = 1 << ILO_STATE_SAMPLER_GS, 133 ILO_DIRTY_SAMPLER_FS = 1 << ILO_STATE_SAMPLER_FS, 134 ILO_DIRTY_SAMPLER_CS = 1 << ILO_STATE_SAMPLER_CS, 135 ILO_DIRTY_VIEW_VS = 1 << ILO_STATE_VIEW_VS, 136 ILO_DIRTY_VIEW_GS = 1 << ILO_STATE_VIEW_GS, 137 ILO_DIRTY_VIEW_FS = 1 << ILO_STATE_VIEW_FS, 138 ILO_DIRTY_VIEW_CS = 1 << ILO_STATE_VIEW_CS, 139 ILO_DIRTY_CBUF = 1 << ILO_STATE_CBUF, 140 ILO_DIRTY_RESOURCE = 1 << ILO_STATE_RESOURCE, 141 ILO_DIRTY_CS = 1 << ILO_STATE_CS, 142 ILO_DIRTY_CS_RESOURCE = 1 << ILO_STATE_CS_RESOURCE, 143 ILO_DIRTY_GLOBAL_BINDING = 1 << ILO_STATE_GLOBAL_BINDING, 144 ILO_DIRTY_ALL = 0xffffffff, 145 }; 146 147 struct ilo_context; 148 struct ilo_shader_state; 149 150 struct ilo_ve_state { 151 unsigned vb_mapping[PIPE_MAX_ATTRIBS]; 152 unsigned vb_count; 153 154 /* these are not valid until the state is finalized */ 155 uint32_t vf_data[PIPE_MAX_ATTRIBS][4]; 156 struct ilo_state_vf_params_info vf_params; 157 struct ilo_state_vf vf; 158 }; 159 160 struct ilo_vb_state { 161 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS]; 162 struct ilo_state_vertex_buffer vb[PIPE_MAX_ATTRIBS]; 163 uint32_t enabled_mask; 164 }; 165 166 struct ilo_ib_state { 167 struct pipe_index_buffer state; 168 169 /* these are not valid until the state is finalized */ 170 struct pipe_resource *hw_resource; 171 unsigned hw_index_size; 172 struct ilo_state_index_buffer ib; 173 }; 174 175 struct ilo_cbuf_cso { 176 struct pipe_resource *resource; 177 struct ilo_state_surface_buffer_info info; 178 struct ilo_state_surface surface; 179 180 /* 181 * this CSO is not so constant because user buffer needs to be uploaded in 182 * finalize_constant_buffers() 183 */ 184 const void *user_buffer; 185 }; 186 187 struct ilo_sampler_cso { 188 struct ilo_state_sampler sampler; 189 struct ilo_state_sampler_border border; 190 bool saturate_s; 191 bool saturate_t; 192 bool saturate_r; 193 }; 194 195 struct ilo_sampler_state { 196 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS]; 197 }; 198 199 struct ilo_cbuf_state { 200 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS]; 201 uint32_t enabled_mask; 202 }; 203 204 struct ilo_resource_state { 205 struct pipe_surface *states[PIPE_MAX_SHADER_IMAGES]; 206 unsigned count; 207 }; 208 209 struct ilo_view_cso { 210 struct pipe_sampler_view base; 211 212 struct ilo_state_surface surface; 213 }; 214 215 struct ilo_view_state { 216 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS]; 217 unsigned count; 218 }; 219 220 struct ilo_stream_output_target { 221 struct pipe_stream_output_target base; 222 223 struct ilo_state_sol_buffer sb; 224 }; 225 226 struct ilo_so_state { 227 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS]; 228 unsigned count; 229 unsigned append_bitmask; 230 231 struct ilo_state_sol_buffer dummy_sb; 232 233 bool enabled; 234 }; 235 236 struct ilo_rasterizer_state { 237 struct pipe_rasterizer_state state; 238 239 /* these are invalid until finalize_rasterizer() */ 240 struct ilo_state_raster_info info; 241 struct ilo_state_raster rs; 242 }; 243 244 struct ilo_viewport_state { 245 struct ilo_state_viewport_matrix_info matrices[ILO_MAX_VIEWPORTS]; 246 struct ilo_state_viewport_scissor_info scissors[ILO_MAX_VIEWPORTS]; 247 struct ilo_state_viewport_params_info params; 248 249 struct pipe_viewport_state viewport0; 250 struct pipe_scissor_state scissor0; 251 252 struct ilo_state_viewport vp; 253 uint32_t vp_data[20 * ILO_MAX_VIEWPORTS]; 254 }; 255 256 struct ilo_surface_cso { 257 struct pipe_surface base; 258 259 bool is_rt; 260 union { 261 struct ilo_state_surface rt; 262 struct ilo_state_zs zs; 263 } u; 264 }; 265 266 struct ilo_fb_state { 267 struct pipe_framebuffer_state state; 268 269 struct ilo_state_surface null_rt; 270 struct ilo_state_zs null_zs; 271 272 struct ilo_fb_blend_caps { 273 bool is_unorm; 274 bool is_integer; 275 bool force_dst_alpha_one; 276 277 bool can_logicop; 278 bool can_blend; 279 bool can_alpha_test; 280 } blend_caps[PIPE_MAX_COLOR_BUFS]; 281 282 unsigned num_samples; 283 284 bool has_integer_rt; 285 bool has_hiz; 286 enum gen_depth_format depth_offset_format; 287 }; 288 289 struct ilo_dsa_state { 290 struct ilo_state_cc_depth_info depth; 291 292 struct ilo_state_cc_stencil_info stencil; 293 struct { 294 uint8_t test_mask; 295 uint8_t write_mask; 296 } stencil_front, stencil_back; 297 298 bool alpha_test; 299 float alpha_ref; 300 enum gen_compare_function alpha_func; 301 }; 302 303 struct ilo_blend_state { 304 struct ilo_state_cc_blend_rt_info rt[PIPE_MAX_COLOR_BUFS]; 305 struct ilo_state_cc_blend_rt_info dummy_rt; 306 bool dual_blend; 307 308 /* these are invalid until finalize_blend() */ 309 struct ilo_state_cc_blend_rt_info effective_rt[PIPE_MAX_COLOR_BUFS]; 310 struct ilo_state_cc_info info; 311 struct ilo_state_cc cc; 312 bool alpha_may_kill; 313 }; 314 315 struct ilo_global_binding_cso { 316 struct pipe_resource *resource; 317 uint32_t *handle; 318 }; 319 320 /* 321 * In theory, we would like a "virtual" bo that serves as the global memory 322 * region. The virtual bo would reserve a region in the GTT aperture, but the 323 * pages of it would come from those of the global bindings. 324 * 325 * The virtual bo would be created in launch_grid(). The global bindings 326 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would 327 * be created. The handles returned by set_global_binding() would be offsets 328 * into the virtual bo. 329 * 330 * But for now, we will create a SURFACE_STATE for each of the bindings. The 331 * handle of a global binding consists of the offset and the binding table 332 * index. 333 */ 334 struct ilo_global_binding { 335 struct util_dynarray bindings; 336 unsigned count; 337 }; 338 339 struct ilo_state_vector { 340 const struct pipe_draw_info *draw; 341 struct gen6_3dprimitive_info draw_info; 342 343 uint32_t dirty; 344 345 struct ilo_vb_state vb; 346 struct ilo_ve_state *ve; 347 struct ilo_ib_state ib; 348 349 struct ilo_shader_state *vs; 350 struct ilo_shader_state *gs; 351 352 struct ilo_state_hs disabled_hs; 353 struct ilo_state_ds disabled_ds; 354 struct ilo_state_gs disabled_gs; 355 356 struct ilo_so_state so; 357 358 struct pipe_clip_state clip; 359 360 struct ilo_viewport_state viewport; 361 362 struct ilo_rasterizer_state *rasterizer; 363 364 struct ilo_state_line_stipple line_stipple; 365 struct ilo_state_poly_stipple poly_stipple; 366 unsigned sample_mask; 367 368 struct ilo_shader_state *fs; 369 370 struct ilo_state_cc_params_info cc_params; 371 struct pipe_stencil_ref stencil_ref; 372 const struct ilo_dsa_state *dsa; 373 struct ilo_blend_state *blend; 374 375 struct ilo_fb_state fb; 376 377 struct ilo_state_urb urb; 378 379 /* shader resources */ 380 struct ilo_sampler_state sampler[PIPE_SHADER_TYPES]; 381 struct ilo_view_state view[PIPE_SHADER_TYPES]; 382 struct ilo_cbuf_state cbuf[PIPE_SHADER_TYPES]; 383 struct ilo_resource_state resource; 384 385 struct ilo_state_sampler disabled_sampler; 386 387 /* GPGPU */ 388 struct ilo_shader_state *cs; 389 struct ilo_resource_state cs_resource; 390 struct ilo_global_binding global_binding; 391 }; 392 393 void 394 ilo_init_state_functions(struct ilo_context *ilo); 395 396 void 397 ilo_finalize_3d_states(struct ilo_context *ilo, 398 const struct pipe_draw_info *draw); 399 400 void 401 ilo_finalize_compute_states(struct ilo_context *ilo); 402 403 void 404 ilo_state_vector_init(const struct ilo_dev *dev, 405 struct ilo_state_vector *vec); 406 407 void 408 ilo_state_vector_cleanup(struct ilo_state_vector *vec); 409 410 void 411 ilo_state_vector_resource_renamed(struct ilo_state_vector *vec, 412 struct pipe_resource *res); 413 414 void 415 ilo_state_vector_dump_dirty(const struct ilo_state_vector *vec); 416 417 #endif /* ILO_STATE_H */ 418