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
;
52 rbug_draw_block_locked(struct rbug_context
*rb_pipe
, int flag
)
55 if (rb_pipe
->draw_blocker
& flag
) {
56 rb_pipe
->draw_blocked
|= flag
;
57 } else if ((rb_pipe
->draw_rule
.blocker
& flag
) &&
58 (rb_pipe
->draw_blocker
& RBUG_BLOCK_RULE
)) {
60 boolean block
= FALSE
;
61 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__
,
62 (void *) rb_pipe
->draw_rule
.fs
, (void *) rb_pipe
->curr
.fs
,
63 (void *) rb_pipe
->draw_rule
.vs
, (void *) rb_pipe
->curr
.vs
,
64 (void *) rb_pipe
->draw_rule
.surf
, 0,
65 (void *) rb_pipe
->draw_rule
.texture
, 0);
66 if (rb_pipe
->draw_rule
.fs
&&
67 rb_pipe
->draw_rule
.fs
== rb_pipe
->curr
.fs
)
69 if (rb_pipe
->draw_rule
.vs
&&
70 rb_pipe
->draw_rule
.vs
== rb_pipe
->curr
.vs
)
72 if (rb_pipe
->draw_rule
.surf
&&
73 rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.zsbuf
)
75 if (rb_pipe
->draw_rule
.surf
)
76 for (k
= 0; k
< rb_pipe
->curr
.nr_cbufs
; k
++)
77 if (rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.cbufs
[k
])
79 if (rb_pipe
->draw_rule
.texture
) {
80 for (k
= 0; k
< rb_pipe
->curr
.num_fs_views
; k
++)
81 if (rb_pipe
->draw_rule
.texture
== rb_pipe
->curr
.fs_texs
[k
])
83 for (k
= 0; k
< rb_pipe
->curr
.num_vs_views
; k
++) {
84 if (rb_pipe
->draw_rule
.texture
== rb_pipe
->curr
.vs_texs
[k
]) {
91 rb_pipe
->draw_blocked
|= (flag
| RBUG_BLOCK_RULE
);
94 if (rb_pipe
->draw_blocked
)
95 rbug_notify_draw_blocked(rb_pipe
);
97 /* wait for rbug to clear the blocked flag */
98 while (rb_pipe
->draw_blocked
& flag
) {
99 rb_pipe
->draw_blocked
|= flag
;
100 #ifdef PIPE_THREAD_HAVE_CONDVAR
101 pipe_condvar_wait(rb_pipe
->draw_cond
, rb_pipe
->draw_mutex
);
103 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
104 #ifdef PIPE_SUBSYSTEM_WINDOWS_USER
107 pipe_mutex_lock(rb_pipe
->draw_mutex
);
114 rbug_draw_arrays(struct pipe_context
*_pipe
,
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
->draw_arrays(pipe
,
130 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
131 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
135 rbug_draw_elements(struct pipe_context
*_pipe
,
136 struct pipe_resource
*_indexResource
,
143 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
144 struct rbug_resource
*rb_resource
= rbug_resource(_indexResource
);
145 struct pipe_context
*pipe
= rb_pipe
->pipe
;
146 struct pipe_resource
*indexResource
= rb_resource
->resource
;
148 pipe_mutex_lock(rb_pipe
->draw_mutex
);
149 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_BEFORE
);
151 pipe
->draw_elements(pipe
,
159 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
160 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
164 rbug_draw_range_elements(struct pipe_context
*_pipe
,
165 struct pipe_resource
*_indexResource
,
174 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
175 struct rbug_resource
*rb_resource
= rbug_resource(_indexResource
);
176 struct pipe_context
*pipe
= rb_pipe
->pipe
;
177 struct pipe_resource
*indexResource
= rb_resource
->resource
;
179 pipe_mutex_lock(rb_pipe
->draw_mutex
);
180 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_BEFORE
);
182 pipe
->draw_range_elements(pipe
,
192 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
193 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
196 static struct pipe_query
*
197 rbug_create_query(struct pipe_context
*_pipe
,
200 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
201 struct pipe_context
*pipe
= rb_pipe
->pipe
;
203 return pipe
->create_query(pipe
,
208 rbug_destroy_query(struct pipe_context
*_pipe
,
209 struct pipe_query
*query
)
211 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
212 struct pipe_context
*pipe
= rb_pipe
->pipe
;
214 pipe
->destroy_query(pipe
,
219 rbug_begin_query(struct pipe_context
*_pipe
,
220 struct pipe_query
*query
)
222 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
223 struct pipe_context
*pipe
= rb_pipe
->pipe
;
225 pipe
->begin_query(pipe
,
230 rbug_end_query(struct pipe_context
*_pipe
,
231 struct pipe_query
*query
)
233 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
234 struct pipe_context
*pipe
= rb_pipe
->pipe
;
236 pipe
->end_query(pipe
,
241 rbug_get_query_result(struct pipe_context
*_pipe
,
242 struct pipe_query
*query
,
246 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
247 struct pipe_context
*pipe
= rb_pipe
->pipe
;
249 return pipe
->get_query_result(pipe
,
256 rbug_create_blend_state(struct pipe_context
*_pipe
,
257 const struct pipe_blend_state
*blend
)
259 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
260 struct pipe_context
*pipe
= rb_pipe
->pipe
;
262 return pipe
->create_blend_state(pipe
,
267 rbug_bind_blend_state(struct pipe_context
*_pipe
,
270 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
271 struct pipe_context
*pipe
= rb_pipe
->pipe
;
273 pipe
->bind_blend_state(pipe
,
278 rbug_delete_blend_state(struct pipe_context
*_pipe
,
281 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
282 struct pipe_context
*pipe
= rb_pipe
->pipe
;
284 pipe
->delete_blend_state(pipe
,
289 rbug_create_sampler_state(struct pipe_context
*_pipe
,
290 const struct pipe_sampler_state
*sampler
)
292 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
293 struct pipe_context
*pipe
= rb_pipe
->pipe
;
295 return pipe
->create_sampler_state(pipe
,
300 rbug_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
301 unsigned num_samplers
,
304 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
305 struct pipe_context
*pipe
= rb_pipe
->pipe
;
307 pipe
->bind_fragment_sampler_states(pipe
,
313 rbug_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
314 unsigned num_samplers
,
317 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
318 struct pipe_context
*pipe
= rb_pipe
->pipe
;
320 pipe
->bind_vertex_sampler_states(pipe
,
326 rbug_delete_sampler_state(struct pipe_context
*_pipe
,
329 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
330 struct pipe_context
*pipe
= rb_pipe
->pipe
;
332 pipe
->delete_sampler_state(pipe
,
337 rbug_create_rasterizer_state(struct pipe_context
*_pipe
,
338 const struct pipe_rasterizer_state
*rasterizer
)
340 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
341 struct pipe_context
*pipe
= rb_pipe
->pipe
;
343 return pipe
->create_rasterizer_state(pipe
,
348 rbug_bind_rasterizer_state(struct pipe_context
*_pipe
,
351 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
352 struct pipe_context
*pipe
= rb_pipe
->pipe
;
354 pipe
->bind_rasterizer_state(pipe
,
359 rbug_delete_rasterizer_state(struct pipe_context
*_pipe
,
362 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
363 struct pipe_context
*pipe
= rb_pipe
->pipe
;
365 pipe
->delete_rasterizer_state(pipe
,
370 rbug_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
371 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
373 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
374 struct pipe_context
*pipe
= rb_pipe
->pipe
;
376 return pipe
->create_depth_stencil_alpha_state(pipe
,
377 depth_stencil_alpha
);
381 rbug_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
382 void *depth_stencil_alpha
)
384 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
385 struct pipe_context
*pipe
= rb_pipe
->pipe
;
387 pipe
->bind_depth_stencil_alpha_state(pipe
,
388 depth_stencil_alpha
);
392 rbug_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
393 void *depth_stencil_alpha
)
395 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
396 struct pipe_context
*pipe
= rb_pipe
->pipe
;
398 pipe
->delete_depth_stencil_alpha_state(pipe
,
399 depth_stencil_alpha
);
403 rbug_create_fs_state(struct pipe_context
*_pipe
,
404 const struct pipe_shader_state
*state
)
406 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
407 struct pipe_context
*pipe
= rb_pipe
->pipe
;
410 result
= pipe
->create_fs_state(pipe
, state
);
414 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_FRAGMENT
);
418 rbug_bind_fs_state(struct pipe_context
*_pipe
,
421 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
422 struct pipe_context
*pipe
= rb_pipe
->pipe
;
425 fs
= rbug_shader_unwrap(_fs
);
426 rb_pipe
->curr
.fs
= rbug_shader(_fs
);
427 pipe
->bind_fs_state(pipe
,
432 rbug_delete_fs_state(struct pipe_context
*_pipe
,
435 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
436 struct rbug_shader
*rb_shader
= rbug_shader(_fs
);
438 rbug_shader_destroy(rb_pipe
, rb_shader
);
442 rbug_create_vs_state(struct pipe_context
*_pipe
,
443 const struct pipe_shader_state
*state
)
445 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
446 struct pipe_context
*pipe
= rb_pipe
->pipe
;
449 result
= pipe
->create_vs_state(pipe
, state
);
453 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_VERTEX
);
457 rbug_bind_vs_state(struct pipe_context
*_pipe
,
460 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
461 struct pipe_context
*pipe
= rb_pipe
->pipe
;
464 vs
= rbug_shader_unwrap(_vs
);
465 rb_pipe
->curr
.vs
= rbug_shader(_vs
);
466 pipe
->bind_vs_state(pipe
,
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 rbug_shader_destroy(rb_pipe
, rb_shader
);
481 rbug_create_gs_state(struct pipe_context
*_pipe
,
482 const struct pipe_shader_state
*state
)
484 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
485 struct pipe_context
*pipe
= rb_pipe
->pipe
;
488 result
= pipe
->create_gs_state(pipe
, state
);
492 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_GEOM
);
496 rbug_bind_gs_state(struct pipe_context
*_pipe
,
499 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
500 struct pipe_context
*pipe
= rb_pipe
->pipe
;
503 gs
= rbug_shader_unwrap(_gs
);
504 rb_pipe
->curr
.gs
= rbug_shader(_gs
);
505 pipe
->bind_gs_state(pipe
,
510 rbug_delete_gs_state(struct pipe_context
*_pipe
,
513 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
514 struct rbug_shader
*rb_shader
= rbug_shader(_gs
);
516 rbug_shader_destroy(rb_pipe
, rb_shader
);
520 rbug_create_vertex_elements_state(struct pipe_context
*_pipe
,
521 unsigned num_elements
,
522 const struct pipe_vertex_element
*vertex_elements
)
524 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
525 struct pipe_context
*pipe
= rb_pipe
->pipe
;
527 return pipe
->create_vertex_elements_state(pipe
,
533 rbug_bind_vertex_elements_state(struct pipe_context
*_pipe
,
536 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
537 struct pipe_context
*pipe
= rb_pipe
->pipe
;
539 pipe
->bind_vertex_elements_state(pipe
,
544 rbug_delete_vertex_elements_state(struct pipe_context
*_pipe
,
547 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
548 struct pipe_context
*pipe
= rb_pipe
->pipe
;
550 pipe
->delete_vertex_elements_state(pipe
,
555 rbug_set_blend_color(struct pipe_context
*_pipe
,
556 const struct pipe_blend_color
*blend_color
)
558 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
559 struct pipe_context
*pipe
= rb_pipe
->pipe
;
561 pipe
->set_blend_color(pipe
,
566 rbug_set_stencil_ref(struct pipe_context
*_pipe
,
567 const struct pipe_stencil_ref
*stencil_ref
)
569 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
570 struct pipe_context
*pipe
= rb_pipe
->pipe
;
572 pipe
->set_stencil_ref(pipe
,
577 rbug_set_clip_state(struct pipe_context
*_pipe
,
578 const struct pipe_clip_state
*clip
)
580 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
581 struct pipe_context
*pipe
= rb_pipe
->pipe
;
583 pipe
->set_clip_state(pipe
,
588 rbug_set_constant_buffer(struct pipe_context
*_pipe
,
591 struct pipe_resource
*_resource
)
593 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
594 struct pipe_context
*pipe
= rb_pipe
->pipe
;
595 struct pipe_resource
*unwrapped_resource
;
596 struct pipe_resource
*resource
= NULL
;
598 /* XXX hmm? unwrap the input state */
600 unwrapped_resource
= rbug_resource_unwrap(_resource
);
601 resource
= unwrapped_resource
;
604 pipe
->set_constant_buffer(pipe
,
611 rbug_set_framebuffer_state(struct pipe_context
*_pipe
,
612 const struct pipe_framebuffer_state
*_state
)
614 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
615 struct pipe_context
*pipe
= rb_pipe
->pipe
;
616 struct pipe_framebuffer_state unwrapped_state
;
617 struct pipe_framebuffer_state
*state
= NULL
;
620 rb_pipe
->curr
.nr_cbufs
= 0;
621 memset(rb_pipe
->curr
.cbufs
, 0, sizeof(rb_pipe
->curr
.cbufs
));
623 /* unwrap the input state */
625 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
627 rb_pipe
->curr
.nr_cbufs
= _state
->nr_cbufs
;
628 for(i
= 0; i
< _state
->nr_cbufs
; i
++) {
629 unwrapped_state
.cbufs
[i
] = rbug_surface_unwrap(_state
->cbufs
[i
]);
630 if (_state
->cbufs
[i
])
631 rb_pipe
->curr
.cbufs
[i
] = rbug_resource(_state
->cbufs
[i
]->texture
);
633 unwrapped_state
.zsbuf
= rbug_surface_unwrap(_state
->zsbuf
);
634 state
= &unwrapped_state
;
637 pipe
->set_framebuffer_state(pipe
,
642 rbug_set_polygon_stipple(struct pipe_context
*_pipe
,
643 const struct pipe_poly_stipple
*poly_stipple
)
645 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
646 struct pipe_context
*pipe
= rb_pipe
->pipe
;
648 pipe
->set_polygon_stipple(pipe
,
653 rbug_set_scissor_state(struct pipe_context
*_pipe
,
654 const struct pipe_scissor_state
*scissor
)
656 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
657 struct pipe_context
*pipe
= rb_pipe
->pipe
;
659 pipe
->set_scissor_state(pipe
,
664 rbug_set_viewport_state(struct pipe_context
*_pipe
,
665 const struct pipe_viewport_state
*viewport
)
667 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
668 struct pipe_context
*pipe
= rb_pipe
->pipe
;
670 pipe
->set_viewport_state(pipe
,
675 rbug_set_fragment_sampler_views(struct pipe_context
*_pipe
,
677 struct pipe_sampler_view
**_views
)
679 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
680 struct pipe_context
*pipe
= rb_pipe
->pipe
;
681 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
682 struct pipe_sampler_view
**views
= NULL
;
685 rb_pipe
->curr
.num_fs_views
= 0;
686 memset(rb_pipe
->curr
.fs_views
, 0, sizeof(rb_pipe
->curr
.fs_views
));
687 memset(rb_pipe
->curr
.fs_texs
, 0, sizeof(rb_pipe
->curr
.fs_texs
));
688 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
691 rb_pipe
->curr
.num_fs_views
= num
;
692 for (i
= 0; i
< num
; i
++) {
693 rb_pipe
->curr
.fs_views
[i
] = rbug_sampler_view(_views
[i
]);
694 rb_pipe
->curr
.fs_texs
[i
] = rbug_resource(_views
[i
] ? _views
[i
]->texture
: NULL
);
695 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
697 views
= unwrapped_views
;
700 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
704 rbug_set_vertex_sampler_views(struct pipe_context
*_pipe
,
706 struct pipe_sampler_view
**_views
)
708 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
709 struct pipe_context
*pipe
= rb_pipe
->pipe
;
710 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_VERTEX_SAMPLERS
];
711 struct pipe_sampler_view
**views
= NULL
;
714 rb_pipe
->curr
.num_vs_views
= 0;
715 memset(rb_pipe
->curr
.vs_views
, 0, sizeof(rb_pipe
->curr
.vs_views
));
716 memset(rb_pipe
->curr
.vs_texs
, 0, sizeof(rb_pipe
->curr
.vs_texs
));
717 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
720 rb_pipe
->curr
.num_vs_views
= num
;
721 for (i
= 0; i
< num
; i
++) {
722 rb_pipe
->curr
.vs_views
[i
] = rbug_sampler_view(_views
[i
]);
723 rb_pipe
->curr
.vs_texs
[i
] = rbug_resource(_views
[i
]->texture
);
724 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
726 views
= unwrapped_views
;
729 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
733 rbug_set_vertex_buffers(struct pipe_context
*_pipe
,
734 unsigned num_buffers
,
735 const struct pipe_vertex_buffer
*_buffers
)
737 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
738 struct pipe_context
*pipe
= rb_pipe
->pipe
;
739 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
740 struct pipe_vertex_buffer
*buffers
= NULL
;
744 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
745 for (i
= 0; i
< num_buffers
; i
++)
746 unwrapped_buffers
[i
].buffer
= rbug_resource_unwrap(_buffers
[i
].buffer
);
747 buffers
= unwrapped_buffers
;
750 pipe
->set_vertex_buffers(pipe
,
756 rbug_set_sample_mask(struct pipe_context
*_pipe
,
757 unsigned sample_mask
)
759 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
760 struct pipe_context
*pipe
= rb_pipe
->pipe
;
762 pipe
->set_sample_mask(pipe
, sample_mask
);
766 rbug_resource_copy_region(struct pipe_context
*_pipe
,
767 struct pipe_resource
*_dst
,
768 struct pipe_subresource subdst
,
772 struct pipe_resource
*_src
,
773 struct pipe_subresource subsrc
,
780 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
781 struct rbug_resource
*rb_resource_dst
= rbug_resource(_dst
);
782 struct rbug_resource
*rb_resource_src
= rbug_resource(_src
);
783 struct pipe_context
*pipe
= rb_pipe
->pipe
;
784 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
785 struct pipe_resource
*src
= rb_resource_src
->resource
;
787 pipe
->resource_copy_region(pipe
,
803 rbug_clear(struct pipe_context
*_pipe
,
809 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
810 struct pipe_context
*pipe
= rb_pipe
->pipe
;
820 rbug_clear_render_target(struct pipe_context
*_pipe
,
821 struct pipe_surface
*_dst
,
823 unsigned dstx
, unsigned dsty
,
824 unsigned width
, unsigned height
)
826 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
827 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
828 struct pipe_context
*pipe
= rb_pipe
->pipe
;
829 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
831 pipe
->clear_render_target(pipe
,
841 rbug_clear_depth_stencil(struct pipe_context
*_pipe
,
842 struct pipe_surface
*_dst
,
843 unsigned clear_flags
,
846 unsigned dstx
, unsigned dsty
,
847 unsigned width
, unsigned height
)
849 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
850 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
851 struct pipe_context
*pipe
= rb_pipe
->pipe
;
852 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
854 pipe
->clear_depth_stencil(pipe
,
866 rbug_flush(struct pipe_context
*_pipe
,
868 struct pipe_fence_handle
**fence
)
870 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
871 struct pipe_context
*pipe
= rb_pipe
->pipe
;
879 rbug_is_resource_referenced(struct pipe_context
*_pipe
,
880 struct pipe_resource
*_resource
,
884 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
885 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
886 struct pipe_context
*pipe
= rb_pipe
->pipe
;
887 struct pipe_resource
*resource
= rb_resource
->resource
;
889 return pipe
->is_resource_referenced(pipe
,
895 static struct pipe_sampler_view
*
896 rbug_context_create_sampler_view(struct pipe_context
*_pipe
,
897 struct pipe_resource
*_resource
,
898 const struct pipe_sampler_view
*templ
)
900 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
901 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
902 struct pipe_context
*pipe
= rb_pipe
->pipe
;
903 struct pipe_resource
*resource
= rb_resource
->resource
;
904 struct pipe_sampler_view
*result
;
906 result
= pipe
->create_sampler_view(pipe
,
911 return rbug_sampler_view_create(rb_pipe
, rb_resource
, result
);
916 rbug_context_sampler_view_destroy(struct pipe_context
*_pipe
,
917 struct pipe_sampler_view
*_view
)
919 rbug_sampler_view_destroy(rbug_context(_pipe
),
920 rbug_sampler_view(_view
));
923 static struct pipe_transfer
*
924 rbug_context_get_transfer(struct pipe_context
*_context
,
925 struct pipe_resource
*_resource
,
926 struct pipe_subresource sr
,
928 const struct pipe_box
*box
)
930 struct rbug_context
*rb_pipe
= rbug_context(_context
);
931 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
932 struct pipe_context
*context
= rb_pipe
->pipe
;
933 struct pipe_resource
*resource
= rb_resource
->resource
;
934 struct pipe_transfer
*result
;
936 result
= context
->get_transfer(context
,
943 return rbug_transfer_create(rb_pipe
, rb_resource
, result
);
948 rbug_context_transfer_destroy(struct pipe_context
*_pipe
,
949 struct pipe_transfer
*_transfer
)
951 rbug_transfer_destroy(rbug_context(_pipe
),
952 rbug_transfer(_transfer
));
956 rbug_context_transfer_map(struct pipe_context
*_context
,
957 struct pipe_transfer
*_transfer
)
959 struct rbug_context
*rb_pipe
= rbug_context(_context
);
960 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
961 struct pipe_context
*context
= rb_pipe
->pipe
;
962 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
964 return context
->transfer_map(context
,
971 rbug_context_transfer_flush_region(struct pipe_context
*_context
,
972 struct pipe_transfer
*_transfer
,
973 const struct pipe_box
*box
)
975 struct rbug_context
*rb_pipe
= rbug_context(_context
);
976 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
977 struct pipe_context
*context
= rb_pipe
->pipe
;
978 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
980 context
->transfer_flush_region(context
,
987 rbug_context_transfer_unmap(struct pipe_context
*_context
,
988 struct pipe_transfer
*_transfer
)
990 struct rbug_context
*rb_pipe
= rbug_context(_context
);
991 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
992 struct pipe_context
*context
= rb_pipe
->pipe
;
993 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
995 context
->transfer_unmap(context
,
1001 rbug_context_transfer_inline_write(struct pipe_context
*_context
,
1002 struct pipe_resource
*_resource
,
1003 struct pipe_subresource sr
,
1005 const struct pipe_box
*box
,
1008 unsigned slice_stride
)
1010 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1011 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1012 struct pipe_context
*context
= rb_pipe
->pipe
;
1013 struct pipe_resource
*resource
= rb_resource
->resource
;
1015 context
->transfer_inline_write(context
,
1026 struct pipe_context
*
1027 rbug_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1029 struct rbug_context
*rb_pipe
;
1030 struct rbug_screen
*rb_screen
= rbug_screen(_screen
);
1035 rb_pipe
= CALLOC_STRUCT(rbug_context
);
1039 pipe_mutex_init(rb_pipe
->draw_mutex
);
1040 pipe_condvar_init(rb_pipe
->draw_cond
);
1041 pipe_mutex_init(rb_pipe
->call_mutex
);
1042 pipe_mutex_init(rb_pipe
->list_mutex
);
1043 make_empty_list(&rb_pipe
->shaders
);
1045 rb_pipe
->base
.winsys
= NULL
;
1046 rb_pipe
->base
.screen
= _screen
;
1047 rb_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1048 rb_pipe
->base
.draw
= NULL
;
1050 rb_pipe
->base
.destroy
= rbug_destroy
;
1051 rb_pipe
->base
.draw_arrays
= rbug_draw_arrays
;
1052 rb_pipe
->base
.draw_elements
= rbug_draw_elements
;
1053 rb_pipe
->base
.draw_range_elements
= rbug_draw_range_elements
;
1054 rb_pipe
->base
.create_query
= rbug_create_query
;
1055 rb_pipe
->base
.destroy_query
= rbug_destroy_query
;
1056 rb_pipe
->base
.begin_query
= rbug_begin_query
;
1057 rb_pipe
->base
.end_query
= rbug_end_query
;
1058 rb_pipe
->base
.get_query_result
= rbug_get_query_result
;
1059 rb_pipe
->base
.create_blend_state
= rbug_create_blend_state
;
1060 rb_pipe
->base
.bind_blend_state
= rbug_bind_blend_state
;
1061 rb_pipe
->base
.delete_blend_state
= rbug_delete_blend_state
;
1062 rb_pipe
->base
.create_sampler_state
= rbug_create_sampler_state
;
1063 rb_pipe
->base
.bind_fragment_sampler_states
= rbug_bind_fragment_sampler_states
;
1064 rb_pipe
->base
.bind_vertex_sampler_states
= rbug_bind_vertex_sampler_states
;
1065 rb_pipe
->base
.delete_sampler_state
= rbug_delete_sampler_state
;
1066 rb_pipe
->base
.create_rasterizer_state
= rbug_create_rasterizer_state
;
1067 rb_pipe
->base
.bind_rasterizer_state
= rbug_bind_rasterizer_state
;
1068 rb_pipe
->base
.delete_rasterizer_state
= rbug_delete_rasterizer_state
;
1069 rb_pipe
->base
.create_depth_stencil_alpha_state
= rbug_create_depth_stencil_alpha_state
;
1070 rb_pipe
->base
.bind_depth_stencil_alpha_state
= rbug_bind_depth_stencil_alpha_state
;
1071 rb_pipe
->base
.delete_depth_stencil_alpha_state
= rbug_delete_depth_stencil_alpha_state
;
1072 rb_pipe
->base
.create_fs_state
= rbug_create_fs_state
;
1073 rb_pipe
->base
.bind_fs_state
= rbug_bind_fs_state
;
1074 rb_pipe
->base
.delete_fs_state
= rbug_delete_fs_state
;
1075 rb_pipe
->base
.create_vs_state
= rbug_create_vs_state
;
1076 rb_pipe
->base
.bind_vs_state
= rbug_bind_vs_state
;
1077 rb_pipe
->base
.delete_vs_state
= rbug_delete_vs_state
;
1078 rb_pipe
->base
.create_gs_state
= rbug_create_gs_state
;
1079 rb_pipe
->base
.bind_gs_state
= rbug_bind_gs_state
;
1080 rb_pipe
->base
.delete_gs_state
= rbug_delete_gs_state
;
1081 rb_pipe
->base
.create_vertex_elements_state
= rbug_create_vertex_elements_state
;
1082 rb_pipe
->base
.bind_vertex_elements_state
= rbug_bind_vertex_elements_state
;
1083 rb_pipe
->base
.delete_vertex_elements_state
= rbug_delete_vertex_elements_state
;
1084 rb_pipe
->base
.set_blend_color
= rbug_set_blend_color
;
1085 rb_pipe
->base
.set_stencil_ref
= rbug_set_stencil_ref
;
1086 rb_pipe
->base
.set_clip_state
= rbug_set_clip_state
;
1087 rb_pipe
->base
.set_constant_buffer
= rbug_set_constant_buffer
;
1088 rb_pipe
->base
.set_framebuffer_state
= rbug_set_framebuffer_state
;
1089 rb_pipe
->base
.set_polygon_stipple
= rbug_set_polygon_stipple
;
1090 rb_pipe
->base
.set_scissor_state
= rbug_set_scissor_state
;
1091 rb_pipe
->base
.set_viewport_state
= rbug_set_viewport_state
;
1092 rb_pipe
->base
.set_fragment_sampler_views
= rbug_set_fragment_sampler_views
;
1093 rb_pipe
->base
.set_vertex_sampler_views
= rbug_set_vertex_sampler_views
;
1094 rb_pipe
->base
.set_vertex_buffers
= rbug_set_vertex_buffers
;
1095 rb_pipe
->base
.set_sample_mask
= rbug_set_sample_mask
;
1096 rb_pipe
->base
.resource_copy_region
= rbug_resource_copy_region
;
1097 rb_pipe
->base
.clear
= rbug_clear
;
1098 rb_pipe
->base
.clear_render_target
= rbug_clear_render_target
;
1099 rb_pipe
->base
.clear_depth_stencil
= rbug_clear_depth_stencil
;
1100 rb_pipe
->base
.flush
= rbug_flush
;
1101 rb_pipe
->base
.is_resource_referenced
= rbug_is_resource_referenced
;
1102 rb_pipe
->base
.create_sampler_view
= rbug_context_create_sampler_view
;
1103 rb_pipe
->base
.sampler_view_destroy
= rbug_context_sampler_view_destroy
;
1104 rb_pipe
->base
.get_transfer
= rbug_context_get_transfer
;
1105 rb_pipe
->base
.transfer_destroy
= rbug_context_transfer_destroy
;
1106 rb_pipe
->base
.transfer_map
= rbug_context_transfer_map
;
1107 rb_pipe
->base
.transfer_unmap
= rbug_context_transfer_unmap
;
1108 rb_pipe
->base
.transfer_flush_region
= rbug_context_transfer_flush_region
;
1109 rb_pipe
->base
.transfer_inline_write
= rbug_context_transfer_inline_write
;
1111 rb_pipe
->pipe
= pipe
;
1113 rbug_screen_add_to_list(rb_screen
, contexts
, rb_pipe
);
1115 return &rb_pipe
->base
;