1 /**************************************************************************
3 * Copyright 2010 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 **************************************************************************/
29 #include "pipe/p_context.h"
30 #include "util/u_memory.h"
31 #include "util/u_inlines.h"
32 #include "util/u_simple_list.h"
34 #include "rbug/rbug_context.h"
36 #include "rbug_context.h"
37 #include "rbug_objects.h"
41 rbug_destroy(struct pipe_context
*_pipe
)
43 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
44 struct pipe_context
*pipe
= rb_pipe
->pipe
;
46 remove_from_list(&rb_pipe
->list
);
47 pipe_mutex_lock(rb_pipe
->call_mutex
);
50 pipe_mutex_unlock(rb_pipe
->call_mutex
);
56 rbug_draw_block_locked(struct rbug_context
*rb_pipe
, int flag
)
59 if (rb_pipe
->draw_blocker
& flag
) {
60 rb_pipe
->draw_blocked
|= flag
;
61 } else if ((rb_pipe
->draw_rule
.blocker
& flag
) &&
62 (rb_pipe
->draw_blocker
& RBUG_BLOCK_RULE
)) {
64 boolean block
= FALSE
;
67 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__
,
68 (void *) rb_pipe
->draw_rule
.shader
[PIPE_SHADER_FRAGMENT
],
69 (void *) rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
],
70 (void *) rb_pipe
->draw_rule
.shader
[PIPE_SHADER_VERTEX
],
71 (void *) rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
],
72 (void *) rb_pipe
->draw_rule
.surf
, 0,
73 (void *) rb_pipe
->draw_rule
.texture
, 0);
74 for (sh
= 0; sh
< PIPE_SHADER_TYPES
; sh
++) {
75 if (rb_pipe
->draw_rule
.shader
[sh
] &&
76 rb_pipe
->draw_rule
.shader
[sh
] == rb_pipe
->curr
.shader
[sh
])
80 if (rb_pipe
->draw_rule
.surf
&&
81 rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.zsbuf
)
83 if (rb_pipe
->draw_rule
.surf
)
84 for (k
= 0; k
< rb_pipe
->curr
.nr_cbufs
; k
++)
85 if (rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.cbufs
[k
])
87 if (rb_pipe
->draw_rule
.texture
) {
88 for (sh
= 0; sh
< Elements(rb_pipe
->curr
.num_views
); sh
++) {
89 for (k
= 0; k
< rb_pipe
->curr
.num_views
[sh
]; k
++) {
90 if (rb_pipe
->draw_rule
.texture
== rb_pipe
->curr
.texs
[sh
][k
]) {
92 sh
= PIPE_SHADER_TYPES
; /* to break out of both loops */
100 rb_pipe
->draw_blocked
|= (flag
| RBUG_BLOCK_RULE
);
103 if (rb_pipe
->draw_blocked
)
104 rbug_notify_draw_blocked(rb_pipe
);
106 /* wait for rbug to clear the blocked flag */
107 while (rb_pipe
->draw_blocked
& flag
) {
108 rb_pipe
->draw_blocked
|= flag
;
109 pipe_condvar_wait(rb_pipe
->draw_cond
, rb_pipe
->draw_mutex
);
115 rbug_draw_vbo(struct pipe_context
*_pipe
, const struct pipe_draw_info
*info
)
117 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
118 struct pipe_context
*pipe
= rb_pipe
->pipe
;
120 pipe_mutex_lock(rb_pipe
->draw_mutex
);
121 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_BEFORE
);
123 pipe_mutex_lock(rb_pipe
->call_mutex
);
124 /* XXX loop over PIPE_SHADER_x here */
125 if (!(rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
] && rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
]->disabled
) &&
126 !(rb_pipe
->curr
.shader
[PIPE_SHADER_GEOMETRY
] && rb_pipe
->curr
.shader
[PIPE_SHADER_GEOMETRY
]->disabled
) &&
127 !(rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
] && rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
]->disabled
))
128 pipe
->draw_vbo(pipe
, info
);
129 pipe_mutex_unlock(rb_pipe
->call_mutex
);
131 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
132 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
135 static struct pipe_query
*
136 rbug_create_query(struct pipe_context
*_pipe
,
139 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
140 struct pipe_context
*pipe
= rb_pipe
->pipe
;
142 pipe_mutex_lock(rb_pipe
->call_mutex
);
143 return pipe
->create_query(pipe
,
145 pipe_mutex_unlock(rb_pipe
->call_mutex
);
149 rbug_destroy_query(struct pipe_context
*_pipe
,
150 struct pipe_query
*query
)
152 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
153 struct pipe_context
*pipe
= rb_pipe
->pipe
;
155 pipe_mutex_lock(rb_pipe
->call_mutex
);
156 pipe
->destroy_query(pipe
,
158 pipe_mutex_unlock(rb_pipe
->call_mutex
);
162 rbug_begin_query(struct pipe_context
*_pipe
,
163 struct pipe_query
*query
)
165 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
166 struct pipe_context
*pipe
= rb_pipe
->pipe
;
168 pipe_mutex_lock(rb_pipe
->call_mutex
);
169 pipe
->begin_query(pipe
,
171 pipe_mutex_unlock(rb_pipe
->call_mutex
);
175 rbug_end_query(struct pipe_context
*_pipe
,
176 struct pipe_query
*query
)
178 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
179 struct pipe_context
*pipe
= rb_pipe
->pipe
;
181 pipe_mutex_lock(rb_pipe
->call_mutex
);
182 pipe
->end_query(pipe
,
184 pipe_mutex_unlock(rb_pipe
->call_mutex
);
188 rbug_get_query_result(struct pipe_context
*_pipe
,
189 struct pipe_query
*query
,
191 union pipe_query_result
*result
)
193 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
194 struct pipe_context
*pipe
= rb_pipe
->pipe
;
197 pipe_mutex_lock(rb_pipe
->call_mutex
);
198 ret
= pipe
->get_query_result(pipe
,
202 pipe_mutex_unlock(rb_pipe
->call_mutex
);
208 rbug_create_blend_state(struct pipe_context
*_pipe
,
209 const struct pipe_blend_state
*blend
)
211 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
212 struct pipe_context
*pipe
= rb_pipe
->pipe
;
215 pipe_mutex_lock(rb_pipe
->call_mutex
);
216 ret
= pipe
->create_blend_state(pipe
,
218 pipe_mutex_unlock(rb_pipe
->call_mutex
);
224 rbug_bind_blend_state(struct pipe_context
*_pipe
,
227 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
228 struct pipe_context
*pipe
= rb_pipe
->pipe
;
230 pipe_mutex_lock(rb_pipe
->call_mutex
);
231 pipe
->bind_blend_state(pipe
,
233 pipe_mutex_unlock(rb_pipe
->call_mutex
);
237 rbug_delete_blend_state(struct pipe_context
*_pipe
,
240 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
241 struct pipe_context
*pipe
= rb_pipe
->pipe
;
243 pipe_mutex_lock(rb_pipe
->call_mutex
);
244 pipe
->delete_blend_state(pipe
,
246 pipe_mutex_unlock(rb_pipe
->call_mutex
);
250 rbug_create_sampler_state(struct pipe_context
*_pipe
,
251 const struct pipe_sampler_state
*sampler
)
253 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
254 struct pipe_context
*pipe
= rb_pipe
->pipe
;
257 pipe_mutex_lock(rb_pipe
->call_mutex
);
258 ret
= pipe
->create_sampler_state(pipe
,
260 pipe_mutex_unlock(rb_pipe
->call_mutex
);
266 rbug_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
267 unsigned num_samplers
,
270 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
271 struct pipe_context
*pipe
= rb_pipe
->pipe
;
273 pipe_mutex_lock(rb_pipe
->call_mutex
);
274 pipe
->bind_fragment_sampler_states(pipe
,
277 pipe_mutex_unlock(rb_pipe
->call_mutex
);
281 rbug_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
282 unsigned num_samplers
,
285 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
286 struct pipe_context
*pipe
= rb_pipe
->pipe
;
288 pipe_mutex_lock(rb_pipe
->call_mutex
);
289 pipe
->bind_vertex_sampler_states(pipe
,
292 pipe_mutex_unlock(rb_pipe
->call_mutex
);
296 rbug_delete_sampler_state(struct pipe_context
*_pipe
,
299 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
300 struct pipe_context
*pipe
= rb_pipe
->pipe
;
302 pipe_mutex_lock(rb_pipe
->call_mutex
);
303 pipe
->delete_sampler_state(pipe
,
305 pipe_mutex_unlock(rb_pipe
->call_mutex
);
309 rbug_create_rasterizer_state(struct pipe_context
*_pipe
,
310 const struct pipe_rasterizer_state
*rasterizer
)
312 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
313 struct pipe_context
*pipe
= rb_pipe
->pipe
;
316 pipe_mutex_lock(rb_pipe
->call_mutex
);
317 ret
= pipe
->create_rasterizer_state(pipe
,
319 pipe_mutex_unlock(rb_pipe
->call_mutex
);
325 rbug_bind_rasterizer_state(struct pipe_context
*_pipe
,
328 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
329 struct pipe_context
*pipe
= rb_pipe
->pipe
;
331 pipe_mutex_lock(rb_pipe
->call_mutex
);
332 pipe
->bind_rasterizer_state(pipe
,
334 pipe_mutex_unlock(rb_pipe
->call_mutex
);
338 rbug_delete_rasterizer_state(struct pipe_context
*_pipe
,
341 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
342 struct pipe_context
*pipe
= rb_pipe
->pipe
;
344 pipe_mutex_lock(rb_pipe
->call_mutex
);
345 pipe
->delete_rasterizer_state(pipe
,
347 pipe_mutex_unlock(rb_pipe
->call_mutex
);
351 rbug_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
352 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
354 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
355 struct pipe_context
*pipe
= rb_pipe
->pipe
;
358 pipe_mutex_lock(rb_pipe
->call_mutex
);
359 ret
= pipe
->create_depth_stencil_alpha_state(pipe
,
360 depth_stencil_alpha
);
361 pipe_mutex_unlock(rb_pipe
->call_mutex
);
367 rbug_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
368 void *depth_stencil_alpha
)
370 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
371 struct pipe_context
*pipe
= rb_pipe
->pipe
;
373 pipe_mutex_lock(rb_pipe
->call_mutex
);
374 pipe
->bind_depth_stencil_alpha_state(pipe
,
375 depth_stencil_alpha
);
376 pipe_mutex_unlock(rb_pipe
->call_mutex
);
380 rbug_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
381 void *depth_stencil_alpha
)
383 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
384 struct pipe_context
*pipe
= rb_pipe
->pipe
;
386 pipe_mutex_lock(rb_pipe
->call_mutex
);
387 pipe
->delete_depth_stencil_alpha_state(pipe
,
388 depth_stencil_alpha
);
389 pipe_mutex_unlock(rb_pipe
->call_mutex
);
393 rbug_create_fs_state(struct pipe_context
*_pipe
,
394 const struct pipe_shader_state
*state
)
396 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
397 struct pipe_context
*pipe
= rb_pipe
->pipe
;
400 pipe_mutex_lock(rb_pipe
->call_mutex
);
401 result
= pipe
->create_fs_state(pipe
, state
);
402 pipe_mutex_unlock(rb_pipe
->call_mutex
);
407 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_FRAGMENT
);
411 rbug_bind_fs_state(struct pipe_context
*_pipe
,
414 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
415 struct pipe_context
*pipe
= rb_pipe
->pipe
;
418 pipe_mutex_lock(rb_pipe
->call_mutex
);
420 fs
= rbug_shader_unwrap(_fs
);
421 rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
] = rbug_shader(_fs
);
422 pipe
->bind_fs_state(pipe
,
425 pipe_mutex_unlock(rb_pipe
->call_mutex
);
429 rbug_delete_fs_state(struct pipe_context
*_pipe
,
432 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
433 struct rbug_shader
*rb_shader
= rbug_shader(_fs
);
435 pipe_mutex_lock(rb_pipe
->call_mutex
);
436 rbug_shader_destroy(rb_pipe
, rb_shader
);
437 pipe_mutex_unlock(rb_pipe
->call_mutex
);
441 rbug_create_vs_state(struct pipe_context
*_pipe
,
442 const struct pipe_shader_state
*state
)
444 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
445 struct pipe_context
*pipe
= rb_pipe
->pipe
;
448 pipe_mutex_lock(rb_pipe
->call_mutex
);
449 result
= pipe
->create_vs_state(pipe
, state
);
450 pipe_mutex_unlock(rb_pipe
->call_mutex
);
455 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_VERTEX
);
459 rbug_bind_vs_state(struct pipe_context
*_pipe
,
462 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
463 struct pipe_context
*pipe
= rb_pipe
->pipe
;
466 pipe_mutex_lock(rb_pipe
->call_mutex
);
468 vs
= rbug_shader_unwrap(_vs
);
469 rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
] = rbug_shader(_vs
);
470 pipe
->bind_vs_state(pipe
,
473 pipe_mutex_unlock(rb_pipe
->call_mutex
);
477 rbug_delete_vs_state(struct pipe_context
*_pipe
,
480 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
481 struct rbug_shader
*rb_shader
= rbug_shader(_vs
);
483 pipe_mutex_unlock(rb_pipe
->call_mutex
);
484 rbug_shader_destroy(rb_pipe
, rb_shader
);
485 pipe_mutex_unlock(rb_pipe
->call_mutex
);
489 rbug_create_gs_state(struct pipe_context
*_pipe
,
490 const struct pipe_shader_state
*state
)
492 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
493 struct pipe_context
*pipe
= rb_pipe
->pipe
;
496 pipe_mutex_lock(rb_pipe
->call_mutex
);
497 result
= pipe
->create_gs_state(pipe
, state
);
498 pipe_mutex_unlock(rb_pipe
->call_mutex
);
503 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_GEOM
);
507 rbug_bind_gs_state(struct pipe_context
*_pipe
,
510 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
511 struct pipe_context
*pipe
= rb_pipe
->pipe
;
514 pipe_mutex_lock(rb_pipe
->call_mutex
);
516 gs
= rbug_shader_unwrap(_gs
);
517 rb_pipe
->curr
.shader
[PIPE_SHADER_GEOMETRY
] = rbug_shader(_gs
);
518 pipe
->bind_gs_state(pipe
,
521 pipe_mutex_unlock(rb_pipe
->call_mutex
);
525 rbug_delete_gs_state(struct pipe_context
*_pipe
,
528 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
529 struct rbug_shader
*rb_shader
= rbug_shader(_gs
);
531 pipe_mutex_lock(rb_pipe
->call_mutex
);
532 rbug_shader_destroy(rb_pipe
, rb_shader
);
533 pipe_mutex_unlock(rb_pipe
->call_mutex
);
537 rbug_create_vertex_elements_state(struct pipe_context
*_pipe
,
538 unsigned num_elements
,
539 const struct pipe_vertex_element
*vertex_elements
)
541 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
542 struct pipe_context
*pipe
= rb_pipe
->pipe
;
545 pipe_mutex_lock(rb_pipe
->call_mutex
);
546 ret
= pipe
->create_vertex_elements_state(pipe
,
549 pipe_mutex_unlock(rb_pipe
->call_mutex
);
555 rbug_bind_vertex_elements_state(struct pipe_context
*_pipe
,
558 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
559 struct pipe_context
*pipe
= rb_pipe
->pipe
;
561 pipe_mutex_lock(rb_pipe
->call_mutex
);
562 pipe
->bind_vertex_elements_state(pipe
,
564 pipe_mutex_unlock(rb_pipe
->call_mutex
);
568 rbug_delete_vertex_elements_state(struct pipe_context
*_pipe
,
571 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
572 struct pipe_context
*pipe
= rb_pipe
->pipe
;
574 pipe_mutex_lock(rb_pipe
->call_mutex
);
575 pipe
->delete_vertex_elements_state(pipe
,
577 pipe_mutex_unlock(rb_pipe
->call_mutex
);
581 rbug_set_blend_color(struct pipe_context
*_pipe
,
582 const struct pipe_blend_color
*blend_color
)
584 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
585 struct pipe_context
*pipe
= rb_pipe
->pipe
;
587 pipe_mutex_lock(rb_pipe
->call_mutex
);
588 pipe
->set_blend_color(pipe
,
590 pipe_mutex_unlock(rb_pipe
->call_mutex
);
594 rbug_set_stencil_ref(struct pipe_context
*_pipe
,
595 const struct pipe_stencil_ref
*stencil_ref
)
597 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
598 struct pipe_context
*pipe
= rb_pipe
->pipe
;
600 pipe_mutex_lock(rb_pipe
->call_mutex
);
601 pipe
->set_stencil_ref(pipe
,
603 pipe_mutex_unlock(rb_pipe
->call_mutex
);
607 rbug_set_clip_state(struct pipe_context
*_pipe
,
608 const struct pipe_clip_state
*clip
)
610 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
611 struct pipe_context
*pipe
= rb_pipe
->pipe
;
613 pipe_mutex_lock(rb_pipe
->call_mutex
);
614 pipe
->set_clip_state(pipe
,
616 pipe_mutex_unlock(rb_pipe
->call_mutex
);
620 rbug_set_constant_buffer(struct pipe_context
*_pipe
,
623 struct pipe_constant_buffer
*_cb
)
625 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
626 struct pipe_context
*pipe
= rb_pipe
->pipe
;
627 struct pipe_constant_buffer cb
;
629 /* XXX hmm? unwrap the input state */
632 cb
.buffer
= rbug_resource_unwrap(_cb
->buffer
);
635 pipe_mutex_lock(rb_pipe
->call_mutex
);
636 pipe
->set_constant_buffer(pipe
,
640 pipe_mutex_unlock(rb_pipe
->call_mutex
);
644 rbug_set_framebuffer_state(struct pipe_context
*_pipe
,
645 const struct pipe_framebuffer_state
*_state
)
647 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
648 struct pipe_context
*pipe
= rb_pipe
->pipe
;
649 struct pipe_framebuffer_state unwrapped_state
;
650 struct pipe_framebuffer_state
*state
= NULL
;
653 /* must protect curr status */
654 pipe_mutex_lock(rb_pipe
->call_mutex
);
656 rb_pipe
->curr
.nr_cbufs
= 0;
657 memset(rb_pipe
->curr
.cbufs
, 0, sizeof(rb_pipe
->curr
.cbufs
));
658 rb_pipe
->curr
.zsbuf
= NULL
;
660 /* unwrap the input state */
662 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
664 rb_pipe
->curr
.nr_cbufs
= _state
->nr_cbufs
;
665 for(i
= 0; i
< _state
->nr_cbufs
; i
++) {
666 unwrapped_state
.cbufs
[i
] = rbug_surface_unwrap(_state
->cbufs
[i
]);
667 if (_state
->cbufs
[i
])
668 rb_pipe
->curr
.cbufs
[i
] = rbug_resource(_state
->cbufs
[i
]->texture
);
670 unwrapped_state
.zsbuf
= rbug_surface_unwrap(_state
->zsbuf
);
672 rb_pipe
->curr
.zsbuf
= rbug_resource(_state
->zsbuf
->texture
);
673 state
= &unwrapped_state
;
676 pipe
->set_framebuffer_state(pipe
,
679 pipe_mutex_unlock(rb_pipe
->call_mutex
);
683 rbug_set_polygon_stipple(struct pipe_context
*_pipe
,
684 const struct pipe_poly_stipple
*poly_stipple
)
686 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
687 struct pipe_context
*pipe
= rb_pipe
->pipe
;
689 pipe_mutex_lock(rb_pipe
->call_mutex
);
690 pipe
->set_polygon_stipple(pipe
,
692 pipe_mutex_unlock(rb_pipe
->call_mutex
);
696 rbug_set_scissor_state(struct pipe_context
*_pipe
,
697 const struct pipe_scissor_state
*scissor
)
699 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
700 struct pipe_context
*pipe
= rb_pipe
->pipe
;
702 pipe_mutex_lock(rb_pipe
->call_mutex
);
703 pipe
->set_scissor_state(pipe
,
705 pipe_mutex_unlock(rb_pipe
->call_mutex
);
709 rbug_set_viewport_state(struct pipe_context
*_pipe
,
710 const struct pipe_viewport_state
*viewport
)
712 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
713 struct pipe_context
*pipe
= rb_pipe
->pipe
;
715 pipe_mutex_lock(rb_pipe
->call_mutex
);
716 pipe
->set_viewport_state(pipe
,
718 pipe_mutex_unlock(rb_pipe
->call_mutex
);
722 rbug_set_sampler_views(struct pipe_context
*_pipe
,
726 struct pipe_sampler_view
**_views
)
728 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
729 struct pipe_context
*pipe
= rb_pipe
->pipe
;
730 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
731 struct pipe_sampler_view
**views
= NULL
;
734 assert(start
== 0); /* XXX fix */
736 /* must protect curr status */
737 pipe_mutex_lock(rb_pipe
->call_mutex
);
739 rb_pipe
->curr
.num_views
[shader
] = 0;
740 memset(rb_pipe
->curr
.views
[shader
], 0, sizeof(rb_pipe
->curr
.views
[shader
]));
741 memset(rb_pipe
->curr
.texs
[shader
], 0, sizeof(rb_pipe
->curr
.texs
[shader
]));
742 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
745 rb_pipe
->curr
.num_views
[shader
] = num
;
746 for (i
= 0; i
< num
; i
++) {
747 rb_pipe
->curr
.views
[shader
][i
] = rbug_sampler_view(_views
[i
]);
748 rb_pipe
->curr
.texs
[shader
][i
] = rbug_resource(_views
[i
] ? _views
[i
]->texture
: NULL
);
749 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
751 views
= unwrapped_views
;
755 case PIPE_SHADER_VERTEX
:
756 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
758 case PIPE_SHADER_FRAGMENT
:
759 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
765 pipe_mutex_unlock(rb_pipe
->call_mutex
);
769 rbug_set_vertex_sampler_views(struct pipe_context
*_pipe
,
771 struct pipe_sampler_view
**_views
)
773 rbug_set_sampler_views(_pipe
, PIPE_SHADER_VERTEX
, 0, num
, _views
);
777 rbug_set_fragment_sampler_views(struct pipe_context
*_pipe
,
779 struct pipe_sampler_view
**_views
)
781 rbug_set_sampler_views(_pipe
, PIPE_SHADER_FRAGMENT
, 0, num
, _views
);
785 rbug_set_vertex_buffers(struct pipe_context
*_pipe
,
786 unsigned start_slot
, unsigned num_buffers
,
787 const struct pipe_vertex_buffer
*_buffers
)
789 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
790 struct pipe_context
*pipe
= rb_pipe
->pipe
;
791 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
792 struct pipe_vertex_buffer
*buffers
= NULL
;
795 pipe_mutex_lock(rb_pipe
->call_mutex
);
798 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
799 for (i
= 0; i
< num_buffers
; i
++)
800 unwrapped_buffers
[i
].buffer
= rbug_resource_unwrap(_buffers
[i
].buffer
);
801 buffers
= unwrapped_buffers
;
804 pipe
->set_vertex_buffers(pipe
, start_slot
,
808 pipe_mutex_unlock(rb_pipe
->call_mutex
);
812 rbug_set_index_buffer(struct pipe_context
*_pipe
,
813 const struct pipe_index_buffer
*_ib
)
815 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
816 struct pipe_context
*pipe
= rb_pipe
->pipe
;
817 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
821 unwrapped_ib
.buffer
= rbug_resource_unwrap(_ib
->buffer
);
825 pipe_mutex_lock(rb_pipe
->call_mutex
);
826 pipe
->set_index_buffer(pipe
, ib
);
827 pipe_mutex_unlock(rb_pipe
->call_mutex
);
831 rbug_set_sample_mask(struct pipe_context
*_pipe
,
832 unsigned sample_mask
)
834 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
835 struct pipe_context
*pipe
= rb_pipe
->pipe
;
837 pipe_mutex_lock(rb_pipe
->call_mutex
);
838 pipe
->set_sample_mask(pipe
, sample_mask
);
839 pipe_mutex_unlock(rb_pipe
->call_mutex
);
843 rbug_resource_copy_region(struct pipe_context
*_pipe
,
844 struct pipe_resource
*_dst
,
849 struct pipe_resource
*_src
,
851 const struct pipe_box
*src_box
)
853 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
854 struct rbug_resource
*rb_resource_dst
= rbug_resource(_dst
);
855 struct rbug_resource
*rb_resource_src
= rbug_resource(_src
);
856 struct pipe_context
*pipe
= rb_pipe
->pipe
;
857 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
858 struct pipe_resource
*src
= rb_resource_src
->resource
;
860 pipe_mutex_lock(rb_pipe
->call_mutex
);
861 pipe
->resource_copy_region(pipe
,
870 pipe_mutex_unlock(rb_pipe
->call_mutex
);
874 rbug_clear(struct pipe_context
*_pipe
,
876 const union pipe_color_union
*color
,
880 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
881 struct pipe_context
*pipe
= rb_pipe
->pipe
;
883 pipe_mutex_lock(rb_pipe
->call_mutex
);
889 pipe_mutex_unlock(rb_pipe
->call_mutex
);
893 rbug_clear_render_target(struct pipe_context
*_pipe
,
894 struct pipe_surface
*_dst
,
895 const union pipe_color_union
*color
,
896 unsigned dstx
, unsigned dsty
,
897 unsigned width
, unsigned height
)
899 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
900 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
901 struct pipe_context
*pipe
= rb_pipe
->pipe
;
902 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
904 pipe_mutex_lock(rb_pipe
->call_mutex
);
905 pipe
->clear_render_target(pipe
,
912 pipe_mutex_unlock(rb_pipe
->call_mutex
);
916 rbug_clear_depth_stencil(struct pipe_context
*_pipe
,
917 struct pipe_surface
*_dst
,
918 unsigned clear_flags
,
921 unsigned dstx
, unsigned dsty
,
922 unsigned width
, unsigned height
)
924 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
925 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
926 struct pipe_context
*pipe
= rb_pipe
->pipe
;
927 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
929 pipe_mutex_lock(rb_pipe
->call_mutex
);
930 pipe
->clear_depth_stencil(pipe
,
939 pipe_mutex_unlock(rb_pipe
->call_mutex
);
943 rbug_flush(struct pipe_context
*_pipe
,
944 struct pipe_fence_handle
**fence
,
947 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
948 struct pipe_context
*pipe
= rb_pipe
->pipe
;
950 pipe_mutex_lock(rb_pipe
->call_mutex
);
951 pipe
->flush(pipe
, fence
, flags
);
952 pipe_mutex_unlock(rb_pipe
->call_mutex
);
955 static struct pipe_sampler_view
*
956 rbug_context_create_sampler_view(struct pipe_context
*_pipe
,
957 struct pipe_resource
*_resource
,
958 const struct pipe_sampler_view
*templ
)
960 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
961 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
962 struct pipe_context
*pipe
= rb_pipe
->pipe
;
963 struct pipe_resource
*resource
= rb_resource
->resource
;
964 struct pipe_sampler_view
*result
;
966 pipe_mutex_lock(rb_pipe
->call_mutex
);
967 result
= pipe
->create_sampler_view(pipe
,
970 pipe_mutex_unlock(rb_pipe
->call_mutex
);
973 return rbug_sampler_view_create(rb_pipe
, rb_resource
, result
);
978 rbug_context_sampler_view_destroy(struct pipe_context
*_pipe
,
979 struct pipe_sampler_view
*_view
)
981 rbug_sampler_view_destroy(rbug_context(_pipe
),
982 rbug_sampler_view(_view
));
985 static struct pipe_surface
*
986 rbug_context_create_surface(struct pipe_context
*_pipe
,
987 struct pipe_resource
*_resource
,
988 const struct pipe_surface
*surf_tmpl
)
990 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
991 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
992 struct pipe_context
*pipe
= rb_pipe
->pipe
;
993 struct pipe_resource
*resource
= rb_resource
->resource
;
994 struct pipe_surface
*result
;
996 pipe_mutex_lock(rb_pipe
->call_mutex
);
997 result
= pipe
->create_surface(pipe
,
1000 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1003 return rbug_surface_create(rb_pipe
, rb_resource
, result
);
1008 rbug_context_surface_destroy(struct pipe_context
*_pipe
,
1009 struct pipe_surface
*_surface
)
1011 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1012 struct rbug_surface
*rb_surface
= rbug_surface(_surface
);
1014 pipe_mutex_lock(rb_pipe
->call_mutex
);
1015 rbug_surface_destroy(rb_pipe
,
1017 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1023 rbug_context_transfer_map(struct pipe_context
*_context
,
1024 struct pipe_resource
*_resource
,
1027 const struct pipe_box
*box
,
1028 struct pipe_transfer
**transfer
)
1030 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1031 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1032 struct pipe_context
*context
= rb_pipe
->pipe
;
1033 struct pipe_resource
*resource
= rb_resource
->resource
;
1034 struct pipe_transfer
*result
;
1037 pipe_mutex_lock(rb_pipe
->call_mutex
);
1038 map
= context
->transfer_map(context
,
1043 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1045 *transfer
= rbug_transfer_create(rb_pipe
, rb_resource
, result
);
1046 return *transfer
? map
: NULL
;
1050 rbug_context_transfer_flush_region(struct pipe_context
*_context
,
1051 struct pipe_transfer
*_transfer
,
1052 const struct pipe_box
*box
)
1054 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1055 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1056 struct pipe_context
*context
= rb_pipe
->pipe
;
1057 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1059 pipe_mutex_lock(rb_pipe
->call_mutex
);
1060 context
->transfer_flush_region(context
,
1063 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1068 rbug_context_transfer_unmap(struct pipe_context
*_context
,
1069 struct pipe_transfer
*_transfer
)
1071 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1072 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1073 struct pipe_context
*context
= rb_pipe
->pipe
;
1074 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1076 pipe_mutex_lock(rb_pipe
->call_mutex
);
1077 context
->transfer_unmap(context
,
1079 rbug_transfer_destroy(rb_pipe
,
1081 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1086 rbug_context_transfer_inline_write(struct pipe_context
*_context
,
1087 struct pipe_resource
*_resource
,
1090 const struct pipe_box
*box
,
1093 unsigned layer_stride
)
1095 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1096 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1097 struct pipe_context
*context
= rb_pipe
->pipe
;
1098 struct pipe_resource
*resource
= rb_resource
->resource
;
1100 pipe_mutex_lock(rb_pipe
->call_mutex
);
1101 context
->transfer_inline_write(context
,
1109 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1113 struct pipe_context
*
1114 rbug_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1116 struct rbug_context
*rb_pipe
;
1117 struct rbug_screen
*rb_screen
= rbug_screen(_screen
);
1122 rb_pipe
= CALLOC_STRUCT(rbug_context
);
1126 pipe_mutex_init(rb_pipe
->draw_mutex
);
1127 pipe_condvar_init(rb_pipe
->draw_cond
);
1128 pipe_mutex_init(rb_pipe
->call_mutex
);
1129 pipe_mutex_init(rb_pipe
->list_mutex
);
1130 make_empty_list(&rb_pipe
->shaders
);
1132 rb_pipe
->base
.screen
= _screen
;
1133 rb_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1134 rb_pipe
->base
.draw
= NULL
;
1136 rb_pipe
->base
.destroy
= rbug_destroy
;
1137 rb_pipe
->base
.draw_vbo
= rbug_draw_vbo
;
1138 rb_pipe
->base
.create_query
= rbug_create_query
;
1139 rb_pipe
->base
.destroy_query
= rbug_destroy_query
;
1140 rb_pipe
->base
.begin_query
= rbug_begin_query
;
1141 rb_pipe
->base
.end_query
= rbug_end_query
;
1142 rb_pipe
->base
.get_query_result
= rbug_get_query_result
;
1143 rb_pipe
->base
.create_blend_state
= rbug_create_blend_state
;
1144 rb_pipe
->base
.bind_blend_state
= rbug_bind_blend_state
;
1145 rb_pipe
->base
.delete_blend_state
= rbug_delete_blend_state
;
1146 rb_pipe
->base
.create_sampler_state
= rbug_create_sampler_state
;
1147 rb_pipe
->base
.bind_fragment_sampler_states
= rbug_bind_fragment_sampler_states
;
1148 rb_pipe
->base
.bind_vertex_sampler_states
= rbug_bind_vertex_sampler_states
;
1149 rb_pipe
->base
.delete_sampler_state
= rbug_delete_sampler_state
;
1150 rb_pipe
->base
.create_rasterizer_state
= rbug_create_rasterizer_state
;
1151 rb_pipe
->base
.bind_rasterizer_state
= rbug_bind_rasterizer_state
;
1152 rb_pipe
->base
.delete_rasterizer_state
= rbug_delete_rasterizer_state
;
1153 rb_pipe
->base
.create_depth_stencil_alpha_state
= rbug_create_depth_stencil_alpha_state
;
1154 rb_pipe
->base
.bind_depth_stencil_alpha_state
= rbug_bind_depth_stencil_alpha_state
;
1155 rb_pipe
->base
.delete_depth_stencil_alpha_state
= rbug_delete_depth_stencil_alpha_state
;
1156 rb_pipe
->base
.create_fs_state
= rbug_create_fs_state
;
1157 rb_pipe
->base
.bind_fs_state
= rbug_bind_fs_state
;
1158 rb_pipe
->base
.delete_fs_state
= rbug_delete_fs_state
;
1159 rb_pipe
->base
.create_vs_state
= rbug_create_vs_state
;
1160 rb_pipe
->base
.bind_vs_state
= rbug_bind_vs_state
;
1161 rb_pipe
->base
.delete_vs_state
= rbug_delete_vs_state
;
1162 rb_pipe
->base
.create_gs_state
= rbug_create_gs_state
;
1163 rb_pipe
->base
.bind_gs_state
= rbug_bind_gs_state
;
1164 rb_pipe
->base
.delete_gs_state
= rbug_delete_gs_state
;
1165 rb_pipe
->base
.create_vertex_elements_state
= rbug_create_vertex_elements_state
;
1166 rb_pipe
->base
.bind_vertex_elements_state
= rbug_bind_vertex_elements_state
;
1167 rb_pipe
->base
.delete_vertex_elements_state
= rbug_delete_vertex_elements_state
;
1168 rb_pipe
->base
.set_blend_color
= rbug_set_blend_color
;
1169 rb_pipe
->base
.set_stencil_ref
= rbug_set_stencil_ref
;
1170 rb_pipe
->base
.set_clip_state
= rbug_set_clip_state
;
1171 rb_pipe
->base
.set_constant_buffer
= rbug_set_constant_buffer
;
1172 rb_pipe
->base
.set_framebuffer_state
= rbug_set_framebuffer_state
;
1173 rb_pipe
->base
.set_polygon_stipple
= rbug_set_polygon_stipple
;
1174 rb_pipe
->base
.set_scissor_state
= rbug_set_scissor_state
;
1175 rb_pipe
->base
.set_viewport_state
= rbug_set_viewport_state
;
1176 rb_pipe
->base
.set_fragment_sampler_views
= rbug_set_fragment_sampler_views
;
1177 rb_pipe
->base
.set_vertex_sampler_views
= rbug_set_vertex_sampler_views
;
1178 rb_pipe
->base
.set_vertex_buffers
= rbug_set_vertex_buffers
;
1179 rb_pipe
->base
.set_index_buffer
= rbug_set_index_buffer
;
1180 rb_pipe
->base
.set_sample_mask
= rbug_set_sample_mask
;
1181 rb_pipe
->base
.resource_copy_region
= rbug_resource_copy_region
;
1182 rb_pipe
->base
.clear
= rbug_clear
;
1183 rb_pipe
->base
.clear_render_target
= rbug_clear_render_target
;
1184 rb_pipe
->base
.clear_depth_stencil
= rbug_clear_depth_stencil
;
1185 rb_pipe
->base
.flush
= rbug_flush
;
1186 rb_pipe
->base
.create_sampler_view
= rbug_context_create_sampler_view
;
1187 rb_pipe
->base
.sampler_view_destroy
= rbug_context_sampler_view_destroy
;
1188 rb_pipe
->base
.create_surface
= rbug_context_create_surface
;
1189 rb_pipe
->base
.surface_destroy
= rbug_context_surface_destroy
;
1190 rb_pipe
->base
.transfer_map
= rbug_context_transfer_map
;
1191 rb_pipe
->base
.transfer_unmap
= rbug_context_transfer_unmap
;
1192 rb_pipe
->base
.transfer_flush_region
= rbug_context_transfer_flush_region
;
1193 rb_pipe
->base
.transfer_inline_write
= rbug_context_transfer_inline_write
;
1195 rb_pipe
->pipe
= pipe
;
1197 rbug_screen_add_to_list(rb_screen
, contexts
, rb_pipe
);
1199 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE
)) {
1200 rb_pipe
->draw_blocked
= RBUG_BLOCK_BEFORE
;
1203 return &rb_pipe
->base
;