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 "util/u_dynarray.h"
29 #include "util/u_helpers.h"
30 #include "util/u_upload_mgr.h"
32 #include "ilo_context.h"
33 #include "ilo_resource.h"
34 #include "ilo_shader.h"
35 #include "ilo_state.h"
36 #include "ilo_state_3d.h"
39 finalize_shader_states(struct ilo_state_vector
*vec
)
43 for (type
= 0; type
< PIPE_SHADER_TYPES
; type
++) {
44 struct ilo_shader_state
*shader
;
48 case PIPE_SHADER_VERTEX
:
52 case PIPE_SHADER_GEOMETRY
:
56 case PIPE_SHADER_FRAGMENT
:
69 /* compile if the shader or the states it depends on changed */
70 if (vec
->dirty
& state
) {
71 ilo_shader_select_kernel(shader
, vec
, ILO_DIRTY_ALL
);
73 else if (ilo_shader_select_kernel(shader
, vec
, vec
->dirty
)) {
74 /* mark the state dirty if a new kernel is selected */
78 /* need to setup SBE for FS */
79 if (type
== PIPE_SHADER_FRAGMENT
&& vec
->dirty
&
80 (state
| ILO_DIRTY_GS
| ILO_DIRTY_VS
| ILO_DIRTY_RASTERIZER
)) {
81 if (ilo_shader_select_kernel_routing(shader
,
82 (vec
->gs
) ? vec
->gs
: vec
->vs
, vec
->rasterizer
))
89 finalize_cbuf_state(struct ilo_context
*ilo
,
90 struct ilo_cbuf_state
*cbuf
,
91 const struct ilo_shader_state
*sh
)
93 uint32_t upload_mask
= cbuf
->enabled_mask
;
95 /* skip CBUF0 if the kernel does not need it */
97 ~ilo_shader_get_kernel_param(sh
, ILO_KERNEL_SKIP_CBUF0_UPLOAD
);
100 const enum pipe_format elem_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
103 i
= u_bit_scan(&upload_mask
);
104 /* no need to upload */
105 if (cbuf
->cso
[i
].resource
)
108 u_upload_data(ilo
->uploader
, 0, cbuf
->cso
[i
].user_buffer_size
,
109 cbuf
->cso
[i
].user_buffer
, &offset
, &cbuf
->cso
[i
].resource
);
111 ilo_gpe_init_view_surface_for_buffer(ilo
->dev
,
112 ilo_buffer(cbuf
->cso
[i
].resource
),
113 offset
, cbuf
->cso
[i
].user_buffer_size
,
114 util_format_get_blocksize(elem_format
), elem_format
,
115 false, false, &cbuf
->cso
[i
].surface
);
117 ilo
->state_vector
.dirty
|= ILO_DIRTY_CBUF
;
122 finalize_constant_buffers(struct ilo_context
*ilo
)
124 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
126 if (vec
->dirty
& (ILO_DIRTY_CBUF
| ILO_DIRTY_VS
))
127 finalize_cbuf_state(ilo
, &vec
->cbuf
[PIPE_SHADER_VERTEX
], vec
->vs
);
129 if (ilo
->state_vector
.dirty
& (ILO_DIRTY_CBUF
| ILO_DIRTY_FS
))
130 finalize_cbuf_state(ilo
, &vec
->cbuf
[PIPE_SHADER_FRAGMENT
], vec
->fs
);
134 finalize_index_buffer(struct ilo_context
*ilo
)
136 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
137 const bool need_upload
= (vec
->draw
->indexed
&&
138 (vec
->ib
.user_buffer
|| vec
->ib
.offset
% vec
->ib
.index_size
));
139 struct pipe_resource
*current_hw_res
= NULL
;
141 if (!(vec
->dirty
& ILO_DIRTY_IB
) && !need_upload
)
144 pipe_resource_reference(¤t_hw_res
, vec
->ib
.hw_resource
);
147 const unsigned offset
= vec
->ib
.index_size
* vec
->draw
->start
;
148 const unsigned size
= vec
->ib
.index_size
* vec
->draw
->count
;
151 if (vec
->ib
.user_buffer
) {
152 u_upload_data(ilo
->uploader
, 0, size
,
153 vec
->ib
.user_buffer
+ offset
, &hw_offset
, &vec
->ib
.hw_resource
);
156 u_upload_buffer(ilo
->uploader
, 0, vec
->ib
.offset
+ offset
, size
,
157 vec
->ib
.buffer
, &hw_offset
, &vec
->ib
.hw_resource
);
160 /* the HW offset should be aligned */
161 assert(hw_offset
% vec
->ib
.index_size
== 0);
162 vec
->ib
.draw_start_offset
= hw_offset
/ vec
->ib
.index_size
;
165 * INDEX[vec->draw->start] in the original buffer is INDEX[0] in the HW
168 vec
->ib
.draw_start_offset
-= vec
->draw
->start
;
171 pipe_resource_reference(&vec
->ib
.hw_resource
, vec
->ib
.buffer
);
173 /* note that index size may be zero when the draw is not indexed */
174 if (vec
->draw
->indexed
)
175 vec
->ib
.draw_start_offset
= vec
->ib
.offset
/ vec
->ib
.index_size
;
177 vec
->ib
.draw_start_offset
= 0;
180 /* treat the IB as clean if the HW states do not change */
181 if (vec
->ib
.hw_resource
== current_hw_res
&&
182 vec
->ib
.hw_index_size
== vec
->ib
.index_size
)
183 vec
->dirty
&= ~ILO_DIRTY_IB
;
185 vec
->ib
.hw_index_size
= vec
->ib
.index_size
;
187 pipe_resource_reference(¤t_hw_res
, NULL
);
191 finalize_vertex_elements(struct ilo_context
*ilo
)
193 struct ilo_state_vector
*vec
= &ilo
->state_vector
;
195 if (!(vec
->dirty
& (ILO_DIRTY_VE
| ILO_DIRTY_VS
)))
198 vec
->dirty
|= ILO_DIRTY_VE
;
200 vec
->ve
->last_cso_edgeflag
= false;
201 if (vec
->ve
->count
&& vec
->vs
&&
202 ilo_shader_get_kernel_param(vec
->vs
, ILO_KERNEL_VS_INPUT_EDGEFLAG
)) {
203 vec
->ve
->edgeflag_cso
= vec
->ve
->cso
[vec
->ve
->count
- 1];
204 ilo_gpe_set_ve_edgeflag(ilo
->dev
, &vec
->ve
->edgeflag_cso
);
205 vec
->ve
->last_cso_edgeflag
= true;
208 vec
->ve
->prepend_nosrc_cso
= false;
210 (ilo_shader_get_kernel_param(vec
->vs
,
211 ILO_KERNEL_VS_INPUT_INSTANCEID
) ||
212 ilo_shader_get_kernel_param(vec
->vs
,
213 ILO_KERNEL_VS_INPUT_VERTEXID
))) {
214 ilo_gpe_init_ve_nosrc(ilo
->dev
,
215 GEN6_VFCOMP_STORE_VID
,
216 GEN6_VFCOMP_STORE_IID
,
219 &vec
->ve
->nosrc_cso
);
220 vec
->ve
->prepend_nosrc_cso
= true;
221 } else if (!vec
->vs
) {
222 /* generate VUE header */
223 ilo_gpe_init_ve_nosrc(ilo
->dev
,
224 GEN6_VFCOMP_STORE_0
, /* Reserved */
225 GEN6_VFCOMP_STORE_0
, /* Render Target Array Index */
226 GEN6_VFCOMP_STORE_0
, /* Viewport Index */
227 GEN6_VFCOMP_STORE_0
, /* Point Width */
228 &vec
->ve
->nosrc_cso
);
229 vec
->ve
->prepend_nosrc_cso
= true;
230 } else if (!vec
->ve
->count
) {
232 * From the Sandy Bridge PRM, volume 2 part 1, page 92:
234 * "SW must ensure that at least one vertex element is defined prior
235 * to issuing a 3DPRIMTIVE command, or operation is UNDEFINED."
237 ilo_gpe_init_ve_nosrc(ilo
->dev
,
241 GEN6_VFCOMP_STORE_1_FP
,
242 &vec
->ve
->nosrc_cso
);
243 vec
->ve
->prepend_nosrc_cso
= true;
248 * Finalize states. Some states depend on other states and are
249 * incomplete/invalid until finalized.
252 ilo_finalize_3d_states(struct ilo_context
*ilo
,
253 const struct pipe_draw_info
*draw
)
255 ilo
->state_vector
.draw
= draw
;
257 finalize_shader_states(&ilo
->state_vector
);
258 finalize_constant_buffers(ilo
);
259 finalize_index_buffer(ilo
);
260 finalize_vertex_elements(ilo
);
262 u_upload_unmap(ilo
->uploader
);
266 finalize_global_binding(struct ilo_state_vector
*vec
)
268 struct ilo_shader_state
*cs
= vec
->cs
;
269 int base
, count
, shift
;
272 count
= ilo_shader_get_kernel_param(cs
,
273 ILO_KERNEL_CS_SURFACE_GLOBAL_COUNT
);
277 base
= ilo_shader_get_kernel_param(cs
, ILO_KERNEL_CS_SURFACE_GLOBAL_BASE
);
278 shift
= 32 - util_last_bit(base
+ count
- 1);
280 if (count
> vec
->global_binding
.count
)
281 count
= vec
->global_binding
.count
;
283 for (i
= 0; i
< count
; i
++) {
284 struct ilo_global_binding_cso
*cso
=
285 util_dynarray_element(&vec
->global_binding
.bindings
,
286 struct ilo_global_binding_cso
, i
);
287 const uint32_t offset
= *cso
->handle
& ((1 << shift
) - 1);
289 *cso
->handle
= ((base
+ i
) << shift
) | offset
;
294 ilo_finalize_compute_states(struct ilo_context
*ilo
)
296 finalize_global_binding(&ilo
->state_vector
);
300 ilo_create_blend_state(struct pipe_context
*pipe
,
301 const struct pipe_blend_state
*state
)
303 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
304 struct ilo_blend_state
*blend
;
306 blend
= MALLOC_STRUCT(ilo_blend_state
);
309 ilo_gpe_init_blend(dev
, state
, blend
);
315 ilo_bind_blend_state(struct pipe_context
*pipe
, void *state
)
317 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
321 vec
->dirty
|= ILO_DIRTY_BLEND
;
325 ilo_delete_blend_state(struct pipe_context
*pipe
, void *state
)
331 ilo_create_sampler_state(struct pipe_context
*pipe
,
332 const struct pipe_sampler_state
*state
)
334 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
335 struct ilo_sampler_cso
*sampler
;
337 sampler
= MALLOC_STRUCT(ilo_sampler_cso
);
340 ilo_gpe_init_sampler_cso(dev
, state
, sampler
);
346 ilo_bind_sampler_states(struct pipe_context
*pipe
, unsigned shader
,
347 unsigned start
, unsigned count
, void **samplers
)
349 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
350 struct ilo_sampler_state
*dst
= &vec
->sampler
[shader
];
351 bool changed
= false;
354 assert(start
+ count
<= Elements(dst
->cso
));
357 for (i
= 0; i
< count
; i
++) {
358 if (dst
->cso
[start
+ i
] != samplers
[i
]) {
359 dst
->cso
[start
+ i
] = samplers
[i
];
362 * This function is sometimes called to reduce the number of bound
363 * samplers. Do not consider that as a state change (and create a
364 * new array of SAMPLER_STATE).
372 for (i
= 0; i
< count
; i
++)
373 dst
->cso
[start
+ i
] = NULL
;
378 case PIPE_SHADER_VERTEX
:
379 vec
->dirty
|= ILO_DIRTY_SAMPLER_VS
;
381 case PIPE_SHADER_GEOMETRY
:
382 vec
->dirty
|= ILO_DIRTY_SAMPLER_GS
;
384 case PIPE_SHADER_FRAGMENT
:
385 vec
->dirty
|= ILO_DIRTY_SAMPLER_FS
;
387 case PIPE_SHADER_COMPUTE
:
388 vec
->dirty
|= ILO_DIRTY_SAMPLER_CS
;
395 ilo_delete_sampler_state(struct pipe_context
*pipe
, void *state
)
401 ilo_create_rasterizer_state(struct pipe_context
*pipe
,
402 const struct pipe_rasterizer_state
*state
)
404 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
405 struct ilo_rasterizer_state
*rast
;
407 rast
= MALLOC_STRUCT(ilo_rasterizer_state
);
410 rast
->state
= *state
;
411 ilo_gpe_init_rasterizer(dev
, state
, rast
);
417 ilo_bind_rasterizer_state(struct pipe_context
*pipe
, void *state
)
419 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
421 vec
->rasterizer
= state
;
423 vec
->dirty
|= ILO_DIRTY_RASTERIZER
;
427 ilo_delete_rasterizer_state(struct pipe_context
*pipe
, void *state
)
433 ilo_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
434 const struct pipe_depth_stencil_alpha_state
*state
)
436 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
437 struct ilo_dsa_state
*dsa
;
439 dsa
= MALLOC_STRUCT(ilo_dsa_state
);
442 ilo_gpe_init_dsa(dev
, state
, dsa
);
448 ilo_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
450 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
454 vec
->dirty
|= ILO_DIRTY_DSA
;
458 ilo_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
464 ilo_create_fs_state(struct pipe_context
*pipe
,
465 const struct pipe_shader_state
*state
)
467 struct ilo_context
*ilo
= ilo_context(pipe
);
468 struct ilo_shader_state
*shader
;
470 shader
= ilo_shader_create_fs(ilo
->dev
, state
, &ilo
->state_vector
);
473 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
479 ilo_bind_fs_state(struct pipe_context
*pipe
, void *state
)
481 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
485 vec
->dirty
|= ILO_DIRTY_FS
;
489 ilo_delete_fs_state(struct pipe_context
*pipe
, void *state
)
491 struct ilo_context
*ilo
= ilo_context(pipe
);
492 struct ilo_shader_state
*fs
= (struct ilo_shader_state
*) state
;
494 ilo_shader_cache_remove(ilo
->shader_cache
, fs
);
495 ilo_shader_destroy(fs
);
499 ilo_create_vs_state(struct pipe_context
*pipe
,
500 const struct pipe_shader_state
*state
)
502 struct ilo_context
*ilo
= ilo_context(pipe
);
503 struct ilo_shader_state
*shader
;
505 shader
= ilo_shader_create_vs(ilo
->dev
, state
, &ilo
->state_vector
);
508 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
514 ilo_bind_vs_state(struct pipe_context
*pipe
, void *state
)
516 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
520 vec
->dirty
|= ILO_DIRTY_VS
;
524 ilo_delete_vs_state(struct pipe_context
*pipe
, void *state
)
526 struct ilo_context
*ilo
= ilo_context(pipe
);
527 struct ilo_shader_state
*vs
= (struct ilo_shader_state
*) state
;
529 ilo_shader_cache_remove(ilo
->shader_cache
, vs
);
530 ilo_shader_destroy(vs
);
534 ilo_create_gs_state(struct pipe_context
*pipe
,
535 const struct pipe_shader_state
*state
)
537 struct ilo_context
*ilo
= ilo_context(pipe
);
538 struct ilo_shader_state
*shader
;
540 shader
= ilo_shader_create_gs(ilo
->dev
, state
, &ilo
->state_vector
);
543 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
549 ilo_bind_gs_state(struct pipe_context
*pipe
, void *state
)
551 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
553 /* util_blitter may set this unnecessarily */
554 if (vec
->gs
== state
)
559 vec
->dirty
|= ILO_DIRTY_GS
;
563 ilo_delete_gs_state(struct pipe_context
*pipe
, void *state
)
565 struct ilo_context
*ilo
= ilo_context(pipe
);
566 struct ilo_shader_state
*gs
= (struct ilo_shader_state
*) state
;
568 ilo_shader_cache_remove(ilo
->shader_cache
, gs
);
569 ilo_shader_destroy(gs
);
573 ilo_create_vertex_elements_state(struct pipe_context
*pipe
,
574 unsigned num_elements
,
575 const struct pipe_vertex_element
*elements
)
577 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
578 struct ilo_ve_state
*ve
;
580 ve
= MALLOC_STRUCT(ilo_ve_state
);
583 ilo_gpe_init_ve(dev
, num_elements
, elements
, ve
);
589 ilo_bind_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
591 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
595 vec
->dirty
|= ILO_DIRTY_VE
;
599 ilo_delete_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
601 struct ilo_ve_state
*ve
= state
;
607 ilo_set_blend_color(struct pipe_context
*pipe
,
608 const struct pipe_blend_color
*state
)
610 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
612 vec
->blend_color
= *state
;
614 vec
->dirty
|= ILO_DIRTY_BLEND_COLOR
;
618 ilo_set_stencil_ref(struct pipe_context
*pipe
,
619 const struct pipe_stencil_ref
*state
)
621 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
623 /* util_blitter may set this unnecessarily */
624 if (!memcmp(&vec
->stencil_ref
, state
, sizeof(*state
)))
627 vec
->stencil_ref
= *state
;
629 vec
->dirty
|= ILO_DIRTY_STENCIL_REF
;
633 ilo_set_sample_mask(struct pipe_context
*pipe
,
634 unsigned sample_mask
)
636 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
638 /* util_blitter may set this unnecessarily */
639 if (vec
->sample_mask
== sample_mask
)
642 vec
->sample_mask
= sample_mask
;
644 vec
->dirty
|= ILO_DIRTY_SAMPLE_MASK
;
648 ilo_set_clip_state(struct pipe_context
*pipe
,
649 const struct pipe_clip_state
*state
)
651 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
655 vec
->dirty
|= ILO_DIRTY_CLIP
;
659 ilo_set_constant_buffer(struct pipe_context
*pipe
,
660 uint shader
, uint index
,
661 struct pipe_constant_buffer
*buf
)
663 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
664 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
665 struct ilo_cbuf_state
*cbuf
= &vec
->cbuf
[shader
];
666 const unsigned count
= 1;
669 assert(shader
< Elements(vec
->cbuf
));
670 assert(index
+ count
<= Elements(vec
->cbuf
[shader
].cso
));
673 for (i
= 0; i
< count
; i
++) {
674 struct ilo_cbuf_cso
*cso
= &cbuf
->cso
[index
+ i
];
676 pipe_resource_reference(&cso
->resource
, buf
[i
].buffer
);
679 const enum pipe_format elem_format
=
680 PIPE_FORMAT_R32G32B32A32_FLOAT
;
682 ilo_gpe_init_view_surface_for_buffer(dev
,
683 ilo_buffer(buf
[i
].buffer
),
684 buf
[i
].buffer_offset
, buf
[i
].buffer_size
,
685 util_format_get_blocksize(elem_format
), elem_format
,
686 false, false, &cso
->surface
);
688 cso
->user_buffer
= NULL
;
689 cso
->user_buffer_size
= 0;
691 cbuf
->enabled_mask
|= 1 << (index
+ i
);
693 else if (buf
[i
].user_buffer
) {
694 cso
->surface
.bo
= NULL
;
696 /* buffer_offset does not apply for user buffer */
697 cso
->user_buffer
= buf
[i
].user_buffer
;
698 cso
->user_buffer_size
= buf
[i
].buffer_size
;
700 cbuf
->enabled_mask
|= 1 << (index
+ i
);
703 cso
->surface
.bo
= NULL
;
704 cso
->user_buffer
= NULL
;
705 cso
->user_buffer_size
= 0;
707 cbuf
->enabled_mask
&= ~(1 << (index
+ i
));
712 for (i
= 0; i
< count
; i
++) {
713 struct ilo_cbuf_cso
*cso
= &cbuf
->cso
[index
+ i
];
715 pipe_resource_reference(&cso
->resource
, NULL
);
716 cso
->surface
.bo
= NULL
;
717 cso
->user_buffer
= NULL
;
718 cso
->user_buffer_size
= 0;
720 cbuf
->enabled_mask
&= ~(1 << (index
+ i
));
724 vec
->dirty
|= ILO_DIRTY_CBUF
;
728 ilo_set_framebuffer_state(struct pipe_context
*pipe
,
729 const struct pipe_framebuffer_state
*state
)
731 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
732 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
734 ilo_gpe_set_fb(dev
, state
, &vec
->fb
);
736 vec
->dirty
|= ILO_DIRTY_FB
;
740 ilo_set_polygon_stipple(struct pipe_context
*pipe
,
741 const struct pipe_poly_stipple
*state
)
743 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
745 vec
->poly_stipple
= *state
;
747 vec
->dirty
|= ILO_DIRTY_POLY_STIPPLE
;
751 ilo_set_scissor_states(struct pipe_context
*pipe
,
753 unsigned num_scissors
,
754 const struct pipe_scissor_state
*scissors
)
756 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
757 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
759 ilo_gpe_set_scissor(dev
, start_slot
, num_scissors
,
760 scissors
, &vec
->scissor
);
762 vec
->dirty
|= ILO_DIRTY_SCISSOR
;
766 ilo_set_viewport_states(struct pipe_context
*pipe
,
768 unsigned num_viewports
,
769 const struct pipe_viewport_state
*viewports
)
771 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
772 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
777 for (i
= 0; i
< num_viewports
; i
++) {
778 ilo_gpe_set_viewport_cso(dev
, &viewports
[i
],
779 &vec
->viewport
.cso
[start_slot
+ i
]);
782 if (vec
->viewport
.count
< start_slot
+ num_viewports
)
783 vec
->viewport
.count
= start_slot
+ num_viewports
;
785 /* need to save viewport 0 for util_blitter */
786 if (!start_slot
&& num_viewports
)
787 vec
->viewport
.viewport0
= viewports
[0];
790 if (vec
->viewport
.count
<= start_slot
+ num_viewports
&&
791 vec
->viewport
.count
> start_slot
)
792 vec
->viewport
.count
= start_slot
;
795 vec
->dirty
|= ILO_DIRTY_VIEWPORT
;
799 ilo_set_sampler_views(struct pipe_context
*pipe
, unsigned shader
,
800 unsigned start
, unsigned count
,
801 struct pipe_sampler_view
**views
)
803 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
804 struct ilo_view_state
*dst
= &vec
->view
[shader
];
807 assert(start
+ count
<= Elements(dst
->states
));
810 for (i
= 0; i
< count
; i
++)
811 pipe_sampler_view_reference(&dst
->states
[start
+ i
], views
[i
]);
814 for (i
= 0; i
< count
; i
++)
815 pipe_sampler_view_reference(&dst
->states
[start
+ i
], NULL
);
818 if (dst
->count
<= start
+ count
) {
824 while (count
> 0 && !dst
->states
[count
- 1])
831 case PIPE_SHADER_VERTEX
:
832 vec
->dirty
|= ILO_DIRTY_VIEW_VS
;
834 case PIPE_SHADER_GEOMETRY
:
835 vec
->dirty
|= ILO_DIRTY_VIEW_GS
;
837 case PIPE_SHADER_FRAGMENT
:
838 vec
->dirty
|= ILO_DIRTY_VIEW_FS
;
840 case PIPE_SHADER_COMPUTE
:
841 vec
->dirty
|= ILO_DIRTY_VIEW_CS
;
847 ilo_set_shader_resources(struct pipe_context
*pipe
,
848 unsigned start
, unsigned count
,
849 struct pipe_surface
**surfaces
)
851 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
852 struct ilo_resource_state
*dst
= &vec
->resource
;
855 assert(start
+ count
<= Elements(dst
->states
));
858 for (i
= 0; i
< count
; i
++)
859 pipe_surface_reference(&dst
->states
[start
+ i
], surfaces
[i
]);
862 for (i
= 0; i
< count
; i
++)
863 pipe_surface_reference(&dst
->states
[start
+ i
], NULL
);
866 if (dst
->count
<= start
+ count
) {
872 while (count
> 0 && !dst
->states
[count
- 1])
878 vec
->dirty
|= ILO_DIRTY_RESOURCE
;
882 ilo_set_vertex_buffers(struct pipe_context
*pipe
,
883 unsigned start_slot
, unsigned num_buffers
,
884 const struct pipe_vertex_buffer
*buffers
)
886 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
889 /* no PIPE_CAP_USER_VERTEX_BUFFERS */
891 for (i
= 0; i
< num_buffers
; i
++)
892 assert(!buffers
[i
].user_buffer
);
895 util_set_vertex_buffers_mask(vec
->vb
.states
,
896 &vec
->vb
.enabled_mask
, buffers
, start_slot
, num_buffers
);
898 vec
->dirty
|= ILO_DIRTY_VB
;
902 ilo_set_index_buffer(struct pipe_context
*pipe
,
903 const struct pipe_index_buffer
*state
)
905 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
908 pipe_resource_reference(&vec
->ib
.buffer
, state
->buffer
);
909 vec
->ib
.user_buffer
= state
->user_buffer
;
910 vec
->ib
.offset
= state
->offset
;
911 vec
->ib
.index_size
= state
->index_size
;
914 pipe_resource_reference(&vec
->ib
.buffer
, NULL
);
915 vec
->ib
.user_buffer
= NULL
;
917 vec
->ib
.index_size
= 0;
920 vec
->dirty
|= ILO_DIRTY_IB
;
923 static struct pipe_stream_output_target
*
924 ilo_create_stream_output_target(struct pipe_context
*pipe
,
925 struct pipe_resource
*res
,
926 unsigned buffer_offset
,
927 unsigned buffer_size
)
929 struct pipe_stream_output_target
*target
;
931 target
= MALLOC_STRUCT(pipe_stream_output_target
);
934 pipe_reference_init(&target
->reference
, 1);
935 target
->buffer
= NULL
;
936 pipe_resource_reference(&target
->buffer
, res
);
937 target
->context
= pipe
;
938 target
->buffer_offset
= buffer_offset
;
939 target
->buffer_size
= buffer_size
;
945 ilo_set_stream_output_targets(struct pipe_context
*pipe
,
946 unsigned num_targets
,
947 struct pipe_stream_output_target
**targets
,
948 const unsigned *offset
)
950 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
952 unsigned append_bitmask
= 0;
957 /* util_blitter may set this unnecessarily */
958 if (!vec
->so
.count
&& !num_targets
)
961 for (i
= 0; i
< num_targets
; i
++) {
962 pipe_so_target_reference(&vec
->so
.states
[i
], targets
[i
]);
963 if (offset
[i
] == (unsigned)-1)
964 append_bitmask
|= 1 << i
;
967 for (; i
< vec
->so
.count
; i
++)
968 pipe_so_target_reference(&vec
->so
.states
[i
], NULL
);
970 vec
->so
.count
= num_targets
;
971 vec
->so
.append_bitmask
= append_bitmask
;
973 vec
->so
.enabled
= (vec
->so
.count
> 0);
975 vec
->dirty
|= ILO_DIRTY_SO
;
979 ilo_stream_output_target_destroy(struct pipe_context
*pipe
,
980 struct pipe_stream_output_target
*target
)
982 pipe_resource_reference(&target
->buffer
, NULL
);
986 static struct pipe_sampler_view
*
987 ilo_create_sampler_view(struct pipe_context
*pipe
,
988 struct pipe_resource
*res
,
989 const struct pipe_sampler_view
*templ
)
991 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
992 struct ilo_view_cso
*view
;
994 view
= MALLOC_STRUCT(ilo_view_cso
);
998 pipe_reference_init(&view
->base
.reference
, 1);
999 view
->base
.texture
= NULL
;
1000 pipe_resource_reference(&view
->base
.texture
, res
);
1001 view
->base
.context
= pipe
;
1003 if (res
->target
== PIPE_BUFFER
) {
1004 const unsigned elem_size
= util_format_get_blocksize(templ
->format
);
1005 const unsigned first_elem
= templ
->u
.buf
.first_element
;
1006 const unsigned num_elems
= templ
->u
.buf
.last_element
- first_elem
+ 1;
1008 ilo_gpe_init_view_surface_for_buffer(dev
, ilo_buffer(res
),
1009 first_elem
* elem_size
, num_elems
* elem_size
,
1010 elem_size
, templ
->format
, false, false, &view
->surface
);
1013 struct ilo_texture
*tex
= ilo_texture(res
);
1015 /* warn about degraded performance because of a missing binding flag */
1016 if (tex
->layout
.tiling
== GEN6_TILING_NONE
&&
1017 !(tex
->base
.bind
& PIPE_BIND_SAMPLER_VIEW
)) {
1018 ilo_warn("creating sampler view for a resource "
1019 "not created for sampling\n");
1022 ilo_gpe_init_view_surface_for_texture(dev
, tex
,
1024 templ
->u
.tex
.first_level
,
1025 templ
->u
.tex
.last_level
- templ
->u
.tex
.first_level
+ 1,
1026 templ
->u
.tex
.first_layer
,
1027 templ
->u
.tex
.last_layer
- templ
->u
.tex
.first_layer
+ 1,
1028 false, &view
->surface
);
1035 ilo_sampler_view_destroy(struct pipe_context
*pipe
,
1036 struct pipe_sampler_view
*view
)
1038 pipe_resource_reference(&view
->texture
, NULL
);
1042 static struct pipe_surface
*
1043 ilo_create_surface(struct pipe_context
*pipe
,
1044 struct pipe_resource
*res
,
1045 const struct pipe_surface
*templ
)
1047 const struct ilo_dev
*dev
= ilo_context(pipe
)->dev
;
1048 struct ilo_surface_cso
*surf
;
1050 surf
= MALLOC_STRUCT(ilo_surface_cso
);
1053 surf
->base
= *templ
;
1054 pipe_reference_init(&surf
->base
.reference
, 1);
1055 surf
->base
.texture
= NULL
;
1056 pipe_resource_reference(&surf
->base
.texture
, res
);
1058 surf
->base
.context
= pipe
;
1059 surf
->base
.width
= u_minify(res
->width0
, templ
->u
.tex
.level
);
1060 surf
->base
.height
= u_minify(res
->height0
, templ
->u
.tex
.level
);
1062 surf
->is_rt
= !util_format_is_depth_or_stencil(templ
->format
);
1066 assert(res
->target
!= PIPE_BUFFER
);
1069 * classic i965 sets render_cache_rw for constant buffers and sol
1070 * surfaces but not render buffers. Why?
1072 ilo_gpe_init_view_surface_for_texture(dev
, ilo_texture(res
),
1073 templ
->format
, templ
->u
.tex
.level
, 1,
1074 templ
->u
.tex
.first_layer
,
1075 templ
->u
.tex
.last_layer
- templ
->u
.tex
.first_layer
+ 1,
1079 assert(res
->target
!= PIPE_BUFFER
);
1081 ilo_gpe_init_zs_surface(dev
, ilo_texture(res
),
1082 templ
->format
, templ
->u
.tex
.level
,
1083 templ
->u
.tex
.first_layer
,
1084 templ
->u
.tex
.last_layer
- templ
->u
.tex
.first_layer
+ 1,
1092 ilo_surface_destroy(struct pipe_context
*pipe
,
1093 struct pipe_surface
*surface
)
1095 pipe_resource_reference(&surface
->texture
, NULL
);
1100 ilo_create_compute_state(struct pipe_context
*pipe
,
1101 const struct pipe_compute_state
*state
)
1103 struct ilo_context
*ilo
= ilo_context(pipe
);
1104 struct ilo_shader_state
*shader
;
1106 shader
= ilo_shader_create_cs(ilo
->dev
, state
, &ilo
->state_vector
);
1109 ilo_shader_cache_add(ilo
->shader_cache
, shader
);
1115 ilo_bind_compute_state(struct pipe_context
*pipe
, void *state
)
1117 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1121 vec
->dirty
|= ILO_DIRTY_CS
;
1125 ilo_delete_compute_state(struct pipe_context
*pipe
, void *state
)
1127 struct ilo_context
*ilo
= ilo_context(pipe
);
1128 struct ilo_shader_state
*cs
= (struct ilo_shader_state
*) state
;
1130 ilo_shader_cache_remove(ilo
->shader_cache
, cs
);
1131 ilo_shader_destroy(cs
);
1135 ilo_set_compute_resources(struct pipe_context
*pipe
,
1136 unsigned start
, unsigned count
,
1137 struct pipe_surface
**surfaces
)
1139 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1140 struct ilo_resource_state
*dst
= &vec
->cs_resource
;
1143 assert(start
+ count
<= Elements(dst
->states
));
1146 for (i
= 0; i
< count
; i
++)
1147 pipe_surface_reference(&dst
->states
[start
+ i
], surfaces
[i
]);
1150 for (i
= 0; i
< count
; i
++)
1151 pipe_surface_reference(&dst
->states
[start
+ i
], NULL
);
1154 if (dst
->count
<= start
+ count
) {
1160 while (count
> 0 && !dst
->states
[count
- 1])
1166 vec
->dirty
|= ILO_DIRTY_CS_RESOURCE
;
1170 ilo_set_global_binding(struct pipe_context
*pipe
,
1171 unsigned start
, unsigned count
,
1172 struct pipe_resource
**resources
,
1175 struct ilo_state_vector
*vec
= &ilo_context(pipe
)->state_vector
;
1176 struct ilo_global_binding_cso
*dst
;
1180 if (vec
->global_binding
.count
< start
+ count
) {
1182 const unsigned old_size
= vec
->global_binding
.bindings
.size
;
1183 const unsigned new_size
= sizeof(*dst
) * (start
+ count
);
1185 if (old_size
< new_size
) {
1186 util_dynarray_resize(&vec
->global_binding
.bindings
, new_size
);
1187 memset(vec
->global_binding
.bindings
.data
+ old_size
, 0,
1188 new_size
- old_size
);
1191 count
= vec
->global_binding
.count
- start
;
1195 dst
= util_dynarray_element(&vec
->global_binding
.bindings
,
1196 struct ilo_global_binding_cso
, start
);
1199 for (i
= 0; i
< count
; i
++) {
1200 pipe_resource_reference(&dst
[i
].resource
, resources
[i
]);
1201 dst
[i
].handle
= handles
[i
];
1204 for (i
= 0; i
< count
; i
++) {
1205 pipe_resource_reference(&dst
[i
].resource
, NULL
);
1206 dst
[i
].handle
= NULL
;
1210 if (vec
->global_binding
.count
<= start
+ count
) {
1211 dst
= util_dynarray_begin(&vec
->global_binding
.bindings
);
1218 while (count
> 0 && !dst
[count
- 1].resource
)
1221 vec
->global_binding
.count
= count
;
1224 vec
->dirty
|= ILO_DIRTY_GLOBAL_BINDING
;
1228 * Initialize state-related functions.
1231 ilo_init_state_functions(struct ilo_context
*ilo
)
1233 STATIC_ASSERT(ILO_STATE_COUNT
<= 32);
1235 ilo
->base
.create_blend_state
= ilo_create_blend_state
;
1236 ilo
->base
.bind_blend_state
= ilo_bind_blend_state
;
1237 ilo
->base
.delete_blend_state
= ilo_delete_blend_state
;
1238 ilo
->base
.create_sampler_state
= ilo_create_sampler_state
;
1239 ilo
->base
.bind_sampler_states
= ilo_bind_sampler_states
;
1240 ilo
->base
.delete_sampler_state
= ilo_delete_sampler_state
;
1241 ilo
->base
.create_rasterizer_state
= ilo_create_rasterizer_state
;
1242 ilo
->base
.bind_rasterizer_state
= ilo_bind_rasterizer_state
;
1243 ilo
->base
.delete_rasterizer_state
= ilo_delete_rasterizer_state
;
1244 ilo
->base
.create_depth_stencil_alpha_state
= ilo_create_depth_stencil_alpha_state
;
1245 ilo
->base
.bind_depth_stencil_alpha_state
= ilo_bind_depth_stencil_alpha_state
;
1246 ilo
->base
.delete_depth_stencil_alpha_state
= ilo_delete_depth_stencil_alpha_state
;
1247 ilo
->base
.create_fs_state
= ilo_create_fs_state
;
1248 ilo
->base
.bind_fs_state
= ilo_bind_fs_state
;
1249 ilo
->base
.delete_fs_state
= ilo_delete_fs_state
;
1250 ilo
->base
.create_vs_state
= ilo_create_vs_state
;
1251 ilo
->base
.bind_vs_state
= ilo_bind_vs_state
;
1252 ilo
->base
.delete_vs_state
= ilo_delete_vs_state
;
1253 ilo
->base
.create_gs_state
= ilo_create_gs_state
;
1254 ilo
->base
.bind_gs_state
= ilo_bind_gs_state
;
1255 ilo
->base
.delete_gs_state
= ilo_delete_gs_state
;
1256 ilo
->base
.create_vertex_elements_state
= ilo_create_vertex_elements_state
;
1257 ilo
->base
.bind_vertex_elements_state
= ilo_bind_vertex_elements_state
;
1258 ilo
->base
.delete_vertex_elements_state
= ilo_delete_vertex_elements_state
;
1260 ilo
->base
.set_blend_color
= ilo_set_blend_color
;
1261 ilo
->base
.set_stencil_ref
= ilo_set_stencil_ref
;
1262 ilo
->base
.set_sample_mask
= ilo_set_sample_mask
;
1263 ilo
->base
.set_clip_state
= ilo_set_clip_state
;
1264 ilo
->base
.set_constant_buffer
= ilo_set_constant_buffer
;
1265 ilo
->base
.set_framebuffer_state
= ilo_set_framebuffer_state
;
1266 ilo
->base
.set_polygon_stipple
= ilo_set_polygon_stipple
;
1267 ilo
->base
.set_scissor_states
= ilo_set_scissor_states
;
1268 ilo
->base
.set_viewport_states
= ilo_set_viewport_states
;
1269 ilo
->base
.set_sampler_views
= ilo_set_sampler_views
;
1270 ilo
->base
.set_shader_resources
= ilo_set_shader_resources
;
1271 ilo
->base
.set_vertex_buffers
= ilo_set_vertex_buffers
;
1272 ilo
->base
.set_index_buffer
= ilo_set_index_buffer
;
1274 ilo
->base
.create_stream_output_target
= ilo_create_stream_output_target
;
1275 ilo
->base
.stream_output_target_destroy
= ilo_stream_output_target_destroy
;
1276 ilo
->base
.set_stream_output_targets
= ilo_set_stream_output_targets
;
1278 ilo
->base
.create_sampler_view
= ilo_create_sampler_view
;
1279 ilo
->base
.sampler_view_destroy
= ilo_sampler_view_destroy
;
1281 ilo
->base
.create_surface
= ilo_create_surface
;
1282 ilo
->base
.surface_destroy
= ilo_surface_destroy
;
1284 ilo
->base
.create_compute_state
= ilo_create_compute_state
;
1285 ilo
->base
.bind_compute_state
= ilo_bind_compute_state
;
1286 ilo
->base
.delete_compute_state
= ilo_delete_compute_state
;
1287 ilo
->base
.set_compute_resources
= ilo_set_compute_resources
;
1288 ilo
->base
.set_global_binding
= ilo_set_global_binding
;
1292 ilo_state_vector_init(const struct ilo_dev
*dev
,
1293 struct ilo_state_vector
*vec
)
1295 ilo_gpe_set_scissor_null(dev
, &vec
->scissor
);
1297 ilo_gpe_init_zs_surface(dev
, NULL
, PIPE_FORMAT_NONE
,
1298 0, 0, 1, &vec
->fb
.null_zs
);
1300 util_dynarray_init(&vec
->global_binding
.bindings
);
1302 vec
->dirty
= ILO_DIRTY_ALL
;
1306 ilo_state_vector_cleanup(struct ilo_state_vector
*vec
)
1310 for (i
= 0; i
< Elements(vec
->vb
.states
); i
++) {
1311 if (vec
->vb
.enabled_mask
& (1 << i
))
1312 pipe_resource_reference(&vec
->vb
.states
[i
].buffer
, NULL
);
1315 pipe_resource_reference(&vec
->ib
.buffer
, NULL
);
1316 pipe_resource_reference(&vec
->ib
.hw_resource
, NULL
);
1318 for (i
= 0; i
< vec
->so
.count
; i
++)
1319 pipe_so_target_reference(&vec
->so
.states
[i
], NULL
);
1321 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
1322 for (i
= 0; i
< vec
->view
[sh
].count
; i
++) {
1323 struct pipe_sampler_view
*view
= vec
->view
[sh
].states
[i
];
1324 pipe_sampler_view_reference(&view
, NULL
);
1327 for (i
= 0; i
< Elements(vec
->cbuf
[sh
].cso
); i
++) {
1328 struct ilo_cbuf_cso
*cbuf
= &vec
->cbuf
[sh
].cso
[i
];
1329 pipe_resource_reference(&cbuf
->resource
, NULL
);
1333 for (i
= 0; i
< vec
->resource
.count
; i
++)
1334 pipe_surface_reference(&vec
->resource
.states
[i
], NULL
);
1336 for (i
= 0; i
< vec
->fb
.state
.nr_cbufs
; i
++)
1337 pipe_surface_reference(&vec
->fb
.state
.cbufs
[i
], NULL
);
1339 if (vec
->fb
.state
.zsbuf
)
1340 pipe_surface_reference(&vec
->fb
.state
.zsbuf
, NULL
);
1342 for (i
= 0; i
< vec
->cs_resource
.count
; i
++)
1343 pipe_surface_reference(&vec
->cs_resource
.states
[i
], NULL
);
1345 for (i
= 0; i
< vec
->global_binding
.count
; i
++) {
1346 struct ilo_global_binding_cso
*cso
=
1347 util_dynarray_element(&vec
->global_binding
.bindings
,
1348 struct ilo_global_binding_cso
, i
);
1349 pipe_resource_reference(&cso
->resource
, NULL
);
1352 util_dynarray_fini(&vec
->global_binding
.bindings
);
1356 * Mark all states that have the resource dirty.
1359 ilo_state_vector_resource_renamed(struct ilo_state_vector
*vec
,
1360 struct pipe_resource
*res
)
1362 struct intel_bo
*bo
= ilo_resource_get_bo(res
);
1363 uint32_t states
= 0;
1366 if (res
->target
== PIPE_BUFFER
) {
1367 uint32_t vb_mask
= vec
->vb
.enabled_mask
;
1370 const unsigned idx
= u_bit_scan(&vb_mask
);
1372 if (vec
->vb
.states
[idx
].buffer
== res
) {
1373 states
|= ILO_DIRTY_VB
;
1378 if (vec
->ib
.buffer
== res
) {
1379 states
|= ILO_DIRTY_IB
;
1382 * finalize_index_buffer() has an optimization that clears
1383 * ILO_DIRTY_IB when the HW states do not change. However, it fails
1384 * to flush the VF cache when the HW states do not change, but the
1385 * contents of the IB has changed. Here, we set the index size to an
1386 * invalid value to avoid the optimization.
1388 vec
->ib
.hw_index_size
= 0;
1391 for (i
= 0; i
< vec
->so
.count
; i
++) {
1392 if (vec
->so
.states
[i
]->buffer
== res
) {
1393 states
|= ILO_DIRTY_SO
;
1399 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
1400 for (i
= 0; i
< vec
->view
[sh
].count
; i
++) {
1401 struct ilo_view_cso
*cso
= (struct ilo_view_cso
*) vec
->view
[sh
].states
[i
];
1403 if (cso
->base
.texture
== res
) {
1404 static const unsigned view_dirty_bits
[PIPE_SHADER_TYPES
] = {
1405 [PIPE_SHADER_VERTEX
] = ILO_DIRTY_VIEW_VS
,
1406 [PIPE_SHADER_FRAGMENT
] = ILO_DIRTY_VIEW_FS
,
1407 [PIPE_SHADER_GEOMETRY
] = ILO_DIRTY_VIEW_GS
,
1408 [PIPE_SHADER_COMPUTE
] = ILO_DIRTY_VIEW_CS
,
1410 cso
->surface
.bo
= bo
;
1412 states
|= view_dirty_bits
[sh
];
1417 if (res
->target
== PIPE_BUFFER
) {
1418 for (i
= 0; i
< Elements(vec
->cbuf
[sh
].cso
); i
++) {
1419 struct ilo_cbuf_cso
*cbuf
= &vec
->cbuf
[sh
].cso
[i
];
1421 if (cbuf
->resource
== res
) {
1422 cbuf
->surface
.bo
= bo
;
1423 states
|= ILO_DIRTY_CBUF
;
1430 for (i
= 0; i
< vec
->resource
.count
; i
++) {
1431 struct ilo_surface_cso
*cso
=
1432 (struct ilo_surface_cso
*) vec
->resource
.states
[i
];
1434 if (cso
->base
.texture
== res
) {
1436 states
|= ILO_DIRTY_RESOURCE
;
1442 if (res
->target
!= PIPE_BUFFER
) {
1443 for (i
= 0; i
< vec
->fb
.state
.nr_cbufs
; i
++) {
1444 struct ilo_surface_cso
*cso
=
1445 (struct ilo_surface_cso
*) vec
->fb
.state
.cbufs
[i
];
1446 if (cso
&& cso
->base
.texture
== res
) {
1448 states
|= ILO_DIRTY_FB
;
1453 if (vec
->fb
.state
.zsbuf
&& vec
->fb
.state
.zsbuf
->texture
== res
) {
1454 struct ilo_surface_cso
*cso
=
1455 (struct ilo_surface_cso
*) vec
->fb
.state
.zsbuf
;
1458 states
|= ILO_DIRTY_FB
;
1462 for (i
= 0; i
< vec
->cs_resource
.count
; i
++) {
1463 struct ilo_surface_cso
*cso
=
1464 (struct ilo_surface_cso
*) vec
->cs_resource
.states
[i
];
1465 if (cso
->base
.texture
== res
) {
1467 states
|= ILO_DIRTY_CS_RESOURCE
;
1472 for (i
= 0; i
< vec
->global_binding
.count
; i
++) {
1473 struct ilo_global_binding_cso
*cso
=
1474 util_dynarray_element(&vec
->global_binding
.bindings
,
1475 struct ilo_global_binding_cso
, i
);
1477 if (cso
->resource
== res
) {
1478 states
|= ILO_DIRTY_GLOBAL_BINDING
;
1483 vec
->dirty
|= states
;
1487 ilo_state_vector_dump_dirty(const struct ilo_state_vector
*vec
)
1489 static const char *state_names
[ILO_STATE_COUNT
] = {
1490 [ILO_STATE_VB
] = "VB",
1491 [ILO_STATE_VE
] = "VE",
1492 [ILO_STATE_IB
] = "IB",
1493 [ILO_STATE_VS
] = "VS",
1494 [ILO_STATE_GS
] = "GS",
1495 [ILO_STATE_SO
] = "SO",
1496 [ILO_STATE_CLIP
] = "CLIP",
1497 [ILO_STATE_VIEWPORT
] = "VIEWPORT",
1498 [ILO_STATE_SCISSOR
] = "SCISSOR",
1499 [ILO_STATE_RASTERIZER
] = "RASTERIZER",
1500 [ILO_STATE_POLY_STIPPLE
] = "POLY_STIPPLE",
1501 [ILO_STATE_SAMPLE_MASK
] = "SAMPLE_MASK",
1502 [ILO_STATE_FS
] = "FS",
1503 [ILO_STATE_DSA
] = "DSA",
1504 [ILO_STATE_STENCIL_REF
] = "STENCIL_REF",
1505 [ILO_STATE_BLEND
] = "BLEND",
1506 [ILO_STATE_BLEND_COLOR
] = "BLEND_COLOR",
1507 [ILO_STATE_FB
] = "FB",
1508 [ILO_STATE_SAMPLER_VS
] = "SAMPLER_VS",
1509 [ILO_STATE_SAMPLER_GS
] = "SAMPLER_GS",
1510 [ILO_STATE_SAMPLER_FS
] = "SAMPLER_FS",
1511 [ILO_STATE_SAMPLER_CS
] = "SAMPLER_CS",
1512 [ILO_STATE_VIEW_VS
] = "VIEW_VS",
1513 [ILO_STATE_VIEW_GS
] = "VIEW_GS",
1514 [ILO_STATE_VIEW_FS
] = "VIEW_FS",
1515 [ILO_STATE_VIEW_CS
] = "VIEW_CS",
1516 [ILO_STATE_CBUF
] = "CBUF",
1517 [ILO_STATE_RESOURCE
] = "RESOURCE",
1518 [ILO_STATE_CS
] = "CS",
1519 [ILO_STATE_CS_RESOURCE
] = "CS_RESOURCE",
1520 [ILO_STATE_GLOBAL_BINDING
] = "GLOBAL_BINDING",
1522 uint32_t dirty
= vec
->dirty
;
1525 ilo_printf("no state is dirty\n");
1529 dirty
&= (1U << ILO_STATE_COUNT
) - 1;
1531 ilo_printf("%2d states are dirty:", util_bitcount(dirty
));
1533 const enum ilo_state state
= u_bit_scan(&dirty
);
1534 ilo_printf(" %s", state_names
[state
]);