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;
65 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
66 (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs,
67 (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs,
68 (void *) rb_pipe->draw_rule.surf, 0,
69 (void *) rb_pipe->draw_rule.texture, 0);
70 if (rb_pipe->draw_rule.fs &&
71 rb_pipe->draw_rule.fs == rb_pipe->curr.fs)
73 if (rb_pipe->draw_rule.vs &&
74 rb_pipe->draw_rule.vs == rb_pipe->curr.vs)
76 if (rb_pipe->draw_rule.surf &&
77 rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
79 if (rb_pipe->draw_rule.surf)
80 for (k = 0; k < rb_pipe->curr.nr_cbufs; k++)
81 if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
83 if (rb_pipe->draw_rule.texture) {
84 for (k = 0; k < rb_pipe->curr.num_fs_views; k++)
85 if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k])
87 for (k = 0; k < rb_pipe->curr.num_vs_views; k++) {
88 if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) {
95 rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
98 if (rb_pipe->draw_blocked)
99 rbug_notify_draw_blocked(rb_pipe);
101 /* wait for rbug to clear the blocked flag */
102 while (rb_pipe->draw_blocked & flag) {
103 rb_pipe->draw_blocked |= flag;
104 pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
110 rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
112 struct rbug_context *rb_pipe = rbug_context(_pipe);
113 struct pipe_context *pipe = rb_pipe->pipe;
115 pipe_mutex_lock(rb_pipe->draw_mutex);
116 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
118 pipe_mutex_lock(rb_pipe->call_mutex);
119 if (!(rb_pipe->curr.fs && rb_pipe->curr.fs->disabled) &&
120 !(rb_pipe->curr.gs && rb_pipe->curr.gs->disabled) &&
121 !(rb_pipe->curr.vs && rb_pipe->curr.vs->disabled))
122 pipe->draw_vbo(pipe, info);
123 pipe_mutex_unlock(rb_pipe->call_mutex);
125 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
126 pipe_mutex_unlock(rb_pipe->draw_mutex);
129 static struct pipe_query *
130 rbug_create_query(struct pipe_context *_pipe,
133 struct rbug_context *rb_pipe = rbug_context(_pipe);
134 struct pipe_context *pipe = rb_pipe->pipe;
136 pipe_mutex_lock(rb_pipe->call_mutex);
137 return pipe->create_query(pipe,
139 pipe_mutex_unlock(rb_pipe->call_mutex);
143 rbug_destroy_query(struct pipe_context *_pipe,
144 struct pipe_query *query)
146 struct rbug_context *rb_pipe = rbug_context(_pipe);
147 struct pipe_context *pipe = rb_pipe->pipe;
149 pipe_mutex_lock(rb_pipe->call_mutex);
150 pipe->destroy_query(pipe,
152 pipe_mutex_unlock(rb_pipe->call_mutex);
156 rbug_begin_query(struct pipe_context *_pipe,
157 struct pipe_query *query)
159 struct rbug_context *rb_pipe = rbug_context(_pipe);
160 struct pipe_context *pipe = rb_pipe->pipe;
162 pipe_mutex_lock(rb_pipe->call_mutex);
163 pipe->begin_query(pipe,
165 pipe_mutex_unlock(rb_pipe->call_mutex);
169 rbug_end_query(struct pipe_context *_pipe,
170 struct pipe_query *query)
172 struct rbug_context *rb_pipe = rbug_context(_pipe);
173 struct pipe_context *pipe = rb_pipe->pipe;
175 pipe_mutex_lock(rb_pipe->call_mutex);
176 pipe->end_query(pipe,
178 pipe_mutex_unlock(rb_pipe->call_mutex);
182 rbug_get_query_result(struct pipe_context *_pipe,
183 struct pipe_query *query,
187 struct rbug_context *rb_pipe = rbug_context(_pipe);
188 struct pipe_context *pipe = rb_pipe->pipe;
191 pipe_mutex_lock(rb_pipe->call_mutex);
192 ret = pipe->get_query_result(pipe,
196 pipe_mutex_unlock(rb_pipe->call_mutex);
202 rbug_create_blend_state(struct pipe_context *_pipe,
203 const struct pipe_blend_state *blend)
205 struct rbug_context *rb_pipe = rbug_context(_pipe);
206 struct pipe_context *pipe = rb_pipe->pipe;
209 pipe_mutex_lock(rb_pipe->call_mutex);
210 ret = pipe->create_blend_state(pipe,
212 pipe_mutex_unlock(rb_pipe->call_mutex);
218 rbug_bind_blend_state(struct pipe_context *_pipe,
221 struct rbug_context *rb_pipe = rbug_context(_pipe);
222 struct pipe_context *pipe = rb_pipe->pipe;
224 pipe_mutex_lock(rb_pipe->call_mutex);
225 pipe->bind_blend_state(pipe,
227 pipe_mutex_unlock(rb_pipe->call_mutex);
231 rbug_delete_blend_state(struct pipe_context *_pipe,
234 struct rbug_context *rb_pipe = rbug_context(_pipe);
235 struct pipe_context *pipe = rb_pipe->pipe;
237 pipe_mutex_lock(rb_pipe->call_mutex);
238 pipe->delete_blend_state(pipe,
240 pipe_mutex_unlock(rb_pipe->call_mutex);
244 rbug_create_sampler_state(struct pipe_context *_pipe,
245 const struct pipe_sampler_state *sampler)
247 struct rbug_context *rb_pipe = rbug_context(_pipe);
248 struct pipe_context *pipe = rb_pipe->pipe;
251 pipe_mutex_lock(rb_pipe->call_mutex);
252 ret = pipe->create_sampler_state(pipe,
254 pipe_mutex_unlock(rb_pipe->call_mutex);
260 rbug_bind_fragment_sampler_states(struct pipe_context *_pipe,
261 unsigned num_samplers,
264 struct rbug_context *rb_pipe = rbug_context(_pipe);
265 struct pipe_context *pipe = rb_pipe->pipe;
267 pipe_mutex_lock(rb_pipe->call_mutex);
268 pipe->bind_fragment_sampler_states(pipe,
271 pipe_mutex_unlock(rb_pipe->call_mutex);
275 rbug_bind_vertex_sampler_states(struct pipe_context *_pipe,
276 unsigned num_samplers,
279 struct rbug_context *rb_pipe = rbug_context(_pipe);
280 struct pipe_context *pipe = rb_pipe->pipe;
282 pipe_mutex_lock(rb_pipe->call_mutex);
283 pipe->bind_vertex_sampler_states(pipe,
286 pipe_mutex_unlock(rb_pipe->call_mutex);
290 rbug_delete_sampler_state(struct pipe_context *_pipe,
293 struct rbug_context *rb_pipe = rbug_context(_pipe);
294 struct pipe_context *pipe = rb_pipe->pipe;
296 pipe_mutex_lock(rb_pipe->call_mutex);
297 pipe->delete_sampler_state(pipe,
299 pipe_mutex_unlock(rb_pipe->call_mutex);
303 rbug_create_rasterizer_state(struct pipe_context *_pipe,
304 const struct pipe_rasterizer_state *rasterizer)
306 struct rbug_context *rb_pipe = rbug_context(_pipe);
307 struct pipe_context *pipe = rb_pipe->pipe;
310 pipe_mutex_lock(rb_pipe->call_mutex);
311 ret = pipe->create_rasterizer_state(pipe,
313 pipe_mutex_unlock(rb_pipe->call_mutex);
319 rbug_bind_rasterizer_state(struct pipe_context *_pipe,
322 struct rbug_context *rb_pipe = rbug_context(_pipe);
323 struct pipe_context *pipe = rb_pipe->pipe;
325 pipe_mutex_lock(rb_pipe->call_mutex);
326 pipe->bind_rasterizer_state(pipe,
328 pipe_mutex_unlock(rb_pipe->call_mutex);
332 rbug_delete_rasterizer_state(struct pipe_context *_pipe,
335 struct rbug_context *rb_pipe = rbug_context(_pipe);
336 struct pipe_context *pipe = rb_pipe->pipe;
338 pipe_mutex_lock(rb_pipe->call_mutex);
339 pipe->delete_rasterizer_state(pipe,
341 pipe_mutex_unlock(rb_pipe->call_mutex);
345 rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
346 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
348 struct rbug_context *rb_pipe = rbug_context(_pipe);
349 struct pipe_context *pipe = rb_pipe->pipe;
352 pipe_mutex_lock(rb_pipe->call_mutex);
353 ret = pipe->create_depth_stencil_alpha_state(pipe,
354 depth_stencil_alpha);
355 pipe_mutex_unlock(rb_pipe->call_mutex);
361 rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
362 void *depth_stencil_alpha)
364 struct rbug_context *rb_pipe = rbug_context(_pipe);
365 struct pipe_context *pipe = rb_pipe->pipe;
367 pipe_mutex_lock(rb_pipe->call_mutex);
368 pipe->bind_depth_stencil_alpha_state(pipe,
369 depth_stencil_alpha);
370 pipe_mutex_unlock(rb_pipe->call_mutex);
374 rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
375 void *depth_stencil_alpha)
377 struct rbug_context *rb_pipe = rbug_context(_pipe);
378 struct pipe_context *pipe = rb_pipe->pipe;
380 pipe_mutex_lock(rb_pipe->call_mutex);
381 pipe->delete_depth_stencil_alpha_state(pipe,
382 depth_stencil_alpha);
383 pipe_mutex_unlock(rb_pipe->call_mutex);
387 rbug_create_fs_state(struct pipe_context *_pipe,
388 const struct pipe_shader_state *state)
390 struct rbug_context *rb_pipe = rbug_context(_pipe);
391 struct pipe_context *pipe = rb_pipe->pipe;
394 pipe_mutex_lock(rb_pipe->call_mutex);
395 result = pipe->create_fs_state(pipe, state);
396 pipe_mutex_unlock(rb_pipe->call_mutex);
401 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
405 rbug_bind_fs_state(struct pipe_context *_pipe,
408 struct rbug_context *rb_pipe = rbug_context(_pipe);
409 struct pipe_context *pipe = rb_pipe->pipe;
412 pipe_mutex_lock(rb_pipe->call_mutex);
414 fs = rbug_shader_unwrap(_fs);
415 rb_pipe->curr.fs = rbug_shader(_fs);
416 pipe->bind_fs_state(pipe,
419 pipe_mutex_unlock(rb_pipe->call_mutex);
423 rbug_delete_fs_state(struct pipe_context *_pipe,
426 struct rbug_context *rb_pipe = rbug_context(_pipe);
427 struct rbug_shader *rb_shader = rbug_shader(_fs);
429 pipe_mutex_lock(rb_pipe->call_mutex);
430 rbug_shader_destroy(rb_pipe, rb_shader);
431 pipe_mutex_unlock(rb_pipe->call_mutex);
435 rbug_create_vs_state(struct pipe_context *_pipe,
436 const struct pipe_shader_state *state)
438 struct rbug_context *rb_pipe = rbug_context(_pipe);
439 struct pipe_context *pipe = rb_pipe->pipe;
442 pipe_mutex_lock(rb_pipe->call_mutex);
443 result = pipe->create_vs_state(pipe, state);
444 pipe_mutex_unlock(rb_pipe->call_mutex);
449 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
453 rbug_bind_vs_state(struct pipe_context *_pipe,
456 struct rbug_context *rb_pipe = rbug_context(_pipe);
457 struct pipe_context *pipe = rb_pipe->pipe;
460 pipe_mutex_lock(rb_pipe->call_mutex);
462 vs = rbug_shader_unwrap(_vs);
463 rb_pipe->curr.vs = rbug_shader(_vs);
464 pipe->bind_vs_state(pipe,
467 pipe_mutex_unlock(rb_pipe->call_mutex);
471 rbug_delete_vs_state(struct pipe_context *_pipe,
474 struct rbug_context *rb_pipe = rbug_context(_pipe);
475 struct rbug_shader *rb_shader = rbug_shader(_vs);
477 pipe_mutex_unlock(rb_pipe->call_mutex);
478 rbug_shader_destroy(rb_pipe, rb_shader);
479 pipe_mutex_unlock(rb_pipe->call_mutex);
483 rbug_create_gs_state(struct pipe_context *_pipe,
484 const struct pipe_shader_state *state)
486 struct rbug_context *rb_pipe = rbug_context(_pipe);
487 struct pipe_context *pipe = rb_pipe->pipe;
490 pipe_mutex_lock(rb_pipe->call_mutex);
491 result = pipe->create_gs_state(pipe, state);
492 pipe_mutex_unlock(rb_pipe->call_mutex);
497 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
501 rbug_bind_gs_state(struct pipe_context *_pipe,
504 struct rbug_context *rb_pipe = rbug_context(_pipe);
505 struct pipe_context *pipe = rb_pipe->pipe;
508 pipe_mutex_lock(rb_pipe->call_mutex);
510 gs = rbug_shader_unwrap(_gs);
511 rb_pipe->curr.gs = rbug_shader(_gs);
512 pipe->bind_gs_state(pipe,
515 pipe_mutex_unlock(rb_pipe->call_mutex);
519 rbug_delete_gs_state(struct pipe_context *_pipe,
522 struct rbug_context *rb_pipe = rbug_context(_pipe);
523 struct rbug_shader *rb_shader = rbug_shader(_gs);
525 pipe_mutex_lock(rb_pipe->call_mutex);
526 rbug_shader_destroy(rb_pipe, rb_shader);
527 pipe_mutex_unlock(rb_pipe->call_mutex);
531 rbug_create_vertex_elements_state(struct pipe_context *_pipe,
532 unsigned num_elements,
533 const struct pipe_vertex_element *vertex_elements)
535 struct rbug_context *rb_pipe = rbug_context(_pipe);
536 struct pipe_context *pipe = rb_pipe->pipe;
539 pipe_mutex_lock(rb_pipe->call_mutex);
540 ret = pipe->create_vertex_elements_state(pipe,
543 pipe_mutex_unlock(rb_pipe->call_mutex);
549 rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
552 struct rbug_context *rb_pipe = rbug_context(_pipe);
553 struct pipe_context *pipe = rb_pipe->pipe;
555 pipe_mutex_lock(rb_pipe->call_mutex);
556 pipe->bind_vertex_elements_state(pipe,
558 pipe_mutex_unlock(rb_pipe->call_mutex);
562 rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
565 struct rbug_context *rb_pipe = rbug_context(_pipe);
566 struct pipe_context *pipe = rb_pipe->pipe;
568 pipe_mutex_lock(rb_pipe->call_mutex);
569 pipe->delete_vertex_elements_state(pipe,
571 pipe_mutex_unlock(rb_pipe->call_mutex);
575 rbug_set_blend_color(struct pipe_context *_pipe,
576 const struct pipe_blend_color *blend_color)
578 struct rbug_context *rb_pipe = rbug_context(_pipe);
579 struct pipe_context *pipe = rb_pipe->pipe;
581 pipe_mutex_lock(rb_pipe->call_mutex);
582 pipe->set_blend_color(pipe,
584 pipe_mutex_unlock(rb_pipe->call_mutex);
588 rbug_set_stencil_ref(struct pipe_context *_pipe,
589 const struct pipe_stencil_ref *stencil_ref)
591 struct rbug_context *rb_pipe = rbug_context(_pipe);
592 struct pipe_context *pipe = rb_pipe->pipe;
594 pipe_mutex_lock(rb_pipe->call_mutex);
595 pipe->set_stencil_ref(pipe,
597 pipe_mutex_unlock(rb_pipe->call_mutex);
601 rbug_set_clip_state(struct pipe_context *_pipe,
602 const struct pipe_clip_state *clip)
604 struct rbug_context *rb_pipe = rbug_context(_pipe);
605 struct pipe_context *pipe = rb_pipe->pipe;
607 pipe_mutex_lock(rb_pipe->call_mutex);
608 pipe->set_clip_state(pipe,
610 pipe_mutex_unlock(rb_pipe->call_mutex);
614 rbug_set_constant_buffer(struct pipe_context *_pipe,
617 struct pipe_resource *_resource)
619 struct rbug_context *rb_pipe = rbug_context(_pipe);
620 struct pipe_context *pipe = rb_pipe->pipe;
621 struct pipe_resource *unwrapped_resource;
622 struct pipe_resource *resource = NULL;
624 /* XXX hmm? unwrap the input state */
626 unwrapped_resource = rbug_resource_unwrap(_resource);
627 resource = unwrapped_resource;
630 pipe_mutex_lock(rb_pipe->call_mutex);
631 pipe->set_constant_buffer(pipe,
635 pipe_mutex_unlock(rb_pipe->call_mutex);
639 rbug_set_framebuffer_state(struct pipe_context *_pipe,
640 const struct pipe_framebuffer_state *_state)
642 struct rbug_context *rb_pipe = rbug_context(_pipe);
643 struct pipe_context *pipe = rb_pipe->pipe;
644 struct pipe_framebuffer_state unwrapped_state;
645 struct pipe_framebuffer_state *state = NULL;
648 /* must protect curr status */
649 pipe_mutex_lock(rb_pipe->call_mutex);
651 rb_pipe->curr.nr_cbufs = 0;
652 memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
653 rb_pipe->curr.zsbuf = NULL;
655 /* unwrap the input state */
657 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
659 rb_pipe->curr.nr_cbufs = _state->nr_cbufs;
660 for(i = 0; i < _state->nr_cbufs; i++) {
661 unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]);
662 if (_state->cbufs[i])
663 rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
665 unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
667 rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
668 state = &unwrapped_state;
671 pipe->set_framebuffer_state(pipe,
674 pipe_mutex_unlock(rb_pipe->call_mutex);
678 rbug_set_polygon_stipple(struct pipe_context *_pipe,
679 const struct pipe_poly_stipple *poly_stipple)
681 struct rbug_context *rb_pipe = rbug_context(_pipe);
682 struct pipe_context *pipe = rb_pipe->pipe;
684 pipe_mutex_lock(rb_pipe->call_mutex);
685 pipe->set_polygon_stipple(pipe,
687 pipe_mutex_unlock(rb_pipe->call_mutex);
691 rbug_set_scissor_state(struct pipe_context *_pipe,
692 const struct pipe_scissor_state *scissor)
694 struct rbug_context *rb_pipe = rbug_context(_pipe);
695 struct pipe_context *pipe = rb_pipe->pipe;
697 pipe_mutex_lock(rb_pipe->call_mutex);
698 pipe->set_scissor_state(pipe,
700 pipe_mutex_unlock(rb_pipe->call_mutex);
704 rbug_set_viewport_state(struct pipe_context *_pipe,
705 const struct pipe_viewport_state *viewport)
707 struct rbug_context *rb_pipe = rbug_context(_pipe);
708 struct pipe_context *pipe = rb_pipe->pipe;
710 pipe_mutex_lock(rb_pipe->call_mutex);
711 pipe->set_viewport_state(pipe,
713 pipe_mutex_unlock(rb_pipe->call_mutex);
717 rbug_set_fragment_sampler_views(struct pipe_context *_pipe,
719 struct pipe_sampler_view **_views)
721 struct rbug_context *rb_pipe = rbug_context(_pipe);
722 struct pipe_context *pipe = rb_pipe->pipe;
723 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
724 struct pipe_sampler_view **views = NULL;
727 /* must protect curr status */
728 pipe_mutex_lock(rb_pipe->call_mutex);
730 rb_pipe->curr.num_fs_views = 0;
731 memset(rb_pipe->curr.fs_views, 0, sizeof(rb_pipe->curr.fs_views));
732 memset(rb_pipe->curr.fs_texs, 0, sizeof(rb_pipe->curr.fs_texs));
733 memset(unwrapped_views, 0, sizeof(unwrapped_views));
736 rb_pipe->curr.num_fs_views = num;
737 for (i = 0; i < num; i++) {
738 rb_pipe->curr.fs_views[i] = rbug_sampler_view(_views[i]);
739 rb_pipe->curr.fs_texs[i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
740 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
742 views = unwrapped_views;
745 pipe->set_fragment_sampler_views(pipe, num, views);
747 pipe_mutex_unlock(rb_pipe->call_mutex);
751 rbug_set_vertex_sampler_views(struct pipe_context *_pipe,
753 struct pipe_sampler_view **_views)
755 struct rbug_context *rb_pipe = rbug_context(_pipe);
756 struct pipe_context *pipe = rb_pipe->pipe;
757 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
758 struct pipe_sampler_view **views = NULL;
761 /* must protect curr status */
762 pipe_mutex_lock(rb_pipe->call_mutex);
764 rb_pipe->curr.num_vs_views = 0;
765 memset(rb_pipe->curr.vs_views, 0, sizeof(rb_pipe->curr.vs_views));
766 memset(rb_pipe->curr.vs_texs, 0, sizeof(rb_pipe->curr.vs_texs));
767 memset(unwrapped_views, 0, sizeof(unwrapped_views));
770 rb_pipe->curr.num_vs_views = num;
771 for (i = 0; i < num; i++) {
772 rb_pipe->curr.vs_views[i] = rbug_sampler_view(_views[i]);
773 rb_pipe->curr.vs_texs[i] = rbug_resource(_views[i]->texture);
774 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
776 views = unwrapped_views;
779 pipe->set_vertex_sampler_views(pipe, num, views);
781 pipe_mutex_unlock(rb_pipe->call_mutex);
785 rbug_set_vertex_buffers(struct pipe_context *_pipe,
786 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,
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,
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,
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)
946 struct rbug_context *rb_pipe = rbug_context(_pipe);
947 struct pipe_context *pipe = rb_pipe->pipe;
949 pipe_mutex_lock(rb_pipe->call_mutex);
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);
1022 static struct pipe_transfer *
1023 rbug_context_get_transfer(struct pipe_context *_context,
1024 struct pipe_resource *_resource,
1027 const struct pipe_box *box)
1029 struct rbug_context *rb_pipe = rbug_context(_context);
1030 struct rbug_resource *rb_resource = rbug_resource(_resource);
1031 struct pipe_context *context = rb_pipe->pipe;
1032 struct pipe_resource *resource = rb_resource->resource;
1033 struct pipe_transfer *result;
1035 pipe_mutex_lock(rb_pipe->call_mutex);
1036 result = context->get_transfer(context,
1041 pipe_mutex_unlock(rb_pipe->call_mutex);
1044 return rbug_transfer_create(rb_pipe, rb_resource, result);
1049 rbug_context_transfer_destroy(struct pipe_context *_pipe,
1050 struct pipe_transfer *_transfer)
1052 struct rbug_context *rb_pipe = rbug_context(_pipe);
1053 struct rbug_transfer *rb_transfer =rbug_transfer(_transfer);
1055 pipe_mutex_lock(rb_pipe->call_mutex);
1056 rbug_transfer_destroy(rb_pipe,
1058 pipe_mutex_unlock(rb_pipe->call_mutex);
1062 rbug_context_transfer_map(struct pipe_context *_context,
1063 struct pipe_transfer *_transfer)
1065 struct rbug_context *rb_pipe = rbug_context(_context);
1066 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1067 struct pipe_context *context = rb_pipe->pipe;
1068 struct pipe_transfer *transfer = rb_transfer->transfer;
1071 pipe_mutex_lock(rb_pipe->call_mutex);
1072 ret = context->transfer_map(context,
1074 pipe_mutex_unlock(rb_pipe->call_mutex);
1082 rbug_context_transfer_flush_region(struct pipe_context *_context,
1083 struct pipe_transfer *_transfer,
1084 const struct pipe_box *box)
1086 struct rbug_context *rb_pipe = rbug_context(_context);
1087 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1088 struct pipe_context *context = rb_pipe->pipe;
1089 struct pipe_transfer *transfer = rb_transfer->transfer;
1091 pipe_mutex_lock(rb_pipe->call_mutex);
1092 context->transfer_flush_region(context,
1095 pipe_mutex_unlock(rb_pipe->call_mutex);
1100 rbug_context_transfer_unmap(struct pipe_context *_context,
1101 struct pipe_transfer *_transfer)
1103 struct rbug_context *rb_pipe = rbug_context(_context);
1104 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1105 struct pipe_context *context = rb_pipe->pipe;
1106 struct pipe_transfer *transfer = rb_transfer->transfer;
1108 pipe_mutex_lock(rb_pipe->call_mutex);
1109 context->transfer_unmap(context,
1111 pipe_mutex_unlock(rb_pipe->call_mutex);
1116 rbug_context_transfer_inline_write(struct pipe_context *_context,
1117 struct pipe_resource *_resource,
1120 const struct pipe_box *box,
1123 unsigned layer_stride)
1125 struct rbug_context *rb_pipe = rbug_context(_context);
1126 struct rbug_resource *rb_resource = rbug_resource(_resource);
1127 struct pipe_context *context = rb_pipe->pipe;
1128 struct pipe_resource *resource = rb_resource->resource;
1130 pipe_mutex_lock(rb_pipe->call_mutex);
1131 context->transfer_inline_write(context,
1139 pipe_mutex_unlock(rb_pipe->call_mutex);
1143 static void rbug_redefine_user_buffer(struct pipe_context *_context,
1144 struct pipe_resource *_resource,
1145 unsigned offset, unsigned size)
1147 struct rbug_context *rb_pipe = rbug_context(_context);
1148 struct rbug_resource *rb_resource = rbug_resource(_resource);
1149 struct pipe_context *context = rb_pipe->pipe;
1150 struct pipe_resource *resource = rb_resource->resource;
1152 pipe_mutex_lock(rb_pipe->call_mutex);
1153 context->redefine_user_buffer(context, resource, offset, size);
1154 pipe_mutex_unlock(rb_pipe->call_mutex);
1158 struct pipe_context *
1159 rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
1161 struct rbug_context *rb_pipe;
1162 struct rbug_screen *rb_screen = rbug_screen(_screen);
1167 rb_pipe = CALLOC_STRUCT(rbug_context);
1171 pipe_mutex_init(rb_pipe->draw_mutex);
1172 pipe_condvar_init(rb_pipe->draw_cond);
1173 pipe_mutex_init(rb_pipe->call_mutex);
1174 pipe_mutex_init(rb_pipe->list_mutex);
1175 make_empty_list(&rb_pipe->shaders);
1177 rb_pipe->base.winsys = NULL;
1178 rb_pipe->base.screen = _screen;
1179 rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
1180 rb_pipe->base.draw = NULL;
1182 rb_pipe->base.destroy = rbug_destroy;
1183 rb_pipe->base.draw_vbo = rbug_draw_vbo;
1184 rb_pipe->base.create_query = rbug_create_query;
1185 rb_pipe->base.destroy_query = rbug_destroy_query;
1186 rb_pipe->base.begin_query = rbug_begin_query;
1187 rb_pipe->base.end_query = rbug_end_query;
1188 rb_pipe->base.get_query_result = rbug_get_query_result;
1189 rb_pipe->base.create_blend_state = rbug_create_blend_state;
1190 rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
1191 rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
1192 rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
1193 rb_pipe->base.bind_fragment_sampler_states = rbug_bind_fragment_sampler_states;
1194 rb_pipe->base.bind_vertex_sampler_states = rbug_bind_vertex_sampler_states;
1195 rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
1196 rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
1197 rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
1198 rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state;
1199 rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state;
1200 rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state;
1201 rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state;
1202 rb_pipe->base.create_fs_state = rbug_create_fs_state;
1203 rb_pipe->base.bind_fs_state = rbug_bind_fs_state;
1204 rb_pipe->base.delete_fs_state = rbug_delete_fs_state;
1205 rb_pipe->base.create_vs_state = rbug_create_vs_state;
1206 rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
1207 rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
1208 rb_pipe->base.create_gs_state = rbug_create_gs_state;
1209 rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
1210 rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
1211 rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
1212 rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
1213 rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
1214 rb_pipe->base.set_blend_color = rbug_set_blend_color;
1215 rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref;
1216 rb_pipe->base.set_clip_state = rbug_set_clip_state;
1217 rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
1218 rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
1219 rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
1220 rb_pipe->base.set_scissor_state = rbug_set_scissor_state;
1221 rb_pipe->base.set_viewport_state = rbug_set_viewport_state;
1222 rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views;
1223 rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views;
1224 rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
1225 rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
1226 rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
1227 rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
1228 rb_pipe->base.clear = rbug_clear;
1229 rb_pipe->base.clear_render_target = rbug_clear_render_target;
1230 rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
1231 rb_pipe->base.flush = rbug_flush;
1232 rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
1233 rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
1234 rb_pipe->base.create_surface = rbug_context_create_surface;
1235 rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
1236 rb_pipe->base.get_transfer = rbug_context_get_transfer;
1237 rb_pipe->base.transfer_destroy = rbug_context_transfer_destroy;
1238 rb_pipe->base.transfer_map = rbug_context_transfer_map;
1239 rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
1240 rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
1241 rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write;
1242 rb_pipe->base.redefine_user_buffer = rbug_redefine_user_buffer;
1244 rb_pipe->pipe = pipe;
1246 rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
1248 return &rb_pipe->base;