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