ilo: simplify setting of shader samplers and views
[mesa.git] / src / gallium / drivers / ilo / ilo_state.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "util/u_framebuffer.h"
29 #include "util/u_helpers.h"
30 #include "util/u_upload_mgr.h"
31
32 #include "ilo_context.h"
33 #include "ilo_resource.h"
34 #include "ilo_shader.h"
35 #include "ilo_state.h"
36
37 static void
38 finalize_shader_states(struct ilo_context *ilo)
39 {
40 unsigned type;
41
42 for (type = 0; type < PIPE_SHADER_TYPES; type++) {
43 struct ilo_shader_state *shader;
44 uint32_t state;
45
46 switch (type) {
47 case PIPE_SHADER_VERTEX:
48 shader = ilo->vs;
49 state = ILO_DIRTY_VS;
50 break;
51 case PIPE_SHADER_GEOMETRY:
52 shader = ilo->gs;
53 state = ILO_DIRTY_GS;
54 break;
55 case PIPE_SHADER_FRAGMENT:
56 shader = ilo->fs;
57 state = ILO_DIRTY_FS;
58 break;
59 default:
60 shader = NULL;
61 state = 0;
62 break;
63 }
64
65 if (!shader)
66 continue;
67
68 /* compile if the shader or the states it depends on changed */
69 if (ilo->dirty & state) {
70 ilo_shader_select_kernel(shader, ilo, ILO_DIRTY_ALL);
71 }
72 else if (ilo_shader_select_kernel(shader, ilo, ilo->dirty)) {
73 /* mark the state dirty if a new kernel is selected */
74 ilo->dirty |= state;
75 }
76
77 /* need to setup SBE for FS */
78 if (type == PIPE_SHADER_FRAGMENT && ilo->dirty &
79 (state | ILO_DIRTY_GS | ILO_DIRTY_VS | ILO_DIRTY_RASTERIZER)) {
80 if (ilo_shader_select_kernel_routing(shader,
81 (ilo->gs) ? ilo->gs : ilo->vs, ilo->rasterizer))
82 ilo->dirty |= state;
83 }
84 }
85 }
86
87 static void
88 finalize_constant_buffers(struct ilo_context *ilo)
89 {
90 int sh;
91
92 if (!(ilo->dirty & ILO_DIRTY_CBUF))
93 return;
94
95 /* TODO push constants? */
96 for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
97 unsigned enabled_mask = ilo->cbuf[sh].enabled_mask;
98
99 while (enabled_mask) {
100 struct ilo_cbuf_cso *cbuf;
101 int i;
102
103 i = u_bit_scan(&enabled_mask);
104 cbuf = &ilo->cbuf[sh].cso[i];
105
106 /* upload user buffer */
107 if (cbuf->user_buffer) {
108 const enum pipe_format elem_format =
109 PIPE_FORMAT_R32G32B32A32_FLOAT;
110 unsigned offset;
111
112 u_upload_data(ilo->uploader, 0, cbuf->user_buffer_size,
113 cbuf->user_buffer, &offset, &cbuf->resource);
114
115 ilo_gpe_init_view_surface_for_buffer(ilo->dev,
116 ilo_buffer(cbuf->resource),
117 offset, cbuf->user_buffer_size,
118 util_format_get_blocksize(elem_format), elem_format,
119 false, false, &cbuf->surface);
120
121 cbuf->user_buffer = NULL;
122 cbuf->user_buffer_size = 0;
123 }
124 }
125 }
126 }
127
128 static void
129 finalize_index_buffer(struct ilo_context *ilo)
130 {
131 const struct pipe_resource *current_hw_res = ilo->ib.hw_resource;
132 const bool need_upload = (ilo->draw->indexed &&
133 (ilo->ib.user_buffer || ilo->ib.offset % ilo->ib.index_size));
134
135 if (!(ilo->dirty & ILO_DIRTY_IB) && !need_upload)
136 return;
137
138 if (need_upload) {
139 const unsigned offset = ilo->ib.index_size * ilo->draw->start;
140 const unsigned size = ilo->ib.index_size * ilo->draw->count;
141 unsigned hw_offset;
142
143 if (ilo->ib.user_buffer) {
144 u_upload_data(ilo->uploader, 0, size,
145 ilo->ib.user_buffer + offset, &hw_offset, &ilo->ib.hw_resource);
146 }
147 else {
148 u_upload_buffer(ilo->uploader, 0, ilo->ib.offset + offset, size,
149 ilo->ib.buffer, &hw_offset, &ilo->ib.hw_resource);
150 }
151
152 /* the HW offset should be aligned */
153 assert(hw_offset % ilo->ib.index_size == 0);
154 ilo->ib.draw_start_offset = hw_offset / ilo->ib.index_size;
155
156 /*
157 * INDEX[ilo->draw->start] in the original buffer is INDEX[0] in the HW
158 * resource
159 */
160 ilo->ib.draw_start_offset -= ilo->draw->start;
161 }
162 else {
163 pipe_resource_reference(&ilo->ib.hw_resource, ilo->ib.buffer);
164
165 /* note that index size may be zero when the draw is not indexed */
166 if (ilo->draw->indexed)
167 ilo->ib.draw_start_offset = ilo->ib.offset / ilo->ib.index_size;
168 else
169 ilo->ib.draw_start_offset = 0;
170 }
171
172 /* treat the IB as clean if the HW states do not change */
173 if (ilo->ib.hw_resource == current_hw_res &&
174 ilo->ib.hw_index_size == ilo->ib.index_size)
175 ilo->dirty &= ~ILO_DIRTY_IB;
176 else
177 ilo->ib.hw_index_size = ilo->ib.index_size;
178 }
179
180 /**
181 * Finalize states. Some states depend on other states and are
182 * incomplete/invalid until finalized.
183 */
184 void
185 ilo_finalize_3d_states(struct ilo_context *ilo,
186 const struct pipe_draw_info *draw)
187 {
188 ilo->draw = draw;
189
190 finalize_shader_states(ilo);
191 finalize_constant_buffers(ilo);
192 finalize_index_buffer(ilo);
193
194 u_upload_unmap(ilo->uploader);
195 }
196
197 static void *
198 ilo_create_blend_state(struct pipe_context *pipe,
199 const struct pipe_blend_state *state)
200 {
201 struct ilo_context *ilo = ilo_context(pipe);
202 struct ilo_blend_state *blend;
203
204 blend = MALLOC_STRUCT(ilo_blend_state);
205 assert(blend);
206
207 ilo_gpe_init_blend(ilo->dev, state, blend);
208
209 return blend;
210 }
211
212 static void
213 ilo_bind_blend_state(struct pipe_context *pipe, void *state)
214 {
215 struct ilo_context *ilo = ilo_context(pipe);
216
217 ilo->blend = state;
218
219 ilo->dirty |= ILO_DIRTY_BLEND;
220 }
221
222 static void
223 ilo_delete_blend_state(struct pipe_context *pipe, void *state)
224 {
225 FREE(state);
226 }
227
228 static void *
229 ilo_create_sampler_state(struct pipe_context *pipe,
230 const struct pipe_sampler_state *state)
231 {
232 struct ilo_context *ilo = ilo_context(pipe);
233 struct ilo_sampler_cso *sampler;
234
235 sampler = MALLOC_STRUCT(ilo_sampler_cso);
236 assert(sampler);
237
238 ilo_gpe_init_sampler_cso(ilo->dev, state, sampler);
239
240 return sampler;
241 }
242
243 static void
244 ilo_bind_sampler_states(struct pipe_context *pipe, unsigned shader,
245 unsigned start, unsigned count, void **samplers)
246 {
247 struct ilo_context *ilo = ilo_context(pipe);
248 struct ilo_sampler_state *dst = &ilo->sampler[shader];
249 unsigned i;
250
251 assert(start + count <= Elements(dst->cso));
252
253 if (samplers) {
254 for (i = 0; i < count; i++)
255 dst->cso[start + i] = samplers[i];
256 }
257 else {
258 for (i = 0; i < count; i++)
259 dst->cso[start + i] = NULL;
260 }
261
262 if (dst->count <= start + count) {
263 if (samplers)
264 count += start;
265 else
266 count = start;
267
268 while (count > 0 && !dst->cso[count - 1])
269 count--;
270
271 dst->count = count;
272 }
273 }
274
275 static void
276 ilo_bind_fragment_sampler_states(struct pipe_context *pipe,
277 unsigned num_samplers,
278 void **samplers)
279 {
280 struct ilo_context *ilo = ilo_context(pipe);
281
282 ilo_bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT,
283 0, num_samplers, samplers);
284
285 if (ilo->sampler[PIPE_SHADER_FRAGMENT].count > num_samplers) {
286 ilo_bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT, num_samplers,
287 ilo->sampler[PIPE_SHADER_FRAGMENT].count - num_samplers, NULL);
288 }
289
290 ilo->dirty |= ILO_DIRTY_SAMPLER_FS;
291 }
292
293 static void
294 ilo_bind_vertex_sampler_states(struct pipe_context *pipe,
295 unsigned num_samplers,
296 void **samplers)
297 {
298 struct ilo_context *ilo = ilo_context(pipe);
299
300 ilo_bind_sampler_states(pipe, PIPE_SHADER_VERTEX,
301 0, num_samplers, samplers);
302
303 if (ilo->sampler[PIPE_SHADER_VERTEX].count > num_samplers) {
304 ilo_bind_sampler_states(pipe, PIPE_SHADER_VERTEX, num_samplers,
305 ilo->sampler[PIPE_SHADER_VERTEX].count - num_samplers, NULL);
306 }
307
308 ilo->dirty |= ILO_DIRTY_SAMPLER_VS;
309 }
310
311 static void
312 ilo_bind_geometry_sampler_states(struct pipe_context *pipe,
313 unsigned num_samplers,
314 void **samplers)
315 {
316 struct ilo_context *ilo = ilo_context(pipe);
317
318 ilo_bind_sampler_states(pipe, PIPE_SHADER_GEOMETRY,
319 0, num_samplers, samplers);
320
321 if (ilo->sampler[PIPE_SHADER_GEOMETRY].count > num_samplers) {
322 ilo_bind_sampler_states(pipe, PIPE_SHADER_GEOMETRY, num_samplers,
323 ilo->sampler[PIPE_SHADER_GEOMETRY].count - num_samplers, NULL);
324 }
325
326 ilo->dirty |= ILO_DIRTY_SAMPLER_GS;
327 }
328
329 static void
330 ilo_bind_compute_sampler_states(struct pipe_context *pipe,
331 unsigned start_slot,
332 unsigned num_samplers,
333 void **samplers)
334 {
335 struct ilo_context *ilo = ilo_context(pipe);
336
337 ilo_bind_sampler_states(pipe, PIPE_SHADER_COMPUTE,
338 start_slot, num_samplers, samplers);
339
340 ilo->dirty |= ILO_DIRTY_SAMPLER_CS;
341 }
342
343 static void
344 ilo_delete_sampler_state(struct pipe_context *pipe, void *state)
345 {
346 FREE(state);
347 }
348
349 static void *
350 ilo_create_rasterizer_state(struct pipe_context *pipe,
351 const struct pipe_rasterizer_state *state)
352 {
353 struct ilo_context *ilo = ilo_context(pipe);
354 struct ilo_rasterizer_state *rast;
355
356 rast = MALLOC_STRUCT(ilo_rasterizer_state);
357 assert(rast);
358
359 rast->state = *state;
360 ilo_gpe_init_rasterizer(ilo->dev, state, rast);
361
362 return rast;
363 }
364
365 static void
366 ilo_bind_rasterizer_state(struct pipe_context *pipe, void *state)
367 {
368 struct ilo_context *ilo = ilo_context(pipe);
369
370 ilo->rasterizer = state;
371
372 ilo->dirty |= ILO_DIRTY_RASTERIZER;
373 }
374
375 static void
376 ilo_delete_rasterizer_state(struct pipe_context *pipe, void *state)
377 {
378 FREE(state);
379 }
380
381 static void *
382 ilo_create_depth_stencil_alpha_state(struct pipe_context *pipe,
383 const struct pipe_depth_stencil_alpha_state *state)
384 {
385 struct ilo_context *ilo = ilo_context(pipe);
386 struct ilo_dsa_state *dsa;
387
388 dsa = MALLOC_STRUCT(ilo_dsa_state);
389 assert(dsa);
390
391 ilo_gpe_init_dsa(ilo->dev, state, dsa);
392
393 return dsa;
394 }
395
396 static void
397 ilo_bind_depth_stencil_alpha_state(struct pipe_context *pipe, void *state)
398 {
399 struct ilo_context *ilo = ilo_context(pipe);
400
401 ilo->dsa = state;
402
403 ilo->dirty |= ILO_DIRTY_DSA;
404 }
405
406 static void
407 ilo_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *state)
408 {
409 FREE(state);
410 }
411
412 static void *
413 ilo_create_fs_state(struct pipe_context *pipe,
414 const struct pipe_shader_state *state)
415 {
416 struct ilo_context *ilo = ilo_context(pipe);
417 struct ilo_shader_state *shader;
418
419 shader = ilo_shader_create_fs(ilo->dev, state, ilo);
420 assert(shader);
421
422 ilo_shader_cache_add(ilo->shader_cache, shader);
423
424 return shader;
425 }
426
427 static void
428 ilo_bind_fs_state(struct pipe_context *pipe, void *state)
429 {
430 struct ilo_context *ilo = ilo_context(pipe);
431
432 ilo->fs = state;
433
434 ilo->dirty |= ILO_DIRTY_FS;
435 }
436
437 static void
438 ilo_delete_fs_state(struct pipe_context *pipe, void *state)
439 {
440 struct ilo_context *ilo = ilo_context(pipe);
441 struct ilo_shader_state *fs = (struct ilo_shader_state *) state;
442
443 ilo_shader_cache_remove(ilo->shader_cache, fs);
444 ilo_shader_destroy(fs);
445 }
446
447 static void *
448 ilo_create_vs_state(struct pipe_context *pipe,
449 const struct pipe_shader_state *state)
450 {
451 struct ilo_context *ilo = ilo_context(pipe);
452 struct ilo_shader_state *shader;
453
454 shader = ilo_shader_create_vs(ilo->dev, state, ilo);
455 assert(shader);
456
457 ilo_shader_cache_add(ilo->shader_cache, shader);
458
459 return shader;
460 }
461
462 static void
463 ilo_bind_vs_state(struct pipe_context *pipe, void *state)
464 {
465 struct ilo_context *ilo = ilo_context(pipe);
466
467 ilo->vs = state;
468
469 ilo->dirty |= ILO_DIRTY_VS;
470 }
471
472 static void
473 ilo_delete_vs_state(struct pipe_context *pipe, void *state)
474 {
475 struct ilo_context *ilo = ilo_context(pipe);
476 struct ilo_shader_state *vs = (struct ilo_shader_state *) state;
477
478 ilo_shader_cache_remove(ilo->shader_cache, vs);
479 ilo_shader_destroy(vs);
480 }
481
482 static void *
483 ilo_create_gs_state(struct pipe_context *pipe,
484 const struct pipe_shader_state *state)
485 {
486 struct ilo_context *ilo = ilo_context(pipe);
487 struct ilo_shader_state *shader;
488
489 shader = ilo_shader_create_gs(ilo->dev, state, ilo);
490 assert(shader);
491
492 ilo_shader_cache_add(ilo->shader_cache, shader);
493
494 return shader;
495 }
496
497 static void
498 ilo_bind_gs_state(struct pipe_context *pipe, void *state)
499 {
500 struct ilo_context *ilo = ilo_context(pipe);
501
502 /* util_blitter may set this unnecessarily */
503 if (ilo->gs == state)
504 return;
505
506 ilo->gs = state;
507
508 ilo->dirty |= ILO_DIRTY_GS;
509 }
510
511 static void
512 ilo_delete_gs_state(struct pipe_context *pipe, void *state)
513 {
514 struct ilo_context *ilo = ilo_context(pipe);
515 struct ilo_shader_state *gs = (struct ilo_shader_state *) state;
516
517 ilo_shader_cache_remove(ilo->shader_cache, gs);
518 ilo_shader_destroy(gs);
519 }
520
521 static void *
522 ilo_create_vertex_elements_state(struct pipe_context *pipe,
523 unsigned num_elements,
524 const struct pipe_vertex_element *elements)
525 {
526 struct ilo_context *ilo = ilo_context(pipe);
527 struct ilo_ve_state *ve;
528
529 ve = MALLOC_STRUCT(ilo_ve_state);
530 assert(ve);
531
532 ilo_gpe_init_ve(ilo->dev, num_elements, elements, ve);
533
534 return ve;
535 }
536
537 static void
538 ilo_bind_vertex_elements_state(struct pipe_context *pipe, void *state)
539 {
540 struct ilo_context *ilo = ilo_context(pipe);
541
542 ilo->ve = state;
543
544 ilo->dirty |= ILO_DIRTY_VE;
545 }
546
547 static void
548 ilo_delete_vertex_elements_state(struct pipe_context *pipe, void *state)
549 {
550 struct ilo_ve_state *ve = state;
551
552 FREE(ve);
553 }
554
555 static void
556 ilo_set_blend_color(struct pipe_context *pipe,
557 const struct pipe_blend_color *state)
558 {
559 struct ilo_context *ilo = ilo_context(pipe);
560
561 ilo->blend_color = *state;
562
563 ilo->dirty |= ILO_DIRTY_BLEND_COLOR;
564 }
565
566 static void
567 ilo_set_stencil_ref(struct pipe_context *pipe,
568 const struct pipe_stencil_ref *state)
569 {
570 struct ilo_context *ilo = ilo_context(pipe);
571
572 /* util_blitter may set this unnecessarily */
573 if (!memcmp(&ilo->stencil_ref, state, sizeof(*state)))
574 return;
575
576 ilo->stencil_ref = *state;
577
578 ilo->dirty |= ILO_DIRTY_STENCIL_REF;
579 }
580
581 static void
582 ilo_set_sample_mask(struct pipe_context *pipe,
583 unsigned sample_mask)
584 {
585 struct ilo_context *ilo = ilo_context(pipe);
586
587 /* util_blitter may set this unnecessarily */
588 if (ilo->sample_mask == sample_mask)
589 return;
590
591 ilo->sample_mask = sample_mask;
592
593 ilo->dirty |= ILO_DIRTY_SAMPLE_MASK;
594 }
595
596 static void
597 ilo_set_clip_state(struct pipe_context *pipe,
598 const struct pipe_clip_state *state)
599 {
600 struct ilo_context *ilo = ilo_context(pipe);
601
602 ilo->clip = *state;
603
604 ilo->dirty |= ILO_DIRTY_CLIP;
605 }
606
607 static void
608 ilo_set_constant_buffer(struct pipe_context *pipe,
609 uint shader, uint index,
610 struct pipe_constant_buffer *buf)
611 {
612 struct ilo_context *ilo = ilo_context(pipe);
613 struct ilo_cbuf_state *cbuf = &ilo->cbuf[shader];
614 const unsigned count = 1;
615 unsigned i;
616
617 assert(shader < Elements(ilo->cbuf));
618 assert(index + count <= Elements(ilo->cbuf[shader].cso));
619
620 if (buf) {
621 for (i = 0; i < count; i++) {
622 struct ilo_cbuf_cso *cso = &cbuf->cso[index + i];
623
624 pipe_resource_reference(&cso->resource, buf[i].buffer);
625
626 if (buf[i].buffer) {
627 const enum pipe_format elem_format =
628 PIPE_FORMAT_R32G32B32A32_FLOAT;
629
630 ilo_gpe_init_view_surface_for_buffer(ilo->dev,
631 ilo_buffer(buf[i].buffer),
632 buf[i].buffer_offset, buf[i].buffer_size,
633 util_format_get_blocksize(elem_format), elem_format,
634 false, false, &cso->surface);
635
636 cso->user_buffer = NULL;
637 cso->user_buffer_size = 0;
638
639 cbuf->enabled_mask |= 1 << (index + i);
640 }
641 else if (buf[i].user_buffer) {
642 cso->surface.bo = NULL;
643
644 /* buffer_offset does not apply for user buffer */
645 cso->user_buffer = buf[i].user_buffer;
646 cso->user_buffer_size = buf[i].buffer_size;
647
648 cbuf->enabled_mask |= 1 << (index + i);
649 }
650 else {
651 cso->surface.bo = NULL;
652 cso->user_buffer = NULL;
653 cso->user_buffer_size = 0;
654
655 cbuf->enabled_mask &= ~(1 << (index + i));
656 }
657 }
658 }
659 else {
660 for (i = 0; i < count; i++) {
661 struct ilo_cbuf_cso *cso = &cbuf->cso[index + i];
662
663 pipe_resource_reference(&cso->resource, NULL);
664 cso->surface.bo = NULL;
665 cso->user_buffer = NULL;
666 cso->user_buffer_size = 0;
667
668 cbuf->enabled_mask &= ~(1 << (index + i));
669 }
670 }
671
672 ilo->dirty |= ILO_DIRTY_CBUF;
673 }
674
675 static void
676 ilo_set_framebuffer_state(struct pipe_context *pipe,
677 const struct pipe_framebuffer_state *state)
678 {
679 struct ilo_context *ilo = ilo_context(pipe);
680
681 util_copy_framebuffer_state(&ilo->fb.state, state);
682
683 if (state->nr_cbufs)
684 ilo->fb.num_samples = state->cbufs[0]->texture->nr_samples;
685 else if (state->zsbuf)
686 ilo->fb.num_samples = state->zsbuf->texture->nr_samples;
687 else
688 ilo->fb.num_samples = 1;
689
690 if (!ilo->fb.num_samples)
691 ilo->fb.num_samples = 1;
692
693 ilo->dirty |= ILO_DIRTY_FB;
694 }
695
696 static void
697 ilo_set_polygon_stipple(struct pipe_context *pipe,
698 const struct pipe_poly_stipple *state)
699 {
700 struct ilo_context *ilo = ilo_context(pipe);
701
702 ilo->poly_stipple = *state;
703
704 ilo->dirty |= ILO_DIRTY_POLY_STIPPLE;
705 }
706
707 static void
708 ilo_set_scissor_states(struct pipe_context *pipe,
709 unsigned start_slot,
710 unsigned num_scissors,
711 const struct pipe_scissor_state *scissors)
712 {
713 struct ilo_context *ilo = ilo_context(pipe);
714
715 ilo_gpe_set_scissor(ilo->dev, start_slot, num_scissors,
716 scissors, &ilo->scissor);
717
718 ilo->dirty |= ILO_DIRTY_SCISSOR;
719 }
720
721 static void
722 ilo_set_viewport_states(struct pipe_context *pipe,
723 unsigned start_slot,
724 unsigned num_viewports,
725 const struct pipe_viewport_state *viewports)
726 {
727 struct ilo_context *ilo = ilo_context(pipe);
728
729 if (viewports) {
730 unsigned i;
731
732 for (i = 0; i < num_viewports; i++) {
733 ilo_gpe_set_viewport_cso(ilo->dev, &viewports[i],
734 &ilo->viewport.cso[start_slot + i]);
735 }
736
737 if (ilo->viewport.count < start_slot + num_viewports)
738 ilo->viewport.count = start_slot + num_viewports;
739
740 /* need to save viewport 0 for util_blitter */
741 if (!start_slot && num_viewports)
742 ilo->viewport.viewport0 = viewports[0];
743 }
744 else {
745 if (ilo->viewport.count <= start_slot + num_viewports &&
746 ilo->viewport.count > start_slot)
747 ilo->viewport.count = start_slot;
748 }
749
750 ilo->dirty |= ILO_DIRTY_VIEWPORT;
751 }
752
753 static void
754 ilo_set_sampler_views(struct pipe_context *pipe, unsigned shader,
755 unsigned start, unsigned count,
756 struct pipe_sampler_view **views)
757 {
758 struct ilo_context *ilo = ilo_context(pipe);
759 struct ilo_view_state *dst = &ilo->view[shader];
760 unsigned i;
761
762 assert(start + count <= Elements(dst->states));
763
764 if (views) {
765 for (i = 0; i < count; i++)
766 pipe_sampler_view_reference(&dst->states[start + i], views[i]);
767 }
768 else {
769 for (i = 0; i < count; i++)
770 pipe_sampler_view_reference(&dst->states[start + i], NULL);
771 }
772
773 if (dst->count <= start + count) {
774 if (views)
775 count += start;
776 else
777 count = start;
778
779 while (count > 0 && !dst->states[count - 1])
780 count--;
781
782 dst->count = count;
783 }
784 }
785
786 static void
787 ilo_set_fragment_sampler_views(struct pipe_context *pipe,
788 unsigned num_views,
789 struct pipe_sampler_view **views)
790 {
791 struct ilo_context *ilo = ilo_context(pipe);
792
793 ilo_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_views, views);
794
795 if (ilo->view[PIPE_SHADER_FRAGMENT].count > num_views) {
796 ilo_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, num_views,
797 ilo->view[PIPE_SHADER_FRAGMENT].count - num_views, NULL);
798 }
799
800 ilo->dirty |= ILO_DIRTY_VIEW_FS;
801 }
802
803 static void
804 ilo_set_vertex_sampler_views(struct pipe_context *pipe,
805 unsigned num_views,
806 struct pipe_sampler_view **views)
807 {
808 struct ilo_context *ilo = ilo_context(pipe);
809
810 ilo_set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0, num_views, views);
811
812 if (ilo->view[PIPE_SHADER_VERTEX].count > num_views) {
813 ilo_set_sampler_views(pipe, PIPE_SHADER_VERTEX, num_views,
814 ilo->view[PIPE_SHADER_VERTEX].count - num_views, NULL);
815 }
816
817 ilo->dirty |= ILO_DIRTY_VIEW_VS;
818 }
819
820 static void
821 ilo_set_geometry_sampler_views(struct pipe_context *pipe,
822 unsigned num_views,
823 struct pipe_sampler_view **views)
824 {
825 struct ilo_context *ilo = ilo_context(pipe);
826
827 ilo_set_sampler_views(pipe, PIPE_SHADER_GEOMETRY, 0, num_views, views);
828
829 if (ilo->view[PIPE_SHADER_GEOMETRY].count > num_views) {
830 ilo_set_sampler_views(pipe, PIPE_SHADER_GEOMETRY, num_views,
831 ilo->view[PIPE_SHADER_GEOMETRY].count - num_views, NULL);
832 }
833
834 ilo->dirty |= ILO_DIRTY_VIEW_GS;
835 }
836
837 static void
838 ilo_set_compute_sampler_views(struct pipe_context *pipe,
839 unsigned start_slot, unsigned num_views,
840 struct pipe_sampler_view **views)
841 {
842 struct ilo_context *ilo = ilo_context(pipe);
843
844 ilo_set_sampler_views(pipe, PIPE_SHADER_COMPUTE,
845 start_slot, num_views, views);
846
847 ilo->dirty |= ILO_DIRTY_VIEW_CS;
848 }
849
850 static void
851 ilo_set_shader_resources(struct pipe_context *pipe,
852 unsigned start, unsigned count,
853 struct pipe_surface **surfaces)
854 {
855 struct ilo_context *ilo = ilo_context(pipe);
856 struct ilo_resource_state *dst = &ilo->resource;
857 unsigned i;
858
859 assert(start + count <= Elements(dst->states));
860
861 if (surfaces) {
862 for (i = 0; i < count; i++)
863 pipe_surface_reference(&dst->states[start + i], surfaces[i]);
864 }
865 else {
866 for (i = 0; i < count; i++)
867 pipe_surface_reference(&dst->states[start + i], NULL);
868 }
869
870 if (dst->count <= start + count) {
871 if (surfaces)
872 count += start;
873 else
874 count = start;
875
876 while (count > 0 && !dst->states[count - 1])
877 count--;
878
879 dst->count = count;
880 }
881
882 ilo->dirty |= ILO_DIRTY_RESOURCE;
883 }
884
885 static void
886 ilo_set_vertex_buffers(struct pipe_context *pipe,
887 unsigned start_slot, unsigned num_buffers,
888 const struct pipe_vertex_buffer *buffers)
889 {
890 struct ilo_context *ilo = ilo_context(pipe);
891 unsigned i;
892
893 /* no PIPE_CAP_USER_VERTEX_BUFFERS */
894 if (buffers) {
895 for (i = 0; i < num_buffers; i++)
896 assert(!buffers[i].user_buffer);
897 }
898
899 util_set_vertex_buffers_mask(ilo->vb.states,
900 &ilo->vb.enabled_mask, buffers, start_slot, num_buffers);
901
902 ilo->dirty |= ILO_DIRTY_VB;
903 }
904
905 static void
906 ilo_set_index_buffer(struct pipe_context *pipe,
907 const struct pipe_index_buffer *state)
908 {
909 struct ilo_context *ilo = ilo_context(pipe);
910
911 if (state) {
912 pipe_resource_reference(&ilo->ib.buffer, state->buffer);
913 ilo->ib.user_buffer = state->user_buffer;
914 ilo->ib.offset = state->offset;
915 ilo->ib.index_size = state->index_size;
916 }
917 else {
918 pipe_resource_reference(&ilo->ib.buffer, NULL);
919 ilo->ib.user_buffer = NULL;
920 ilo->ib.offset = 0;
921 ilo->ib.index_size = 0;
922 }
923
924 ilo->dirty |= ILO_DIRTY_IB;
925 }
926
927 static struct pipe_stream_output_target *
928 ilo_create_stream_output_target(struct pipe_context *pipe,
929 struct pipe_resource *res,
930 unsigned buffer_offset,
931 unsigned buffer_size)
932 {
933 struct pipe_stream_output_target *target;
934
935 target = MALLOC_STRUCT(pipe_stream_output_target);
936 assert(target);
937
938 pipe_reference_init(&target->reference, 1);
939 target->buffer = NULL;
940 pipe_resource_reference(&target->buffer, res);
941 target->context = pipe;
942 target->buffer_offset = buffer_offset;
943 target->buffer_size = buffer_size;
944
945 return target;
946 }
947
948 static void
949 ilo_set_stream_output_targets(struct pipe_context *pipe,
950 unsigned num_targets,
951 struct pipe_stream_output_target **targets,
952 unsigned append_bitmask)
953 {
954 struct ilo_context *ilo = ilo_context(pipe);
955 unsigned i;
956
957 if (!targets)
958 num_targets = 0;
959
960 /* util_blitter may set this unnecessarily */
961 if (!ilo->so.count && !num_targets)
962 return;
963
964 for (i = 0; i < num_targets; i++)
965 pipe_so_target_reference(&ilo->so.states[i], targets[i]);
966
967 for (; i < ilo->so.count; i++)
968 pipe_so_target_reference(&ilo->so.states[i], NULL);
969
970 ilo->so.count = num_targets;
971 ilo->so.append_bitmask = append_bitmask;
972
973 ilo->so.enabled = (ilo->so.count > 0);
974
975 ilo->dirty |= ILO_DIRTY_SO;
976 }
977
978 static void
979 ilo_stream_output_target_destroy(struct pipe_context *pipe,
980 struct pipe_stream_output_target *target)
981 {
982 pipe_resource_reference(&target->buffer, NULL);
983 FREE(target);
984 }
985
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)
990 {
991 struct ilo_context *ilo = ilo_context(pipe);
992 struct ilo_view_cso *view;
993
994 view = MALLOC_STRUCT(ilo_view_cso);
995 assert(view);
996
997 view->base = *templ;
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;
1002
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;
1007
1008 ilo_gpe_init_view_surface_for_buffer(ilo->dev, ilo_buffer(res),
1009 first_elem * elem_size, num_elems * elem_size,
1010 elem_size, templ->format, false, false, &view->surface);
1011 }
1012 else {
1013 struct ilo_texture *tex = ilo_texture(res);
1014
1015 /* warn about degraded performance because of a missing binding flag */
1016 if (tex->tiling == INTEL_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");
1020 }
1021
1022 ilo_gpe_init_view_surface_for_texture(ilo->dev, tex,
1023 templ->format,
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, false, &view->surface);
1029 }
1030
1031 return &view->base;
1032 }
1033
1034 static void
1035 ilo_sampler_view_destroy(struct pipe_context *pipe,
1036 struct pipe_sampler_view *view)
1037 {
1038 pipe_resource_reference(&view->texture, NULL);
1039 FREE(view);
1040 }
1041
1042 static struct pipe_surface *
1043 ilo_create_surface(struct pipe_context *pipe,
1044 struct pipe_resource *res,
1045 const struct pipe_surface *templ)
1046 {
1047 struct ilo_context *ilo = ilo_context(pipe);
1048 struct ilo_surface_cso *surf;
1049
1050 surf = MALLOC_STRUCT(ilo_surface_cso);
1051 assert(surf);
1052
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);
1057
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);
1061
1062 surf->is_rt = !util_format_is_depth_or_stencil(templ->format);
1063
1064 if (surf->is_rt) {
1065 /* relax this? */
1066 assert(res->target != PIPE_BUFFER);
1067
1068 /*
1069 * classic i965 sets render_cache_rw for constant buffers and sol
1070 * surfaces but not render buffers. Why?
1071 */
1072 ilo_gpe_init_view_surface_for_texture(ilo->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,
1076 true, true, &surf->u.rt);
1077 }
1078 else {
1079 assert(res->target != PIPE_BUFFER);
1080
1081 ilo_gpe_init_zs_surface(ilo->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,
1085 &surf->u.zs);
1086 }
1087
1088 return &surf->base;
1089 }
1090
1091 static void
1092 ilo_surface_destroy(struct pipe_context *pipe,
1093 struct pipe_surface *surface)
1094 {
1095 pipe_resource_reference(&surface->texture, NULL);
1096 FREE(surface);
1097 }
1098
1099 static void *
1100 ilo_create_compute_state(struct pipe_context *pipe,
1101 const struct pipe_compute_state *state)
1102 {
1103 struct ilo_context *ilo = ilo_context(pipe);
1104 struct ilo_shader_state *shader;
1105
1106 shader = ilo_shader_create_cs(ilo->dev, state, ilo);
1107 assert(shader);
1108
1109 ilo_shader_cache_add(ilo->shader_cache, shader);
1110
1111 return shader;
1112 }
1113
1114 static void
1115 ilo_bind_compute_state(struct pipe_context *pipe, void *state)
1116 {
1117 struct ilo_context *ilo = ilo_context(pipe);
1118
1119 ilo->cs = state;
1120
1121 ilo->dirty |= ILO_DIRTY_CS;
1122 }
1123
1124 static void
1125 ilo_delete_compute_state(struct pipe_context *pipe, void *state)
1126 {
1127 struct ilo_context *ilo = ilo_context(pipe);
1128 struct ilo_shader_state *cs = (struct ilo_shader_state *) state;
1129
1130 ilo_shader_cache_remove(ilo->shader_cache, cs);
1131 ilo_shader_destroy(cs);
1132 }
1133
1134 static void
1135 ilo_set_compute_resources(struct pipe_context *pipe,
1136 unsigned start, unsigned count,
1137 struct pipe_surface **surfaces)
1138 {
1139 struct ilo_context *ilo = ilo_context(pipe);
1140 struct ilo_resource_state *dst = &ilo->cs_resource;
1141 unsigned i;
1142
1143 assert(start + count <= Elements(dst->states));
1144
1145 if (surfaces) {
1146 for (i = 0; i < count; i++)
1147 pipe_surface_reference(&dst->states[start + i], surfaces[i]);
1148 }
1149 else {
1150 for (i = 0; i < count; i++)
1151 pipe_surface_reference(&dst->states[start + i], NULL);
1152 }
1153
1154 if (dst->count <= start + count) {
1155 if (surfaces)
1156 count += start;
1157 else
1158 count = start;
1159
1160 while (count > 0 && !dst->states[count - 1])
1161 count--;
1162
1163 dst->count = count;
1164 }
1165
1166 ilo->dirty |= ILO_DIRTY_CS_RESOURCE;
1167 }
1168
1169 static void
1170 ilo_set_global_binding(struct pipe_context *pipe,
1171 unsigned start, unsigned count,
1172 struct pipe_resource **resources,
1173 uint32_t **handles)
1174 {
1175 struct ilo_context *ilo = ilo_context(pipe);
1176 struct ilo_global_binding *dst = &ilo->global_binding;
1177 unsigned i;
1178
1179 assert(start + count <= Elements(dst->resources));
1180
1181 if (resources) {
1182 for (i = 0; i < count; i++)
1183 pipe_resource_reference(&dst->resources[start + i], resources[i]);
1184 }
1185 else {
1186 for (i = 0; i < count; i++)
1187 pipe_resource_reference(&dst->resources[start + i], NULL);
1188 }
1189
1190 if (dst->count <= start + count) {
1191 if (resources)
1192 count += start;
1193 else
1194 count = start;
1195
1196 while (count > 0 && !dst->resources[count - 1])
1197 count--;
1198
1199 dst->count = count;
1200 }
1201
1202 ilo->dirty |= ILO_DIRTY_GLOBAL_BINDING;
1203 }
1204
1205 /**
1206 * Initialize state-related functions.
1207 */
1208 void
1209 ilo_init_state_functions(struct ilo_context *ilo)
1210 {
1211 STATIC_ASSERT(ILO_STATE_COUNT <= 32);
1212
1213 ilo->base.create_blend_state = ilo_create_blend_state;
1214 ilo->base.bind_blend_state = ilo_bind_blend_state;
1215 ilo->base.delete_blend_state = ilo_delete_blend_state;
1216 ilo->base.create_sampler_state = ilo_create_sampler_state;
1217 ilo->base.bind_fragment_sampler_states = ilo_bind_fragment_sampler_states;
1218 ilo->base.bind_vertex_sampler_states = ilo_bind_vertex_sampler_states;
1219 ilo->base.bind_geometry_sampler_states = ilo_bind_geometry_sampler_states;
1220 ilo->base.bind_compute_sampler_states = ilo_bind_compute_sampler_states;
1221 ilo->base.delete_sampler_state = ilo_delete_sampler_state;
1222 ilo->base.create_rasterizer_state = ilo_create_rasterizer_state;
1223 ilo->base.bind_rasterizer_state = ilo_bind_rasterizer_state;
1224 ilo->base.delete_rasterizer_state = ilo_delete_rasterizer_state;
1225 ilo->base.create_depth_stencil_alpha_state = ilo_create_depth_stencil_alpha_state;
1226 ilo->base.bind_depth_stencil_alpha_state = ilo_bind_depth_stencil_alpha_state;
1227 ilo->base.delete_depth_stencil_alpha_state = ilo_delete_depth_stencil_alpha_state;
1228 ilo->base.create_fs_state = ilo_create_fs_state;
1229 ilo->base.bind_fs_state = ilo_bind_fs_state;
1230 ilo->base.delete_fs_state = ilo_delete_fs_state;
1231 ilo->base.create_vs_state = ilo_create_vs_state;
1232 ilo->base.bind_vs_state = ilo_bind_vs_state;
1233 ilo->base.delete_vs_state = ilo_delete_vs_state;
1234 ilo->base.create_gs_state = ilo_create_gs_state;
1235 ilo->base.bind_gs_state = ilo_bind_gs_state;
1236 ilo->base.delete_gs_state = ilo_delete_gs_state;
1237 ilo->base.create_vertex_elements_state = ilo_create_vertex_elements_state;
1238 ilo->base.bind_vertex_elements_state = ilo_bind_vertex_elements_state;
1239 ilo->base.delete_vertex_elements_state = ilo_delete_vertex_elements_state;
1240
1241 ilo->base.set_blend_color = ilo_set_blend_color;
1242 ilo->base.set_stencil_ref = ilo_set_stencil_ref;
1243 ilo->base.set_sample_mask = ilo_set_sample_mask;
1244 ilo->base.set_clip_state = ilo_set_clip_state;
1245 ilo->base.set_constant_buffer = ilo_set_constant_buffer;
1246 ilo->base.set_framebuffer_state = ilo_set_framebuffer_state;
1247 ilo->base.set_polygon_stipple = ilo_set_polygon_stipple;
1248 ilo->base.set_scissor_states = ilo_set_scissor_states;
1249 ilo->base.set_viewport_states = ilo_set_viewport_states;
1250 ilo->base.set_fragment_sampler_views = ilo_set_fragment_sampler_views;
1251 ilo->base.set_vertex_sampler_views = ilo_set_vertex_sampler_views;
1252 ilo->base.set_geometry_sampler_views = ilo_set_geometry_sampler_views;
1253 ilo->base.set_compute_sampler_views = ilo_set_compute_sampler_views;
1254 ilo->base.set_shader_resources = ilo_set_shader_resources;
1255 ilo->base.set_vertex_buffers = ilo_set_vertex_buffers;
1256 ilo->base.set_index_buffer = ilo_set_index_buffer;
1257
1258 ilo->base.create_stream_output_target = ilo_create_stream_output_target;
1259 ilo->base.stream_output_target_destroy = ilo_stream_output_target_destroy;
1260 ilo->base.set_stream_output_targets = ilo_set_stream_output_targets;
1261
1262 ilo->base.create_sampler_view = ilo_create_sampler_view;
1263 ilo->base.sampler_view_destroy = ilo_sampler_view_destroy;
1264
1265 ilo->base.create_surface = ilo_create_surface;
1266 ilo->base.surface_destroy = ilo_surface_destroy;
1267
1268 ilo->base.create_compute_state = ilo_create_compute_state;
1269 ilo->base.bind_compute_state = ilo_bind_compute_state;
1270 ilo->base.delete_compute_state = ilo_delete_compute_state;
1271 ilo->base.set_compute_resources = ilo_set_compute_resources;
1272 ilo->base.set_global_binding = ilo_set_global_binding;
1273 }
1274
1275 void
1276 ilo_init_states(struct ilo_context *ilo)
1277 {
1278 ilo_gpe_set_scissor_null(ilo->dev, &ilo->scissor);
1279
1280 ilo_gpe_init_zs_surface(ilo->dev, NULL,
1281 PIPE_FORMAT_NONE, 0, 0, 1, &ilo->fb.null_zs);
1282
1283 ilo->dirty = ILO_DIRTY_ALL;
1284 }
1285
1286 void
1287 ilo_cleanup_states(struct ilo_context *ilo)
1288 {
1289 unsigned i, sh;
1290
1291 for (i = 0; i < Elements(ilo->vb.states); i++) {
1292 if (ilo->vb.enabled_mask & (1 << i))
1293 pipe_resource_reference(&ilo->vb.states[i].buffer, NULL);
1294 }
1295
1296 pipe_resource_reference(&ilo->ib.buffer, NULL);
1297 pipe_resource_reference(&ilo->ib.hw_resource, NULL);
1298
1299 for (i = 0; i < ilo->so.count; i++)
1300 pipe_so_target_reference(&ilo->so.states[i], NULL);
1301
1302 for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
1303 for (i = 0; i < ilo->view[sh].count; i++) {
1304 struct pipe_sampler_view *view = ilo->view[sh].states[i];
1305 pipe_sampler_view_reference(&view, NULL);
1306 }
1307
1308 for (i = 0; i < Elements(ilo->cbuf[sh].cso); i++) {
1309 struct ilo_cbuf_cso *cbuf = &ilo->cbuf[sh].cso[i];
1310 pipe_resource_reference(&cbuf->resource, NULL);
1311 }
1312 }
1313
1314 for (i = 0; i < ilo->resource.count; i++)
1315 pipe_surface_reference(&ilo->resource.states[i], NULL);
1316
1317 for (i = 0; i < ilo->fb.state.nr_cbufs; i++)
1318 pipe_surface_reference(&ilo->fb.state.cbufs[i], NULL);
1319
1320 if (ilo->fb.state.zsbuf)
1321 pipe_surface_reference(&ilo->fb.state.zsbuf, NULL);
1322
1323 for (i = 0; i < ilo->cs_resource.count; i++)
1324 pipe_surface_reference(&ilo->cs_resource.states[i], NULL);
1325
1326 for (i = 0; i < ilo->global_binding.count; i++)
1327 pipe_resource_reference(&ilo->global_binding.resources[i], NULL);
1328 }
1329
1330 /**
1331 * Mark all states that have the resource dirty.
1332 */
1333 void
1334 ilo_mark_states_with_resource_dirty(struct ilo_context *ilo,
1335 const struct pipe_resource *res)
1336 {
1337 uint32_t states = 0;
1338 unsigned sh, i;
1339
1340 if (res->target == PIPE_BUFFER) {
1341 uint32_t vb_mask = ilo->vb.enabled_mask;
1342
1343 while (vb_mask) {
1344 const unsigned idx = u_bit_scan(&vb_mask);
1345
1346 if (ilo->vb.states[idx].buffer == res) {
1347 states |= ILO_DIRTY_VB;
1348 break;
1349 }
1350 }
1351
1352 if (ilo->ib.buffer == res) {
1353 states |= ILO_DIRTY_IB;
1354
1355 /*
1356 * finalize_index_buffer() has an optimization that clears
1357 * ILO_DIRTY_IB when the HW states do not change. However, it fails
1358 * to flush the VF cache when the HW states do not change, but the
1359 * contents of the IB has changed. Here, we set the index size to an
1360 * invalid value to avoid the optimization.
1361 */
1362 ilo->ib.hw_index_size = 0;
1363 }
1364
1365 for (i = 0; i < ilo->so.count; i++) {
1366 if (ilo->so.states[i]->buffer == res) {
1367 states |= ILO_DIRTY_SO;
1368 break;
1369 }
1370 }
1371 }
1372
1373 for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
1374 for (i = 0; i < ilo->view[sh].count; i++) {
1375 struct pipe_sampler_view *view = ilo->view[sh].states[i];
1376
1377 if (view->texture == res) {
1378 static const unsigned view_dirty_bits[PIPE_SHADER_TYPES] = {
1379 [PIPE_SHADER_VERTEX] = ILO_DIRTY_VIEW_VS,
1380 [PIPE_SHADER_FRAGMENT] = ILO_DIRTY_VIEW_FS,
1381 [PIPE_SHADER_GEOMETRY] = ILO_DIRTY_VIEW_GS,
1382 [PIPE_SHADER_COMPUTE] = ILO_DIRTY_VIEW_CS,
1383 };
1384
1385 states |= view_dirty_bits[sh];
1386 break;
1387 }
1388 }
1389
1390 if (res->target == PIPE_BUFFER) {
1391 for (i = 0; i < Elements(ilo->cbuf[sh].cso); i++) {
1392 struct ilo_cbuf_cso *cbuf = &ilo->cbuf[sh].cso[i];
1393
1394 if (cbuf->resource == res) {
1395 states |= ILO_DIRTY_CBUF;
1396 break;
1397 }
1398 }
1399 }
1400 }
1401
1402 for (i = 0; i < ilo->resource.count; i++) {
1403 if (ilo->resource.states[i]->texture == res) {
1404 states |= ILO_DIRTY_RESOURCE;
1405 break;
1406 }
1407 }
1408
1409 /* for now? */
1410 if (res->target != PIPE_BUFFER) {
1411 for (i = 0; i < ilo->fb.state.nr_cbufs; i++) {
1412 if (ilo->fb.state.cbufs[i]->texture == res) {
1413 states |= ILO_DIRTY_FB;
1414 break;
1415 }
1416 }
1417
1418 if (ilo->fb.state.zsbuf && ilo->fb.state.zsbuf->texture == res)
1419 states |= ILO_DIRTY_FB;
1420 }
1421
1422 for (i = 0; i < ilo->cs_resource.count; i++) {
1423 pipe_surface_reference(&ilo->cs_resource.states[i], NULL);
1424 if (ilo->cs_resource.states[i]->texture == res) {
1425 states |= ILO_DIRTY_CS_RESOURCE;
1426 break;
1427 }
1428 }
1429
1430 for (i = 0; i < ilo->global_binding.count; i++) {
1431 if (ilo->global_binding.resources[i] == res) {
1432 states |= ILO_DIRTY_GLOBAL_BINDING;
1433 break;
1434 }
1435 }
1436
1437 ilo->dirty |= states;
1438 }