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>
28 #include "core/ilo_builder_3d.h" /* for gen6_3d_translate_pipe_prim() */
29 #include "core/ilo_format.h"
30 #include "util/u_dual_blend.h"
31 #include "util/u_dynarray.h"
32 #include "util/u_framebuffer.h"
33 #include "util/u_helpers.h"
34 #include "util/u_resource.h"
35 #include "util/u_upload_mgr.h"
37 #include "ilo_context.h"
38 #include "ilo_resource.h"
39 #include "ilo_shader.h"
40 #include "ilo_state.h"
42 static enum gen_index_format
43 ilo_translate_index_size(unsigned index_size
)
46 case 1: return GEN6_INDEX_BYTE
;
47 case 2: return GEN6_INDEX_WORD
;
48 case 4: return GEN6_INDEX_DWORD
;
50 assert(!"unknown index size");
51 return GEN6_INDEX_BYTE
;
55 static enum gen_mip_filter
56 ilo_translate_mip_filter(unsigned filter
)
59 case PIPE_TEX_MIPFILTER_NEAREST
: return GEN6_MIPFILTER_NEAREST
;
60 case PIPE_TEX_MIPFILTER_LINEAR
: return GEN6_MIPFILTER_LINEAR
;
61 case PIPE_TEX_MIPFILTER_NONE
: return GEN6_MIPFILTER_NONE
;
63 assert(!"unknown mipfilter");
64 return GEN6_MIPFILTER_NONE
;
69 ilo_translate_img_filter(unsigned filter
)
72 case PIPE_TEX_FILTER_NEAREST
: return GEN6_MAPFILTER_NEAREST
;
73 case PIPE_TEX_FILTER_LINEAR
: return GEN6_MAPFILTER_LINEAR
;
75 assert(!"unknown sampler filter");
76 return GEN6_MAPFILTER_NEAREST
;
80 static enum gen_texcoord_mode
81 ilo_translate_address_wrap(unsigned wrap
)
84 case PIPE_TEX_WRAP_CLAMP
: return GEN8_TEXCOORDMODE_HALF_BORDER
;
85 case PIPE_TEX_WRAP_REPEAT
: return GEN6_TEXCOORDMODE_WRAP
;
86 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
: return GEN6_TEXCOORDMODE_CLAMP
;
87 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
: return GEN6_TEXCOORDMODE_CLAMP_BORDER
;
88 case PIPE_TEX_WRAP_MIRROR_REPEAT
: return GEN6_TEXCOORDMODE_MIRROR
;
89 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
90 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
91 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
93 assert(!"unknown sampler wrap mode");
94 return GEN6_TEXCOORDMODE_WRAP
;
98 static enum gen_aniso_ratio
99 ilo_translate_max_anisotropy(unsigned max_anisotropy
)
101 switch (max_anisotropy
) {
102 case 0: case 1: case 2: return GEN6_ANISORATIO_2
;
103 case 3: case 4: return GEN6_ANISORATIO_4
;
104 case 5: case 6: return GEN6_ANISORATIO_6
;
105 case 7: case 8: return GEN6_ANISORATIO_8
;
106 case 9: case 10: return GEN6_ANISORATIO_10
;
107 case 11: case 12: return GEN6_ANISORATIO_12
;
108 case 13: case 14: return GEN6_ANISORATIO_14
;
109 default: return GEN6_ANISORATIO_16
;
113 static enum gen_prefilter_op
114 ilo_translate_shadow_func(unsigned func
)
117 * For PIPE_FUNC_x, the reference value is on the left-hand side of the
118 * comparison, and 1.0 is returned when the comparison is true.
120 * For GEN6_PREFILTEROP_x, the reference value is on the right-hand side of
121 * the comparison, and 0.0 is returned when the comparison is true.
124 case PIPE_FUNC_NEVER
: return GEN6_PREFILTEROP_ALWAYS
;
125 case PIPE_FUNC_LESS
: return GEN6_PREFILTEROP_LEQUAL
;
126 case PIPE_FUNC_EQUAL
: return GEN6_PREFILTEROP_NOTEQUAL
;
127 case PIPE_FUNC_LEQUAL
: return GEN6_PREFILTEROP_LESS
;
128 case PIPE_FUNC_GREATER
: return GEN6_PREFILTEROP_GEQUAL
;
129 case PIPE_FUNC_NOTEQUAL
: return GEN6_PREFILTEROP_EQUAL
;
130 case PIPE_FUNC_GEQUAL
: return GEN6_PREFILTEROP_GREATER
;
131 case PIPE_FUNC_ALWAYS
: return GEN6_PREFILTEROP_NEVER
;
133 assert(!"unknown shadow compare function");
134 return GEN6_PREFILTEROP_NEVER
;
138 static enum gen_front_winding
139 ilo_translate_front_ccw(unsigned front_ccw
)
141 return (front_ccw
) ? GEN6_FRONTWINDING_CCW
: GEN6_FRONTWINDING_CW
;
144 static enum gen_cull_mode
145 ilo_translate_cull_face(unsigned cull_face
)
148 case PIPE_FACE_NONE
: return GEN6_CULLMODE_NONE
;
149 case PIPE_FACE_FRONT
: return GEN6_CULLMODE_FRONT
;
150 case PIPE_FACE_BACK
: return GEN6_CULLMODE_BACK
;
151 case PIPE_FACE_FRONT_AND_BACK
: return GEN6_CULLMODE_BOTH
;
153 assert(!"unknown face culling");
154 return GEN6_CULLMODE_NONE
;
158 static enum gen_fill_mode
159 ilo_translate_poly_mode(unsigned poly_mode
)
162 case PIPE_POLYGON_MODE_FILL
: return GEN6_FILLMODE_SOLID
;
163 case PIPE_POLYGON_MODE_LINE
: return GEN6_FILLMODE_WIREFRAME
;
164 case PIPE_POLYGON_MODE_POINT
: return GEN6_FILLMODE_POINT
;
166 assert(!"unknown polygon mode");
167 return GEN6_FILLMODE_SOLID
;
171 static enum gen_pixel_location
172 ilo_translate_half_pixel_center(bool half_pixel_center
)
174 return (half_pixel_center
) ? GEN6_PIXLOC_CENTER
: GEN6_PIXLOC_UL_CORNER
;
177 static enum gen_compare_function
178 ilo_translate_compare_func(unsigned func
)
181 case PIPE_FUNC_NEVER
: return GEN6_COMPAREFUNCTION_NEVER
;
182 case PIPE_FUNC_LESS
: return GEN6_COMPAREFUNCTION_LESS
;
183 case PIPE_FUNC_EQUAL
: return GEN6_COMPAREFUNCTION_EQUAL
;
184 case PIPE_FUNC_LEQUAL
: return GEN6_COMPAREFUNCTION_LEQUAL
;
185 case PIPE_FUNC_GREATER
: return GEN6_COMPAREFUNCTION_GREATER
;
186 case PIPE_FUNC_NOTEQUAL
: return GEN6_COMPAREFUNCTION_NOTEQUAL
;
187 case PIPE_FUNC_GEQUAL
: return GEN6_COMPAREFUNCTION_GEQUAL
;
188 case PIPE_FUNC_ALWAYS
: return GEN6_COMPAREFUNCTION_ALWAYS
;
190 assert(!"unknown compare function");
191 return GEN6_COMPAREFUNCTION_NEVER
;
195 static enum gen_stencil_op
196 ilo_translate_stencil_op(unsigned stencil_op
)
198 switch (stencil_op
) {
199 case PIPE_STENCIL_OP_KEEP
: return GEN6_STENCILOP_KEEP
;
200 case PIPE_STENCIL_OP_ZERO
: return GEN6_STENCILOP_ZERO
;
201 case PIPE_STENCIL_OP_REPLACE
: return GEN6_STENCILOP_REPLACE
;
202 case PIPE_STENCIL_OP_INCR
: return GEN6_STENCILOP_INCRSAT
;
203 case PIPE_STENCIL_OP_DECR
: return GEN6_STENCILOP_DECRSAT
;
204 case PIPE_STENCIL_OP_INCR_WRAP
: return GEN6_STENCILOP_INCR
;
205 case PIPE_STENCIL_OP_DECR_WRAP
: return GEN6_STENCILOP_DECR
;
206 case PIPE_STENCIL_OP_INVERT
: return GEN6_STENCILOP_INVERT
;
208 assert(!"unknown stencil op");
209 return GEN6_STENCILOP_KEEP
;
213 static enum gen_logic_op
214 ilo_translate_logicop(unsigned logicop
)
217 case PIPE_LOGICOP_CLEAR
: return GEN6_LOGICOP_CLEAR
;
218 case PIPE_LOGICOP_NOR
: return GEN6_LOGICOP_NOR
;
219 case PIPE_LOGICOP_AND_INVERTED
: return GEN6_LOGICOP_AND_INVERTED
;
220 case PIPE_LOGICOP_COPY_INVERTED
: return GEN6_LOGICOP_COPY_INVERTED
;
221 case PIPE_LOGICOP_AND_REVERSE
: return GEN6_LOGICOP_AND_REVERSE
;
222 case PIPE_LOGICOP_INVERT
: return GEN6_LOGICOP_INVERT
;
223 case PIPE_LOGICOP_XOR
: return GEN6_LOGICOP_XOR
;
224 case PIPE_LOGICOP_NAND
: return GEN6_LOGICOP_NAND
;
225 case PIPE_LOGICOP_AND
: return GEN6_LOGICOP_AND
;
226 case PIPE_LOGICOP_EQUIV
: return GEN6_LOGICOP_EQUIV
;
227 case PIPE_LOGICOP_NOOP
: return GEN6_LOGICOP_NOOP
;
228 case PIPE_LOGICOP_OR_INVERTED
: return GEN6_LOGICOP_OR_INVERTED
;
229 case PIPE_LOGICOP_COPY
: return GEN6_LOGICOP_COPY
;
230 case PIPE_LOGICOP_OR_REVERSE
: return GEN6_LOGICOP_OR_REVERSE
;
231 case PIPE_LOGICOP_OR
: return GEN6_LOGICOP_OR
;
232 case PIPE_LOGICOP_SET
: return GEN6_LOGICOP_SET
;
234 assert(!"unknown logicop function");
235 return GEN6_LOGICOP_CLEAR
;
240 ilo_translate_blend_func(unsigned blend
)
243 case PIPE_BLEND_ADD
: return GEN6_BLENDFUNCTION_ADD
;
244 case PIPE_BLEND_SUBTRACT
: return GEN6_BLENDFUNCTION_SUBTRACT
;
245 case PIPE_BLEND_REVERSE_SUBTRACT
: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT
;
246 case PIPE_BLEND_MIN
: return GEN6_BLENDFUNCTION_MIN
;
247 case PIPE_BLEND_MAX
: return GEN6_BLENDFUNCTION_MAX
;
249 assert(!"unknown blend function");
250 return GEN6_BLENDFUNCTION_ADD
;
255 ilo_translate_blend_factor(unsigned factor
)
258 case PIPE_BLENDFACTOR_ONE
: return GEN6_BLENDFACTOR_ONE
;
259 case PIPE_BLENDFACTOR_SRC_COLOR
: return GEN6_BLENDFACTOR_SRC_COLOR
;
260 case PIPE_BLENDFACTOR_SRC_ALPHA
: return GEN6_BLENDFACTOR_SRC_ALPHA
;
261 case PIPE_BLENDFACTOR_DST_ALPHA
: return GEN6_BLENDFACTOR_DST_ALPHA
;
262 case PIPE_BLENDFACTOR_DST_COLOR
: return GEN6_BLENDFACTOR_DST_COLOR
;
263 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE
;
264 case PIPE_BLENDFACTOR_CONST_COLOR
: return GEN6_BLENDFACTOR_CONST_COLOR
;
265 case PIPE_BLENDFACTOR_CONST_ALPHA
: return GEN6_BLENDFACTOR_CONST_ALPHA
;
266 case PIPE_BLENDFACTOR_SRC1_COLOR
: return GEN6_BLENDFACTOR_SRC1_COLOR
;
267 case PIPE_BLENDFACTOR_SRC1_ALPHA
: return GEN6_BLENDFACTOR_SRC1_ALPHA
;
268 case PIPE_BLENDFACTOR_ZERO
: return GEN6_BLENDFACTOR_ZERO
;
269 case PIPE_BLENDFACTOR_INV_SRC_COLOR
: return GEN6_BLENDFACTOR_INV_SRC_COLOR
;
270 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
: return GEN6_BLENDFACTOR_INV_SRC_ALPHA
;
271 case PIPE_BLENDFACTOR_INV_DST_ALPHA
: return GEN6_BLENDFACTOR_INV_DST_ALPHA
;
272 case PIPE_BLENDFACTOR_INV_DST_COLOR
: return GEN6_BLENDFACTOR_INV_DST_COLOR
;
273 case PIPE_BLENDFACTOR_INV_CONST_COLOR
: return GEN6_BLENDFACTOR_INV_CONST_COLOR
;
274 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
: return GEN6_BLENDFACTOR_INV_CONST_ALPHA
;
275 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
: return GEN6_BLENDFACTOR_INV_SRC1_COLOR
;
276 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA
;
278 assert(!"unknown blend factor");
279 return GEN6_BLENDFACTOR_ONE
;
284 finalize_shader_states(struct ilo_state_vector
*vec
)
288 for (type
= 0; type
< PIPE_SHADER_TYPES
; type
++) {
289 struct ilo_shader_state
*shader
;
293 case PIPE_SHADER_VERTEX
:
295 state
= ILO_DIRTY_VS
;
297 case PIPE_SHADER_GEOMETRY
:
299 state
= ILO_DIRTY_GS
;
301 case PIPE_SHADER_FRAGMENT
:
303 state
= ILO_DIRTY_FS
;
314 /* compile if the shader or the states it depends on changed */
315 if (vec
->dirty
& state
) {
316 ilo_shader_select_kernel(shader
, vec
, ILO_DIRTY_ALL
);
318 else if (ilo_shader_select_kernel(shader
, vec
, vec
->dirty
)) {
319 /* mark the state dirty if a new kernel is selected */
323 /* need to setup SBE for FS */
324 if (type
== PIPE_SHADER_FRAGMENT
&& vec
->dirty
&
325 (state
| ILO_DIRTY_GS
| ILO_DIRTY_VS
| ILO_DIRTY_RASTERIZER
)) {
326 if (ilo_shader_select_kernel_sbe(shader
,
327 (vec
->gs
) ? vec
->gs
: vec
->vs
, vec
->rasterizer
))
334 finalize_cbuf_state(struct ilo_context
*ilo
,
335 struct ilo_cbuf_state
*cbuf
,
336 const struct ilo_shader_state
*sh
)
338 uint32_t upload_mask
= cbuf
->enabled_mask
;
340 /* skip CBUF0 if the kernel does not need it */
342 ~ilo_shader_get_kernel_param(sh
, ILO_KERNEL_SKIP_CBUF0_UPLOAD
);
344 while (upload_mask
) {
347 i
= u_bit_scan(&upload_mask
);
348 /* no need to upload */
349 if (cbuf
->cso
[i
].resource
)
352 u_upload_data(ilo
->uploader
, 0, cbuf
->cso
[i
].info
.size
,
353 cbuf
->cso
[i
].user_buffer
, &offset
, &cbuf
->cso
[i
].resource
);
355 cbuf
->cso
[i
].info
.buf
= ilo_buffer(cbuf
->cso
[i
].resource
);
356 cbuf
->cso
[i
].info
.offset
= offset
;
358 memset(&cbuf
->cso
[i
].surface
, 0, sizeof(cbuf
->cso
[i
].surface
));
359 ilo_state_surface_init_for_buffer(&cbuf
->cso
[i
].surface
,
360 ilo
->dev
, &cbuf
->cso
[i
].info
);
361 cbuf
->cso
[i
].surface
.bo
= cbuf
->cso
[i
].info
.buf
->bo
;
363 ilo
->state_vector
.dirty
|= ILO_DIRTY_CBUF
;
368 finalize_constant_buffers(struct ilo_context
*ilo
)
370 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
372 if (vec
->dirty
& (ILO_DIRTY_CBUF
| ILO_DIRTY_VS
))
373 finalize_cbuf_state(ilo
, &vec
->cbuf
[PIPE_SHADER_VERTEX
], vec
->vs
);
375 if (ilo
->state_vector
.dirty
& (ILO_DIRTY_CBUF
| ILO_DIRTY_FS
))
376 finalize_cbuf_state(ilo
, &vec
->cbuf
[PIPE_SHADER_FRAGMENT
], vec
->fs
);
380 finalize_index_buffer(struct ilo_context
*ilo
)
382 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
383 const bool need_upload
= (vec
->draw
->indexed
&&
384 (vec
->ib
.state
.user_buffer
||
385 vec
->ib
.state
.offset
% vec
->ib
.state
.index_size
));
386 struct pipe_resource
*current_hw_res
= NULL
;
388 if (!(vec
->dirty
& ILO_DIRTY_IB
) && !need_upload
)
391 /* make sure vec->ib.hw_resource changes when reallocated */
392 pipe_resource_reference(¤t_hw_res
, vec
->ib
.hw_resource
);
395 const unsigned offset
= vec
->ib
.state
.index_size
* vec
->draw
->start
;
396 const unsigned size
= vec
->ib
.state
.index_size
* vec
->draw
->count
;
399 if (vec
->ib
.state
.user_buffer
) {
400 u_upload_data(ilo
->uploader
, 0, size
,
401 vec
->ib
.state
.user_buffer
+ offset
,
402 &hw_offset
, &vec
->ib
.hw_resource
);
404 u_upload_buffer(ilo
->uploader
, 0,
405 vec
->ib
.state
.offset
+ offset
, size
, vec
->ib
.state
.buffer
,
406 &hw_offset
, &vec
->ib
.hw_resource
);
409 /* the HW offset should be aligned */
410 assert(hw_offset
% vec
->ib
.state
.index_size
== 0);
411 vec
->ib
.draw_start_offset
= hw_offset
/ vec
->ib
.state
.index_size
;
414 * INDEX[vec->draw->start] in the original buffer is INDEX[0] in the HW
417 vec
->ib
.draw_start_offset
-= vec
->draw
->start
;
419 pipe_resource_reference(&vec
->ib
.hw_resource
, vec
->ib
.state
.buffer
);
421 /* note that index size may be zero when the draw is not indexed */
422 if (vec
->draw
->indexed
) {
423 vec
->ib
.draw_start_offset
=
424 vec
->ib
.state
.offset
/ vec
->ib
.state
.index_size
;
426 vec
->ib
.draw_start_offset
= 0;
430 /* treat the IB as clean if the HW states do not change */
431 if (vec
->ib
.hw_resource
== current_hw_res
&&
432 vec
->ib
.hw_index_size
== vec
->ib
.state
.index_size
)
433 vec
->dirty
&= ~ILO_DIRTY_IB
;
435 vec
->ib
.hw_index_size
= vec
->ib
.state
.index_size
;
437 pipe_resource_reference(¤t_hw_res
, NULL
);
441 finalize_vertex_elements(struct ilo_context
*ilo
)
443 const struct ilo_dev
*dev
= ilo
->dev
;
444 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
445 struct ilo_ve_state
*ve
= vec
->ve
;
446 const enum gen_3dprim_type topology
=
447 gen6_3d_translate_pipe_prim(vec
->draw
->mode
);
448 const bool last_element_edge_flag
= (vec
->vs
&&
449 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_VS_INPUT_EDGEFLAG
));
450 const bool prepend_vertexid
= (vec
->vs
&&
451 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_VS_INPUT_VERTEXID
));
452 const bool prepend_instanceid
= (vec
->vs
&&
453 ilo_shader_get_kernel_param(vec
->vs
,
454 ILO_KERNEL_VS_INPUT_INSTANCEID
));
455 const enum gen_index_format index_format
= (vec
->draw
->indexed
) ?
456 ilo_translate_index_size(vec
->ib
.state
.index_size
) : GEN6_INDEX_DWORD
;
458 /* check for non-orthogonal states */
459 if (ve
->vf_params
.cv_topology
!= topology
||
460 ve
->vf_params
.prepend_vertexid
!= prepend_vertexid
||
461 ve
->vf_params
.prepend_instanceid
!= prepend_instanceid
||
462 ve
->vf_params
.last_element_edge_flag
!= last_element_edge_flag
||
463 ve
->vf_params
.cv_index_format
!= index_format
||
464 ve
->vf_params
.cut_index_enable
!= vec
->draw
->primitive_restart
||
465 ve
->vf_params
.cut_index
!= vec
->draw
->restart_index
) {
466 ve
->vf_params
.cv_topology
= topology
;
467 ve
->vf_params
.prepend_vertexid
= prepend_vertexid
;
468 ve
->vf_params
.prepend_instanceid
= prepend_instanceid
;
469 ve
->vf_params
.last_element_edge_flag
= last_element_edge_flag
;
470 ve
->vf_params
.cv_index_format
= index_format
;
471 ve
->vf_params
.cut_index_enable
= vec
->draw
->primitive_restart
;
472 ve
->vf_params
.cut_index
= vec
->draw
->restart_index
;
474 ilo_state_vf_set_params(&ve
->vf
, dev
, &ve
->vf_params
);
476 vec
->dirty
|= ILO_DIRTY_VE
;
481 finalize_urb(struct ilo_context
*ilo
)
483 const uint16_t attr_size
= sizeof(uint32_t) * 4;
484 const struct ilo_dev
*dev
= ilo
->dev
;
485 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
486 struct ilo_state_urb_info info
;
488 if (!(vec
->dirty
& (ILO_DIRTY_VE
| ILO_DIRTY_VS
|
489 ILO_DIRTY_GS
| ILO_DIRTY_FS
)))
492 memset(&info
, 0, sizeof(info
));
494 info
.ve_entry_size
= attr_size
* ilo_state_vf_get_attr_count(&vec
->ve
->vf
);
497 info
.vs_const_data
= (bool)
498 (ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_PCB_CBUF0_SIZE
) +
499 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_VS_PCB_UCP_SIZE
));
500 info
.vs_entry_size
= attr_size
*
501 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_OUTPUT_COUNT
);
505 info
.gs_const_data
= (bool)
506 ilo_shader_get_kernel_param(vec
->gs
, ILO_KERNEL_PCB_CBUF0_SIZE
);
509 * From the Ivy Bridge PRM, volume 2 part 1, page 189:
511 * "All outputs of a GS thread will be stored in the single GS
512 * thread output URB entry."
516 info
.gs_entry_size
= attr_size
*
517 ilo_shader_get_kernel_param(vec
->gs
, ILO_KERNEL_OUTPUT_COUNT
);
521 info
.ps_const_data
= (bool)
522 ilo_shader_get_kernel_param(vec
->fs
, ILO_KERNEL_PCB_CBUF0_SIZE
);
525 ilo_state_urb_set_info(&vec
->urb
, dev
, &info
);
529 finalize_viewport(struct ilo_context
*ilo
)
531 const struct ilo_dev
*dev
= ilo
->dev
;
532 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
534 if (vec
->dirty
& ILO_DIRTY_VIEWPORT
) {
535 ilo_state_viewport_set_params(&vec
->viewport
.vp
,
536 dev
, &vec
->viewport
.params
, false);
537 } else if (vec
->dirty
& ILO_DIRTY_SCISSOR
) {
538 ilo_state_viewport_set_params(&vec
->viewport
.vp
,
539 dev
, &vec
->viewport
.params
, true);
540 vec
->dirty
|= ILO_DIRTY_VIEWPORT
;
545 can_enable_gb_test(const struct ilo_rasterizer_state
*rasterizer
,
546 const struct ilo_viewport_state
*viewport
,
547 const struct ilo_fb_state
*fb
)
552 * There are several reasons that guard band test should be disabled
554 * - GL wide points (to avoid partially visibie object)
555 * - GL wide or AA lines (to avoid partially visibie object)
556 * - missing 2D clipping
558 if (rasterizer
->state
.point_size_per_vertex
||
559 rasterizer
->state
.point_size
> 1.0f
||
560 rasterizer
->state
.line_width
> 1.0f
||
561 rasterizer
->state
.line_smooth
)
564 for (i
= 0; i
< viewport
->params
.count
; i
++) {
565 const struct ilo_state_viewport_matrix_info
*mat
=
566 &viewport
->matrices
[i
];
567 float min_x
, max_x
, min_y
, max_y
;
569 min_x
= -1.0f
* fabsf(mat
->scale
[0]) + mat
->translate
[0];
570 max_x
= 1.0f
* fabsf(mat
->scale
[0]) + mat
->translate
[0];
571 min_y
= -1.0f
* fabsf(mat
->scale
[1]) + mat
->translate
[1];
572 max_y
= 1.0f
* fabsf(mat
->scale
[1]) + mat
->translate
[1];
574 if (min_x
> 0.0f
|| max_x
< fb
->state
.width
||
575 min_y
> 0.0f
|| max_y
< fb
->state
.height
)
583 finalize_rasterizer(struct ilo_context
*ilo
)
585 const struct ilo_dev
*dev
= ilo
->dev
;
586 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
587 struct ilo_rasterizer_state
*rasterizer
= vec
->rasterizer
;
588 struct ilo_state_raster_info
*info
= &vec
->rasterizer
->info
;
589 const bool gb_test_enable
=
590 can_enable_gb_test(rasterizer
, &vec
->viewport
, &vec
->fb
);
591 const bool multisample
=
592 (rasterizer
->state
.multisample
&& vec
->fb
.num_samples
> 1);
593 const uint8_t barycentric_interps
= ilo_shader_get_kernel_param(vec
->fs
,
594 ILO_KERNEL_FS_BARYCENTRIC_INTERPOLATIONS
);
596 /* check for non-orthogonal states */
597 if (info
->clip
.viewport_count
!= vec
->viewport
.params
.count
||
598 info
->clip
.gb_test_enable
!= gb_test_enable
||
599 info
->setup
.msaa_enable
!= multisample
||
600 info
->setup
.line_msaa_enable
!= multisample
||
601 info
->tri
.depth_offset_format
!= vec
->fb
.depth_offset_format
||
602 info
->scan
.sample_count
!= vec
->fb
.num_samples
||
603 info
->scan
.sample_mask
!= vec
->sample_mask
||
604 info
->scan
.barycentric_interps
!= barycentric_interps
||
605 info
->params
.any_integer_rt
!= vec
->fb
.has_integer_rt
||
606 info
->params
.hiz_enable
!= vec
->fb
.has_hiz
) {
607 info
->clip
.viewport_count
= vec
->viewport
.params
.count
;
608 info
->clip
.gb_test_enable
= gb_test_enable
;
609 info
->setup
.msaa_enable
= multisample
;
610 info
->setup
.line_msaa_enable
= multisample
;
611 info
->tri
.depth_offset_format
= vec
->fb
.depth_offset_format
;
612 info
->scan
.sample_count
= vec
->fb
.num_samples
;
613 info
->scan
.sample_mask
= vec
->sample_mask
;
614 info
->scan
.barycentric_interps
= barycentric_interps
;
615 info
->params
.any_integer_rt
= vec
->fb
.has_integer_rt
;
616 info
->params
.hiz_enable
= vec
->fb
.has_hiz
;
618 ilo_state_raster_set_info(&rasterizer
->rs
, dev
, &rasterizer
->info
);
620 vec
->dirty
|= ILO_DIRTY_RASTERIZER
;
625 finalize_blend_rt(struct ilo_context
*ilo
)
627 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
628 const struct ilo_fb_state
*fb
= &vec
->fb
;
629 struct ilo_blend_state
*blend
= vec
->blend
;
630 struct ilo_state_cc_blend_info
*info
= &vec
->blend
->info
.blend
;
631 bool changed
= false;
634 if (!(vec
->dirty
& (ILO_DIRTY_FB
| ILO_DIRTY_BLEND
)))
637 /* set up one for dummy RT writes */
638 if (!fb
->state
.nr_cbufs
) {
639 if (info
->rt
!= &blend
->dummy_rt
) {
640 info
->rt
= &blend
->dummy_rt
;
648 if (info
->rt
!= blend
->effective_rt
||
649 info
->rt_count
!= fb
->state
.nr_cbufs
) {
650 info
->rt
= blend
->effective_rt
;
651 info
->rt_count
= fb
->state
.nr_cbufs
;
655 for (i
= 0; i
< fb
->state
.nr_cbufs
; i
++) {
656 const struct ilo_fb_blend_caps
*caps
= &fb
->blend_caps
[i
];
657 struct ilo_state_cc_blend_rt_info
*rt
= &blend
->effective_rt
[i
];
658 /* ignore logicop when not UNORM */
659 const bool logicop_enable
=
660 (blend
->rt
[i
].logicop_enable
&& caps
->is_unorm
);
662 if (rt
->cv_is_unorm
!= caps
->is_unorm
||
663 rt
->cv_is_integer
!= caps
->is_integer
||
664 rt
->logicop_enable
!= logicop_enable
||
665 rt
->force_dst_alpha_one
!= caps
->force_dst_alpha_one
) {
666 rt
->cv_is_unorm
= caps
->is_unorm
;
667 rt
->cv_is_integer
= caps
->is_integer
;
668 rt
->logicop_enable
= logicop_enable
;
669 rt
->force_dst_alpha_one
= caps
->force_dst_alpha_one
;
679 finalize_blend(struct ilo_context
*ilo
)
681 const struct ilo_dev
*dev
= ilo
->dev
;
682 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
683 struct ilo_blend_state
*blend
= vec
->blend
;
684 struct ilo_state_cc_info
*info
= &blend
->info
;
685 const bool sample_count_one
= (vec
->fb
.num_samples
<= 1);
686 const bool float_source0_alpha
=
687 (!vec
->fb
.state
.nr_cbufs
|| !vec
->fb
.state
.cbufs
[0] ||
688 !util_format_is_pure_integer(vec
->fb
.state
.cbufs
[0]->format
));
690 /* check for non-orthogonal states */
691 if (finalize_blend_rt(ilo
) ||
692 info
->alpha
.cv_sample_count_one
!= sample_count_one
||
693 info
->alpha
.cv_float_source0_alpha
!= float_source0_alpha
||
694 info
->alpha
.test_enable
!= vec
->dsa
->alpha_test
||
695 info
->alpha
.test_func
!= vec
->dsa
->alpha_func
||
696 memcmp(&info
->stencil
, &vec
->dsa
->stencil
, sizeof(info
->stencil
)) ||
697 memcmp(&info
->depth
, &vec
->dsa
->depth
, sizeof(info
->depth
)) ||
698 memcmp(&info
->params
, &vec
->cc_params
, sizeof(info
->params
))) {
699 info
->alpha
.cv_sample_count_one
= sample_count_one
;
700 info
->alpha
.cv_float_source0_alpha
= float_source0_alpha
;
701 info
->alpha
.test_enable
= vec
->dsa
->alpha_test
;
702 info
->alpha
.test_func
= vec
->dsa
->alpha_func
;
703 info
->stencil
= vec
->dsa
->stencil
;
704 info
->depth
= vec
->dsa
->depth
;
705 info
->params
= vec
->cc_params
;
707 ilo_state_cc_set_info(&blend
->cc
, dev
, info
);
709 blend
->alpha_may_kill
= (info
->alpha
.alpha_to_coverage
||
710 info
->alpha
.test_enable
);
712 vec
->dirty
|= ILO_DIRTY_BLEND
;
717 * Finalize states. Some states depend on other states and are
718 * incomplete/invalid until finalized.
721 ilo_finalize_3d_states(struct ilo_context
*ilo
,
722 const struct pipe_draw_info
*draw
)
724 ilo
->state_vector
.draw
= draw
;
727 finalize_shader_states(&ilo
->state_vector
);
728 finalize_constant_buffers(ilo
);
729 finalize_index_buffer(ilo
);
730 finalize_vertex_elements(ilo
);
733 finalize_rasterizer(ilo
);
734 finalize_viewport(ilo
);
736 u_upload_unmap(ilo
->uploader
);
740 finalize_global_binding(struct ilo_state_vector
*vec
)
742 struct ilo_shader_state
*cs
= vec
->cs
;
743 int base
, count
, shift
;
746 count
= ilo_shader_get_kernel_param(cs
,
747 ILO_KERNEL_CS_SURFACE_GLOBAL_COUNT
);
751 base
= ilo_shader_get_kernel_param(cs
, ILO_KERNEL_CS_SURFACE_GLOBAL_BASE
);
752 shift
= 32 - util_last_bit(base
+ count
- 1);
754 if (count
> vec
->global_binding
.count
)
755 count
= vec
->global_binding
.count
;
757 for (i
= 0; i
< count
; i
++) {
758 struct ilo_global_binding_cso
*cso
=
759 util_dynarray_element(&vec
->global_binding
.bindings
,
760 struct ilo_global_binding_cso
, i
);
761 const uint32_t offset
= *cso
->handle
& ((1 << shift
) - 1);
763 *cso
->handle
= ((base
+ i
) << shift
) | offset
;
768 ilo_finalize_compute_states(struct ilo_context
*ilo
)
770 finalize_global_binding(&ilo
->state_vector
);
774 ilo_create_blend_state(struct pipe_context
*pipe
,
775 const struct pipe_blend_state
*state
)
777 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
778 struct ilo_state_cc_info
*info
;
779 struct ilo_blend_state
*blend
;
782 blend
= CALLOC_STRUCT(ilo_blend_state
);
787 info
->alpha
.cv_float_source0_alpha
= true;
788 info
->alpha
.cv_sample_count_one
= true;
789 info
->alpha
.alpha_to_one
= state
->alpha_to_one
;
790 info
->alpha
.alpha_to_coverage
= state
->alpha_to_coverage
;
791 info
->alpha
.test_enable
= false;
792 info
->alpha
.test_func
= GEN6_COMPAREFUNCTION_ALWAYS
;
794 info
->stencil
.cv_has_buffer
= true;
795 info
->depth
.cv_has_buffer
= true;
797 info
->blend
.rt
= blend
->effective_rt
;
798 info
->blend
.rt_count
= 1;
799 info
->blend
.dither_enable
= state
->dither
;
801 for (i
= 0; i
< ARRAY_SIZE(blend
->rt
); i
++) {
802 const struct pipe_rt_blend_state
*rt
= &state
->rt
[i
];
803 struct ilo_state_cc_blend_rt_info
*rt_info
= &blend
->rt
[i
];
805 rt_info
->cv_has_buffer
= true;
806 rt_info
->cv_is_unorm
= true;
807 rt_info
->cv_is_integer
= false;
809 /* logic op takes precedence over blending */
810 if (state
->logicop_enable
) {
811 rt_info
->logicop_enable
= true;
812 rt_info
->logicop_func
= ilo_translate_logicop(state
->logicop_func
);
813 } else if (rt
->blend_enable
) {
814 rt_info
->blend_enable
= true;
816 rt_info
->rgb_src
= ilo_translate_blend_factor(rt
->rgb_src_factor
);
817 rt_info
->rgb_dst
= ilo_translate_blend_factor(rt
->rgb_dst_factor
);
818 rt_info
->rgb_func
= ilo_translate_blend_func(rt
->rgb_func
);
820 rt_info
->a_src
= ilo_translate_blend_factor(rt
->alpha_src_factor
);
821 rt_info
->a_dst
= ilo_translate_blend_factor(rt
->alpha_dst_factor
);
822 rt_info
->a_func
= ilo_translate_blend_func(rt
->alpha_func
);
825 if (!(rt
->colormask
& PIPE_MASK_A
))
826 rt_info
->argb_write_disables
|= (1 << 3);
827 if (!(rt
->colormask
& PIPE_MASK_R
))
828 rt_info
->argb_write_disables
|= (1 << 2);
829 if (!(rt
->colormask
& PIPE_MASK_G
))
830 rt_info
->argb_write_disables
|= (1 << 1);
831 if (!(rt
->colormask
& PIPE_MASK_B
))
832 rt_info
->argb_write_disables
|= (1 << 0);
834 if (!state
->independent_blend_enable
) {
835 for (i
= 1; i
< ARRAY_SIZE(blend
->rt
); i
++)
836 blend
->rt
[i
] = *rt_info
;
841 memcpy(blend
->effective_rt
, blend
->rt
, sizeof(blend
->rt
));
843 blend
->dummy_rt
.argb_write_disables
= 0xf;
845 if (!ilo_state_cc_init(&blend
->cc
, dev
, &blend
->info
)) {
850 blend
->dual_blend
= util_blend_state_is_dual(state
, 0);
856 ilo_bind_blend_state(struct pipe_context
*pipe
, void *state
)
858 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
862 vec
->dirty
|= ILO_DIRTY_BLEND
;
866 ilo_delete_blend_state(struct pipe_context
*pipe
, void *state
)
872 ilo_create_sampler_state(struct pipe_context
*pipe
,
873 const struct pipe_sampler_state
*state
)
875 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
876 struct ilo_sampler_cso
*sampler
;
877 struct ilo_state_sampler_info info
;
878 struct ilo_state_sampler_border_info border
;
880 sampler
= CALLOC_STRUCT(ilo_sampler_cso
);
883 memset(&info
, 0, sizeof(info
));
885 info
.non_normalized
= !state
->normalized_coords
;
886 if (state
->normalized_coords
) {
887 info
.lod_bias
= state
->lod_bias
;
888 info
.min_lod
= state
->min_lod
;
889 info
.max_lod
= state
->max_lod
;
891 info
.mip_filter
= ilo_translate_mip_filter(state
->min_mip_filter
);
893 /* work around a bug in util_blitter */
894 info
.mip_filter
= GEN6_MIPFILTER_NONE
;
897 if (state
->max_anisotropy
) {
898 info
.min_filter
= GEN6_MAPFILTER_ANISOTROPIC
;
899 info
.mag_filter
= GEN6_MAPFILTER_ANISOTROPIC
;
901 info
.min_filter
= ilo_translate_img_filter(state
->min_img_filter
);
902 info
.mag_filter
= ilo_translate_img_filter(state
->mag_img_filter
);
905 info
.max_anisotropy
= ilo_translate_max_anisotropy(state
->max_anisotropy
);
907 /* use LOD 0 when no mipmapping (see sampler_set_gen6_SAMPLER_STATE()) */
908 if (info
.mip_filter
== GEN6_MIPFILTER_NONE
&& info
.min_lod
> 0.0f
) {
910 info
.mag_filter
= info
.min_filter
;
913 if (state
->seamless_cube_map
) {
914 if (state
->min_img_filter
== PIPE_TEX_FILTER_NEAREST
||
915 state
->mag_img_filter
== PIPE_TEX_FILTER_NEAREST
) {
916 info
.tcx_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
917 info
.tcy_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
918 info
.tcz_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
920 info
.tcx_ctrl
= GEN6_TEXCOORDMODE_CUBE
;
921 info
.tcy_ctrl
= GEN6_TEXCOORDMODE_CUBE
;
922 info
.tcz_ctrl
= GEN6_TEXCOORDMODE_CUBE
;
925 info
.tcx_ctrl
= ilo_translate_address_wrap(state
->wrap_s
);
926 info
.tcy_ctrl
= ilo_translate_address_wrap(state
->wrap_t
);
927 info
.tcz_ctrl
= ilo_translate_address_wrap(state
->wrap_r
);
929 if (ilo_dev_gen(dev
) < ILO_GEN(8)) {
931 * For nearest filtering, PIPE_TEX_WRAP_CLAMP means
932 * PIPE_TEX_WRAP_CLAMP_TO_EDGE; for linear filtering,
933 * PIPE_TEX_WRAP_CLAMP means PIPE_TEX_WRAP_CLAMP_TO_BORDER while
934 * additionally clamping the texture coordinates to [0.0, 1.0].
936 * PIPE_TEX_WRAP_CLAMP is not supported natively until Gen8. The
937 * clamping has to be taken care of in the shaders. There are two
938 * filters here, but let the minification one has a say.
940 const bool clamp_is_to_edge
=
941 (state
->min_img_filter
== PIPE_TEX_FILTER_NEAREST
);
943 if (clamp_is_to_edge
) {
944 if (info
.tcx_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
)
945 info
.tcx_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
946 if (info
.tcy_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
)
947 info
.tcy_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
948 if (info
.tcz_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
)
949 info
.tcz_ctrl
= GEN6_TEXCOORDMODE_CLAMP
;
951 if (info
.tcx_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
) {
952 info
.tcx_ctrl
= GEN6_TEXCOORDMODE_CLAMP_BORDER
;
953 sampler
->saturate_s
= true;
955 if (info
.tcy_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
) {
956 info
.tcy_ctrl
= GEN6_TEXCOORDMODE_CLAMP_BORDER
;
957 sampler
->saturate_t
= true;
959 if (info
.tcz_ctrl
== GEN8_TEXCOORDMODE_HALF_BORDER
) {
960 info
.tcz_ctrl
= GEN6_TEXCOORDMODE_CLAMP_BORDER
;
961 sampler
->saturate_r
= true;
967 if (state
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
)
968 info
.shadow_func
= ilo_translate_shadow_func(state
->compare_func
);
970 ilo_state_sampler_init(&sampler
->sampler
, dev
, &info
);
972 memset(&border
, 0, sizeof(border
));
973 memcpy(border
.rgba
.f
, state
->border_color
.f
, sizeof(border
.rgba
.f
));
975 ilo_state_sampler_border_init(&sampler
->border
, dev
, &border
);
981 ilo_bind_sampler_states(struct pipe_context
*pipe
, unsigned shader
,
982 unsigned start
, unsigned count
, void **samplers
)
984 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
985 struct ilo_sampler_state
*dst
= &vec
->sampler
[shader
];
986 bool changed
= false;
989 assert(start
+ count
<= Elements(dst
->cso
));
992 for (i
= 0; i
< count
; i
++) {
993 if (dst
->cso
[start
+ i
] != samplers
[i
]) {
994 dst
->cso
[start
+ i
] = samplers
[i
];
997 * This function is sometimes called to reduce the number of bound
998 * samplers. Do not consider that as a state change (and create a
999 * new array of SAMPLER_STATE).
1007 for (i
= 0; i
< count
; i
++)
1008 dst
->cso
[start
+ i
] = NULL
;
1013 case PIPE_SHADER_VERTEX
:
1014 vec
->dirty
|= ILO_DIRTY_SAMPLER_VS
;
1016 case PIPE_SHADER_GEOMETRY
:
1017 vec
->dirty
|= ILO_DIRTY_SAMPLER_GS
;
1019 case PIPE_SHADER_FRAGMENT
:
1020 vec
->dirty
|= ILO_DIRTY_SAMPLER_FS
;
1022 case PIPE_SHADER_COMPUTE
:
1023 vec
->dirty
|= ILO_DIRTY_SAMPLER_CS
;
1030 ilo_delete_sampler_state(struct pipe_context
*pipe
, void *state
)
1036 ilo_create_rasterizer_state(struct pipe_context
*pipe
,
1037 const struct pipe_rasterizer_state
*state
)
1039 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1040 struct ilo_rasterizer_state
*rast
;
1041 struct ilo_state_raster_info
*info
;
1043 rast
= CALLOC_STRUCT(ilo_rasterizer_state
);
1046 rast
->state
= *state
;
1050 info
->clip
.clip_enable
= true;
1051 info
->clip
.stats_enable
= true;
1052 info
->clip
.viewport_count
= 1;
1053 info
->clip
.force_rtaindex_zero
= true;
1054 info
->clip
.user_clip_enables
= state
->clip_plane_enable
;
1055 info
->clip
.gb_test_enable
= true;
1056 info
->clip
.xy_test_enable
= true;
1057 info
->clip
.z_far_enable
= state
->depth_clip
;
1058 info
->clip
.z_near_enable
= state
->depth_clip
;
1059 info
->clip
.z_near_zero
= state
->clip_halfz
;
1061 info
->setup
.first_vertex_provoking
= state
->flatshade_first
;
1062 info
->setup
.viewport_transform
= true;
1063 info
->setup
.scissor_enable
= state
->scissor
;
1064 info
->setup
.msaa_enable
= false;
1065 info
->setup
.line_msaa_enable
= false;
1066 info
->point
.aa_enable
= state
->point_smooth
;
1067 info
->point
.programmable_width
= state
->point_size_per_vertex
;
1068 info
->line
.aa_enable
= state
->line_smooth
;
1069 info
->line
.stipple_enable
= state
->line_stipple_enable
;
1070 info
->line
.giq_enable
= true;
1071 info
->line
.giq_last_pixel
= state
->line_last_pixel
;
1072 info
->tri
.front_winding
= ilo_translate_front_ccw(state
->front_ccw
);
1073 info
->tri
.cull_mode
= ilo_translate_cull_face(state
->cull_face
);
1074 info
->tri
.fill_mode_front
= ilo_translate_poly_mode(state
->fill_front
);
1075 info
->tri
.fill_mode_back
= ilo_translate_poly_mode(state
->fill_back
);
1076 info
->tri
.depth_offset_format
= GEN6_ZFORMAT_D24_UNORM_X8_UINT
;
1077 info
->tri
.depth_offset_solid
= state
->offset_tri
;
1078 info
->tri
.depth_offset_wireframe
= state
->offset_line
;
1079 info
->tri
.depth_offset_point
= state
->offset_point
;
1080 info
->tri
.poly_stipple_enable
= state
->poly_stipple_enable
;
1082 info
->scan
.stats_enable
= true;
1083 info
->scan
.sample_count
= 1;
1085 ilo_translate_half_pixel_center(state
->half_pixel_center
);
1086 info
->scan
.sample_mask
= ~0u;
1087 info
->scan
.zw_interp
= GEN6_ZW_INTERP_PIXEL
;
1088 info
->scan
.barycentric_interps
= GEN6_INTERP_PERSPECTIVE_PIXEL
;
1089 info
->scan
.earlyz_control
= GEN7_EDSC_NORMAL
;
1090 info
->scan
.earlyz_op
= ILO_STATE_RASTER_EARLYZ_NORMAL
;
1091 info
->scan
.earlyz_stencil_clear
= false;
1093 info
->params
.any_integer_rt
= false;
1094 info
->params
.hiz_enable
= true;
1095 info
->params
.point_width
=
1096 (state
->point_size
== 0.0f
) ? 1.0f
: state
->point_size
;
1097 info
->params
.line_width
=
1098 (state
->line_width
== 0.0f
) ? 1.0f
: state
->line_width
;
1100 info
->params
.depth_offset_scale
= state
->offset_scale
;
1102 * Scale the constant term. The minimum representable value used by the HW
1103 * is not large enouch to be the minimum resolvable difference.
1105 info
->params
.depth_offset_const
= state
->offset_units
* 2.0f
;
1106 info
->params
.depth_offset_clamp
= state
->offset_clamp
;
1108 ilo_state_raster_init(&rast
->rs
, dev
, info
);
1114 ilo_bind_rasterizer_state(struct pipe_context
*pipe
, void *state
)
1116 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1117 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1119 vec
->rasterizer
= state
;
1121 if (vec
->rasterizer
) {
1122 struct ilo_state_line_stipple_info info
;
1124 info
.pattern
= vec
->rasterizer
->state
.line_stipple_pattern
;
1125 info
.repeat_count
= vec
->rasterizer
->state
.line_stipple_factor
+ 1;
1127 ilo_state_line_stipple_set_info(&vec
->line_stipple
, dev
, &info
);
1130 vec
->dirty
|= ILO_DIRTY_RASTERIZER
;
1134 ilo_delete_rasterizer_state(struct pipe_context
*pipe
, void *state
)
1140 ilo_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
1141 const struct pipe_depth_stencil_alpha_state
*state
)
1143 struct ilo_dsa_state
*dsa
;
1146 dsa
= CALLOC_STRUCT(ilo_dsa_state
);
1149 dsa
->depth
.cv_has_buffer
= true;
1150 dsa
->depth
.test_enable
= state
->depth
.enabled
;
1151 dsa
->depth
.write_enable
= state
->depth
.writemask
;
1152 dsa
->depth
.test_func
= ilo_translate_compare_func(state
->depth
.func
);
1154 dsa
->stencil
.cv_has_buffer
= true;
1155 for (i
= 0; i
< ARRAY_SIZE(state
->stencil
); i
++) {
1156 const struct pipe_stencil_state
*stencil
= &state
->stencil
[i
];
1157 struct ilo_state_cc_stencil_op_info
*op
;
1159 if (!stencil
->enabled
)
1163 dsa
->stencil
.test_enable
= true;
1164 dsa
->stencil_front
.test_mask
= stencil
->valuemask
;
1165 dsa
->stencil_front
.write_mask
= stencil
->writemask
;
1167 op
= &dsa
->stencil
.front
;
1169 dsa
->stencil
.twosided_enable
= true;
1170 dsa
->stencil_back
.test_mask
= stencil
->valuemask
;
1171 dsa
->stencil_back
.write_mask
= stencil
->writemask
;
1173 op
= &dsa
->stencil
.back
;
1176 op
->test_func
= ilo_translate_compare_func(stencil
->func
);
1177 op
->fail_op
= ilo_translate_stencil_op(stencil
->fail_op
);
1178 op
->zfail_op
= ilo_translate_stencil_op(stencil
->zfail_op
);
1179 op
->zpass_op
= ilo_translate_stencil_op(stencil
->zpass_op
);
1182 dsa
->alpha_test
= state
->alpha
.enabled
;
1183 dsa
->alpha_ref
= state
->alpha
.ref_value
;
1184 dsa
->alpha_func
= ilo_translate_compare_func(state
->alpha
.func
);
1190 ilo_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
1192 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1196 vec
->cc_params
.alpha_ref
= vec
->dsa
->alpha_ref
;
1197 vec
->cc_params
.stencil_front
.test_mask
=
1198 vec
->dsa
->stencil_front
.test_mask
;
1199 vec
->cc_params
.stencil_front
.write_mask
=
1200 vec
->dsa
->stencil_front
.write_mask
;
1201 vec
->cc_params
.stencil_back
.test_mask
=
1202 vec
->dsa
->stencil_back
.test_mask
;
1203 vec
->cc_params
.stencil_back
.write_mask
=
1204 vec
->dsa
->stencil_back
.write_mask
;
1207 vec
->dirty
|= ILO_DIRTY_DSA
;
1211 ilo_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
1217 ilo_create_fs_state(struct pipe_context
*pipe
,
1218 const struct pipe_shader_state
*state
)
1220 struct ilo_context
*ilo
= ilo_context(pipe
);
1221 struct ilo_shader_state
*shader
;
1223 shader
= ilo_shader_create_fs(ilo
->dev
, state
, &ilo
->state_vector
);
1226 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
1232 ilo_bind_fs_state(struct pipe_context
*pipe
, void *state
)
1234 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1238 vec
->dirty
|= ILO_DIRTY_FS
;
1242 ilo_delete_fs_state(struct pipe_context
*pipe
, void *state
)
1244 struct ilo_context
*ilo
= ilo_context(pipe
);
1245 struct ilo_shader_state
*fs
= (struct ilo_shader_state
*) state
;
1247 ilo_shader_cache_remove(ilo
->shader_cache
, fs
);
1248 ilo_shader_destroy(fs
);
1252 ilo_create_vs_state(struct pipe_context
*pipe
,
1253 const struct pipe_shader_state
*state
)
1255 struct ilo_context
*ilo
= ilo_context(pipe
);
1256 struct ilo_shader_state
*shader
;
1258 shader
= ilo_shader_create_vs(ilo
->dev
, state
, &ilo
->state_vector
);
1261 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
1267 ilo_bind_vs_state(struct pipe_context
*pipe
, void *state
)
1269 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1273 vec
->dirty
|= ILO_DIRTY_VS
;
1277 ilo_delete_vs_state(struct pipe_context
*pipe
, void *state
)
1279 struct ilo_context
*ilo
= ilo_context(pipe
);
1280 struct ilo_shader_state
*vs
= (struct ilo_shader_state
*) state
;
1282 ilo_shader_cache_remove(ilo
->shader_cache
, vs
);
1283 ilo_shader_destroy(vs
);
1287 ilo_create_gs_state(struct pipe_context
*pipe
,
1288 const struct pipe_shader_state
*state
)
1290 struct ilo_context
*ilo
= ilo_context(pipe
);
1291 struct ilo_shader_state
*shader
;
1293 shader
= ilo_shader_create_gs(ilo
->dev
, state
, &ilo
->state_vector
);
1296 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
1302 ilo_bind_gs_state(struct pipe_context
*pipe
, void *state
)
1304 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1306 /* util_blitter may set this unnecessarily */
1307 if (vec
->gs
== state
)
1312 vec
->dirty
|= ILO_DIRTY_GS
;
1316 ilo_delete_gs_state(struct pipe_context
*pipe
, void *state
)
1318 struct ilo_context
*ilo
= ilo_context(pipe
);
1319 struct ilo_shader_state
*gs
= (struct ilo_shader_state
*) state
;
1321 ilo_shader_cache_remove(ilo
->shader_cache
, gs
);
1322 ilo_shader_destroy(gs
);
1326 ilo_create_vertex_elements_state(struct pipe_context
*pipe
,
1327 unsigned num_elements
,
1328 const struct pipe_vertex_element
*elements
)
1330 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1331 struct ilo_state_vf_element_info vf_elements
[PIPE_MAX_ATTRIBS
];
1332 unsigned instance_divisors
[PIPE_MAX_ATTRIBS
];
1333 struct ilo_state_vf_info vf_info
;
1334 struct ilo_ve_state
*ve
;
1337 ve
= CALLOC_STRUCT(ilo_ve_state
);
1340 for (i
= 0; i
< num_elements
; i
++) {
1341 const struct pipe_vertex_element
*elem
= &elements
[i
];
1342 struct ilo_state_vf_element_info
*attr
= &vf_elements
[i
];
1346 * map the pipe vb to the hardware vb, which has a fixed instance
1349 for (hw_idx
= 0; hw_idx
< ve
->vb_count
; hw_idx
++) {
1350 if (ve
->vb_mapping
[hw_idx
] == elem
->vertex_buffer_index
&&
1351 instance_divisors
[hw_idx
] == elem
->instance_divisor
)
1355 /* create one if there is no matching hardware vb */
1356 if (hw_idx
>= ve
->vb_count
) {
1357 hw_idx
= ve
->vb_count
++;
1359 ve
->vb_mapping
[hw_idx
] = elem
->vertex_buffer_index
;
1360 instance_divisors
[hw_idx
] = elem
->instance_divisor
;
1363 attr
->buffer
= hw_idx
;
1364 attr
->vertex_offset
= elem
->src_offset
;
1365 attr
->format
= ilo_format_translate_vertex(dev
, elem
->src_format
);
1366 attr
->format_size
= util_format_get_blocksize(elem
->src_format
);
1367 attr
->component_count
= util_format_get_nr_components(elem
->src_format
);
1368 attr
->is_integer
= util_format_is_pure_integer(elem
->src_format
);
1369 attr
->is_double
= (util_format_is_float(elem
->src_format
) &&
1370 attr
->format_size
== attr
->component_count
* 8);
1372 attr
->instancing_enable
= (elem
->instance_divisor
!= 0);
1373 attr
->instancing_step_rate
= elem
->instance_divisor
;
1376 memset(&vf_info
, 0, sizeof(vf_info
));
1377 vf_info
.data
= ve
->vf_data
;
1378 vf_info
.data_size
= sizeof(ve
->vf_data
);
1379 vf_info
.elements
= vf_elements
;
1380 vf_info
.element_count
= num_elements
;
1381 /* vf_info.params and ve->vf_params are both zeroed */
1383 if (!ilo_state_vf_init(&ve
->vf
, dev
, &vf_info
)) {
1392 ilo_bind_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
1394 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1398 vec
->dirty
|= ILO_DIRTY_VE
;
1402 ilo_delete_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
1404 struct ilo_ve_state
*ve
= state
;
1410 ilo_set_blend_color(struct pipe_context
*pipe
,
1411 const struct pipe_blend_color
*state
)
1413 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1415 memcpy(vec
->cc_params
.blend_rgba
, state
->color
, sizeof(state
->color
));
1417 vec
->dirty
|= ILO_DIRTY_BLEND_COLOR
;
1421 ilo_set_stencil_ref(struct pipe_context
*pipe
,
1422 const struct pipe_stencil_ref
*state
)
1424 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1426 /* util_blitter may set this unnecessarily */
1427 if (!memcmp(&vec
->stencil_ref
, state
, sizeof(*state
)))
1430 vec
->stencil_ref
= *state
;
1432 vec
->cc_params
.stencil_front
.test_ref
= state
->ref_value
[0];
1433 vec
->cc_params
.stencil_back
.test_ref
= state
->ref_value
[1];
1435 vec
->dirty
|= ILO_DIRTY_STENCIL_REF
;
1439 ilo_set_sample_mask(struct pipe_context
*pipe
,
1440 unsigned sample_mask
)
1442 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1444 /* util_blitter may set this unnecessarily */
1445 if (vec
->sample_mask
== sample_mask
)
1448 vec
->sample_mask
= sample_mask
;
1450 vec
->dirty
|= ILO_DIRTY_SAMPLE_MASK
;
1454 ilo_set_clip_state(struct pipe_context
*pipe
,
1455 const struct pipe_clip_state
*state
)
1457 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1461 vec
->dirty
|= ILO_DIRTY_CLIP
;
1465 ilo_set_constant_buffer(struct pipe_context
*pipe
,
1466 uint shader
, uint index
,
1467 struct pipe_constant_buffer
*buf
)
1469 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1470 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1471 struct ilo_cbuf_state
*cbuf
= &vec
->cbuf
[shader
];
1472 const unsigned count
= 1;
1475 assert(shader
< Elements(vec
->cbuf
));
1476 assert(index
+ count
<= Elements(vec
->cbuf
[shader
].cso
));
1479 for (i
= 0; i
< count
; i
++) {
1480 struct ilo_cbuf_cso
*cso
= &cbuf
->cso
[index
+ i
];
1482 pipe_resource_reference(&cso
->resource
, buf
[i
].buffer
);
1484 cso
->info
.access
= ILO_STATE_SURFACE_ACCESS_DP_DATA
;
1485 cso
->info
.format
= GEN6_FORMAT_R32G32B32A32_FLOAT
;
1486 cso
->info
.format_size
= 16;
1487 cso
->info
.struct_size
= 16;
1488 cso
->info
.readonly
= true;
1489 cso
->info
.size
= buf
[i
].buffer_size
;
1491 if (buf
[i
].buffer
) {
1492 cso
->info
.buf
= ilo_buffer(buf
[i
].buffer
);
1493 cso
->info
.offset
= buf
[i
].buffer_offset
;
1495 memset(&cso
->surface
, 0, sizeof(cso
->surface
));
1496 ilo_state_surface_init_for_buffer(&cso
->surface
, dev
, &cso
->info
);
1497 cso
->surface
.bo
= cso
->info
.buf
->bo
;
1499 cso
->user_buffer
= NULL
;
1501 cbuf
->enabled_mask
|= 1 << (index
+ i
);
1502 } else if (buf
[i
].user_buffer
) {
1503 cso
->info
.buf
= NULL
;
1504 /* buffer_offset does not apply for user buffer */
1505 cso
->user_buffer
= buf
[i
].user_buffer
;
1507 cbuf
->enabled_mask
|= 1 << (index
+ i
);
1509 cso
->info
.buf
= NULL
;
1511 cso
->user_buffer
= NULL
;
1513 cbuf
->enabled_mask
&= ~(1 << (index
+ i
));
1517 for (i
= 0; i
< count
; i
++) {
1518 struct ilo_cbuf_cso
*cso
= &cbuf
->cso
[index
+ i
];
1520 pipe_resource_reference(&cso
->resource
, NULL
);
1522 cso
->info
.buf
= NULL
;
1524 cso
->user_buffer
= NULL
;
1526 cbuf
->enabled_mask
&= ~(1 << (index
+ i
));
1530 vec
->dirty
|= ILO_DIRTY_CBUF
;
1534 fb_set_blend_caps(const struct ilo_dev
*dev
,
1535 enum pipe_format format
,
1536 struct ilo_fb_blend_caps
*caps
)
1538 const struct util_format_description
*desc
=
1539 util_format_description(format
);
1540 const int ch
= util_format_get_first_non_void_channel(format
);
1542 memset(caps
, 0, sizeof(*caps
));
1544 if (format
== PIPE_FORMAT_NONE
|| desc
->is_mixed
)
1547 caps
->is_unorm
= (ch
>= 0 && desc
->channel
[ch
].normalized
&&
1548 desc
->channel
[ch
].type
== UTIL_FORMAT_TYPE_UNSIGNED
&&
1549 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
);
1550 caps
->is_integer
= util_format_is_pure_integer(format
);
1553 * From the Sandy Bridge PRM, volume 2 part 1, page 365:
1555 * "Logic Ops are only supported on *_UNORM surfaces (excluding _SRGB
1556 * variants), otherwise Logic Ops must be DISABLED."
1558 * According to the classic driver, this is lifted on Gen8+.
1560 caps
->can_logicop
= (ilo_dev_gen(dev
) >= ILO_GEN(8) || caps
->is_unorm
);
1562 /* no blending for pure integer formats */
1563 caps
->can_blend
= !caps
->is_integer
;
1566 * From the Sandy Bridge PRM, volume 2 part 1, page 382:
1568 * "Alpha Test can only be enabled if Pixel Shader outputs a float
1571 caps
->can_alpha_test
= !caps
->is_integer
;
1573 caps
->force_dst_alpha_one
=
1574 (ilo_format_translate_render(dev
, format
) !=
1575 ilo_format_translate_color(dev
, format
));
1578 if (caps
->force_dst_alpha_one
) {
1579 enum pipe_format render_format
;
1582 case PIPE_FORMAT_B8G8R8X8_UNORM
:
1583 render_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
1586 render_format
= PIPE_FORMAT_NONE
;
1590 assert(ilo_format_translate_render(dev
, format
) ==
1591 ilo_format_translate_color(dev
, render_format
));
1596 ilo_set_framebuffer_state(struct pipe_context
*pipe
,
1597 const struct pipe_framebuffer_state
*state
)
1599 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1600 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1601 struct ilo_fb_state
*fb
= &vec
->fb
;
1602 const struct pipe_surface
*first_surf
= NULL
;
1605 util_copy_framebuffer_state(&fb
->state
, state
);
1607 fb
->has_integer_rt
= false;
1608 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
1609 if (state
->cbufs
[i
]) {
1610 fb_set_blend_caps(dev
, state
->cbufs
[i
]->format
, &fb
->blend_caps
[i
]);
1612 fb
->has_integer_rt
|= fb
->blend_caps
[i
].is_integer
;
1615 first_surf
= state
->cbufs
[i
];
1617 fb_set_blend_caps(dev
, PIPE_FORMAT_NONE
, &fb
->blend_caps
[i
]);
1621 if (!first_surf
&& state
->zsbuf
)
1622 first_surf
= state
->zsbuf
;
1624 fb
->num_samples
= (first_surf
) ? first_surf
->texture
->nr_samples
: 1;
1625 if (!fb
->num_samples
)
1626 fb
->num_samples
= 1;
1629 const struct ilo_surface_cso
*cso
=
1630 (const struct ilo_surface_cso
*) state
->zsbuf
;
1632 fb
->has_hiz
= cso
->u
.zs
.hiz_bo
;
1633 fb
->depth_offset_format
=
1634 ilo_state_zs_get_depth_format(&cso
->u
.zs
, dev
);
1636 fb
->has_hiz
= false;
1637 fb
->depth_offset_format
= GEN6_ZFORMAT_D32_FLOAT
;
1641 * The PRMs list several restrictions when the framebuffer has more than
1642 * one surface. It seems they are actually lifted on GEN6+.
1645 vec
->dirty
|= ILO_DIRTY_FB
;
1649 ilo_set_polygon_stipple(struct pipe_context
*pipe
,
1650 const struct pipe_poly_stipple
*state
)
1652 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1653 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1654 struct ilo_state_poly_stipple_info info
;
1657 for (i
= 0; i
< 32; i
++)
1658 info
.pattern
[i
] = state
->stipple
[i
];
1660 ilo_state_poly_stipple_set_info(&vec
->poly_stipple
, dev
, &info
);
1662 vec
->dirty
|= ILO_DIRTY_POLY_STIPPLE
;
1666 ilo_set_scissor_states(struct pipe_context
*pipe
,
1667 unsigned start_slot
,
1668 unsigned num_scissors
,
1669 const struct pipe_scissor_state
*scissors
)
1671 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1674 for (i
= 0; i
< num_scissors
; i
++) {
1675 struct ilo_state_viewport_scissor_info
*info
=
1676 &vec
->viewport
.scissors
[start_slot
+ i
];
1678 if (scissors
[i
].minx
< scissors
[i
].maxx
&&
1679 scissors
[i
].miny
< scissors
[i
].maxy
) {
1680 info
->min_x
= scissors
[i
].minx
;
1681 info
->min_y
= scissors
[i
].miny
;
1682 info
->max_x
= scissors
[i
].maxx
- 1;
1683 info
->max_y
= scissors
[i
].maxy
- 1;
1692 vec
->dirty
|= ILO_DIRTY_SCISSOR
;
1696 ilo_set_viewport_states(struct pipe_context
*pipe
,
1697 unsigned start_slot
,
1698 unsigned num_viewports
,
1699 const struct pipe_viewport_state
*viewports
)
1701 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1706 for (i
= 0; i
< num_viewports
; i
++) {
1707 struct ilo_state_viewport_matrix_info
*info
=
1708 &vec
->viewport
.matrices
[start_slot
+ i
];
1710 memcpy(info
->scale
, viewports
[i
].scale
, sizeof(info
->scale
));
1711 memcpy(info
->translate
, viewports
[i
].translate
,
1712 sizeof(info
->translate
));
1715 if (vec
->viewport
.params
.count
< start_slot
+ num_viewports
)
1716 vec
->viewport
.params
.count
= start_slot
+ num_viewports
;
1718 /* need to save viewport 0 for util_blitter */
1719 if (!start_slot
&& num_viewports
)
1720 vec
->viewport
.viewport0
= viewports
[0];
1723 if (vec
->viewport
.params
.count
<= start_slot
+ num_viewports
&&
1724 vec
->viewport
.params
.count
> start_slot
)
1725 vec
->viewport
.params
.count
= start_slot
;
1728 vec
->dirty
|= ILO_DIRTY_VIEWPORT
;
1732 ilo_set_sampler_views(struct pipe_context
*pipe
, unsigned shader
,
1733 unsigned start
, unsigned count
,
1734 struct pipe_sampler_view
**views
)
1736 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1737 struct ilo_view_state
*dst
= &vec
->view
[shader
];
1740 assert(start
+ count
<= Elements(dst
->states
));
1743 for (i
= 0; i
< count
; i
++)
1744 pipe_sampler_view_reference(&dst
->states
[start
+ i
], views
[i
]);
1747 for (i
= 0; i
< count
; i
++)
1748 pipe_sampler_view_reference(&dst
->states
[start
+ i
], NULL
);
1751 if (dst
->count
<= start
+ count
) {
1757 while (count
> 0 && !dst
->states
[count
- 1])
1764 case PIPE_SHADER_VERTEX
:
1765 vec
->dirty
|= ILO_DIRTY_VIEW_VS
;
1767 case PIPE_SHADER_GEOMETRY
:
1768 vec
->dirty
|= ILO_DIRTY_VIEW_GS
;
1770 case PIPE_SHADER_FRAGMENT
:
1771 vec
->dirty
|= ILO_DIRTY_VIEW_FS
;
1773 case PIPE_SHADER_COMPUTE
:
1774 vec
->dirty
|= ILO_DIRTY_VIEW_CS
;
1780 ilo_set_shader_resources(struct pipe_context
*pipe
,
1781 unsigned start
, unsigned count
,
1782 struct pipe_surface
**surfaces
)
1784 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1785 struct ilo_resource_state
*dst
= &vec
->resource
;
1788 assert(start
+ count
<= Elements(dst
->states
));
1791 for (i
= 0; i
< count
; i
++)
1792 pipe_surface_reference(&dst
->states
[start
+ i
], surfaces
[i
]);
1795 for (i
= 0; i
< count
; i
++)
1796 pipe_surface_reference(&dst
->states
[start
+ i
], NULL
);
1799 if (dst
->count
<= start
+ count
) {
1805 while (count
> 0 && !dst
->states
[count
- 1])
1811 vec
->dirty
|= ILO_DIRTY_RESOURCE
;
1815 ilo_set_vertex_buffers(struct pipe_context
*pipe
,
1816 unsigned start_slot
, unsigned num_buffers
,
1817 const struct pipe_vertex_buffer
*buffers
)
1819 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1822 /* no PIPE_CAP_USER_VERTEX_BUFFERS */
1824 for (i
= 0; i
< num_buffers
; i
++)
1825 assert(!buffers
[i
].user_buffer
);
1828 util_set_vertex_buffers_mask(vec
->vb
.states
,
1829 &vec
->vb
.enabled_mask
, buffers
, start_slot
, num_buffers
);
1831 vec
->dirty
|= ILO_DIRTY_VB
;
1835 ilo_set_index_buffer(struct pipe_context
*pipe
,
1836 const struct pipe_index_buffer
*state
)
1838 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1841 pipe_resource_reference(&vec
->ib
.state
.buffer
, state
->buffer
);
1842 vec
->ib
.state
= *state
;
1844 pipe_resource_reference(&vec
->ib
.state
.buffer
, NULL
);
1845 memset(&vec
->ib
.state
, 0, sizeof(vec
->ib
.state
));
1848 vec
->dirty
|= ILO_DIRTY_IB
;
1851 static struct pipe_stream_output_target
*
1852 ilo_create_stream_output_target(struct pipe_context
*pipe
,
1853 struct pipe_resource
*res
,
1854 unsigned buffer_offset
,
1855 unsigned buffer_size
)
1857 struct pipe_stream_output_target
*target
;
1859 target
= MALLOC_STRUCT(pipe_stream_output_target
);
1862 pipe_reference_init(&target
->reference
, 1);
1863 target
->buffer
= NULL
;
1864 pipe_resource_reference(&target
->buffer
, res
);
1865 target
->context
= pipe
;
1866 target
->buffer_offset
= buffer_offset
;
1867 target
->buffer_size
= buffer_size
;
1873 ilo_set_stream_output_targets(struct pipe_context
*pipe
,
1874 unsigned num_targets
,
1875 struct pipe_stream_output_target
**targets
,
1876 const unsigned *offset
)
1878 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1880 unsigned append_bitmask
= 0;
1885 /* util_blitter may set this unnecessarily */
1886 if (!vec
->so
.count
&& !num_targets
)
1889 for (i
= 0; i
< num_targets
; i
++) {
1890 pipe_so_target_reference(&vec
->so
.states
[i
], targets
[i
]);
1891 if (offset
[i
] == (unsigned)-1)
1892 append_bitmask
|= 1 << i
;
1895 for (; i
< vec
->so
.count
; i
++)
1896 pipe_so_target_reference(&vec
->so
.states
[i
], NULL
);
1898 vec
->so
.count
= num_targets
;
1899 vec
->so
.append_bitmask
= append_bitmask
;
1901 vec
->so
.enabled
= (vec
->so
.count
> 0);
1903 vec
->dirty
|= ILO_DIRTY_SO
;
1907 ilo_stream_output_target_destroy(struct pipe_context
*pipe
,
1908 struct pipe_stream_output_target
*target
)
1910 pipe_resource_reference(&target
->buffer
, NULL
);
1914 static struct pipe_sampler_view
*
1915 ilo_create_sampler_view(struct pipe_context
*pipe
,
1916 struct pipe_resource
*res
,
1917 const struct pipe_sampler_view
*templ
)
1919 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1920 struct ilo_view_cso
*view
;
1922 view
= CALLOC_STRUCT(ilo_view_cso
);
1925 view
->base
= *templ
;
1926 pipe_reference_init(&view
->base
.reference
, 1);
1927 view
->base
.texture
= NULL
;
1928 pipe_resource_reference(&view
->base
.texture
, res
);
1929 view
->base
.context
= pipe
;
1931 if (res
->target
== PIPE_BUFFER
) {
1932 struct ilo_state_surface_buffer_info info
;
1934 memset(&info
, 0, sizeof(info
));
1935 info
.buf
= ilo_buffer(res
);
1936 info
.access
= ILO_STATE_SURFACE_ACCESS_SAMPLER
;
1937 info
.format
= ilo_format_translate_color(dev
, templ
->format
);
1938 info
.format_size
= util_format_get_blocksize(templ
->format
);
1939 info
.struct_size
= info
.format_size
;
1940 info
.readonly
= true;
1941 info
.offset
= templ
->u
.buf
.first_element
* info
.struct_size
;
1942 info
.size
= (templ
->u
.buf
.last_element
-
1943 templ
->u
.buf
.first_element
+ 1) * info
.struct_size
;
1945 ilo_state_surface_init_for_buffer(&view
->surface
, dev
, &info
);
1946 view
->surface
.bo
= info
.buf
->bo
;
1948 struct ilo_texture
*tex
= ilo_texture(res
);
1949 struct ilo_state_surface_image_info info
;
1951 /* warn about degraded performance because of a missing binding flag */
1952 if (tex
->image
.tiling
== GEN6_TILING_NONE
&&
1953 !(tex
->base
.bind
& PIPE_BIND_SAMPLER_VIEW
)) {
1954 ilo_warn("creating sampler view for a resource "
1955 "not created for sampling\n");
1958 memset(&info
, 0, sizeof(info
));
1959 info
.img
= &tex
->image
;
1961 info
.access
= ILO_STATE_SURFACE_ACCESS_SAMPLER
;
1963 if (templ
->format
== PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
&&
1964 tex
->image
.separate_stencil
) {
1965 info
.format
= ilo_format_translate_texture(dev
,
1966 PIPE_FORMAT_Z32_FLOAT
);
1968 info
.format
= ilo_format_translate_texture(dev
, templ
->format
);
1971 info
.is_cube_map
= (tex
->image
.target
== PIPE_TEXTURE_CUBE
||
1972 tex
->image
.target
== PIPE_TEXTURE_CUBE_ARRAY
);
1973 info
.is_array
= util_resource_is_array_texture(&tex
->base
);
1974 info
.readonly
= true;
1976 info
.level_base
= templ
->u
.tex
.first_level
;
1977 info
.level_count
= templ
->u
.tex
.last_level
-
1978 templ
->u
.tex
.first_level
+ 1;
1979 info
.slice_base
= templ
->u
.tex
.first_layer
;
1980 info
.slice_count
= templ
->u
.tex
.last_layer
-
1981 templ
->u
.tex
.first_layer
+ 1;
1983 ilo_state_surface_init_for_image(&view
->surface
, dev
, &info
);
1984 view
->surface
.bo
= info
.img
->bo
;
1991 ilo_sampler_view_destroy(struct pipe_context
*pipe
,
1992 struct pipe_sampler_view
*view
)
1994 pipe_resource_reference(&view
->texture
, NULL
);
1998 static struct pipe_surface
*
1999 ilo_create_surface(struct pipe_context
*pipe
,
2000 struct pipe_resource
*res
,
2001 const struct pipe_surface
*templ
)
2003 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
2004 struct ilo_texture
*tex
= ilo_texture(res
);
2005 struct ilo_surface_cso
*surf
;
2007 surf
= CALLOC_STRUCT(ilo_surface_cso
);
2010 surf
->base
= *templ
;
2011 pipe_reference_init(&surf
->base
.reference
, 1);
2012 surf
->base
.texture
= NULL
;
2013 pipe_resource_reference(&surf
->base
.texture
, &tex
->base
);
2015 surf
->base
.context
= pipe
;
2016 surf
->base
.width
= u_minify(tex
->base
.width0
, templ
->u
.tex
.level
);
2017 surf
->base
.height
= u_minify(tex
->base
.height0
, templ
->u
.tex
.level
);
2019 surf
->is_rt
= !util_format_is_depth_or_stencil(templ
->format
);
2022 struct ilo_state_surface_image_info info
;
2025 assert(tex
->base
.target
!= PIPE_BUFFER
);
2027 memset(&info
, 0, sizeof(info
));
2028 info
.img
= &tex
->image
;
2029 info
.access
= ILO_STATE_SURFACE_ACCESS_DP_RENDER
;
2030 info
.format
= ilo_format_translate_render(dev
, templ
->format
);
2031 info
.is_array
= util_resource_is_array_texture(&tex
->base
);
2032 info
.level_base
= templ
->u
.tex
.level
;
2033 info
.level_count
= 1;
2034 info
.slice_base
= templ
->u
.tex
.first_layer
;
2035 info
.slice_count
= templ
->u
.tex
.last_layer
-
2036 templ
->u
.tex
.first_layer
+ 1;
2038 ilo_state_surface_init_for_image(&surf
->u
.rt
, dev
, &info
);
2039 surf
->u
.rt
.bo
= info
.img
->bo
;
2041 struct ilo_state_zs_info info
;
2043 assert(res
->target
!= PIPE_BUFFER
);
2045 memset(&info
, 0, sizeof(info
));
2047 if (templ
->format
== PIPE_FORMAT_S8_UINT
) {
2048 info
.s_img
= &tex
->image
;
2050 info
.z_img
= &tex
->image
;
2051 info
.s_img
= (tex
->separate_s8
) ? &tex
->separate_s8
->image
: NULL
;
2054 ilo_image_can_enable_aux(&tex
->image
, templ
->u
.tex
.level
);
2057 info
.level
= templ
->u
.tex
.level
;
2058 info
.slice_base
= templ
->u
.tex
.first_layer
;
2059 info
.slice_count
= templ
->u
.tex
.last_layer
-
2060 templ
->u
.tex
.first_layer
+ 1;
2062 ilo_state_zs_init(&surf
->u
.zs
, dev
, &info
);
2065 surf
->u
.zs
.depth_bo
= info
.z_img
->bo
;
2066 if (info
.hiz_enable
)
2067 surf
->u
.zs
.hiz_bo
= info
.z_img
->aux
.bo
;
2071 surf
->u
.zs
.stencil_bo
= info
.s_img
->bo
;
2078 ilo_surface_destroy(struct pipe_context
*pipe
,
2079 struct pipe_surface
*surface
)
2081 pipe_resource_reference(&surface
->texture
, NULL
);
2086 ilo_create_compute_state(struct pipe_context
*pipe
,
2087 const struct pipe_compute_state
*state
)
2089 struct ilo_context
*ilo
= ilo_context(pipe
);
2090 struct ilo_shader_state
*shader
;
2092 shader
= ilo_shader_create_cs(ilo
->dev
, state
, &ilo
->state_vector
);
2095 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
2101 ilo_bind_compute_state(struct pipe_context
*pipe
, void *state
)
2103 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
2107 vec
->dirty
|= ILO_DIRTY_CS
;
2111 ilo_delete_compute_state(struct pipe_context
*pipe
, void *state
)
2113 struct ilo_context
*ilo
= ilo_context(pipe
);
2114 struct ilo_shader_state
*cs
= (struct ilo_shader_state
*) state
;
2116 ilo_shader_cache_remove(ilo
->shader_cache
, cs
);
2117 ilo_shader_destroy(cs
);
2121 ilo_set_compute_resources(struct pipe_context
*pipe
,
2122 unsigned start
, unsigned count
,
2123 struct pipe_surface
**surfaces
)
2125 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
2126 struct ilo_resource_state
*dst
= &vec
->cs_resource
;
2129 assert(start
+ count
<= Elements(dst
->states
));
2132 for (i
= 0; i
< count
; i
++)
2133 pipe_surface_reference(&dst
->states
[start
+ i
], surfaces
[i
]);
2136 for (i
= 0; i
< count
; i
++)
2137 pipe_surface_reference(&dst
->states
[start
+ i
], NULL
);
2140 if (dst
->count
<= start
+ count
) {
2146 while (count
> 0 && !dst
->states
[count
- 1])
2152 vec
->dirty
|= ILO_DIRTY_CS_RESOURCE
;
2156 ilo_set_global_binding(struct pipe_context
*pipe
,
2157 unsigned start
, unsigned count
,
2158 struct pipe_resource
**resources
,
2161 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
2162 struct ilo_global_binding_cso
*dst
;
2166 if (vec
->global_binding
.count
< start
+ count
) {
2168 const unsigned old_size
= vec
->global_binding
.bindings
.size
;
2169 const unsigned new_size
= sizeof(*dst
) * (start
+ count
);
2171 if (old_size
< new_size
) {
2172 util_dynarray_resize(&vec
->global_binding
.bindings
, new_size
);
2173 memset(vec
->global_binding
.bindings
.data
+ old_size
, 0,
2174 new_size
- old_size
);
2177 count
= vec
->global_binding
.count
- start
;
2181 dst
= util_dynarray_element(&vec
->global_binding
.bindings
,
2182 struct ilo_global_binding_cso
, start
);
2185 for (i
= 0; i
< count
; i
++) {
2186 pipe_resource_reference(&dst
[i
].resource
, resources
[i
]);
2187 dst
[i
].handle
= handles
[i
];
2190 for (i
= 0; i
< count
; i
++) {
2191 pipe_resource_reference(&dst
[i
].resource
, NULL
);
2192 dst
[i
].handle
= NULL
;
2196 if (vec
->global_binding
.count
<= start
+ count
) {
2197 dst
= util_dynarray_begin(&vec
->global_binding
.bindings
);
2204 while (count
> 0 && !dst
[count
- 1].resource
)
2207 vec
->global_binding
.count
= count
;
2210 vec
->dirty
|= ILO_DIRTY_GLOBAL_BINDING
;
2214 * Initialize state-related functions.
2217 ilo_init_state_functions(struct ilo_context
*ilo
)
2219 STATIC_ASSERT(ILO_STATE_COUNT
<= 32);
2221 ilo
->base
.create_blend_state
= ilo_create_blend_state
;
2222 ilo
->base
.bind_blend_state
= ilo_bind_blend_state
;
2223 ilo
->base
.delete_blend_state
= ilo_delete_blend_state
;
2224 ilo
->base
.create_sampler_state
= ilo_create_sampler_state
;
2225 ilo
->base
.bind_sampler_states
= ilo_bind_sampler_states
;
2226 ilo
->base
.delete_sampler_state
= ilo_delete_sampler_state
;
2227 ilo
->base
.create_rasterizer_state
= ilo_create_rasterizer_state
;
2228 ilo
->base
.bind_rasterizer_state
= ilo_bind_rasterizer_state
;
2229 ilo
->base
.delete_rasterizer_state
= ilo_delete_rasterizer_state
;
2230 ilo
->base
.create_depth_stencil_alpha_state
= ilo_create_depth_stencil_alpha_state
;
2231 ilo
->base
.bind_depth_stencil_alpha_state
= ilo_bind_depth_stencil_alpha_state
;
2232 ilo
->base
.delete_depth_stencil_alpha_state
= ilo_delete_depth_stencil_alpha_state
;
2233 ilo
->base
.create_fs_state
= ilo_create_fs_state
;
2234 ilo
->base
.bind_fs_state
= ilo_bind_fs_state
;
2235 ilo
->base
.delete_fs_state
= ilo_delete_fs_state
;
2236 ilo
->base
.create_vs_state
= ilo_create_vs_state
;
2237 ilo
->base
.bind_vs_state
= ilo_bind_vs_state
;
2238 ilo
->base
.delete_vs_state
= ilo_delete_vs_state
;
2239 ilo
->base
.create_gs_state
= ilo_create_gs_state
;
2240 ilo
->base
.bind_gs_state
= ilo_bind_gs_state
;
2241 ilo
->base
.delete_gs_state
= ilo_delete_gs_state
;
2242 ilo
->base
.create_vertex_elements_state
= ilo_create_vertex_elements_state
;
2243 ilo
->base
.bind_vertex_elements_state
= ilo_bind_vertex_elements_state
;
2244 ilo
->base
.delete_vertex_elements_state
= ilo_delete_vertex_elements_state
;
2246 ilo
->base
.set_blend_color
= ilo_set_blend_color
;
2247 ilo
->base
.set_stencil_ref
= ilo_set_stencil_ref
;
2248 ilo
->base
.set_sample_mask
= ilo_set_sample_mask
;
2249 ilo
->base
.set_clip_state
= ilo_set_clip_state
;
2250 ilo
->base
.set_constant_buffer
= ilo_set_constant_buffer
;
2251 ilo
->base
.set_framebuffer_state
= ilo_set_framebuffer_state
;
2252 ilo
->base
.set_polygon_stipple
= ilo_set_polygon_stipple
;
2253 ilo
->base
.set_scissor_states
= ilo_set_scissor_states
;
2254 ilo
->base
.set_viewport_states
= ilo_set_viewport_states
;
2255 ilo
->base
.set_sampler_views
= ilo_set_sampler_views
;
2256 ilo
->base
.set_shader_resources
= ilo_set_shader_resources
;
2257 ilo
->base
.set_vertex_buffers
= ilo_set_vertex_buffers
;
2258 ilo
->base
.set_index_buffer
= ilo_set_index_buffer
;
2260 ilo
->base
.create_stream_output_target
= ilo_create_stream_output_target
;
2261 ilo
->base
.stream_output_target_destroy
= ilo_stream_output_target_destroy
;
2262 ilo
->base
.set_stream_output_targets
= ilo_set_stream_output_targets
;
2264 ilo
->base
.create_sampler_view
= ilo_create_sampler_view
;
2265 ilo
->base
.sampler_view_destroy
= ilo_sampler_view_destroy
;
2267 ilo
->base
.create_surface
= ilo_create_surface
;
2268 ilo
->base
.surface_destroy
= ilo_surface_destroy
;
2270 ilo
->base
.create_compute_state
= ilo_create_compute_state
;
2271 ilo
->base
.bind_compute_state
= ilo_bind_compute_state
;
2272 ilo
->base
.delete_compute_state
= ilo_delete_compute_state
;
2273 ilo
->base
.set_compute_resources
= ilo_set_compute_resources
;
2274 ilo
->base
.set_global_binding
= ilo_set_global_binding
;
2278 ilo_state_vector_init(const struct ilo_dev
*dev
,
2279 struct ilo_state_vector
*vec
)
2281 struct ilo_state_urb_info urb_info
;
2283 vec
->sample_mask
= ~0u;
2285 ilo_state_viewport_init_data_only(&vec
->viewport
.vp
, dev
,
2286 vec
->viewport
.vp_data
, sizeof(vec
->viewport
.vp_data
));
2287 assert(vec
->viewport
.vp
.array_size
>= ILO_MAX_VIEWPORTS
);
2289 vec
->viewport
.params
.matrices
= vec
->viewport
.matrices
;
2290 vec
->viewport
.params
.scissors
= vec
->viewport
.scissors
;
2292 ilo_state_hs_init_disabled(&vec
->disabled_hs
, dev
);
2293 ilo_state_ds_init_disabled(&vec
->disabled_ds
, dev
);
2294 ilo_state_gs_init_disabled(&vec
->disabled_gs
, dev
);
2296 ilo_state_surface_init_for_null(&vec
->fb
.null_rt
, dev
);
2297 ilo_state_zs_init_for_null(&vec
->fb
.null_zs
, dev
);
2299 ilo_state_sampler_init_disabled(&vec
->disabled_sampler
, dev
);
2301 memset(&urb_info
, 0, sizeof(urb_info
));
2302 ilo_state_urb_init(&vec
->urb
, dev
, &urb_info
);
2304 util_dynarray_init(&vec
->global_binding
.bindings
);
2306 vec
->dirty
= ILO_DIRTY_ALL
;
2310 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
)
2314 for (i
= 0; i
< Elements(vec
->vb
.states
); i
++) {
2315 if (vec
->vb
.enabled_mask
& (1 << i
))
2316 pipe_resource_reference(&vec
->vb
.states
[i
].buffer
, NULL
);
2319 pipe_resource_reference(&vec
->ib
.state
.buffer
, NULL
);
2320 pipe_resource_reference(&vec
->ib
.hw_resource
, NULL
);
2322 for (i
= 0; i
< vec
->so
.count
; i
++)
2323 pipe_so_target_reference(&vec
->so
.states
[i
], NULL
);
2325 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
2326 for (i
= 0; i
< vec
->view
[sh
].count
; i
++) {
2327 struct pipe_sampler_view
*view
= vec
->view
[sh
].states
[i
];
2328 pipe_sampler_view_reference(&view
, NULL
);
2331 for (i
= 0; i
< Elements(vec
->cbuf
[sh
].cso
); i
++) {
2332 struct ilo_cbuf_cso
*cbuf
= &vec
->cbuf
[sh
].cso
[i
];
2333 pipe_resource_reference(&cbuf
->resource
, NULL
);
2337 for (i
= 0; i
< vec
->resource
.count
; i
++)
2338 pipe_surface_reference(&vec
->resource
.states
[i
], NULL
);
2340 for (i
= 0; i
< vec
->fb
.state
.nr_cbufs
; i
++)
2341 pipe_surface_reference(&vec
->fb
.state
.cbufs
[i
], NULL
);
2343 if (vec
->fb
.state
.zsbuf
)
2344 pipe_surface_reference(&vec
->fb
.state
.zsbuf
, NULL
);
2346 for (i
= 0; i
< vec
->cs_resource
.count
; i
++)
2347 pipe_surface_reference(&vec
->cs_resource
.states
[i
], NULL
);
2349 for (i
= 0; i
< vec
->global_binding
.count
; i
++) {
2350 struct ilo_global_binding_cso
*cso
=
2351 util_dynarray_element(&vec
->global_binding
.bindings
,
2352 struct ilo_global_binding_cso
, i
);
2353 pipe_resource_reference(&cso
->resource
, NULL
);
2356 util_dynarray_fini(&vec
->global_binding
.bindings
);
2360 * Mark all states that have the resource dirty.
2363 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
2364 struct pipe_resource
*res
)
2366 struct intel_bo
*bo
= ilo_resource_get_bo(res
);
2367 uint32_t states
= 0;
2370 if (res
->target
== PIPE_BUFFER
) {
2371 uint32_t vb_mask
= vec
->vb
.enabled_mask
;
2374 const unsigned idx
= u_bit_scan(&vb_mask
);
2376 if (vec
->vb
.states
[idx
].buffer
== res
) {
2377 states
|= ILO_DIRTY_VB
;
2382 if (vec
->ib
.state
.buffer
== res
) {
2383 states
|= ILO_DIRTY_IB
;
2386 * finalize_index_buffer() has an optimization that clears
2387 * ILO_DIRTY_IB when the HW states do not change. However, it fails
2388 * to flush the VF cache when the HW states do not change, but the
2389 * contents of the IB has changed. Here, we set the index size to an
2390 * invalid value to avoid the optimization.
2392 vec
->ib
.hw_index_size
= 0;
2395 for (i
= 0; i
< vec
->so
.count
; i
++) {
2396 if (vec
->so
.states
[i
]->buffer
== res
) {
2397 states
|= ILO_DIRTY_SO
;
2403 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
2404 for (i
= 0; i
< vec
->view
[sh
].count
; i
++) {
2405 struct ilo_view_cso
*cso
= (struct ilo_view_cso
*) vec
->view
[sh
].states
[i
];
2407 if (cso
->base
.texture
== res
) {
2408 static const unsigned view_dirty_bits
[PIPE_SHADER_TYPES
] = {
2409 [PIPE_SHADER_VERTEX
] = ILO_DIRTY_VIEW_VS
,
2410 [PIPE_SHADER_FRAGMENT
] = ILO_DIRTY_VIEW_FS
,
2411 [PIPE_SHADER_GEOMETRY
] = ILO_DIRTY_VIEW_GS
,
2412 [PIPE_SHADER_COMPUTE
] = ILO_DIRTY_VIEW_CS
,
2414 cso
->surface
.bo
= bo
;
2416 states
|= view_dirty_bits
[sh
];
2421 if (res
->target
== PIPE_BUFFER
) {
2422 for (i
= 0; i
< Elements(vec
->cbuf
[sh
].cso
); i
++) {
2423 struct ilo_cbuf_cso
*cbuf
= &vec
->cbuf
[sh
].cso
[i
];
2425 if (cbuf
->resource
== res
) {
2426 cbuf
->surface
.bo
= bo
;
2427 states
|= ILO_DIRTY_CBUF
;
2434 for (i
= 0; i
< vec
->resource
.count
; i
++) {
2435 struct ilo_surface_cso
*cso
=
2436 (struct ilo_surface_cso
*) vec
->resource
.states
[i
];
2438 if (cso
->base
.texture
== res
) {
2440 states
|= ILO_DIRTY_RESOURCE
;
2446 if (res
->target
!= PIPE_BUFFER
) {
2447 for (i
= 0; i
< vec
->fb
.state
.nr_cbufs
; i
++) {
2448 struct ilo_surface_cso
*cso
=
2449 (struct ilo_surface_cso
*) vec
->fb
.state
.cbufs
[i
];
2450 if (cso
&& cso
->base
.texture
== res
) {
2452 states
|= ILO_DIRTY_FB
;
2457 if (vec
->fb
.state
.zsbuf
&& vec
->fb
.state
.zsbuf
->texture
== res
) {
2458 struct ilo_surface_cso
*cso
=
2459 (struct ilo_surface_cso
*) vec
->fb
.state
.zsbuf
;
2461 cso
->u
.zs
.depth_bo
= bo
;
2463 states
|= ILO_DIRTY_FB
;
2467 for (i
= 0; i
< vec
->cs_resource
.count
; i
++) {
2468 struct ilo_surface_cso
*cso
=
2469 (struct ilo_surface_cso
*) vec
->cs_resource
.states
[i
];
2470 if (cso
->base
.texture
== res
) {
2472 states
|= ILO_DIRTY_CS_RESOURCE
;
2477 for (i
= 0; i
< vec
->global_binding
.count
; i
++) {
2478 struct ilo_global_binding_cso
*cso
=
2479 util_dynarray_element(&vec
->global_binding
.bindings
,
2480 struct ilo_global_binding_cso
, i
);
2482 if (cso
->resource
== res
) {
2483 states
|= ILO_DIRTY_GLOBAL_BINDING
;
2488 vec
->dirty
|= states
;
2492 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
)
2494 static const char *state_names
[ILO_STATE_COUNT
] = {
2495 [ILO_STATE_VB
] = "VB",
2496 [ILO_STATE_VE
] = "VE",
2497 [ILO_STATE_IB
] = "IB",
2498 [ILO_STATE_VS
] = "VS",
2499 [ILO_STATE_GS
] = "GS",
2500 [ILO_STATE_SO
] = "SO",
2501 [ILO_STATE_CLIP
] = "CLIP",
2502 [ILO_STATE_VIEWPORT
] = "VIEWPORT",
2503 [ILO_STATE_SCISSOR
] = "SCISSOR",
2504 [ILO_STATE_RASTERIZER
] = "RASTERIZER",
2505 [ILO_STATE_POLY_STIPPLE
] = "POLY_STIPPLE",
2506 [ILO_STATE_SAMPLE_MASK
] = "SAMPLE_MASK",
2507 [ILO_STATE_FS
] = "FS",
2508 [ILO_STATE_DSA
] = "DSA",
2509 [ILO_STATE_STENCIL_REF
] = "STENCIL_REF",
2510 [ILO_STATE_BLEND
] = "BLEND",
2511 [ILO_STATE_BLEND_COLOR
] = "BLEND_COLOR",
2512 [ILO_STATE_FB
] = "FB",
2513 [ILO_STATE_SAMPLER_VS
] = "SAMPLER_VS",
2514 [ILO_STATE_SAMPLER_GS
] = "SAMPLER_GS",
2515 [ILO_STATE_SAMPLER_FS
] = "SAMPLER_FS",
2516 [ILO_STATE_SAMPLER_CS
] = "SAMPLER_CS",
2517 [ILO_STATE_VIEW_VS
] = "VIEW_VS",
2518 [ILO_STATE_VIEW_GS
] = "VIEW_GS",
2519 [ILO_STATE_VIEW_FS
] = "VIEW_FS",
2520 [ILO_STATE_VIEW_CS
] = "VIEW_CS",
2521 [ILO_STATE_CBUF
] = "CBUF",
2522 [ILO_STATE_RESOURCE
] = "RESOURCE",
2523 [ILO_STATE_CS
] = "CS",
2524 [ILO_STATE_CS_RESOURCE
] = "CS_RESOURCE",
2525 [ILO_STATE_GLOBAL_BINDING
] = "GLOBAL_BINDING",
2527 uint32_t dirty
= vec
->dirty
;
2530 ilo_printf("no state is dirty\n");
2534 dirty
&= (1U << ILO_STATE_COUNT
) - 1;
2536 ilo_printf("%2d states are dirty:", util_bitcount(dirty
));
2538 const enum ilo_state state
= u_bit_scan(&dirty
);
2539 ilo_printf(" %s", state_names
[state
]);