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
;
188 pipe_mutex_lock(rb_pipe
->call_mutex
);
189 pipe
->end_query(pipe
,
191 pipe_mutex_unlock(rb_pipe
->call_mutex
);
195 rbug_get_query_result(struct pipe_context
*_pipe
,
196 struct pipe_query
*query
,
198 union pipe_query_result
*result
)
200 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
201 struct pipe_context
*pipe
= rb_pipe
->pipe
;
204 pipe_mutex_lock(rb_pipe
->call_mutex
);
205 ret
= pipe
->get_query_result(pipe
,
209 pipe_mutex_unlock(rb_pipe
->call_mutex
);
215 rbug_create_blend_state(struct pipe_context
*_pipe
,
216 const struct pipe_blend_state
*blend
)
218 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
219 struct pipe_context
*pipe
= rb_pipe
->pipe
;
222 pipe_mutex_lock(rb_pipe
->call_mutex
);
223 ret
= pipe
->create_blend_state(pipe
,
225 pipe_mutex_unlock(rb_pipe
->call_mutex
);
231 rbug_bind_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
->bind_blend_state(pipe
,
240 pipe_mutex_unlock(rb_pipe
->call_mutex
);
244 rbug_delete_blend_state(struct pipe_context
*_pipe
,
247 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
248 struct pipe_context
*pipe
= rb_pipe
->pipe
;
250 pipe_mutex_lock(rb_pipe
->call_mutex
);
251 pipe
->delete_blend_state(pipe
,
253 pipe_mutex_unlock(rb_pipe
->call_mutex
);
257 rbug_create_sampler_state(struct pipe_context
*_pipe
,
258 const struct pipe_sampler_state
*sampler
)
260 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
261 struct pipe_context
*pipe
= rb_pipe
->pipe
;
264 pipe_mutex_lock(rb_pipe
->call_mutex
);
265 ret
= pipe
->create_sampler_state(pipe
,
267 pipe_mutex_unlock(rb_pipe
->call_mutex
);
273 rbug_bind_sampler_states(struct pipe_context
*_pipe
, unsigned shader
,
274 unsigned start
, unsigned count
,
277 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
278 struct pipe_context
*pipe
= rb_pipe
->pipe
;
280 pipe_mutex_lock(rb_pipe
->call_mutex
);
281 pipe
->bind_sampler_states(pipe
, shader
, start
, count
, samplers
);
282 pipe_mutex_unlock(rb_pipe
->call_mutex
);
286 rbug_delete_sampler_state(struct pipe_context
*_pipe
,
289 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
290 struct pipe_context
*pipe
= rb_pipe
->pipe
;
292 pipe_mutex_lock(rb_pipe
->call_mutex
);
293 pipe
->delete_sampler_state(pipe
,
295 pipe_mutex_unlock(rb_pipe
->call_mutex
);
299 rbug_create_rasterizer_state(struct pipe_context
*_pipe
,
300 const struct pipe_rasterizer_state
*rasterizer
)
302 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
303 struct pipe_context
*pipe
= rb_pipe
->pipe
;
306 pipe_mutex_lock(rb_pipe
->call_mutex
);
307 ret
= pipe
->create_rasterizer_state(pipe
,
309 pipe_mutex_unlock(rb_pipe
->call_mutex
);
315 rbug_bind_rasterizer_state(struct pipe_context
*_pipe
,
318 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
319 struct pipe_context
*pipe
= rb_pipe
->pipe
;
321 pipe_mutex_lock(rb_pipe
->call_mutex
);
322 pipe
->bind_rasterizer_state(pipe
,
324 pipe_mutex_unlock(rb_pipe
->call_mutex
);
328 rbug_delete_rasterizer_state(struct pipe_context
*_pipe
,
331 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
332 struct pipe_context
*pipe
= rb_pipe
->pipe
;
334 pipe_mutex_lock(rb_pipe
->call_mutex
);
335 pipe
->delete_rasterizer_state(pipe
,
337 pipe_mutex_unlock(rb_pipe
->call_mutex
);
341 rbug_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
342 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
344 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
345 struct pipe_context
*pipe
= rb_pipe
->pipe
;
348 pipe_mutex_lock(rb_pipe
->call_mutex
);
349 ret
= pipe
->create_depth_stencil_alpha_state(pipe
,
350 depth_stencil_alpha
);
351 pipe_mutex_unlock(rb_pipe
->call_mutex
);
357 rbug_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
358 void *depth_stencil_alpha
)
360 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
361 struct pipe_context
*pipe
= rb_pipe
->pipe
;
363 pipe_mutex_lock(rb_pipe
->call_mutex
);
364 pipe
->bind_depth_stencil_alpha_state(pipe
,
365 depth_stencil_alpha
);
366 pipe_mutex_unlock(rb_pipe
->call_mutex
);
370 rbug_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
371 void *depth_stencil_alpha
)
373 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
374 struct pipe_context
*pipe
= rb_pipe
->pipe
;
376 pipe_mutex_lock(rb_pipe
->call_mutex
);
377 pipe
->delete_depth_stencil_alpha_state(pipe
,
378 depth_stencil_alpha
);
379 pipe_mutex_unlock(rb_pipe
->call_mutex
);
383 rbug_create_fs_state(struct pipe_context
*_pipe
,
384 const struct pipe_shader_state
*state
)
386 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
387 struct pipe_context
*pipe
= rb_pipe
->pipe
;
390 pipe_mutex_lock(rb_pipe
->call_mutex
);
391 result
= pipe
->create_fs_state(pipe
, state
);
392 pipe_mutex_unlock(rb_pipe
->call_mutex
);
397 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_FRAGMENT
);
401 rbug_bind_fs_state(struct pipe_context
*_pipe
,
404 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
405 struct pipe_context
*pipe
= rb_pipe
->pipe
;
408 pipe_mutex_lock(rb_pipe
->call_mutex
);
410 fs
= rbug_shader_unwrap(_fs
);
411 rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
] = rbug_shader(_fs
);
412 pipe
->bind_fs_state(pipe
,
415 pipe_mutex_unlock(rb_pipe
->call_mutex
);
419 rbug_delete_fs_state(struct pipe_context
*_pipe
,
422 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
423 struct rbug_shader
*rb_shader
= rbug_shader(_fs
);
425 pipe_mutex_lock(rb_pipe
->call_mutex
);
426 rbug_shader_destroy(rb_pipe
, rb_shader
);
427 pipe_mutex_unlock(rb_pipe
->call_mutex
);
431 rbug_create_vs_state(struct pipe_context
*_pipe
,
432 const struct pipe_shader_state
*state
)
434 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
435 struct pipe_context
*pipe
= rb_pipe
->pipe
;
438 pipe_mutex_lock(rb_pipe
->call_mutex
);
439 result
= pipe
->create_vs_state(pipe
, state
);
440 pipe_mutex_unlock(rb_pipe
->call_mutex
);
445 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_VERTEX
);
449 rbug_bind_vs_state(struct pipe_context
*_pipe
,
452 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
453 struct pipe_context
*pipe
= rb_pipe
->pipe
;
456 pipe_mutex_lock(rb_pipe
->call_mutex
);
458 vs
= rbug_shader_unwrap(_vs
);
459 rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
] = rbug_shader(_vs
);
460 pipe
->bind_vs_state(pipe
,
463 pipe_mutex_unlock(rb_pipe
->call_mutex
);
467 rbug_delete_vs_state(struct pipe_context
*_pipe
,
470 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
471 struct rbug_shader
*rb_shader
= rbug_shader(_vs
);
473 pipe_mutex_unlock(rb_pipe
->call_mutex
);
474 rbug_shader_destroy(rb_pipe
, rb_shader
);
475 pipe_mutex_unlock(rb_pipe
->call_mutex
);
479 rbug_create_gs_state(struct pipe_context
*_pipe
,
480 const struct pipe_shader_state
*state
)
482 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
483 struct pipe_context
*pipe
= rb_pipe
->pipe
;
486 pipe_mutex_lock(rb_pipe
->call_mutex
);
487 result
= pipe
->create_gs_state(pipe
, state
);
488 pipe_mutex_unlock(rb_pipe
->call_mutex
);
493 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_GEOM
);
497 rbug_bind_gs_state(struct pipe_context
*_pipe
,
500 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
501 struct pipe_context
*pipe
= rb_pipe
->pipe
;
504 pipe_mutex_lock(rb_pipe
->call_mutex
);
506 gs
= rbug_shader_unwrap(_gs
);
507 rb_pipe
->curr
.shader
[PIPE_SHADER_GEOMETRY
] = rbug_shader(_gs
);
508 pipe
->bind_gs_state(pipe
,
511 pipe_mutex_unlock(rb_pipe
->call_mutex
);
515 rbug_delete_gs_state(struct pipe_context
*_pipe
,
518 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
519 struct rbug_shader
*rb_shader
= rbug_shader(_gs
);
521 pipe_mutex_lock(rb_pipe
->call_mutex
);
522 rbug_shader_destroy(rb_pipe
, rb_shader
);
523 pipe_mutex_unlock(rb_pipe
->call_mutex
);
527 rbug_create_vertex_elements_state(struct pipe_context
*_pipe
,
528 unsigned num_elements
,
529 const struct pipe_vertex_element
*vertex_elements
)
531 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
532 struct pipe_context
*pipe
= rb_pipe
->pipe
;
535 pipe_mutex_lock(rb_pipe
->call_mutex
);
536 ret
= pipe
->create_vertex_elements_state(pipe
,
539 pipe_mutex_unlock(rb_pipe
->call_mutex
);
545 rbug_bind_vertex_elements_state(struct pipe_context
*_pipe
,
548 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
549 struct pipe_context
*pipe
= rb_pipe
->pipe
;
551 pipe_mutex_lock(rb_pipe
->call_mutex
);
552 pipe
->bind_vertex_elements_state(pipe
,
554 pipe_mutex_unlock(rb_pipe
->call_mutex
);
558 rbug_delete_vertex_elements_state(struct pipe_context
*_pipe
,
561 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
562 struct pipe_context
*pipe
= rb_pipe
->pipe
;
564 pipe_mutex_lock(rb_pipe
->call_mutex
);
565 pipe
->delete_vertex_elements_state(pipe
,
567 pipe_mutex_unlock(rb_pipe
->call_mutex
);
571 rbug_set_blend_color(struct pipe_context
*_pipe
,
572 const struct pipe_blend_color
*blend_color
)
574 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
575 struct pipe_context
*pipe
= rb_pipe
->pipe
;
577 pipe_mutex_lock(rb_pipe
->call_mutex
);
578 pipe
->set_blend_color(pipe
,
580 pipe_mutex_unlock(rb_pipe
->call_mutex
);
584 rbug_set_stencil_ref(struct pipe_context
*_pipe
,
585 const struct pipe_stencil_ref
*stencil_ref
)
587 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
588 struct pipe_context
*pipe
= rb_pipe
->pipe
;
590 pipe_mutex_lock(rb_pipe
->call_mutex
);
591 pipe
->set_stencil_ref(pipe
,
593 pipe_mutex_unlock(rb_pipe
->call_mutex
);
597 rbug_set_clip_state(struct pipe_context
*_pipe
,
598 const struct pipe_clip_state
*clip
)
600 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
601 struct pipe_context
*pipe
= rb_pipe
->pipe
;
603 pipe_mutex_lock(rb_pipe
->call_mutex
);
604 pipe
->set_clip_state(pipe
,
606 pipe_mutex_unlock(rb_pipe
->call_mutex
);
610 rbug_set_constant_buffer(struct pipe_context
*_pipe
,
613 struct pipe_constant_buffer
*_cb
)
615 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
616 struct pipe_context
*pipe
= rb_pipe
->pipe
;
617 struct pipe_constant_buffer cb
;
619 /* XXX hmm? unwrap the input state */
622 cb
.buffer
= rbug_resource_unwrap(_cb
->buffer
);
625 pipe_mutex_lock(rb_pipe
->call_mutex
);
626 pipe
->set_constant_buffer(pipe
,
630 pipe_mutex_unlock(rb_pipe
->call_mutex
);
634 rbug_set_framebuffer_state(struct pipe_context
*_pipe
,
635 const struct pipe_framebuffer_state
*_state
)
637 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
638 struct pipe_context
*pipe
= rb_pipe
->pipe
;
639 struct pipe_framebuffer_state unwrapped_state
;
640 struct pipe_framebuffer_state
*state
= NULL
;
643 /* must protect curr status */
644 pipe_mutex_lock(rb_pipe
->call_mutex
);
646 rb_pipe
->curr
.nr_cbufs
= 0;
647 memset(rb_pipe
->curr
.cbufs
, 0, sizeof(rb_pipe
->curr
.cbufs
));
648 rb_pipe
->curr
.zsbuf
= NULL
;
650 /* unwrap the input state */
652 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
654 rb_pipe
->curr
.nr_cbufs
= _state
->nr_cbufs
;
655 for(i
= 0; i
< _state
->nr_cbufs
; i
++) {
656 unwrapped_state
.cbufs
[i
] = rbug_surface_unwrap(_state
->cbufs
[i
]);
657 if (_state
->cbufs
[i
])
658 rb_pipe
->curr
.cbufs
[i
] = rbug_resource(_state
->cbufs
[i
]->texture
);
660 unwrapped_state
.zsbuf
= rbug_surface_unwrap(_state
->zsbuf
);
662 rb_pipe
->curr
.zsbuf
= rbug_resource(_state
->zsbuf
->texture
);
663 state
= &unwrapped_state
;
666 pipe
->set_framebuffer_state(pipe
,
669 pipe_mutex_unlock(rb_pipe
->call_mutex
);
673 rbug_set_polygon_stipple(struct pipe_context
*_pipe
,
674 const struct pipe_poly_stipple
*poly_stipple
)
676 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
677 struct pipe_context
*pipe
= rb_pipe
->pipe
;
679 pipe_mutex_lock(rb_pipe
->call_mutex
);
680 pipe
->set_polygon_stipple(pipe
,
682 pipe_mutex_unlock(rb_pipe
->call_mutex
);
686 rbug_set_scissor_states(struct pipe_context
*_pipe
,
688 unsigned num_scissors
,
689 const struct pipe_scissor_state
*scissor
)
691 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
692 struct pipe_context
*pipe
= rb_pipe
->pipe
;
694 pipe_mutex_lock(rb_pipe
->call_mutex
);
695 pipe
->set_scissor_states(pipe
, start_slot
, num_scissors
, scissor
);
696 pipe_mutex_unlock(rb_pipe
->call_mutex
);
700 rbug_set_viewport_states(struct pipe_context
*_pipe
,
702 unsigned num_viewports
,
703 const struct pipe_viewport_state
*viewport
)
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_viewport_states(pipe
, start_slot
, num_viewports
, viewport
);
710 pipe_mutex_unlock(rb_pipe
->call_mutex
);
714 rbug_set_sampler_views(struct pipe_context
*_pipe
,
718 struct pipe_sampler_view
**_views
)
720 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
721 struct pipe_context
*pipe
= rb_pipe
->pipe
;
722 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
723 struct pipe_sampler_view
**views
= NULL
;
726 assert(start
== 0); /* XXX fix */
728 /* must protect curr status */
729 pipe_mutex_lock(rb_pipe
->call_mutex
);
731 rb_pipe
->curr
.num_views
[shader
] = 0;
732 memset(rb_pipe
->curr
.views
[shader
], 0, sizeof(rb_pipe
->curr
.views
[shader
]));
733 memset(rb_pipe
->curr
.texs
[shader
], 0, sizeof(rb_pipe
->curr
.texs
[shader
]));
734 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
737 rb_pipe
->curr
.num_views
[shader
] = num
;
738 for (i
= 0; i
< num
; i
++) {
739 rb_pipe
->curr
.views
[shader
][i
] = rbug_sampler_view(_views
[i
]);
740 rb_pipe
->curr
.texs
[shader
][i
] = rbug_resource(_views
[i
] ? _views
[i
]->texture
: NULL
);
741 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
743 views
= unwrapped_views
;
746 pipe
->set_sampler_views(pipe
, shader
, start
, num
, views
);
748 pipe_mutex_unlock(rb_pipe
->call_mutex
);
752 rbug_set_vertex_buffers(struct pipe_context
*_pipe
,
753 unsigned start_slot
, unsigned num_buffers
,
754 const struct pipe_vertex_buffer
*_buffers
)
756 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
757 struct pipe_context
*pipe
= rb_pipe
->pipe
;
758 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
759 struct pipe_vertex_buffer
*buffers
= NULL
;
762 pipe_mutex_lock(rb_pipe
->call_mutex
);
764 if (num_buffers
&& _buffers
) {
765 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
766 for (i
= 0; i
< num_buffers
; i
++)
767 unwrapped_buffers
[i
].buffer
= rbug_resource_unwrap(_buffers
[i
].buffer
);
768 buffers
= unwrapped_buffers
;
771 pipe
->set_vertex_buffers(pipe
, start_slot
,
775 pipe_mutex_unlock(rb_pipe
->call_mutex
);
779 rbug_set_index_buffer(struct pipe_context
*_pipe
,
780 const struct pipe_index_buffer
*_ib
)
782 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
783 struct pipe_context
*pipe
= rb_pipe
->pipe
;
784 struct pipe_index_buffer unwrapped_ib
, *ib
= NULL
;
788 unwrapped_ib
.buffer
= rbug_resource_unwrap(_ib
->buffer
);
792 pipe_mutex_lock(rb_pipe
->call_mutex
);
793 pipe
->set_index_buffer(pipe
, ib
);
794 pipe_mutex_unlock(rb_pipe
->call_mutex
);
798 rbug_set_sample_mask(struct pipe_context
*_pipe
,
799 unsigned sample_mask
)
801 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
802 struct pipe_context
*pipe
= rb_pipe
->pipe
;
804 pipe_mutex_lock(rb_pipe
->call_mutex
);
805 pipe
->set_sample_mask(pipe
, sample_mask
);
806 pipe_mutex_unlock(rb_pipe
->call_mutex
);
809 static struct pipe_stream_output_target
*
810 rbug_create_stream_output_target(struct pipe_context
*_pipe
,
811 struct pipe_resource
*_res
,
812 unsigned buffer_offset
, unsigned buffer_size
)
814 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
815 struct pipe_context
*pipe
= rb_pipe
->pipe
;
816 struct pipe_resource
*res
= rbug_resource_unwrap(_res
);
817 struct pipe_stream_output_target
*target
;
819 pipe_mutex_lock(rb_pipe
->call_mutex
);
820 target
= pipe
->create_stream_output_target(pipe
, res
, buffer_offset
,
822 pipe_mutex_unlock(rb_pipe
->call_mutex
);
827 rbug_stream_output_target_destroy(struct pipe_context
*_pipe
,
828 struct pipe_stream_output_target
*target
)
830 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
831 struct pipe_context
*pipe
= rb_pipe
->pipe
;
833 pipe_mutex_lock(rb_pipe
->call_mutex
);
834 pipe
->stream_output_target_destroy(pipe
, target
);
835 pipe_mutex_unlock(rb_pipe
->call_mutex
);
839 rbug_set_stream_output_targets(struct pipe_context
*_pipe
,
840 unsigned num_targets
,
841 struct pipe_stream_output_target
**targets
,
842 const unsigned *offsets
)
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
->set_stream_output_targets(pipe
, num_targets
, targets
, offsets
);
849 pipe_mutex_unlock(rb_pipe
->call_mutex
);
853 rbug_resource_copy_region(struct pipe_context
*_pipe
,
854 struct pipe_resource
*_dst
,
859 struct pipe_resource
*_src
,
861 const struct pipe_box
*src_box
)
863 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
864 struct rbug_resource
*rb_resource_dst
= rbug_resource(_dst
);
865 struct rbug_resource
*rb_resource_src
= rbug_resource(_src
);
866 struct pipe_context
*pipe
= rb_pipe
->pipe
;
867 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
868 struct pipe_resource
*src
= rb_resource_src
->resource
;
870 pipe_mutex_lock(rb_pipe
->call_mutex
);
871 pipe
->resource_copy_region(pipe
,
880 pipe_mutex_unlock(rb_pipe
->call_mutex
);
884 rbug_blit(struct pipe_context
*_pipe
, const struct pipe_blit_info
*_blit_info
)
886 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
887 struct rbug_resource
*rb_resource_dst
= rbug_resource(_blit_info
->dst
.resource
);
888 struct rbug_resource
*rb_resource_src
= rbug_resource(_blit_info
->src
.resource
);
889 struct pipe_context
*pipe
= rb_pipe
->pipe
;
890 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
891 struct pipe_resource
*src
= rb_resource_src
->resource
;
892 struct pipe_blit_info blit_info
;
894 blit_info
= *_blit_info
;
895 blit_info
.dst
.resource
= dst
;
896 blit_info
.src
.resource
= src
;
898 pipe_mutex_lock(rb_pipe
->call_mutex
);
899 pipe
->blit(pipe
, &blit_info
);
900 pipe_mutex_unlock(rb_pipe
->call_mutex
);
904 rbug_flush_resource(struct pipe_context
*_pipe
,
905 struct pipe_resource
*_res
)
907 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
908 struct rbug_resource
*rb_resource_res
= rbug_resource(_res
);
909 struct pipe_context
*pipe
= rb_pipe
->pipe
;
910 struct pipe_resource
*res
= rb_resource_res
->resource
;
912 pipe_mutex_lock(rb_pipe
->call_mutex
);
913 pipe
->flush_resource(pipe
, res
);
914 pipe_mutex_unlock(rb_pipe
->call_mutex
);
918 rbug_clear(struct pipe_context
*_pipe
,
920 const union pipe_color_union
*color
,
924 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
925 struct pipe_context
*pipe
= rb_pipe
->pipe
;
927 pipe_mutex_lock(rb_pipe
->call_mutex
);
933 pipe_mutex_unlock(rb_pipe
->call_mutex
);
937 rbug_clear_render_target(struct pipe_context
*_pipe
,
938 struct pipe_surface
*_dst
,
939 const union pipe_color_union
*color
,
940 unsigned dstx
, unsigned dsty
,
941 unsigned width
, unsigned height
)
943 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
944 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
945 struct pipe_context
*pipe
= rb_pipe
->pipe
;
946 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
948 pipe_mutex_lock(rb_pipe
->call_mutex
);
949 pipe
->clear_render_target(pipe
,
956 pipe_mutex_unlock(rb_pipe
->call_mutex
);
960 rbug_clear_depth_stencil(struct pipe_context
*_pipe
,
961 struct pipe_surface
*_dst
,
962 unsigned clear_flags
,
965 unsigned dstx
, unsigned dsty
,
966 unsigned width
, unsigned height
)
968 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
969 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
970 struct pipe_context
*pipe
= rb_pipe
->pipe
;
971 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
973 pipe_mutex_lock(rb_pipe
->call_mutex
);
974 pipe
->clear_depth_stencil(pipe
,
983 pipe_mutex_unlock(rb_pipe
->call_mutex
);
987 rbug_flush(struct pipe_context
*_pipe
,
988 struct pipe_fence_handle
**fence
,
991 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
992 struct pipe_context
*pipe
= rb_pipe
->pipe
;
994 pipe_mutex_lock(rb_pipe
->call_mutex
);
995 pipe
->flush(pipe
, fence
, flags
);
996 pipe_mutex_unlock(rb_pipe
->call_mutex
);
999 static struct pipe_sampler_view
*
1000 rbug_context_create_sampler_view(struct pipe_context
*_pipe
,
1001 struct pipe_resource
*_resource
,
1002 const struct pipe_sampler_view
*templ
)
1004 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1005 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1006 struct pipe_context
*pipe
= rb_pipe
->pipe
;
1007 struct pipe_resource
*resource
= rb_resource
->resource
;
1008 struct pipe_sampler_view
*result
;
1010 pipe_mutex_lock(rb_pipe
->call_mutex
);
1011 result
= pipe
->create_sampler_view(pipe
,
1014 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1017 return rbug_sampler_view_create(rb_pipe
, rb_resource
, result
);
1022 rbug_context_sampler_view_destroy(struct pipe_context
*_pipe
,
1023 struct pipe_sampler_view
*_view
)
1025 rbug_sampler_view_destroy(rbug_context(_pipe
),
1026 rbug_sampler_view(_view
));
1029 static struct pipe_surface
*
1030 rbug_context_create_surface(struct pipe_context
*_pipe
,
1031 struct pipe_resource
*_resource
,
1032 const struct pipe_surface
*surf_tmpl
)
1034 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1035 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1036 struct pipe_context
*pipe
= rb_pipe
->pipe
;
1037 struct pipe_resource
*resource
= rb_resource
->resource
;
1038 struct pipe_surface
*result
;
1040 pipe_mutex_lock(rb_pipe
->call_mutex
);
1041 result
= pipe
->create_surface(pipe
,
1044 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1047 return rbug_surface_create(rb_pipe
, rb_resource
, result
);
1052 rbug_context_surface_destroy(struct pipe_context
*_pipe
,
1053 struct pipe_surface
*_surface
)
1055 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1056 struct rbug_surface
*rb_surface
= rbug_surface(_surface
);
1058 pipe_mutex_lock(rb_pipe
->call_mutex
);
1059 rbug_surface_destroy(rb_pipe
,
1061 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1067 rbug_context_transfer_map(struct pipe_context
*_context
,
1068 struct pipe_resource
*_resource
,
1071 const struct pipe_box
*box
,
1072 struct pipe_transfer
**transfer
)
1074 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1075 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1076 struct pipe_context
*context
= rb_pipe
->pipe
;
1077 struct pipe_resource
*resource
= rb_resource
->resource
;
1078 struct pipe_transfer
*result
;
1081 pipe_mutex_lock(rb_pipe
->call_mutex
);
1082 map
= context
->transfer_map(context
,
1087 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1089 *transfer
= rbug_transfer_create(rb_pipe
, rb_resource
, result
);
1090 return *transfer
? map
: NULL
;
1094 rbug_context_transfer_flush_region(struct pipe_context
*_context
,
1095 struct pipe_transfer
*_transfer
,
1096 const struct pipe_box
*box
)
1098 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1099 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1100 struct pipe_context
*context
= rb_pipe
->pipe
;
1101 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1103 pipe_mutex_lock(rb_pipe
->call_mutex
);
1104 context
->transfer_flush_region(context
,
1107 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1112 rbug_context_transfer_unmap(struct pipe_context
*_context
,
1113 struct pipe_transfer
*_transfer
)
1115 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1116 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1117 struct pipe_context
*context
= rb_pipe
->pipe
;
1118 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1120 pipe_mutex_lock(rb_pipe
->call_mutex
);
1121 context
->transfer_unmap(context
,
1123 rbug_transfer_destroy(rb_pipe
,
1125 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1130 rbug_context_transfer_inline_write(struct pipe_context
*_context
,
1131 struct pipe_resource
*_resource
,
1134 const struct pipe_box
*box
,
1137 unsigned layer_stride
)
1139 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1140 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1141 struct pipe_context
*context
= rb_pipe
->pipe
;
1142 struct pipe_resource
*resource
= rb_resource
->resource
;
1144 pipe_mutex_lock(rb_pipe
->call_mutex
);
1145 context
->transfer_inline_write(context
,
1153 pipe_mutex_unlock(rb_pipe
->call_mutex
);
1157 struct pipe_context
*
1158 rbug_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1160 struct rbug_context
*rb_pipe
;
1161 struct rbug_screen
*rb_screen
= rbug_screen(_screen
);
1166 rb_pipe
= CALLOC_STRUCT(rbug_context
);
1170 pipe_mutex_init(rb_pipe
->draw_mutex
);
1171 pipe_condvar_init(rb_pipe
->draw_cond
);
1172 pipe_mutex_init(rb_pipe
->call_mutex
);
1173 pipe_mutex_init(rb_pipe
->list_mutex
);
1174 make_empty_list(&rb_pipe
->shaders
);
1176 rb_pipe
->base
.screen
= _screen
;
1177 rb_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1178 rb_pipe
->base
.draw
= NULL
;
1180 rb_pipe
->base
.destroy
= rbug_destroy
;
1181 rb_pipe
->base
.draw_vbo
= rbug_draw_vbo
;
1182 rb_pipe
->base
.create_query
= rbug_create_query
;
1183 rb_pipe
->base
.destroy_query
= rbug_destroy_query
;
1184 rb_pipe
->base
.begin_query
= rbug_begin_query
;
1185 rb_pipe
->base
.end_query
= rbug_end_query
;
1186 rb_pipe
->base
.get_query_result
= rbug_get_query_result
;
1187 rb_pipe
->base
.create_blend_state
= rbug_create_blend_state
;
1188 rb_pipe
->base
.bind_blend_state
= rbug_bind_blend_state
;
1189 rb_pipe
->base
.delete_blend_state
= rbug_delete_blend_state
;
1190 rb_pipe
->base
.create_sampler_state
= rbug_create_sampler_state
;
1191 rb_pipe
->base
.bind_sampler_states
= rbug_bind_sampler_states
;
1192 rb_pipe
->base
.delete_sampler_state
= rbug_delete_sampler_state
;
1193 rb_pipe
->base
.create_rasterizer_state
= rbug_create_rasterizer_state
;
1194 rb_pipe
->base
.bind_rasterizer_state
= rbug_bind_rasterizer_state
;
1195 rb_pipe
->base
.delete_rasterizer_state
= rbug_delete_rasterizer_state
;
1196 rb_pipe
->base
.create_depth_stencil_alpha_state
= rbug_create_depth_stencil_alpha_state
;
1197 rb_pipe
->base
.bind_depth_stencil_alpha_state
= rbug_bind_depth_stencil_alpha_state
;
1198 rb_pipe
->base
.delete_depth_stencil_alpha_state
= rbug_delete_depth_stencil_alpha_state
;
1199 rb_pipe
->base
.create_fs_state
= rbug_create_fs_state
;
1200 rb_pipe
->base
.bind_fs_state
= rbug_bind_fs_state
;
1201 rb_pipe
->base
.delete_fs_state
= rbug_delete_fs_state
;
1202 rb_pipe
->base
.create_vs_state
= rbug_create_vs_state
;
1203 rb_pipe
->base
.bind_vs_state
= rbug_bind_vs_state
;
1204 rb_pipe
->base
.delete_vs_state
= rbug_delete_vs_state
;
1205 rb_pipe
->base
.create_gs_state
= rbug_create_gs_state
;
1206 rb_pipe
->base
.bind_gs_state
= rbug_bind_gs_state
;
1207 rb_pipe
->base
.delete_gs_state
= rbug_delete_gs_state
;
1208 rb_pipe
->base
.create_vertex_elements_state
= rbug_create_vertex_elements_state
;
1209 rb_pipe
->base
.bind_vertex_elements_state
= rbug_bind_vertex_elements_state
;
1210 rb_pipe
->base
.delete_vertex_elements_state
= rbug_delete_vertex_elements_state
;
1211 rb_pipe
->base
.set_blend_color
= rbug_set_blend_color
;
1212 rb_pipe
->base
.set_stencil_ref
= rbug_set_stencil_ref
;
1213 rb_pipe
->base
.set_clip_state
= rbug_set_clip_state
;
1214 rb_pipe
->base
.set_constant_buffer
= rbug_set_constant_buffer
;
1215 rb_pipe
->base
.set_framebuffer_state
= rbug_set_framebuffer_state
;
1216 rb_pipe
->base
.set_polygon_stipple
= rbug_set_polygon_stipple
;
1217 rb_pipe
->base
.set_scissor_states
= rbug_set_scissor_states
;
1218 rb_pipe
->base
.set_viewport_states
= rbug_set_viewport_states
;
1219 rb_pipe
->base
.set_sampler_views
= rbug_set_sampler_views
;
1220 rb_pipe
->base
.set_vertex_buffers
= rbug_set_vertex_buffers
;
1221 rb_pipe
->base
.set_index_buffer
= rbug_set_index_buffer
;
1222 rb_pipe
->base
.set_sample_mask
= rbug_set_sample_mask
;
1223 rb_pipe
->base
.create_stream_output_target
= rbug_create_stream_output_target
;
1224 rb_pipe
->base
.stream_output_target_destroy
= rbug_stream_output_target_destroy
;
1225 rb_pipe
->base
.set_stream_output_targets
= rbug_set_stream_output_targets
;
1226 rb_pipe
->base
.resource_copy_region
= rbug_resource_copy_region
;
1227 rb_pipe
->base
.blit
= rbug_blit
;
1228 rb_pipe
->base
.flush_resource
= rbug_flush_resource
;
1229 rb_pipe
->base
.clear
= rbug_clear
;
1230 rb_pipe
->base
.clear_render_target
= rbug_clear_render_target
;
1231 rb_pipe
->base
.clear_depth_stencil
= rbug_clear_depth_stencil
;
1232 rb_pipe
->base
.flush
= rbug_flush
;
1233 rb_pipe
->base
.create_sampler_view
= rbug_context_create_sampler_view
;
1234 rb_pipe
->base
.sampler_view_destroy
= rbug_context_sampler_view_destroy
;
1235 rb_pipe
->base
.create_surface
= rbug_context_create_surface
;
1236 rb_pipe
->base
.surface_destroy
= rbug_context_surface_destroy
;
1237 rb_pipe
->base
.transfer_map
= rbug_context_transfer_map
;
1238 rb_pipe
->base
.transfer_unmap
= rbug_context_transfer_unmap
;
1239 rb_pipe
->base
.transfer_flush_region
= rbug_context_transfer_flush_region
;
1240 rb_pipe
->base
.transfer_inline_write
= rbug_context_transfer_inline_write
;
1242 rb_pipe
->pipe
= pipe
;
1244 rbug_screen_add_to_list(rb_screen
, contexts
, rb_pipe
);
1246 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE
)) {
1247 rb_pipe
->draw_blocked
= RBUG_BLOCK_BEFORE
;
1250 return &rb_pipe
->base
;