gallium: split transfer_inline_write into buffer and texture callbacks
[mesa.git] / src / gallium / drivers / rbug / rbug_context.c
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_context.h"
30 #include "util/u_memory.h"
31 #include "util/u_inlines.h"
32 #include "util/simple_list.h"
33
34 #include "rbug/rbug_context.h"
35
36 #include "rbug_context.h"
37 #include "rbug_objects.h"
38
39
40 static void
41 rbug_destroy(struct pipe_context *_pipe)
42 {
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;
46
47 rbug_screen_remove_from_list(rb_screen, contexts, rb_pipe);
48
49 pipe_mutex_lock(rb_pipe->call_mutex);
50 pipe->destroy(pipe);
51 rb_pipe->pipe = NULL;
52 pipe_mutex_unlock(rb_pipe->call_mutex);
53
54 FREE(rb_pipe);
55 }
56
57 static void
58 rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
59 {
60
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)) {
65 unsigned k;
66 boolean block = FALSE;
67 unsigned sh;
68
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])
79 block = TRUE;
80 }
81
82 if (rb_pipe->draw_rule.surf &&
83 rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
84 block = TRUE;
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])
88 block = TRUE;
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]) {
93 block = TRUE;
94 sh = PIPE_SHADER_TYPES; /* to break out of both loops */
95 break;
96 }
97 }
98 }
99 }
100
101 if (block)
102 rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
103 }
104
105 if (rb_pipe->draw_blocked)
106 rbug_notify_draw_blocked(rb_pipe);
107
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);
112 }
113
114 }
115
116 static void
117 rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
118 {
119 struct rbug_context *rb_pipe = rbug_context(_pipe);
120 struct pipe_context *pipe = rb_pipe->pipe;
121
122 pipe_mutex_lock(rb_pipe->draw_mutex);
123 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
124
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);
132
133 rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
134 pipe_mutex_unlock(rb_pipe->draw_mutex);
135 }
136
137 static struct pipe_query *
138 rbug_create_query(struct pipe_context *_pipe,
139 unsigned query_type,
140 unsigned index)
141 {
142 struct rbug_context *rb_pipe = rbug_context(_pipe);
143 struct pipe_context *pipe = rb_pipe->pipe;
144 struct pipe_query *query;
145
146 pipe_mutex_lock(rb_pipe->call_mutex);
147 query = pipe->create_query(pipe,
148 query_type,
149 index);
150 pipe_mutex_unlock(rb_pipe->call_mutex);
151 return query;
152 }
153
154 static void
155 rbug_destroy_query(struct pipe_context *_pipe,
156 struct pipe_query *query)
157 {
158 struct rbug_context *rb_pipe = rbug_context(_pipe);
159 struct pipe_context *pipe = rb_pipe->pipe;
160
161 pipe_mutex_lock(rb_pipe->call_mutex);
162 pipe->destroy_query(pipe,
163 query);
164 pipe_mutex_unlock(rb_pipe->call_mutex);
165 }
166
167 static boolean
168 rbug_begin_query(struct pipe_context *_pipe,
169 struct pipe_query *query)
170 {
171 struct rbug_context *rb_pipe = rbug_context(_pipe);
172 struct pipe_context *pipe = rb_pipe->pipe;
173 boolean ret;
174
175 pipe_mutex_lock(rb_pipe->call_mutex);
176 ret = pipe->begin_query(pipe, query);
177 pipe_mutex_unlock(rb_pipe->call_mutex);
178 return ret;
179 }
180
181 static bool
182 rbug_end_query(struct pipe_context *_pipe,
183 struct pipe_query *query)
184 {
185 struct rbug_context *rb_pipe = rbug_context(_pipe);
186 struct pipe_context *pipe = rb_pipe->pipe;
187 bool ret;
188
189 pipe_mutex_lock(rb_pipe->call_mutex);
190 ret = pipe->end_query(pipe,
191 query);
192 pipe_mutex_unlock(rb_pipe->call_mutex);
193
194 return ret;
195 }
196
197 static boolean
198 rbug_get_query_result(struct pipe_context *_pipe,
199 struct pipe_query *query,
200 boolean wait,
201 union pipe_query_result *result)
202 {
203 struct rbug_context *rb_pipe = rbug_context(_pipe);
204 struct pipe_context *pipe = rb_pipe->pipe;
205 boolean ret;
206
207 pipe_mutex_lock(rb_pipe->call_mutex);
208 ret = pipe->get_query_result(pipe,
209 query,
210 wait,
211 result);
212 pipe_mutex_unlock(rb_pipe->call_mutex);
213
214 return ret;
215 }
216
217 static void
218 rbug_set_active_query_state(struct pipe_context *_pipe, boolean enable)
219 {
220 struct rbug_context *rb_pipe = rbug_context(_pipe);
221 struct pipe_context *pipe = rb_pipe->pipe;
222
223 pipe_mutex_lock(rb_pipe->call_mutex);
224 pipe->set_active_query_state(pipe, enable);
225 pipe_mutex_unlock(rb_pipe->call_mutex);
226 }
227
228 static void *
229 rbug_create_blend_state(struct pipe_context *_pipe,
230 const struct pipe_blend_state *blend)
231 {
232 struct rbug_context *rb_pipe = rbug_context(_pipe);
233 struct pipe_context *pipe = rb_pipe->pipe;
234 void *ret;
235
236 pipe_mutex_lock(rb_pipe->call_mutex);
237 ret = pipe->create_blend_state(pipe,
238 blend);
239 pipe_mutex_unlock(rb_pipe->call_mutex);
240
241 return ret;
242 }
243
244 static void
245 rbug_bind_blend_state(struct pipe_context *_pipe,
246 void *blend)
247 {
248 struct rbug_context *rb_pipe = rbug_context(_pipe);
249 struct pipe_context *pipe = rb_pipe->pipe;
250
251 pipe_mutex_lock(rb_pipe->call_mutex);
252 pipe->bind_blend_state(pipe,
253 blend);
254 pipe_mutex_unlock(rb_pipe->call_mutex);
255 }
256
257 static void
258 rbug_delete_blend_state(struct pipe_context *_pipe,
259 void *blend)
260 {
261 struct rbug_context *rb_pipe = rbug_context(_pipe);
262 struct pipe_context *pipe = rb_pipe->pipe;
263
264 pipe_mutex_lock(rb_pipe->call_mutex);
265 pipe->delete_blend_state(pipe,
266 blend);
267 pipe_mutex_unlock(rb_pipe->call_mutex);
268 }
269
270 static void *
271 rbug_create_sampler_state(struct pipe_context *_pipe,
272 const struct pipe_sampler_state *sampler)
273 {
274 struct rbug_context *rb_pipe = rbug_context(_pipe);
275 struct pipe_context *pipe = rb_pipe->pipe;
276 void *ret;
277
278 pipe_mutex_lock(rb_pipe->call_mutex);
279 ret = pipe->create_sampler_state(pipe,
280 sampler);
281 pipe_mutex_unlock(rb_pipe->call_mutex);
282
283 return ret;
284 }
285
286 static void
287 rbug_bind_sampler_states(struct pipe_context *_pipe, unsigned shader,
288 unsigned start, unsigned count,
289 void **samplers)
290 {
291 struct rbug_context *rb_pipe = rbug_context(_pipe);
292 struct pipe_context *pipe = rb_pipe->pipe;
293
294 pipe_mutex_lock(rb_pipe->call_mutex);
295 pipe->bind_sampler_states(pipe, shader, start, count, samplers);
296 pipe_mutex_unlock(rb_pipe->call_mutex);
297 }
298
299 static void
300 rbug_delete_sampler_state(struct pipe_context *_pipe,
301 void *sampler)
302 {
303 struct rbug_context *rb_pipe = rbug_context(_pipe);
304 struct pipe_context *pipe = rb_pipe->pipe;
305
306 pipe_mutex_lock(rb_pipe->call_mutex);
307 pipe->delete_sampler_state(pipe,
308 sampler);
309 pipe_mutex_unlock(rb_pipe->call_mutex);
310 }
311
312 static void *
313 rbug_create_rasterizer_state(struct pipe_context *_pipe,
314 const struct pipe_rasterizer_state *rasterizer)
315 {
316 struct rbug_context *rb_pipe = rbug_context(_pipe);
317 struct pipe_context *pipe = rb_pipe->pipe;
318 void *ret;
319
320 pipe_mutex_lock(rb_pipe->call_mutex);
321 ret = pipe->create_rasterizer_state(pipe,
322 rasterizer);
323 pipe_mutex_unlock(rb_pipe->call_mutex);
324
325 return ret;
326 }
327
328 static void
329 rbug_bind_rasterizer_state(struct pipe_context *_pipe,
330 void *rasterizer)
331 {
332 struct rbug_context *rb_pipe = rbug_context(_pipe);
333 struct pipe_context *pipe = rb_pipe->pipe;
334
335 pipe_mutex_lock(rb_pipe->call_mutex);
336 pipe->bind_rasterizer_state(pipe,
337 rasterizer);
338 pipe_mutex_unlock(rb_pipe->call_mutex);
339 }
340
341 static void
342 rbug_delete_rasterizer_state(struct pipe_context *_pipe,
343 void *rasterizer)
344 {
345 struct rbug_context *rb_pipe = rbug_context(_pipe);
346 struct pipe_context *pipe = rb_pipe->pipe;
347
348 pipe_mutex_lock(rb_pipe->call_mutex);
349 pipe->delete_rasterizer_state(pipe,
350 rasterizer);
351 pipe_mutex_unlock(rb_pipe->call_mutex);
352 }
353
354 static void *
355 rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
356 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
357 {
358 struct rbug_context *rb_pipe = rbug_context(_pipe);
359 struct pipe_context *pipe = rb_pipe->pipe;
360 void *ret;
361
362 pipe_mutex_lock(rb_pipe->call_mutex);
363 ret = pipe->create_depth_stencil_alpha_state(pipe,
364 depth_stencil_alpha);
365 pipe_mutex_unlock(rb_pipe->call_mutex);
366
367 return ret;
368 }
369
370 static void
371 rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
372 void *depth_stencil_alpha)
373 {
374 struct rbug_context *rb_pipe = rbug_context(_pipe);
375 struct pipe_context *pipe = rb_pipe->pipe;
376
377 pipe_mutex_lock(rb_pipe->call_mutex);
378 pipe->bind_depth_stencil_alpha_state(pipe,
379 depth_stencil_alpha);
380 pipe_mutex_unlock(rb_pipe->call_mutex);
381 }
382
383 static void
384 rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
385 void *depth_stencil_alpha)
386 {
387 struct rbug_context *rb_pipe = rbug_context(_pipe);
388 struct pipe_context *pipe = rb_pipe->pipe;
389
390 pipe_mutex_lock(rb_pipe->call_mutex);
391 pipe->delete_depth_stencil_alpha_state(pipe,
392 depth_stencil_alpha);
393 pipe_mutex_unlock(rb_pipe->call_mutex);
394 }
395
396 static void *
397 rbug_create_fs_state(struct pipe_context *_pipe,
398 const struct pipe_shader_state *state)
399 {
400 struct rbug_context *rb_pipe = rbug_context(_pipe);
401 struct pipe_context *pipe = rb_pipe->pipe;
402 void *result;
403
404 pipe_mutex_lock(rb_pipe->call_mutex);
405 result = pipe->create_fs_state(pipe, state);
406 pipe_mutex_unlock(rb_pipe->call_mutex);
407
408 if (!result)
409 return NULL;
410
411 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
412 }
413
414 static void
415 rbug_bind_fs_state(struct pipe_context *_pipe,
416 void *_fs)
417 {
418 struct rbug_context *rb_pipe = rbug_context(_pipe);
419 struct pipe_context *pipe = rb_pipe->pipe;
420 void *fs;
421
422 pipe_mutex_lock(rb_pipe->call_mutex);
423
424 fs = rbug_shader_unwrap(_fs);
425 rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs);
426 pipe->bind_fs_state(pipe,
427 fs);
428
429 pipe_mutex_unlock(rb_pipe->call_mutex);
430 }
431
432 static void
433 rbug_delete_fs_state(struct pipe_context *_pipe,
434 void *_fs)
435 {
436 struct rbug_context *rb_pipe = rbug_context(_pipe);
437 struct rbug_shader *rb_shader = rbug_shader(_fs);
438
439 pipe_mutex_lock(rb_pipe->call_mutex);
440 rbug_shader_destroy(rb_pipe, rb_shader);
441 pipe_mutex_unlock(rb_pipe->call_mutex);
442 }
443
444 static void *
445 rbug_create_vs_state(struct pipe_context *_pipe,
446 const struct pipe_shader_state *state)
447 {
448 struct rbug_context *rb_pipe = rbug_context(_pipe);
449 struct pipe_context *pipe = rb_pipe->pipe;
450 void *result;
451
452 pipe_mutex_lock(rb_pipe->call_mutex);
453 result = pipe->create_vs_state(pipe, state);
454 pipe_mutex_unlock(rb_pipe->call_mutex);
455
456 if (!result)
457 return NULL;
458
459 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
460 }
461
462 static void
463 rbug_bind_vs_state(struct pipe_context *_pipe,
464 void *_vs)
465 {
466 struct rbug_context *rb_pipe = rbug_context(_pipe);
467 struct pipe_context *pipe = rb_pipe->pipe;
468 void *vs;
469
470 pipe_mutex_lock(rb_pipe->call_mutex);
471
472 vs = rbug_shader_unwrap(_vs);
473 rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs);
474 pipe->bind_vs_state(pipe,
475 vs);
476
477 pipe_mutex_unlock(rb_pipe->call_mutex);
478 }
479
480 static void
481 rbug_delete_vs_state(struct pipe_context *_pipe,
482 void *_vs)
483 {
484 struct rbug_context *rb_pipe = rbug_context(_pipe);
485 struct rbug_shader *rb_shader = rbug_shader(_vs);
486
487 pipe_mutex_unlock(rb_pipe->call_mutex);
488 rbug_shader_destroy(rb_pipe, rb_shader);
489 pipe_mutex_unlock(rb_pipe->call_mutex);
490 }
491
492 static void *
493 rbug_create_gs_state(struct pipe_context *_pipe,
494 const struct pipe_shader_state *state)
495 {
496 struct rbug_context *rb_pipe = rbug_context(_pipe);
497 struct pipe_context *pipe = rb_pipe->pipe;
498 void *result;
499
500 pipe_mutex_lock(rb_pipe->call_mutex);
501 result = pipe->create_gs_state(pipe, state);
502 pipe_mutex_unlock(rb_pipe->call_mutex);
503
504 if (!result)
505 return NULL;
506
507 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
508 }
509
510 static void
511 rbug_bind_gs_state(struct pipe_context *_pipe,
512 void *_gs)
513 {
514 struct rbug_context *rb_pipe = rbug_context(_pipe);
515 struct pipe_context *pipe = rb_pipe->pipe;
516 void *gs;
517
518 pipe_mutex_lock(rb_pipe->call_mutex);
519
520 gs = rbug_shader_unwrap(_gs);
521 rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs);
522 pipe->bind_gs_state(pipe,
523 gs);
524
525 pipe_mutex_unlock(rb_pipe->call_mutex);
526 }
527
528 static void
529 rbug_delete_gs_state(struct pipe_context *_pipe,
530 void *_gs)
531 {
532 struct rbug_context *rb_pipe = rbug_context(_pipe);
533 struct rbug_shader *rb_shader = rbug_shader(_gs);
534
535 pipe_mutex_lock(rb_pipe->call_mutex);
536 rbug_shader_destroy(rb_pipe, rb_shader);
537 pipe_mutex_unlock(rb_pipe->call_mutex);
538 }
539
540 static void *
541 rbug_create_vertex_elements_state(struct pipe_context *_pipe,
542 unsigned num_elements,
543 const struct pipe_vertex_element *vertex_elements)
544 {
545 struct rbug_context *rb_pipe = rbug_context(_pipe);
546 struct pipe_context *pipe = rb_pipe->pipe;
547 void *ret;
548
549 pipe_mutex_lock(rb_pipe->call_mutex);
550 ret = pipe->create_vertex_elements_state(pipe,
551 num_elements,
552 vertex_elements);
553 pipe_mutex_unlock(rb_pipe->call_mutex);
554
555 return ret;
556 }
557
558 static void
559 rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
560 void *velems)
561 {
562 struct rbug_context *rb_pipe = rbug_context(_pipe);
563 struct pipe_context *pipe = rb_pipe->pipe;
564
565 pipe_mutex_lock(rb_pipe->call_mutex);
566 pipe->bind_vertex_elements_state(pipe,
567 velems);
568 pipe_mutex_unlock(rb_pipe->call_mutex);
569 }
570
571 static void
572 rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
573 void *velems)
574 {
575 struct rbug_context *rb_pipe = rbug_context(_pipe);
576 struct pipe_context *pipe = rb_pipe->pipe;
577
578 pipe_mutex_lock(rb_pipe->call_mutex);
579 pipe->delete_vertex_elements_state(pipe,
580 velems);
581 pipe_mutex_unlock(rb_pipe->call_mutex);
582 }
583
584 static void
585 rbug_set_blend_color(struct pipe_context *_pipe,
586 const struct pipe_blend_color *blend_color)
587 {
588 struct rbug_context *rb_pipe = rbug_context(_pipe);
589 struct pipe_context *pipe = rb_pipe->pipe;
590
591 pipe_mutex_lock(rb_pipe->call_mutex);
592 pipe->set_blend_color(pipe,
593 blend_color);
594 pipe_mutex_unlock(rb_pipe->call_mutex);
595 }
596
597 static void
598 rbug_set_stencil_ref(struct pipe_context *_pipe,
599 const struct pipe_stencil_ref *stencil_ref)
600 {
601 struct rbug_context *rb_pipe = rbug_context(_pipe);
602 struct pipe_context *pipe = rb_pipe->pipe;
603
604 pipe_mutex_lock(rb_pipe->call_mutex);
605 pipe->set_stencil_ref(pipe,
606 stencil_ref);
607 pipe_mutex_unlock(rb_pipe->call_mutex);
608 }
609
610 static void
611 rbug_set_clip_state(struct pipe_context *_pipe,
612 const struct pipe_clip_state *clip)
613 {
614 struct rbug_context *rb_pipe = rbug_context(_pipe);
615 struct pipe_context *pipe = rb_pipe->pipe;
616
617 pipe_mutex_lock(rb_pipe->call_mutex);
618 pipe->set_clip_state(pipe,
619 clip);
620 pipe_mutex_unlock(rb_pipe->call_mutex);
621 }
622
623 static void
624 rbug_set_constant_buffer(struct pipe_context *_pipe,
625 uint shader,
626 uint index,
627 const struct pipe_constant_buffer *_cb)
628 {
629 struct rbug_context *rb_pipe = rbug_context(_pipe);
630 struct pipe_context *pipe = rb_pipe->pipe;
631 struct pipe_constant_buffer cb;
632
633 /* XXX hmm? unwrap the input state */
634 if (_cb) {
635 cb = *_cb;
636 cb.buffer = rbug_resource_unwrap(_cb->buffer);
637 }
638
639 pipe_mutex_lock(rb_pipe->call_mutex);
640 pipe->set_constant_buffer(pipe,
641 shader,
642 index,
643 _cb ? &cb : NULL);
644 pipe_mutex_unlock(rb_pipe->call_mutex);
645 }
646
647 static void
648 rbug_set_framebuffer_state(struct pipe_context *_pipe,
649 const struct pipe_framebuffer_state *_state)
650 {
651 struct rbug_context *rb_pipe = rbug_context(_pipe);
652 struct pipe_context *pipe = rb_pipe->pipe;
653 struct pipe_framebuffer_state unwrapped_state;
654 struct pipe_framebuffer_state *state = NULL;
655 unsigned i;
656
657 /* must protect curr status */
658 pipe_mutex_lock(rb_pipe->call_mutex);
659
660 rb_pipe->curr.nr_cbufs = 0;
661 memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
662 rb_pipe->curr.zsbuf = NULL;
663
664 /* unwrap the input state */
665 if (_state) {
666 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
667
668 rb_pipe->curr.nr_cbufs = _state->nr_cbufs;
669 for(i = 0; i < _state->nr_cbufs; i++) {
670 unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]);
671 if (_state->cbufs[i])
672 rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
673 }
674 unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
675 if (_state->zsbuf)
676 rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
677 state = &unwrapped_state;
678 }
679
680 pipe->set_framebuffer_state(pipe,
681 state);
682
683 pipe_mutex_unlock(rb_pipe->call_mutex);
684 }
685
686 static void
687 rbug_set_polygon_stipple(struct pipe_context *_pipe,
688 const struct pipe_poly_stipple *poly_stipple)
689 {
690 struct rbug_context *rb_pipe = rbug_context(_pipe);
691 struct pipe_context *pipe = rb_pipe->pipe;
692
693 pipe_mutex_lock(rb_pipe->call_mutex);
694 pipe->set_polygon_stipple(pipe,
695 poly_stipple);
696 pipe_mutex_unlock(rb_pipe->call_mutex);
697 }
698
699 static void
700 rbug_set_scissor_states(struct pipe_context *_pipe,
701 unsigned start_slot,
702 unsigned num_scissors,
703 const struct pipe_scissor_state *scissor)
704 {
705 struct rbug_context *rb_pipe = rbug_context(_pipe);
706 struct pipe_context *pipe = rb_pipe->pipe;
707
708 pipe_mutex_lock(rb_pipe->call_mutex);
709 pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
710 pipe_mutex_unlock(rb_pipe->call_mutex);
711 }
712
713 static void
714 rbug_set_viewport_states(struct pipe_context *_pipe,
715 unsigned start_slot,
716 unsigned num_viewports,
717 const struct pipe_viewport_state *viewport)
718 {
719 struct rbug_context *rb_pipe = rbug_context(_pipe);
720 struct pipe_context *pipe = rb_pipe->pipe;
721
722 pipe_mutex_lock(rb_pipe->call_mutex);
723 pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
724 pipe_mutex_unlock(rb_pipe->call_mutex);
725 }
726
727 static void
728 rbug_set_sampler_views(struct pipe_context *_pipe,
729 unsigned shader,
730 unsigned start,
731 unsigned num,
732 struct pipe_sampler_view **_views)
733 {
734 struct rbug_context *rb_pipe = rbug_context(_pipe);
735 struct pipe_context *pipe = rb_pipe->pipe;
736 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
737 struct pipe_sampler_view **views = NULL;
738 unsigned i;
739
740 assert(start == 0); /* XXX fix */
741
742 /* must protect curr status */
743 pipe_mutex_lock(rb_pipe->call_mutex);
744
745 rb_pipe->curr.num_views[shader] = 0;
746 memset(rb_pipe->curr.views[shader], 0, sizeof(rb_pipe->curr.views[shader]));
747 memset(rb_pipe->curr.texs[shader], 0, sizeof(rb_pipe->curr.texs[shader]));
748 memset(unwrapped_views, 0, sizeof(unwrapped_views));
749
750 if (_views) {
751 rb_pipe->curr.num_views[shader] = num;
752 for (i = 0; i < num; i++) {
753 rb_pipe->curr.views[shader][i] = rbug_sampler_view(_views[i]);
754 rb_pipe->curr.texs[shader][i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
755 unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
756 }
757 views = unwrapped_views;
758 }
759
760 pipe->set_sampler_views(pipe, shader, start, num, views);
761
762 pipe_mutex_unlock(rb_pipe->call_mutex);
763 }
764
765 static void
766 rbug_set_vertex_buffers(struct pipe_context *_pipe,
767 unsigned start_slot, unsigned num_buffers,
768 const struct pipe_vertex_buffer *_buffers)
769 {
770 struct rbug_context *rb_pipe = rbug_context(_pipe);
771 struct pipe_context *pipe = rb_pipe->pipe;
772 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
773 struct pipe_vertex_buffer *buffers = NULL;
774 unsigned i;
775
776 pipe_mutex_lock(rb_pipe->call_mutex);
777
778 if (num_buffers && _buffers) {
779 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
780 for (i = 0; i < num_buffers; i++)
781 unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer);
782 buffers = unwrapped_buffers;
783 }
784
785 pipe->set_vertex_buffers(pipe, start_slot,
786 num_buffers,
787 buffers);
788
789 pipe_mutex_unlock(rb_pipe->call_mutex);
790 }
791
792 static void
793 rbug_set_index_buffer(struct pipe_context *_pipe,
794 const struct pipe_index_buffer *_ib)
795 {
796 struct rbug_context *rb_pipe = rbug_context(_pipe);
797 struct pipe_context *pipe = rb_pipe->pipe;
798 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
799
800 if (_ib) {
801 unwrapped_ib = *_ib;
802 unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer);
803 ib = &unwrapped_ib;
804 }
805
806 pipe_mutex_lock(rb_pipe->call_mutex);
807 pipe->set_index_buffer(pipe, ib);
808 pipe_mutex_unlock(rb_pipe->call_mutex);
809 }
810
811 static void
812 rbug_set_sample_mask(struct pipe_context *_pipe,
813 unsigned sample_mask)
814 {
815 struct rbug_context *rb_pipe = rbug_context(_pipe);
816 struct pipe_context *pipe = rb_pipe->pipe;
817
818 pipe_mutex_lock(rb_pipe->call_mutex);
819 pipe->set_sample_mask(pipe, sample_mask);
820 pipe_mutex_unlock(rb_pipe->call_mutex);
821 }
822
823 static struct pipe_stream_output_target *
824 rbug_create_stream_output_target(struct pipe_context *_pipe,
825 struct pipe_resource *_res,
826 unsigned buffer_offset, unsigned buffer_size)
827 {
828 struct rbug_context *rb_pipe = rbug_context(_pipe);
829 struct pipe_context *pipe = rb_pipe->pipe;
830 struct pipe_resource *res = rbug_resource_unwrap(_res);
831 struct pipe_stream_output_target *target;
832
833 pipe_mutex_lock(rb_pipe->call_mutex);
834 target = pipe->create_stream_output_target(pipe, res, buffer_offset,
835 buffer_size);
836 pipe_mutex_unlock(rb_pipe->call_mutex);
837 return target;
838 }
839
840 static void
841 rbug_stream_output_target_destroy(struct pipe_context *_pipe,
842 struct pipe_stream_output_target *target)
843 {
844 struct rbug_context *rb_pipe = rbug_context(_pipe);
845 struct pipe_context *pipe = rb_pipe->pipe;
846
847 pipe_mutex_lock(rb_pipe->call_mutex);
848 pipe->stream_output_target_destroy(pipe, target);
849 pipe_mutex_unlock(rb_pipe->call_mutex);
850 }
851
852 static void
853 rbug_set_stream_output_targets(struct pipe_context *_pipe,
854 unsigned num_targets,
855 struct pipe_stream_output_target **targets,
856 const unsigned *offsets)
857 {
858 struct rbug_context *rb_pipe = rbug_context(_pipe);
859 struct pipe_context *pipe = rb_pipe->pipe;
860
861 pipe_mutex_lock(rb_pipe->call_mutex);
862 pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
863 pipe_mutex_unlock(rb_pipe->call_mutex);
864 }
865
866 static void
867 rbug_resource_copy_region(struct pipe_context *_pipe,
868 struct pipe_resource *_dst,
869 unsigned dst_level,
870 unsigned dstx,
871 unsigned dsty,
872 unsigned dstz,
873 struct pipe_resource *_src,
874 unsigned src_level,
875 const struct pipe_box *src_box)
876 {
877 struct rbug_context *rb_pipe = rbug_context(_pipe);
878 struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
879 struct rbug_resource *rb_resource_src = rbug_resource(_src);
880 struct pipe_context *pipe = rb_pipe->pipe;
881 struct pipe_resource *dst = rb_resource_dst->resource;
882 struct pipe_resource *src = rb_resource_src->resource;
883
884 pipe_mutex_lock(rb_pipe->call_mutex);
885 pipe->resource_copy_region(pipe,
886 dst,
887 dst_level,
888 dstx,
889 dsty,
890 dstz,
891 src,
892 src_level,
893 src_box);
894 pipe_mutex_unlock(rb_pipe->call_mutex);
895 }
896
897 static void
898 rbug_blit(struct pipe_context *_pipe, const struct pipe_blit_info *_blit_info)
899 {
900 struct rbug_context *rb_pipe = rbug_context(_pipe);
901 struct rbug_resource *rb_resource_dst = rbug_resource(_blit_info->dst.resource);
902 struct rbug_resource *rb_resource_src = rbug_resource(_blit_info->src.resource);
903 struct pipe_context *pipe = rb_pipe->pipe;
904 struct pipe_resource *dst = rb_resource_dst->resource;
905 struct pipe_resource *src = rb_resource_src->resource;
906 struct pipe_blit_info blit_info;
907
908 blit_info = *_blit_info;
909 blit_info.dst.resource = dst;
910 blit_info.src.resource = src;
911
912 pipe_mutex_lock(rb_pipe->call_mutex);
913 pipe->blit(pipe, &blit_info);
914 pipe_mutex_unlock(rb_pipe->call_mutex);
915 }
916
917 static void
918 rbug_flush_resource(struct pipe_context *_pipe,
919 struct pipe_resource *_res)
920 {
921 struct rbug_context *rb_pipe = rbug_context(_pipe);
922 struct rbug_resource *rb_resource_res = rbug_resource(_res);
923 struct pipe_context *pipe = rb_pipe->pipe;
924 struct pipe_resource *res = rb_resource_res->resource;
925
926 pipe_mutex_lock(rb_pipe->call_mutex);
927 pipe->flush_resource(pipe, res);
928 pipe_mutex_unlock(rb_pipe->call_mutex);
929 }
930
931 static void
932 rbug_clear(struct pipe_context *_pipe,
933 unsigned buffers,
934 const union pipe_color_union *color,
935 double depth,
936 unsigned stencil)
937 {
938 struct rbug_context *rb_pipe = rbug_context(_pipe);
939 struct pipe_context *pipe = rb_pipe->pipe;
940
941 pipe_mutex_lock(rb_pipe->call_mutex);
942 pipe->clear(pipe,
943 buffers,
944 color,
945 depth,
946 stencil);
947 pipe_mutex_unlock(rb_pipe->call_mutex);
948 }
949
950 static void
951 rbug_clear_render_target(struct pipe_context *_pipe,
952 struct pipe_surface *_dst,
953 const union pipe_color_union *color,
954 unsigned dstx, unsigned dsty,
955 unsigned width, unsigned height)
956 {
957 struct rbug_context *rb_pipe = rbug_context(_pipe);
958 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
959 struct pipe_context *pipe = rb_pipe->pipe;
960 struct pipe_surface *dst = rb_surface_dst->surface;
961
962 pipe_mutex_lock(rb_pipe->call_mutex);
963 pipe->clear_render_target(pipe,
964 dst,
965 color,
966 dstx,
967 dsty,
968 width,
969 height);
970 pipe_mutex_unlock(rb_pipe->call_mutex);
971 }
972
973 static void
974 rbug_clear_depth_stencil(struct pipe_context *_pipe,
975 struct pipe_surface *_dst,
976 unsigned clear_flags,
977 double depth,
978 unsigned stencil,
979 unsigned dstx, unsigned dsty,
980 unsigned width, unsigned height)
981 {
982 struct rbug_context *rb_pipe = rbug_context(_pipe);
983 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
984 struct pipe_context *pipe = rb_pipe->pipe;
985 struct pipe_surface *dst = rb_surface_dst->surface;
986
987 pipe_mutex_lock(rb_pipe->call_mutex);
988 pipe->clear_depth_stencil(pipe,
989 dst,
990 clear_flags,
991 depth,
992 stencil,
993 dstx,
994 dsty,
995 width,
996 height);
997 pipe_mutex_unlock(rb_pipe->call_mutex);
998 }
999
1000 static void
1001 rbug_flush(struct pipe_context *_pipe,
1002 struct pipe_fence_handle **fence,
1003 unsigned flags)
1004 {
1005 struct rbug_context *rb_pipe = rbug_context(_pipe);
1006 struct pipe_context *pipe = rb_pipe->pipe;
1007
1008 pipe_mutex_lock(rb_pipe->call_mutex);
1009 pipe->flush(pipe, fence, flags);
1010 pipe_mutex_unlock(rb_pipe->call_mutex);
1011 }
1012
1013 static struct pipe_sampler_view *
1014 rbug_context_create_sampler_view(struct pipe_context *_pipe,
1015 struct pipe_resource *_resource,
1016 const struct pipe_sampler_view *templ)
1017 {
1018 struct rbug_context *rb_pipe = rbug_context(_pipe);
1019 struct rbug_resource *rb_resource = rbug_resource(_resource);
1020 struct pipe_context *pipe = rb_pipe->pipe;
1021 struct pipe_resource *resource = rb_resource->resource;
1022 struct pipe_sampler_view *result;
1023
1024 pipe_mutex_lock(rb_pipe->call_mutex);
1025 result = pipe->create_sampler_view(pipe,
1026 resource,
1027 templ);
1028 pipe_mutex_unlock(rb_pipe->call_mutex);
1029
1030 if (result)
1031 return rbug_sampler_view_create(rb_pipe, rb_resource, result);
1032 return NULL;
1033 }
1034
1035 static void
1036 rbug_context_sampler_view_destroy(struct pipe_context *_pipe,
1037 struct pipe_sampler_view *_view)
1038 {
1039 rbug_sampler_view_destroy(rbug_context(_pipe),
1040 rbug_sampler_view(_view));
1041 }
1042
1043 static struct pipe_surface *
1044 rbug_context_create_surface(struct pipe_context *_pipe,
1045 struct pipe_resource *_resource,
1046 const struct pipe_surface *surf_tmpl)
1047 {
1048 struct rbug_context *rb_pipe = rbug_context(_pipe);
1049 struct rbug_resource *rb_resource = rbug_resource(_resource);
1050 struct pipe_context *pipe = rb_pipe->pipe;
1051 struct pipe_resource *resource = rb_resource->resource;
1052 struct pipe_surface *result;
1053
1054 pipe_mutex_lock(rb_pipe->call_mutex);
1055 result = pipe->create_surface(pipe,
1056 resource,
1057 surf_tmpl);
1058 pipe_mutex_unlock(rb_pipe->call_mutex);
1059
1060 if (result)
1061 return rbug_surface_create(rb_pipe, rb_resource, result);
1062 return NULL;
1063 }
1064
1065 static void
1066 rbug_context_surface_destroy(struct pipe_context *_pipe,
1067 struct pipe_surface *_surface)
1068 {
1069 struct rbug_context *rb_pipe = rbug_context(_pipe);
1070 struct rbug_surface *rb_surface = rbug_surface(_surface);
1071
1072 pipe_mutex_lock(rb_pipe->call_mutex);
1073 rbug_surface_destroy(rb_pipe,
1074 rb_surface);
1075 pipe_mutex_unlock(rb_pipe->call_mutex);
1076 }
1077
1078
1079
1080 static void *
1081 rbug_context_transfer_map(struct pipe_context *_context,
1082 struct pipe_resource *_resource,
1083 unsigned level,
1084 unsigned usage,
1085 const struct pipe_box *box,
1086 struct pipe_transfer **transfer)
1087 {
1088 struct rbug_context *rb_pipe = rbug_context(_context);
1089 struct rbug_resource *rb_resource = rbug_resource(_resource);
1090 struct pipe_context *context = rb_pipe->pipe;
1091 struct pipe_resource *resource = rb_resource->resource;
1092 struct pipe_transfer *result;
1093 void *map;
1094
1095 pipe_mutex_lock(rb_pipe->call_mutex);
1096 map = context->transfer_map(context,
1097 resource,
1098 level,
1099 usage,
1100 box, &result);
1101 pipe_mutex_unlock(rb_pipe->call_mutex);
1102
1103 *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
1104 return *transfer ? map : NULL;
1105 }
1106
1107 static void
1108 rbug_context_transfer_flush_region(struct pipe_context *_context,
1109 struct pipe_transfer *_transfer,
1110 const struct pipe_box *box)
1111 {
1112 struct rbug_context *rb_pipe = rbug_context(_context);
1113 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1114 struct pipe_context *context = rb_pipe->pipe;
1115 struct pipe_transfer *transfer = rb_transfer->transfer;
1116
1117 pipe_mutex_lock(rb_pipe->call_mutex);
1118 context->transfer_flush_region(context,
1119 transfer,
1120 box);
1121 pipe_mutex_unlock(rb_pipe->call_mutex);
1122 }
1123
1124
1125 static void
1126 rbug_context_transfer_unmap(struct pipe_context *_context,
1127 struct pipe_transfer *_transfer)
1128 {
1129 struct rbug_context *rb_pipe = rbug_context(_context);
1130 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1131 struct pipe_context *context = rb_pipe->pipe;
1132 struct pipe_transfer *transfer = rb_transfer->transfer;
1133
1134 pipe_mutex_lock(rb_pipe->call_mutex);
1135 context->transfer_unmap(context,
1136 transfer);
1137 rbug_transfer_destroy(rb_pipe,
1138 rb_transfer);
1139 pipe_mutex_unlock(rb_pipe->call_mutex);
1140 }
1141
1142
1143 static void
1144 rbug_context_buffer_subdata(struct pipe_context *_context,
1145 struct pipe_resource *_resource,
1146 unsigned usage, unsigned offset,
1147 unsigned size, const void *data)
1148 {
1149 struct rbug_context *rb_pipe = rbug_context(_context);
1150 struct rbug_resource *rb_resource = rbug_resource(_resource);
1151 struct pipe_context *context = rb_pipe->pipe;
1152 struct pipe_resource *resource = rb_resource->resource;
1153
1154 pipe_mutex_lock(rb_pipe->call_mutex);
1155 context->buffer_subdata(context, resource, usage, offset, size, data);
1156 pipe_mutex_unlock(rb_pipe->call_mutex);
1157 }
1158
1159
1160 static void
1161 rbug_context_texture_subdata(struct pipe_context *_context,
1162 struct pipe_resource *_resource,
1163 unsigned level,
1164 unsigned usage,
1165 const struct pipe_box *box,
1166 const void *data,
1167 unsigned stride,
1168 unsigned layer_stride)
1169 {
1170 struct rbug_context *rb_pipe = rbug_context(_context);
1171 struct rbug_resource *rb_resource = rbug_resource(_resource);
1172 struct pipe_context *context = rb_pipe->pipe;
1173 struct pipe_resource *resource = rb_resource->resource;
1174
1175 pipe_mutex_lock(rb_pipe->call_mutex);
1176 context->texture_subdata(context,
1177 resource,
1178 level,
1179 usage,
1180 box,
1181 data,
1182 stride,
1183 layer_stride);
1184 pipe_mutex_unlock(rb_pipe->call_mutex);
1185 }
1186
1187
1188 struct pipe_context *
1189 rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
1190 {
1191 struct rbug_context *rb_pipe;
1192 struct rbug_screen *rb_screen = rbug_screen(_screen);
1193
1194 if (!rb_screen)
1195 return NULL;
1196
1197 rb_pipe = CALLOC_STRUCT(rbug_context);
1198 if (!rb_pipe)
1199 return NULL;
1200
1201 pipe_mutex_init(rb_pipe->draw_mutex);
1202 pipe_condvar_init(rb_pipe->draw_cond);
1203 pipe_mutex_init(rb_pipe->call_mutex);
1204 pipe_mutex_init(rb_pipe->list_mutex);
1205 make_empty_list(&rb_pipe->shaders);
1206
1207 rb_pipe->base.screen = _screen;
1208 rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
1209 rb_pipe->base.draw = NULL;
1210
1211 rb_pipe->base.destroy = rbug_destroy;
1212 rb_pipe->base.draw_vbo = rbug_draw_vbo;
1213 rb_pipe->base.create_query = rbug_create_query;
1214 rb_pipe->base.destroy_query = rbug_destroy_query;
1215 rb_pipe->base.begin_query = rbug_begin_query;
1216 rb_pipe->base.end_query = rbug_end_query;
1217 rb_pipe->base.get_query_result = rbug_get_query_result;
1218 rb_pipe->base.set_active_query_state = rbug_set_active_query_state;
1219 rb_pipe->base.create_blend_state = rbug_create_blend_state;
1220 rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
1221 rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
1222 rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
1223 rb_pipe->base.bind_sampler_states = rbug_bind_sampler_states;
1224 rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
1225 rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
1226 rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
1227 rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state;
1228 rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state;
1229 rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state;
1230 rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state;
1231 rb_pipe->base.create_fs_state = rbug_create_fs_state;
1232 rb_pipe->base.bind_fs_state = rbug_bind_fs_state;
1233 rb_pipe->base.delete_fs_state = rbug_delete_fs_state;
1234 rb_pipe->base.create_vs_state = rbug_create_vs_state;
1235 rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
1236 rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
1237 rb_pipe->base.create_gs_state = rbug_create_gs_state;
1238 rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
1239 rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
1240 rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
1241 rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
1242 rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
1243 rb_pipe->base.set_blend_color = rbug_set_blend_color;
1244 rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref;
1245 rb_pipe->base.set_clip_state = rbug_set_clip_state;
1246 rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
1247 rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
1248 rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
1249 rb_pipe->base.set_scissor_states = rbug_set_scissor_states;
1250 rb_pipe->base.set_viewport_states = rbug_set_viewport_states;
1251 rb_pipe->base.set_sampler_views = rbug_set_sampler_views;
1252 rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
1253 rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
1254 rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
1255 rb_pipe->base.create_stream_output_target = rbug_create_stream_output_target;
1256 rb_pipe->base.stream_output_target_destroy = rbug_stream_output_target_destroy;
1257 rb_pipe->base.set_stream_output_targets = rbug_set_stream_output_targets;
1258 rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
1259 rb_pipe->base.blit = rbug_blit;
1260 rb_pipe->base.flush_resource = rbug_flush_resource;
1261 rb_pipe->base.clear = rbug_clear;
1262 rb_pipe->base.clear_render_target = rbug_clear_render_target;
1263 rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
1264 rb_pipe->base.flush = rbug_flush;
1265 rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
1266 rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
1267 rb_pipe->base.create_surface = rbug_context_create_surface;
1268 rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
1269 rb_pipe->base.transfer_map = rbug_context_transfer_map;
1270 rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
1271 rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
1272 rb_pipe->base.buffer_subdata = rbug_context_buffer_subdata;
1273 rb_pipe->base.texture_subdata = rbug_context_texture_subdata;
1274
1275 rb_pipe->pipe = pipe;
1276
1277 rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
1278
1279 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) {
1280 rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE;
1281 }
1282
1283 return &rb_pipe->base;
1284 }