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
];
66 struct pipe_context
*pipe
;
67 struct cso_cache
*cache
;
70 boolean has_geometry_shader
;
71 boolean has_tessellation
;
72 boolean has_streamout
;
74 struct pipe_sampler_view
*fragment_views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
75 unsigned nr_fragment_views
;
77 struct pipe_sampler_view
*fragment_views_saved
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
78 unsigned nr_fragment_views_saved
;
80 void *fragment_samplers_saved
[PIPE_MAX_SAMPLERS
];
81 unsigned nr_fragment_samplers_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_framebuffer_state fb
, fb_saved
;
115 struct pipe_viewport_state vp
, vp_saved
;
116 struct pipe_blend_color blend_color
;
117 unsigned sample_mask
, sample_mask_saved
;
118 unsigned min_samples
, min_samples_saved
;
119 struct pipe_stencil_ref stencil_ref
, stencil_ref_saved
;
123 static boolean
delete_blend_state(struct cso_context
*ctx
, void *state
)
125 struct cso_blend
*cso
= (struct cso_blend
*)state
;
127 if (ctx
->blend
== cso
->data
)
130 if (cso
->delete_state
)
131 cso
->delete_state(cso
->context
, cso
->data
);
136 static boolean
delete_depth_stencil_state(struct cso_context
*ctx
, void *state
)
138 struct cso_depth_stencil_alpha
*cso
=
139 (struct cso_depth_stencil_alpha
*)state
;
141 if (ctx
->depth_stencil
== cso
->data
)
144 if (cso
->delete_state
)
145 cso
->delete_state(cso
->context
, cso
->data
);
151 static boolean
delete_sampler_state(struct cso_context
*ctx
, void *state
)
153 struct cso_sampler
*cso
= (struct cso_sampler
*)state
;
154 if (cso
->delete_state
)
155 cso
->delete_state(cso
->context
, cso
->data
);
160 static boolean
delete_rasterizer_state(struct cso_context
*ctx
, void *state
)
162 struct cso_rasterizer
*cso
= (struct cso_rasterizer
*)state
;
164 if (ctx
->rasterizer
== cso
->data
)
166 if (cso
->delete_state
)
167 cso
->delete_state(cso
->context
, cso
->data
);
172 static boolean
delete_vertex_elements(struct cso_context
*ctx
,
175 struct cso_velements
*cso
= (struct cso_velements
*)state
;
177 if (ctx
->velements
== cso
->data
)
180 if (cso
->delete_state
)
181 cso
->delete_state(cso
->context
, cso
->data
);
187 static inline boolean
delete_cso(struct cso_context
*ctx
,
188 void *state
, enum cso_cache_type type
)
192 return delete_blend_state(ctx
, state
);
194 return delete_sampler_state(ctx
, state
);
195 case CSO_DEPTH_STENCIL_ALPHA
:
196 return delete_depth_stencil_state(ctx
, state
);
198 return delete_rasterizer_state(ctx
, state
);
200 return delete_vertex_elements(ctx
, state
);
209 sanitize_hash(struct cso_hash
*hash
, enum cso_cache_type type
,
210 int max_size
, void *user_data
)
212 struct cso_context
*ctx
= (struct cso_context
*)user_data
;
213 /* if we're approach the maximum size, remove fourth of the entries
214 * otherwise every subsequent call will go through the same */
215 int hash_size
= cso_hash_size(hash
);
216 int max_entries
= (max_size
> hash_size
) ? max_size
: hash_size
;
217 int to_remove
= (max_size
< max_entries
) * max_entries
/4;
218 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
219 if (hash_size
> max_size
)
220 to_remove
+= hash_size
- max_size
;
222 /*remove elements until we're good */
223 /*fixme: currently we pick the nodes to remove at random*/
224 void *cso
= cso_hash_iter_data(iter
);
225 if (delete_cso(ctx
, cso
, type
)) {
226 iter
= cso_hash_erase(hash
, iter
);
229 iter
= cso_hash_iter_next(iter
);
233 static void cso_init_vbuf(struct cso_context
*cso
)
235 struct u_vbuf_caps caps
;
237 /* Install u_vbuf if there is anything unsupported. */
238 if (u_vbuf_get_caps(cso
->pipe
->screen
, &caps
)) {
239 cso
->vbuf
= u_vbuf_create(cso
->pipe
, &caps
,
240 cso
->aux_vertex_buffer_index
);
244 struct cso_context
*cso_create_context( struct pipe_context
*pipe
)
246 struct cso_context
*ctx
= CALLOC_STRUCT(cso_context
);
250 ctx
->cache
= cso_cache_create();
251 if (ctx
->cache
== NULL
)
253 cso_cache_set_sanitize_callback(ctx
->cache
,
258 ctx
->sample_mask
= ~0;
260 ctx
->aux_vertex_buffer_index
= 0; /* 0 for now */
264 /* Enable for testing: */
265 if (0) cso_set_maximum_cache_size( ctx
->cache
, 4 );
267 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_GEOMETRY
,
268 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
269 ctx
->has_geometry_shader
= TRUE
;
271 if (pipe
->screen
->get_shader_param(pipe
->screen
, PIPE_SHADER_TESS_CTRL
,
272 PIPE_SHADER_CAP_MAX_INSTRUCTIONS
) > 0) {
273 ctx
->has_tessellation
= TRUE
;
275 if (pipe
->screen
->get_param(pipe
->screen
,
276 PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS
) != 0) {
277 ctx
->has_streamout
= TRUE
;
283 cso_destroy_context( ctx
);
288 * Free the CSO context.
290 void cso_destroy_context( struct cso_context
*ctx
)
295 ctx
->pipe
->set_index_buffer(ctx
->pipe
, NULL
);
297 ctx
->pipe
->bind_blend_state( ctx
->pipe
, NULL
);
298 ctx
->pipe
->bind_rasterizer_state( ctx
->pipe
, NULL
);
301 static struct pipe_sampler_view
*views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
] = { NULL
};
302 static void *zeros
[PIPE_MAX_SAMPLERS
] = { NULL
};
303 struct pipe_screen
*scr
= ctx
->pipe
->screen
;
305 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
306 int maxsam
= scr
->get_shader_param(scr
, sh
,
307 PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS
);
308 int maxview
= scr
->get_shader_param(scr
, sh
,
309 PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS
);
310 assert(maxsam
<= PIPE_MAX_SAMPLERS
);
311 assert(maxview
<= PIPE_MAX_SHADER_SAMPLER_VIEWS
);
313 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, sh
, 0, maxsam
, zeros
);
316 ctx
->pipe
->set_sampler_views(ctx
->pipe
, sh
, 0, maxview
, views
);
321 ctx
->pipe
->bind_depth_stencil_alpha_state( ctx
->pipe
, NULL
);
322 ctx
->pipe
->bind_fs_state( ctx
->pipe
, NULL
);
323 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_FRAGMENT
, 0, NULL
);
324 ctx
->pipe
->bind_vs_state( ctx
->pipe
, NULL
);
325 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_VERTEX
, 0, NULL
);
326 if (ctx
->has_geometry_shader
) {
327 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
328 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_GEOMETRY
, 0, NULL
);
330 if (ctx
->has_tessellation
) {
331 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, NULL
);
332 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_TESS_CTRL
, 0, NULL
);
333 ctx
->pipe
->bind_tes_state(ctx
->pipe
, NULL
);
334 ctx
->pipe
->set_constant_buffer(ctx
->pipe
, PIPE_SHADER_TESS_EVAL
, 0, NULL
);
336 ctx
->pipe
->bind_vertex_elements_state( ctx
->pipe
, NULL
);
338 if (ctx
->has_streamout
)
339 ctx
->pipe
->set_stream_output_targets(ctx
->pipe
, 0, NULL
, NULL
);
342 for (i
= 0; i
< PIPE_MAX_SHADER_SAMPLER_VIEWS
; i
++) {
343 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
344 pipe_sampler_view_reference(&ctx
->fragment_views_saved
[i
], NULL
);
347 util_unreference_framebuffer_state(&ctx
->fb
);
348 util_unreference_framebuffer_state(&ctx
->fb_saved
);
350 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
, NULL
);
351 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
353 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
354 pipe_resource_reference(&ctx
->aux_constbuf_current
[i
].buffer
, NULL
);
355 pipe_resource_reference(&ctx
->aux_constbuf_saved
[i
].buffer
, NULL
);
358 for (i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
359 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
360 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], NULL
);
364 cso_cache_delete( ctx
->cache
);
369 u_vbuf_destroy(ctx
->vbuf
);
374 /* Those function will either find the state of the given template
375 * in the cache or they will create a new state from the given
376 * template, insert it in the cache and return it.
380 * If the driver returns 0 from the create method then they will assign
381 * the data member of the cso to be the template itself.
384 enum pipe_error
cso_set_blend(struct cso_context
*ctx
,
385 const struct pipe_blend_state
*templ
)
387 unsigned key_size
, hash_key
;
388 struct cso_hash_iter iter
;
391 key_size
= templ
->independent_blend_enable
?
392 sizeof(struct pipe_blend_state
) :
393 (char *)&(templ
->rt
[1]) - (char *)templ
;
394 hash_key
= cso_construct_key((void*)templ
, key_size
);
395 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_BLEND
,
396 (void*)templ
, key_size
);
398 if (cso_hash_iter_is_null(iter
)) {
399 struct cso_blend
*cso
= MALLOC(sizeof(struct cso_blend
));
401 return PIPE_ERROR_OUT_OF_MEMORY
;
403 memset(&cso
->state
, 0, sizeof cso
->state
);
404 memcpy(&cso
->state
, templ
, key_size
);
405 cso
->data
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &cso
->state
);
406 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_blend_state
;
407 cso
->context
= ctx
->pipe
;
409 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_BLEND
, cso
);
410 if (cso_hash_iter_is_null(iter
)) {
412 return PIPE_ERROR_OUT_OF_MEMORY
;
418 handle
= ((struct cso_blend
*)cso_hash_iter_data(iter
))->data
;
421 if (ctx
->blend
!= handle
) {
423 ctx
->pipe
->bind_blend_state(ctx
->pipe
, handle
);
428 void cso_save_blend(struct cso_context
*ctx
)
430 assert(!ctx
->blend_saved
);
431 ctx
->blend_saved
= ctx
->blend
;
434 void cso_restore_blend(struct cso_context
*ctx
)
436 if (ctx
->blend
!= ctx
->blend_saved
) {
437 ctx
->blend
= ctx
->blend_saved
;
438 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend_saved
);
440 ctx
->blend_saved
= NULL
;
446 cso_set_depth_stencil_alpha(struct cso_context
*ctx
,
447 const struct pipe_depth_stencil_alpha_state
*templ
)
449 unsigned key_size
= sizeof(struct pipe_depth_stencil_alpha_state
);
450 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
451 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
453 CSO_DEPTH_STENCIL_ALPHA
,
454 (void*)templ
, key_size
);
457 if (cso_hash_iter_is_null(iter
)) {
458 struct cso_depth_stencil_alpha
*cso
=
459 MALLOC(sizeof(struct cso_depth_stencil_alpha
));
461 return PIPE_ERROR_OUT_OF_MEMORY
;
463 memcpy(&cso
->state
, templ
, sizeof(*templ
));
464 cso
->data
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
,
467 (cso_state_callback
)ctx
->pipe
->delete_depth_stencil_alpha_state
;
468 cso
->context
= ctx
->pipe
;
470 iter
= cso_insert_state(ctx
->cache
, hash_key
,
471 CSO_DEPTH_STENCIL_ALPHA
, cso
);
472 if (cso_hash_iter_is_null(iter
)) {
474 return PIPE_ERROR_OUT_OF_MEMORY
;
480 handle
= ((struct cso_depth_stencil_alpha
*)
481 cso_hash_iter_data(iter
))->data
;
484 if (ctx
->depth_stencil
!= handle
) {
485 ctx
->depth_stencil
= handle
;
486 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, handle
);
491 void cso_save_depth_stencil_alpha(struct cso_context
*ctx
)
493 assert(!ctx
->depth_stencil_saved
);
494 ctx
->depth_stencil_saved
= ctx
->depth_stencil
;
497 void cso_restore_depth_stencil_alpha(struct cso_context
*ctx
)
499 if (ctx
->depth_stencil
!= ctx
->depth_stencil_saved
) {
500 ctx
->depth_stencil
= ctx
->depth_stencil_saved
;
501 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
,
502 ctx
->depth_stencil_saved
);
504 ctx
->depth_stencil_saved
= NULL
;
509 enum pipe_error
cso_set_rasterizer(struct cso_context
*ctx
,
510 const struct pipe_rasterizer_state
*templ
)
512 unsigned key_size
= sizeof(struct pipe_rasterizer_state
);
513 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
514 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
517 (void*)templ
, key_size
);
520 if (cso_hash_iter_is_null(iter
)) {
521 struct cso_rasterizer
*cso
= MALLOC(sizeof(struct cso_rasterizer
));
523 return PIPE_ERROR_OUT_OF_MEMORY
;
525 memcpy(&cso
->state
, templ
, sizeof(*templ
));
526 cso
->data
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &cso
->state
);
528 (cso_state_callback
)ctx
->pipe
->delete_rasterizer_state
;
529 cso
->context
= ctx
->pipe
;
531 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_RASTERIZER
, cso
);
532 if (cso_hash_iter_is_null(iter
)) {
534 return PIPE_ERROR_OUT_OF_MEMORY
;
540 handle
= ((struct cso_rasterizer
*)cso_hash_iter_data(iter
))->data
;
543 if (ctx
->rasterizer
!= handle
) {
544 ctx
->rasterizer
= handle
;
545 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, handle
);
550 void cso_save_rasterizer(struct cso_context
*ctx
)
552 assert(!ctx
->rasterizer_saved
);
553 ctx
->rasterizer_saved
= ctx
->rasterizer
;
556 void cso_restore_rasterizer(struct cso_context
*ctx
)
558 if (ctx
->rasterizer
!= ctx
->rasterizer_saved
) {
559 ctx
->rasterizer
= ctx
->rasterizer_saved
;
560 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rasterizer_saved
);
562 ctx
->rasterizer_saved
= NULL
;
566 void cso_set_fragment_shader_handle(struct cso_context
*ctx
, void *handle
)
568 if (ctx
->fragment_shader
!= handle
) {
569 ctx
->fragment_shader
= handle
;
570 ctx
->pipe
->bind_fs_state(ctx
->pipe
, handle
);
574 void cso_delete_fragment_shader(struct cso_context
*ctx
, void *handle
)
576 if (handle
== ctx
->fragment_shader
) {
577 /* unbind before deleting */
578 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
579 ctx
->fragment_shader
= NULL
;
581 ctx
->pipe
->delete_fs_state(ctx
->pipe
, handle
);
584 void cso_save_fragment_shader(struct cso_context
*ctx
)
586 assert(!ctx
->fragment_shader_saved
);
587 ctx
->fragment_shader_saved
= ctx
->fragment_shader
;
590 void cso_restore_fragment_shader(struct cso_context
*ctx
)
592 if (ctx
->fragment_shader_saved
!= ctx
->fragment_shader
) {
593 ctx
->pipe
->bind_fs_state(ctx
->pipe
, ctx
->fragment_shader_saved
);
594 ctx
->fragment_shader
= ctx
->fragment_shader_saved
;
596 ctx
->fragment_shader_saved
= NULL
;
600 void cso_set_vertex_shader_handle(struct cso_context
*ctx
, void *handle
)
602 if (ctx
->vertex_shader
!= handle
) {
603 ctx
->vertex_shader
= handle
;
604 ctx
->pipe
->bind_vs_state(ctx
->pipe
, handle
);
608 void cso_delete_vertex_shader(struct cso_context
*ctx
, void *handle
)
610 if (handle
== ctx
->vertex_shader
) {
611 /* unbind before deleting */
612 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
613 ctx
->vertex_shader
= NULL
;
615 ctx
->pipe
->delete_vs_state(ctx
->pipe
, handle
);
618 void cso_save_vertex_shader(struct cso_context
*ctx
)
620 assert(!ctx
->vertex_shader_saved
);
621 ctx
->vertex_shader_saved
= ctx
->vertex_shader
;
624 void cso_restore_vertex_shader(struct cso_context
*ctx
)
626 if (ctx
->vertex_shader_saved
!= ctx
->vertex_shader
) {
627 ctx
->pipe
->bind_vs_state(ctx
->pipe
, ctx
->vertex_shader_saved
);
628 ctx
->vertex_shader
= ctx
->vertex_shader_saved
;
630 ctx
->vertex_shader_saved
= NULL
;
634 void cso_set_framebuffer(struct cso_context
*ctx
,
635 const struct pipe_framebuffer_state
*fb
)
637 if (memcmp(&ctx
->fb
, fb
, sizeof(*fb
)) != 0) {
638 util_copy_framebuffer_state(&ctx
->fb
, fb
);
639 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, fb
);
643 void cso_save_framebuffer(struct cso_context
*ctx
)
645 util_copy_framebuffer_state(&ctx
->fb_saved
, &ctx
->fb
);
648 void cso_restore_framebuffer(struct cso_context
*ctx
)
650 if (memcmp(&ctx
->fb
, &ctx
->fb_saved
, sizeof(ctx
->fb
))) {
651 util_copy_framebuffer_state(&ctx
->fb
, &ctx
->fb_saved
);
652 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, &ctx
->fb
);
653 util_unreference_framebuffer_state(&ctx
->fb_saved
);
658 void cso_set_viewport(struct cso_context
*ctx
,
659 const struct pipe_viewport_state
*vp
)
661 if (memcmp(&ctx
->vp
, vp
, sizeof(*vp
))) {
663 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, vp
);
667 void cso_save_viewport(struct cso_context
*ctx
)
669 ctx
->vp_saved
= ctx
->vp
;
673 void cso_restore_viewport(struct cso_context
*ctx
)
675 if (memcmp(&ctx
->vp
, &ctx
->vp_saved
, sizeof(ctx
->vp
))) {
676 ctx
->vp
= ctx
->vp_saved
;
677 ctx
->pipe
->set_viewport_states(ctx
->pipe
, 0, 1, &ctx
->vp
);
682 void cso_set_blend_color(struct cso_context
*ctx
,
683 const struct pipe_blend_color
*bc
)
685 if (memcmp(&ctx
->blend_color
, bc
, sizeof(ctx
->blend_color
))) {
686 ctx
->blend_color
= *bc
;
687 ctx
->pipe
->set_blend_color(ctx
->pipe
, bc
);
691 void cso_set_sample_mask(struct cso_context
*ctx
, unsigned sample_mask
)
693 if (ctx
->sample_mask
!= sample_mask
) {
694 ctx
->sample_mask
= sample_mask
;
695 ctx
->pipe
->set_sample_mask(ctx
->pipe
, sample_mask
);
699 void cso_save_sample_mask(struct cso_context
*ctx
)
701 ctx
->sample_mask_saved
= ctx
->sample_mask
;
704 void cso_restore_sample_mask(struct cso_context
*ctx
)
706 cso_set_sample_mask(ctx
, ctx
->sample_mask_saved
);
709 void cso_set_min_samples(struct cso_context
*ctx
, unsigned min_samples
)
711 if (ctx
->min_samples
!= min_samples
&& ctx
->pipe
->set_min_samples
) {
712 ctx
->min_samples
= min_samples
;
713 ctx
->pipe
->set_min_samples(ctx
->pipe
, min_samples
);
717 void cso_save_min_samples(struct cso_context
*ctx
)
719 ctx
->min_samples_saved
= ctx
->min_samples
;
722 void cso_restore_min_samples(struct cso_context
*ctx
)
724 cso_set_min_samples(ctx
, ctx
->min_samples_saved
);
727 void cso_set_stencil_ref(struct cso_context
*ctx
,
728 const struct pipe_stencil_ref
*sr
)
730 if (memcmp(&ctx
->stencil_ref
, sr
, sizeof(ctx
->stencil_ref
))) {
731 ctx
->stencil_ref
= *sr
;
732 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, sr
);
736 void cso_save_stencil_ref(struct cso_context
*ctx
)
738 ctx
->stencil_ref_saved
= ctx
->stencil_ref
;
742 void cso_restore_stencil_ref(struct cso_context
*ctx
)
744 if (memcmp(&ctx
->stencil_ref
, &ctx
->stencil_ref_saved
,
745 sizeof(ctx
->stencil_ref
))) {
746 ctx
->stencil_ref
= ctx
->stencil_ref_saved
;
747 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, &ctx
->stencil_ref
);
751 void cso_set_render_condition(struct cso_context
*ctx
,
752 struct pipe_query
*query
,
753 boolean condition
, uint mode
)
755 struct pipe_context
*pipe
= ctx
->pipe
;
757 if (ctx
->render_condition
!= query
||
758 ctx
->render_condition_mode
!= mode
||
759 ctx
->render_condition_cond
!= condition
) {
760 pipe
->render_condition(pipe
, query
, condition
, mode
);
761 ctx
->render_condition
= query
;
762 ctx
->render_condition_cond
= condition
;
763 ctx
->render_condition_mode
= mode
;
767 void cso_save_render_condition(struct cso_context
*ctx
)
769 ctx
->render_condition_saved
= ctx
->render_condition
;
770 ctx
->render_condition_cond_saved
= ctx
->render_condition_cond
;
771 ctx
->render_condition_mode_saved
= ctx
->render_condition_mode
;
774 void cso_restore_render_condition(struct cso_context
*ctx
)
776 cso_set_render_condition(ctx
, ctx
->render_condition_saved
,
777 ctx
->render_condition_cond_saved
,
778 ctx
->render_condition_mode_saved
);
781 void cso_set_geometry_shader_handle(struct cso_context
*ctx
, void *handle
)
783 assert(ctx
->has_geometry_shader
|| !handle
);
785 if (ctx
->has_geometry_shader
&& ctx
->geometry_shader
!= handle
) {
786 ctx
->geometry_shader
= handle
;
787 ctx
->pipe
->bind_gs_state(ctx
->pipe
, handle
);
791 void cso_delete_geometry_shader(struct cso_context
*ctx
, void *handle
)
793 if (handle
== ctx
->geometry_shader
) {
794 /* unbind before deleting */
795 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
796 ctx
->geometry_shader
= NULL
;
798 ctx
->pipe
->delete_gs_state(ctx
->pipe
, handle
);
801 void cso_save_geometry_shader(struct cso_context
*ctx
)
803 if (!ctx
->has_geometry_shader
) {
807 assert(!ctx
->geometry_shader_saved
);
808 ctx
->geometry_shader_saved
= ctx
->geometry_shader
;
811 void cso_restore_geometry_shader(struct cso_context
*ctx
)
813 if (!ctx
->has_geometry_shader
) {
817 if (ctx
->geometry_shader_saved
!= ctx
->geometry_shader
) {
818 ctx
->pipe
->bind_gs_state(ctx
->pipe
, ctx
->geometry_shader_saved
);
819 ctx
->geometry_shader
= ctx
->geometry_shader_saved
;
821 ctx
->geometry_shader_saved
= NULL
;
824 void cso_set_tessctrl_shader_handle(struct cso_context
*ctx
, void *handle
)
826 assert(ctx
->has_tessellation
|| !handle
);
828 if (ctx
->has_tessellation
&& ctx
->tessctrl_shader
!= handle
) {
829 ctx
->tessctrl_shader
= handle
;
830 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, handle
);
834 void cso_delete_tessctrl_shader(struct cso_context
*ctx
, void *handle
)
836 if (handle
== ctx
->tessctrl_shader
) {
837 /* unbind before deleting */
838 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, NULL
);
839 ctx
->tessctrl_shader
= NULL
;
841 ctx
->pipe
->delete_tcs_state(ctx
->pipe
, handle
);
844 void cso_save_tessctrl_shader(struct cso_context
*ctx
)
846 if (!ctx
->has_tessellation
) {
850 assert(!ctx
->tessctrl_shader_saved
);
851 ctx
->tessctrl_shader_saved
= ctx
->tessctrl_shader
;
854 void cso_restore_tessctrl_shader(struct cso_context
*ctx
)
856 if (!ctx
->has_tessellation
) {
860 if (ctx
->tessctrl_shader_saved
!= ctx
->tessctrl_shader
) {
861 ctx
->pipe
->bind_tcs_state(ctx
->pipe
, ctx
->tessctrl_shader_saved
);
862 ctx
->tessctrl_shader
= ctx
->tessctrl_shader_saved
;
864 ctx
->tessctrl_shader_saved
= NULL
;
867 void cso_set_tesseval_shader_handle(struct cso_context
*ctx
, void *handle
)
869 assert(ctx
->has_tessellation
|| !handle
);
871 if (ctx
->has_tessellation
&& ctx
->tesseval_shader
!= handle
) {
872 ctx
->tesseval_shader
= handle
;
873 ctx
->pipe
->bind_tes_state(ctx
->pipe
, handle
);
877 void cso_delete_tesseval_shader(struct cso_context
*ctx
, void *handle
)
879 if (handle
== ctx
->tesseval_shader
) {
880 /* unbind before deleting */
881 ctx
->pipe
->bind_tes_state(ctx
->pipe
, NULL
);
882 ctx
->tesseval_shader
= NULL
;
884 ctx
->pipe
->delete_tes_state(ctx
->pipe
, handle
);
887 void cso_save_tesseval_shader(struct cso_context
*ctx
)
889 if (!ctx
->has_tessellation
) {
893 assert(!ctx
->tesseval_shader_saved
);
894 ctx
->tesseval_shader_saved
= ctx
->tesseval_shader
;
897 void cso_restore_tesseval_shader(struct cso_context
*ctx
)
899 if (!ctx
->has_tessellation
) {
903 if (ctx
->tesseval_shader_saved
!= ctx
->tesseval_shader
) {
904 ctx
->pipe
->bind_tes_state(ctx
->pipe
, ctx
->tesseval_shader_saved
);
905 ctx
->tesseval_shader
= ctx
->tesseval_shader_saved
;
907 ctx
->tesseval_shader_saved
= NULL
;
911 cso_set_vertex_elements(struct cso_context
*ctx
,
913 const struct pipe_vertex_element
*states
)
915 struct u_vbuf
*vbuf
= ctx
->vbuf
;
916 unsigned key_size
, hash_key
;
917 struct cso_hash_iter iter
;
919 struct cso_velems_state velems_state
;
922 u_vbuf_set_vertex_elements(vbuf
, count
, states
);
926 /* Need to include the count into the stored state data too.
927 * Otherwise first few count pipe_vertex_elements could be identical
928 * even if count is different, and there's no guarantee the hash would
929 * be different in that case neither.
931 key_size
= sizeof(struct pipe_vertex_element
) * count
+ sizeof(unsigned);
932 velems_state
.count
= count
;
933 memcpy(velems_state
.velems
, states
,
934 sizeof(struct pipe_vertex_element
) * count
);
935 hash_key
= cso_construct_key((void*)&velems_state
, key_size
);
936 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_VELEMENTS
,
937 (void*)&velems_state
, key_size
);
939 if (cso_hash_iter_is_null(iter
)) {
940 struct cso_velements
*cso
= MALLOC(sizeof(struct cso_velements
));
942 return PIPE_ERROR_OUT_OF_MEMORY
;
944 memcpy(&cso
->state
, &velems_state
, key_size
);
945 cso
->data
= ctx
->pipe
->create_vertex_elements_state(ctx
->pipe
, count
,
946 &cso
->state
.velems
[0]);
948 (cso_state_callback
) ctx
->pipe
->delete_vertex_elements_state
;
949 cso
->context
= ctx
->pipe
;
951 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VELEMENTS
, cso
);
952 if (cso_hash_iter_is_null(iter
)) {
954 return PIPE_ERROR_OUT_OF_MEMORY
;
960 handle
= ((struct cso_velements
*)cso_hash_iter_data(iter
))->data
;
963 if (ctx
->velements
!= handle
) {
964 ctx
->velements
= handle
;
965 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, handle
);
970 void cso_save_vertex_elements(struct cso_context
*ctx
)
972 struct u_vbuf
*vbuf
= ctx
->vbuf
;
975 u_vbuf_save_vertex_elements(vbuf
);
979 assert(!ctx
->velements_saved
);
980 ctx
->velements_saved
= ctx
->velements
;
983 void cso_restore_vertex_elements(struct cso_context
*ctx
)
985 struct u_vbuf
*vbuf
= ctx
->vbuf
;
988 u_vbuf_restore_vertex_elements(vbuf
);
992 if (ctx
->velements
!= ctx
->velements_saved
) {
993 ctx
->velements
= ctx
->velements_saved
;
994 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->velements_saved
);
996 ctx
->velements_saved
= NULL
;
1001 void cso_set_vertex_buffers(struct cso_context
*ctx
,
1002 unsigned start_slot
, unsigned count
,
1003 const struct pipe_vertex_buffer
*buffers
)
1005 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1008 u_vbuf_set_vertex_buffers(vbuf
, start_slot
, count
, buffers
);
1012 /* Save what's in the auxiliary slot, so that we can save and restore it
1014 if (start_slot
<= ctx
->aux_vertex_buffer_index
&&
1015 start_slot
+count
> ctx
->aux_vertex_buffer_index
) {
1017 const struct pipe_vertex_buffer
*vb
=
1018 buffers
+ (ctx
->aux_vertex_buffer_index
- start_slot
);
1020 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1022 memcpy(&ctx
->aux_vertex_buffer_current
, vb
,
1023 sizeof(struct pipe_vertex_buffer
));
1026 pipe_resource_reference(&ctx
->aux_vertex_buffer_current
.buffer
,
1028 ctx
->aux_vertex_buffer_current
.user_buffer
= NULL
;
1032 ctx
->pipe
->set_vertex_buffers(ctx
->pipe
, start_slot
, count
, buffers
);
1035 void cso_save_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1037 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1040 u_vbuf_save_aux_vertex_buffer_slot(vbuf
);
1044 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
,
1045 ctx
->aux_vertex_buffer_current
.buffer
);
1046 memcpy(&ctx
->aux_vertex_buffer_saved
, &ctx
->aux_vertex_buffer_current
,
1047 sizeof(struct pipe_vertex_buffer
));
1050 void cso_restore_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1052 struct u_vbuf
*vbuf
= ctx
->vbuf
;
1055 u_vbuf_restore_aux_vertex_buffer_slot(vbuf
);
1059 cso_set_vertex_buffers(ctx
, ctx
->aux_vertex_buffer_index
, 1,
1060 &ctx
->aux_vertex_buffer_saved
);
1061 pipe_resource_reference(&ctx
->aux_vertex_buffer_saved
.buffer
, NULL
);
1064 unsigned cso_get_aux_vertex_buffer_slot(struct cso_context
*ctx
)
1066 return ctx
->aux_vertex_buffer_index
;
1070 /**************** fragment/vertex sampler view state *************************/
1072 static enum pipe_error
1073 single_sampler(struct cso_context
*ctx
,
1074 struct sampler_info
*info
,
1076 const struct pipe_sampler_state
*templ
)
1078 void *handle
= NULL
;
1080 if (templ
!= NULL
) {
1081 unsigned key_size
= sizeof(struct pipe_sampler_state
);
1082 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
1083 struct cso_hash_iter iter
=
1084 cso_find_state_template(ctx
->cache
,
1085 hash_key
, CSO_SAMPLER
,
1086 (void *) templ
, key_size
);
1088 if (cso_hash_iter_is_null(iter
)) {
1089 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
1091 return PIPE_ERROR_OUT_OF_MEMORY
;
1093 memcpy(&cso
->state
, templ
, sizeof(*templ
));
1094 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
1096 (cso_state_callback
) ctx
->pipe
->delete_sampler_state
;
1097 cso
->context
= ctx
->pipe
;
1099 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
1100 if (cso_hash_iter_is_null(iter
)) {
1102 return PIPE_ERROR_OUT_OF_MEMORY
;
1108 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
1112 info
->samplers
[idx
] = handle
;
1118 cso_single_sampler(struct cso_context
*ctx
,
1119 unsigned shader_stage
,
1121 const struct pipe_sampler_state
*templ
)
1123 return single_sampler(ctx
, &ctx
->samplers
[shader_stage
], idx
, templ
);
1129 single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1131 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1134 /* find highest non-null sampler */
1135 for (i
= PIPE_MAX_SAMPLERS
; i
> 0; i
--) {
1136 if (info
->samplers
[i
- 1] != NULL
)
1140 info
->nr_samplers
= i
;
1141 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, shader_stage
, 0, i
,
1146 cso_single_sampler_done(struct cso_context
*ctx
, unsigned shader_stage
)
1148 single_sampler_done(ctx
, shader_stage
);
1153 * If the function encouters any errors it will return the
1154 * last one. Done to always try to set as many samplers
1158 cso_set_samplers(struct cso_context
*ctx
,
1159 unsigned shader_stage
,
1161 const struct pipe_sampler_state
**templates
)
1163 struct sampler_info
*info
= &ctx
->samplers
[shader_stage
];
1165 enum pipe_error temp
, error
= PIPE_OK
;
1170 for (i
= 0; i
< nr
; i
++) {
1171 temp
= single_sampler(ctx
, info
, i
, templates
[i
]);
1172 if (temp
!= PIPE_OK
)
1176 for ( ; i
< info
->nr_samplers
; i
++) {
1177 temp
= single_sampler(ctx
, info
, i
, NULL
);
1178 if (temp
!= PIPE_OK
)
1182 single_sampler_done(ctx
, shader_stage
);
1188 cso_save_fragment_samplers(struct cso_context
*ctx
)
1190 struct sampler_info
*info
= &ctx
->samplers
[PIPE_SHADER_FRAGMENT
];
1192 ctx
->nr_fragment_samplers_saved
= info
->nr_samplers
;
1193 memcpy(ctx
->fragment_samplers_saved
, info
->samplers
,
1194 sizeof(info
->samplers
));
1199 cso_restore_fragment_samplers(struct cso_context
*ctx
)
1201 struct sampler_info
*info
= &ctx
->samplers
[PIPE_SHADER_FRAGMENT
];
1203 info
->nr_samplers
= ctx
->nr_fragment_samplers_saved
;
1204 memcpy(info
->samplers
, ctx
->fragment_samplers_saved
,
1205 sizeof(info
->samplers
));
1206 single_sampler_done(ctx
, PIPE_SHADER_FRAGMENT
);
1211 cso_set_sampler_views(struct cso_context
*ctx
,
1212 unsigned shader_stage
,
1214 struct pipe_sampler_view
**views
)
1216 if (shader_stage
== PIPE_SHADER_FRAGMENT
) {
1218 boolean any_change
= FALSE
;
1220 /* reference new views */
1221 for (i
= 0; i
< count
; i
++) {
1222 any_change
|= ctx
->fragment_views
[i
] != views
[i
];
1223 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], views
[i
]);
1225 /* unref extra old views, if any */
1226 for (; i
< ctx
->nr_fragment_views
; i
++) {
1227 any_change
|= ctx
->fragment_views
[i
] != NULL
;
1228 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1231 /* bind the new sampler views */
1233 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0,
1234 MAX2(ctx
->nr_fragment_views
, count
),
1235 ctx
->fragment_views
);
1238 ctx
->nr_fragment_views
= count
;
1241 ctx
->pipe
->set_sampler_views(ctx
->pipe
, shader_stage
, 0, count
, views
);
1246 cso_save_fragment_sampler_views(struct cso_context
*ctx
)
1250 ctx
->nr_fragment_views_saved
= ctx
->nr_fragment_views
;
1252 for (i
= 0; i
< ctx
->nr_fragment_views
; i
++) {
1253 assert(!ctx
->fragment_views_saved
[i
]);
1254 pipe_sampler_view_reference(&ctx
->fragment_views_saved
[i
],
1255 ctx
->fragment_views
[i
]);
1261 cso_restore_fragment_sampler_views(struct cso_context
*ctx
)
1263 unsigned i
, nr_saved
= ctx
->nr_fragment_views_saved
;
1266 for (i
= 0; i
< nr_saved
; i
++) {
1267 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1268 /* move the reference from one pointer to another */
1269 ctx
->fragment_views
[i
] = ctx
->fragment_views_saved
[i
];
1270 ctx
->fragment_views_saved
[i
] = NULL
;
1272 for (; i
< ctx
->nr_fragment_views
; i
++) {
1273 pipe_sampler_view_reference(&ctx
->fragment_views
[i
], NULL
);
1276 num
= MAX2(ctx
->nr_fragment_views
, nr_saved
);
1278 /* bind the old/saved sampler views */
1279 ctx
->pipe
->set_sampler_views(ctx
->pipe
, PIPE_SHADER_FRAGMENT
, 0, num
,
1280 ctx
->fragment_views
);
1282 ctx
->nr_fragment_views
= nr_saved
;
1283 ctx
->nr_fragment_views_saved
= 0;
1288 cso_set_stream_outputs(struct cso_context
*ctx
,
1289 unsigned num_targets
,
1290 struct pipe_stream_output_target
**targets
,
1291 const unsigned *offsets
)
1293 struct pipe_context
*pipe
= ctx
->pipe
;
1296 if (!ctx
->has_streamout
) {
1297 assert(num_targets
== 0);
1301 if (ctx
->nr_so_targets
== 0 && num_targets
== 0) {
1302 /* Nothing to do. */
1306 /* reference new targets */
1307 for (i
= 0; i
< num_targets
; i
++) {
1308 pipe_so_target_reference(&ctx
->so_targets
[i
], targets
[i
]);
1310 /* unref extra old targets, if any */
1311 for (; i
< ctx
->nr_so_targets
; i
++) {
1312 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1315 pipe
->set_stream_output_targets(pipe
, num_targets
, targets
,
1317 ctx
->nr_so_targets
= num_targets
;
1321 cso_save_stream_outputs(struct cso_context
*ctx
)
1325 if (!ctx
->has_streamout
) {
1329 ctx
->nr_so_targets_saved
= ctx
->nr_so_targets
;
1331 for (i
= 0; i
< ctx
->nr_so_targets
; i
++) {
1332 assert(!ctx
->so_targets_saved
[i
]);
1333 pipe_so_target_reference(&ctx
->so_targets_saved
[i
], ctx
->so_targets
[i
]);
1338 cso_restore_stream_outputs(struct cso_context
*ctx
)
1340 struct pipe_context
*pipe
= ctx
->pipe
;
1342 unsigned offset
[PIPE_MAX_SO_BUFFERS
];
1344 if (!ctx
->has_streamout
) {
1348 if (ctx
->nr_so_targets
== 0 && ctx
->nr_so_targets_saved
== 0) {
1349 /* Nothing to do. */
1353 assert(ctx
->nr_so_targets_saved
<= PIPE_MAX_SO_BUFFERS
);
1354 for (i
= 0; i
< ctx
->nr_so_targets_saved
; i
++) {
1355 pipe_so_target_reference(&ctx
->so_targets
[i
], NULL
);
1356 /* move the reference from one pointer to another */
1357 ctx
->so_targets
[i
] = ctx
->so_targets_saved
[i
];
1358 ctx
->so_targets_saved
[i
] = NULL
;
1359 /* -1 means append */
1360 offset
[i
] = (unsigned)-1;
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
, ctx
->nr_so_targets_saved
,
1367 ctx
->so_targets
, offset
);
1369 ctx
->nr_so_targets
= ctx
->nr_so_targets_saved
;
1370 ctx
->nr_so_targets_saved
= 0;
1373 /* constant buffers */
1376 cso_set_constant_buffer(struct cso_context
*cso
, unsigned shader_stage
,
1377 unsigned index
, struct pipe_constant_buffer
*cb
)
1379 struct pipe_context
*pipe
= cso
->pipe
;
1381 pipe
->set_constant_buffer(pipe
, shader_stage
, index
, cb
);
1384 util_copy_constant_buffer(&cso
->aux_constbuf_current
[shader_stage
], cb
);
1389 cso_set_constant_buffer_resource(struct cso_context
*cso
,
1390 unsigned shader_stage
,
1392 struct pipe_resource
*buffer
)
1395 struct pipe_constant_buffer cb
;
1397 cb
.buffer_offset
= 0;
1398 cb
.buffer_size
= buffer
->width0
;
1399 cb
.user_buffer
= NULL
;
1400 cso_set_constant_buffer(cso
, shader_stage
, index
, &cb
);
1402 cso_set_constant_buffer(cso
, shader_stage
, index
, NULL
);
1407 cso_save_constant_buffer_slot0(struct cso_context
*cso
,
1408 unsigned shader_stage
)
1410 util_copy_constant_buffer(&cso
->aux_constbuf_saved
[shader_stage
],
1411 &cso
->aux_constbuf_current
[shader_stage
]);
1415 cso_restore_constant_buffer_slot0(struct cso_context
*cso
,
1416 unsigned shader_stage
)
1418 cso_set_constant_buffer(cso
, shader_stage
, 0,
1419 &cso
->aux_constbuf_saved
[shader_stage
]);
1420 pipe_resource_reference(&cso
->aux_constbuf_saved
[shader_stage
].buffer
,
1427 cso_set_index_buffer(struct cso_context
*cso
,
1428 const struct pipe_index_buffer
*ib
)
1430 struct u_vbuf
*vbuf
= cso
->vbuf
;
1433 u_vbuf_set_index_buffer(vbuf
, ib
);
1435 struct pipe_context
*pipe
= cso
->pipe
;
1436 pipe
->set_index_buffer(pipe
, ib
);
1441 cso_draw_vbo(struct cso_context
*cso
,
1442 const struct pipe_draw_info
*info
)
1444 struct u_vbuf
*vbuf
= cso
->vbuf
;
1447 u_vbuf_draw_vbo(vbuf
, info
);
1449 struct pipe_context
*pipe
= cso
->pipe
;
1450 pipe
->draw_vbo(pipe
, info
);
1455 cso_draw_arrays(struct cso_context
*cso
, uint mode
, uint start
, uint count
)
1457 struct pipe_draw_info info
;
1459 util_draw_init_info(&info
);
1464 info
.min_index
= start
;
1465 info
.max_index
= start
+ count
- 1;
1467 cso_draw_vbo(cso
, &info
);
1471 cso_draw_arrays_instanced(struct cso_context
*cso
, uint mode
,
1472 uint start
, uint count
,
1473 uint start_instance
, uint instance_count
)
1475 struct pipe_draw_info info
;
1477 util_draw_init_info(&info
);
1482 info
.min_index
= start
;
1483 info
.max_index
= start
+ count
- 1;
1484 info
.start_instance
= start_instance
;
1485 info
.instance_count
= instance_count
;
1487 cso_draw_vbo(cso
, &info
);