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_framebuffer.h"
29 #include "util/u_helpers.h"
31 #include "ilo_context.h"
32 #include "ilo_resource.h"
33 #include "ilo_shader.h"
34 #include "ilo_state.h"
37 * We simply remember the pipe states here and derive HW commands/states from
38 * them later. We could do better by deriving (some of the) HW
39 * commands/states directly.
43 finalize_shader_states(struct ilo_context
*ilo
)
45 /* this table is ugly and is a burden to maintain.. */
47 struct ilo_shader_state
*state
;
48 struct ilo_shader
*prev_shader
;
49 uint32_t prev_cache_seqno
;
52 } sh
[PIPE_SHADER_TYPES
] = {
53 [PIPE_SHADER_VERTEX
] = {
55 .prev_shader
= (ilo
->vs
) ? ilo
->vs
->shader
: NULL
,
56 .prev_cache_seqno
= (ilo
->vs
) ? ilo
->vs
->shader
->cache_seqno
: 0,
57 .dirty
= ILO_DIRTY_VS
,
58 .deps
= ILO_DIRTY_VERTEX_SAMPLER_VIEWS
|
61 [PIPE_SHADER_FRAGMENT
] = {
63 .prev_shader
= (ilo
->fs
) ? ilo
->fs
->shader
: NULL
,
64 .prev_cache_seqno
= (ilo
->fs
) ? ilo
->fs
->shader
->cache_seqno
: 0,
65 .dirty
= ILO_DIRTY_FS
,
66 .deps
= ILO_DIRTY_FRAGMENT_SAMPLER_VIEWS
|
67 ILO_DIRTY_RASTERIZER
|
68 ILO_DIRTY_FRAMEBUFFER
,
70 [PIPE_SHADER_GEOMETRY
] = {
72 .prev_shader
= (ilo
->gs
) ? ilo
->gs
->shader
: NULL
,
73 .prev_cache_seqno
= (ilo
->gs
) ? ilo
->gs
->shader
->cache_seqno
: 0,
74 .dirty
= ILO_DIRTY_GS
,
75 .deps
= ILO_DIRTY_GEOMETRY_SAMPLER_VIEWS
|
79 [PIPE_SHADER_COMPUTE
] = {
82 .prev_cache_seqno
= 0,
87 struct ilo_shader
*shaders
[PIPE_SHADER_TYPES
];
88 int num_shaders
= 0, i
;
90 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
95 /* switch variant if the shader or the states it depends on changed */
96 if (ilo
->dirty
& (sh
[i
].dirty
| sh
[i
].deps
)) {
97 struct ilo_shader_variant variant
;
99 ilo_shader_variant_init(&variant
, &sh
[i
].state
->info
, ilo
);
100 ilo_shader_state_use_variant(sh
[i
].state
, &variant
);
103 shaders
[num_shaders
++] = sh
[i
].state
->shader
;
106 ilo_shader_cache_set(ilo
->shader_cache
, shaders
, num_shaders
);
108 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
114 * mark the shader state dirty if
116 * - a new variant is selected, or
117 * - the kernel is uploaded to a different bo
119 if (sh
[i
].state
->shader
!= sh
[i
].prev_shader
||
120 sh
[i
].state
->shader
->cache_seqno
!= sh
[i
].prev_cache_seqno
)
121 ilo
->dirty
|= sh
[i
].dirty
;
126 finalize_constant_buffers(struct ilo_context
*ilo
)
130 if (!(ilo
->dirty
& ILO_DIRTY_CONSTANT_BUFFER
))
133 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
134 int last_cbuf
= Elements(ilo
->cbuf
[sh
].cso
) - 1;
136 /* find the last cbuf */
137 while (last_cbuf
>= 0 &&
138 !ilo
->cbuf
[sh
].cso
[last_cbuf
].resource
)
141 ilo
->cbuf
[sh
].count
= last_cbuf
+ 1;
146 * Finalize states. Some states depend on other states and are
147 * incomplete/invalid until finalized.
150 ilo_finalize_states(struct ilo_context
*ilo
)
152 finalize_shader_states(ilo
);
153 finalize_constant_buffers(ilo
);
157 ilo_create_blend_state(struct pipe_context
*pipe
,
158 const struct pipe_blend_state
*state
)
160 struct ilo_context
*ilo
= ilo_context(pipe
);
161 struct ilo_blend_state
*blend
;
163 blend
= MALLOC_STRUCT(ilo_blend_state
);
166 ilo_gpe_init_blend(ilo
->dev
, state
, blend
);
172 ilo_bind_blend_state(struct pipe_context
*pipe
, void *state
)
174 struct ilo_context
*ilo
= ilo_context(pipe
);
178 ilo
->dirty
|= ILO_DIRTY_BLEND
;
182 ilo_delete_blend_state(struct pipe_context
*pipe
, void *state
)
188 ilo_create_sampler_state(struct pipe_context
*pipe
,
189 const struct pipe_sampler_state
*state
)
191 struct ilo_context
*ilo
= ilo_context(pipe
);
192 struct ilo_sampler_cso
*sampler
;
194 sampler
= MALLOC_STRUCT(ilo_sampler_cso
);
197 ilo_gpe_init_sampler_cso(ilo
->dev
, state
, sampler
);
203 bind_samplers(struct ilo_context
*ilo
,
204 unsigned shader
, unsigned start
, unsigned count
,
205 void **samplers
, bool unbind_old
)
207 const struct ilo_sampler_cso
**dst
= ilo
->sampler
[shader
].cso
;
210 assert(start
+ count
<= Elements(ilo
->sampler
[shader
].cso
));
218 for (i
= 0; i
< start
; i
++)
220 for (; i
< start
+ count
; i
++)
221 dst
[i
] = samplers
[i
- start
];
222 for (; i
< ilo
->sampler
[shader
].count
; i
++)
225 ilo
->sampler
[shader
].count
= start
+ count
;
232 for (i
= 0; i
< count
; i
++)
233 dst
[i
] = samplers
[i
];
236 for (i
= 0; i
< count
; i
++)
240 if (ilo
->sampler
[shader
].count
<= start
+ count
) {
243 while (count
> 0 && !ilo
->sampler
[shader
].cso
[count
- 1])
246 ilo
->sampler
[shader
].count
= count
;
251 ilo_bind_fragment_sampler_states(struct pipe_context
*pipe
,
252 unsigned num_samplers
,
255 struct ilo_context
*ilo
= ilo_context(pipe
);
257 bind_samplers(ilo
, PIPE_SHADER_FRAGMENT
, 0, num_samplers
, samplers
, true);
258 ilo
->dirty
|= ILO_DIRTY_FRAGMENT_SAMPLERS
;
262 ilo_bind_vertex_sampler_states(struct pipe_context
*pipe
,
263 unsigned num_samplers
,
266 struct ilo_context
*ilo
= ilo_context(pipe
);
268 bind_samplers(ilo
, PIPE_SHADER_VERTEX
, 0, num_samplers
, samplers
, true);
269 ilo
->dirty
|= ILO_DIRTY_VERTEX_SAMPLERS
;
273 ilo_bind_geometry_sampler_states(struct pipe_context
*pipe
,
274 unsigned num_samplers
,
277 struct ilo_context
*ilo
= ilo_context(pipe
);
279 bind_samplers(ilo
, PIPE_SHADER_GEOMETRY
, 0, num_samplers
, samplers
, true);
280 ilo
->dirty
|= ILO_DIRTY_GEOMETRY_SAMPLERS
;
284 ilo_bind_compute_sampler_states(struct pipe_context
*pipe
,
286 unsigned num_samplers
,
289 struct ilo_context
*ilo
= ilo_context(pipe
);
291 bind_samplers(ilo
, PIPE_SHADER_COMPUTE
,
292 start_slot
, num_samplers
, samplers
, false);
293 ilo
->dirty
|= ILO_DIRTY_COMPUTE_SAMPLERS
;
297 ilo_delete_sampler_state(struct pipe_context
*pipe
, void *state
)
303 ilo_create_rasterizer_state(struct pipe_context
*pipe
,
304 const struct pipe_rasterizer_state
*state
)
306 struct ilo_rasterizer_state
*rast
;
308 rast
= MALLOC_STRUCT(ilo_rasterizer_state
);
311 rast
->state
= *state
;
317 ilo_bind_rasterizer_state(struct pipe_context
*pipe
, void *state
)
319 struct ilo_context
*ilo
= ilo_context(pipe
);
321 ilo
->rasterizer
= state
;
323 ilo
->dirty
|= ILO_DIRTY_RASTERIZER
;
327 ilo_delete_rasterizer_state(struct pipe_context
*pipe
, void *state
)
333 ilo_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
334 const struct pipe_depth_stencil_alpha_state
*state
)
336 struct ilo_context
*ilo
= ilo_context(pipe
);
337 struct ilo_dsa_state
*dsa
;
339 dsa
= MALLOC_STRUCT(ilo_dsa_state
);
342 ilo_gpe_init_dsa(ilo
->dev
, state
, dsa
);
348 ilo_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
350 struct ilo_context
*ilo
= ilo_context(pipe
);
354 ilo
->dirty
|= ILO_DIRTY_DEPTH_STENCIL_ALPHA
;
358 ilo_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *state
)
364 ilo_create_fs_state(struct pipe_context
*pipe
,
365 const struct pipe_shader_state
*state
)
367 struct ilo_context
*ilo
= ilo_context(pipe
);
368 return ilo_shader_state_create(ilo
, PIPE_SHADER_FRAGMENT
, state
);
372 ilo_bind_fs_state(struct pipe_context
*pipe
, void *state
)
374 struct ilo_context
*ilo
= ilo_context(pipe
);
378 ilo
->dirty
|= ILO_DIRTY_FS
;
382 ilo_delete_fs_state(struct pipe_context
*pipe
, void *state
)
384 struct ilo_shader_state
*fs
= (struct ilo_shader_state
*) state
;
385 ilo_shader_state_destroy(fs
);
389 ilo_create_vs_state(struct pipe_context
*pipe
,
390 const struct pipe_shader_state
*state
)
392 struct ilo_context
*ilo
= ilo_context(pipe
);
393 return ilo_shader_state_create(ilo
, PIPE_SHADER_VERTEX
, state
);
397 ilo_bind_vs_state(struct pipe_context
*pipe
, void *state
)
399 struct ilo_context
*ilo
= ilo_context(pipe
);
403 ilo
->dirty
|= ILO_DIRTY_VS
;
407 ilo_delete_vs_state(struct pipe_context
*pipe
, void *state
)
409 struct ilo_shader_state
*vs
= (struct ilo_shader_state
*) state
;
410 ilo_shader_state_destroy(vs
);
414 ilo_create_gs_state(struct pipe_context
*pipe
,
415 const struct pipe_shader_state
*state
)
417 struct ilo_context
*ilo
= ilo_context(pipe
);
418 return ilo_shader_state_create(ilo
, PIPE_SHADER_GEOMETRY
, state
);
422 ilo_bind_gs_state(struct pipe_context
*pipe
, void *state
)
424 struct ilo_context
*ilo
= ilo_context(pipe
);
428 ilo
->dirty
|= ILO_DIRTY_GS
;
432 ilo_delete_gs_state(struct pipe_context
*pipe
, void *state
)
434 struct ilo_shader_state
*gs
= (struct ilo_shader_state
*) state
;
435 ilo_shader_state_destroy(gs
);
439 ilo_create_vertex_elements_state(struct pipe_context
*pipe
,
440 unsigned num_elements
,
441 const struct pipe_vertex_element
*elements
)
443 struct ilo_context
*ilo
= ilo_context(pipe
);
444 struct ilo_ve_state
*ve
;
446 ve
= MALLOC_STRUCT(ilo_ve_state
);
449 ilo_gpe_init_ve(ilo
->dev
, num_elements
, elements
, ve
);
455 ilo_bind_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
457 struct ilo_context
*ilo
= ilo_context(pipe
);
461 ilo
->dirty
|= ILO_DIRTY_VERTEX_ELEMENTS
;
465 ilo_delete_vertex_elements_state(struct pipe_context
*pipe
, void *state
)
467 struct ilo_ve_state
*ve
= state
;
473 ilo_set_blend_color(struct pipe_context
*pipe
,
474 const struct pipe_blend_color
*state
)
476 struct ilo_context
*ilo
= ilo_context(pipe
);
478 ilo
->blend_color
= *state
;
480 ilo
->dirty
|= ILO_DIRTY_BLEND_COLOR
;
484 ilo_set_stencil_ref(struct pipe_context
*pipe
,
485 const struct pipe_stencil_ref
*state
)
487 struct ilo_context
*ilo
= ilo_context(pipe
);
489 ilo
->stencil_ref
= *state
;
491 ilo
->dirty
|= ILO_DIRTY_STENCIL_REF
;
495 ilo_set_sample_mask(struct pipe_context
*pipe
,
496 unsigned sample_mask
)
498 struct ilo_context
*ilo
= ilo_context(pipe
);
500 ilo
->sample_mask
= sample_mask
;
502 ilo
->dirty
|= ILO_DIRTY_SAMPLE_MASK
;
506 ilo_set_clip_state(struct pipe_context
*pipe
,
507 const struct pipe_clip_state
*state
)
509 struct ilo_context
*ilo
= ilo_context(pipe
);
513 ilo
->dirty
|= ILO_DIRTY_CLIP
;
517 ilo_set_constant_buffer(struct pipe_context
*pipe
,
518 uint shader
, uint index
,
519 struct pipe_constant_buffer
*buf
)
521 struct ilo_context
*ilo
= ilo_context(pipe
);
522 struct ilo_cbuf_cso
*cbuf
;
524 assert(shader
< Elements(ilo
->cbuf
));
525 assert(index
< Elements(ilo
->cbuf
[shader
].cso
));
527 cbuf
= &ilo
->cbuf
[shader
].cso
[index
];
530 const enum pipe_format elem_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
532 pipe_resource_reference(&cbuf
->resource
, buf
->buffer
);
534 ilo_gpe_init_view_surface_for_buffer(ilo
->dev
, ilo_buffer(buf
->buffer
),
535 buf
->buffer_offset
, buf
->buffer_size
,
536 util_format_get_blocksize(elem_format
), elem_format
,
537 false, false, &cbuf
->surface
);
540 pipe_resource_reference(&cbuf
->resource
, NULL
);
541 cbuf
->surface
.bo
= NULL
;
544 /* the correct value will be set in ilo_finalize_states() */
545 ilo
->cbuf
[shader
].count
= 0;
547 ilo
->dirty
|= ILO_DIRTY_CONSTANT_BUFFER
;
551 ilo_set_framebuffer_state(struct pipe_context
*pipe
,
552 const struct pipe_framebuffer_state
*state
)
554 struct ilo_context
*ilo
= ilo_context(pipe
);
556 util_copy_framebuffer_state(&ilo
->fb
.state
, state
);
559 ilo
->fb
.num_samples
= state
->cbufs
[0]->texture
->nr_samples
;
560 else if (state
->zsbuf
)
561 ilo
->fb
.num_samples
= state
->zsbuf
->texture
->nr_samples
;
563 ilo
->fb
.num_samples
= 1;
565 if (!ilo
->fb
.num_samples
)
566 ilo
->fb
.num_samples
= 1;
568 ilo
->dirty
|= ILO_DIRTY_FRAMEBUFFER
;
572 ilo_set_polygon_stipple(struct pipe_context
*pipe
,
573 const struct pipe_poly_stipple
*state
)
575 struct ilo_context
*ilo
= ilo_context(pipe
);
577 ilo
->poly_stipple
= *state
;
579 ilo
->dirty
|= ILO_DIRTY_POLY_STIPPLE
;
583 ilo_set_scissor_states(struct pipe_context
*pipe
,
585 unsigned num_scissors
,
586 const struct pipe_scissor_state
*scissors
)
588 struct ilo_context
*ilo
= ilo_context(pipe
);
590 ilo_gpe_set_scissor(ilo
->dev
, start_slot
, num_scissors
,
591 scissors
, &ilo
->scissor
);
593 ilo
->dirty
|= ILO_DIRTY_SCISSOR
;
597 ilo_set_viewport_states(struct pipe_context
*pipe
,
599 unsigned num_viewports
,
600 const struct pipe_viewport_state
*viewports
)
602 struct ilo_context
*ilo
= ilo_context(pipe
);
607 for (i
= 0; i
< num_viewports
; i
++) {
608 ilo_gpe_set_viewport_cso(ilo
->dev
, &viewports
[i
],
609 &ilo
->viewport
.cso
[start_slot
+ i
]);
612 if (ilo
->viewport
.count
< start_slot
+ num_viewports
)
613 ilo
->viewport
.count
= start_slot
+ num_viewports
;
615 /* need to save viewport 0 for util_blitter */
616 if (!start_slot
&& num_viewports
)
617 ilo
->viewport
.viewport0
= viewports
[0];
620 if (ilo
->viewport
.count
<= start_slot
+ num_viewports
&&
621 ilo
->viewport
.count
> start_slot
)
622 ilo
->viewport
.count
= start_slot
;
625 ilo
->dirty
|= ILO_DIRTY_VIEWPORT
;
629 set_sampler_views(struct ilo_context
*ilo
,
630 unsigned shader
, unsigned start
, unsigned count
,
631 struct pipe_sampler_view
**views
, bool unset_old
)
633 struct pipe_sampler_view
**dst
= ilo
->view
[shader
].states
;
636 assert(start
+ count
<= Elements(ilo
->view
[shader
].states
));
644 for (i
= 0; i
< start
; i
++)
645 pipe_sampler_view_reference(&dst
[i
], NULL
);
646 for (; i
< start
+ count
; i
++)
647 pipe_sampler_view_reference(&dst
[i
], views
[i
- start
]);
648 for (; i
< ilo
->view
[shader
].count
; i
++)
649 pipe_sampler_view_reference(&dst
[i
], NULL
);
651 ilo
->view
[shader
].count
= start
+ count
;
658 for (i
= 0; i
< count
; i
++)
659 pipe_sampler_view_reference(&dst
[i
], views
[i
]);
662 for (i
= 0; i
< count
; i
++)
663 pipe_sampler_view_reference(&dst
[i
], NULL
);
666 if (ilo
->view
[shader
].count
<= start
+ count
) {
669 while (count
> 0 && !ilo
->view
[shader
].states
[count
- 1])
672 ilo
->view
[shader
].count
= count
;
677 ilo_set_fragment_sampler_views(struct pipe_context
*pipe
,
679 struct pipe_sampler_view
**views
)
681 struct ilo_context
*ilo
= ilo_context(pipe
);
683 set_sampler_views(ilo
, PIPE_SHADER_FRAGMENT
, 0, num_views
, views
, true);
684 ilo
->dirty
|= ILO_DIRTY_FRAGMENT_SAMPLER_VIEWS
;
688 ilo_set_vertex_sampler_views(struct pipe_context
*pipe
,
690 struct pipe_sampler_view
**views
)
692 struct ilo_context
*ilo
= ilo_context(pipe
);
694 set_sampler_views(ilo
, PIPE_SHADER_VERTEX
, 0, num_views
, views
, true);
695 ilo
->dirty
|= ILO_DIRTY_VERTEX_SAMPLER_VIEWS
;
699 ilo_set_geometry_sampler_views(struct pipe_context
*pipe
,
701 struct pipe_sampler_view
**views
)
703 struct ilo_context
*ilo
= ilo_context(pipe
);
705 set_sampler_views(ilo
, PIPE_SHADER_GEOMETRY
, 0, num_views
, views
, true);
706 ilo
->dirty
|= ILO_DIRTY_GEOMETRY_SAMPLER_VIEWS
;
710 ilo_set_compute_sampler_views(struct pipe_context
*pipe
,
711 unsigned start_slot
, unsigned num_views
,
712 struct pipe_sampler_view
**views
)
714 struct ilo_context
*ilo
= ilo_context(pipe
);
716 set_sampler_views(ilo
, PIPE_SHADER_COMPUTE
,
717 start_slot
, num_views
, views
, false);
719 ilo
->dirty
|= ILO_DIRTY_COMPUTE_SAMPLER_VIEWS
;
723 ilo_set_shader_resources(struct pipe_context
*pipe
,
724 unsigned start
, unsigned count
,
725 struct pipe_surface
**surfaces
)
727 struct ilo_context
*ilo
= ilo_context(pipe
);
728 struct pipe_surface
**dst
= ilo
->resource
.states
;
731 assert(start
+ count
<= Elements(ilo
->resource
.states
));
735 for (i
= 0; i
< count
; i
++)
736 pipe_surface_reference(&dst
[i
], surfaces
[i
]);
739 for (i
= 0; i
< count
; i
++)
740 pipe_surface_reference(&dst
[i
], NULL
);
743 if (ilo
->resource
.count
<= start
+ count
) {
746 while (count
> 0 && !ilo
->resource
.states
[count
- 1])
749 ilo
->resource
.count
= count
;
752 ilo
->dirty
|= ILO_DIRTY_SHADER_RESOURCES
;
756 ilo_set_vertex_buffers(struct pipe_context
*pipe
,
757 unsigned start_slot
, unsigned num_buffers
,
758 const struct pipe_vertex_buffer
*buffers
)
760 struct ilo_context
*ilo
= ilo_context(pipe
);
762 util_set_vertex_buffers_mask(ilo
->vb
.states
,
763 &ilo
->vb
.enabled_mask
, buffers
, start_slot
, num_buffers
);
765 ilo
->dirty
|= ILO_DIRTY_VERTEX_BUFFERS
;
769 ilo_set_index_buffer(struct pipe_context
*pipe
,
770 const struct pipe_index_buffer
*state
)
772 struct ilo_context
*ilo
= ilo_context(pipe
);
775 ilo
->ib
.state
.index_size
= state
->index_size
;
776 ilo
->ib
.state
.offset
= state
->offset
;
777 pipe_resource_reference(&ilo
->ib
.state
.buffer
, state
->buffer
);
778 ilo
->ib
.state
.user_buffer
= state
->user_buffer
;
781 ilo
->ib
.state
.index_size
= 0;
782 ilo
->ib
.state
.offset
= 0;
783 pipe_resource_reference(&ilo
->ib
.state
.buffer
, NULL
);
784 ilo
->ib
.state
.user_buffer
= NULL
;
787 ilo
->dirty
|= ILO_DIRTY_INDEX_BUFFER
;
790 static struct pipe_stream_output_target
*
791 ilo_create_stream_output_target(struct pipe_context
*pipe
,
792 struct pipe_resource
*res
,
793 unsigned buffer_offset
,
794 unsigned buffer_size
)
796 struct pipe_stream_output_target
*target
;
798 target
= MALLOC_STRUCT(pipe_stream_output_target
);
801 pipe_reference_init(&target
->reference
, 1);
802 target
->buffer
= NULL
;
803 pipe_resource_reference(&target
->buffer
, res
);
804 target
->context
= pipe
;
805 target
->buffer_offset
= buffer_offset
;
806 target
->buffer_size
= buffer_size
;
812 ilo_set_stream_output_targets(struct pipe_context
*pipe
,
813 unsigned num_targets
,
814 struct pipe_stream_output_target
**targets
,
815 unsigned append_bitmask
)
817 struct ilo_context
*ilo
= ilo_context(pipe
);
823 for (i
= 0; i
< num_targets
; i
++)
824 pipe_so_target_reference(&ilo
->so
.states
[i
], targets
[i
]);
826 for (; i
< ilo
->so
.count
; i
++)
827 pipe_so_target_reference(&ilo
->so
.states
[i
], NULL
);
829 ilo
->so
.count
= num_targets
;
830 ilo
->so
.append_bitmask
= append_bitmask
;
832 ilo
->so
.enabled
= (ilo
->so
.count
> 0);
834 ilo
->dirty
|= ILO_DIRTY_STREAM_OUTPUT_TARGETS
;
838 ilo_stream_output_target_destroy(struct pipe_context
*pipe
,
839 struct pipe_stream_output_target
*target
)
841 pipe_resource_reference(&target
->buffer
, NULL
);
845 static struct pipe_sampler_view
*
846 ilo_create_sampler_view(struct pipe_context
*pipe
,
847 struct pipe_resource
*res
,
848 const struct pipe_sampler_view
*templ
)
850 struct ilo_context
*ilo
= ilo_context(pipe
);
851 struct ilo_view_cso
*view
;
853 view
= MALLOC_STRUCT(ilo_view_cso
);
857 pipe_reference_init(&view
->base
.reference
, 1);
858 view
->base
.texture
= NULL
;
859 pipe_resource_reference(&view
->base
.texture
, res
);
860 view
->base
.context
= pipe
;
862 if (res
->target
== PIPE_BUFFER
) {
863 const unsigned elem_size
= util_format_get_blocksize(templ
->format
);
864 const unsigned first_elem
= templ
->u
.buf
.first_element
;
865 const unsigned num_elems
= templ
->u
.buf
.last_element
- first_elem
+ 1;
867 ilo_gpe_init_view_surface_for_buffer(ilo
->dev
, ilo_buffer(res
),
868 first_elem
* elem_size
, num_elems
* elem_size
,
869 elem_size
, templ
->format
, false, false, &view
->surface
);
872 ilo_gpe_init_view_surface_for_texture(ilo
->dev
, ilo_texture(res
),
874 templ
->u
.tex
.first_level
,
875 templ
->u
.tex
.last_level
- templ
->u
.tex
.first_level
+ 1,
876 templ
->u
.tex
.first_layer
,
877 templ
->u
.tex
.last_layer
- templ
->u
.tex
.first_layer
+ 1,
878 false, false, &view
->surface
);
885 ilo_sampler_view_destroy(struct pipe_context
*pipe
,
886 struct pipe_sampler_view
*view
)
888 pipe_resource_reference(&view
->texture
, NULL
);
892 static struct pipe_surface
*
893 ilo_create_surface(struct pipe_context
*pipe
,
894 struct pipe_resource
*res
,
895 const struct pipe_surface
*templ
)
897 struct pipe_surface
*surface
;
899 surface
= MALLOC_STRUCT(pipe_surface
);
903 pipe_reference_init(&surface
->reference
, 1);
904 surface
->texture
= NULL
;
905 pipe_resource_reference(&surface
->texture
, res
);
907 surface
->context
= pipe
;
908 surface
->width
= u_minify(res
->width0
, surface
->u
.tex
.level
);
909 surface
->height
= u_minify(res
->height0
, surface
->u
.tex
.level
);
915 ilo_surface_destroy(struct pipe_context
*pipe
,
916 struct pipe_surface
*surface
)
918 pipe_resource_reference(&surface
->texture
, NULL
);
923 ilo_create_compute_state(struct pipe_context
*pipe
,
924 const struct pipe_compute_state
*state
)
926 struct ilo_context
*ilo
= ilo_context(pipe
);
927 return ilo_shader_state_create(ilo
, PIPE_SHADER_COMPUTE
, state
);
931 ilo_bind_compute_state(struct pipe_context
*pipe
, void *state
)
933 struct ilo_context
*ilo
= ilo_context(pipe
);
937 ilo
->dirty
|= ILO_DIRTY_COMPUTE
;
941 ilo_delete_compute_state(struct pipe_context
*pipe
, void *state
)
943 struct ilo_shader_state
*cs
= (struct ilo_shader_state
*) state
;
944 ilo_shader_state_destroy(cs
);
948 ilo_set_compute_resources(struct pipe_context
*pipe
,
949 unsigned start
, unsigned count
,
950 struct pipe_surface
**surfaces
)
952 struct ilo_context
*ilo
= ilo_context(pipe
);
953 struct pipe_surface
**dst
= ilo
->cs_resource
.states
;
956 assert(start
+ count
<= Elements(ilo
->cs_resource
.states
));
960 for (i
= 0; i
< count
; i
++)
961 pipe_surface_reference(&dst
[i
], surfaces
[i
]);
964 for (i
= 0; i
< count
; i
++)
965 pipe_surface_reference(&dst
[i
], NULL
);
968 if (ilo
->cs_resource
.count
<= start
+ count
) {
971 while (count
> 0 && !ilo
->cs_resource
.states
[count
- 1])
974 ilo
->cs_resource
.count
= count
;
977 ilo
->dirty
|= ILO_DIRTY_COMPUTE_RESOURCES
;
981 ilo_set_global_binding(struct pipe_context
*pipe
,
982 unsigned start
, unsigned count
,
983 struct pipe_resource
**resources
,
986 struct ilo_context
*ilo
= ilo_context(pipe
);
987 struct pipe_resource
**dst
= ilo
->global_binding
.resources
;
990 assert(start
+ count
<= Elements(ilo
->global_binding
.resources
));
994 for (i
= 0; i
< count
; i
++)
995 pipe_resource_reference(&dst
[i
], resources
[i
]);
998 for (i
= 0; i
< count
; i
++)
999 pipe_resource_reference(&dst
[i
], NULL
);
1002 if (ilo
->global_binding
.count
<= start
+ count
) {
1005 while (count
> 0 && !ilo
->global_binding
.resources
[count
- 1])
1008 ilo
->global_binding
.count
= count
;
1011 ilo
->dirty
|= ILO_DIRTY_GLOBAL_BINDING
;
1015 * Initialize state-related functions.
1018 ilo_init_state_functions(struct ilo_context
*ilo
)
1020 STATIC_ASSERT(ILO_STATE_COUNT
<= 32);
1022 ilo
->base
.create_blend_state
= ilo_create_blend_state
;
1023 ilo
->base
.bind_blend_state
= ilo_bind_blend_state
;
1024 ilo
->base
.delete_blend_state
= ilo_delete_blend_state
;
1025 ilo
->base
.create_sampler_state
= ilo_create_sampler_state
;
1026 ilo
->base
.bind_fragment_sampler_states
= ilo_bind_fragment_sampler_states
;
1027 ilo
->base
.bind_vertex_sampler_states
= ilo_bind_vertex_sampler_states
;
1028 ilo
->base
.bind_geometry_sampler_states
= ilo_bind_geometry_sampler_states
;
1029 ilo
->base
.bind_compute_sampler_states
= ilo_bind_compute_sampler_states
;
1030 ilo
->base
.delete_sampler_state
= ilo_delete_sampler_state
;
1031 ilo
->base
.create_rasterizer_state
= ilo_create_rasterizer_state
;
1032 ilo
->base
.bind_rasterizer_state
= ilo_bind_rasterizer_state
;
1033 ilo
->base
.delete_rasterizer_state
= ilo_delete_rasterizer_state
;
1034 ilo
->base
.create_depth_stencil_alpha_state
= ilo_create_depth_stencil_alpha_state
;
1035 ilo
->base
.bind_depth_stencil_alpha_state
= ilo_bind_depth_stencil_alpha_state
;
1036 ilo
->base
.delete_depth_stencil_alpha_state
= ilo_delete_depth_stencil_alpha_state
;
1037 ilo
->base
.create_fs_state
= ilo_create_fs_state
;
1038 ilo
->base
.bind_fs_state
= ilo_bind_fs_state
;
1039 ilo
->base
.delete_fs_state
= ilo_delete_fs_state
;
1040 ilo
->base
.create_vs_state
= ilo_create_vs_state
;
1041 ilo
->base
.bind_vs_state
= ilo_bind_vs_state
;
1042 ilo
->base
.delete_vs_state
= ilo_delete_vs_state
;
1043 ilo
->base
.create_gs_state
= ilo_create_gs_state
;
1044 ilo
->base
.bind_gs_state
= ilo_bind_gs_state
;
1045 ilo
->base
.delete_gs_state
= ilo_delete_gs_state
;
1046 ilo
->base
.create_vertex_elements_state
= ilo_create_vertex_elements_state
;
1047 ilo
->base
.bind_vertex_elements_state
= ilo_bind_vertex_elements_state
;
1048 ilo
->base
.delete_vertex_elements_state
= ilo_delete_vertex_elements_state
;
1050 ilo
->base
.set_blend_color
= ilo_set_blend_color
;
1051 ilo
->base
.set_stencil_ref
= ilo_set_stencil_ref
;
1052 ilo
->base
.set_sample_mask
= ilo_set_sample_mask
;
1053 ilo
->base
.set_clip_state
= ilo_set_clip_state
;
1054 ilo
->base
.set_constant_buffer
= ilo_set_constant_buffer
;
1055 ilo
->base
.set_framebuffer_state
= ilo_set_framebuffer_state
;
1056 ilo
->base
.set_polygon_stipple
= ilo_set_polygon_stipple
;
1057 ilo
->base
.set_scissor_states
= ilo_set_scissor_states
;
1058 ilo
->base
.set_viewport_states
= ilo_set_viewport_states
;
1059 ilo
->base
.set_fragment_sampler_views
= ilo_set_fragment_sampler_views
;
1060 ilo
->base
.set_vertex_sampler_views
= ilo_set_vertex_sampler_views
;
1061 ilo
->base
.set_geometry_sampler_views
= ilo_set_geometry_sampler_views
;
1062 ilo
->base
.set_compute_sampler_views
= ilo_set_compute_sampler_views
;
1063 ilo
->base
.set_shader_resources
= ilo_set_shader_resources
;
1064 ilo
->base
.set_vertex_buffers
= ilo_set_vertex_buffers
;
1065 ilo
->base
.set_index_buffer
= ilo_set_index_buffer
;
1067 ilo
->base
.create_stream_output_target
= ilo_create_stream_output_target
;
1068 ilo
->base
.stream_output_target_destroy
= ilo_stream_output_target_destroy
;
1069 ilo
->base
.set_stream_output_targets
= ilo_set_stream_output_targets
;
1071 ilo
->base
.create_sampler_view
= ilo_create_sampler_view
;
1072 ilo
->base
.sampler_view_destroy
= ilo_sampler_view_destroy
;
1074 ilo
->base
.create_surface
= ilo_create_surface
;
1075 ilo
->base
.surface_destroy
= ilo_surface_destroy
;
1077 ilo
->base
.create_compute_state
= ilo_create_compute_state
;
1078 ilo
->base
.bind_compute_state
= ilo_bind_compute_state
;
1079 ilo
->base
.delete_compute_state
= ilo_delete_compute_state
;
1080 ilo
->base
.set_compute_resources
= ilo_set_compute_resources
;
1081 ilo
->base
.set_global_binding
= ilo_set_global_binding
;
1085 ilo_init_states(struct ilo_context
*ilo
)
1087 ilo_gpe_set_scissor_null(ilo
->dev
, &ilo
->scissor
);
1091 ilo_cleanup_states(struct ilo_context
*ilo
)