gallium/util: replace pipe_condvar_wait() with cnd_wait()
[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 cnd_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,
288 enum pipe_shader_type shader,
289 unsigned start, unsigned count,
290 void **samplers)
291 {
292 struct rbug_context *rb_pipe = rbug_context(_pipe);
293 struct pipe_context *pipe = rb_pipe->pipe;
294
295 pipe_mutex_lock(rb_pipe->call_mutex);
296 pipe->bind_sampler_states(pipe, shader, start, count, samplers);
297 pipe_mutex_unlock(rb_pipe->call_mutex);
298 }
299
300 static void
301 rbug_delete_sampler_state(struct pipe_context *_pipe,
302 void *sampler)
303 {
304 struct rbug_context *rb_pipe = rbug_context(_pipe);
305 struct pipe_context *pipe = rb_pipe->pipe;
306
307 pipe_mutex_lock(rb_pipe->call_mutex);
308 pipe->delete_sampler_state(pipe,
309 sampler);
310 pipe_mutex_unlock(rb_pipe->call_mutex);
311 }
312
313 static void *
314 rbug_create_rasterizer_state(struct pipe_context *_pipe,
315 const struct pipe_rasterizer_state *rasterizer)
316 {
317 struct rbug_context *rb_pipe = rbug_context(_pipe);
318 struct pipe_context *pipe = rb_pipe->pipe;
319 void *ret;
320
321 pipe_mutex_lock(rb_pipe->call_mutex);
322 ret = pipe->create_rasterizer_state(pipe,
323 rasterizer);
324 pipe_mutex_unlock(rb_pipe->call_mutex);
325
326 return ret;
327 }
328
329 static void
330 rbug_bind_rasterizer_state(struct pipe_context *_pipe,
331 void *rasterizer)
332 {
333 struct rbug_context *rb_pipe = rbug_context(_pipe);
334 struct pipe_context *pipe = rb_pipe->pipe;
335
336 pipe_mutex_lock(rb_pipe->call_mutex);
337 pipe->bind_rasterizer_state(pipe,
338 rasterizer);
339 pipe_mutex_unlock(rb_pipe->call_mutex);
340 }
341
342 static void
343 rbug_delete_rasterizer_state(struct pipe_context *_pipe,
344 void *rasterizer)
345 {
346 struct rbug_context *rb_pipe = rbug_context(_pipe);
347 struct pipe_context *pipe = rb_pipe->pipe;
348
349 pipe_mutex_lock(rb_pipe->call_mutex);
350 pipe->delete_rasterizer_state(pipe,
351 rasterizer);
352 pipe_mutex_unlock(rb_pipe->call_mutex);
353 }
354
355 static void *
356 rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
357 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
358 {
359 struct rbug_context *rb_pipe = rbug_context(_pipe);
360 struct pipe_context *pipe = rb_pipe->pipe;
361 void *ret;
362
363 pipe_mutex_lock(rb_pipe->call_mutex);
364 ret = pipe->create_depth_stencil_alpha_state(pipe,
365 depth_stencil_alpha);
366 pipe_mutex_unlock(rb_pipe->call_mutex);
367
368 return ret;
369 }
370
371 static void
372 rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
373 void *depth_stencil_alpha)
374 {
375 struct rbug_context *rb_pipe = rbug_context(_pipe);
376 struct pipe_context *pipe = rb_pipe->pipe;
377
378 pipe_mutex_lock(rb_pipe->call_mutex);
379 pipe->bind_depth_stencil_alpha_state(pipe,
380 depth_stencil_alpha);
381 pipe_mutex_unlock(rb_pipe->call_mutex);
382 }
383
384 static void
385 rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
386 void *depth_stencil_alpha)
387 {
388 struct rbug_context *rb_pipe = rbug_context(_pipe);
389 struct pipe_context *pipe = rb_pipe->pipe;
390
391 pipe_mutex_lock(rb_pipe->call_mutex);
392 pipe->delete_depth_stencil_alpha_state(pipe,
393 depth_stencil_alpha);
394 pipe_mutex_unlock(rb_pipe->call_mutex);
395 }
396
397 static void *
398 rbug_create_fs_state(struct pipe_context *_pipe,
399 const struct pipe_shader_state *state)
400 {
401 struct rbug_context *rb_pipe = rbug_context(_pipe);
402 struct pipe_context *pipe = rb_pipe->pipe;
403 void *result;
404
405 pipe_mutex_lock(rb_pipe->call_mutex);
406 result = pipe->create_fs_state(pipe, state);
407 pipe_mutex_unlock(rb_pipe->call_mutex);
408
409 if (!result)
410 return NULL;
411
412 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
413 }
414
415 static void
416 rbug_bind_fs_state(struct pipe_context *_pipe,
417 void *_fs)
418 {
419 struct rbug_context *rb_pipe = rbug_context(_pipe);
420 struct pipe_context *pipe = rb_pipe->pipe;
421 void *fs;
422
423 pipe_mutex_lock(rb_pipe->call_mutex);
424
425 fs = rbug_shader_unwrap(_fs);
426 rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs);
427 pipe->bind_fs_state(pipe,
428 fs);
429
430 pipe_mutex_unlock(rb_pipe->call_mutex);
431 }
432
433 static void
434 rbug_delete_fs_state(struct pipe_context *_pipe,
435 void *_fs)
436 {
437 struct rbug_context *rb_pipe = rbug_context(_pipe);
438 struct rbug_shader *rb_shader = rbug_shader(_fs);
439
440 pipe_mutex_lock(rb_pipe->call_mutex);
441 rbug_shader_destroy(rb_pipe, rb_shader);
442 pipe_mutex_unlock(rb_pipe->call_mutex);
443 }
444
445 static void *
446 rbug_create_vs_state(struct pipe_context *_pipe,
447 const struct pipe_shader_state *state)
448 {
449 struct rbug_context *rb_pipe = rbug_context(_pipe);
450 struct pipe_context *pipe = rb_pipe->pipe;
451 void *result;
452
453 pipe_mutex_lock(rb_pipe->call_mutex);
454 result = pipe->create_vs_state(pipe, state);
455 pipe_mutex_unlock(rb_pipe->call_mutex);
456
457 if (!result)
458 return NULL;
459
460 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
461 }
462
463 static void
464 rbug_bind_vs_state(struct pipe_context *_pipe,
465 void *_vs)
466 {
467 struct rbug_context *rb_pipe = rbug_context(_pipe);
468 struct pipe_context *pipe = rb_pipe->pipe;
469 void *vs;
470
471 pipe_mutex_lock(rb_pipe->call_mutex);
472
473 vs = rbug_shader_unwrap(_vs);
474 rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs);
475 pipe->bind_vs_state(pipe,
476 vs);
477
478 pipe_mutex_unlock(rb_pipe->call_mutex);
479 }
480
481 static void
482 rbug_delete_vs_state(struct pipe_context *_pipe,
483 void *_vs)
484 {
485 struct rbug_context *rb_pipe = rbug_context(_pipe);
486 struct rbug_shader *rb_shader = rbug_shader(_vs);
487
488 pipe_mutex_unlock(rb_pipe->call_mutex);
489 rbug_shader_destroy(rb_pipe, rb_shader);
490 pipe_mutex_unlock(rb_pipe->call_mutex);
491 }
492
493 static void *
494 rbug_create_gs_state(struct pipe_context *_pipe,
495 const struct pipe_shader_state *state)
496 {
497 struct rbug_context *rb_pipe = rbug_context(_pipe);
498 struct pipe_context *pipe = rb_pipe->pipe;
499 void *result;
500
501 pipe_mutex_lock(rb_pipe->call_mutex);
502 result = pipe->create_gs_state(pipe, state);
503 pipe_mutex_unlock(rb_pipe->call_mutex);
504
505 if (!result)
506 return NULL;
507
508 return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
509 }
510
511 static void
512 rbug_bind_gs_state(struct pipe_context *_pipe,
513 void *_gs)
514 {
515 struct rbug_context *rb_pipe = rbug_context(_pipe);
516 struct pipe_context *pipe = rb_pipe->pipe;
517 void *gs;
518
519 pipe_mutex_lock(rb_pipe->call_mutex);
520
521 gs = rbug_shader_unwrap(_gs);
522 rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs);
523 pipe->bind_gs_state(pipe,
524 gs);
525
526 pipe_mutex_unlock(rb_pipe->call_mutex);
527 }
528
529 static void
530 rbug_delete_gs_state(struct pipe_context *_pipe,
531 void *_gs)
532 {
533 struct rbug_context *rb_pipe = rbug_context(_pipe);
534 struct rbug_shader *rb_shader = rbug_shader(_gs);
535
536 pipe_mutex_lock(rb_pipe->call_mutex);
537 rbug_shader_destroy(rb_pipe, rb_shader);
538 pipe_mutex_unlock(rb_pipe->call_mutex);
539 }
540
541 static void *
542 rbug_create_vertex_elements_state(struct pipe_context *_pipe,
543 unsigned num_elements,
544 const struct pipe_vertex_element *vertex_elements)
545 {
546 struct rbug_context *rb_pipe = rbug_context(_pipe);
547 struct pipe_context *pipe = rb_pipe->pipe;
548 void *ret;
549
550 pipe_mutex_lock(rb_pipe->call_mutex);
551 ret = pipe->create_vertex_elements_state(pipe,
552 num_elements,
553 vertex_elements);
554 pipe_mutex_unlock(rb_pipe->call_mutex);
555
556 return ret;
557 }
558
559 static void
560 rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
561 void *velems)
562 {
563 struct rbug_context *rb_pipe = rbug_context(_pipe);
564 struct pipe_context *pipe = rb_pipe->pipe;
565
566 pipe_mutex_lock(rb_pipe->call_mutex);
567 pipe->bind_vertex_elements_state(pipe,
568 velems);
569 pipe_mutex_unlock(rb_pipe->call_mutex);
570 }
571
572 static void
573 rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
574 void *velems)
575 {
576 struct rbug_context *rb_pipe = rbug_context(_pipe);
577 struct pipe_context *pipe = rb_pipe->pipe;
578
579 pipe_mutex_lock(rb_pipe->call_mutex);
580 pipe->delete_vertex_elements_state(pipe,
581 velems);
582 pipe_mutex_unlock(rb_pipe->call_mutex);
583 }
584
585 static void
586 rbug_set_blend_color(struct pipe_context *_pipe,
587 const struct pipe_blend_color *blend_color)
588 {
589 struct rbug_context *rb_pipe = rbug_context(_pipe);
590 struct pipe_context *pipe = rb_pipe->pipe;
591
592 pipe_mutex_lock(rb_pipe->call_mutex);
593 pipe->set_blend_color(pipe,
594 blend_color);
595 pipe_mutex_unlock(rb_pipe->call_mutex);
596 }
597
598 static void
599 rbug_set_stencil_ref(struct pipe_context *_pipe,
600 const struct pipe_stencil_ref *stencil_ref)
601 {
602 struct rbug_context *rb_pipe = rbug_context(_pipe);
603 struct pipe_context *pipe = rb_pipe->pipe;
604
605 pipe_mutex_lock(rb_pipe->call_mutex);
606 pipe->set_stencil_ref(pipe,
607 stencil_ref);
608 pipe_mutex_unlock(rb_pipe->call_mutex);
609 }
610
611 static void
612 rbug_set_clip_state(struct pipe_context *_pipe,
613 const struct pipe_clip_state *clip)
614 {
615 struct rbug_context *rb_pipe = rbug_context(_pipe);
616 struct pipe_context *pipe = rb_pipe->pipe;
617
618 pipe_mutex_lock(rb_pipe->call_mutex);
619 pipe->set_clip_state(pipe,
620 clip);
621 pipe_mutex_unlock(rb_pipe->call_mutex);
622 }
623
624 static void
625 rbug_set_constant_buffer(struct pipe_context *_pipe,
626 uint shader,
627 uint index,
628 const struct pipe_constant_buffer *_cb)
629 {
630 struct rbug_context *rb_pipe = rbug_context(_pipe);
631 struct pipe_context *pipe = rb_pipe->pipe;
632 struct pipe_constant_buffer cb;
633
634 /* XXX hmm? unwrap the input state */
635 if (_cb) {
636 cb = *_cb;
637 cb.buffer = rbug_resource_unwrap(_cb->buffer);
638 }
639
640 pipe_mutex_lock(rb_pipe->call_mutex);
641 pipe->set_constant_buffer(pipe,
642 shader,
643 index,
644 _cb ? &cb : NULL);
645 pipe_mutex_unlock(rb_pipe->call_mutex);
646 }
647
648 static void
649 rbug_set_framebuffer_state(struct pipe_context *_pipe,
650 const struct pipe_framebuffer_state *_state)
651 {
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;
656 unsigned i;
657
658 /* must protect curr status */
659 pipe_mutex_lock(rb_pipe->call_mutex);
660
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;
664
665 /* unwrap the input state */
666 if (_state) {
667 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
668
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);
674 }
675 unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
676 if (_state->zsbuf)
677 rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
678 state = &unwrapped_state;
679 }
680
681 pipe->set_framebuffer_state(pipe,
682 state);
683
684 pipe_mutex_unlock(rb_pipe->call_mutex);
685 }
686
687 static void
688 rbug_set_polygon_stipple(struct pipe_context *_pipe,
689 const struct pipe_poly_stipple *poly_stipple)
690 {
691 struct rbug_context *rb_pipe = rbug_context(_pipe);
692 struct pipe_context *pipe = rb_pipe->pipe;
693
694 pipe_mutex_lock(rb_pipe->call_mutex);
695 pipe->set_polygon_stipple(pipe,
696 poly_stipple);
697 pipe_mutex_unlock(rb_pipe->call_mutex);
698 }
699
700 static void
701 rbug_set_scissor_states(struct pipe_context *_pipe,
702 unsigned start_slot,
703 unsigned num_scissors,
704 const struct pipe_scissor_state *scissor)
705 {
706 struct rbug_context *rb_pipe = rbug_context(_pipe);
707 struct pipe_context *pipe = rb_pipe->pipe;
708
709 pipe_mutex_lock(rb_pipe->call_mutex);
710 pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
711 pipe_mutex_unlock(rb_pipe->call_mutex);
712 }
713
714 static void
715 rbug_set_viewport_states(struct pipe_context *_pipe,
716 unsigned start_slot,
717 unsigned num_viewports,
718 const struct pipe_viewport_state *viewport)
719 {
720 struct rbug_context *rb_pipe = rbug_context(_pipe);
721 struct pipe_context *pipe = rb_pipe->pipe;
722
723 pipe_mutex_lock(rb_pipe->call_mutex);
724 pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
725 pipe_mutex_unlock(rb_pipe->call_mutex);
726 }
727
728 static void
729 rbug_set_sampler_views(struct pipe_context *_pipe,
730 enum pipe_shader_type shader,
731 unsigned start,
732 unsigned num,
733 struct pipe_sampler_view **_views)
734 {
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;
739 unsigned i;
740
741 assert(start == 0); /* XXX fix */
742
743 /* must protect curr status */
744 pipe_mutex_lock(rb_pipe->call_mutex);
745
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));
750
751 if (_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]);
757 }
758 views = unwrapped_views;
759 }
760
761 pipe->set_sampler_views(pipe, shader, start, num, views);
762
763 pipe_mutex_unlock(rb_pipe->call_mutex);
764 }
765
766 static void
767 rbug_set_vertex_buffers(struct pipe_context *_pipe,
768 unsigned start_slot, unsigned num_buffers,
769 const struct pipe_vertex_buffer *_buffers)
770 {
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;
775 unsigned i;
776
777 pipe_mutex_lock(rb_pipe->call_mutex);
778
779 if (num_buffers && _buffers) {
780 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
781 for (i = 0; i < num_buffers; i++)
782 unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer);
783 buffers = unwrapped_buffers;
784 }
785
786 pipe->set_vertex_buffers(pipe, start_slot,
787 num_buffers,
788 buffers);
789
790 pipe_mutex_unlock(rb_pipe->call_mutex);
791 }
792
793 static void
794 rbug_set_index_buffer(struct pipe_context *_pipe,
795 const struct pipe_index_buffer *_ib)
796 {
797 struct rbug_context *rb_pipe = rbug_context(_pipe);
798 struct pipe_context *pipe = rb_pipe->pipe;
799 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
800
801 if (_ib) {
802 unwrapped_ib = *_ib;
803 unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer);
804 ib = &unwrapped_ib;
805 }
806
807 pipe_mutex_lock(rb_pipe->call_mutex);
808 pipe->set_index_buffer(pipe, ib);
809 pipe_mutex_unlock(rb_pipe->call_mutex);
810 }
811
812 static void
813 rbug_set_sample_mask(struct pipe_context *_pipe,
814 unsigned sample_mask)
815 {
816 struct rbug_context *rb_pipe = rbug_context(_pipe);
817 struct pipe_context *pipe = rb_pipe->pipe;
818
819 pipe_mutex_lock(rb_pipe->call_mutex);
820 pipe->set_sample_mask(pipe, sample_mask);
821 pipe_mutex_unlock(rb_pipe->call_mutex);
822 }
823
824 static struct pipe_stream_output_target *
825 rbug_create_stream_output_target(struct pipe_context *_pipe,
826 struct pipe_resource *_res,
827 unsigned buffer_offset, unsigned buffer_size)
828 {
829 struct rbug_context *rb_pipe = rbug_context(_pipe);
830 struct pipe_context *pipe = rb_pipe->pipe;
831 struct pipe_resource *res = rbug_resource_unwrap(_res);
832 struct pipe_stream_output_target *target;
833
834 pipe_mutex_lock(rb_pipe->call_mutex);
835 target = pipe->create_stream_output_target(pipe, res, buffer_offset,
836 buffer_size);
837 pipe_mutex_unlock(rb_pipe->call_mutex);
838 return target;
839 }
840
841 static void
842 rbug_stream_output_target_destroy(struct pipe_context *_pipe,
843 struct pipe_stream_output_target *target)
844 {
845 struct rbug_context *rb_pipe = rbug_context(_pipe);
846 struct pipe_context *pipe = rb_pipe->pipe;
847
848 pipe_mutex_lock(rb_pipe->call_mutex);
849 pipe->stream_output_target_destroy(pipe, target);
850 pipe_mutex_unlock(rb_pipe->call_mutex);
851 }
852
853 static void
854 rbug_set_stream_output_targets(struct pipe_context *_pipe,
855 unsigned num_targets,
856 struct pipe_stream_output_target **targets,
857 const unsigned *offsets)
858 {
859 struct rbug_context *rb_pipe = rbug_context(_pipe);
860 struct pipe_context *pipe = rb_pipe->pipe;
861
862 pipe_mutex_lock(rb_pipe->call_mutex);
863 pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
864 pipe_mutex_unlock(rb_pipe->call_mutex);
865 }
866
867 static void
868 rbug_resource_copy_region(struct pipe_context *_pipe,
869 struct pipe_resource *_dst,
870 unsigned dst_level,
871 unsigned dstx,
872 unsigned dsty,
873 unsigned dstz,
874 struct pipe_resource *_src,
875 unsigned src_level,
876 const struct pipe_box *src_box)
877 {
878 struct rbug_context *rb_pipe = rbug_context(_pipe);
879 struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
880 struct rbug_resource *rb_resource_src = rbug_resource(_src);
881 struct pipe_context *pipe = rb_pipe->pipe;
882 struct pipe_resource *dst = rb_resource_dst->resource;
883 struct pipe_resource *src = rb_resource_src->resource;
884
885 pipe_mutex_lock(rb_pipe->call_mutex);
886 pipe->resource_copy_region(pipe,
887 dst,
888 dst_level,
889 dstx,
890 dsty,
891 dstz,
892 src,
893 src_level,
894 src_box);
895 pipe_mutex_unlock(rb_pipe->call_mutex);
896 }
897
898 static void
899 rbug_blit(struct pipe_context *_pipe, const struct pipe_blit_info *_blit_info)
900 {
901 struct rbug_context *rb_pipe = rbug_context(_pipe);
902 struct rbug_resource *rb_resource_dst = rbug_resource(_blit_info->dst.resource);
903 struct rbug_resource *rb_resource_src = rbug_resource(_blit_info->src.resource);
904 struct pipe_context *pipe = rb_pipe->pipe;
905 struct pipe_resource *dst = rb_resource_dst->resource;
906 struct pipe_resource *src = rb_resource_src->resource;
907 struct pipe_blit_info blit_info;
908
909 blit_info = *_blit_info;
910 blit_info.dst.resource = dst;
911 blit_info.src.resource = src;
912
913 pipe_mutex_lock(rb_pipe->call_mutex);
914 pipe->blit(pipe, &blit_info);
915 pipe_mutex_unlock(rb_pipe->call_mutex);
916 }
917
918 static void
919 rbug_flush_resource(struct pipe_context *_pipe,
920 struct pipe_resource *_res)
921 {
922 struct rbug_context *rb_pipe = rbug_context(_pipe);
923 struct rbug_resource *rb_resource_res = rbug_resource(_res);
924 struct pipe_context *pipe = rb_pipe->pipe;
925 struct pipe_resource *res = rb_resource_res->resource;
926
927 pipe_mutex_lock(rb_pipe->call_mutex);
928 pipe->flush_resource(pipe, res);
929 pipe_mutex_unlock(rb_pipe->call_mutex);
930 }
931
932 static void
933 rbug_clear(struct pipe_context *_pipe,
934 unsigned buffers,
935 const union pipe_color_union *color,
936 double depth,
937 unsigned stencil)
938 {
939 struct rbug_context *rb_pipe = rbug_context(_pipe);
940 struct pipe_context *pipe = rb_pipe->pipe;
941
942 pipe_mutex_lock(rb_pipe->call_mutex);
943 pipe->clear(pipe,
944 buffers,
945 color,
946 depth,
947 stencil);
948 pipe_mutex_unlock(rb_pipe->call_mutex);
949 }
950
951 static void
952 rbug_clear_render_target(struct pipe_context *_pipe,
953 struct pipe_surface *_dst,
954 const union pipe_color_union *color,
955 unsigned dstx, unsigned dsty,
956 unsigned width, unsigned height,
957 bool render_condition_enabled)
958 {
959 struct rbug_context *rb_pipe = rbug_context(_pipe);
960 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
961 struct pipe_context *pipe = rb_pipe->pipe;
962 struct pipe_surface *dst = rb_surface_dst->surface;
963
964 pipe_mutex_lock(rb_pipe->call_mutex);
965 pipe->clear_render_target(pipe,
966 dst,
967 color,
968 dstx,
969 dsty,
970 width,
971 height,
972 render_condition_enabled);
973 pipe_mutex_unlock(rb_pipe->call_mutex);
974 }
975
976 static void
977 rbug_clear_depth_stencil(struct pipe_context *_pipe,
978 struct pipe_surface *_dst,
979 unsigned clear_flags,
980 double depth,
981 unsigned stencil,
982 unsigned dstx, unsigned dsty,
983 unsigned width, unsigned height,
984 bool render_condition_enabled)
985 {
986 struct rbug_context *rb_pipe = rbug_context(_pipe);
987 struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
988 struct pipe_context *pipe = rb_pipe->pipe;
989 struct pipe_surface *dst = rb_surface_dst->surface;
990
991 pipe_mutex_lock(rb_pipe->call_mutex);
992 pipe->clear_depth_stencil(pipe,
993 dst,
994 clear_flags,
995 depth,
996 stencil,
997 dstx,
998 dsty,
999 width,
1000 height,
1001 render_condition_enabled);
1002 pipe_mutex_unlock(rb_pipe->call_mutex);
1003 }
1004
1005 static void
1006 rbug_flush(struct pipe_context *_pipe,
1007 struct pipe_fence_handle **fence,
1008 unsigned flags)
1009 {
1010 struct rbug_context *rb_pipe = rbug_context(_pipe);
1011 struct pipe_context *pipe = rb_pipe->pipe;
1012
1013 pipe_mutex_lock(rb_pipe->call_mutex);
1014 pipe->flush(pipe, fence, flags);
1015 pipe_mutex_unlock(rb_pipe->call_mutex);
1016 }
1017
1018 static struct pipe_sampler_view *
1019 rbug_context_create_sampler_view(struct pipe_context *_pipe,
1020 struct pipe_resource *_resource,
1021 const struct pipe_sampler_view *templ)
1022 {
1023 struct rbug_context *rb_pipe = rbug_context(_pipe);
1024 struct rbug_resource *rb_resource = rbug_resource(_resource);
1025 struct pipe_context *pipe = rb_pipe->pipe;
1026 struct pipe_resource *resource = rb_resource->resource;
1027 struct pipe_sampler_view *result;
1028
1029 pipe_mutex_lock(rb_pipe->call_mutex);
1030 result = pipe->create_sampler_view(pipe,
1031 resource,
1032 templ);
1033 pipe_mutex_unlock(rb_pipe->call_mutex);
1034
1035 if (result)
1036 return rbug_sampler_view_create(rb_pipe, rb_resource, result);
1037 return NULL;
1038 }
1039
1040 static void
1041 rbug_context_sampler_view_destroy(struct pipe_context *_pipe,
1042 struct pipe_sampler_view *_view)
1043 {
1044 rbug_sampler_view_destroy(rbug_context(_pipe),
1045 rbug_sampler_view(_view));
1046 }
1047
1048 static struct pipe_surface *
1049 rbug_context_create_surface(struct pipe_context *_pipe,
1050 struct pipe_resource *_resource,
1051 const struct pipe_surface *surf_tmpl)
1052 {
1053 struct rbug_context *rb_pipe = rbug_context(_pipe);
1054 struct rbug_resource *rb_resource = rbug_resource(_resource);
1055 struct pipe_context *pipe = rb_pipe->pipe;
1056 struct pipe_resource *resource = rb_resource->resource;
1057 struct pipe_surface *result;
1058
1059 pipe_mutex_lock(rb_pipe->call_mutex);
1060 result = pipe->create_surface(pipe,
1061 resource,
1062 surf_tmpl);
1063 pipe_mutex_unlock(rb_pipe->call_mutex);
1064
1065 if (result)
1066 return rbug_surface_create(rb_pipe, rb_resource, result);
1067 return NULL;
1068 }
1069
1070 static void
1071 rbug_context_surface_destroy(struct pipe_context *_pipe,
1072 struct pipe_surface *_surface)
1073 {
1074 struct rbug_context *rb_pipe = rbug_context(_pipe);
1075 struct rbug_surface *rb_surface = rbug_surface(_surface);
1076
1077 pipe_mutex_lock(rb_pipe->call_mutex);
1078 rbug_surface_destroy(rb_pipe,
1079 rb_surface);
1080 pipe_mutex_unlock(rb_pipe->call_mutex);
1081 }
1082
1083
1084
1085 static void *
1086 rbug_context_transfer_map(struct pipe_context *_context,
1087 struct pipe_resource *_resource,
1088 unsigned level,
1089 unsigned usage,
1090 const struct pipe_box *box,
1091 struct pipe_transfer **transfer)
1092 {
1093 struct rbug_context *rb_pipe = rbug_context(_context);
1094 struct rbug_resource *rb_resource = rbug_resource(_resource);
1095 struct pipe_context *context = rb_pipe->pipe;
1096 struct pipe_resource *resource = rb_resource->resource;
1097 struct pipe_transfer *result;
1098 void *map;
1099
1100 pipe_mutex_lock(rb_pipe->call_mutex);
1101 map = context->transfer_map(context,
1102 resource,
1103 level,
1104 usage,
1105 box, &result);
1106 pipe_mutex_unlock(rb_pipe->call_mutex);
1107
1108 *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
1109 return *transfer ? map : NULL;
1110 }
1111
1112 static void
1113 rbug_context_transfer_flush_region(struct pipe_context *_context,
1114 struct pipe_transfer *_transfer,
1115 const struct pipe_box *box)
1116 {
1117 struct rbug_context *rb_pipe = rbug_context(_context);
1118 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1119 struct pipe_context *context = rb_pipe->pipe;
1120 struct pipe_transfer *transfer = rb_transfer->transfer;
1121
1122 pipe_mutex_lock(rb_pipe->call_mutex);
1123 context->transfer_flush_region(context,
1124 transfer,
1125 box);
1126 pipe_mutex_unlock(rb_pipe->call_mutex);
1127 }
1128
1129
1130 static void
1131 rbug_context_transfer_unmap(struct pipe_context *_context,
1132 struct pipe_transfer *_transfer)
1133 {
1134 struct rbug_context *rb_pipe = rbug_context(_context);
1135 struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
1136 struct pipe_context *context = rb_pipe->pipe;
1137 struct pipe_transfer *transfer = rb_transfer->transfer;
1138
1139 pipe_mutex_lock(rb_pipe->call_mutex);
1140 context->transfer_unmap(context,
1141 transfer);
1142 rbug_transfer_destroy(rb_pipe,
1143 rb_transfer);
1144 pipe_mutex_unlock(rb_pipe->call_mutex);
1145 }
1146
1147
1148 static void
1149 rbug_context_buffer_subdata(struct pipe_context *_context,
1150 struct pipe_resource *_resource,
1151 unsigned usage, unsigned offset,
1152 unsigned size, const void *data)
1153 {
1154 struct rbug_context *rb_pipe = rbug_context(_context);
1155 struct rbug_resource *rb_resource = rbug_resource(_resource);
1156 struct pipe_context *context = rb_pipe->pipe;
1157 struct pipe_resource *resource = rb_resource->resource;
1158
1159 pipe_mutex_lock(rb_pipe->call_mutex);
1160 context->buffer_subdata(context, resource, usage, offset, size, data);
1161 pipe_mutex_unlock(rb_pipe->call_mutex);
1162 }
1163
1164
1165 static void
1166 rbug_context_texture_subdata(struct pipe_context *_context,
1167 struct pipe_resource *_resource,
1168 unsigned level,
1169 unsigned usage,
1170 const struct pipe_box *box,
1171 const void *data,
1172 unsigned stride,
1173 unsigned layer_stride)
1174 {
1175 struct rbug_context *rb_pipe = rbug_context(_context);
1176 struct rbug_resource *rb_resource = rbug_resource(_resource);
1177 struct pipe_context *context = rb_pipe->pipe;
1178 struct pipe_resource *resource = rb_resource->resource;
1179
1180 pipe_mutex_lock(rb_pipe->call_mutex);
1181 context->texture_subdata(context,
1182 resource,
1183 level,
1184 usage,
1185 box,
1186 data,
1187 stride,
1188 layer_stride);
1189 pipe_mutex_unlock(rb_pipe->call_mutex);
1190 }
1191
1192
1193 struct pipe_context *
1194 rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
1195 {
1196 struct rbug_context *rb_pipe;
1197 struct rbug_screen *rb_screen = rbug_screen(_screen);
1198
1199 if (!rb_screen)
1200 return NULL;
1201
1202 rb_pipe = CALLOC_STRUCT(rbug_context);
1203 if (!rb_pipe)
1204 return NULL;
1205
1206 pipe_mutex_init(rb_pipe->draw_mutex);
1207 cnd_init(&rb_pipe->draw_cond);
1208 pipe_mutex_init(rb_pipe->call_mutex);
1209 pipe_mutex_init(rb_pipe->list_mutex);
1210 make_empty_list(&rb_pipe->shaders);
1211
1212 rb_pipe->base.screen = _screen;
1213 rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
1214 rb_pipe->base.draw = NULL;
1215 rb_pipe->base.stream_uploader = pipe->stream_uploader;
1216 rb_pipe->base.const_uploader = pipe->const_uploader;
1217
1218 rb_pipe->base.destroy = rbug_destroy;
1219 rb_pipe->base.draw_vbo = rbug_draw_vbo;
1220 rb_pipe->base.create_query = rbug_create_query;
1221 rb_pipe->base.destroy_query = rbug_destroy_query;
1222 rb_pipe->base.begin_query = rbug_begin_query;
1223 rb_pipe->base.end_query = rbug_end_query;
1224 rb_pipe->base.get_query_result = rbug_get_query_result;
1225 rb_pipe->base.set_active_query_state = rbug_set_active_query_state;
1226 rb_pipe->base.create_blend_state = rbug_create_blend_state;
1227 rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
1228 rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
1229 rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
1230 rb_pipe->base.bind_sampler_states = rbug_bind_sampler_states;
1231 rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
1232 rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
1233 rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
1234 rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state;
1235 rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state;
1236 rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state;
1237 rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state;
1238 rb_pipe->base.create_fs_state = rbug_create_fs_state;
1239 rb_pipe->base.bind_fs_state = rbug_bind_fs_state;
1240 rb_pipe->base.delete_fs_state = rbug_delete_fs_state;
1241 rb_pipe->base.create_vs_state = rbug_create_vs_state;
1242 rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
1243 rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
1244 rb_pipe->base.create_gs_state = rbug_create_gs_state;
1245 rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
1246 rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
1247 rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
1248 rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
1249 rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
1250 rb_pipe->base.set_blend_color = rbug_set_blend_color;
1251 rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref;
1252 rb_pipe->base.set_clip_state = rbug_set_clip_state;
1253 rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
1254 rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
1255 rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
1256 rb_pipe->base.set_scissor_states = rbug_set_scissor_states;
1257 rb_pipe->base.set_viewport_states = rbug_set_viewport_states;
1258 rb_pipe->base.set_sampler_views = rbug_set_sampler_views;
1259 rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
1260 rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
1261 rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
1262 rb_pipe->base.create_stream_output_target = rbug_create_stream_output_target;
1263 rb_pipe->base.stream_output_target_destroy = rbug_stream_output_target_destroy;
1264 rb_pipe->base.set_stream_output_targets = rbug_set_stream_output_targets;
1265 rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
1266 rb_pipe->base.blit = rbug_blit;
1267 rb_pipe->base.flush_resource = rbug_flush_resource;
1268 rb_pipe->base.clear = rbug_clear;
1269 rb_pipe->base.clear_render_target = rbug_clear_render_target;
1270 rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
1271 rb_pipe->base.flush = rbug_flush;
1272 rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
1273 rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
1274 rb_pipe->base.create_surface = rbug_context_create_surface;
1275 rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
1276 rb_pipe->base.transfer_map = rbug_context_transfer_map;
1277 rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
1278 rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
1279 rb_pipe->base.buffer_subdata = rbug_context_buffer_subdata;
1280 rb_pipe->base.texture_subdata = rbug_context_texture_subdata;
1281
1282 rb_pipe->pipe = pipe;
1283
1284 rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
1285
1286 if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) {
1287 rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE;
1288 }
1289
1290 return &rb_pipe->base;
1291 }