1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <zack@tungstengraphics.com>
35 * @author Keith Whitwell <keith@tungstengraphics.com>
38 #include "pipe/p_state.h"
39 #include "pipe/p_util.h"
40 #include "pipe/p_inlines.h"
41 #include "tgsi/util/tgsi_parse.h"
43 #include "cso_cache/cso_context.h"
44 #include "cso_cache/cso_cache.h"
45 #include "cso_cache/cso_hash.h"
48 struct pipe_context
*pipe
;
49 struct cso_cache
*cache
;
52 void *samplers
[PIPE_MAX_SAMPLERS
];
56 void *samplers
[PIPE_MAX_SAMPLERS
];
59 void *samplers_saved
[PIPE_MAX_SAMPLERS
];
60 unsigned nr_samplers_saved
;
62 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
65 struct pipe_texture
*textures_saved
[PIPE_MAX_SAMPLERS
];
66 uint nr_textures_saved
;
68 /** Current and saved state.
69 * The saved state is used as a 1-deep stack.
71 void *blend
, *blend_saved
;
72 void *depth_stencil
, *depth_stencil_saved
;
73 void *rasterizer
, *rasterizer_saved
;
74 void *fragment_shader
, *fragment_shader_saved
;
75 void *vertex_shader
, *vertex_shader_saved
;
77 struct pipe_framebuffer_state fb
, fb_saved
;
78 struct pipe_viewport_state vp
, vp_saved
;
79 struct pipe_blend_color blend_color
;
83 static boolean
delete_blend_state(struct cso_context
*ctx
, void *state
)
85 struct cso_blend
*cso
= (struct cso_blend
*)state
;
87 if (ctx
->blend
== cso
->data
)
90 if (cso
->delete_state
)
91 cso
->delete_state(cso
->context
, cso
->data
);
96 static boolean
delete_depth_stencil_state(struct cso_context
*ctx
, void *state
)
98 struct cso_depth_stencil_alpha
*cso
= (struct cso_depth_stencil_alpha
*)state
;
100 if (ctx
->depth_stencil
== cso
->data
)
103 if (cso
->delete_state
)
104 cso
->delete_state(cso
->context
, cso
->data
);
110 static boolean
delete_sampler_state(struct cso_context
*ctx
, void *state
)
112 struct cso_sampler
*cso
= (struct cso_sampler
*)state
;
113 if (cso
->delete_state
)
114 cso
->delete_state(cso
->context
, cso
->data
);
119 static boolean
delete_rasterizer_state(struct cso_context
*ctx
, void *state
)
121 struct cso_rasterizer
*cso
= (struct cso_rasterizer
*)state
;
123 if (ctx
->rasterizer
== cso
->data
)
125 if (cso
->delete_state
)
126 cso
->delete_state(cso
->context
, cso
->data
);
131 static boolean
delete_fs_state(struct cso_context
*ctx
, void *state
)
133 struct cso_fragment_shader
*cso
= (struct cso_fragment_shader
*)state
;
134 if (ctx
->fragment_shader
== cso
->data
)
136 if (cso
->delete_state
)
137 cso
->delete_state(cso
->context
, cso
->data
);
142 static boolean
delete_vs_state(struct cso_context
*ctx
, void *state
)
144 struct cso_vertex_shader
*cso
= (struct cso_vertex_shader
*)state
;
145 if (ctx
->vertex_shader
== cso
->data
)
147 if (cso
->delete_state
)
148 cso
->delete_state(cso
->context
, cso
->data
);
154 static INLINE boolean
delete_cso(struct cso_context
*ctx
,
155 void *state
, enum cso_cache_type type
)
159 return delete_blend_state(ctx
, state
);
162 return delete_sampler_state(ctx
, state
);
164 case CSO_DEPTH_STENCIL_ALPHA
:
165 return delete_depth_stencil_state(ctx
, state
);
168 return delete_rasterizer_state(ctx
, state
);
170 case CSO_FRAGMENT_SHADER
:
171 return delete_fs_state(ctx
, state
);
173 case CSO_VERTEX_SHADER
:
174 return delete_vs_state(ctx
, state
);
183 static INLINE
void sanitize_hash(struct cso_hash
*hash
, enum cso_cache_type type
,
184 int max_size
, void *user_data
)
186 struct cso_context
*ctx
= (struct cso_context
*)user_data
;
187 /* if we're approach the maximum size, remove fourth of the entries
188 * otherwise every subsequent call will go through the same */
189 int hash_size
= cso_hash_size(hash
);
190 int max_entries
= (max_size
> hash_size
) ? max_size
: hash_size
;
191 int to_remove
= (max_size
< max_entries
) * max_entries
/4;
192 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
193 if (hash_size
> max_size
)
194 to_remove
+= hash_size
- max_size
;
196 /*remove elements until we're good */
197 /*fixme: currently we pick the nodes to remove at random*/
198 void *cso
= cso_hash_iter_data(iter
);
199 if (delete_cso(ctx
, cso
, type
)) {
200 iter
= cso_hash_erase(hash
, iter
);
203 iter
= cso_hash_iter_next(iter
);
208 struct cso_context
*cso_create_context( struct pipe_context
*pipe
)
210 struct cso_context
*ctx
= CALLOC_STRUCT(cso_context
);
214 ctx
->cache
= cso_cache_create();
215 if (ctx
->cache
== NULL
)
217 cso_cache_set_sanitize_callback(ctx
->cache
,
223 /* Enable for testing: */
224 if (0) cso_set_maximum_cache_size( ctx
->cache
, 4 );
229 cso_destroy_context( ctx
);
235 * Prior to context destruction, this function unbinds all state objects.
237 void cso_release_all( struct cso_context
*ctx
)
242 ctx
->pipe
->bind_blend_state( ctx
->pipe
, NULL
);
243 ctx
->pipe
->bind_rasterizer_state( ctx
->pipe
, NULL
);
244 ctx
->pipe
->bind_sampler_states( ctx
->pipe
, 0, NULL
);
245 ctx
->pipe
->bind_depth_stencil_alpha_state( ctx
->pipe
, NULL
);
246 ctx
->pipe
->bind_fs_state( ctx
->pipe
, NULL
);
247 ctx
->pipe
->bind_vs_state( ctx
->pipe
, NULL
);
250 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
251 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
252 pipe_texture_reference(&ctx
->textures_saved
[i
], NULL
);
256 cso_cache_delete( ctx
->cache
);
262 void cso_destroy_context( struct cso_context
*ctx
)
265 //cso_release_all( ctx );
271 /* Those function will either find the state of the given template
272 * in the cache or they will create a new state from the given
273 * template, insert it in the cache and return it.
277 * If the driver returns 0 from the create method then they will assign
278 * the data member of the cso to be the template itself.
281 enum pipe_error
cso_set_blend(struct cso_context
*ctx
,
282 const struct pipe_blend_state
*templ
)
284 unsigned hash_key
= cso_construct_key((void*)templ
, sizeof(struct pipe_blend_state
));
285 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
290 if (cso_hash_iter_is_null(iter
)) {
291 struct cso_blend
*cso
= MALLOC(sizeof(struct cso_blend
));
293 return PIPE_ERROR_OUT_OF_MEMORY
;
296 cso
->data
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &cso
->state
);
297 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_blend_state
;
298 cso
->context
= ctx
->pipe
;
300 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_BLEND
, cso
);
301 if (cso_hash_iter_is_null(iter
)) {
303 return PIPE_ERROR_OUT_OF_MEMORY
;
309 handle
= ((struct cso_blend
*)cso_hash_iter_data(iter
))->data
;
312 if (ctx
->blend
!= handle
) {
314 ctx
->pipe
->bind_blend_state(ctx
->pipe
, handle
);
319 void cso_save_blend(struct cso_context
*ctx
)
321 assert(!ctx
->blend_saved
);
322 ctx
->blend_saved
= ctx
->blend
;
325 void cso_restore_blend(struct cso_context
*ctx
)
327 if (ctx
->blend
!= ctx
->blend_saved
) {
328 ctx
->blend
= ctx
->blend_saved
;
329 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend_saved
);
331 ctx
->blend_saved
= NULL
;
336 enum pipe_error
cso_single_sampler(struct cso_context
*ctx
,
338 const struct pipe_sampler_state
*templ
)
343 unsigned hash_key
= cso_construct_key((void*)templ
, sizeof(struct pipe_sampler_state
));
344 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
345 hash_key
, CSO_SAMPLER
,
348 if (cso_hash_iter_is_null(iter
)) {
349 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
351 return PIPE_ERROR_OUT_OF_MEMORY
;
354 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
355 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_sampler_state
;
356 cso
->context
= ctx
->pipe
;
358 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
359 if (cso_hash_iter_is_null(iter
)) {
361 return PIPE_ERROR_OUT_OF_MEMORY
;
367 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
371 ctx
->samplers
[idx
] = handle
;
375 void cso_single_sampler_done( struct cso_context
*ctx
)
379 /* find highest non-null sampler */
380 for (i
= PIPE_MAX_SAMPLERS
; i
> 0; i
--) {
381 if (ctx
->samplers
[i
- 1] != NULL
)
385 ctx
->nr_samplers
= i
;
387 if (ctx
->hw
.nr_samplers
!= ctx
->nr_samplers
||
388 memcmp(ctx
->hw
.samplers
,
390 ctx
->nr_samplers
* sizeof(void *)) != 0)
392 memcpy(ctx
->hw
.samplers
, ctx
->samplers
, ctx
->nr_samplers
* sizeof(void *));
393 ctx
->hw
.nr_samplers
= ctx
->nr_samplers
;
395 ctx
->pipe
->bind_sampler_states(ctx
->pipe
, ctx
->nr_samplers
, ctx
->samplers
);
400 * If the function encouters any errors it will return the
401 * last one. Done to always try to set as many samplers
404 enum pipe_error
cso_set_samplers( struct cso_context
*ctx
,
406 const struct pipe_sampler_state
**templates
)
409 enum pipe_error temp
, error
= PIPE_OK
;
414 for (i
= 0; i
< nr
; i
++) {
415 temp
= cso_single_sampler( ctx
, i
, templates
[i
] );
420 for ( ; i
< ctx
->nr_samplers
; i
++) {
421 temp
= cso_single_sampler( ctx
, i
, NULL
);
426 cso_single_sampler_done( ctx
);
431 void cso_save_samplers(struct cso_context
*ctx
)
433 ctx
->nr_samplers_saved
= ctx
->nr_samplers
;
434 memcpy(ctx
->samplers_saved
, ctx
->samplers
, sizeof(ctx
->samplers
));
437 void cso_restore_samplers(struct cso_context
*ctx
)
439 ctx
->nr_samplers
= ctx
->nr_samplers_saved
;
440 memcpy(ctx
->samplers
, ctx
->samplers_saved
, sizeof(ctx
->samplers
));
441 cso_single_sampler_done( ctx
);
445 enum pipe_error
cso_set_sampler_textures( struct cso_context
*ctx
,
447 struct pipe_texture
**textures
)
451 ctx
->nr_textures
= count
;
453 for (i
= 0; i
< count
; i
++)
454 pipe_texture_reference(&ctx
->textures
[i
], textures
[i
]);
455 for ( ; i
< PIPE_MAX_SAMPLERS
; i
++)
456 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
458 ctx
->pipe
->set_sampler_textures(ctx
->pipe
, count
, textures
);
463 void cso_save_sampler_textures( struct cso_context
*ctx
)
467 ctx
->nr_textures_saved
= ctx
->nr_textures
;
468 for (i
= 0; i
< ctx
->nr_textures
; i
++) {
469 assert(!ctx
->textures_saved
[i
]);
470 pipe_texture_reference(&ctx
->textures_saved
[i
], ctx
->textures
[i
]);
474 void cso_restore_sampler_textures( struct cso_context
*ctx
)
478 ctx
->nr_textures
= ctx
->nr_textures_saved
;
480 for (i
= 0; i
< ctx
->nr_textures
; i
++) {
481 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
482 ctx
->textures
[i
] = ctx
->textures_saved
[i
];
483 ctx
->textures_saved
[i
] = NULL
;
485 for ( ; i
< PIPE_MAX_SAMPLERS
; i
++)
486 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
488 ctx
->pipe
->set_sampler_textures(ctx
->pipe
, ctx
->nr_textures
, ctx
->textures
);
490 ctx
->nr_textures_saved
= 0;
495 enum pipe_error
cso_set_depth_stencil_alpha(struct cso_context
*ctx
,
496 const struct pipe_depth_stencil_alpha_state
*templ
)
498 unsigned hash_key
= cso_construct_key((void*)templ
,
499 sizeof(struct pipe_depth_stencil_alpha_state
));
500 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
502 CSO_DEPTH_STENCIL_ALPHA
,
506 if (cso_hash_iter_is_null(iter
)) {
507 struct cso_depth_stencil_alpha
*cso
= MALLOC(sizeof(struct cso_depth_stencil_alpha
));
509 return PIPE_ERROR_OUT_OF_MEMORY
;
512 cso
->data
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &cso
->state
);
513 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_depth_stencil_alpha_state
;
514 cso
->context
= ctx
->pipe
;
516 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_DEPTH_STENCIL_ALPHA
, cso
);
517 if (cso_hash_iter_is_null(iter
)) {
519 return PIPE_ERROR_OUT_OF_MEMORY
;
525 handle
= ((struct cso_depth_stencil_alpha
*)cso_hash_iter_data(iter
))->data
;
528 if (ctx
->depth_stencil
!= handle
) {
529 ctx
->depth_stencil
= handle
;
530 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, handle
);
535 void cso_save_depth_stencil_alpha(struct cso_context
*ctx
)
537 assert(!ctx
->depth_stencil_saved
);
538 ctx
->depth_stencil_saved
= ctx
->depth_stencil
;
541 void cso_restore_depth_stencil_alpha(struct cso_context
*ctx
)
543 if (ctx
->depth_stencil
!= ctx
->depth_stencil_saved
) {
544 ctx
->depth_stencil
= ctx
->depth_stencil_saved
;
545 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->depth_stencil_saved
);
547 ctx
->depth_stencil_saved
= NULL
;
552 enum pipe_error
cso_set_rasterizer(struct cso_context
*ctx
,
553 const struct pipe_rasterizer_state
*templ
)
555 unsigned hash_key
= cso_construct_key((void*)templ
,
556 sizeof(struct pipe_rasterizer_state
));
557 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
558 hash_key
, CSO_RASTERIZER
,
562 if (cso_hash_iter_is_null(iter
)) {
563 struct cso_rasterizer
*cso
= MALLOC(sizeof(struct cso_rasterizer
));
565 return PIPE_ERROR_OUT_OF_MEMORY
;
568 cso
->data
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &cso
->state
);
569 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_rasterizer_state
;
570 cso
->context
= ctx
->pipe
;
572 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_RASTERIZER
, cso
);
573 if (cso_hash_iter_is_null(iter
)) {
575 return PIPE_ERROR_OUT_OF_MEMORY
;
581 handle
= ((struct cso_rasterizer
*)cso_hash_iter_data(iter
))->data
;
584 if (ctx
->rasterizer
!= handle
) {
585 ctx
->rasterizer
= handle
;
586 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, handle
);
591 void cso_save_rasterizer(struct cso_context
*ctx
)
593 assert(!ctx
->rasterizer_saved
);
594 ctx
->rasterizer_saved
= ctx
->rasterizer
;
597 void cso_restore_rasterizer(struct cso_context
*ctx
)
599 if (ctx
->rasterizer
!= ctx
->rasterizer_saved
) {
600 ctx
->rasterizer
= ctx
->rasterizer_saved
;
601 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rasterizer_saved
);
603 ctx
->rasterizer_saved
= NULL
;
608 enum pipe_error
cso_set_fragment_shader_handle(struct cso_context
*ctx
,
611 if (ctx
->fragment_shader
!= handle
) {
612 ctx
->fragment_shader
= handle
;
613 ctx
->pipe
->bind_fs_state(ctx
->pipe
, handle
);
618 void cso_delete_fragment_shader(struct cso_context
*ctx
, void *handle
)
620 if (handle
== ctx
->fragment_shader
) {
621 /* unbind before deleting */
622 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
623 ctx
->fragment_shader
= NULL
;
625 ctx
->pipe
->delete_fs_state(ctx
->pipe
, handle
);
628 /* Not really working:
631 enum pipe_error
cso_set_fragment_shader(struct cso_context
*ctx
,
632 const struct pipe_shader_state
*templ
)
634 const struct tgsi_token
*tokens
= templ
->tokens
;
635 unsigned num_tokens
= tgsi_num_tokens(tokens
);
636 size_t tokens_size
= num_tokens
*sizeof(struct tgsi_token
);
637 unsigned hash_key
= cso_construct_key((void*)tokens
, tokens_size
);
638 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
644 if (cso_hash_iter_is_null(iter
)) {
645 struct cso_fragment_shader
*cso
= MALLOC(sizeof(struct cso_fragment_shader
) + tokens_size
);
646 struct tgsi_token
*cso_tokens
= (struct tgsi_token
*)((char *)cso
+ sizeof(*cso
));
649 return PIPE_ERROR_OUT_OF_MEMORY
;
651 memcpy(cso_tokens
, tokens
, tokens_size
);
652 cso
->state
.tokens
= cso_tokens
;
653 cso
->data
= ctx
->pipe
->create_fs_state(ctx
->pipe
, &cso
->state
);
654 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_fs_state
;
655 cso
->context
= ctx
->pipe
;
657 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_FRAGMENT_SHADER
, cso
);
658 if (cso_hash_iter_is_null(iter
)) {
660 return PIPE_ERROR_OUT_OF_MEMORY
;
666 handle
= ((struct cso_fragment_shader
*)cso_hash_iter_data(iter
))->data
;
669 return cso_set_fragment_shader_handle( ctx
, handle
);
673 void cso_save_fragment_shader(struct cso_context
*ctx
)
675 assert(!ctx
->fragment_shader_saved
);
676 ctx
->fragment_shader_saved
= ctx
->fragment_shader
;
679 void cso_restore_fragment_shader(struct cso_context
*ctx
)
681 if (ctx
->fragment_shader_saved
!= ctx
->fragment_shader
) {
682 ctx
->pipe
->bind_fs_state(ctx
->pipe
, ctx
->fragment_shader_saved
);
683 ctx
->fragment_shader
= ctx
->fragment_shader_saved
;
685 ctx
->fragment_shader_saved
= NULL
;
689 enum pipe_error
cso_set_vertex_shader_handle(struct cso_context
*ctx
,
692 if (ctx
->vertex_shader
!= handle
) {
693 ctx
->vertex_shader
= handle
;
694 ctx
->pipe
->bind_vs_state(ctx
->pipe
, handle
);
699 void cso_delete_vertex_shader(struct cso_context
*ctx
, void *handle
)
701 if (handle
== ctx
->vertex_shader
) {
702 /* unbind before deleting */
703 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
704 ctx
->vertex_shader
= NULL
;
706 ctx
->pipe
->delete_vs_state(ctx
->pipe
, handle
);
710 /* Not really working:
713 enum pipe_error
cso_set_vertex_shader(struct cso_context
*ctx
,
714 const struct pipe_shader_state
*templ
)
716 unsigned hash_key
= cso_construct_key((void*)templ
,
717 sizeof(struct pipe_shader_state
));
718 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
719 hash_key
, CSO_VERTEX_SHADER
,
723 if (cso_hash_iter_is_null(iter
)) {
724 struct cso_vertex_shader
*cso
= MALLOC(sizeof(struct cso_vertex_shader
));
727 return PIPE_ERROR_OUT_OF_MEMORY
;
730 cso
->data
= ctx
->pipe
->create_vs_state(ctx
->pipe
, &cso
->state
);
731 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_vs_state
;
732 cso
->context
= ctx
->pipe
;
734 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VERTEX_SHADER
, cso
);
735 if (cso_hash_iter_is_null(iter
)) {
737 return PIPE_ERROR_OUT_OF_MEMORY
;
743 handle
= ((struct cso_vertex_shader
*)cso_hash_iter_data(iter
))->data
;
746 return cso_set_vertex_shader_handle( ctx
, handle
);
752 void cso_save_vertex_shader(struct cso_context
*ctx
)
754 assert(!ctx
->vertex_shader_saved
);
755 ctx
->vertex_shader_saved
= ctx
->vertex_shader
;
758 void cso_restore_vertex_shader(struct cso_context
*ctx
)
760 if (ctx
->vertex_shader_saved
!= ctx
->vertex_shader
) {
761 ctx
->pipe
->bind_vs_state(ctx
->pipe
, ctx
->vertex_shader_saved
);
762 ctx
->vertex_shader
= ctx
->vertex_shader_saved
;
764 ctx
->vertex_shader_saved
= NULL
;
769 enum pipe_error
cso_set_framebuffer(struct cso_context
*ctx
,
770 const struct pipe_framebuffer_state
*fb
)
772 if (memcmp(&ctx
->fb
, fb
, sizeof(*fb
)) != 0) {
774 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, fb
);
779 void cso_save_framebuffer(struct cso_context
*ctx
)
781 ctx
->fb_saved
= ctx
->fb
;
784 void cso_restore_framebuffer(struct cso_context
*ctx
)
786 if (memcmp(&ctx
->fb
, &ctx
->fb_saved
, sizeof(ctx
->fb
))) {
787 ctx
->fb
= ctx
->fb_saved
;
788 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, &ctx
->fb
);
793 enum pipe_error
cso_set_viewport(struct cso_context
*ctx
,
794 const struct pipe_viewport_state
*vp
)
796 if (memcmp(&ctx
->vp
, vp
, sizeof(*vp
))) {
798 ctx
->pipe
->set_viewport_state(ctx
->pipe
, vp
);
803 void cso_save_viewport(struct cso_context
*ctx
)
805 ctx
->vp_saved
= ctx
->vp
;
809 void cso_restore_viewport(struct cso_context
*ctx
)
811 if (memcmp(&ctx
->vp
, &ctx
->vp_saved
, sizeof(ctx
->vp
))) {
812 ctx
->vp
= ctx
->vp_saved
;
813 ctx
->pipe
->set_viewport_state(ctx
->pipe
, &ctx
->vp
);
820 enum pipe_error
cso_set_blend_color(struct cso_context
*ctx
,
821 const struct pipe_blend_color
*bc
)
823 if (memcmp(&ctx
->blend_color
, bc
, sizeof(ctx
->blend_color
))) {
824 ctx
->blend_color
= *bc
;
825 ctx
->pipe
->set_blend_color(ctx
->pipe
, bc
);