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.
60 void *samplers
[PIPE_MAX_SAMPLERS
];
64 void *samplers
[PIPE_MAX_SAMPLERS
];
67 void *samplers_saved
[PIPE_MAX_SAMPLERS
];
68 unsigned nr_samplers_saved
;
70 struct pipe_sampler_view
*views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
73 struct pipe_sampler_view
*views_saved
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
74 unsigned nr_views_saved
;
80 struct pipe_context
*pipe
;
81 struct cso_cache
*cache
;
84 boolean has_geometry_shader
;
85 boolean has_tessellation
;
86 boolean has_streamout
;
88 struct sampler_info samplers
[PIPE_SHADER_TYPES
];
90 struct pipe_vertex_buffer aux_vertex_buffer_current
;
91 struct pipe_vertex_buffer aux_vertex_buffer_saved
;
92 unsigned aux_vertex_buffer_index
;
94 struct pipe_constant_buffer aux_constbuf_current
[PIPE_SHADER_TYPES
];
95 struct pipe_constant_buffer aux_constbuf_saved
[PIPE_SHADER_TYPES
];
97 unsigned nr_so_targets
;
98 struct pipe_stream_output_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
100 unsigned nr_so_targets_saved
;
101 struct pipe_stream_output_target
*so_targets_saved
[PIPE_MAX_SO_BUFFERS
];
103 /** Current and saved state.
104 * The saved state is used as a 1-deep stack.
106 void *blend
, *blend_saved
;
107 void *depth_stencil
, *depth_stencil_saved
;
108 void *rasterizer
, *rasterizer_saved
;
109 void *fragment_shader
, *fragment_shader_saved
;
110 void *vertex_shader
, *vertex_shader_saved
;
111 void *geometry_shader
, *geometry_shader_saved
;
112 void *tessctrl_shader
, *tessctrl_shader_saved
;
113 void *tesseval_shader
, *tesseval_shader_saved
;
114 void *velements
, *velements_saved
;
115 struct pipe_query
*render_condition
, *render_condition_saved
;
116 uint render_condition_mode
, render_condition_mode_saved
;
117 boolean render_condition_cond
, render_condition_cond_saved
;
119 struct pipe_clip_state clip
;
120 struct pipe_clip_state clip_saved
;
122 struct pipe_framebuffer_state fb
, fb_saved
;
123 struct pipe_viewport_state vp
, vp_saved
;
124 struct pipe_blend_color blend_color
;
125 unsigned sample_mask
, sample_mask_saved
;
126 unsigned min_samples
, min_samples_saved
;
127 struct pipe_stencil_ref stencil_ref
, stencil_ref_saved
;
131 static boolean
delete_blend_state(struct cso_context
*ctx
, void *state
)
133 struct cso_blend
*cso
= (struct cso_blend
*)state
;
135 if (ctx
->blend
== cso
->data
)
138 if (cso
->delete_state
)
139 cso
->delete_state(cso
->context
, cso
->data
);
144 static boolean
delete_depth_stencil_state(struct cso_context
*ctx
, void *state
)
146 struct cso_depth_stencil_alpha
*cso
=
147 (struct cso_depth_stencil_alpha
*)state
;
149 if (ctx
->depth_stencil
== cso
->data
)
152 if (cso
->delete_state
)
153 cso
->delete_state(cso
->context
, cso
->data
);
159 static boolean
delete_sampler_state(struct cso_context
*ctx
, void *state
)
161 struct cso_sampler
*cso
= (struct cso_sampler
*)state
;
162 if (cso
->delete_state
)
163 cso
->delete_state(cso
->context
, cso
->data
);
168 static boolean
delete_rasterizer_state(struct cso_context
*ctx
, void *state
)
170 struct cso_rasterizer
*cso
= (struct cso_rasterizer
*)state
;
172 if (ctx
->rasterizer
== cso
->data
)
174 if (cso
->delete_state
)
175 cso
->delete_state(cso
->context
, cso
->data
);
180 static boolean
delete_vertex_elements(struct cso_context
*ctx
,
183 struct cso_velements
*cso
= (struct cso_velements
*)state
;
185 if (ctx
->velements
== cso
->data
)
188 if (cso
->delete_state
)
189 cso
->delete_state(cso
->context
, cso
->data
);
195 static INLINE boolean
delete_cso(struct cso_context
*ctx
,
196 void *state
, enum cso_cache_type type
)
200 return delete_blend_state(ctx
, state
);
202 return delete_sampler_state(ctx
, state
);
203 case CSO_DEPTH_STENCIL_ALPHA
:
204 return delete_depth_stencil_state(ctx
, state
);
206 return delete_rasterizer_state(ctx
, state
);
208 return delete_vertex_elements(ctx
, state
);
217 sanitize_hash(struct cso_hash
*hash
, enum cso_cache_type type
,
218 int max_size
, void *user_data
)
220 struct cso_context
*ctx
= (struct cso_context
*)user_data
;
221 /* if we're approach the maximum size, remove fourth of the entries
222 * otherwise every subsequent call will go through the same */
223 int hash_size
= cso_hash_size(hash
);
224 int max_entries
= (max_size
> hash_size
) ? max_size
: hash_size
;
225 int to_remove
= (max_size
< max_entries
) * max_entries
/4;
226 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
227 if (hash_size
> max_size
)
228 to_remove
+= hash_size
- max_size
;
230 /*remove elements until we're good */
231 /*fixme: currently we pick the nodes to remove at random*/
232 void *cso
= cso_hash_iter_data(iter
);
233 if (delete_cso(ctx
, cso
, type
)) {
234 iter
= cso_hash_erase(hash
, iter
);
237 iter
= cso_hash_iter_next(iter
);
241 static void cso_init_vbuf(struct cso_context
*cso
)
243 struct u_vbuf_caps caps
;
245 /* Install u_vbuf if there is anything unsupported. */
246 if (u_vbuf_get_caps(cso
->pipe
->screen
, &caps
)) {
247 cso
->vbuf
= u_vbuf_create(cso
->pipe
, &caps
,
248 cso
->aux_vertex_buffer_index
);
252 struct cso_context
*cso_create_context( struct pipe_context
*pipe
)
254 struct cso_context
*ctx
= CALLOC_STRUCT(cso_context
);
258 ctx
->cache
= cso_cache_create();
259 if (ctx
->cache
== NULL
)
261 cso_cache_set_sanitize_callback(ctx
->cache
,
266 ctx
->sample_mask
= ~0;
268 ctx
->aux_vertex_buffer_index
= 0; /* 0 for now */
272 /* Enable for testing: */
273 if (0) cso_set_maximum_cache_size( ctx
->cache
, 4 );
275 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_GEOMETRY
,
276 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
277 ctx
->has_geometry_shader
= TRUE
;
279 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_TESS_CTRL
,
280 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
281 ctx
->has_tessellation
= TRUE
;
283 if (pipe
->screen
->get_param(pipe
->screen
,
284 PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
) != 0) {
285 ctx
->has_streamout
= TRUE
;
291 cso_destroy_context( ctx
);
296 * Free the CSO context.
298 void cso_destroy_context( struct cso_context
*ctx
)
303 ctx
->pipe
->bind_blend_state( ctx
->pipe
, NULL
);
304 ctx
->pipe
->bind_rasterizer_state( ctx
->pipe
, NULL
);
307 static struct pipe_sampler_view
*views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
] = { NULL
};
308 static void *zeros
[PIPE_MAX_SAMPLERS
] = { NULL
};
309 struct pipe_screen
*scr
= ctx
->pipe
->screen
;
311 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
312 int maxsam
= scr
->get_shader_param(scr
, sh
,
313 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
314 int maxview
= scr
->get_shader_param(scr
, sh
,
315 PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS
);
316 assert(maxsam
<= PIPE_MAX_SAMPLERS
);
317 assert(maxview
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
319 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, sh
, 0, maxsam
, zeros
);
322 ctx
->pipe
->set_sampler_views(ctx
->pipe
, sh
, 0, maxview
, views
);
327 ctx
->pipe
->bind_depth_stencil_alpha_state( ctx
->pipe
, NULL
);
328 ctx
->pipe
->bind_fs_state( ctx
->pipe
, NULL
);
329 ctx
->pipe
->bind_vs_state( ctx
->pipe
, NULL
);
330 ctx
->pipe
->bind_vertex_elements_state( ctx
->pipe
, NULL
);
332 if (ctx
->has_streamout
)
333 ctx
->pipe
->set_stream_output_targets(ctx
->pipe
, 0, NULL
, NULL
);
336 /* free sampler views for each shader stage */
337 for (shader
= 0; shader
< Elements(ctx
->samplers
); shader
++) {
338 struct sampler_info
*info
= &ctx
->samplers
[shader
];
339 for (i
= 0; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; i
++) {
340 pipe_sampler_view_reference(&info
->views
[i
], NULL
);
341 pipe_sampler_view_reference(&info
->views_saved
[i
], NULL
);
345 util_unreference_framebuffer_state(&ctx
->fb
);
346 util_unreference_framebuffer_state(&ctx
->fb_saved
);
348 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
, NULL
);
349 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
351 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
352 pipe_resource_reference(&ctx
->aux_constbuf_current
[i
].buffer
, NULL
);
353 pipe_resource_reference(&ctx
->aux_constbuf_saved
[i
].buffer
, NULL
);
356 for (i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
357 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
358 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], NULL
);
362 cso_cache_delete( ctx
->cache
);
367 u_vbuf_destroy(ctx
->vbuf
);
372 /* Those function will either find the state of the given template
373 * in the cache or they will create a new state from the given
374 * template, insert it in the cache and return it.
378 * If the driver returns 0 from the create method then they will assign
379 * the data member of the cso to be the template itself.
382 enum pipe_error
cso_set_blend(struct cso_context
*ctx
,
383 const struct pipe_blend_state
*templ
)
385 unsigned key_size
, hash_key
;
386 struct cso_hash_iter iter
;
389 key_size
= templ
->independent_blend_enable
?
390 sizeof(struct pipe_blend_state
) :
391 (char *)&(templ
->rt
[1]) - (char *)templ
;
392 hash_key
= cso_construct_key((void*)templ
, key_size
);
393 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_BLEND
,
394 (void*)templ
, key_size
);
396 if (cso_hash_iter_is_null(iter
)) {
397 struct cso_blend
*cso
= MALLOC(sizeof(struct cso_blend
));
399 return PIPE_ERROR_OUT_OF_MEMORY
;
401 memset(&cso
->state
, 0, sizeof cso
->state
);
402 memcpy(&cso
->state
, templ
, key_size
);
403 cso
->data
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &cso
->state
);
404 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_blend_state
;
405 cso
->context
= ctx
->pipe
;
407 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_BLEND
, cso
);
408 if (cso_hash_iter_is_null(iter
)) {
410 return PIPE_ERROR_OUT_OF_MEMORY
;
416 handle
= ((struct cso_blend
*)cso_hash_iter_data(iter
))->data
;
419 if (ctx
->blend
!= handle
) {
421 ctx
->pipe
->bind_blend_state(ctx
->pipe
, handle
);
426 void cso_save_blend(struct cso_context
*ctx
)
428 assert(!ctx
->blend_saved
);
429 ctx
->blend_saved
= ctx
->blend
;
432 void cso_restore_blend(struct cso_context
*ctx
)
434 if (ctx
->blend
!= ctx
->blend_saved
) {
435 ctx
->blend
= ctx
->blend_saved
;
436 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend_saved
);
438 ctx
->blend_saved
= NULL
;
444 cso_set_depth_stencil_alpha(struct cso_context
*ctx
,
445 const struct pipe_depth_stencil_alpha_state
*templ
)
447 unsigned key_size
= sizeof(struct pipe_depth_stencil_alpha_state
);
448 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
449 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
451 CSO_DEPTH_STENCIL_ALPHA
,
452 (void*)templ
, key_size
);
455 if (cso_hash_iter_is_null(iter
)) {
456 struct cso_depth_stencil_alpha
*cso
=
457 MALLOC(sizeof(struct cso_depth_stencil_alpha
));
459 return PIPE_ERROR_OUT_OF_MEMORY
;
461 memcpy(&cso
->state
, templ
, sizeof(*templ
));
462 cso
->data
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
,
465 (cso_state_callback
)ctx
->pipe
->delete_depth_stencil_alpha_state
;
466 cso
->context
= ctx
->pipe
;
468 iter
= cso_insert_state(ctx
->cache
, hash_key
,
469 CSO_DEPTH_STENCIL_ALPHA
, cso
);
470 if (cso_hash_iter_is_null(iter
)) {
472 return PIPE_ERROR_OUT_OF_MEMORY
;
478 handle
= ((struct cso_depth_stencil_alpha
*)
479 cso_hash_iter_data(iter
))->data
;
482 if (ctx
->depth_stencil
!= handle
) {
483 ctx
->depth_stencil
= handle
;
484 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, handle
);
489 void cso_save_depth_stencil_alpha(struct cso_context
*ctx
)
491 assert(!ctx
->depth_stencil_saved
);
492 ctx
->depth_stencil_saved
= ctx
->depth_stencil
;
495 void cso_restore_depth_stencil_alpha(struct cso_context
*ctx
)
497 if (ctx
->depth_stencil
!= ctx
->depth_stencil_saved
) {
498 ctx
->depth_stencil
= ctx
->depth_stencil_saved
;
499 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
,
500 ctx
->depth_stencil_saved
);
502 ctx
->depth_stencil_saved
= NULL
;
507 enum pipe_error
cso_set_rasterizer(struct cso_context
*ctx
,
508 const struct pipe_rasterizer_state
*templ
)
510 unsigned key_size
= sizeof(struct pipe_rasterizer_state
);
511 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
512 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
515 (void*)templ
, key_size
);
518 if (cso_hash_iter_is_null(iter
)) {
519 struct cso_rasterizer
*cso
= MALLOC(sizeof(struct cso_rasterizer
));
521 return PIPE_ERROR_OUT_OF_MEMORY
;
523 memcpy(&cso
->state
, templ
, sizeof(*templ
));
524 cso
->data
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &cso
->state
);
526 (cso_state_callback
)ctx
->pipe
->delete_rasterizer_state
;
527 cso
->context
= ctx
->pipe
;
529 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_RASTERIZER
, cso
);
530 if (cso_hash_iter_is_null(iter
)) {
532 return PIPE_ERROR_OUT_OF_MEMORY
;
538 handle
= ((struct cso_rasterizer
*)cso_hash_iter_data(iter
))->data
;
541 if (ctx
->rasterizer
!= handle
) {
542 ctx
->rasterizer
= handle
;
543 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, handle
);
548 void cso_save_rasterizer(struct cso_context
*ctx
)
550 assert(!ctx
->rasterizer_saved
);
551 ctx
->rasterizer_saved
= ctx
->rasterizer
;
554 void cso_restore_rasterizer(struct cso_context
*ctx
)
556 if (ctx
->rasterizer
!= ctx
->rasterizer_saved
) {
557 ctx
->rasterizer
= ctx
->rasterizer_saved
;
558 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rasterizer_saved
);
560 ctx
->rasterizer_saved
= NULL
;
564 void cso_set_fragment_shader_handle(struct cso_context
*ctx
, void *handle
)
566 if (ctx
->fragment_shader
!= handle
) {
567 ctx
->fragment_shader
= handle
;
568 ctx
->pipe
->bind_fs_state(ctx
->pipe
, handle
);
572 void cso_delete_fragment_shader(struct cso_context
*ctx
, void *handle
)
574 if (handle
== ctx
->fragment_shader
) {
575 /* unbind before deleting */
576 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
577 ctx
->fragment_shader
= NULL
;
579 ctx
->pipe
->delete_fs_state(ctx
->pipe
, handle
);
582 void cso_save_fragment_shader(struct cso_context
*ctx
)
584 assert(!ctx
->fragment_shader_saved
);
585 ctx
->fragment_shader_saved
= ctx
->fragment_shader
;
588 void cso_restore_fragment_shader(struct cso_context
*ctx
)
590 if (ctx
->fragment_shader_saved
!= ctx
->fragment_shader
) {
591 ctx
->pipe
->bind_fs_state(ctx
->pipe
, ctx
->fragment_shader_saved
);
592 ctx
->fragment_shader
= ctx
->fragment_shader_saved
;
594 ctx
->fragment_shader_saved
= NULL
;
598 void cso_set_vertex_shader_handle(struct cso_context
*ctx
, void *handle
)
600 if (ctx
->vertex_shader
!= handle
) {
601 ctx
->vertex_shader
= handle
;
602 ctx
->pipe
->bind_vs_state(ctx
->pipe
, handle
);
606 void cso_delete_vertex_shader(struct cso_context
*ctx
, void *handle
)
608 if (handle
== ctx
->vertex_shader
) {
609 /* unbind before deleting */
610 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
611 ctx
->vertex_shader
= NULL
;
613 ctx
->pipe
->delete_vs_state(ctx
->pipe
, handle
);
616 void cso_save_vertex_shader(struct cso_context
*ctx
)
618 assert(!ctx
->vertex_shader_saved
);
619 ctx
->vertex_shader_saved
= ctx
->vertex_shader
;
622 void cso_restore_vertex_shader(struct cso_context
*ctx
)
624 if (ctx
->vertex_shader_saved
!= ctx
->vertex_shader
) {
625 ctx
->pipe
->bind_vs_state(ctx
->pipe
, ctx
->vertex_shader_saved
);
626 ctx
->vertex_shader
= ctx
->vertex_shader_saved
;
628 ctx
->vertex_shader_saved
= NULL
;
632 void cso_set_framebuffer(struct cso_context
*ctx
,
633 const struct pipe_framebuffer_state
*fb
)
635 if (memcmp(&ctx
->fb
, fb
, sizeof(*fb
)) != 0) {
636 util_copy_framebuffer_state(&ctx
->fb
, fb
);
637 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, fb
);
641 void cso_save_framebuffer(struct cso_context
*ctx
)
643 util_copy_framebuffer_state(&ctx
->fb_saved
, &ctx
->fb
);
646 void cso_restore_framebuffer(struct cso_context
*ctx
)
648 if (memcmp(&ctx
->fb
, &ctx
->fb_saved
, sizeof(ctx
->fb
))) {
649 util_copy_framebuffer_state(&ctx
->fb
, &ctx
->fb_saved
);
650 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, &ctx
->fb
);
651 util_unreference_framebuffer_state(&ctx
->fb_saved
);
656 void cso_set_viewport(struct cso_context
*ctx
,
657 const struct pipe_viewport_state
*vp
)
659 if (memcmp(&ctx
->vp
, vp
, sizeof(*vp
))) {
661 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, vp
);
665 void cso_save_viewport(struct cso_context
*ctx
)
667 ctx
->vp_saved
= ctx
->vp
;
671 void cso_restore_viewport(struct cso_context
*ctx
)
673 if (memcmp(&ctx
->vp
, &ctx
->vp_saved
, sizeof(ctx
->vp
))) {
674 ctx
->vp
= ctx
->vp_saved
;
675 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, &ctx
->vp
);
680 void cso_set_blend_color(struct cso_context
*ctx
,
681 const struct pipe_blend_color
*bc
)
683 if (memcmp(&ctx
->blend_color
, bc
, sizeof(ctx
->blend_color
))) {
684 ctx
->blend_color
= *bc
;
685 ctx
->pipe
->set_blend_color(ctx
->pipe
, bc
);
689 void cso_set_sample_mask(struct cso_context
*ctx
, unsigned sample_mask
)
691 if (ctx
->sample_mask
!= sample_mask
) {
692 ctx
->sample_mask
= sample_mask
;
693 ctx
->pipe
->set_sample_mask(ctx
->pipe
, sample_mask
);
697 void cso_save_sample_mask(struct cso_context
*ctx
)
699 ctx
->sample_mask_saved
= ctx
->sample_mask
;
702 void cso_restore_sample_mask(struct cso_context
*ctx
)
704 cso_set_sample_mask(ctx
, ctx
->sample_mask_saved
);
707 void cso_set_min_samples(struct cso_context
*ctx
, unsigned min_samples
)
709 if (ctx
->min_samples
!= min_samples
&& ctx
->pipe
->set_min_samples
) {
710 ctx
->min_samples
= min_samples
;
711 ctx
->pipe
->set_min_samples(ctx
->pipe
, min_samples
);
715 void cso_save_min_samples(struct cso_context
*ctx
)
717 ctx
->min_samples_saved
= ctx
->min_samples
;
720 void cso_restore_min_samples(struct cso_context
*ctx
)
722 cso_set_min_samples(ctx
, ctx
->min_samples_saved
);
725 void cso_set_stencil_ref(struct cso_context
*ctx
,
726 const struct pipe_stencil_ref
*sr
)
728 if (memcmp(&ctx
->stencil_ref
, sr
, sizeof(ctx
->stencil_ref
))) {
729 ctx
->stencil_ref
= *sr
;
730 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, sr
);
734 void cso_save_stencil_ref(struct cso_context
*ctx
)
736 ctx
->stencil_ref_saved
= ctx
->stencil_ref
;
740 void cso_restore_stencil_ref(struct cso_context
*ctx
)
742 if (memcmp(&ctx
->stencil_ref
, &ctx
->stencil_ref_saved
,
743 sizeof(ctx
->stencil_ref
))) {
744 ctx
->stencil_ref
= ctx
->stencil_ref_saved
;
745 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, &ctx
->stencil_ref
);
749 void cso_set_render_condition(struct cso_context
*ctx
,
750 struct pipe_query
*query
,
751 boolean condition
, uint mode
)
753 struct pipe_context
*pipe
= ctx
->pipe
;
755 if (ctx
->render_condition
!= query
||
756 ctx
->render_condition_mode
!= mode
||
757 ctx
->render_condition_cond
!= condition
) {
758 pipe
->render_condition(pipe
, query
, condition
, mode
);
759 ctx
->render_condition
= query
;
760 ctx
->render_condition_cond
= condition
;
761 ctx
->render_condition_mode
= mode
;
765 void cso_save_render_condition(struct cso_context
*ctx
)
767 ctx
->render_condition_saved
= ctx
->render_condition
;
768 ctx
->render_condition_cond_saved
= ctx
->render_condition_cond
;
769 ctx
->render_condition_mode_saved
= ctx
->render_condition_mode
;
772 void cso_restore_render_condition(struct cso_context
*ctx
)
774 cso_set_render_condition(ctx
, ctx
->render_condition_saved
,
775 ctx
->render_condition_cond_saved
,
776 ctx
->render_condition_mode_saved
);
779 void cso_set_geometry_shader_handle(struct cso_context
*ctx
, void *handle
)
781 assert(ctx
->has_geometry_shader
|| !handle
);
783 if (ctx
->has_geometry_shader
&& ctx
->geometry_shader
!= handle
) {
784 ctx
->geometry_shader
= handle
;
785 ctx
->pipe
->bind_gs_state(ctx
->pipe
, handle
);
789 void cso_delete_geometry_shader(struct cso_context
*ctx
, void *handle
)
791 if (handle
== ctx
->geometry_shader
) {
792 /* unbind before deleting */
793 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
794 ctx
->geometry_shader
= NULL
;
796 ctx
->pipe
->delete_gs_state(ctx
->pipe
, handle
);
799 void cso_save_geometry_shader(struct cso_context
*ctx
)
801 if (!ctx
->has_geometry_shader
) {
805 assert(!ctx
->geometry_shader_saved
);
806 ctx
->geometry_shader_saved
= ctx
->geometry_shader
;
809 void cso_restore_geometry_shader(struct cso_context
*ctx
)
811 if (!ctx
->has_geometry_shader
) {
815 if (ctx
->geometry_shader_saved
!= ctx
->geometry_shader
) {
816 ctx
->pipe
->bind_gs_state(ctx
->pipe
, ctx
->geometry_shader_saved
);
817 ctx
->geometry_shader
= ctx
->geometry_shader_saved
;
819 ctx
->geometry_shader_saved
= NULL
;
822 void cso_set_tessctrl_shader_handle(struct cso_context
*ctx
, void *handle
)
824 assert(ctx
->has_tessellation
|| !handle
);
826 if (ctx
->has_tessellation
&& ctx
->tessctrl_shader
!= handle
) {
827 ctx
->tessctrl_shader
= handle
;
828 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, handle
);
832 void cso_delete_tessctrl_shader(struct cso_context
*ctx
, void *handle
)
834 if (handle
== ctx
->tessctrl_shader
) {
835 /* unbind before deleting */
836 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, NULL
);
837 ctx
->tessctrl_shader
= NULL
;
839 ctx
->pipe
->delete_tcs_state(ctx
->pipe
, handle
);
842 void cso_save_tessctrl_shader(struct cso_context
*ctx
)
844 if (!ctx
->has_tessellation
) {
848 assert(!ctx
->tessctrl_shader_saved
);
849 ctx
->tessctrl_shader_saved
= ctx
->tessctrl_shader
;
852 void cso_restore_tessctrl_shader(struct cso_context
*ctx
)
854 if (!ctx
->has_tessellation
) {
858 if (ctx
->tessctrl_shader_saved
!= ctx
->tessctrl_shader
) {
859 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, ctx
->tessctrl_shader_saved
);
860 ctx
->tessctrl_shader
= ctx
->tessctrl_shader_saved
;
862 ctx
->tessctrl_shader_saved
= NULL
;
865 void cso_set_tesseval_shader_handle(struct cso_context
*ctx
, void *handle
)
867 assert(ctx
->has_tessellation
|| !handle
);
869 if (ctx
->has_tessellation
&& ctx
->tesseval_shader
!= handle
) {
870 ctx
->tesseval_shader
= handle
;
871 ctx
->pipe
->bind_tes_state(ctx
->pipe
, handle
);
875 void cso_delete_tesseval_shader(struct cso_context
*ctx
, void *handle
)
877 if (handle
== ctx
->tesseval_shader
) {
878 /* unbind before deleting */
879 ctx
->pipe
->bind_tes_state(ctx
->pipe
, NULL
);
880 ctx
->tesseval_shader
= NULL
;
882 ctx
->pipe
->delete_tes_state(ctx
->pipe
, handle
);
885 void cso_save_tesseval_shader(struct cso_context
*ctx
)
887 if (!ctx
->has_tessellation
) {
891 assert(!ctx
->tesseval_shader_saved
);
892 ctx
->tesseval_shader_saved
= ctx
->tesseval_shader
;
895 void cso_restore_tesseval_shader(struct cso_context
*ctx
)
897 if (!ctx
->has_tessellation
) {
901 if (ctx
->tesseval_shader_saved
!= ctx
->tesseval_shader
) {
902 ctx
->pipe
->bind_tes_state(ctx
->pipe
, ctx
->tesseval_shader_saved
);
903 ctx
->tesseval_shader
= ctx
->tesseval_shader_saved
;
905 ctx
->tesseval_shader_saved
= NULL
;
911 clip_state_cpy(struct pipe_clip_state
*dst
,
912 const struct pipe_clip_state
*src
)
914 memcpy(dst
->ucp
, src
->ucp
, sizeof(dst
->ucp
));
918 clip_state_cmp(const struct pipe_clip_state
*a
,
919 const struct pipe_clip_state
*b
)
921 return memcmp(a
->ucp
, b
->ucp
, sizeof(a
->ucp
));
925 cso_set_clip(struct cso_context
*ctx
,
926 const struct pipe_clip_state
*clip
)
928 if (clip_state_cmp(&ctx
->clip
, clip
)) {
929 clip_state_cpy(&ctx
->clip
, clip
);
930 ctx
->pipe
->set_clip_state(ctx
->pipe
, clip
);
935 cso_save_clip(struct cso_context
*ctx
)
937 clip_state_cpy(&ctx
->clip_saved
, &ctx
->clip
);
941 cso_restore_clip(struct cso_context
*ctx
)
943 if (clip_state_cmp(&ctx
->clip
, &ctx
->clip_saved
)) {
944 clip_state_cpy(&ctx
->clip
, &ctx
->clip_saved
);
945 ctx
->pipe
->set_clip_state(ctx
->pipe
, &ctx
->clip_saved
);
950 cso_set_vertex_elements(struct cso_context
*ctx
,
952 const struct pipe_vertex_element
*states
)
954 struct u_vbuf
*vbuf
= ctx
->vbuf
;
955 unsigned key_size
, hash_key
;
956 struct cso_hash_iter iter
;
958 struct cso_velems_state velems_state
;
961 u_vbuf_set_vertex_elements(vbuf
, count
, states
);
965 /* Need to include the count into the stored state data too.
966 * Otherwise first few count pipe_vertex_elements could be identical
967 * even if count is different, and there's no guarantee the hash would
968 * be different in that case neither.
970 key_size
= sizeof(struct pipe_vertex_element
) * count
+ sizeof(unsigned);
971 velems_state
.count
= count
;
972 memcpy(velems_state
.velems
, states
,
973 sizeof(struct pipe_vertex_element
) * count
);
974 hash_key
= cso_construct_key((void*)&velems_state
, key_size
);
975 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_VELEMENTS
,
976 (void*)&velems_state
, key_size
);
978 if (cso_hash_iter_is_null(iter
)) {
979 struct cso_velements
*cso
= MALLOC(sizeof(struct cso_velements
));
981 return PIPE_ERROR_OUT_OF_MEMORY
;
983 memcpy(&cso
->state
, &velems_state
, key_size
);
984 cso
->data
= ctx
->pipe
->create_vertex_elements_state(ctx
->pipe
, count
,
985 &cso
->state
.velems
[0]);
987 (cso_state_callback
) ctx
->pipe
->delete_vertex_elements_state
;
988 cso
->context
= ctx
->pipe
;
990 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VELEMENTS
, cso
);
991 if (cso_hash_iter_is_null(iter
)) {
993 return PIPE_ERROR_OUT_OF_MEMORY
;
999 handle
= ((struct cso_velements
*)cso_hash_iter_data(iter
))->data
;
1002 if (ctx
->velements
!= handle
) {
1003 ctx
->velements
= handle
;
1004 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, handle
);
1009 void cso_save_vertex_elements(struct cso_context
*ctx
)
1011 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1014 u_vbuf_save_vertex_elements(vbuf
);
1018 assert(!ctx
->velements_saved
);
1019 ctx
->velements_saved
= ctx
->velements
;
1022 void cso_restore_vertex_elements(struct cso_context
*ctx
)
1024 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1027 u_vbuf_restore_vertex_elements(vbuf
);
1031 if (ctx
->velements
!= ctx
->velements_saved
) {
1032 ctx
->velements
= ctx
->velements_saved
;
1033 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->velements_saved
);
1035 ctx
->velements_saved
= NULL
;
1038 /* vertex buffers */
1040 void cso_set_vertex_buffers(struct cso_context
*ctx
,
1041 unsigned start_slot
, unsigned count
,
1042 const struct pipe_vertex_buffer
*buffers
)
1044 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1047 u_vbuf_set_vertex_buffers(vbuf
, start_slot
, count
, buffers
);
1051 /* Save what's in the auxiliary slot, so that we can save and restore it
1053 if (start_slot
<= ctx
->aux_vertex_buffer_index
&&
1054 start_slot
+count
> ctx
->aux_vertex_buffer_index
) {
1056 const struct pipe_vertex_buffer
*vb
=
1057 buffers
+ (ctx
->aux_vertex_buffer_index
- start_slot
);
1059 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1061 memcpy(&ctx
->aux_vertex_buffer_current
, vb
,
1062 sizeof(struct pipe_vertex_buffer
));
1065 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1067 ctx
->aux_vertex_buffer_current
.user_buffer
= NULL
;
1071 ctx
->pipe
->set_vertex_buffers(ctx
->pipe
, start_slot
, count
, buffers
);
1074 void cso_save_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1076 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1079 u_vbuf_save_aux_vertex_buffer_slot(vbuf
);
1083 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
,
1084 ctx
->aux_vertex_buffer_current
.buffer
);
1085 memcpy(&ctx
->aux_vertex_buffer_saved
, &ctx
->aux_vertex_buffer_current
,
1086 sizeof(struct pipe_vertex_buffer
));
1089 void cso_restore_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1091 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1094 u_vbuf_restore_aux_vertex_buffer_slot(vbuf
);
1098 cso_set_vertex_buffers(ctx
, ctx
->aux_vertex_buffer_index
, 1,
1099 &ctx
->aux_vertex_buffer_saved
);
1100 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
1103 unsigned cso_get_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1105 return ctx
->aux_vertex_buffer_index
;
1109 /**************** fragment/vertex sampler view state *************************/
1111 static enum pipe_error
1112 single_sampler(struct cso_context
*ctx
,
1113 struct sampler_info
*info
,
1115 const struct pipe_sampler_state
*templ
)
1117 void *handle
= NULL
;
1119 if (templ
!= NULL
) {
1120 unsigned key_size
= sizeof(struct pipe_sampler_state
);
1121 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
1122 struct cso_hash_iter iter
=
1123 cso_find_state_template(ctx
->cache
,
1124 hash_key
, CSO_SAMPLER
,
1125 (void *) templ
, key_size
);
1127 if (cso_hash_iter_is_null(iter
)) {
1128 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
1130 return PIPE_ERROR_OUT_OF_MEMORY
;
1132 memcpy(&cso
->state
, templ
, sizeof(*templ
));
1133 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
1135 (cso_state_callback
) ctx
->pipe
->delete_sampler_state
;
1136 cso
->context
= ctx
->pipe
;
1138 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
1139 if (cso_hash_iter_is_null(iter
)) {
1141 return PIPE_ERROR_OUT_OF_MEMORY
;
1147 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
1151 info
->samplers
[idx
] = handle
;
1157 cso_single_sampler(struct cso_context
*ctx
,
1158 unsigned shader_stage
,
1160 const struct pipe_sampler_state
*templ
)
1162 return single_sampler(ctx
, &ctx
->samplers
[shader_stage
], idx
, templ
);
1168 single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1170 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1173 /* find highest non-null sampler */
1174 for (i
= PIPE_MAX_SAMPLERS
; i
> 0; i
--) {
1175 if (info
->samplers
[i
- 1] != NULL
)
1179 info
->nr_samplers
= i
;
1181 if (info
->hw
.nr_samplers
!= info
->nr_samplers
||
1182 memcmp(info
->hw
.samplers
,
1184 info
->nr_samplers
* sizeof(void *)) != 0)
1186 memcpy(info
->hw
.samplers
,
1188 info
->nr_samplers
* sizeof(void *));
1190 /* set remaining slots/pointers to null */
1191 for (i
= info
->nr_samplers
; i
< info
->hw
.nr_samplers
; i
++)
1192 info
->samplers
[i
] = NULL
;
1194 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, shader_stage
, 0,
1195 MAX2(info
->nr_samplers
,
1196 info
->hw
.nr_samplers
),
1199 info
->hw
.nr_samplers
= info
->nr_samplers
;
1204 cso_single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1206 single_sampler_done(ctx
, shader_stage
);
1211 * If the function encouters any errors it will return the
1212 * last one. Done to always try to set as many samplers
1216 cso_set_samplers(struct cso_context
*ctx
,
1217 unsigned shader_stage
,
1219 const struct pipe_sampler_state
**templates
)
1221 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1223 enum pipe_error temp
, error
= PIPE_OK
;
1228 for (i
= 0; i
< nr
; i
++) {
1229 temp
= single_sampler(ctx
, info
, i
, templates
[i
]);
1230 if (temp
!= PIPE_OK
)
1234 for ( ; i
< info
->nr_samplers
; i
++) {
1235 temp
= single_sampler(ctx
, info
, i
, NULL
);
1236 if (temp
!= PIPE_OK
)
1240 single_sampler_done(ctx
, shader_stage
);
1246 cso_save_samplers(struct cso_context
*ctx
, unsigned shader_stage
)
1248 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1249 info
->nr_samplers_saved
= info
->nr_samplers
;
1250 memcpy(info
->samplers_saved
, info
->samplers
, sizeof(info
->samplers
));
1255 cso_restore_samplers(struct cso_context
*ctx
, unsigned shader_stage
)
1257 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1258 info
->nr_samplers
= info
->nr_samplers_saved
;
1259 memcpy(info
->samplers
, info
->samplers_saved
, sizeof(info
->samplers
));
1260 single_sampler_done(ctx
, shader_stage
);
1265 cso_set_sampler_views(struct cso_context
*ctx
,
1266 unsigned shader_stage
,
1268 struct pipe_sampler_view
**views
)
1270 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1272 boolean any_change
= FALSE
;
1274 /* reference new views */
1275 for (i
= 0; i
< count
; i
++) {
1276 any_change
|= info
->views
[i
] != views
[i
];
1277 pipe_sampler_view_reference(&info
->views
[i
], views
[i
]);
1279 /* unref extra old views, if any */
1280 for (; i
< info
->nr_views
; i
++) {
1281 any_change
|= info
->views
[i
] != NULL
;
1282 pipe_sampler_view_reference(&info
->views
[i
], NULL
);
1285 /* bind the new sampler views */
1287 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0,
1288 MAX2(info
->nr_views
, count
),
1292 info
->nr_views
= count
;
1297 cso_save_sampler_views(struct cso_context
*ctx
, unsigned shader_stage
)
1299 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1302 info
->nr_views_saved
= info
->nr_views
;
1304 for (i
= 0; i
< info
->nr_views
; i
++) {
1305 assert(!info
->views_saved
[i
]);
1306 pipe_sampler_view_reference(&info
->views_saved
[i
], info
->views
[i
]);
1312 cso_restore_sampler_views(struct cso_context
*ctx
, unsigned shader_stage
)
1314 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1315 unsigned i
, nr_saved
= info
->nr_views_saved
;
1318 for (i
= 0; i
< nr_saved
; i
++) {
1319 pipe_sampler_view_reference(&info
->views
[i
], NULL
);
1320 /* move the reference from one pointer to another */
1321 info
->views
[i
] = info
->views_saved
[i
];
1322 info
->views_saved
[i
] = NULL
;
1324 for (; i
< info
->nr_views
; i
++) {
1325 pipe_sampler_view_reference(&info
->views
[i
], NULL
);
1328 num
= MAX2(info
->nr_views
, nr_saved
);
1330 /* bind the old/saved sampler views */
1331 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0, num
, info
->views
);
1333 info
->nr_views
= nr_saved
;
1334 info
->nr_views_saved
= 0;
1339 cso_set_stream_outputs(struct cso_context
*ctx
,
1340 unsigned num_targets
,
1341 struct pipe_stream_output_target
**targets
,
1342 const unsigned *offsets
)
1344 struct pipe_context
*pipe
= ctx
->pipe
;
1347 if (!ctx
->has_streamout
) {
1348 assert(num_targets
== 0);
1352 if (ctx
->nr_so_targets
== 0 && num_targets
== 0) {
1353 /* Nothing to do. */
1357 /* reference new targets */
1358 for (i
= 0; i
< num_targets
; i
++) {
1359 pipe_so_target_reference(&ctx
->so_targets
[i
], targets
[i
]);
1361 /* unref extra old targets, if any */
1362 for (; i
< ctx
->nr_so_targets
; i
++) {
1363 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1366 pipe
->set_stream_output_targets(pipe
, num_targets
, targets
,
1368 ctx
->nr_so_targets
= num_targets
;
1372 cso_save_stream_outputs(struct cso_context
*ctx
)
1376 if (!ctx
->has_streamout
) {
1380 ctx
->nr_so_targets_saved
= ctx
->nr_so_targets
;
1382 for (i
= 0; i
< ctx
->nr_so_targets
; i
++) {
1383 assert(!ctx
->so_targets_saved
[i
]);
1384 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], ctx
->so_targets
[i
]);
1389 cso_restore_stream_outputs(struct cso_context
*ctx
)
1391 struct pipe_context
*pipe
= ctx
->pipe
;
1393 unsigned offset
[PIPE_MAX_SO_BUFFERS
];
1395 if (!ctx
->has_streamout
) {
1399 if (ctx
->nr_so_targets
== 0 && ctx
->nr_so_targets_saved
== 0) {
1400 /* Nothing to do. */
1404 assert(ctx
->nr_so_targets_saved
<= PIPE_MAX_SO_BUFFERS
);
1405 for (i
= 0; i
< ctx
->nr_so_targets_saved
; i
++) {
1406 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1407 /* move the reference from one pointer to another */
1408 ctx
->so_targets
[i
] = ctx
->so_targets_saved
[i
];
1409 ctx
->so_targets_saved
[i
] = NULL
;
1410 /* -1 means append */
1411 offset
[i
] = (unsigned)-1;
1413 for (; i
< ctx
->nr_so_targets
; i
++) {
1414 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1417 pipe
->set_stream_output_targets(pipe
, ctx
->nr_so_targets_saved
,
1418 ctx
->so_targets
, offset
);
1420 ctx
->nr_so_targets
= ctx
->nr_so_targets_saved
;
1421 ctx
->nr_so_targets_saved
= 0;
1424 /* constant buffers */
1427 cso_set_constant_buffer(struct cso_context
*cso
, unsigned shader_stage
,
1428 unsigned index
, struct pipe_constant_buffer
*cb
)
1430 struct pipe_context
*pipe
= cso
->pipe
;
1432 pipe
->set_constant_buffer(pipe
, shader_stage
, index
, cb
);
1435 util_copy_constant_buffer(&cso
->aux_constbuf_current
[shader_stage
], cb
);
1440 cso_set_constant_buffer_resource(struct cso_context
*cso
,
1441 unsigned shader_stage
,
1443 struct pipe_resource
*buffer
)
1446 struct pipe_constant_buffer cb
;
1448 cb
.buffer_offset
= 0;
1449 cb
.buffer_size
= buffer
->width0
;
1450 cb
.user_buffer
= NULL
;
1451 cso_set_constant_buffer(cso
, shader_stage
, index
, &cb
);
1453 cso_set_constant_buffer(cso
, shader_stage
, index
, NULL
);
1458 cso_save_constant_buffer_slot0(struct cso_context
*cso
,
1459 unsigned shader_stage
)
1461 util_copy_constant_buffer(&cso
->aux_constbuf_saved
[shader_stage
],
1462 &cso
->aux_constbuf_current
[shader_stage
]);
1466 cso_restore_constant_buffer_slot0(struct cso_context
*cso
,
1467 unsigned shader_stage
)
1469 cso_set_constant_buffer(cso
, shader_stage
, 0,
1470 &cso
->aux_constbuf_saved
[shader_stage
]);
1471 pipe_resource_reference(&cso
->aux_constbuf_saved
[shader_stage
].buffer
,
1478 cso_set_index_buffer(struct cso_context
*cso
,
1479 const struct pipe_index_buffer
*ib
)
1481 struct u_vbuf
*vbuf
= cso
->vbuf
;
1484 u_vbuf_set_index_buffer(vbuf
, ib
);
1486 struct pipe_context
*pipe
= cso
->pipe
;
1487 pipe
->set_index_buffer(pipe
, ib
);
1492 cso_draw_vbo(struct cso_context
*cso
,
1493 const struct pipe_draw_info
*info
)
1495 struct u_vbuf
*vbuf
= cso
->vbuf
;
1498 u_vbuf_draw_vbo(vbuf
, info
);
1500 struct pipe_context
*pipe
= cso
->pipe
;
1501 pipe
->draw_vbo(pipe
, info
);
1506 cso_draw_arrays(struct cso_context
*cso
, uint mode
, uint start
, uint count
)
1508 struct pipe_draw_info info
;
1510 util_draw_init_info(&info
);
1515 info
.min_index
= start
;
1516 info
.max_index
= start
+ count
- 1;
1518 cso_draw_vbo(cso
, &info
);
1522 cso_draw_arrays_instanced(struct cso_context
*cso
, uint mode
,
1523 uint start
, uint count
,
1524 uint start_instance
, uint instance_count
)
1526 struct pipe_draw_info info
;
1528 util_draw_init_info(&info
);
1533 info
.min_index
= start
;
1534 info
.max_index
= start
+ count
- 1;
1535 info
.start_instance
= start_instance
;
1536 info
.instance_count
= instance_count
;
1538 cso_draw_vbo(cso
, &info
);