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
);
53 rbug_draw_block_locked(struct rbug_context
*rb_pipe
, int flag
)
56 if (rb_pipe
->draw_blocker
& flag
) {
57 rb_pipe
->draw_blocked
|= flag
;
58 } else if ((rb_pipe
->draw_rule
.blocker
& flag
) &&
59 (rb_pipe
->draw_blocker
& RBUG_BLOCK_RULE
)) {
61 boolean block
= FALSE
;
62 debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__
,
63 (void *) rb_pipe
->draw_rule
.fs
, (void *) rb_pipe
->curr
.fs
,
64 (void *) rb_pipe
->draw_rule
.vs
, (void *) rb_pipe
->curr
.vs
,
65 (void *) rb_pipe
->draw_rule
.surf
, 0,
66 (void *) rb_pipe
->draw_rule
.texture
, 0);
67 if (rb_pipe
->draw_rule
.fs
&&
68 rb_pipe
->draw_rule
.fs
== rb_pipe
->curr
.fs
)
70 if (rb_pipe
->draw_rule
.vs
&&
71 rb_pipe
->draw_rule
.vs
== rb_pipe
->curr
.vs
)
73 if (rb_pipe
->draw_rule
.surf
&&
74 rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.zsbuf
)
76 if (rb_pipe
->draw_rule
.surf
)
77 for (k
= 0; k
< rb_pipe
->curr
.nr_cbufs
; k
++)
78 if (rb_pipe
->draw_rule
.surf
== rb_pipe
->curr
.cbufs
[k
])
80 if (rb_pipe
->draw_rule
.texture
) {
81 for (k
= 0; k
< rb_pipe
->curr
.num_fs_views
; k
++)
82 if (rb_pipe
->draw_rule
.texture
== rb_pipe
->curr
.fs_texs
[k
])
84 for (k
= 0; k
< rb_pipe
->curr
.num_vs_views
; k
++) {
85 if (rb_pipe
->draw_rule
.texture
== rb_pipe
->curr
.vs_texs
[k
]) {
92 rb_pipe
->draw_blocked
|= (flag
| RBUG_BLOCK_RULE
);
95 if (rb_pipe
->draw_blocked
)
96 rbug_notify_draw_blocked(rb_pipe
);
98 /* wait for rbug to clear the blocked flag */
99 while (rb_pipe
->draw_blocked
& flag
) {
100 rb_pipe
->draw_blocked
|= flag
;
101 pipe_condvar_wait(rb_pipe
->draw_cond
, rb_pipe
->draw_mutex
);
107 rbug_draw_vbo(struct pipe_context
*_pipe
, const struct pipe_draw_info
*info
)
109 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
110 struct pipe_context
*pipe
= rb_pipe
->pipe
;
112 pipe_mutex_lock(rb_pipe
->draw_mutex
);
113 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_BEFORE
);
115 pipe
->draw_vbo(pipe
, info
);
117 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
118 pipe_mutex_unlock(rb_pipe
->draw_mutex
);
121 static struct pipe_query
*
122 rbug_create_query(struct pipe_context
*_pipe
,
125 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
126 struct pipe_context
*pipe
= rb_pipe
->pipe
;
128 return pipe
->create_query(pipe
,
133 rbug_destroy_query(struct pipe_context
*_pipe
,
134 struct pipe_query
*query
)
136 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
137 struct pipe_context
*pipe
= rb_pipe
->pipe
;
139 pipe
->destroy_query(pipe
,
144 rbug_begin_query(struct pipe_context
*_pipe
,
145 struct pipe_query
*query
)
147 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
148 struct pipe_context
*pipe
= rb_pipe
->pipe
;
150 pipe
->begin_query(pipe
,
155 rbug_end_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
->end_query(pipe
,
166 rbug_get_query_result(struct pipe_context
*_pipe
,
167 struct pipe_query
*query
,
171 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
172 struct pipe_context
*pipe
= rb_pipe
->pipe
;
174 return pipe
->get_query_result(pipe
,
181 rbug_create_blend_state(struct pipe_context
*_pipe
,
182 const struct pipe_blend_state
*blend
)
184 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
185 struct pipe_context
*pipe
= rb_pipe
->pipe
;
187 return pipe
->create_blend_state(pipe
,
192 rbug_bind_blend_state(struct pipe_context
*_pipe
,
195 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
196 struct pipe_context
*pipe
= rb_pipe
->pipe
;
198 pipe
->bind_blend_state(pipe
,
203 rbug_delete_blend_state(struct pipe_context
*_pipe
,
206 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
207 struct pipe_context
*pipe
= rb_pipe
->pipe
;
209 pipe
->delete_blend_state(pipe
,
214 rbug_create_sampler_state(struct pipe_context
*_pipe
,
215 const struct pipe_sampler_state
*sampler
)
217 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
218 struct pipe_context
*pipe
= rb_pipe
->pipe
;
220 return pipe
->create_sampler_state(pipe
,
225 rbug_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
226 unsigned num_samplers
,
229 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
230 struct pipe_context
*pipe
= rb_pipe
->pipe
;
232 pipe
->bind_fragment_sampler_states(pipe
,
238 rbug_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
239 unsigned num_samplers
,
242 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
243 struct pipe_context
*pipe
= rb_pipe
->pipe
;
245 pipe
->bind_vertex_sampler_states(pipe
,
251 rbug_delete_sampler_state(struct pipe_context
*_pipe
,
254 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
255 struct pipe_context
*pipe
= rb_pipe
->pipe
;
257 pipe
->delete_sampler_state(pipe
,
262 rbug_create_rasterizer_state(struct pipe_context
*_pipe
,
263 const struct pipe_rasterizer_state
*rasterizer
)
265 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
266 struct pipe_context
*pipe
= rb_pipe
->pipe
;
268 return pipe
->create_rasterizer_state(pipe
,
273 rbug_bind_rasterizer_state(struct pipe_context
*_pipe
,
276 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
277 struct pipe_context
*pipe
= rb_pipe
->pipe
;
279 pipe
->bind_rasterizer_state(pipe
,
284 rbug_delete_rasterizer_state(struct pipe_context
*_pipe
,
287 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
288 struct pipe_context
*pipe
= rb_pipe
->pipe
;
290 pipe
->delete_rasterizer_state(pipe
,
295 rbug_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
296 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
298 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
299 struct pipe_context
*pipe
= rb_pipe
->pipe
;
301 return pipe
->create_depth_stencil_alpha_state(pipe
,
302 depth_stencil_alpha
);
306 rbug_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
307 void *depth_stencil_alpha
)
309 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
310 struct pipe_context
*pipe
= rb_pipe
->pipe
;
312 pipe
->bind_depth_stencil_alpha_state(pipe
,
313 depth_stencil_alpha
);
317 rbug_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
318 void *depth_stencil_alpha
)
320 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
321 struct pipe_context
*pipe
= rb_pipe
->pipe
;
323 pipe
->delete_depth_stencil_alpha_state(pipe
,
324 depth_stencil_alpha
);
328 rbug_create_fs_state(struct pipe_context
*_pipe
,
329 const struct pipe_shader_state
*state
)
331 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
332 struct pipe_context
*pipe
= rb_pipe
->pipe
;
335 result
= pipe
->create_fs_state(pipe
, state
);
339 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_FRAGMENT
);
343 rbug_bind_fs_state(struct pipe_context
*_pipe
,
346 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
347 struct pipe_context
*pipe
= rb_pipe
->pipe
;
350 fs
= rbug_shader_unwrap(_fs
);
351 rb_pipe
->curr
.fs
= rbug_shader(_fs
);
352 pipe
->bind_fs_state(pipe
,
357 rbug_delete_fs_state(struct pipe_context
*_pipe
,
360 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
361 struct rbug_shader
*rb_shader
= rbug_shader(_fs
);
363 rbug_shader_destroy(rb_pipe
, rb_shader
);
367 rbug_create_vs_state(struct pipe_context
*_pipe
,
368 const struct pipe_shader_state
*state
)
370 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
371 struct pipe_context
*pipe
= rb_pipe
->pipe
;
374 result
= pipe
->create_vs_state(pipe
, state
);
378 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_VERTEX
);
382 rbug_bind_vs_state(struct pipe_context
*_pipe
,
385 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
386 struct pipe_context
*pipe
= rb_pipe
->pipe
;
389 vs
= rbug_shader_unwrap(_vs
);
390 rb_pipe
->curr
.vs
= rbug_shader(_vs
);
391 pipe
->bind_vs_state(pipe
,
396 rbug_delete_vs_state(struct pipe_context
*_pipe
,
399 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
400 struct rbug_shader
*rb_shader
= rbug_shader(_vs
);
402 rbug_shader_destroy(rb_pipe
, rb_shader
);
406 rbug_create_gs_state(struct pipe_context
*_pipe
,
407 const struct pipe_shader_state
*state
)
409 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
410 struct pipe_context
*pipe
= rb_pipe
->pipe
;
413 result
= pipe
->create_gs_state(pipe
, state
);
417 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_GEOM
);
421 rbug_bind_gs_state(struct pipe_context
*_pipe
,
424 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
425 struct pipe_context
*pipe
= rb_pipe
->pipe
;
428 gs
= rbug_shader_unwrap(_gs
);
429 rb_pipe
->curr
.gs
= rbug_shader(_gs
);
430 pipe
->bind_gs_state(pipe
,
435 rbug_delete_gs_state(struct pipe_context
*_pipe
,
438 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
439 struct rbug_shader
*rb_shader
= rbug_shader(_gs
);
441 rbug_shader_destroy(rb_pipe
, rb_shader
);
445 rbug_create_vertex_elements_state(struct pipe_context
*_pipe
,
446 unsigned num_elements
,
447 const struct pipe_vertex_element
*vertex_elements
)
449 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
450 struct pipe_context
*pipe
= rb_pipe
->pipe
;
452 return pipe
->create_vertex_elements_state(pipe
,
458 rbug_bind_vertex_elements_state(struct pipe_context
*_pipe
,
461 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
462 struct pipe_context
*pipe
= rb_pipe
->pipe
;
464 pipe
->bind_vertex_elements_state(pipe
,
469 rbug_delete_vertex_elements_state(struct pipe_context
*_pipe
,
472 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
473 struct pipe_context
*pipe
= rb_pipe
->pipe
;
475 pipe
->delete_vertex_elements_state(pipe
,
480 rbug_set_blend_color(struct pipe_context
*_pipe
,
481 const struct pipe_blend_color
*blend_color
)
483 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
484 struct pipe_context
*pipe
= rb_pipe
->pipe
;
486 pipe
->set_blend_color(pipe
,
491 rbug_set_stencil_ref(struct pipe_context
*_pipe
,
492 const struct pipe_stencil_ref
*stencil_ref
)
494 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
495 struct pipe_context
*pipe
= rb_pipe
->pipe
;
497 pipe
->set_stencil_ref(pipe
,
502 rbug_set_clip_state(struct pipe_context
*_pipe
,
503 const struct pipe_clip_state
*clip
)
505 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
506 struct pipe_context
*pipe
= rb_pipe
->pipe
;
508 pipe
->set_clip_state(pipe
,
513 rbug_set_constant_buffer(struct pipe_context
*_pipe
,
516 struct pipe_resource
*_resource
)
518 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
519 struct pipe_context
*pipe
= rb_pipe
->pipe
;
520 struct pipe_resource
*unwrapped_resource
;
521 struct pipe_resource
*resource
= NULL
;
523 /* XXX hmm? unwrap the input state */
525 unwrapped_resource
= rbug_resource_unwrap(_resource
);
526 resource
= unwrapped_resource
;
529 pipe
->set_constant_buffer(pipe
,
536 rbug_set_framebuffer_state(struct pipe_context
*_pipe
,
537 const struct pipe_framebuffer_state
*_state
)
539 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
540 struct pipe_context
*pipe
= rb_pipe
->pipe
;
541 struct pipe_framebuffer_state unwrapped_state
;
542 struct pipe_framebuffer_state
*state
= NULL
;
545 rb_pipe
->curr
.nr_cbufs
= 0;
546 memset(rb_pipe
->curr
.cbufs
, 0, sizeof(rb_pipe
->curr
.cbufs
));
547 rb_pipe
->curr
.zsbuf
= NULL
;
549 /* unwrap the input state */
551 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
553 rb_pipe
->curr
.nr_cbufs
= _state
->nr_cbufs
;
554 for(i
= 0; i
< _state
->nr_cbufs
; i
++) {
555 unwrapped_state
.cbufs
[i
] = rbug_surface_unwrap(_state
->cbufs
[i
]);
556 if (_state
->cbufs
[i
])
557 rb_pipe
->curr
.cbufs
[i
] = rbug_resource(_state
->cbufs
[i
]->texture
);
559 unwrapped_state
.zsbuf
= rbug_surface_unwrap(_state
->zsbuf
);
561 rb_pipe
->curr
.zsbuf
= rbug_resource(_state
->zsbuf
->texture
);
562 state
= &unwrapped_state
;
565 pipe
->set_framebuffer_state(pipe
,
570 rbug_set_polygon_stipple(struct pipe_context
*_pipe
,
571 const struct pipe_poly_stipple
*poly_stipple
)
573 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
574 struct pipe_context
*pipe
= rb_pipe
->pipe
;
576 pipe
->set_polygon_stipple(pipe
,
581 rbug_set_scissor_state(struct pipe_context
*_pipe
,
582 const struct pipe_scissor_state
*scissor
)
584 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
585 struct pipe_context
*pipe
= rb_pipe
->pipe
;
587 pipe
->set_scissor_state(pipe
,
592 rbug_set_viewport_state(struct pipe_context
*_pipe
,
593 const struct pipe_viewport_state
*viewport
)
595 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
596 struct pipe_context
*pipe
= rb_pipe
->pipe
;
598 pipe
->set_viewport_state(pipe
,
603 rbug_set_fragment_sampler_views(struct pipe_context
*_pipe
,
605 struct pipe_sampler_view
**_views
)
607 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
608 struct pipe_context
*pipe
= rb_pipe
->pipe
;
609 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SAMPLERS
];
610 struct pipe_sampler_view
**views
= NULL
;
613 rb_pipe
->curr
.num_fs_views
= 0;
614 memset(rb_pipe
->curr
.fs_views
, 0, sizeof(rb_pipe
->curr
.fs_views
));
615 memset(rb_pipe
->curr
.fs_texs
, 0, sizeof(rb_pipe
->curr
.fs_texs
));
616 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
619 rb_pipe
->curr
.num_fs_views
= num
;
620 for (i
= 0; i
< num
; i
++) {
621 rb_pipe
->curr
.fs_views
[i
] = rbug_sampler_view(_views
[i
]);
622 rb_pipe
->curr
.fs_texs
[i
] = rbug_resource(_views
[i
] ? _views
[i
]->texture
: NULL
);
623 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
625 views
= unwrapped_views
;
628 pipe
->set_fragment_sampler_views(pipe
, num
, views
);
632 rbug_set_vertex_sampler_views(struct pipe_context
*_pipe
,
634 struct pipe_sampler_view
**_views
)
636 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
637 struct pipe_context
*pipe
= rb_pipe
->pipe
;
638 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_VERTEX_SAMPLERS
];
639 struct pipe_sampler_view
**views
= NULL
;
642 rb_pipe
->curr
.num_vs_views
= 0;
643 memset(rb_pipe
->curr
.vs_views
, 0, sizeof(rb_pipe
->curr
.vs_views
));
644 memset(rb_pipe
->curr
.vs_texs
, 0, sizeof(rb_pipe
->curr
.vs_texs
));
645 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
648 rb_pipe
->curr
.num_vs_views
= num
;
649 for (i
= 0; i
< num
; i
++) {
650 rb_pipe
->curr
.vs_views
[i
] = rbug_sampler_view(_views
[i
]);
651 rb_pipe
->curr
.vs_texs
[i
] = rbug_resource(_views
[i
]->texture
);
652 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
654 views
= unwrapped_views
;
657 pipe
->set_vertex_sampler_views(pipe
, num
, views
);
661 rbug_set_vertex_buffers(struct pipe_context
*_pipe
,
662 unsigned num_buffers
,
663 const struct pipe_vertex_buffer
*_buffers
)
665 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
666 struct pipe_context
*pipe
= rb_pipe
->pipe
;
667 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
668 struct pipe_vertex_buffer
*buffers
= NULL
;
672 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
673 for (i
= 0; i
< num_buffers
; i
++)
674 unwrapped_buffers
[i
].buffer
= rbug_resource_unwrap(_buffers
[i
].buffer
);
675 buffers
= unwrapped_buffers
;
678 pipe
->set_vertex_buffers(pipe
,
684 rbug_set_index_buffer(struct pipe_context
*_pipe
,
685 const struct pipe_index_buffer
*_ib
)
687 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
688 struct pipe_context
*pipe
= rb_pipe
->pipe
;
689 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
693 unwrapped_ib
.buffer
= rbug_resource_unwrap(_ib
->buffer
);
697 pipe
->set_index_buffer(pipe
, ib
);
701 rbug_set_sample_mask(struct pipe_context
*_pipe
,
702 unsigned sample_mask
)
704 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
705 struct pipe_context
*pipe
= rb_pipe
->pipe
;
707 pipe
->set_sample_mask(pipe
, sample_mask
);
711 rbug_resource_copy_region(struct pipe_context
*_pipe
,
712 struct pipe_resource
*_dst
,
717 struct pipe_resource
*_src
,
719 const struct pipe_box
*src_box
)
721 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
722 struct rbug_resource
*rb_resource_dst
= rbug_resource(_dst
);
723 struct rbug_resource
*rb_resource_src
= rbug_resource(_src
);
724 struct pipe_context
*pipe
= rb_pipe
->pipe
;
725 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
726 struct pipe_resource
*src
= rb_resource_src
->resource
;
728 pipe
->resource_copy_region(pipe
,
740 rbug_clear(struct pipe_context
*_pipe
,
746 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
747 struct pipe_context
*pipe
= rb_pipe
->pipe
;
757 rbug_clear_render_target(struct pipe_context
*_pipe
,
758 struct pipe_surface
*_dst
,
760 unsigned dstx
, unsigned dsty
,
761 unsigned width
, unsigned height
)
763 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
764 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
765 struct pipe_context
*pipe
= rb_pipe
->pipe
;
766 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
768 pipe
->clear_render_target(pipe
,
778 rbug_clear_depth_stencil(struct pipe_context
*_pipe
,
779 struct pipe_surface
*_dst
,
780 unsigned clear_flags
,
783 unsigned dstx
, unsigned dsty
,
784 unsigned width
, unsigned height
)
786 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
787 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
788 struct pipe_context
*pipe
= rb_pipe
->pipe
;
789 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
791 pipe
->clear_depth_stencil(pipe
,
803 rbug_flush(struct pipe_context
*_pipe
,
805 struct pipe_fence_handle
**fence
)
807 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
808 struct pipe_context
*pipe
= rb_pipe
->pipe
;
816 rbug_is_resource_referenced(struct pipe_context
*_pipe
,
817 struct pipe_resource
*_resource
,
821 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
822 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
823 struct pipe_context
*pipe
= rb_pipe
->pipe
;
824 struct pipe_resource
*resource
= rb_resource
->resource
;
826 return pipe
->is_resource_referenced(pipe
,
832 static struct pipe_sampler_view
*
833 rbug_context_create_sampler_view(struct pipe_context
*_pipe
,
834 struct pipe_resource
*_resource
,
835 const struct pipe_sampler_view
*templ
)
837 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
838 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
839 struct pipe_context
*pipe
= rb_pipe
->pipe
;
840 struct pipe_resource
*resource
= rb_resource
->resource
;
841 struct pipe_sampler_view
*result
;
843 result
= pipe
->create_sampler_view(pipe
,
848 return rbug_sampler_view_create(rb_pipe
, rb_resource
, result
);
853 rbug_context_sampler_view_destroy(struct pipe_context
*_pipe
,
854 struct pipe_sampler_view
*_view
)
856 rbug_sampler_view_destroy(rbug_context(_pipe
),
857 rbug_sampler_view(_view
));
860 static struct pipe_surface
*
861 rbug_context_create_surface(struct pipe_context
*_pipe
,
862 struct pipe_resource
*_resource
,
863 const struct pipe_surface
*surf_tmpl
)
865 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
866 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
867 struct pipe_context
*pipe
= rb_pipe
->pipe
;
868 struct pipe_resource
*resource
= rb_resource
->resource
;
869 struct pipe_surface
*result
;
871 result
= pipe
->create_surface(pipe
,
876 return rbug_surface_create(rb_pipe
, rb_resource
, result
);
881 rbug_context_surface_destroy(struct pipe_context
*_pipe
,
882 struct pipe_surface
*_surface
)
884 rbug_surface_destroy(rbug_context(_pipe
),
885 rbug_surface(_surface
));
890 static struct pipe_transfer
*
891 rbug_context_get_transfer(struct pipe_context
*_context
,
892 struct pipe_resource
*_resource
,
895 const struct pipe_box
*box
)
897 struct rbug_context
*rb_pipe
= rbug_context(_context
);
898 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
899 struct pipe_context
*context
= rb_pipe
->pipe
;
900 struct pipe_resource
*resource
= rb_resource
->resource
;
901 struct pipe_transfer
*result
;
903 result
= context
->get_transfer(context
,
910 return rbug_transfer_create(rb_pipe
, rb_resource
, result
);
915 rbug_context_transfer_destroy(struct pipe_context
*_pipe
,
916 struct pipe_transfer
*_transfer
)
918 rbug_transfer_destroy(rbug_context(_pipe
),
919 rbug_transfer(_transfer
));
923 rbug_context_transfer_map(struct pipe_context
*_context
,
924 struct pipe_transfer
*_transfer
)
926 struct rbug_context
*rb_pipe
= rbug_context(_context
);
927 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
928 struct pipe_context
*context
= rb_pipe
->pipe
;
929 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
931 return context
->transfer_map(context
,
938 rbug_context_transfer_flush_region(struct pipe_context
*_context
,
939 struct pipe_transfer
*_transfer
,
940 const struct pipe_box
*box
)
942 struct rbug_context
*rb_pipe
= rbug_context(_context
);
943 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
944 struct pipe_context
*context
= rb_pipe
->pipe
;
945 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
947 context
->transfer_flush_region(context
,
954 rbug_context_transfer_unmap(struct pipe_context
*_context
,
955 struct pipe_transfer
*_transfer
)
957 struct rbug_context
*rb_pipe
= rbug_context(_context
);
958 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
959 struct pipe_context
*context
= rb_pipe
->pipe
;
960 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
962 context
->transfer_unmap(context
,
968 rbug_context_transfer_inline_write(struct pipe_context
*_context
,
969 struct pipe_resource
*_resource
,
972 const struct pipe_box
*box
,
975 unsigned layer_stride
)
977 struct rbug_context
*rb_pipe
= rbug_context(_context
);
978 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
979 struct pipe_context
*context
= rb_pipe
->pipe
;
980 struct pipe_resource
*resource
= rb_resource
->resource
;
982 context
->transfer_inline_write(context
,
993 static void rbug_redefine_user_buffer(struct pipe_context
*_context
,
994 struct pipe_resource
*_resource
,
995 unsigned offset
, unsigned size
)
997 struct rbug_context
*rb_pipe
= rbug_context(_context
);
998 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
999 struct pipe_context
*context
= rb_pipe
->pipe
;
1000 struct pipe_resource
*resource
= rb_resource
->resource
;
1002 context
->redefine_user_buffer(context
, resource
, offset
, size
);
1006 struct pipe_context
*
1007 rbug_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1009 struct rbug_context
*rb_pipe
;
1010 struct rbug_screen
*rb_screen
= rbug_screen(_screen
);
1015 rb_pipe
= CALLOC_STRUCT(rbug_context
);
1019 pipe_mutex_init(rb_pipe
->draw_mutex
);
1020 pipe_condvar_init(rb_pipe
->draw_cond
);
1021 pipe_mutex_init(rb_pipe
->call_mutex
);
1022 pipe_mutex_init(rb_pipe
->list_mutex
);
1023 make_empty_list(&rb_pipe
->shaders
);
1025 rb_pipe
->base
.winsys
= NULL
;
1026 rb_pipe
->base
.screen
= _screen
;
1027 rb_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1028 rb_pipe
->base
.draw
= NULL
;
1030 rb_pipe
->base
.destroy
= rbug_destroy
;
1031 rb_pipe
->base
.draw_vbo
= rbug_draw_vbo
;
1032 rb_pipe
->base
.create_query
= rbug_create_query
;
1033 rb_pipe
->base
.destroy_query
= rbug_destroy_query
;
1034 rb_pipe
->base
.begin_query
= rbug_begin_query
;
1035 rb_pipe
->base
.end_query
= rbug_end_query
;
1036 rb_pipe
->base
.get_query_result
= rbug_get_query_result
;
1037 rb_pipe
->base
.create_blend_state
= rbug_create_blend_state
;
1038 rb_pipe
->base
.bind_blend_state
= rbug_bind_blend_state
;
1039 rb_pipe
->base
.delete_blend_state
= rbug_delete_blend_state
;
1040 rb_pipe
->base
.create_sampler_state
= rbug_create_sampler_state
;
1041 rb_pipe
->base
.bind_fragment_sampler_states
= rbug_bind_fragment_sampler_states
;
1042 rb_pipe
->base
.bind_vertex_sampler_states
= rbug_bind_vertex_sampler_states
;
1043 rb_pipe
->base
.delete_sampler_state
= rbug_delete_sampler_state
;
1044 rb_pipe
->base
.create_rasterizer_state
= rbug_create_rasterizer_state
;
1045 rb_pipe
->base
.bind_rasterizer_state
= rbug_bind_rasterizer_state
;
1046 rb_pipe
->base
.delete_rasterizer_state
= rbug_delete_rasterizer_state
;
1047 rb_pipe
->base
.create_depth_stencil_alpha_state
= rbug_create_depth_stencil_alpha_state
;
1048 rb_pipe
->base
.bind_depth_stencil_alpha_state
= rbug_bind_depth_stencil_alpha_state
;
1049 rb_pipe
->base
.delete_depth_stencil_alpha_state
= rbug_delete_depth_stencil_alpha_state
;
1050 rb_pipe
->base
.create_fs_state
= rbug_create_fs_state
;
1051 rb_pipe
->base
.bind_fs_state
= rbug_bind_fs_state
;
1052 rb_pipe
->base
.delete_fs_state
= rbug_delete_fs_state
;
1053 rb_pipe
->base
.create_vs_state
= rbug_create_vs_state
;
1054 rb_pipe
->base
.bind_vs_state
= rbug_bind_vs_state
;
1055 rb_pipe
->base
.delete_vs_state
= rbug_delete_vs_state
;
1056 rb_pipe
->base
.create_gs_state
= rbug_create_gs_state
;
1057 rb_pipe
->base
.bind_gs_state
= rbug_bind_gs_state
;
1058 rb_pipe
->base
.delete_gs_state
= rbug_delete_gs_state
;
1059 rb_pipe
->base
.create_vertex_elements_state
= rbug_create_vertex_elements_state
;
1060 rb_pipe
->base
.bind_vertex_elements_state
= rbug_bind_vertex_elements_state
;
1061 rb_pipe
->base
.delete_vertex_elements_state
= rbug_delete_vertex_elements_state
;
1062 rb_pipe
->base
.set_blend_color
= rbug_set_blend_color
;
1063 rb_pipe
->base
.set_stencil_ref
= rbug_set_stencil_ref
;
1064 rb_pipe
->base
.set_clip_state
= rbug_set_clip_state
;
1065 rb_pipe
->base
.set_constant_buffer
= rbug_set_constant_buffer
;
1066 rb_pipe
->base
.set_framebuffer_state
= rbug_set_framebuffer_state
;
1067 rb_pipe
->base
.set_polygon_stipple
= rbug_set_polygon_stipple
;
1068 rb_pipe
->base
.set_scissor_state
= rbug_set_scissor_state
;
1069 rb_pipe
->base
.set_viewport_state
= rbug_set_viewport_state
;
1070 rb_pipe
->base
.set_fragment_sampler_views
= rbug_set_fragment_sampler_views
;
1071 rb_pipe
->base
.set_vertex_sampler_views
= rbug_set_vertex_sampler_views
;
1072 rb_pipe
->base
.set_vertex_buffers
= rbug_set_vertex_buffers
;
1073 rb_pipe
->base
.set_index_buffer
= rbug_set_index_buffer
;
1074 rb_pipe
->base
.set_sample_mask
= rbug_set_sample_mask
;
1075 rb_pipe
->base
.resource_copy_region
= rbug_resource_copy_region
;
1076 rb_pipe
->base
.clear
= rbug_clear
;
1077 rb_pipe
->base
.clear_render_target
= rbug_clear_render_target
;
1078 rb_pipe
->base
.clear_depth_stencil
= rbug_clear_depth_stencil
;
1079 rb_pipe
->base
.flush
= rbug_flush
;
1080 rb_pipe
->base
.is_resource_referenced
= rbug_is_resource_referenced
;
1081 rb_pipe
->base
.create_sampler_view
= rbug_context_create_sampler_view
;
1082 rb_pipe
->base
.sampler_view_destroy
= rbug_context_sampler_view_destroy
;
1083 rb_pipe
->base
.create_surface
= rbug_context_create_surface
;
1084 rb_pipe
->base
.surface_destroy
= rbug_context_surface_destroy
;
1085 rb_pipe
->base
.get_transfer
= rbug_context_get_transfer
;
1086 rb_pipe
->base
.transfer_destroy
= rbug_context_transfer_destroy
;
1087 rb_pipe
->base
.transfer_map
= rbug_context_transfer_map
;
1088 rb_pipe
->base
.transfer_unmap
= rbug_context_transfer_unmap
;
1089 rb_pipe
->base
.transfer_flush_region
= rbug_context_transfer_flush_region
;
1090 rb_pipe
->base
.transfer_inline_write
= rbug_context_transfer_inline_write
;
1091 rb_pipe
->base
.redefine_user_buffer
= rbug_redefine_user_buffer
;
1093 rb_pipe
->pipe
= pipe
;
1095 rbug_screen_add_to_list(rb_screen
, contexts
, rb_pipe
);
1097 return &rb_pipe
->base
;