1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Wrap the cso cache & hash mechanisms in a simplified
32 * pipe-driver-specific interface.
34 * @author Zack Rusin <zackr@vmware.com>
35 * @author Keith Whitwell <keithw@vmware.com>
38 #include "pipe/p_state.h"
39 #include "util/u_draw.h"
40 #include "util/u_framebuffer.h"
41 #include "util/u_inlines.h"
42 #include "util/u_math.h"
43 #include "util/u_memory.h"
44 #include "util/u_vbuf.h"
45 #include "tgsi/tgsi_parse.h"
47 #include "cso_cache/cso_context.h"
48 #include "cso_cache/cso_cache.h"
49 #include "cso_cache/cso_hash.h"
50 #include "cso_context.h"
54 * Info related to samplers and sampler views.
55 * We have one of these for fragment samplers and another for vertex samplers.
59 void *samplers
[PIPE_MAX_SAMPLERS
];
62 void *samplers_saved
[PIPE_MAX_SAMPLERS
];
63 unsigned nr_samplers_saved
;
69 struct pipe_context
*pipe
;
70 struct cso_cache
*cache
;
73 boolean has_geometry_shader
;
74 boolean has_tessellation
;
75 boolean has_streamout
;
77 struct pipe_sampler_view
*fragment_views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
78 unsigned nr_fragment_views
;
80 struct pipe_sampler_view
*fragment_views_saved
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
81 unsigned nr_fragment_views_saved
;
83 struct sampler_info samplers
[PIPE_SHADER_TYPES
];
85 struct pipe_vertex_buffer aux_vertex_buffer_current
;
86 struct pipe_vertex_buffer aux_vertex_buffer_saved
;
87 unsigned aux_vertex_buffer_index
;
89 struct pipe_constant_buffer aux_constbuf_current
[PIPE_SHADER_TYPES
];
90 struct pipe_constant_buffer aux_constbuf_saved
[PIPE_SHADER_TYPES
];
92 unsigned nr_so_targets
;
93 struct pipe_stream_output_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
95 unsigned nr_so_targets_saved
;
96 struct pipe_stream_output_target
*so_targets_saved
[PIPE_MAX_SO_BUFFERS
];
98 /** Current and saved state.
99 * The saved state is used as a 1-deep stack.
101 void *blend
, *blend_saved
;
102 void *depth_stencil
, *depth_stencil_saved
;
103 void *rasterizer
, *rasterizer_saved
;
104 void *fragment_shader
, *fragment_shader_saved
;
105 void *vertex_shader
, *vertex_shader_saved
;
106 void *geometry_shader
, *geometry_shader_saved
;
107 void *tessctrl_shader
, *tessctrl_shader_saved
;
108 void *tesseval_shader
, *tesseval_shader_saved
;
109 void *velements
, *velements_saved
;
110 struct pipe_query
*render_condition
, *render_condition_saved
;
111 uint render_condition_mode
, render_condition_mode_saved
;
112 boolean render_condition_cond
, render_condition_cond_saved
;
114 struct pipe_clip_state clip
;
115 struct pipe_clip_state clip_saved
;
117 struct pipe_framebuffer_state fb
, fb_saved
;
118 struct pipe_viewport_state vp
, vp_saved
;
119 struct pipe_blend_color blend_color
;
120 unsigned sample_mask
, sample_mask_saved
;
121 unsigned min_samples
, min_samples_saved
;
122 struct pipe_stencil_ref stencil_ref
, stencil_ref_saved
;
126 static boolean
delete_blend_state(struct cso_context
*ctx
, void *state
)
128 struct cso_blend
*cso
= (struct cso_blend
*)state
;
130 if (ctx
->blend
== cso
->data
)
133 if (cso
->delete_state
)
134 cso
->delete_state(cso
->context
, cso
->data
);
139 static boolean
delete_depth_stencil_state(struct cso_context
*ctx
, void *state
)
141 struct cso_depth_stencil_alpha
*cso
=
142 (struct cso_depth_stencil_alpha
*)state
;
144 if (ctx
->depth_stencil
== cso
->data
)
147 if (cso
->delete_state
)
148 cso
->delete_state(cso
->context
, cso
->data
);
154 static boolean
delete_sampler_state(struct cso_context
*ctx
, void *state
)
156 struct cso_sampler
*cso
= (struct cso_sampler
*)state
;
157 if (cso
->delete_state
)
158 cso
->delete_state(cso
->context
, cso
->data
);
163 static boolean
delete_rasterizer_state(struct cso_context
*ctx
, void *state
)
165 struct cso_rasterizer
*cso
= (struct cso_rasterizer
*)state
;
167 if (ctx
->rasterizer
== cso
->data
)
169 if (cso
->delete_state
)
170 cso
->delete_state(cso
->context
, cso
->data
);
175 static boolean
delete_vertex_elements(struct cso_context
*ctx
,
178 struct cso_velements
*cso
= (struct cso_velements
*)state
;
180 if (ctx
->velements
== cso
->data
)
183 if (cso
->delete_state
)
184 cso
->delete_state(cso
->context
, cso
->data
);
190 static inline boolean
delete_cso(struct cso_context
*ctx
,
191 void *state
, enum cso_cache_type type
)
195 return delete_blend_state(ctx
, state
);
197 return delete_sampler_state(ctx
, state
);
198 case CSO_DEPTH_STENCIL_ALPHA
:
199 return delete_depth_stencil_state(ctx
, state
);
201 return delete_rasterizer_state(ctx
, state
);
203 return delete_vertex_elements(ctx
, state
);
212 sanitize_hash(struct cso_hash
*hash
, enum cso_cache_type type
,
213 int max_size
, void *user_data
)
215 struct cso_context
*ctx
= (struct cso_context
*)user_data
;
216 /* if we're approach the maximum size, remove fourth of the entries
217 * otherwise every subsequent call will go through the same */
218 int hash_size
= cso_hash_size(hash
);
219 int max_entries
= (max_size
> hash_size
) ? max_size
: hash_size
;
220 int to_remove
= (max_size
< max_entries
) * max_entries
/4;
221 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
222 if (hash_size
> max_size
)
223 to_remove
+= hash_size
- max_size
;
225 /*remove elements until we're good */
226 /*fixme: currently we pick the nodes to remove at random*/
227 void *cso
= cso_hash_iter_data(iter
);
228 if (delete_cso(ctx
, cso
, type
)) {
229 iter
= cso_hash_erase(hash
, iter
);
232 iter
= cso_hash_iter_next(iter
);
236 static void cso_init_vbuf(struct cso_context
*cso
)
238 struct u_vbuf_caps caps
;
240 /* Install u_vbuf if there is anything unsupported. */
241 if (u_vbuf_get_caps(cso
->pipe
->screen
, &caps
)) {
242 cso
->vbuf
= u_vbuf_create(cso
->pipe
, &caps
,
243 cso
->aux_vertex_buffer_index
);
247 struct cso_context
*cso_create_context( struct pipe_context
*pipe
)
249 struct cso_context
*ctx
= CALLOC_STRUCT(cso_context
);
253 ctx
->cache
= cso_cache_create();
254 if (ctx
->cache
== NULL
)
256 cso_cache_set_sanitize_callback(ctx
->cache
,
261 ctx
->sample_mask
= ~0;
263 ctx
->aux_vertex_buffer_index
= 0; /* 0 for now */
267 /* Enable for testing: */
268 if (0) cso_set_maximum_cache_size( ctx
->cache
, 4 );
270 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_GEOMETRY
,
271 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
272 ctx
->has_geometry_shader
= TRUE
;
274 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_TESS_CTRL
,
275 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
276 ctx
->has_tessellation
= TRUE
;
278 if (pipe
->screen
->get_param(pipe
->screen
,
279 PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
) != 0) {
280 ctx
->has_streamout
= TRUE
;
286 cso_destroy_context( ctx
);
291 * Free the CSO context.
293 void cso_destroy_context( struct cso_context
*ctx
)
298 ctx
->pipe
->set_index_buffer(ctx
->pipe
, NULL
);
300 ctx
->pipe
->bind_blend_state( ctx
->pipe
, NULL
);
301 ctx
->pipe
->bind_rasterizer_state( ctx
->pipe
, NULL
);
304 static struct pipe_sampler_view
*views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
] = { NULL
};
305 static void *zeros
[PIPE_MAX_SAMPLERS
] = { NULL
};
306 struct pipe_screen
*scr
= ctx
->pipe
->screen
;
308 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
309 int maxsam
= scr
->get_shader_param(scr
, sh
,
310 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
311 int maxview
= scr
->get_shader_param(scr
, sh
,
312 PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS
);
313 assert(maxsam
<= PIPE_MAX_SAMPLERS
);
314 assert(maxview
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
316 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, sh
, 0, maxsam
, zeros
);
319 ctx
->pipe
->set_sampler_views(ctx
->pipe
, sh
, 0, maxview
, views
);
324 ctx
->pipe
->bind_depth_stencil_alpha_state( ctx
->pipe
, NULL
);
325 ctx
->pipe
->bind_fs_state( ctx
->pipe
, NULL
);
326 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_FRAGMENT
, 0, NULL
);
327 ctx
->pipe
->bind_vs_state( ctx
->pipe
, NULL
);
328 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_VERTEX
, 0, NULL
);
329 if (ctx
->has_geometry_shader
) {
330 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
331 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_GEOMETRY
, 0, NULL
);
333 if (ctx
->has_tessellation
) {
334 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, NULL
);
335 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_TESS_CTRL
, 0, NULL
);
336 ctx
->pipe
->bind_tes_state(ctx
->pipe
, NULL
);
337 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_TESS_EVAL
, 0, NULL
);
339 ctx
->pipe
->bind_vertex_elements_state( ctx
->pipe
, NULL
);
341 if (ctx
->has_streamout
)
342 ctx
->pipe
->set_stream_output_targets(ctx
->pipe
, 0, NULL
, NULL
);
345 for (i
= 0; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; i
++) {
346 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
347 pipe_sampler_view_reference(&ctx
->fragment_views_saved
[i
], NULL
);
350 util_unreference_framebuffer_state(&ctx
->fb
);
351 util_unreference_framebuffer_state(&ctx
->fb_saved
);
353 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
, NULL
);
354 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
356 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
357 pipe_resource_reference(&ctx
->aux_constbuf_current
[i
].buffer
, NULL
);
358 pipe_resource_reference(&ctx
->aux_constbuf_saved
[i
].buffer
, NULL
);
361 for (i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
362 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
363 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], NULL
);
367 cso_cache_delete( ctx
->cache
);
372 u_vbuf_destroy(ctx
->vbuf
);
377 /* Those function will either find the state of the given template
378 * in the cache or they will create a new state from the given
379 * template, insert it in the cache and return it.
383 * If the driver returns 0 from the create method then they will assign
384 * the data member of the cso to be the template itself.
387 enum pipe_error
cso_set_blend(struct cso_context
*ctx
,
388 const struct pipe_blend_state
*templ
)
390 unsigned key_size
, hash_key
;
391 struct cso_hash_iter iter
;
394 key_size
= templ
->independent_blend_enable
?
395 sizeof(struct pipe_blend_state
) :
396 (char *)&(templ
->rt
[1]) - (char *)templ
;
397 hash_key
= cso_construct_key((void*)templ
, key_size
);
398 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_BLEND
,
399 (void*)templ
, key_size
);
401 if (cso_hash_iter_is_null(iter
)) {
402 struct cso_blend
*cso
= MALLOC(sizeof(struct cso_blend
));
404 return PIPE_ERROR_OUT_OF_MEMORY
;
406 memset(&cso
->state
, 0, sizeof cso
->state
);
407 memcpy(&cso
->state
, templ
, key_size
);
408 cso
->data
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &cso
->state
);
409 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_blend_state
;
410 cso
->context
= ctx
->pipe
;
412 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_BLEND
, cso
);
413 if (cso_hash_iter_is_null(iter
)) {
415 return PIPE_ERROR_OUT_OF_MEMORY
;
421 handle
= ((struct cso_blend
*)cso_hash_iter_data(iter
))->data
;
424 if (ctx
->blend
!= handle
) {
426 ctx
->pipe
->bind_blend_state(ctx
->pipe
, handle
);
431 void cso_save_blend(struct cso_context
*ctx
)
433 assert(!ctx
->blend_saved
);
434 ctx
->blend_saved
= ctx
->blend
;
437 void cso_restore_blend(struct cso_context
*ctx
)
439 if (ctx
->blend
!= ctx
->blend_saved
) {
440 ctx
->blend
= ctx
->blend_saved
;
441 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend_saved
);
443 ctx
->blend_saved
= NULL
;
449 cso_set_depth_stencil_alpha(struct cso_context
*ctx
,
450 const struct pipe_depth_stencil_alpha_state
*templ
)
452 unsigned key_size
= sizeof(struct pipe_depth_stencil_alpha_state
);
453 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
454 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
456 CSO_DEPTH_STENCIL_ALPHA
,
457 (void*)templ
, key_size
);
460 if (cso_hash_iter_is_null(iter
)) {
461 struct cso_depth_stencil_alpha
*cso
=
462 MALLOC(sizeof(struct cso_depth_stencil_alpha
));
464 return PIPE_ERROR_OUT_OF_MEMORY
;
466 memcpy(&cso
->state
, templ
, sizeof(*templ
));
467 cso
->data
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
,
470 (cso_state_callback
)ctx
->pipe
->delete_depth_stencil_alpha_state
;
471 cso
->context
= ctx
->pipe
;
473 iter
= cso_insert_state(ctx
->cache
, hash_key
,
474 CSO_DEPTH_STENCIL_ALPHA
, cso
);
475 if (cso_hash_iter_is_null(iter
)) {
477 return PIPE_ERROR_OUT_OF_MEMORY
;
483 handle
= ((struct cso_depth_stencil_alpha
*)
484 cso_hash_iter_data(iter
))->data
;
487 if (ctx
->depth_stencil
!= handle
) {
488 ctx
->depth_stencil
= handle
;
489 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, handle
);
494 void cso_save_depth_stencil_alpha(struct cso_context
*ctx
)
496 assert(!ctx
->depth_stencil_saved
);
497 ctx
->depth_stencil_saved
= ctx
->depth_stencil
;
500 void cso_restore_depth_stencil_alpha(struct cso_context
*ctx
)
502 if (ctx
->depth_stencil
!= ctx
->depth_stencil_saved
) {
503 ctx
->depth_stencil
= ctx
->depth_stencil_saved
;
504 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
,
505 ctx
->depth_stencil_saved
);
507 ctx
->depth_stencil_saved
= NULL
;
512 enum pipe_error
cso_set_rasterizer(struct cso_context
*ctx
,
513 const struct pipe_rasterizer_state
*templ
)
515 unsigned key_size
= sizeof(struct pipe_rasterizer_state
);
516 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
517 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
520 (void*)templ
, key_size
);
523 if (cso_hash_iter_is_null(iter
)) {
524 struct cso_rasterizer
*cso
= MALLOC(sizeof(struct cso_rasterizer
));
526 return PIPE_ERROR_OUT_OF_MEMORY
;
528 memcpy(&cso
->state
, templ
, sizeof(*templ
));
529 cso
->data
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &cso
->state
);
531 (cso_state_callback
)ctx
->pipe
->delete_rasterizer_state
;
532 cso
->context
= ctx
->pipe
;
534 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_RASTERIZER
, cso
);
535 if (cso_hash_iter_is_null(iter
)) {
537 return PIPE_ERROR_OUT_OF_MEMORY
;
543 handle
= ((struct cso_rasterizer
*)cso_hash_iter_data(iter
))->data
;
546 if (ctx
->rasterizer
!= handle
) {
547 ctx
->rasterizer
= handle
;
548 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, handle
);
553 void cso_save_rasterizer(struct cso_context
*ctx
)
555 assert(!ctx
->rasterizer_saved
);
556 ctx
->rasterizer_saved
= ctx
->rasterizer
;
559 void cso_restore_rasterizer(struct cso_context
*ctx
)
561 if (ctx
->rasterizer
!= ctx
->rasterizer_saved
) {
562 ctx
->rasterizer
= ctx
->rasterizer_saved
;
563 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rasterizer_saved
);
565 ctx
->rasterizer_saved
= NULL
;
569 void cso_set_fragment_shader_handle(struct cso_context
*ctx
, void *handle
)
571 if (ctx
->fragment_shader
!= handle
) {
572 ctx
->fragment_shader
= handle
;
573 ctx
->pipe
->bind_fs_state(ctx
->pipe
, handle
);
577 void cso_delete_fragment_shader(struct cso_context
*ctx
, void *handle
)
579 if (handle
== ctx
->fragment_shader
) {
580 /* unbind before deleting */
581 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
582 ctx
->fragment_shader
= NULL
;
584 ctx
->pipe
->delete_fs_state(ctx
->pipe
, handle
);
587 void cso_save_fragment_shader(struct cso_context
*ctx
)
589 assert(!ctx
->fragment_shader_saved
);
590 ctx
->fragment_shader_saved
= ctx
->fragment_shader
;
593 void cso_restore_fragment_shader(struct cso_context
*ctx
)
595 if (ctx
->fragment_shader_saved
!= ctx
->fragment_shader
) {
596 ctx
->pipe
->bind_fs_state(ctx
->pipe
, ctx
->fragment_shader_saved
);
597 ctx
->fragment_shader
= ctx
->fragment_shader_saved
;
599 ctx
->fragment_shader_saved
= NULL
;
603 void cso_set_vertex_shader_handle(struct cso_context
*ctx
, void *handle
)
605 if (ctx
->vertex_shader
!= handle
) {
606 ctx
->vertex_shader
= handle
;
607 ctx
->pipe
->bind_vs_state(ctx
->pipe
, handle
);
611 void cso_delete_vertex_shader(struct cso_context
*ctx
, void *handle
)
613 if (handle
== ctx
->vertex_shader
) {
614 /* unbind before deleting */
615 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
616 ctx
->vertex_shader
= NULL
;
618 ctx
->pipe
->delete_vs_state(ctx
->pipe
, handle
);
621 void cso_save_vertex_shader(struct cso_context
*ctx
)
623 assert(!ctx
->vertex_shader_saved
);
624 ctx
->vertex_shader_saved
= ctx
->vertex_shader
;
627 void cso_restore_vertex_shader(struct cso_context
*ctx
)
629 if (ctx
->vertex_shader_saved
!= ctx
->vertex_shader
) {
630 ctx
->pipe
->bind_vs_state(ctx
->pipe
, ctx
->vertex_shader_saved
);
631 ctx
->vertex_shader
= ctx
->vertex_shader_saved
;
633 ctx
->vertex_shader_saved
= NULL
;
637 void cso_set_framebuffer(struct cso_context
*ctx
,
638 const struct pipe_framebuffer_state
*fb
)
640 if (memcmp(&ctx
->fb
, fb
, sizeof(*fb
)) != 0) {
641 util_copy_framebuffer_state(&ctx
->fb
, fb
);
642 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, fb
);
646 void cso_save_framebuffer(struct cso_context
*ctx
)
648 util_copy_framebuffer_state(&ctx
->fb_saved
, &ctx
->fb
);
651 void cso_restore_framebuffer(struct cso_context
*ctx
)
653 if (memcmp(&ctx
->fb
, &ctx
->fb_saved
, sizeof(ctx
->fb
))) {
654 util_copy_framebuffer_state(&ctx
->fb
, &ctx
->fb_saved
);
655 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, &ctx
->fb
);
656 util_unreference_framebuffer_state(&ctx
->fb_saved
);
661 void cso_set_viewport(struct cso_context
*ctx
,
662 const struct pipe_viewport_state
*vp
)
664 if (memcmp(&ctx
->vp
, vp
, sizeof(*vp
))) {
666 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, vp
);
670 void cso_save_viewport(struct cso_context
*ctx
)
672 ctx
->vp_saved
= ctx
->vp
;
676 void cso_restore_viewport(struct cso_context
*ctx
)
678 if (memcmp(&ctx
->vp
, &ctx
->vp_saved
, sizeof(ctx
->vp
))) {
679 ctx
->vp
= ctx
->vp_saved
;
680 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, &ctx
->vp
);
685 void cso_set_blend_color(struct cso_context
*ctx
,
686 const struct pipe_blend_color
*bc
)
688 if (memcmp(&ctx
->blend_color
, bc
, sizeof(ctx
->blend_color
))) {
689 ctx
->blend_color
= *bc
;
690 ctx
->pipe
->set_blend_color(ctx
->pipe
, bc
);
694 void cso_set_sample_mask(struct cso_context
*ctx
, unsigned sample_mask
)
696 if (ctx
->sample_mask
!= sample_mask
) {
697 ctx
->sample_mask
= sample_mask
;
698 ctx
->pipe
->set_sample_mask(ctx
->pipe
, sample_mask
);
702 void cso_save_sample_mask(struct cso_context
*ctx
)
704 ctx
->sample_mask_saved
= ctx
->sample_mask
;
707 void cso_restore_sample_mask(struct cso_context
*ctx
)
709 cso_set_sample_mask(ctx
, ctx
->sample_mask_saved
);
712 void cso_set_min_samples(struct cso_context
*ctx
, unsigned min_samples
)
714 if (ctx
->min_samples
!= min_samples
&& ctx
->pipe
->set_min_samples
) {
715 ctx
->min_samples
= min_samples
;
716 ctx
->pipe
->set_min_samples(ctx
->pipe
, min_samples
);
720 void cso_save_min_samples(struct cso_context
*ctx
)
722 ctx
->min_samples_saved
= ctx
->min_samples
;
725 void cso_restore_min_samples(struct cso_context
*ctx
)
727 cso_set_min_samples(ctx
, ctx
->min_samples_saved
);
730 void cso_set_stencil_ref(struct cso_context
*ctx
,
731 const struct pipe_stencil_ref
*sr
)
733 if (memcmp(&ctx
->stencil_ref
, sr
, sizeof(ctx
->stencil_ref
))) {
734 ctx
->stencil_ref
= *sr
;
735 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, sr
);
739 void cso_save_stencil_ref(struct cso_context
*ctx
)
741 ctx
->stencil_ref_saved
= ctx
->stencil_ref
;
745 void cso_restore_stencil_ref(struct cso_context
*ctx
)
747 if (memcmp(&ctx
->stencil_ref
, &ctx
->stencil_ref_saved
,
748 sizeof(ctx
->stencil_ref
))) {
749 ctx
->stencil_ref
= ctx
->stencil_ref_saved
;
750 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, &ctx
->stencil_ref
);
754 void cso_set_render_condition(struct cso_context
*ctx
,
755 struct pipe_query
*query
,
756 boolean condition
, uint mode
)
758 struct pipe_context
*pipe
= ctx
->pipe
;
760 if (ctx
->render_condition
!= query
||
761 ctx
->render_condition_mode
!= mode
||
762 ctx
->render_condition_cond
!= condition
) {
763 pipe
->render_condition(pipe
, query
, condition
, mode
);
764 ctx
->render_condition
= query
;
765 ctx
->render_condition_cond
= condition
;
766 ctx
->render_condition_mode
= mode
;
770 void cso_save_render_condition(struct cso_context
*ctx
)
772 ctx
->render_condition_saved
= ctx
->render_condition
;
773 ctx
->render_condition_cond_saved
= ctx
->render_condition_cond
;
774 ctx
->render_condition_mode_saved
= ctx
->render_condition_mode
;
777 void cso_restore_render_condition(struct cso_context
*ctx
)
779 cso_set_render_condition(ctx
, ctx
->render_condition_saved
,
780 ctx
->render_condition_cond_saved
,
781 ctx
->render_condition_mode_saved
);
784 void cso_set_geometry_shader_handle(struct cso_context
*ctx
, void *handle
)
786 assert(ctx
->has_geometry_shader
|| !handle
);
788 if (ctx
->has_geometry_shader
&& ctx
->geometry_shader
!= handle
) {
789 ctx
->geometry_shader
= handle
;
790 ctx
->pipe
->bind_gs_state(ctx
->pipe
, handle
);
794 void cso_delete_geometry_shader(struct cso_context
*ctx
, void *handle
)
796 if (handle
== ctx
->geometry_shader
) {
797 /* unbind before deleting */
798 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
799 ctx
->geometry_shader
= NULL
;
801 ctx
->pipe
->delete_gs_state(ctx
->pipe
, handle
);
804 void cso_save_geometry_shader(struct cso_context
*ctx
)
806 if (!ctx
->has_geometry_shader
) {
810 assert(!ctx
->geometry_shader_saved
);
811 ctx
->geometry_shader_saved
= ctx
->geometry_shader
;
814 void cso_restore_geometry_shader(struct cso_context
*ctx
)
816 if (!ctx
->has_geometry_shader
) {
820 if (ctx
->geometry_shader_saved
!= ctx
->geometry_shader
) {
821 ctx
->pipe
->bind_gs_state(ctx
->pipe
, ctx
->geometry_shader_saved
);
822 ctx
->geometry_shader
= ctx
->geometry_shader_saved
;
824 ctx
->geometry_shader_saved
= NULL
;
827 void cso_set_tessctrl_shader_handle(struct cso_context
*ctx
, void *handle
)
829 assert(ctx
->has_tessellation
|| !handle
);
831 if (ctx
->has_tessellation
&& ctx
->tessctrl_shader
!= handle
) {
832 ctx
->tessctrl_shader
= handle
;
833 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, handle
);
837 void cso_delete_tessctrl_shader(struct cso_context
*ctx
, void *handle
)
839 if (handle
== ctx
->tessctrl_shader
) {
840 /* unbind before deleting */
841 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, NULL
);
842 ctx
->tessctrl_shader
= NULL
;
844 ctx
->pipe
->delete_tcs_state(ctx
->pipe
, handle
);
847 void cso_save_tessctrl_shader(struct cso_context
*ctx
)
849 if (!ctx
->has_tessellation
) {
853 assert(!ctx
->tessctrl_shader_saved
);
854 ctx
->tessctrl_shader_saved
= ctx
->tessctrl_shader
;
857 void cso_restore_tessctrl_shader(struct cso_context
*ctx
)
859 if (!ctx
->has_tessellation
) {
863 if (ctx
->tessctrl_shader_saved
!= ctx
->tessctrl_shader
) {
864 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, ctx
->tessctrl_shader_saved
);
865 ctx
->tessctrl_shader
= ctx
->tessctrl_shader_saved
;
867 ctx
->tessctrl_shader_saved
= NULL
;
870 void cso_set_tesseval_shader_handle(struct cso_context
*ctx
, void *handle
)
872 assert(ctx
->has_tessellation
|| !handle
);
874 if (ctx
->has_tessellation
&& ctx
->tesseval_shader
!= handle
) {
875 ctx
->tesseval_shader
= handle
;
876 ctx
->pipe
->bind_tes_state(ctx
->pipe
, handle
);
880 void cso_delete_tesseval_shader(struct cso_context
*ctx
, void *handle
)
882 if (handle
== ctx
->tesseval_shader
) {
883 /* unbind before deleting */
884 ctx
->pipe
->bind_tes_state(ctx
->pipe
, NULL
);
885 ctx
->tesseval_shader
= NULL
;
887 ctx
->pipe
->delete_tes_state(ctx
->pipe
, handle
);
890 void cso_save_tesseval_shader(struct cso_context
*ctx
)
892 if (!ctx
->has_tessellation
) {
896 assert(!ctx
->tesseval_shader_saved
);
897 ctx
->tesseval_shader_saved
= ctx
->tesseval_shader
;
900 void cso_restore_tesseval_shader(struct cso_context
*ctx
)
902 if (!ctx
->has_tessellation
) {
906 if (ctx
->tesseval_shader_saved
!= ctx
->tesseval_shader
) {
907 ctx
->pipe
->bind_tes_state(ctx
->pipe
, ctx
->tesseval_shader_saved
);
908 ctx
->tesseval_shader
= ctx
->tesseval_shader_saved
;
910 ctx
->tesseval_shader_saved
= NULL
;
916 clip_state_cpy(struct pipe_clip_state
*dst
,
917 const struct pipe_clip_state
*src
)
919 memcpy(dst
->ucp
, src
->ucp
, sizeof(dst
->ucp
));
923 clip_state_cmp(const struct pipe_clip_state
*a
,
924 const struct pipe_clip_state
*b
)
926 return memcmp(a
->ucp
, b
->ucp
, sizeof(a
->ucp
));
930 cso_set_clip(struct cso_context
*ctx
,
931 const struct pipe_clip_state
*clip
)
933 if (clip_state_cmp(&ctx
->clip
, clip
)) {
934 clip_state_cpy(&ctx
->clip
, clip
);
935 ctx
->pipe
->set_clip_state(ctx
->pipe
, clip
);
940 cso_save_clip(struct cso_context
*ctx
)
942 clip_state_cpy(&ctx
->clip_saved
, &ctx
->clip
);
946 cso_restore_clip(struct cso_context
*ctx
)
948 if (clip_state_cmp(&ctx
->clip
, &ctx
->clip_saved
)) {
949 clip_state_cpy(&ctx
->clip
, &ctx
->clip_saved
);
950 ctx
->pipe
->set_clip_state(ctx
->pipe
, &ctx
->clip_saved
);
955 cso_set_vertex_elements(struct cso_context
*ctx
,
957 const struct pipe_vertex_element
*states
)
959 struct u_vbuf
*vbuf
= ctx
->vbuf
;
960 unsigned key_size
, hash_key
;
961 struct cso_hash_iter iter
;
963 struct cso_velems_state velems_state
;
966 u_vbuf_set_vertex_elements(vbuf
, count
, states
);
970 /* Need to include the count into the stored state data too.
971 * Otherwise first few count pipe_vertex_elements could be identical
972 * even if count is different, and there's no guarantee the hash would
973 * be different in that case neither.
975 key_size
= sizeof(struct pipe_vertex_element
) * count
+ sizeof(unsigned);
976 velems_state
.count
= count
;
977 memcpy(velems_state
.velems
, states
,
978 sizeof(struct pipe_vertex_element
) * count
);
979 hash_key
= cso_construct_key((void*)&velems_state
, key_size
);
980 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_VELEMENTS
,
981 (void*)&velems_state
, key_size
);
983 if (cso_hash_iter_is_null(iter
)) {
984 struct cso_velements
*cso
= MALLOC(sizeof(struct cso_velements
));
986 return PIPE_ERROR_OUT_OF_MEMORY
;
988 memcpy(&cso
->state
, &velems_state
, key_size
);
989 cso
->data
= ctx
->pipe
->create_vertex_elements_state(ctx
->pipe
, count
,
990 &cso
->state
.velems
[0]);
992 (cso_state_callback
) ctx
->pipe
->delete_vertex_elements_state
;
993 cso
->context
= ctx
->pipe
;
995 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VELEMENTS
, cso
);
996 if (cso_hash_iter_is_null(iter
)) {
998 return PIPE_ERROR_OUT_OF_MEMORY
;
1004 handle
= ((struct cso_velements
*)cso_hash_iter_data(iter
))->data
;
1007 if (ctx
->velements
!= handle
) {
1008 ctx
->velements
= handle
;
1009 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, handle
);
1014 void cso_save_vertex_elements(struct cso_context
*ctx
)
1016 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1019 u_vbuf_save_vertex_elements(vbuf
);
1023 assert(!ctx
->velements_saved
);
1024 ctx
->velements_saved
= ctx
->velements
;
1027 void cso_restore_vertex_elements(struct cso_context
*ctx
)
1029 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1032 u_vbuf_restore_vertex_elements(vbuf
);
1036 if (ctx
->velements
!= ctx
->velements_saved
) {
1037 ctx
->velements
= ctx
->velements_saved
;
1038 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->velements_saved
);
1040 ctx
->velements_saved
= NULL
;
1043 /* vertex buffers */
1045 void cso_set_vertex_buffers(struct cso_context
*ctx
,
1046 unsigned start_slot
, unsigned count
,
1047 const struct pipe_vertex_buffer
*buffers
)
1049 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1052 u_vbuf_set_vertex_buffers(vbuf
, start_slot
, count
, buffers
);
1056 /* Save what's in the auxiliary slot, so that we can save and restore it
1058 if (start_slot
<= ctx
->aux_vertex_buffer_index
&&
1059 start_slot
+count
> ctx
->aux_vertex_buffer_index
) {
1061 const struct pipe_vertex_buffer
*vb
=
1062 buffers
+ (ctx
->aux_vertex_buffer_index
- start_slot
);
1064 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1066 memcpy(&ctx
->aux_vertex_buffer_current
, vb
,
1067 sizeof(struct pipe_vertex_buffer
));
1070 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1072 ctx
->aux_vertex_buffer_current
.user_buffer
= NULL
;
1076 ctx
->pipe
->set_vertex_buffers(ctx
->pipe
, start_slot
, count
, buffers
);
1079 void cso_save_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1081 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1084 u_vbuf_save_aux_vertex_buffer_slot(vbuf
);
1088 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
,
1089 ctx
->aux_vertex_buffer_current
.buffer
);
1090 memcpy(&ctx
->aux_vertex_buffer_saved
, &ctx
->aux_vertex_buffer_current
,
1091 sizeof(struct pipe_vertex_buffer
));
1094 void cso_restore_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1096 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1099 u_vbuf_restore_aux_vertex_buffer_slot(vbuf
);
1103 cso_set_vertex_buffers(ctx
, ctx
->aux_vertex_buffer_index
, 1,
1104 &ctx
->aux_vertex_buffer_saved
);
1105 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
1108 unsigned cso_get_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1110 return ctx
->aux_vertex_buffer_index
;
1114 /**************** fragment/vertex sampler view state *************************/
1116 static enum pipe_error
1117 single_sampler(struct cso_context
*ctx
,
1118 struct sampler_info
*info
,
1120 const struct pipe_sampler_state
*templ
)
1122 void *handle
= NULL
;
1124 if (templ
!= NULL
) {
1125 unsigned key_size
= sizeof(struct pipe_sampler_state
);
1126 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
1127 struct cso_hash_iter iter
=
1128 cso_find_state_template(ctx
->cache
,
1129 hash_key
, CSO_SAMPLER
,
1130 (void *) templ
, key_size
);
1132 if (cso_hash_iter_is_null(iter
)) {
1133 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
1135 return PIPE_ERROR_OUT_OF_MEMORY
;
1137 memcpy(&cso
->state
, templ
, sizeof(*templ
));
1138 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
1140 (cso_state_callback
) ctx
->pipe
->delete_sampler_state
;
1141 cso
->context
= ctx
->pipe
;
1143 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
1144 if (cso_hash_iter_is_null(iter
)) {
1146 return PIPE_ERROR_OUT_OF_MEMORY
;
1152 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
1156 info
->samplers
[idx
] = handle
;
1162 cso_single_sampler(struct cso_context
*ctx
,
1163 unsigned shader_stage
,
1165 const struct pipe_sampler_state
*templ
)
1167 return single_sampler(ctx
, &ctx
->samplers
[shader_stage
], idx
, templ
);
1173 single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1175 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1178 /* find highest non-null sampler */
1179 for (i
= PIPE_MAX_SAMPLERS
; i
> 0; i
--) {
1180 if (info
->samplers
[i
- 1] != NULL
)
1184 info
->nr_samplers
= i
;
1185 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, shader_stage
, 0, i
,
1190 cso_single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1192 single_sampler_done(ctx
, shader_stage
);
1197 * If the function encouters any errors it will return the
1198 * last one. Done to always try to set as many samplers
1202 cso_set_samplers(struct cso_context
*ctx
,
1203 unsigned shader_stage
,
1205 const struct pipe_sampler_state
**templates
)
1207 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1209 enum pipe_error temp
, error
= PIPE_OK
;
1214 for (i
= 0; i
< nr
; i
++) {
1215 temp
= single_sampler(ctx
, info
, i
, templates
[i
]);
1216 if (temp
!= PIPE_OK
)
1220 for ( ; i
< info
->nr_samplers
; i
++) {
1221 temp
= single_sampler(ctx
, info
, i
, NULL
);
1222 if (temp
!= PIPE_OK
)
1226 single_sampler_done(ctx
, shader_stage
);
1232 cso_save_samplers(struct cso_context
*ctx
, unsigned shader_stage
)
1234 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1235 info
->nr_samplers_saved
= info
->nr_samplers
;
1236 memcpy(info
->samplers_saved
, info
->samplers
, sizeof(info
->samplers
));
1241 cso_restore_samplers(struct cso_context
*ctx
, unsigned shader_stage
)
1243 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1244 info
->nr_samplers
= info
->nr_samplers_saved
;
1245 memcpy(info
->samplers
, info
->samplers_saved
, sizeof(info
->samplers
));
1246 single_sampler_done(ctx
, shader_stage
);
1251 cso_set_sampler_views(struct cso_context
*ctx
,
1252 unsigned shader_stage
,
1254 struct pipe_sampler_view
**views
)
1256 if (shader_stage
== PIPE_SHADER_FRAGMENT
) {
1258 boolean any_change
= FALSE
;
1260 /* reference new views */
1261 for (i
= 0; i
< count
; i
++) {
1262 any_change
|= ctx
->fragment_views
[i
] != views
[i
];
1263 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], views
[i
]);
1265 /* unref extra old views, if any */
1266 for (; i
< ctx
->nr_fragment_views
; i
++) {
1267 any_change
|= ctx
->fragment_views
[i
] != NULL
;
1268 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1271 /* bind the new sampler views */
1273 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0,
1274 MAX2(ctx
->nr_fragment_views
, count
),
1275 ctx
->fragment_views
);
1278 ctx
->nr_fragment_views
= count
;
1281 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0, count
, views
);
1286 cso_save_fragment_sampler_views(struct cso_context
*ctx
)
1290 ctx
->nr_fragment_views_saved
= ctx
->nr_fragment_views
;
1292 for (i
= 0; i
< ctx
->nr_fragment_views
; i
++) {
1293 assert(!ctx
->fragment_views_saved
[i
]);
1294 pipe_sampler_view_reference(&ctx
->fragment_views_saved
[i
],
1295 ctx
->fragment_views
[i
]);
1301 cso_restore_fragment_sampler_views(struct cso_context
*ctx
)
1303 unsigned i
, nr_saved
= ctx
->nr_fragment_views_saved
;
1306 for (i
= 0; i
< nr_saved
; i
++) {
1307 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1308 /* move the reference from one pointer to another */
1309 ctx
->fragment_views
[i
] = ctx
->fragment_views_saved
[i
];
1310 ctx
->fragment_views_saved
[i
] = NULL
;
1312 for (; i
< ctx
->nr_fragment_views
; i
++) {
1313 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1316 num
= MAX2(ctx
->nr_fragment_views
, nr_saved
);
1318 /* bind the old/saved sampler views */
1319 ctx
->pipe
->set_sampler_views(ctx
->pipe
, PIPE_SHADER_FRAGMENT
, 0, num
,
1320 ctx
->fragment_views
);
1322 ctx
->nr_fragment_views
= nr_saved
;
1323 ctx
->nr_fragment_views_saved
= 0;
1328 cso_set_stream_outputs(struct cso_context
*ctx
,
1329 unsigned num_targets
,
1330 struct pipe_stream_output_target
**targets
,
1331 const unsigned *offsets
)
1333 struct pipe_context
*pipe
= ctx
->pipe
;
1336 if (!ctx
->has_streamout
) {
1337 assert(num_targets
== 0);
1341 if (ctx
->nr_so_targets
== 0 && num_targets
== 0) {
1342 /* Nothing to do. */
1346 /* reference new targets */
1347 for (i
= 0; i
< num_targets
; i
++) {
1348 pipe_so_target_reference(&ctx
->so_targets
[i
], targets
[i
]);
1350 /* unref extra old targets, if any */
1351 for (; i
< ctx
->nr_so_targets
; i
++) {
1352 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1355 pipe
->set_stream_output_targets(pipe
, num_targets
, targets
,
1357 ctx
->nr_so_targets
= num_targets
;
1361 cso_save_stream_outputs(struct cso_context
*ctx
)
1365 if (!ctx
->has_streamout
) {
1369 ctx
->nr_so_targets_saved
= ctx
->nr_so_targets
;
1371 for (i
= 0; i
< ctx
->nr_so_targets
; i
++) {
1372 assert(!ctx
->so_targets_saved
[i
]);
1373 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], ctx
->so_targets
[i
]);
1378 cso_restore_stream_outputs(struct cso_context
*ctx
)
1380 struct pipe_context
*pipe
= ctx
->pipe
;
1382 unsigned offset
[PIPE_MAX_SO_BUFFERS
];
1384 if (!ctx
->has_streamout
) {
1388 if (ctx
->nr_so_targets
== 0 && ctx
->nr_so_targets_saved
== 0) {
1389 /* Nothing to do. */
1393 assert(ctx
->nr_so_targets_saved
<= PIPE_MAX_SO_BUFFERS
);
1394 for (i
= 0; i
< ctx
->nr_so_targets_saved
; i
++) {
1395 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1396 /* move the reference from one pointer to another */
1397 ctx
->so_targets
[i
] = ctx
->so_targets_saved
[i
];
1398 ctx
->so_targets_saved
[i
] = NULL
;
1399 /* -1 means append */
1400 offset
[i
] = (unsigned)-1;
1402 for (; i
< ctx
->nr_so_targets
; i
++) {
1403 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1406 pipe
->set_stream_output_targets(pipe
, ctx
->nr_so_targets_saved
,
1407 ctx
->so_targets
, offset
);
1409 ctx
->nr_so_targets
= ctx
->nr_so_targets_saved
;
1410 ctx
->nr_so_targets_saved
= 0;
1413 /* constant buffers */
1416 cso_set_constant_buffer(struct cso_context
*cso
, unsigned shader_stage
,
1417 unsigned index
, struct pipe_constant_buffer
*cb
)
1419 struct pipe_context
*pipe
= cso
->pipe
;
1421 pipe
->set_constant_buffer(pipe
, shader_stage
, index
, cb
);
1424 util_copy_constant_buffer(&cso
->aux_constbuf_current
[shader_stage
], cb
);
1429 cso_set_constant_buffer_resource(struct cso_context
*cso
,
1430 unsigned shader_stage
,
1432 struct pipe_resource
*buffer
)
1435 struct pipe_constant_buffer cb
;
1437 cb
.buffer_offset
= 0;
1438 cb
.buffer_size
= buffer
->width0
;
1439 cb
.user_buffer
= NULL
;
1440 cso_set_constant_buffer(cso
, shader_stage
, index
, &cb
);
1442 cso_set_constant_buffer(cso
, shader_stage
, index
, NULL
);
1447 cso_save_constant_buffer_slot0(struct cso_context
*cso
,
1448 unsigned shader_stage
)
1450 util_copy_constant_buffer(&cso
->aux_constbuf_saved
[shader_stage
],
1451 &cso
->aux_constbuf_current
[shader_stage
]);
1455 cso_restore_constant_buffer_slot0(struct cso_context
*cso
,
1456 unsigned shader_stage
)
1458 cso_set_constant_buffer(cso
, shader_stage
, 0,
1459 &cso
->aux_constbuf_saved
[shader_stage
]);
1460 pipe_resource_reference(&cso
->aux_constbuf_saved
[shader_stage
].buffer
,
1467 cso_set_index_buffer(struct cso_context
*cso
,
1468 const struct pipe_index_buffer
*ib
)
1470 struct u_vbuf
*vbuf
= cso
->vbuf
;
1473 u_vbuf_set_index_buffer(vbuf
, ib
);
1475 struct pipe_context
*pipe
= cso
->pipe
;
1476 pipe
->set_index_buffer(pipe
, ib
);
1481 cso_draw_vbo(struct cso_context
*cso
,
1482 const struct pipe_draw_info
*info
)
1484 struct u_vbuf
*vbuf
= cso
->vbuf
;
1487 u_vbuf_draw_vbo(vbuf
, info
);
1489 struct pipe_context
*pipe
= cso
->pipe
;
1490 pipe
->draw_vbo(pipe
, info
);
1495 cso_draw_arrays(struct cso_context
*cso
, uint mode
, uint start
, uint count
)
1497 struct pipe_draw_info info
;
1499 util_draw_init_info(&info
);
1504 info
.min_index
= start
;
1505 info
.max_index
= start
+ count
- 1;
1507 cso_draw_vbo(cso
, &info
);
1511 cso_draw_arrays_instanced(struct cso_context
*cso
, uint mode
,
1512 uint start
, uint count
,
1513 uint start_instance
, uint instance_count
)
1515 struct pipe_draw_info info
;
1517 util_draw_init_info(&info
);
1522 info
.min_index
= start
;
1523 info
.max_index
= start
+ count
- 1;
1524 info
.start_instance
= start_instance
;
1525 info
.instance_count
= instance_count
;
1527 cso_draw_vbo(cso
, &info
);