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 mtx_lock(&rb_pipe
->call_mutex
);
52 mtx_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
)) {
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
< ARRAY_SIZE(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 cnd_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 mtx_lock(&rb_pipe
->draw_mutex
);
123 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_BEFORE
);
125 mtx_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 mtx_unlock(&rb_pipe
->call_mutex
);
133 rbug_draw_block_locked(rb_pipe
, RBUG_BLOCK_AFTER
);
134 mtx_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 mtx_lock(&rb_pipe
->call_mutex
);
147 query
= pipe
->create_query(pipe
,
150 mtx_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 mtx_lock(&rb_pipe
->call_mutex
);
162 pipe
->destroy_query(pipe
,
164 mtx_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 mtx_lock(&rb_pipe
->call_mutex
);
176 ret
= pipe
->begin_query(pipe
, query
);
177 mtx_unlock(&rb_pipe
->call_mutex
);
182 rbug_end_query(struct pipe_context
*_pipe
,
183 struct pipe_query
*query
)
185 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
186 struct pipe_context
*pipe
= rb_pipe
->pipe
;
189 mtx_lock(&rb_pipe
->call_mutex
);
190 ret
= pipe
->end_query(pipe
,
192 mtx_unlock(&rb_pipe
->call_mutex
);
198 rbug_get_query_result(struct pipe_context
*_pipe
,
199 struct pipe_query
*query
,
201 union pipe_query_result
*result
)
203 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
204 struct pipe_context
*pipe
= rb_pipe
->pipe
;
207 mtx_lock(&rb_pipe
->call_mutex
);
208 ret
= pipe
->get_query_result(pipe
,
212 mtx_unlock(&rb_pipe
->call_mutex
);
218 rbug_set_active_query_state(struct pipe_context
*_pipe
, bool enable
)
220 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
221 struct pipe_context
*pipe
= rb_pipe
->pipe
;
223 mtx_lock(&rb_pipe
->call_mutex
);
224 pipe
->set_active_query_state(pipe
, enable
);
225 mtx_unlock(&rb_pipe
->call_mutex
);
229 rbug_create_blend_state(struct pipe_context
*_pipe
,
230 const struct pipe_blend_state
*blend
)
232 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
233 struct pipe_context
*pipe
= rb_pipe
->pipe
;
236 mtx_lock(&rb_pipe
->call_mutex
);
237 ret
= pipe
->create_blend_state(pipe
,
239 mtx_unlock(&rb_pipe
->call_mutex
);
245 rbug_bind_blend_state(struct pipe_context
*_pipe
,
248 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
249 struct pipe_context
*pipe
= rb_pipe
->pipe
;
251 mtx_lock(&rb_pipe
->call_mutex
);
252 pipe
->bind_blend_state(pipe
,
254 mtx_unlock(&rb_pipe
->call_mutex
);
258 rbug_delete_blend_state(struct pipe_context
*_pipe
,
261 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
262 struct pipe_context
*pipe
= rb_pipe
->pipe
;
264 mtx_lock(&rb_pipe
->call_mutex
);
265 pipe
->delete_blend_state(pipe
,
267 mtx_unlock(&rb_pipe
->call_mutex
);
271 rbug_create_sampler_state(struct pipe_context
*_pipe
,
272 const struct pipe_sampler_state
*sampler
)
274 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
275 struct pipe_context
*pipe
= rb_pipe
->pipe
;
278 mtx_lock(&rb_pipe
->call_mutex
);
279 ret
= pipe
->create_sampler_state(pipe
,
281 mtx_unlock(&rb_pipe
->call_mutex
);
287 rbug_bind_sampler_states(struct pipe_context
*_pipe
,
288 enum pipe_shader_type shader
,
289 unsigned start
, unsigned count
,
292 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
293 struct pipe_context
*pipe
= rb_pipe
->pipe
;
295 mtx_lock(&rb_pipe
->call_mutex
);
296 pipe
->bind_sampler_states(pipe
, shader
, start
, count
, samplers
);
297 mtx_unlock(&rb_pipe
->call_mutex
);
301 rbug_delete_sampler_state(struct pipe_context
*_pipe
,
304 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
305 struct pipe_context
*pipe
= rb_pipe
->pipe
;
307 mtx_lock(&rb_pipe
->call_mutex
);
308 pipe
->delete_sampler_state(pipe
,
310 mtx_unlock(&rb_pipe
->call_mutex
);
314 rbug_create_rasterizer_state(struct pipe_context
*_pipe
,
315 const struct pipe_rasterizer_state
*rasterizer
)
317 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
318 struct pipe_context
*pipe
= rb_pipe
->pipe
;
321 mtx_lock(&rb_pipe
->call_mutex
);
322 ret
= pipe
->create_rasterizer_state(pipe
,
324 mtx_unlock(&rb_pipe
->call_mutex
);
330 rbug_bind_rasterizer_state(struct pipe_context
*_pipe
,
333 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
334 struct pipe_context
*pipe
= rb_pipe
->pipe
;
336 mtx_lock(&rb_pipe
->call_mutex
);
337 pipe
->bind_rasterizer_state(pipe
,
339 mtx_unlock(&rb_pipe
->call_mutex
);
343 rbug_delete_rasterizer_state(struct pipe_context
*_pipe
,
346 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
347 struct pipe_context
*pipe
= rb_pipe
->pipe
;
349 mtx_lock(&rb_pipe
->call_mutex
);
350 pipe
->delete_rasterizer_state(pipe
,
352 mtx_unlock(&rb_pipe
->call_mutex
);
356 rbug_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
357 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
359 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
360 struct pipe_context
*pipe
= rb_pipe
->pipe
;
363 mtx_lock(&rb_pipe
->call_mutex
);
364 ret
= pipe
->create_depth_stencil_alpha_state(pipe
,
365 depth_stencil_alpha
);
366 mtx_unlock(&rb_pipe
->call_mutex
);
372 rbug_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
373 void *depth_stencil_alpha
)
375 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
376 struct pipe_context
*pipe
= rb_pipe
->pipe
;
378 mtx_lock(&rb_pipe
->call_mutex
);
379 pipe
->bind_depth_stencil_alpha_state(pipe
,
380 depth_stencil_alpha
);
381 mtx_unlock(&rb_pipe
->call_mutex
);
385 rbug_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
386 void *depth_stencil_alpha
)
388 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
389 struct pipe_context
*pipe
= rb_pipe
->pipe
;
391 mtx_lock(&rb_pipe
->call_mutex
);
392 pipe
->delete_depth_stencil_alpha_state(pipe
,
393 depth_stencil_alpha
);
394 mtx_unlock(&rb_pipe
->call_mutex
);
398 rbug_create_fs_state(struct pipe_context
*_pipe
,
399 const struct pipe_shader_state
*state
)
401 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
402 struct pipe_context
*pipe
= rb_pipe
->pipe
;
405 mtx_lock(&rb_pipe
->call_mutex
);
406 result
= pipe
->create_fs_state(pipe
, state
);
407 mtx_unlock(&rb_pipe
->call_mutex
);
412 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_FRAGMENT
);
416 rbug_bind_fs_state(struct pipe_context
*_pipe
,
419 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
420 struct pipe_context
*pipe
= rb_pipe
->pipe
;
423 mtx_lock(&rb_pipe
->call_mutex
);
425 fs
= rbug_shader_unwrap(_fs
);
426 rb_pipe
->curr
.shader
[PIPE_SHADER_FRAGMENT
] = rbug_shader(_fs
);
427 pipe
->bind_fs_state(pipe
,
430 mtx_unlock(&rb_pipe
->call_mutex
);
434 rbug_delete_fs_state(struct pipe_context
*_pipe
,
437 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
438 struct rbug_shader
*rb_shader
= rbug_shader(_fs
);
440 mtx_lock(&rb_pipe
->call_mutex
);
441 rbug_shader_destroy(rb_pipe
, rb_shader
);
442 mtx_unlock(&rb_pipe
->call_mutex
);
446 rbug_create_vs_state(struct pipe_context
*_pipe
,
447 const struct pipe_shader_state
*state
)
449 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
450 struct pipe_context
*pipe
= rb_pipe
->pipe
;
453 mtx_lock(&rb_pipe
->call_mutex
);
454 result
= pipe
->create_vs_state(pipe
, state
);
455 mtx_unlock(&rb_pipe
->call_mutex
);
460 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_VERTEX
);
464 rbug_bind_vs_state(struct pipe_context
*_pipe
,
467 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
468 struct pipe_context
*pipe
= rb_pipe
->pipe
;
471 mtx_lock(&rb_pipe
->call_mutex
);
473 vs
= rbug_shader_unwrap(_vs
);
474 rb_pipe
->curr
.shader
[PIPE_SHADER_VERTEX
] = rbug_shader(_vs
);
475 pipe
->bind_vs_state(pipe
,
478 mtx_unlock(&rb_pipe
->call_mutex
);
482 rbug_delete_vs_state(struct pipe_context
*_pipe
,
485 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
486 struct rbug_shader
*rb_shader
= rbug_shader(_vs
);
488 mtx_unlock(&rb_pipe
->call_mutex
);
489 rbug_shader_destroy(rb_pipe
, rb_shader
);
490 mtx_unlock(&rb_pipe
->call_mutex
);
494 rbug_create_gs_state(struct pipe_context
*_pipe
,
495 const struct pipe_shader_state
*state
)
497 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
498 struct pipe_context
*pipe
= rb_pipe
->pipe
;
501 mtx_lock(&rb_pipe
->call_mutex
);
502 result
= pipe
->create_gs_state(pipe
, state
);
503 mtx_unlock(&rb_pipe
->call_mutex
);
508 return rbug_shader_create(rb_pipe
, state
, result
, RBUG_SHADER_GEOM
);
512 rbug_bind_gs_state(struct pipe_context
*_pipe
,
515 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
516 struct pipe_context
*pipe
= rb_pipe
->pipe
;
519 mtx_lock(&rb_pipe
->call_mutex
);
521 gs
= rbug_shader_unwrap(_gs
);
522 rb_pipe
->curr
.shader
[PIPE_SHADER_GEOMETRY
] = rbug_shader(_gs
);
523 pipe
->bind_gs_state(pipe
,
526 mtx_unlock(&rb_pipe
->call_mutex
);
530 rbug_delete_gs_state(struct pipe_context
*_pipe
,
533 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
534 struct rbug_shader
*rb_shader
= rbug_shader(_gs
);
536 mtx_lock(&rb_pipe
->call_mutex
);
537 rbug_shader_destroy(rb_pipe
, rb_shader
);
538 mtx_unlock(&rb_pipe
->call_mutex
);
542 rbug_create_vertex_elements_state(struct pipe_context
*_pipe
,
543 unsigned num_elements
,
544 const struct pipe_vertex_element
*vertex_elements
)
546 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
547 struct pipe_context
*pipe
= rb_pipe
->pipe
;
550 mtx_lock(&rb_pipe
->call_mutex
);
551 ret
= pipe
->create_vertex_elements_state(pipe
,
554 mtx_unlock(&rb_pipe
->call_mutex
);
560 rbug_bind_vertex_elements_state(struct pipe_context
*_pipe
,
563 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
564 struct pipe_context
*pipe
= rb_pipe
->pipe
;
566 mtx_lock(&rb_pipe
->call_mutex
);
567 pipe
->bind_vertex_elements_state(pipe
,
569 mtx_unlock(&rb_pipe
->call_mutex
);
573 rbug_delete_vertex_elements_state(struct pipe_context
*_pipe
,
576 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
577 struct pipe_context
*pipe
= rb_pipe
->pipe
;
579 mtx_lock(&rb_pipe
->call_mutex
);
580 pipe
->delete_vertex_elements_state(pipe
,
582 mtx_unlock(&rb_pipe
->call_mutex
);
586 rbug_set_blend_color(struct pipe_context
*_pipe
,
587 const struct pipe_blend_color
*blend_color
)
589 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
590 struct pipe_context
*pipe
= rb_pipe
->pipe
;
592 mtx_lock(&rb_pipe
->call_mutex
);
593 pipe
->set_blend_color(pipe
,
595 mtx_unlock(&rb_pipe
->call_mutex
);
599 rbug_set_stencil_ref(struct pipe_context
*_pipe
,
600 const struct pipe_stencil_ref
*stencil_ref
)
602 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
603 struct pipe_context
*pipe
= rb_pipe
->pipe
;
605 mtx_lock(&rb_pipe
->call_mutex
);
606 pipe
->set_stencil_ref(pipe
,
608 mtx_unlock(&rb_pipe
->call_mutex
);
612 rbug_set_clip_state(struct pipe_context
*_pipe
,
613 const struct pipe_clip_state
*clip
)
615 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
616 struct pipe_context
*pipe
= rb_pipe
->pipe
;
618 mtx_lock(&rb_pipe
->call_mutex
);
619 pipe
->set_clip_state(pipe
,
621 mtx_unlock(&rb_pipe
->call_mutex
);
625 rbug_set_constant_buffer(struct pipe_context
*_pipe
,
626 enum pipe_shader_type shader
,
628 const struct pipe_constant_buffer
*_cb
)
630 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
631 struct pipe_context
*pipe
= rb_pipe
->pipe
;
632 struct pipe_constant_buffer cb
;
634 /* XXX hmm? unwrap the input state */
637 cb
.buffer
= rbug_resource_unwrap(_cb
->buffer
);
640 mtx_lock(&rb_pipe
->call_mutex
);
641 pipe
->set_constant_buffer(pipe
,
645 mtx_unlock(&rb_pipe
->call_mutex
);
649 rbug_set_framebuffer_state(struct pipe_context
*_pipe
,
650 const struct pipe_framebuffer_state
*_state
)
652 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
653 struct pipe_context
*pipe
= rb_pipe
->pipe
;
654 struct pipe_framebuffer_state unwrapped_state
;
655 struct pipe_framebuffer_state
*state
= NULL
;
658 /* must protect curr status */
659 mtx_lock(&rb_pipe
->call_mutex
);
661 rb_pipe
->curr
.nr_cbufs
= 0;
662 memset(rb_pipe
->curr
.cbufs
, 0, sizeof(rb_pipe
->curr
.cbufs
));
663 rb_pipe
->curr
.zsbuf
= NULL
;
665 /* unwrap the input state */
667 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
669 rb_pipe
->curr
.nr_cbufs
= _state
->nr_cbufs
;
670 for(i
= 0; i
< _state
->nr_cbufs
; i
++) {
671 unwrapped_state
.cbufs
[i
] = rbug_surface_unwrap(_state
->cbufs
[i
]);
672 if (_state
->cbufs
[i
])
673 rb_pipe
->curr
.cbufs
[i
] = rbug_resource(_state
->cbufs
[i
]->texture
);
675 unwrapped_state
.zsbuf
= rbug_surface_unwrap(_state
->zsbuf
);
677 rb_pipe
->curr
.zsbuf
= rbug_resource(_state
->zsbuf
->texture
);
678 state
= &unwrapped_state
;
681 pipe
->set_framebuffer_state(pipe
,
684 mtx_unlock(&rb_pipe
->call_mutex
);
688 rbug_set_polygon_stipple(struct pipe_context
*_pipe
,
689 const struct pipe_poly_stipple
*poly_stipple
)
691 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
692 struct pipe_context
*pipe
= rb_pipe
->pipe
;
694 mtx_lock(&rb_pipe
->call_mutex
);
695 pipe
->set_polygon_stipple(pipe
,
697 mtx_unlock(&rb_pipe
->call_mutex
);
701 rbug_set_scissor_states(struct pipe_context
*_pipe
,
703 unsigned num_scissors
,
704 const struct pipe_scissor_state
*scissor
)
706 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
707 struct pipe_context
*pipe
= rb_pipe
->pipe
;
709 mtx_lock(&rb_pipe
->call_mutex
);
710 pipe
->set_scissor_states(pipe
, start_slot
, num_scissors
, scissor
);
711 mtx_unlock(&rb_pipe
->call_mutex
);
715 rbug_set_viewport_states(struct pipe_context
*_pipe
,
717 unsigned num_viewports
,
718 const struct pipe_viewport_state
*viewport
)
720 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
721 struct pipe_context
*pipe
= rb_pipe
->pipe
;
723 mtx_lock(&rb_pipe
->call_mutex
);
724 pipe
->set_viewport_states(pipe
, start_slot
, num_viewports
, viewport
);
725 mtx_unlock(&rb_pipe
->call_mutex
);
729 rbug_set_sampler_views(struct pipe_context
*_pipe
,
730 enum pipe_shader_type shader
,
733 struct pipe_sampler_view
**_views
)
735 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
736 struct pipe_context
*pipe
= rb_pipe
->pipe
;
737 struct pipe_sampler_view
*unwrapped_views
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
738 struct pipe_sampler_view
**views
= NULL
;
741 assert(start
== 0); /* XXX fix */
743 /* must protect curr status */
744 mtx_lock(&rb_pipe
->call_mutex
);
746 rb_pipe
->curr
.num_views
[shader
] = 0;
747 memset(rb_pipe
->curr
.views
[shader
], 0, sizeof(rb_pipe
->curr
.views
[shader
]));
748 memset(rb_pipe
->curr
.texs
[shader
], 0, sizeof(rb_pipe
->curr
.texs
[shader
]));
749 memset(unwrapped_views
, 0, sizeof(unwrapped_views
));
752 rb_pipe
->curr
.num_views
[shader
] = num
;
753 for (i
= 0; i
< num
; i
++) {
754 rb_pipe
->curr
.views
[shader
][i
] = rbug_sampler_view(_views
[i
]);
755 rb_pipe
->curr
.texs
[shader
][i
] = rbug_resource(_views
[i
] ? _views
[i
]->texture
: NULL
);
756 unwrapped_views
[i
] = rbug_sampler_view_unwrap(_views
[i
]);
758 views
= unwrapped_views
;
761 pipe
->set_sampler_views(pipe
, shader
, start
, num
, views
);
763 mtx_unlock(&rb_pipe
->call_mutex
);
767 rbug_set_vertex_buffers(struct pipe_context
*_pipe
,
768 unsigned start_slot
, unsigned num_buffers
,
769 const struct pipe_vertex_buffer
*_buffers
)
771 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
772 struct pipe_context
*pipe
= rb_pipe
->pipe
;
773 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
774 struct pipe_vertex_buffer
*buffers
= NULL
;
777 mtx_lock(&rb_pipe
->call_mutex
);
779 if (num_buffers
&& _buffers
) {
780 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
781 for (i
= 0; i
< num_buffers
; i
++) {
782 if (!_buffers
[i
].is_user_buffer
)
783 unwrapped_buffers
[i
].buffer
.resource
=
784 rbug_resource_unwrap(_buffers
[i
].buffer
.resource
);
786 buffers
= unwrapped_buffers
;
789 pipe
->set_vertex_buffers(pipe
, start_slot
,
793 mtx_unlock(&rb_pipe
->call_mutex
);
797 rbug_set_sample_mask(struct pipe_context
*_pipe
,
798 unsigned sample_mask
)
800 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
801 struct pipe_context
*pipe
= rb_pipe
->pipe
;
803 mtx_lock(&rb_pipe
->call_mutex
);
804 pipe
->set_sample_mask(pipe
, sample_mask
);
805 mtx_unlock(&rb_pipe
->call_mutex
);
808 static struct pipe_stream_output_target
*
809 rbug_create_stream_output_target(struct pipe_context
*_pipe
,
810 struct pipe_resource
*_res
,
811 unsigned buffer_offset
, unsigned buffer_size
)
813 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
814 struct pipe_context
*pipe
= rb_pipe
->pipe
;
815 struct pipe_resource
*res
= rbug_resource_unwrap(_res
);
816 struct pipe_stream_output_target
*target
;
818 mtx_lock(&rb_pipe
->call_mutex
);
819 target
= pipe
->create_stream_output_target(pipe
, res
, buffer_offset
,
821 mtx_unlock(&rb_pipe
->call_mutex
);
826 rbug_stream_output_target_destroy(struct pipe_context
*_pipe
,
827 struct pipe_stream_output_target
*target
)
829 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
830 struct pipe_context
*pipe
= rb_pipe
->pipe
;
832 mtx_lock(&rb_pipe
->call_mutex
);
833 pipe
->stream_output_target_destroy(pipe
, target
);
834 mtx_unlock(&rb_pipe
->call_mutex
);
838 rbug_set_stream_output_targets(struct pipe_context
*_pipe
,
839 unsigned num_targets
,
840 struct pipe_stream_output_target
**targets
,
841 const unsigned *offsets
)
843 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
844 struct pipe_context
*pipe
= rb_pipe
->pipe
;
846 mtx_lock(&rb_pipe
->call_mutex
);
847 pipe
->set_stream_output_targets(pipe
, num_targets
, targets
, offsets
);
848 mtx_unlock(&rb_pipe
->call_mutex
);
852 rbug_resource_copy_region(struct pipe_context
*_pipe
,
853 struct pipe_resource
*_dst
,
858 struct pipe_resource
*_src
,
860 const struct pipe_box
*src_box
)
862 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
863 struct rbug_resource
*rb_resource_dst
= rbug_resource(_dst
);
864 struct rbug_resource
*rb_resource_src
= rbug_resource(_src
);
865 struct pipe_context
*pipe
= rb_pipe
->pipe
;
866 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
867 struct pipe_resource
*src
= rb_resource_src
->resource
;
869 mtx_lock(&rb_pipe
->call_mutex
);
870 pipe
->resource_copy_region(pipe
,
879 mtx_unlock(&rb_pipe
->call_mutex
);
883 rbug_blit(struct pipe_context
*_pipe
, const struct pipe_blit_info
*_blit_info
)
885 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
886 struct rbug_resource
*rb_resource_dst
= rbug_resource(_blit_info
->dst
.resource
);
887 struct rbug_resource
*rb_resource_src
= rbug_resource(_blit_info
->src
.resource
);
888 struct pipe_context
*pipe
= rb_pipe
->pipe
;
889 struct pipe_resource
*dst
= rb_resource_dst
->resource
;
890 struct pipe_resource
*src
= rb_resource_src
->resource
;
891 struct pipe_blit_info blit_info
;
893 blit_info
= *_blit_info
;
894 blit_info
.dst
.resource
= dst
;
895 blit_info
.src
.resource
= src
;
897 mtx_lock(&rb_pipe
->call_mutex
);
898 pipe
->blit(pipe
, &blit_info
);
899 mtx_unlock(&rb_pipe
->call_mutex
);
903 rbug_flush_resource(struct pipe_context
*_pipe
,
904 struct pipe_resource
*_res
)
906 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
907 struct rbug_resource
*rb_resource_res
= rbug_resource(_res
);
908 struct pipe_context
*pipe
= rb_pipe
->pipe
;
909 struct pipe_resource
*res
= rb_resource_res
->resource
;
911 mtx_lock(&rb_pipe
->call_mutex
);
912 pipe
->flush_resource(pipe
, res
);
913 mtx_unlock(&rb_pipe
->call_mutex
);
917 rbug_clear(struct pipe_context
*_pipe
,
919 const union pipe_color_union
*color
,
923 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
924 struct pipe_context
*pipe
= rb_pipe
->pipe
;
926 mtx_lock(&rb_pipe
->call_mutex
);
932 mtx_unlock(&rb_pipe
->call_mutex
);
936 rbug_clear_render_target(struct pipe_context
*_pipe
,
937 struct pipe_surface
*_dst
,
938 const union pipe_color_union
*color
,
939 unsigned dstx
, unsigned dsty
,
940 unsigned width
, unsigned height
,
941 bool render_condition_enabled
)
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 mtx_lock(&rb_pipe
->call_mutex
);
949 pipe
->clear_render_target(pipe
,
956 render_condition_enabled
);
957 mtx_unlock(&rb_pipe
->call_mutex
);
961 rbug_clear_depth_stencil(struct pipe_context
*_pipe
,
962 struct pipe_surface
*_dst
,
963 unsigned clear_flags
,
966 unsigned dstx
, unsigned dsty
,
967 unsigned width
, unsigned height
,
968 bool render_condition_enabled
)
970 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
971 struct rbug_surface
*rb_surface_dst
= rbug_surface(_dst
);
972 struct pipe_context
*pipe
= rb_pipe
->pipe
;
973 struct pipe_surface
*dst
= rb_surface_dst
->surface
;
975 mtx_lock(&rb_pipe
->call_mutex
);
976 pipe
->clear_depth_stencil(pipe
,
985 render_condition_enabled
);
986 mtx_unlock(&rb_pipe
->call_mutex
);
990 rbug_flush(struct pipe_context
*_pipe
,
991 struct pipe_fence_handle
**fence
,
994 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
995 struct pipe_context
*pipe
= rb_pipe
->pipe
;
997 mtx_lock(&rb_pipe
->call_mutex
);
998 pipe
->flush(pipe
, fence
, flags
);
999 mtx_unlock(&rb_pipe
->call_mutex
);
1002 static struct pipe_sampler_view
*
1003 rbug_context_create_sampler_view(struct pipe_context
*_pipe
,
1004 struct pipe_resource
*_resource
,
1005 const struct pipe_sampler_view
*templ
)
1007 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1008 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1009 struct pipe_context
*pipe
= rb_pipe
->pipe
;
1010 struct pipe_resource
*resource
= rb_resource
->resource
;
1011 struct pipe_sampler_view
*result
;
1013 mtx_lock(&rb_pipe
->call_mutex
);
1014 result
= pipe
->create_sampler_view(pipe
,
1017 mtx_unlock(&rb_pipe
->call_mutex
);
1020 return rbug_sampler_view_create(rb_pipe
, rb_resource
, result
);
1025 rbug_context_sampler_view_destroy(struct pipe_context
*_pipe
,
1026 struct pipe_sampler_view
*_view
)
1028 rbug_sampler_view_destroy(rbug_context(_pipe
),
1029 rbug_sampler_view(_view
));
1032 static struct pipe_surface
*
1033 rbug_context_create_surface(struct pipe_context
*_pipe
,
1034 struct pipe_resource
*_resource
,
1035 const struct pipe_surface
*surf_tmpl
)
1037 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1038 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1039 struct pipe_context
*pipe
= rb_pipe
->pipe
;
1040 struct pipe_resource
*resource
= rb_resource
->resource
;
1041 struct pipe_surface
*result
;
1043 mtx_lock(&rb_pipe
->call_mutex
);
1044 result
= pipe
->create_surface(pipe
,
1047 mtx_unlock(&rb_pipe
->call_mutex
);
1050 return rbug_surface_create(rb_pipe
, rb_resource
, result
);
1055 rbug_context_surface_destroy(struct pipe_context
*_pipe
,
1056 struct pipe_surface
*_surface
)
1058 struct rbug_context
*rb_pipe
= rbug_context(_pipe
);
1059 struct rbug_surface
*rb_surface
= rbug_surface(_surface
);
1061 mtx_lock(&rb_pipe
->call_mutex
);
1062 rbug_surface_destroy(rb_pipe
,
1064 mtx_unlock(&rb_pipe
->call_mutex
);
1070 rbug_context_transfer_map(struct pipe_context
*_context
,
1071 struct pipe_resource
*_resource
,
1074 const struct pipe_box
*box
,
1075 struct pipe_transfer
**transfer
)
1077 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1078 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1079 struct pipe_context
*context
= rb_pipe
->pipe
;
1080 struct pipe_resource
*resource
= rb_resource
->resource
;
1081 struct pipe_transfer
*result
;
1084 mtx_lock(&rb_pipe
->call_mutex
);
1085 map
= context
->transfer_map(context
,
1090 mtx_unlock(&rb_pipe
->call_mutex
);
1092 *transfer
= rbug_transfer_create(rb_pipe
, rb_resource
, result
);
1093 return *transfer
? map
: NULL
;
1097 rbug_context_transfer_flush_region(struct pipe_context
*_context
,
1098 struct pipe_transfer
*_transfer
,
1099 const struct pipe_box
*box
)
1101 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1102 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1103 struct pipe_context
*context
= rb_pipe
->pipe
;
1104 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1106 mtx_lock(&rb_pipe
->call_mutex
);
1107 context
->transfer_flush_region(context
,
1110 mtx_unlock(&rb_pipe
->call_mutex
);
1115 rbug_context_transfer_unmap(struct pipe_context
*_context
,
1116 struct pipe_transfer
*_transfer
)
1118 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1119 struct rbug_transfer
*rb_transfer
= rbug_transfer(_transfer
);
1120 struct pipe_context
*context
= rb_pipe
->pipe
;
1121 struct pipe_transfer
*transfer
= rb_transfer
->transfer
;
1123 mtx_lock(&rb_pipe
->call_mutex
);
1124 context
->transfer_unmap(context
,
1126 rbug_transfer_destroy(rb_pipe
,
1128 mtx_unlock(&rb_pipe
->call_mutex
);
1133 rbug_context_buffer_subdata(struct pipe_context
*_context
,
1134 struct pipe_resource
*_resource
,
1135 unsigned usage
, unsigned offset
,
1136 unsigned size
, const void *data
)
1138 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1139 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1140 struct pipe_context
*context
= rb_pipe
->pipe
;
1141 struct pipe_resource
*resource
= rb_resource
->resource
;
1143 mtx_lock(&rb_pipe
->call_mutex
);
1144 context
->buffer_subdata(context
, resource
, usage
, offset
, size
, data
);
1145 mtx_unlock(&rb_pipe
->call_mutex
);
1150 rbug_context_texture_subdata(struct pipe_context
*_context
,
1151 struct pipe_resource
*_resource
,
1154 const struct pipe_box
*box
,
1157 unsigned layer_stride
)
1159 struct rbug_context
*rb_pipe
= rbug_context(_context
);
1160 struct rbug_resource
*rb_resource
= rbug_resource(_resource
);
1161 struct pipe_context
*context
= rb_pipe
->pipe
;
1162 struct pipe_resource
*resource
= rb_resource
->resource
;
1164 mtx_lock(&rb_pipe
->call_mutex
);
1165 context
->texture_subdata(context
,
1173 mtx_unlock(&rb_pipe
->call_mutex
);
1177 struct pipe_context
*
1178 rbug_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
1180 struct rbug_context
*rb_pipe
;
1181 struct rbug_screen
*rb_screen
= rbug_screen(_screen
);
1186 rb_pipe
= CALLOC_STRUCT(rbug_context
);
1190 (void) mtx_init(&rb_pipe
->draw_mutex
, mtx_plain
);
1191 cnd_init(&rb_pipe
->draw_cond
);
1192 (void) mtx_init(&rb_pipe
->call_mutex
, mtx_plain
);
1193 (void) mtx_init(&rb_pipe
->list_mutex
, mtx_plain
);
1194 make_empty_list(&rb_pipe
->shaders
);
1196 rb_pipe
->base
.screen
= _screen
;
1197 rb_pipe
->base
.priv
= pipe
->priv
; /* expose wrapped data */
1198 rb_pipe
->base
.draw
= NULL
;
1199 rb_pipe
->base
.stream_uploader
= pipe
->stream_uploader
;
1200 rb_pipe
->base
.const_uploader
= pipe
->const_uploader
;
1202 rb_pipe
->base
.destroy
= rbug_destroy
;
1203 rb_pipe
->base
.draw_vbo
= rbug_draw_vbo
;
1204 rb_pipe
->base
.create_query
= rbug_create_query
;
1205 rb_pipe
->base
.destroy_query
= rbug_destroy_query
;
1206 rb_pipe
->base
.begin_query
= rbug_begin_query
;
1207 rb_pipe
->base
.end_query
= rbug_end_query
;
1208 rb_pipe
->base
.get_query_result
= rbug_get_query_result
;
1209 rb_pipe
->base
.set_active_query_state
= rbug_set_active_query_state
;
1210 rb_pipe
->base
.create_blend_state
= rbug_create_blend_state
;
1211 rb_pipe
->base
.bind_blend_state
= rbug_bind_blend_state
;
1212 rb_pipe
->base
.delete_blend_state
= rbug_delete_blend_state
;
1213 rb_pipe
->base
.create_sampler_state
= rbug_create_sampler_state
;
1214 rb_pipe
->base
.bind_sampler_states
= rbug_bind_sampler_states
;
1215 rb_pipe
->base
.delete_sampler_state
= rbug_delete_sampler_state
;
1216 rb_pipe
->base
.create_rasterizer_state
= rbug_create_rasterizer_state
;
1217 rb_pipe
->base
.bind_rasterizer_state
= rbug_bind_rasterizer_state
;
1218 rb_pipe
->base
.delete_rasterizer_state
= rbug_delete_rasterizer_state
;
1219 rb_pipe
->base
.create_depth_stencil_alpha_state
= rbug_create_depth_stencil_alpha_state
;
1220 rb_pipe
->base
.bind_depth_stencil_alpha_state
= rbug_bind_depth_stencil_alpha_state
;
1221 rb_pipe
->base
.delete_depth_stencil_alpha_state
= rbug_delete_depth_stencil_alpha_state
;
1222 rb_pipe
->base
.create_fs_state
= rbug_create_fs_state
;
1223 rb_pipe
->base
.bind_fs_state
= rbug_bind_fs_state
;
1224 rb_pipe
->base
.delete_fs_state
= rbug_delete_fs_state
;
1225 rb_pipe
->base
.create_vs_state
= rbug_create_vs_state
;
1226 rb_pipe
->base
.bind_vs_state
= rbug_bind_vs_state
;
1227 rb_pipe
->base
.delete_vs_state
= rbug_delete_vs_state
;
1228 rb_pipe
->base
.create_gs_state
= rbug_create_gs_state
;
1229 rb_pipe
->base
.bind_gs_state
= rbug_bind_gs_state
;
1230 rb_pipe
->base
.delete_gs_state
= rbug_delete_gs_state
;
1231 rb_pipe
->base
.create_vertex_elements_state
= rbug_create_vertex_elements_state
;
1232 rb_pipe
->base
.bind_vertex_elements_state
= rbug_bind_vertex_elements_state
;
1233 rb_pipe
->base
.delete_vertex_elements_state
= rbug_delete_vertex_elements_state
;
1234 rb_pipe
->base
.set_blend_color
= rbug_set_blend_color
;
1235 rb_pipe
->base
.set_stencil_ref
= rbug_set_stencil_ref
;
1236 rb_pipe
->base
.set_clip_state
= rbug_set_clip_state
;
1237 rb_pipe
->base
.set_constant_buffer
= rbug_set_constant_buffer
;
1238 rb_pipe
->base
.set_framebuffer_state
= rbug_set_framebuffer_state
;
1239 rb_pipe
->base
.set_polygon_stipple
= rbug_set_polygon_stipple
;
1240 rb_pipe
->base
.set_scissor_states
= rbug_set_scissor_states
;
1241 rb_pipe
->base
.set_viewport_states
= rbug_set_viewport_states
;
1242 rb_pipe
->base
.set_sampler_views
= rbug_set_sampler_views
;
1243 rb_pipe
->base
.set_vertex_buffers
= rbug_set_vertex_buffers
;
1244 rb_pipe
->base
.set_sample_mask
= rbug_set_sample_mask
;
1245 rb_pipe
->base
.create_stream_output_target
= rbug_create_stream_output_target
;
1246 rb_pipe
->base
.stream_output_target_destroy
= rbug_stream_output_target_destroy
;
1247 rb_pipe
->base
.set_stream_output_targets
= rbug_set_stream_output_targets
;
1248 rb_pipe
->base
.resource_copy_region
= rbug_resource_copy_region
;
1249 rb_pipe
->base
.blit
= rbug_blit
;
1250 rb_pipe
->base
.flush_resource
= rbug_flush_resource
;
1251 rb_pipe
->base
.clear
= rbug_clear
;
1252 rb_pipe
->base
.clear_render_target
= rbug_clear_render_target
;
1253 rb_pipe
->base
.clear_depth_stencil
= rbug_clear_depth_stencil
;
1254 rb_pipe
->base
.flush
= rbug_flush
;
1255 rb_pipe
->base
.create_sampler_view
= rbug_context_create_sampler_view
;
1256 rb_pipe
->base
.sampler_view_destroy
= rbug_context_sampler_view_destroy
;
1257 rb_pipe
->base
.create_surface
= rbug_context_create_surface
;
1258 rb_pipe
->base
.surface_destroy
= rbug_context_surface_destroy
;
1259 rb_pipe
->base
.transfer_map
= rbug_context_transfer_map
;
1260 rb_pipe
->base
.transfer_unmap
= rbug_context_transfer_unmap
;
1261 rb_pipe
->base
.transfer_flush_region
= rbug_context_transfer_flush_region
;
1262 rb_pipe
->base
.buffer_subdata
= rbug_context_buffer_subdata
;
1263 rb_pipe
->base
.texture_subdata
= rbug_context_texture_subdata
;
1265 rb_pipe
->pipe
= pipe
;
1267 rbug_screen_add_to_list(rb_screen
, contexts
, rb_pipe
);
1269 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", false)) {
1270 rb_pipe
->draw_blocked
= RBUG_BLOCK_BEFORE
;
1273 return &rb_pipe
->base
;