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/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_screen *rb_screen = rbug_screen(_pipe->screen);
44 struct rbug_context *rb_pipe = rbug_context(_pipe);
45 struct pipe_context *pipe = rb_pipe->pipe;
47 rbug_screen_remove_from_list(rb_screen, contexts, rb_pipe);
49 pipe_mutex_lock(rb_pipe->call_mutex);
52 pipe_mutex_unlock(rb_pipe->call_mutex);
58 rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
61 if (rb_pipe->draw_blocker & flag) {
62 rb_pipe->draw_blocked |= flag;
63 } else if ((rb_pipe->draw_rule.blocker & flag) &&
64 (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
66 boolean block = FALSE;
69 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
70 (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_FRAGMENT],
71 (void *) rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT],
72 (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_VERTEX],
73 (void *) rb_pipe->curr.shader[PIPE_SHADER_VERTEX],
74 (void *) rb_pipe->draw_rule.surf, 0,
75 (void *) rb_pipe->draw_rule.texture, 0);
76 for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
77 if (rb_pipe->draw_rule.shader[sh] &&
78 rb_pipe->draw_rule.shader[sh] == rb_pipe->curr.shader[sh])
82 if (rb_pipe->draw_rule.surf &&
83 rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
85 if (rb_pipe->draw_rule.surf)
86 for (k = 0; k < rb_pipe->curr.nr_cbufs; k++)
87 if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
89 if (rb_pipe->draw_rule.texture) {
90 for (sh = 0; sh < Elements(rb_pipe->curr.num_views); sh++) {
91 for (k = 0; k < rb_pipe->curr.num_views[sh]; k++) {
92 if (rb_pipe->draw_rule.texture == rb_pipe->curr.texs[sh][k]) {
94 sh = PIPE_SHADER_TYPES; /* to break out of both loops */
102 rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
105 if (rb_pipe->draw_blocked)
106 rbug_notify_draw_blocked(rb_pipe);
108 /* wait for rbug to clear the blocked flag */
109 while (rb_pipe->draw_blocked & flag) {
110 rb_pipe->draw_blocked |= flag;
111 pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
117 rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
119 struct rbug_context *rb_pipe = rbug_context(_pipe);
120 struct pipe_context *pipe = rb_pipe->pipe;
122 pipe_mutex_lock(rb_pipe->draw_mutex);
123 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
125 pipe_mutex_lock(rb_pipe->call_mutex);
126 /* XXX loop over PIPE_SHADER_x here */
127 if (!(rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] && rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT]->disabled) &&
128 !(rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) &&
129 !(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->disabled))
130 pipe->draw_vbo(pipe, info);
131 pipe_mutex_unlock(rb_pipe->call_mutex);
133 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
134 pipe_mutex_unlock(rb_pipe->draw_mutex);
137 static struct pipe_query *
138 rbug_create_query(struct pipe_context *_pipe,
142 struct rbug_context *rb_pipe = rbug_context(_pipe);
143 struct pipe_context *pipe = rb_pipe->pipe;
144 struct pipe_query *query;
146 pipe_mutex_lock(rb_pipe->call_mutex);
147 query = pipe->create_query(pipe,
150 pipe_mutex_unlock(rb_pipe->call_mutex);
155 rbug_destroy_query(struct pipe_context *_pipe,
156 struct pipe_query *query)
158 struct rbug_context *rb_pipe = rbug_context(_pipe);
159 struct pipe_context *pipe = rb_pipe->pipe;
161 pipe_mutex_lock(rb_pipe->call_mutex);
162 pipe->destroy_query(pipe,
164 pipe_mutex_unlock(rb_pipe->call_mutex);
168 rbug_begin_query(struct pipe_context *_pipe,
169 struct pipe_query *query)
171 struct rbug_context *rb_pipe = rbug_context(_pipe);
172 struct pipe_context *pipe = rb_pipe->pipe;
175 pipe_mutex_lock(rb_pipe->call_mutex);
176 ret = pipe->begin_query(pipe, query);
177 pipe_mutex_unlock(rb_pipe->call_mutex);
182 rbug_end_query(struct pipe_context *_pipe,
183 struct pipe_query *query)
185 struct rbug_context *rb_pipe = rbug_context(_pipe);
186 struct pipe_context *pipe = rb_pipe->pipe;
189 pipe_mutex_lock(rb_pipe->call_mutex);
190 ret = pipe->end_query(pipe,
192 pipe_mutex_unlock(rb_pipe->call_mutex);
198 rbug_get_query_result(struct pipe_context *_pipe,
199 struct pipe_query *query,
201 union pipe_query_result *result)
203 struct rbug_context *rb_pipe = rbug_context(_pipe);
204 struct pipe_context *pipe = rb_pipe->pipe;
207 pipe_mutex_lock(rb_pipe->call_mutex);
208 ret = pipe->get_query_result(pipe,
212 pipe_mutex_unlock(rb_pipe->call_mutex);
218 rbug_set_active_query_state(struct pipe_context *_pipe, boolean enable)
220 struct rbug_context *rb_pipe = rbug_context(_pipe);
221 struct pipe_context *pipe = rb_pipe->pipe;
223 pipe_mutex_lock(rb_pipe->call_mutex);
224 pipe->set_active_query_state(pipe, enable);
225 pipe_mutex_unlock(rb_pipe->call_mutex);
229 rbug_create_blend_state(struct pipe_context *_pipe,
230 const struct pipe_blend_state *blend)
232 struct rbug_context *rb_pipe = rbug_context(_pipe);
233 struct pipe_context *pipe = rb_pipe->pipe;
236 pipe_mutex_lock(rb_pipe->call_mutex);
237 ret = pipe->create_blend_state(pipe,
239 pipe_mutex_unlock(rb_pipe->call_mutex);
245 rbug_bind_blend_state(struct pipe_context *_pipe,
248 struct rbug_context *rb_pipe = rbug_context(_pipe);
249 struct pipe_context *pipe = rb_pipe->pipe;
251 pipe_mutex_lock(rb_pipe->call_mutex);
252 pipe->bind_blend_state(pipe,
254 pipe_mutex_unlock(rb_pipe->call_mutex);
258 rbug_delete_blend_state(struct pipe_context *_pipe,
261 struct rbug_context *rb_pipe = rbug_context(_pipe);
262 struct pipe_context *pipe = rb_pipe->pipe;
264 pipe_mutex_lock(rb_pipe->call_mutex);
265 pipe->delete_blend_state(pipe,
267 pipe_mutex_unlock(rb_pipe->call_mutex);
271 rbug_create_sampler_state(struct pipe_context *_pipe,
272 const struct pipe_sampler_state *sampler)
274 struct rbug_context *rb_pipe = rbug_context(_pipe);
275 struct pipe_context *pipe = rb_pipe->pipe;
278 pipe_mutex_lock(rb_pipe->call_mutex);
279 ret = pipe->create_sampler_state(pipe,
281 pipe_mutex_unlock(rb_pipe->call_mutex);
287 rbug_bind_sampler_states(struct pipe_context *_pipe, unsigned shader,
288 unsigned start, unsigned count,
291 struct rbug_context *rb_pipe = rbug_context(_pipe);
292 struct pipe_context *pipe = rb_pipe->pipe;
294 pipe_mutex_lock(rb_pipe->call_mutex);
295 pipe->bind_sampler_states(pipe, shader, start, count, samplers);
296 pipe_mutex_unlock(rb_pipe->call_mutex);
300 rbug_delete_sampler_state(struct pipe_context *_pipe,
303 struct rbug_context *rb_pipe = rbug_context(_pipe);
304 struct pipe_context *pipe = rb_pipe->pipe;
306 pipe_mutex_lock(rb_pipe->call_mutex);
307 pipe->delete_sampler_state(pipe,
309 pipe_mutex_unlock(rb_pipe->call_mutex);
313 rbug_create_rasterizer_state(struct pipe_context *_pipe,
314 const struct pipe_rasterizer_state *rasterizer)
316 struct rbug_context *rb_pipe = rbug_context(_pipe);
317 struct pipe_context *pipe = rb_pipe->pipe;
320 pipe_mutex_lock(rb_pipe->call_mutex);
321 ret = pipe->create_rasterizer_state(pipe,
323 pipe_mutex_unlock(rb_pipe->call_mutex);
329 rbug_bind_rasterizer_state(struct pipe_context *_pipe,
332 struct rbug_context *rb_pipe = rbug_context(_pipe);
333 struct pipe_context *pipe = rb_pipe->pipe;
335 pipe_mutex_lock(rb_pipe->call_mutex);
336 pipe->bind_rasterizer_state(pipe,
338 pipe_mutex_unlock(rb_pipe->call_mutex);
342 rbug_delete_rasterizer_state(struct pipe_context *_pipe,
345 struct rbug_context *rb_pipe = rbug_context(_pipe);
346 struct pipe_context *pipe = rb_pipe->pipe;
348 pipe_mutex_lock(rb_pipe->call_mutex);
349 pipe->delete_rasterizer_state(pipe,
351 pipe_mutex_unlock(rb_pipe->call_mutex);
355 rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
356 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
358 struct rbug_context *rb_pipe = rbug_context(_pipe);
359 struct pipe_context *pipe = rb_pipe->pipe;
362 pipe_mutex_lock(rb_pipe->call_mutex);
363 ret = pipe->create_depth_stencil_alpha_state(pipe,
364 depth_stencil_alpha);
365 pipe_mutex_unlock(rb_pipe->call_mutex);
371 rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
372 void *depth_stencil_alpha)
374 struct rbug_context *rb_pipe = rbug_context(_pipe);
375 struct pipe_context *pipe = rb_pipe->pipe;
377 pipe_mutex_lock(rb_pipe->call_mutex);
378 pipe->bind_depth_stencil_alpha_state(pipe,
379 depth_stencil_alpha);
380 pipe_mutex_unlock(rb_pipe->call_mutex);
384 rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
385 void *depth_stencil_alpha)
387 struct rbug_context *rb_pipe = rbug_context(_pipe);
388 struct pipe_context *pipe = rb_pipe->pipe;
390 pipe_mutex_lock(rb_pipe->call_mutex);
391 pipe->delete_depth_stencil_alpha_state(pipe,
392 depth_stencil_alpha);
393 pipe_mutex_unlock(rb_pipe->call_mutex);
397 rbug_create_fs_state(struct pipe_context *_pipe,
398 const struct pipe_shader_state *state)
400 struct rbug_context *rb_pipe = rbug_context(_pipe);
401 struct pipe_context *pipe = rb_pipe->pipe;
404 pipe_mutex_lock(rb_pipe->call_mutex);
405 result = pipe->create_fs_state(pipe, state);
406 pipe_mutex_unlock(rb_pipe->call_mutex);
411 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
415 rbug_bind_fs_state(struct pipe_context *_pipe,
418 struct rbug_context *rb_pipe = rbug_context(_pipe);
419 struct pipe_context *pipe = rb_pipe->pipe;
422 pipe_mutex_lock(rb_pipe->call_mutex);
424 fs = rbug_shader_unwrap(_fs);
425 rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs);
426 pipe->bind_fs_state(pipe,
429 pipe_mutex_unlock(rb_pipe->call_mutex);
433 rbug_delete_fs_state(struct pipe_context *_pipe,
436 struct rbug_context *rb_pipe = rbug_context(_pipe);
437 struct rbug_shader *rb_shader = rbug_shader(_fs);
439 pipe_mutex_lock(rb_pipe->call_mutex);
440 rbug_shader_destroy(rb_pipe, rb_shader);
441 pipe_mutex_unlock(rb_pipe->call_mutex);
445 rbug_create_vs_state(struct pipe_context *_pipe,
446 const struct pipe_shader_state *state)
448 struct rbug_context *rb_pipe = rbug_context(_pipe);
449 struct pipe_context *pipe = rb_pipe->pipe;
452 pipe_mutex_lock(rb_pipe->call_mutex);
453 result = pipe->create_vs_state(pipe, state);
454 pipe_mutex_unlock(rb_pipe->call_mutex);
459 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
463 rbug_bind_vs_state(struct pipe_context *_pipe,
466 struct rbug_context *rb_pipe = rbug_context(_pipe);
467 struct pipe_context *pipe = rb_pipe->pipe;
470 pipe_mutex_lock(rb_pipe->call_mutex);
472 vs = rbug_shader_unwrap(_vs);
473 rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs);
474 pipe->bind_vs_state(pipe,
477 pipe_mutex_unlock(rb_pipe->call_mutex);
481 rbug_delete_vs_state(struct pipe_context *_pipe,
484 struct rbug_context *rb_pipe = rbug_context(_pipe);
485 struct rbug_shader *rb_shader = rbug_shader(_vs);
487 pipe_mutex_unlock(rb_pipe->call_mutex);
488 rbug_shader_destroy(rb_pipe, rb_shader);
489 pipe_mutex_unlock(rb_pipe->call_mutex);
493 rbug_create_gs_state(struct pipe_context *_pipe,
494 const struct pipe_shader_state *state)
496 struct rbug_context *rb_pipe = rbug_context(_pipe);
497 struct pipe_context *pipe = rb_pipe->pipe;
500 pipe_mutex_lock(rb_pipe->call_mutex);
501 result = pipe->create_gs_state(pipe, state);
502 pipe_mutex_unlock(rb_pipe->call_mutex);
507 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
511 rbug_bind_gs_state(struct pipe_context *_pipe,
514 struct rbug_context *rb_pipe = rbug_context(_pipe);
515 struct pipe_context *pipe = rb_pipe->pipe;
518 pipe_mutex_lock(rb_pipe->call_mutex);
520 gs = rbug_shader_unwrap(_gs);
521 rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs);
522 pipe->bind_gs_state(pipe,
525 pipe_mutex_unlock(rb_pipe->call_mutex);
529 rbug_delete_gs_state(struct pipe_context *_pipe,
532 struct rbug_context *rb_pipe = rbug_context(_pipe);
533 struct rbug_shader *rb_shader = rbug_shader(_gs);
535 pipe_mutex_lock(rb_pipe->call_mutex);
536 rbug_shader_destroy(rb_pipe, rb_shader);
537 pipe_mutex_unlock(rb_pipe->call_mutex);
541 rbug_create_vertex_elements_state(struct pipe_context *_pipe,
542 unsigned num_elements,
543 const struct pipe_vertex_element *vertex_elements)
545 struct rbug_context *rb_pipe = rbug_context(_pipe);
546 struct pipe_context *pipe = rb_pipe->pipe;
549 pipe_mutex_lock(rb_pipe->call_mutex);
550 ret = pipe->create_vertex_elements_state(pipe,
553 pipe_mutex_unlock(rb_pipe->call_mutex);
559 rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
562 struct rbug_context *rb_pipe = rbug_context(_pipe);
563 struct pipe_context *pipe = rb_pipe->pipe;
565 pipe_mutex_lock(rb_pipe->call_mutex);
566 pipe->bind_vertex_elements_state(pipe,
568 pipe_mutex_unlock(rb_pipe->call_mutex);
572 rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
575 struct rbug_context *rb_pipe = rbug_context(_pipe);
576 struct pipe_context *pipe = rb_pipe->pipe;
578 pipe_mutex_lock(rb_pipe->call_mutex);
579 pipe->delete_vertex_elements_state(pipe,
581 pipe_mutex_unlock(rb_pipe->call_mutex);
585 rbug_set_blend_color(struct pipe_context *_pipe,
586 const struct pipe_blend_color *blend_color)
588 struct rbug_context *rb_pipe = rbug_context(_pipe);
589 struct pipe_context *pipe = rb_pipe->pipe;
591 pipe_mutex_lock(rb_pipe->call_mutex);
592 pipe->set_blend_color(pipe,
594 pipe_mutex_unlock(rb_pipe->call_mutex);
598 rbug_set_stencil_ref(struct pipe_context *_pipe,
599 const struct pipe_stencil_ref *stencil_ref)
601 struct rbug_context *rb_pipe = rbug_context(_pipe);
602 struct pipe_context *pipe = rb_pipe->pipe;
604 pipe_mutex_lock(rb_pipe->call_mutex);
605 pipe->set_stencil_ref(pipe,
607 pipe_mutex_unlock(rb_pipe->call_mutex);
611 rbug_set_clip_state(struct pipe_context *_pipe,
612 const struct pipe_clip_state *clip)
614 struct rbug_context *rb_pipe = rbug_context(_pipe);
615 struct pipe_context *pipe = rb_pipe->pipe;
617 pipe_mutex_lock(rb_pipe->call_mutex);
618 pipe->set_clip_state(pipe,
620 pipe_mutex_unlock(rb_pipe->call_mutex);
624 rbug_set_constant_buffer(struct pipe_context *_pipe,
627 struct pipe_constant_buffer *_cb)
629 struct rbug_context *rb_pipe = rbug_context(_pipe);
630 struct pipe_context *pipe = rb_pipe->pipe;
631 struct pipe_constant_buffer cb;
633 /* XXX hmm? unwrap the input state */
636 cb.buffer = rbug_resource_unwrap(_cb->buffer);
639 pipe_mutex_lock(rb_pipe->call_mutex);
640 pipe->set_constant_buffer(pipe,
644 pipe_mutex_unlock(rb_pipe->call_mutex);
648 rbug_set_framebuffer_state(struct pipe_context *_pipe,
649 const struct pipe_framebuffer_state *_state)
651 struct rbug_context *rb_pipe = rbug_context(_pipe);
652 struct pipe_context *pipe = rb_pipe->pipe;
653 struct pipe_framebuffer_state unwrapped_state;
654 struct pipe_framebuffer_state *state = NULL;
657 /* must protect curr status */
658 pipe_mutex_lock(rb_pipe->call_mutex);
660 rb_pipe->curr.nr_cbufs = 0;
661 memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
662 rb_pipe->curr.zsbuf = NULL;
664 /* unwrap the input state */
666 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
668 rb_pipe->curr.nr_cbufs = _state->nr_cbufs;
669 for(i = 0; i < _state->nr_cbufs; i++) {
670 unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]);
671 if (_state->cbufs[i])
672 rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
674 unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
676 rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
677 state = &unwrapped_state;
680 pipe->set_framebuffer_state(pipe,
683 pipe_mutex_unlock(rb_pipe->call_mutex);
687 rbug_set_polygon_stipple(struct pipe_context *_pipe,
688 const struct pipe_poly_stipple *poly_stipple)
690 struct rbug_context *rb_pipe = rbug_context(_pipe);
691 struct pipe_context *pipe = rb_pipe->pipe;
693 pipe_mutex_lock(rb_pipe->call_mutex);
694 pipe->set_polygon_stipple(pipe,
696 pipe_mutex_unlock(rb_pipe->call_mutex);
700 rbug_set_scissor_states(struct pipe_context *_pipe,
702 unsigned num_scissors,
703 const struct pipe_scissor_state *scissor)
705 struct rbug_context *rb_pipe = rbug_context(_pipe);
706 struct pipe_context *pipe = rb_pipe->pipe;
708 pipe_mutex_lock(rb_pipe->call_mutex);
709 pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
710 pipe_mutex_unlock(rb_pipe->call_mutex);
714 rbug_set_viewport_states(struct pipe_context *_pipe,
716 unsigned num_viewports,
717 const struct pipe_viewport_state *viewport)
719 struct rbug_context *rb_pipe = rbug_context(_pipe);
720 struct pipe_context *pipe = rb_pipe->pipe;
722 pipe_mutex_lock(rb_pipe->call_mutex);
723 pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
724 pipe_mutex_unlock(rb_pipe->call_mutex);
728 rbug_set_sampler_views(struct pipe_context *_pipe,
732 struct pipe_sampler_view **_views)
734 struct rbug_context *rb_pipe = rbug_context(_pipe);
735 struct pipe_context *pipe = rb_pipe->pipe;
736 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
737 struct pipe_sampler_view **views = NULL;
740 assert(start == 0); /* XXX fix */
742 /* must protect curr status */
743 pipe_mutex_lock(rb_pipe->call_mutex);
745 rb_pipe->curr.num_views[shader] = 0;
746 memset(rb_pipe->curr.views[shader], 0, sizeof(rb_pipe->curr.views[shader]));
747 memset(rb_pipe->curr.texs[shader], 0, sizeof(rb_pipe->curr.texs[shader]));
748 memset(unwrapped_views, 0, sizeof(unwrapped_views));
751 rb_pipe->curr.num_views[shader] = num;
752 for (i = 0; i < num; i++) {
753 rb_pipe->curr.views[shader][i] = rbug_sampler_view(_views[i]);
754 rb_pipe->curr.texs[shader][i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
755 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
757 views = unwrapped_views;
760 pipe->set_sampler_views(pipe, shader, start, num, views);
762 pipe_mutex_unlock(rb_pipe->call_mutex);
766 rbug_set_vertex_buffers(struct pipe_context *_pipe,
767 unsigned start_slot, unsigned num_buffers,
768 const struct pipe_vertex_buffer *_buffers)
770 struct rbug_context *rb_pipe = rbug_context(_pipe);
771 struct pipe_context *pipe = rb_pipe->pipe;
772 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
773 struct pipe_vertex_buffer *buffers = NULL;
776 pipe_mutex_lock(rb_pipe->call_mutex);
778 if (num_buffers && _buffers) {
779 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
780 for (i = 0; i < num_buffers; i++)
781 unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer);
782 buffers = unwrapped_buffers;
785 pipe->set_vertex_buffers(pipe, start_slot,
789 pipe_mutex_unlock(rb_pipe->call_mutex);
793 rbug_set_index_buffer(struct pipe_context *_pipe,
794 const struct pipe_index_buffer *_ib)
796 struct rbug_context *rb_pipe = rbug_context(_pipe);
797 struct pipe_context *pipe = rb_pipe->pipe;
798 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
802 unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer);
806 pipe_mutex_lock(rb_pipe->call_mutex);
807 pipe->set_index_buffer(pipe, ib);
808 pipe_mutex_unlock(rb_pipe->call_mutex);
812 rbug_set_sample_mask(struct pipe_context *_pipe,
813 unsigned sample_mask)
815 struct rbug_context *rb_pipe = rbug_context(_pipe);
816 struct pipe_context *pipe = rb_pipe->pipe;
818 pipe_mutex_lock(rb_pipe->call_mutex);
819 pipe->set_sample_mask(pipe, sample_mask);
820 pipe_mutex_unlock(rb_pipe->call_mutex);
823 static struct pipe_stream_output_target *
824 rbug_create_stream_output_target(struct pipe_context *_pipe,
825 struct pipe_resource *_res,
826 unsigned buffer_offset, unsigned buffer_size)
828 struct rbug_context *rb_pipe = rbug_context(_pipe);
829 struct pipe_context *pipe = rb_pipe->pipe;
830 struct pipe_resource *res = rbug_resource_unwrap(_res);
831 struct pipe_stream_output_target *target;
833 pipe_mutex_lock(rb_pipe->call_mutex);
834 target = pipe->create_stream_output_target(pipe, res, buffer_offset,
836 pipe_mutex_unlock(rb_pipe->call_mutex);
841 rbug_stream_output_target_destroy(struct pipe_context *_pipe,
842 struct pipe_stream_output_target *target)
844 struct rbug_context *rb_pipe = rbug_context(_pipe);
845 struct pipe_context *pipe = rb_pipe->pipe;
847 pipe_mutex_lock(rb_pipe->call_mutex);
848 pipe->stream_output_target_destroy(pipe, target);
849 pipe_mutex_unlock(rb_pipe->call_mutex);
853 rbug_set_stream_output_targets(struct pipe_context *_pipe,
854 unsigned num_targets,
855 struct pipe_stream_output_target **targets,
856 const unsigned *offsets)
858 struct rbug_context *rb_pipe = rbug_context(_pipe);
859 struct pipe_context *pipe = rb_pipe->pipe;
861 pipe_mutex_lock(rb_pipe->call_mutex);
862 pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
863 pipe_mutex_unlock(rb_pipe->call_mutex);
867 rbug_resource_copy_region(struct pipe_context *_pipe,
868 struct pipe_resource *_dst,
873 struct pipe_resource *_src,
875 const struct pipe_box *src_box)
877 struct rbug_context *rb_pipe = rbug_context(_pipe);
878 struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
879 struct rbug_resource *rb_resource_src = rbug_resource(_src);
880 struct pipe_context *pipe = rb_pipe->pipe;
881 struct pipe_resource *dst = rb_resource_dst->resource;
882 struct pipe_resource *src = rb_resource_src->resource;
884 pipe_mutex_lock(rb_pipe->call_mutex);
885 pipe->resource_copy_region(pipe,
894 pipe_mutex_unlock(rb_pipe->call_mutex);
898 rbug_blit(struct pipe_context *_pipe, const struct pipe_blit_info *_blit_info)
900 struct rbug_context *rb_pipe = rbug_context(_pipe);
901 struct rbug_resource *rb_resource_dst = rbug_resource(_blit_info->dst.resource);
902 struct rbug_resource *rb_resource_src = rbug_resource(_blit_info->src.resource);
903 struct pipe_context *pipe = rb_pipe->pipe;
904 struct pipe_resource *dst = rb_resource_dst->resource;
905 struct pipe_resource *src = rb_resource_src->resource;
906 struct pipe_blit_info blit_info;
908 blit_info = *_blit_info;
909 blit_info.dst.resource = dst;
910 blit_info.src.resource = src;
912 pipe_mutex_lock(rb_pipe->call_mutex);
913 pipe->blit(pipe, &blit_info);
914 pipe_mutex_unlock(rb_pipe->call_mutex);
918 rbug_flush_resource(struct pipe_context *_pipe,
919 struct pipe_resource *_res)
921 struct rbug_context *rb_pipe = rbug_context(_pipe);
922 struct rbug_resource *rb_resource_res = rbug_resource(_res);
923 struct pipe_context *pipe = rb_pipe->pipe;
924 struct pipe_resource *res = rb_resource_res->resource;
926 pipe_mutex_lock(rb_pipe->call_mutex);
927 pipe->flush_resource(pipe, res);
928 pipe_mutex_unlock(rb_pipe->call_mutex);
932 rbug_clear(struct pipe_context *_pipe,
934 const union pipe_color_union *color,
938 struct rbug_context *rb_pipe = rbug_context(_pipe);
939 struct pipe_context *pipe = rb_pipe->pipe;
941 pipe_mutex_lock(rb_pipe->call_mutex);
947 pipe_mutex_unlock(rb_pipe->call_mutex);
951 rbug_clear_render_target(struct pipe_context *_pipe,
952 struct pipe_surface *_dst,
953 const union pipe_color_union *color,
954 unsigned dstx, unsigned dsty,
955 unsigned width, unsigned height)
957 struct rbug_context *rb_pipe = rbug_context(_pipe);
958 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
959 struct pipe_context *pipe = rb_pipe->pipe;
960 struct pipe_surface *dst = rb_surface_dst->surface;
962 pipe_mutex_lock(rb_pipe->call_mutex);
963 pipe->clear_render_target(pipe,
970 pipe_mutex_unlock(rb_pipe->call_mutex);
974 rbug_clear_depth_stencil(struct pipe_context *_pipe,
975 struct pipe_surface *_dst,
976 unsigned clear_flags,
979 unsigned dstx, unsigned dsty,
980 unsigned width, unsigned height)
982 struct rbug_context *rb_pipe = rbug_context(_pipe);
983 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
984 struct pipe_context *pipe = rb_pipe->pipe;
985 struct pipe_surface *dst = rb_surface_dst->surface;
987 pipe_mutex_lock(rb_pipe->call_mutex);
988 pipe->clear_depth_stencil(pipe,
997 pipe_mutex_unlock(rb_pipe->call_mutex);
1001 rbug_flush(struct pipe_context *_pipe,
1002 struct pipe_fence_handle **fence,
1005 struct rbug_context *rb_pipe = rbug_context(_pipe);
1006 struct pipe_context *pipe = rb_pipe->pipe;
1008 pipe_mutex_lock(rb_pipe->call_mutex);
1009 pipe->flush(pipe, fence, flags);
1010 pipe_mutex_unlock(rb_pipe->call_mutex);
1013 static struct pipe_sampler_view *
1014 rbug_context_create_sampler_view(struct pipe_context *_pipe,
1015 struct pipe_resource *_resource,
1016 const struct pipe_sampler_view *templ)
1018 struct rbug_context *rb_pipe = rbug_context(_pipe);
1019 struct rbug_resource *rb_resource = rbug_resource(_resource);
1020 struct pipe_context *pipe = rb_pipe->pipe;
1021 struct pipe_resource *resource = rb_resource->resource;
1022 struct pipe_sampler_view *result;
1024 pipe_mutex_lock(rb_pipe->call_mutex);
1025 result = pipe->create_sampler_view(pipe,
1028 pipe_mutex_unlock(rb_pipe->call_mutex);
1031 return rbug_sampler_view_create(rb_pipe, rb_resource, result);
1036 rbug_context_sampler_view_destroy(struct pipe_context *_pipe,
1037 struct pipe_sampler_view *_view)
1039 rbug_sampler_view_destroy(rbug_context(_pipe),
1040 rbug_sampler_view(_view));
1043 static struct pipe_surface *
1044 rbug_context_create_surface(struct pipe_context *_pipe,
1045 struct pipe_resource *_resource,
1046 const struct pipe_surface *surf_tmpl)
1048 struct rbug_context *rb_pipe = rbug_context(_pipe);
1049 struct rbug_resource *rb_resource = rbug_resource(_resource);
1050 struct pipe_context *pipe = rb_pipe->pipe;
1051 struct pipe_resource *resource = rb_resource->resource;
1052 struct pipe_surface *result;
1054 pipe_mutex_lock(rb_pipe->call_mutex);
1055 result = pipe->create_surface(pipe,
1058 pipe_mutex_unlock(rb_pipe->call_mutex);
1061 return rbug_surface_create(rb_pipe, rb_resource, result);
1066 rbug_context_surface_destroy(struct pipe_context *_pipe,
1067 struct pipe_surface *_surface)
1069 struct rbug_context *rb_pipe = rbug_context(_pipe);
1070 struct rbug_surface *rb_surface = rbug_surface(_surface);
1072 pipe_mutex_lock(rb_pipe->call_mutex);
1073 rbug_surface_destroy(rb_pipe,
1075 pipe_mutex_unlock(rb_pipe->call_mutex);
1081 rbug_context_transfer_map(struct pipe_context *_context,
1082 struct pipe_resource *_resource,
1085 const struct pipe_box *box,
1086 struct pipe_transfer **transfer)
1088 struct rbug_context *rb_pipe = rbug_context(_context);
1089 struct rbug_resource *rb_resource = rbug_resource(_resource);
1090 struct pipe_context *context = rb_pipe->pipe;
1091 struct pipe_resource *resource = rb_resource->resource;
1092 struct pipe_transfer *result;
1095 pipe_mutex_lock(rb_pipe->call_mutex);
1096 map = context->transfer_map(context,
1101 pipe_mutex_unlock(rb_pipe->call_mutex);
1103 *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
1104 return *transfer ? map : NULL;
1108 rbug_context_transfer_flush_region(struct pipe_context *_context,
1109 struct pipe_transfer *_transfer,
1110 const struct pipe_box *box)
1112 struct rbug_context *rb_pipe = rbug_context(_context);
1113 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1114 struct pipe_context *context = rb_pipe->pipe;
1115 struct pipe_transfer *transfer = rb_transfer->transfer;
1117 pipe_mutex_lock(rb_pipe->call_mutex);
1118 context->transfer_flush_region(context,
1121 pipe_mutex_unlock(rb_pipe->call_mutex);
1126 rbug_context_transfer_unmap(struct pipe_context *_context,
1127 struct pipe_transfer *_transfer)
1129 struct rbug_context *rb_pipe = rbug_context(_context);
1130 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1131 struct pipe_context *context = rb_pipe->pipe;
1132 struct pipe_transfer *transfer = rb_transfer->transfer;
1134 pipe_mutex_lock(rb_pipe->call_mutex);
1135 context->transfer_unmap(context,
1137 rbug_transfer_destroy(rb_pipe,
1139 pipe_mutex_unlock(rb_pipe->call_mutex);
1144 rbug_context_transfer_inline_write(struct pipe_context *_context,
1145 struct pipe_resource *_resource,
1148 const struct pipe_box *box,
1151 unsigned layer_stride)
1153 struct rbug_context *rb_pipe = rbug_context(_context);
1154 struct rbug_resource *rb_resource = rbug_resource(_resource);
1155 struct pipe_context *context = rb_pipe->pipe;
1156 struct pipe_resource *resource = rb_resource->resource;
1158 pipe_mutex_lock(rb_pipe->call_mutex);
1159 context->transfer_inline_write(context,
1167 pipe_mutex_unlock(rb_pipe->call_mutex);
1171 struct pipe_context *
1172 rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
1174 struct rbug_context *rb_pipe;
1175 struct rbug_screen *rb_screen = rbug_screen(_screen);
1180 rb_pipe = CALLOC_STRUCT(rbug_context);
1184 pipe_mutex_init(rb_pipe->draw_mutex);
1185 pipe_condvar_init(rb_pipe->draw_cond);
1186 pipe_mutex_init(rb_pipe->call_mutex);
1187 pipe_mutex_init(rb_pipe->list_mutex);
1188 make_empty_list(&rb_pipe->shaders);
1190 rb_pipe->base.screen = _screen;
1191 rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
1192 rb_pipe->base.draw = NULL;
1194 rb_pipe->base.destroy = rbug_destroy;
1195 rb_pipe->base.draw_vbo = rbug_draw_vbo;
1196 rb_pipe->base.create_query = rbug_create_query;
1197 rb_pipe->base.destroy_query = rbug_destroy_query;
1198 rb_pipe->base.begin_query = rbug_begin_query;
1199 rb_pipe->base.end_query = rbug_end_query;
1200 rb_pipe->base.get_query_result = rbug_get_query_result;
1201 rb_pipe->base.set_active_query_state = rbug_set_active_query_state;
1202 rb_pipe->base.create_blend_state = rbug_create_blend_state;
1203 rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
1204 rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
1205 rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
1206 rb_pipe->base.bind_sampler_states = rbug_bind_sampler_states;
1207 rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
1208 rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
1209 rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
1210 rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state;
1211 rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state;
1212 rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state;
1213 rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state;
1214 rb_pipe->base.create_fs_state = rbug_create_fs_state;
1215 rb_pipe->base.bind_fs_state = rbug_bind_fs_state;
1216 rb_pipe->base.delete_fs_state = rbug_delete_fs_state;
1217 rb_pipe->base.create_vs_state = rbug_create_vs_state;
1218 rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
1219 rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
1220 rb_pipe->base.create_gs_state = rbug_create_gs_state;
1221 rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
1222 rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
1223 rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
1224 rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
1225 rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
1226 rb_pipe->base.set_blend_color = rbug_set_blend_color;
1227 rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref;
1228 rb_pipe->base.set_clip_state = rbug_set_clip_state;
1229 rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
1230 rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
1231 rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
1232 rb_pipe->base.set_scissor_states = rbug_set_scissor_states;
1233 rb_pipe->base.set_viewport_states = rbug_set_viewport_states;
1234 rb_pipe->base.set_sampler_views = rbug_set_sampler_views;
1235 rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
1236 rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
1237 rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
1238 rb_pipe->base.create_stream_output_target = rbug_create_stream_output_target;
1239 rb_pipe->base.stream_output_target_destroy = rbug_stream_output_target_destroy;
1240 rb_pipe->base.set_stream_output_targets = rbug_set_stream_output_targets;
1241 rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
1242 rb_pipe->base.blit = rbug_blit;
1243 rb_pipe->base.flush_resource = rbug_flush_resource;
1244 rb_pipe->base.clear = rbug_clear;
1245 rb_pipe->base.clear_render_target = rbug_clear_render_target;
1246 rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
1247 rb_pipe->base.flush = rbug_flush;
1248 rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
1249 rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
1250 rb_pipe->base.create_surface = rbug_context_create_surface;
1251 rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
1252 rb_pipe->base.transfer_map = rbug_context_transfer_map;
1253 rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
1254 rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
1255 rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write;
1257 rb_pipe->pipe = pipe;
1259 rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
1261 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) {
1262 rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE;
1265 return &rb_pipe->base;