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 "util/u_inlines.h"
40 #include "util/u_math.h"
41 #include "util/u_memory.h"
42 #include "util/u_sampler.h"
43 #include "tgsi/tgsi_parse.h"
45 #include "cso_cache/cso_context.h"
46 #include "cso_cache/cso_cache.h"
47 #include "cso_cache/cso_hash.h"
48 #include "cso_context.h"
51 struct pipe_context
*pipe
;
52 struct cso_cache
*cache
;
55 void *samplers
[PIPE_MAX_SAMPLERS
];
58 void *vertex_samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
59 unsigned nr_vertex_samplers
;
62 void *samplers
[PIPE_MAX_SAMPLERS
];
65 void *vertex_samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
66 unsigned nr_vertex_samplers
;
68 unsigned nr_samplers_saved
;
69 void *samplers_saved
[PIPE_MAX_SAMPLERS
];
71 unsigned nr_vertex_samplers_saved
;
72 void *vertex_samplers_saved
[PIPE_MAX_VERTEX_SAMPLERS
];
74 struct pipe_texture
*textures
[PIPE_MAX_SAMPLERS
];
75 uint nr_fragment_sampler_views
;
76 struct pipe_sampler_view
*fragment_sampler_views
[PIPE_MAX_SAMPLERS
];
79 struct pipe_texture
*vertex_textures
[PIPE_MAX_VERTEX_SAMPLERS
];
80 uint nr_vertex_sampler_views
;
81 struct pipe_sampler_view
*vertex_sampler_views
[PIPE_MAX_VERTEX_SAMPLERS
];
82 uint nr_vertex_textures
;
84 uint nr_textures_saved
;
85 struct pipe_texture
*textures_saved
[PIPE_MAX_SAMPLERS
];
86 uint nr_fragment_sampler_views_saved
;
87 struct pipe_sampler_view
*fragment_sampler_views_saved
[PIPE_MAX_SAMPLERS
];
89 uint nr_vertex_textures_saved
;
90 struct pipe_texture
*vertex_textures_saved
[PIPE_MAX_VERTEX_SAMPLERS
];
91 uint nr_vertex_sampler_views_saved
;
92 struct pipe_sampler_view
*vertex_sampler_views_saved
[PIPE_MAX_VERTEX_SAMPLERS
];
94 /** Current and saved state.
95 * The saved state is used as a 1-deep stack.
97 void *blend
, *blend_saved
;
98 void *depth_stencil
, *depth_stencil_saved
;
99 void *rasterizer
, *rasterizer_saved
;
100 void *fragment_shader
, *fragment_shader_saved
, *geometry_shader
;
101 void *vertex_shader
, *vertex_shader_saved
, *geometry_shader_saved
;
102 void *velements
, *velements_saved
;
104 struct pipe_clip_state clip
;
105 struct pipe_clip_state clip_saved
;
107 struct pipe_framebuffer_state fb
, fb_saved
;
108 struct pipe_viewport_state vp
, vp_saved
;
109 struct pipe_blend_color blend_color
;
110 struct pipe_stencil_ref stencil_ref
, stencil_ref_saved
;
115 free_framebuffer_state(struct pipe_framebuffer_state
*fb
);
118 static boolean
delete_blend_state(struct cso_context
*ctx
, void *state
)
120 struct cso_blend
*cso
= (struct cso_blend
*)state
;
122 if (ctx
->blend
== cso
->data
)
125 if (cso
->delete_state
)
126 cso
->delete_state(cso
->context
, cso
->data
);
131 static boolean
delete_depth_stencil_state(struct cso_context
*ctx
, void *state
)
133 struct cso_depth_stencil_alpha
*cso
= (struct cso_depth_stencil_alpha
*)state
;
135 if (ctx
->depth_stencil
== cso
->data
)
138 if (cso
->delete_state
)
139 cso
->delete_state(cso
->context
, cso
->data
);
145 static boolean
delete_sampler_state(struct cso_context
*ctx
, void *state
)
147 struct cso_sampler
*cso
= (struct cso_sampler
*)state
;
148 if (cso
->delete_state
)
149 cso
->delete_state(cso
->context
, cso
->data
);
154 static boolean
delete_rasterizer_state(struct cso_context
*ctx
, void *state
)
156 struct cso_rasterizer
*cso
= (struct cso_rasterizer
*)state
;
158 if (ctx
->rasterizer
== cso
->data
)
160 if (cso
->delete_state
)
161 cso
->delete_state(cso
->context
, cso
->data
);
166 static boolean
delete_fs_state(struct cso_context
*ctx
, void *state
)
168 struct cso_fragment_shader
*cso
= (struct cso_fragment_shader
*)state
;
169 if (ctx
->fragment_shader
== cso
->data
)
171 if (cso
->delete_state
)
172 cso
->delete_state(cso
->context
, cso
->data
);
177 static boolean
delete_vs_state(struct cso_context
*ctx
, void *state
)
179 struct cso_vertex_shader
*cso
= (struct cso_vertex_shader
*)state
;
180 if (ctx
->vertex_shader
== cso
->data
)
182 if (cso
->delete_state
)
183 cso
->delete_state(cso
->context
, cso
->data
);
188 static boolean
delete_vertex_elements(struct cso_context
*ctx
,
191 struct cso_velements
*cso
= (struct cso_velements
*)state
;
193 if (ctx
->velements
== cso
->data
)
196 if (cso
->delete_state
)
197 cso
->delete_state(cso
->context
, cso
->data
);
203 static INLINE boolean
delete_cso(struct cso_context
*ctx
,
204 void *state
, enum cso_cache_type type
)
208 return delete_blend_state(ctx
, state
);
211 return delete_sampler_state(ctx
, state
);
213 case CSO_DEPTH_STENCIL_ALPHA
:
214 return delete_depth_stencil_state(ctx
, state
);
217 return delete_rasterizer_state(ctx
, state
);
219 case CSO_FRAGMENT_SHADER
:
220 return delete_fs_state(ctx
, state
);
222 case CSO_VERTEX_SHADER
:
223 return delete_vs_state(ctx
, state
);
226 return delete_vertex_elements(ctx
, state
);
235 static INLINE
void sanitize_hash(struct cso_hash
*hash
, enum cso_cache_type type
,
236 int max_size
, void *user_data
)
238 struct cso_context
*ctx
= (struct cso_context
*)user_data
;
239 /* if we're approach the maximum size, remove fourth of the entries
240 * otherwise every subsequent call will go through the same */
241 int hash_size
= cso_hash_size(hash
);
242 int max_entries
= (max_size
> hash_size
) ? max_size
: hash_size
;
243 int to_remove
= (max_size
< max_entries
) * max_entries
/4;
244 struct cso_hash_iter iter
= cso_hash_first_node(hash
);
245 if (hash_size
> max_size
)
246 to_remove
+= hash_size
- max_size
;
248 /*remove elements until we're good */
249 /*fixme: currently we pick the nodes to remove at random*/
250 void *cso
= cso_hash_iter_data(iter
);
251 if (delete_cso(ctx
, cso
, type
)) {
252 iter
= cso_hash_erase(hash
, iter
);
255 iter
= cso_hash_iter_next(iter
);
260 struct cso_context
*cso_create_context( struct pipe_context
*pipe
)
262 struct cso_context
*ctx
= CALLOC_STRUCT(cso_context
);
266 ctx
->cache
= cso_cache_create();
267 if (ctx
->cache
== NULL
)
269 cso_cache_set_sanitize_callback(ctx
->cache
,
275 /* Enable for testing: */
276 if (0) cso_set_maximum_cache_size( ctx
->cache
, 4 );
281 cso_destroy_context( ctx
);
287 * Prior to context destruction, this function unbinds all state objects.
289 void cso_release_all( struct cso_context
*ctx
)
294 ctx
->pipe
->bind_blend_state( ctx
->pipe
, NULL
);
295 ctx
->pipe
->bind_rasterizer_state( ctx
->pipe
, NULL
);
296 ctx
->pipe
->bind_fragment_sampler_states( ctx
->pipe
, 0, NULL
);
297 if (ctx
->pipe
->bind_vertex_sampler_states
)
298 ctx
->pipe
->bind_vertex_sampler_states(ctx
->pipe
, 0, NULL
);
299 ctx
->pipe
->bind_depth_stencil_alpha_state( ctx
->pipe
, NULL
);
300 ctx
->pipe
->bind_fs_state( ctx
->pipe
, NULL
);
301 ctx
->pipe
->bind_vs_state( ctx
->pipe
, NULL
);
302 ctx
->pipe
->bind_vertex_elements_state( ctx
->pipe
, NULL
);
305 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
306 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
307 pipe_texture_reference(&ctx
->textures_saved
[i
], NULL
);
308 pipe_sampler_view_reference(&ctx
->fragment_sampler_views
[i
], NULL
);
309 pipe_sampler_view_reference(&ctx
->fragment_sampler_views_saved
[i
], NULL
);
312 for (i
= 0; i
< PIPE_MAX_VERTEX_SAMPLERS
; i
++) {
313 pipe_texture_reference(&ctx
->vertex_textures
[i
], NULL
);
314 pipe_texture_reference(&ctx
->vertex_textures_saved
[i
], NULL
);
315 pipe_sampler_view_reference(&ctx
->vertex_sampler_views
[i
], NULL
);
316 pipe_sampler_view_reference(&ctx
->vertex_sampler_views_saved
[i
], NULL
);
319 free_framebuffer_state(&ctx
->fb
);
320 free_framebuffer_state(&ctx
->fb_saved
);
323 cso_cache_delete( ctx
->cache
);
329 void cso_destroy_context( struct cso_context
*ctx
)
332 /*cso_release_all( ctx );*/
338 /* Those function will either find the state of the given template
339 * in the cache or they will create a new state from the given
340 * template, insert it in the cache and return it.
344 * If the driver returns 0 from the create method then they will assign
345 * the data member of the cso to be the template itself.
348 enum pipe_error
cso_set_blend(struct cso_context
*ctx
,
349 const struct pipe_blend_state
*templ
)
351 unsigned key_size
, hash_key
;
352 struct cso_hash_iter iter
;
355 key_size
= templ
->independent_blend_enable
? sizeof(struct pipe_blend_state
) :
356 (char *)&(templ
->rt
[1]) - (char *)templ
;
357 hash_key
= cso_construct_key((void*)templ
, key_size
);
358 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_BLEND
, (void*)templ
, key_size
);
360 if (cso_hash_iter_is_null(iter
)) {
361 struct cso_blend
*cso
= MALLOC(sizeof(struct cso_blend
));
363 return PIPE_ERROR_OUT_OF_MEMORY
;
365 memcpy(&cso
->state
, templ
, key_size
);
366 cso
->data
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &cso
->state
);
367 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_blend_state
;
368 cso
->context
= ctx
->pipe
;
370 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_BLEND
, cso
);
371 if (cso_hash_iter_is_null(iter
)) {
373 return PIPE_ERROR_OUT_OF_MEMORY
;
379 handle
= ((struct cso_blend
*)cso_hash_iter_data(iter
))->data
;
382 if (ctx
->blend
!= handle
) {
384 ctx
->pipe
->bind_blend_state(ctx
->pipe
, handle
);
389 void cso_save_blend(struct cso_context
*ctx
)
391 assert(!ctx
->blend_saved
);
392 ctx
->blend_saved
= ctx
->blend
;
395 void cso_restore_blend(struct cso_context
*ctx
)
397 if (ctx
->blend
!= ctx
->blend_saved
) {
398 ctx
->blend
= ctx
->blend_saved
;
399 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend_saved
);
401 ctx
->blend_saved
= NULL
;
406 enum pipe_error
cso_single_sampler(struct cso_context
*ctx
,
408 const struct pipe_sampler_state
*templ
)
413 unsigned key_size
= sizeof(struct pipe_sampler_state
);
414 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
415 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
416 hash_key
, CSO_SAMPLER
,
417 (void*)templ
, key_size
);
419 if (cso_hash_iter_is_null(iter
)) {
420 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
422 return PIPE_ERROR_OUT_OF_MEMORY
;
424 memcpy(&cso
->state
, templ
, sizeof(*templ
));
425 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
426 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_sampler_state
;
427 cso
->context
= ctx
->pipe
;
429 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
430 if (cso_hash_iter_is_null(iter
)) {
432 return PIPE_ERROR_OUT_OF_MEMORY
;
438 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
442 ctx
->samplers
[idx
] = handle
;
447 cso_single_vertex_sampler(struct cso_context
*ctx
,
449 const struct pipe_sampler_state
*templ
)
454 unsigned key_size
= sizeof(struct pipe_sampler_state
);
455 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
456 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
457 hash_key
, CSO_SAMPLER
,
458 (void*)templ
, key_size
);
460 if (cso_hash_iter_is_null(iter
)) {
461 struct cso_sampler
*cso
= MALLOC(sizeof(struct cso_sampler
));
463 return PIPE_ERROR_OUT_OF_MEMORY
;
465 memcpy(&cso
->state
, templ
, sizeof(*templ
));
466 cso
->data
= ctx
->pipe
->create_sampler_state(ctx
->pipe
, &cso
->state
);
467 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_sampler_state
;
468 cso
->context
= ctx
->pipe
;
470 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_SAMPLER
, cso
);
471 if (cso_hash_iter_is_null(iter
)) {
473 return PIPE_ERROR_OUT_OF_MEMORY
;
479 handle
= ((struct cso_sampler
*)cso_hash_iter_data(iter
))->data
;
483 ctx
->vertex_samplers
[idx
] = handle
;
487 void cso_single_sampler_done( struct cso_context
*ctx
)
491 /* find highest non-null sampler */
492 for (i
= PIPE_MAX_SAMPLERS
; i
> 0; i
--) {
493 if (ctx
->samplers
[i
- 1] != NULL
)
497 ctx
->nr_samplers
= i
;
499 if (ctx
->hw
.nr_samplers
!= ctx
->nr_samplers
||
500 memcmp(ctx
->hw
.samplers
,
502 ctx
->nr_samplers
* sizeof(void *)) != 0)
504 memcpy(ctx
->hw
.samplers
, ctx
->samplers
, ctx
->nr_samplers
* sizeof(void *));
505 ctx
->hw
.nr_samplers
= ctx
->nr_samplers
;
507 ctx
->pipe
->bind_fragment_sampler_states(ctx
->pipe
, ctx
->nr_samplers
, ctx
->samplers
);
512 cso_single_vertex_sampler_done(struct cso_context
*ctx
)
516 /* find highest non-null sampler */
517 for (i
= PIPE_MAX_VERTEX_SAMPLERS
; i
> 0; i
--) {
518 if (ctx
->vertex_samplers
[i
- 1] != NULL
)
522 ctx
->nr_vertex_samplers
= i
;
524 if (ctx
->hw
.nr_vertex_samplers
!= ctx
->nr_vertex_samplers
||
525 memcmp(ctx
->hw
.vertex_samplers
,
526 ctx
->vertex_samplers
,
527 ctx
->nr_vertex_samplers
* sizeof(void *)) != 0)
529 memcpy(ctx
->hw
.vertex_samplers
,
530 ctx
->vertex_samplers
,
531 ctx
->nr_vertex_samplers
* sizeof(void *));
532 ctx
->hw
.nr_vertex_samplers
= ctx
->nr_vertex_samplers
;
534 ctx
->pipe
->bind_vertex_sampler_states(ctx
->pipe
,
535 ctx
->nr_vertex_samplers
,
536 ctx
->vertex_samplers
);
541 * If the function encouters any errors it will return the
542 * last one. Done to always try to set as many samplers
545 enum pipe_error
cso_set_samplers( struct cso_context
*ctx
,
547 const struct pipe_sampler_state
**templates
)
550 enum pipe_error temp
, error
= PIPE_OK
;
555 for (i
= 0; i
< nr
; i
++) {
556 temp
= cso_single_sampler( ctx
, i
, templates
[i
] );
561 for ( ; i
< ctx
->nr_samplers
; i
++) {
562 temp
= cso_single_sampler( ctx
, i
, NULL
);
567 cso_single_sampler_done( ctx
);
572 void cso_save_samplers(struct cso_context
*ctx
)
574 ctx
->nr_samplers_saved
= ctx
->nr_samplers
;
575 memcpy(ctx
->samplers_saved
, ctx
->samplers
, sizeof(ctx
->samplers
));
578 void cso_restore_samplers(struct cso_context
*ctx
)
580 ctx
->nr_samplers
= ctx
->nr_samplers_saved
;
581 memcpy(ctx
->samplers
, ctx
->samplers_saved
, sizeof(ctx
->samplers
));
582 cso_single_sampler_done( ctx
);
586 * If the function encouters any errors it will return the
587 * last one. Done to always try to set as many samplers
590 enum pipe_error
cso_set_vertex_samplers(struct cso_context
*ctx
,
592 const struct pipe_sampler_state
**templates
)
595 enum pipe_error temp
, error
= PIPE_OK
;
600 for (i
= 0; i
< nr
; i
++) {
601 temp
= cso_single_vertex_sampler( ctx
, i
, templates
[i
] );
606 for ( ; i
< ctx
->nr_samplers
; i
++) {
607 temp
= cso_single_vertex_sampler( ctx
, i
, NULL
);
612 cso_single_vertex_sampler_done( ctx
);
618 cso_save_vertex_samplers(struct cso_context
*ctx
)
620 ctx
->nr_vertex_samplers_saved
= ctx
->nr_vertex_samplers
;
621 memcpy(ctx
->vertex_samplers_saved
, ctx
->vertex_samplers
, sizeof(ctx
->vertex_samplers
));
625 cso_restore_vertex_samplers(struct cso_context
*ctx
)
627 ctx
->nr_vertex_samplers
= ctx
->nr_vertex_samplers_saved
;
628 memcpy(ctx
->vertex_samplers
, ctx
->vertex_samplers_saved
, sizeof(ctx
->vertex_samplers
));
629 cso_single_vertex_sampler_done(ctx
);
633 enum pipe_error
cso_set_sampler_textures( struct cso_context
*ctx
,
635 struct pipe_texture
**textures
)
639 ctx
->nr_textures
= count
;
641 for (i
= 0; i
< count
; i
++) {
642 struct pipe_sampler_view templ
, *view
;
644 u_sampler_view_default_template(&templ
,
646 textures
[i
]->format
);
647 view
= ctx
->pipe
->create_sampler_view(ctx
->pipe
,
651 pipe_texture_reference(&ctx
->textures
[i
], textures
[i
]);
652 pipe_sampler_view_reference(&ctx
->fragment_sampler_views
[i
], view
);
654 for ( ; i
< PIPE_MAX_SAMPLERS
; i
++) {
655 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
656 pipe_sampler_view_reference(&ctx
->fragment_sampler_views
[i
], NULL
);
659 ctx
->pipe
->set_fragment_sampler_views(ctx
->pipe
,
661 ctx
->fragment_sampler_views
);
666 void cso_save_sampler_textures( struct cso_context
*ctx
)
670 ctx
->nr_textures_saved
= ctx
->nr_textures
;
671 for (i
= 0; i
< ctx
->nr_textures
; i
++) {
672 assert(!ctx
->textures_saved
[i
]);
673 assert(!ctx
->fragment_sampler_views_saved
[i
]);
675 pipe_texture_reference(&ctx
->textures_saved
[i
], ctx
->textures
[i
]);
676 pipe_sampler_view_reference(&ctx
->fragment_sampler_views_saved
[i
],
677 ctx
->fragment_sampler_views
[i
]);
681 void cso_restore_sampler_textures( struct cso_context
*ctx
)
685 ctx
->nr_textures
= ctx
->nr_textures_saved
;
687 for (i
= 0; i
< ctx
->nr_textures
; i
++) {
688 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
689 ctx
->textures
[i
] = ctx
->textures_saved
[i
];
690 ctx
->textures_saved
[i
] = NULL
;
692 pipe_sampler_view_reference(&ctx
->fragment_sampler_views
[i
], NULL
);
693 ctx
->fragment_sampler_views
[i
] = ctx
->fragment_sampler_views_saved
[i
];
694 ctx
->fragment_sampler_views_saved
[i
] = NULL
;
696 for ( ; i
< PIPE_MAX_SAMPLERS
; i
++) {
697 pipe_texture_reference(&ctx
->textures
[i
], NULL
);
698 pipe_sampler_view_reference(&ctx
->fragment_sampler_views
[i
], NULL
);
701 ctx
->pipe
->set_fragment_sampler_views(ctx
->pipe
,
703 ctx
->fragment_sampler_views
);
705 ctx
->nr_textures_saved
= 0;
711 cso_set_vertex_sampler_textures(struct cso_context
*ctx
,
713 struct pipe_texture
**textures
)
717 ctx
->nr_vertex_textures
= count
;
719 for (i
= 0; i
< count
; i
++) {
720 struct pipe_sampler_view templ
, *view
;
722 u_sampler_view_default_template(&templ
,
724 textures
[i
]->format
);
725 view
= ctx
->pipe
->create_sampler_view(ctx
->pipe
,
729 pipe_texture_reference(&ctx
->vertex_textures
[i
], textures
[i
]);
730 pipe_sampler_view_reference(&ctx
->vertex_sampler_views
[i
], view
);
732 for ( ; i
< PIPE_MAX_VERTEX_SAMPLERS
; i
++) {
733 pipe_texture_reference(&ctx
->vertex_textures
[i
], NULL
);
734 pipe_sampler_view_reference(&ctx
->vertex_sampler_views
[i
], NULL
);
737 ctx
->pipe
->set_vertex_sampler_views(ctx
->pipe
,
739 ctx
->vertex_sampler_views
);
745 cso_save_vertex_sampler_textures(struct cso_context
*ctx
)
749 ctx
->nr_vertex_textures_saved
= ctx
->nr_vertex_textures
;
750 for (i
= 0; i
< ctx
->nr_vertex_textures
; i
++) {
751 assert(!ctx
->vertex_textures_saved
[i
]);
752 assert(!ctx
->vertex_sampler_views_saved
[i
]);
754 pipe_texture_reference(&ctx
->vertex_textures_saved
[i
], ctx
->vertex_textures
[i
]);
755 pipe_sampler_view_reference(&ctx
->vertex_sampler_views_saved
[i
],
756 ctx
->vertex_sampler_views
[i
]);
761 cso_restore_vertex_sampler_textures(struct cso_context
*ctx
)
765 ctx
->nr_vertex_textures
= ctx
->nr_vertex_textures_saved
;
767 for (i
= 0; i
< ctx
->nr_vertex_textures
; i
++) {
768 pipe_texture_reference(&ctx
->vertex_textures
[i
], NULL
);
769 ctx
->vertex_textures
[i
] = ctx
->vertex_textures_saved
[i
];
770 ctx
->vertex_textures_saved
[i
] = NULL
;
772 pipe_sampler_view_reference(&ctx
->vertex_sampler_views
[i
], NULL
);
773 ctx
->vertex_sampler_views
[i
] = ctx
->vertex_sampler_views_saved
[i
];
774 ctx
->vertex_sampler_views_saved
[i
] = NULL
;
776 for ( ; i
< PIPE_MAX_VERTEX_SAMPLERS
; i
++) {
777 pipe_texture_reference(&ctx
->vertex_textures
[i
], NULL
);
778 pipe_sampler_view_reference(&ctx
->vertex_sampler_views
[i
], NULL
);
781 ctx
->pipe
->set_vertex_sampler_views(ctx
->pipe
,
782 ctx
->nr_vertex_textures
,
783 ctx
->vertex_sampler_views
);
785 ctx
->nr_vertex_textures_saved
= 0;
790 enum pipe_error
cso_set_depth_stencil_alpha(struct cso_context
*ctx
,
791 const struct pipe_depth_stencil_alpha_state
*templ
)
793 unsigned key_size
= sizeof(struct pipe_depth_stencil_alpha_state
);
794 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
795 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
797 CSO_DEPTH_STENCIL_ALPHA
,
798 (void*)templ
, key_size
);
801 if (cso_hash_iter_is_null(iter
)) {
802 struct cso_depth_stencil_alpha
*cso
= MALLOC(sizeof(struct cso_depth_stencil_alpha
));
804 return PIPE_ERROR_OUT_OF_MEMORY
;
806 memcpy(&cso
->state
, templ
, sizeof(*templ
));
807 cso
->data
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &cso
->state
);
808 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_depth_stencil_alpha_state
;
809 cso
->context
= ctx
->pipe
;
811 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_DEPTH_STENCIL_ALPHA
, cso
);
812 if (cso_hash_iter_is_null(iter
)) {
814 return PIPE_ERROR_OUT_OF_MEMORY
;
820 handle
= ((struct cso_depth_stencil_alpha
*)cso_hash_iter_data(iter
))->data
;
823 if (ctx
->depth_stencil
!= handle
) {
824 ctx
->depth_stencil
= handle
;
825 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, handle
);
830 void cso_save_depth_stencil_alpha(struct cso_context
*ctx
)
832 assert(!ctx
->depth_stencil_saved
);
833 ctx
->depth_stencil_saved
= ctx
->depth_stencil
;
836 void cso_restore_depth_stencil_alpha(struct cso_context
*ctx
)
838 if (ctx
->depth_stencil
!= ctx
->depth_stencil_saved
) {
839 ctx
->depth_stencil
= ctx
->depth_stencil_saved
;
840 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->depth_stencil_saved
);
842 ctx
->depth_stencil_saved
= NULL
;
847 enum pipe_error
cso_set_rasterizer(struct cso_context
*ctx
,
848 const struct pipe_rasterizer_state
*templ
)
850 unsigned key_size
= sizeof(struct pipe_rasterizer_state
);
851 unsigned hash_key
= cso_construct_key((void*)templ
, key_size
);
852 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
853 hash_key
, CSO_RASTERIZER
,
854 (void*)templ
, key_size
);
857 if (cso_hash_iter_is_null(iter
)) {
858 struct cso_rasterizer
*cso
= MALLOC(sizeof(struct cso_rasterizer
));
860 return PIPE_ERROR_OUT_OF_MEMORY
;
862 memcpy(&cso
->state
, templ
, sizeof(*templ
));
863 cso
->data
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &cso
->state
);
864 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_rasterizer_state
;
865 cso
->context
= ctx
->pipe
;
867 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_RASTERIZER
, cso
);
868 if (cso_hash_iter_is_null(iter
)) {
870 return PIPE_ERROR_OUT_OF_MEMORY
;
876 handle
= ((struct cso_rasterizer
*)cso_hash_iter_data(iter
))->data
;
879 if (ctx
->rasterizer
!= handle
) {
880 ctx
->rasterizer
= handle
;
881 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, handle
);
886 void cso_save_rasterizer(struct cso_context
*ctx
)
888 assert(!ctx
->rasterizer_saved
);
889 ctx
->rasterizer_saved
= ctx
->rasterizer
;
892 void cso_restore_rasterizer(struct cso_context
*ctx
)
894 if (ctx
->rasterizer
!= ctx
->rasterizer_saved
) {
895 ctx
->rasterizer
= ctx
->rasterizer_saved
;
896 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rasterizer_saved
);
898 ctx
->rasterizer_saved
= NULL
;
903 enum pipe_error
cso_set_fragment_shader_handle(struct cso_context
*ctx
,
906 if (ctx
->fragment_shader
!= handle
) {
907 ctx
->fragment_shader
= handle
;
908 ctx
->pipe
->bind_fs_state(ctx
->pipe
, handle
);
913 void cso_delete_fragment_shader(struct cso_context
*ctx
, void *handle
)
915 if (handle
== ctx
->fragment_shader
) {
916 /* unbind before deleting */
917 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
918 ctx
->fragment_shader
= NULL
;
920 ctx
->pipe
->delete_fs_state(ctx
->pipe
, handle
);
923 /* Not really working:
926 enum pipe_error
cso_set_fragment_shader(struct cso_context
*ctx
,
927 const struct pipe_shader_state
*templ
)
929 const struct tgsi_token
*tokens
= templ
->tokens
;
930 unsigned num_tokens
= tgsi_num_tokens(tokens
);
931 size_t tokens_size
= num_tokens
*sizeof(struct tgsi_token
);
932 unsigned hash_key
= cso_construct_key((void*)tokens
, tokens_size
);
933 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
937 sizeof(*templ
)); /* XXX correct? tokens_size? */
940 if (cso_hash_iter_is_null(iter
)) {
941 struct cso_fragment_shader
*cso
= MALLOC(sizeof(struct cso_fragment_shader
) + tokens_size
);
942 struct tgsi_token
*cso_tokens
= (struct tgsi_token
*)((char *)cso
+ sizeof(*cso
));
945 return PIPE_ERROR_OUT_OF_MEMORY
;
947 memcpy(cso_tokens
, tokens
, tokens_size
);
948 cso
->state
.tokens
= cso_tokens
;
949 cso
->data
= ctx
->pipe
->create_fs_state(ctx
->pipe
, &cso
->state
);
950 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_fs_state
;
951 cso
->context
= ctx
->pipe
;
953 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_FRAGMENT_SHADER
, cso
);
954 if (cso_hash_iter_is_null(iter
)) {
956 return PIPE_ERROR_OUT_OF_MEMORY
;
962 handle
= ((struct cso_fragment_shader
*)cso_hash_iter_data(iter
))->data
;
965 return cso_set_fragment_shader_handle( ctx
, handle
);
969 void cso_save_fragment_shader(struct cso_context
*ctx
)
971 assert(!ctx
->fragment_shader_saved
);
972 ctx
->fragment_shader_saved
= ctx
->fragment_shader
;
975 void cso_restore_fragment_shader(struct cso_context
*ctx
)
977 if (ctx
->fragment_shader_saved
!= ctx
->fragment_shader
) {
978 ctx
->pipe
->bind_fs_state(ctx
->pipe
, ctx
->fragment_shader_saved
);
979 ctx
->fragment_shader
= ctx
->fragment_shader_saved
;
981 ctx
->fragment_shader_saved
= NULL
;
985 enum pipe_error
cso_set_vertex_shader_handle(struct cso_context
*ctx
,
988 if (ctx
->vertex_shader
!= handle
) {
989 ctx
->vertex_shader
= handle
;
990 ctx
->pipe
->bind_vs_state(ctx
->pipe
, handle
);
995 void cso_delete_vertex_shader(struct cso_context
*ctx
, void *handle
)
997 if (handle
== ctx
->vertex_shader
) {
998 /* unbind before deleting */
999 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
1000 ctx
->vertex_shader
= NULL
;
1002 ctx
->pipe
->delete_vs_state(ctx
->pipe
, handle
);
1006 /* Not really working:
1009 enum pipe_error
cso_set_vertex_shader(struct cso_context
*ctx
,
1010 const struct pipe_shader_state
*templ
)
1012 unsigned hash_key
= cso_construct_key((void*)templ
,
1013 sizeof(struct pipe_shader_state
));
1014 struct cso_hash_iter iter
= cso_find_state_template(ctx
->cache
,
1015 hash_key
, CSO_VERTEX_SHADER
,
1018 void *handle
= NULL
;
1020 if (cso_hash_iter_is_null(iter
)) {
1021 struct cso_vertex_shader
*cso
= MALLOC(sizeof(struct cso_vertex_shader
));
1024 return PIPE_ERROR_OUT_OF_MEMORY
;
1026 memcpy(cso
->state
, templ
, sizeof(*templ
));
1027 cso
->data
= ctx
->pipe
->create_vs_state(ctx
->pipe
, &cso
->state
);
1028 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_vs_state
;
1029 cso
->context
= ctx
->pipe
;
1031 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VERTEX_SHADER
, cso
);
1032 if (cso_hash_iter_is_null(iter
)) {
1034 return PIPE_ERROR_OUT_OF_MEMORY
;
1040 handle
= ((struct cso_vertex_shader
*)cso_hash_iter_data(iter
))->data
;
1043 return cso_set_vertex_shader_handle( ctx
, handle
);
1049 void cso_save_vertex_shader(struct cso_context
*ctx
)
1051 assert(!ctx
->vertex_shader_saved
);
1052 ctx
->vertex_shader_saved
= ctx
->vertex_shader
;
1055 void cso_restore_vertex_shader(struct cso_context
*ctx
)
1057 if (ctx
->vertex_shader_saved
!= ctx
->vertex_shader
) {
1058 ctx
->pipe
->bind_vs_state(ctx
->pipe
, ctx
->vertex_shader_saved
);
1059 ctx
->vertex_shader
= ctx
->vertex_shader_saved
;
1061 ctx
->vertex_shader_saved
= NULL
;
1066 * Copy framebuffer state from src to dst with refcounting of surfaces.
1069 copy_framebuffer_state(struct pipe_framebuffer_state
*dst
,
1070 const struct pipe_framebuffer_state
*src
)
1074 dst
->width
= src
->width
;
1075 dst
->height
= src
->height
;
1076 dst
->nr_cbufs
= src
->nr_cbufs
;
1077 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
1078 pipe_surface_reference(&dst
->cbufs
[i
], src
->cbufs
[i
]);
1080 pipe_surface_reference(&dst
->zsbuf
, src
->zsbuf
);
1085 free_framebuffer_state(struct pipe_framebuffer_state
*fb
)
1089 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
1090 pipe_surface_reference(&fb
->cbufs
[i
], NULL
);
1092 pipe_surface_reference(&fb
->zsbuf
, NULL
);
1096 enum pipe_error
cso_set_framebuffer(struct cso_context
*ctx
,
1097 const struct pipe_framebuffer_state
*fb
)
1099 if (memcmp(&ctx
->fb
, fb
, sizeof(*fb
)) != 0) {
1100 copy_framebuffer_state(&ctx
->fb
, fb
);
1101 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, fb
);
1106 void cso_save_framebuffer(struct cso_context
*ctx
)
1108 copy_framebuffer_state(&ctx
->fb_saved
, &ctx
->fb
);
1111 void cso_restore_framebuffer(struct cso_context
*ctx
)
1113 if (memcmp(&ctx
->fb
, &ctx
->fb_saved
, sizeof(ctx
->fb
))) {
1114 copy_framebuffer_state(&ctx
->fb
, &ctx
->fb_saved
);
1115 ctx
->pipe
->set_framebuffer_state(ctx
->pipe
, &ctx
->fb
);
1116 free_framebuffer_state(&ctx
->fb_saved
);
1121 enum pipe_error
cso_set_viewport(struct cso_context
*ctx
,
1122 const struct pipe_viewport_state
*vp
)
1124 if (memcmp(&ctx
->vp
, vp
, sizeof(*vp
))) {
1126 ctx
->pipe
->set_viewport_state(ctx
->pipe
, vp
);
1131 void cso_save_viewport(struct cso_context
*ctx
)
1133 ctx
->vp_saved
= ctx
->vp
;
1137 void cso_restore_viewport(struct cso_context
*ctx
)
1139 if (memcmp(&ctx
->vp
, &ctx
->vp_saved
, sizeof(ctx
->vp
))) {
1140 ctx
->vp
= ctx
->vp_saved
;
1141 ctx
->pipe
->set_viewport_state(ctx
->pipe
, &ctx
->vp
);
1146 enum pipe_error
cso_set_blend_color(struct cso_context
*ctx
,
1147 const struct pipe_blend_color
*bc
)
1149 if (memcmp(&ctx
->blend_color
, bc
, sizeof(ctx
->blend_color
))) {
1150 ctx
->blend_color
= *bc
;
1151 ctx
->pipe
->set_blend_color(ctx
->pipe
, bc
);
1156 enum pipe_error
cso_set_stencil_ref(struct cso_context
*ctx
,
1157 const struct pipe_stencil_ref
*sr
)
1159 if (memcmp(&ctx
->stencil_ref
, sr
, sizeof(ctx
->stencil_ref
))) {
1160 ctx
->stencil_ref
= *sr
;
1161 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, sr
);
1166 void cso_save_stencil_ref(struct cso_context
*ctx
)
1168 ctx
->stencil_ref_saved
= ctx
->stencil_ref
;
1172 void cso_restore_stencil_ref(struct cso_context
*ctx
)
1174 if (memcmp(&ctx
->stencil_ref
, &ctx
->stencil_ref_saved
, sizeof(ctx
->stencil_ref
))) {
1175 ctx
->stencil_ref
= ctx
->stencil_ref_saved
;
1176 ctx
->pipe
->set_stencil_ref(ctx
->pipe
, &ctx
->stencil_ref
);
1180 enum pipe_error
cso_set_geometry_shader_handle(struct cso_context
*ctx
,
1183 if (ctx
->geometry_shader
!= handle
) {
1184 ctx
->geometry_shader
= handle
;
1185 ctx
->pipe
->bind_gs_state(ctx
->pipe
, handle
);
1190 void cso_delete_geometry_shader(struct cso_context
*ctx
, void *handle
)
1192 if (handle
== ctx
->geometry_shader
) {
1193 /* unbind before deleting */
1194 ctx
->pipe
->bind_gs_state(ctx
->pipe
, NULL
);
1195 ctx
->geometry_shader
= NULL
;
1197 ctx
->pipe
->delete_gs_state(ctx
->pipe
, handle
);
1200 void cso_save_geometry_shader(struct cso_context
*ctx
)
1202 assert(!ctx
->geometry_shader_saved
);
1203 ctx
->geometry_shader_saved
= ctx
->geometry_shader
;
1206 void cso_restore_geometry_shader(struct cso_context
*ctx
)
1208 if (ctx
->geometry_shader_saved
!= ctx
->geometry_shader
) {
1209 ctx
->pipe
->bind_gs_state(ctx
->pipe
, ctx
->geometry_shader_saved
);
1210 ctx
->geometry_shader
= ctx
->geometry_shader_saved
;
1212 ctx
->geometry_shader_saved
= NULL
;
1218 clip_state_cpy(struct pipe_clip_state
*dst
,
1219 const struct pipe_clip_state
*src
)
1223 memcpy(dst
->ucp
, src
->ucp
, src
->nr
* sizeof(src
->ucp
[0]));
1228 clip_state_cmp(const struct pipe_clip_state
*a
,
1229 const struct pipe_clip_state
*b
)
1231 if (a
->nr
!= b
->nr
) {
1235 return memcmp(a
->ucp
, b
->ucp
, a
->nr
* sizeof(a
->ucp
[0]));
1241 cso_set_clip(struct cso_context
*ctx
,
1242 const struct pipe_clip_state
*clip
)
1244 if (clip_state_cmp(&ctx
->clip
, clip
)) {
1245 clip_state_cpy(&ctx
->clip
, clip
);
1246 ctx
->pipe
->set_clip_state(ctx
->pipe
, clip
);
1251 cso_save_clip(struct cso_context
*ctx
)
1253 clip_state_cpy(&ctx
->clip_saved
, &ctx
->clip
);
1257 cso_restore_clip(struct cso_context
*ctx
)
1259 if (clip_state_cmp(&ctx
->clip
, &ctx
->clip_saved
)) {
1260 clip_state_cpy(&ctx
->clip
, &ctx
->clip_saved
);
1261 ctx
->pipe
->set_clip_state(ctx
->pipe
, &ctx
->clip_saved
);
1265 enum pipe_error
cso_set_vertex_elements(struct cso_context
*ctx
,
1267 const struct pipe_vertex_element
*states
)
1269 unsigned key_size
, hash_key
;
1270 struct cso_hash_iter iter
;
1272 struct cso_velems_state velems_state
;
1274 /* need to include the count into the stored state data too.
1275 Otherwise first few count pipe_vertex_elements could be identical even if count
1276 is different, and there's no guarantee the hash would be different in that
1278 key_size
= sizeof(struct pipe_vertex_element
) * count
+ sizeof(unsigned);
1279 velems_state
.count
= count
;
1280 memcpy(velems_state
.velems
, states
, sizeof(struct pipe_vertex_element
) * count
);
1281 hash_key
= cso_construct_key((void*)&velems_state
, key_size
);
1282 iter
= cso_find_state_template(ctx
->cache
, hash_key
, CSO_VELEMENTS
, (void*)&velems_state
, key_size
);
1284 if (cso_hash_iter_is_null(iter
)) {
1285 struct cso_velements
*cso
= MALLOC(sizeof(struct cso_velements
));
1287 return PIPE_ERROR_OUT_OF_MEMORY
;
1289 memcpy(&cso
->state
, &velems_state
, key_size
);
1290 cso
->data
= ctx
->pipe
->create_vertex_elements_state(ctx
->pipe
, count
, &cso
->state
.velems
[0]);
1291 cso
->delete_state
= (cso_state_callback
)ctx
->pipe
->delete_vertex_elements_state
;
1292 cso
->context
= ctx
->pipe
;
1294 iter
= cso_insert_state(ctx
->cache
, hash_key
, CSO_VELEMENTS
, cso
);
1295 if (cso_hash_iter_is_null(iter
)) {
1297 return PIPE_ERROR_OUT_OF_MEMORY
;
1303 handle
= ((struct cso_velements
*)cso_hash_iter_data(iter
))->data
;
1306 if (ctx
->velements
!= handle
) {
1307 ctx
->velements
= handle
;
1308 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, handle
);
1313 void cso_save_vertex_elements(struct cso_context
*ctx
)
1315 assert(!ctx
->velements_saved
);
1316 ctx
->velements_saved
= ctx
->velements
;
1319 void cso_restore_vertex_elements(struct cso_context
*ctx
)
1321 if (ctx
->velements
!= ctx
->velements_saved
) {
1322 ctx
->velements
= ctx
->velements_saved
;
1323 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->velements_saved
);
1325 ctx
->velements_saved
= NULL
;
1328 /* fragment sampler view state */
1331 cso_set_fragment_sampler_views(struct cso_context
*cso
,
1333 struct pipe_sampler_view
**views
)
1337 for (i
= 0; i
< count
; i
++) {
1338 pipe_sampler_view_reference(&cso
->fragment_sampler_views
[i
], views
[i
]);
1340 for (; i
< cso
->nr_fragment_sampler_views
; i
++) {
1341 pipe_sampler_view_reference(&cso
->fragment_sampler_views
[i
], NULL
);
1344 cso
->pipe
->set_fragment_sampler_views(cso
->pipe
,
1345 MAX2(count
, cso
->nr_fragment_sampler_views
),
1346 cso
->fragment_sampler_views
);
1348 cso
->nr_fragment_sampler_views
= count
;
1352 cso_save_fragment_sampler_views(struct cso_context
*cso
)
1356 cso
->nr_fragment_sampler_views_saved
= cso
->nr_fragment_sampler_views
;
1358 for (i
= 0; i
< cso
->nr_fragment_sampler_views
; i
++) {
1359 assert(!cso
->fragment_sampler_views_saved
[i
]);
1361 pipe_sampler_view_reference(&cso
->fragment_sampler_views_saved
[i
],
1362 cso
->fragment_sampler_views
[i
]);
1367 cso_restore_fragment_sampler_views(struct cso_context
*cso
)
1371 for (i
= 0; i
< cso
->nr_fragment_sampler_views_saved
; i
++) {
1372 pipe_sampler_view_reference(&cso
->fragment_sampler_views
[i
], cso
->fragment_sampler_views_saved
[i
]);
1373 pipe_sampler_view_reference(&cso
->fragment_sampler_views_saved
[i
], NULL
);
1375 for (; i
< cso
->nr_fragment_sampler_views
; i
++) {
1376 pipe_sampler_view_reference(&cso
->fragment_sampler_views
[i
], NULL
);
1379 cso
->pipe
->set_fragment_sampler_views(cso
->pipe
,
1380 MAX2(cso
->nr_fragment_sampler_views
, cso
->nr_fragment_sampler_views_saved
),
1381 cso
->fragment_sampler_views
);
1383 cso
->nr_fragment_sampler_views
= cso
->nr_fragment_sampler_views_saved
;
1384 cso
->nr_fragment_sampler_views_saved
= 0;
1388 /* vertex sampler view state */
1391 cso_set_vertex_sampler_views(struct cso_context
*cso
,
1393 struct pipe_sampler_view
**views
)
1397 for (i
= 0; i
< count
; i
++) {
1398 pipe_sampler_view_reference(&cso
->vertex_sampler_views
[i
], views
[i
]);
1400 for (; i
< cso
->nr_vertex_sampler_views
; i
++) {
1401 pipe_sampler_view_reference(&cso
->vertex_sampler_views
[i
], NULL
);
1404 cso
->pipe
->set_vertex_sampler_views(cso
->pipe
,
1405 MAX2(count
, cso
->nr_vertex_sampler_views
),
1406 cso
->vertex_sampler_views
);
1408 cso
->nr_vertex_sampler_views
= count
;
1412 cso_save_vertex_sampler_views(struct cso_context
*cso
)
1416 cso
->nr_vertex_sampler_views_saved
= cso
->nr_vertex_sampler_views
;
1418 for (i
= 0; i
< cso
->nr_vertex_sampler_views
; i
++) {
1419 assert(!cso
->vertex_sampler_views_saved
[i
]);
1421 pipe_sampler_view_reference(&cso
->vertex_sampler_views_saved
[i
],
1422 cso
->vertex_sampler_views
[i
]);
1427 cso_restore_vertex_sampler_views(struct cso_context
*cso
)
1431 for (i
= 0; i
< cso
->nr_vertex_sampler_views_saved
; i
++) {
1432 pipe_sampler_view_reference(&cso
->vertex_sampler_views
[i
], cso
->vertex_sampler_views_saved
[i
]);
1433 pipe_sampler_view_reference(&cso
->vertex_sampler_views_saved
[i
], NULL
);
1435 for (; i
< cso
->nr_vertex_sampler_views
; i
++) {
1436 pipe_sampler_view_reference(&cso
->vertex_sampler_views
[i
], NULL
);
1439 cso
->pipe
->set_vertex_sampler_views(cso
->pipe
,
1440 MAX2(cso
->nr_vertex_sampler_views
, cso
->nr_vertex_sampler_views_saved
),
1441 cso
->vertex_sampler_views
);
1443 cso
->nr_vertex_sampler_views
= cso
->nr_vertex_sampler_views_saved
;
1444 cso
->nr_vertex_sampler_views_saved
= 0;