radeonsi: move handling of DBG_NO_OPT_VARIANT into si_shader_selector_key
[mesa.git] / src / gallium / drivers / rbug / rbug_context.c
index e0dd5cf8c2b17a226a229b233e40279ace9ff8b0..e1f3c4f28447aa768c553591770eac38fd4cb9be 100644 (file)
@@ -29,7 +29,7 @@
 #include "pipe/p_context.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
-#include "util/u_simple_list.h"
+#include "util/simple_list.h"
 
 #include "rbug/rbug_context.h"
 
 static void
 rbug_destroy(struct pipe_context *_pipe)
 {
+   struct rbug_screen *rb_screen = rbug_screen(_pipe->screen);
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   rbug_screen_remove_from_list(rb_screen, contexts, rb_pipe);
+
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->destroy(pipe);
+   rb_pipe->pipe = NULL;
+   mtx_unlock(&rb_pipe->call_mutex);
 
    FREE(rb_pipe);
 }
@@ -56,19 +62,23 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
       rb_pipe->draw_blocked |= flag;
    } else if ((rb_pipe->draw_rule.blocker & flag) &&
               (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
-      int k;
+      unsigned k;
       boolean block = FALSE;
+      unsigned sh;
+
       debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
-                   (void *) rb_pipe->draw_rule.fs, (void *) rb_pipe->curr.fs,
-                   (void *) rb_pipe->draw_rule.vs, (void *) rb_pipe->curr.vs,
+                   (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_FRAGMENT],
+                   (void *) rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT],
+                   (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_VERTEX],
+                   (void *) rb_pipe->curr.shader[PIPE_SHADER_VERTEX],
                    (void *) rb_pipe->draw_rule.surf, 0,
                    (void *) rb_pipe->draw_rule.texture, 0);
-      if (rb_pipe->draw_rule.fs &&
-          rb_pipe->draw_rule.fs == rb_pipe->curr.fs)
-         block = TRUE;
-      if (rb_pipe->draw_rule.vs &&
-          rb_pipe->draw_rule.vs == rb_pipe->curr.vs)
-         block = TRUE;
+      for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
+         if (rb_pipe->draw_rule.shader[sh] &&
+             rb_pipe->draw_rule.shader[sh] == rb_pipe->curr.shader[sh])
+            block = TRUE;
+      }
+
       if (rb_pipe->draw_rule.surf &&
           rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
             block = TRUE;
@@ -77,12 +87,13 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
             if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
                block = TRUE;
       if (rb_pipe->draw_rule.texture) {
-         for (k = 0; k < rb_pipe->curr.num_fs_views; k++)
-            if (rb_pipe->draw_rule.texture == rb_pipe->curr.fs_texs[k])
-               block = TRUE;
-         for (k = 0; k < rb_pipe->curr.num_vs_views; k++) {
-            if (rb_pipe->draw_rule.texture == rb_pipe->curr.vs_texs[k]) {
-               block = TRUE;
+         for (sh = 0; sh < ARRAY_SIZE(rb_pipe->curr.num_views); sh++) {
+            for (k = 0; k < rb_pipe->curr.num_views[sh]; k++) {
+               if (rb_pipe->draw_rule.texture == rb_pipe->curr.texs[sh][k]) {
+                  block = TRUE;
+                  sh = PIPE_SHADER_TYPES; /* to break out of both loops */
+                  break;
+               }
             }
          }
       }
@@ -97,103 +108,47 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
    /* wait for rbug to clear the blocked flag */
    while (rb_pipe->draw_blocked & flag) {
       rb_pipe->draw_blocked |= flag;
-      pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
+      cnd_wait(&rb_pipe->draw_cond, &rb_pipe->draw_mutex);
    }
 
 }
 
 static void
-rbug_draw_arrays(struct pipe_context *_pipe,
-                 unsigned prim,
-                 unsigned start,
-                 unsigned count)
+rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
-   pipe_mutex_lock(rb_pipe->draw_mutex);
+   mtx_lock(&rb_pipe->draw_mutex);
    rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
 
-   pipe->draw_arrays(pipe,
-                     prim,
-                     start,
-                     count);
+   mtx_lock(&rb_pipe->call_mutex);
+   /* XXX loop over PIPE_SHADER_x here */
+   if (!(rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] && rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT]->disabled) &&
+       !(rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) &&
+       !(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->disabled))
+      pipe->draw_vbo(pipe, info);
+   mtx_unlock(&rb_pipe->call_mutex);
 
    rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
-   pipe_mutex_unlock(rb_pipe->draw_mutex);
-}
-
-static void
-rbug_draw_elements(struct pipe_context *_pipe,
-                   struct pipe_resource *_indexResource,
-                   unsigned indexSize,
-                   int indexBias,
-                   unsigned prim,
-                   unsigned start,
-                   unsigned count)
-{
-   struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct rbug_resource *rb_resource = rbug_resource(_indexResource);
-   struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_resource *indexResource = rb_resource->resource;
-
-   pipe_mutex_lock(rb_pipe->draw_mutex);
-   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
-
-   pipe->draw_elements(pipe,
-                       indexResource,
-                       indexSize,
-                       indexBias,
-                       prim,
-                       start,
-                       count);
-
-   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
-   pipe_mutex_unlock(rb_pipe->draw_mutex);
-}
-
-static void
-rbug_draw_range_elements(struct pipe_context *_pipe,
-                         struct pipe_resource *_indexResource,
-                         unsigned indexSize,
-                         int indexBias,
-                         unsigned minIndex,
-                         unsigned maxIndex,
-                         unsigned mode,
-                         unsigned start,
-                         unsigned count)
-{
-   struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct rbug_resource *rb_resource = rbug_resource(_indexResource);
-   struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_resource *indexResource = rb_resource->resource;
-
-   pipe_mutex_lock(rb_pipe->draw_mutex);
-   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
-
-   pipe->draw_range_elements(pipe,
-                             indexResource,
-                             indexSize,
-                             indexBias,
-                             minIndex,
-                             maxIndex,
-                             mode,
-                             start,
-                             count);
-
-   rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
-   pipe_mutex_unlock(rb_pipe->draw_mutex);
+   mtx_unlock(&rb_pipe->draw_mutex);
 }
 
 static struct pipe_query *
 rbug_create_query(struct pipe_context *_pipe,
-                  unsigned query_type)
+                  unsigned query_type,
+                  unsigned index)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
-
-   return pipe->create_query(pipe,
-                             query_type);
+   struct pipe_query *query;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   query = pipe->create_query(pipe,
+                              query_type,
+                              index);
+   mtx_unlock(&rb_pipe->call_mutex);
+   return query;
 }
 
 static void
@@ -203,45 +158,71 @@ rbug_destroy_query(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->destroy_query(pipe,
                        query);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
-static void
+static boolean
 rbug_begin_query(struct pipe_context *_pipe,
                  struct pipe_query *query)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   boolean ret;
 
-   pipe->begin_query(pipe,
-                     query);
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->begin_query(pipe, query);
+   mtx_unlock(&rb_pipe->call_mutex);
+   return ret;
 }
 
-static void
+static bool
 rbug_end_query(struct pipe_context *_pipe,
                struct pipe_query *query)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   bool ret;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->end_query(pipe,
+                         query);
+   mtx_unlock(&rb_pipe->call_mutex);
 
-   pipe->end_query(pipe,
-                   query);
+   return ret;
 }
 
 static boolean
 rbug_get_query_result(struct pipe_context *_pipe,
                       struct pipe_query *query,
                       boolean wait,
-                      void *result)
+                      union pipe_query_result *result)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct pipe_context *pipe = rb_pipe->pipe;
+   boolean ret;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->get_query_result(pipe,
+                                query,
+                                wait,
+                                result);
+   mtx_unlock(&rb_pipe->call_mutex);
+
+   return ret;
+}
+
+static void
+rbug_set_active_query_state(struct pipe_context *_pipe, boolean enable)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
-   return pipe->get_query_result(pipe,
-                                 query,
-                                 wait,
-                                 result);
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->set_active_query_state(pipe, enable);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -250,9 +231,14 @@ rbug_create_blend_state(struct pipe_context *_pipe,
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   void *ret;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->create_blend_state(pipe,
+                                  blend);
+   mtx_unlock(&rb_pipe->call_mutex);
 
-   return pipe->create_blend_state(pipe,
-                                   blend);
+   return ret;
 }
 
 static void
@@ -262,8 +248,10 @@ rbug_bind_blend_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->bind_blend_state(pipe,
-                              blend);
+                          blend);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -273,8 +261,10 @@ rbug_delete_blend_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->delete_blend_state(pipe,
                             blend);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -283,35 +273,28 @@ rbug_create_sampler_state(struct pipe_context *_pipe,
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   void *ret;
 
-   return pipe->create_sampler_state(pipe,
-                                     sampler);
-}
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->create_sampler_state(pipe,
+                                    sampler);
+   mtx_unlock(&rb_pipe->call_mutex);
 
-static void
-rbug_bind_fragment_sampler_states(struct pipe_context *_pipe,
-                                  unsigned num_samplers,
-                                  void **samplers)
-{
-   struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct pipe_context *pipe = rb_pipe->pipe;
-
-   pipe->bind_fragment_sampler_states(pipe,
-                                      num_samplers,
-                                      samplers);
+   return ret;
 }
 
 static void
-rbug_bind_vertex_sampler_states(struct pipe_context *_pipe,
-                                unsigned num_samplers,
-                                void **samplers)
+rbug_bind_sampler_states(struct pipe_context *_pipe,
+                         enum pipe_shader_type shader,
+                         unsigned start, unsigned count,
+                         void **samplers)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
-   pipe->bind_vertex_sampler_states(pipe,
-                                    num_samplers,
-                                    samplers);
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->bind_sampler_states(pipe, shader, start, count, samplers);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -321,8 +304,10 @@ rbug_delete_sampler_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->delete_sampler_state(pipe,
                               sampler);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -331,9 +316,14 @@ rbug_create_rasterizer_state(struct pipe_context *_pipe,
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   void *ret;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->create_rasterizer_state(pipe,
+                                       rasterizer);
+   mtx_unlock(&rb_pipe->call_mutex);
 
-   return pipe->create_rasterizer_state(pipe,
-                                        rasterizer);
+   return ret;
 }
 
 static void
@@ -343,8 +333,10 @@ rbug_bind_rasterizer_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->bind_rasterizer_state(pipe,
                                rasterizer);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -354,8 +346,10 @@ rbug_delete_rasterizer_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->delete_rasterizer_state(pipe,
                                  rasterizer);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -364,9 +358,14 @@ rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   void *ret;
 
-   return pipe->create_depth_stencil_alpha_state(pipe,
-                                                 depth_stencil_alpha);
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->create_depth_stencil_alpha_state(pipe,
+                                                depth_stencil_alpha);
+   mtx_unlock(&rb_pipe->call_mutex);
+
+   return ret;
 }
 
 static void
@@ -376,8 +375,10 @@ rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->bind_depth_stencil_alpha_state(pipe,
                                         depth_stencil_alpha);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -387,8 +388,10 @@ rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->delete_depth_stencil_alpha_state(pipe,
                                           depth_stencil_alpha);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -399,7 +402,10 @@ rbug_create_fs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *result;
 
+   mtx_lock(&rb_pipe->call_mutex);
    result = pipe->create_fs_state(pipe, state);
+   mtx_unlock(&rb_pipe->call_mutex);
+
    if (!result)
       return NULL;
 
@@ -414,10 +420,14 @@ rbug_bind_fs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *fs;
 
+   mtx_lock(&rb_pipe->call_mutex);
+
    fs = rbug_shader_unwrap(_fs);
-   rb_pipe->curr.fs = rbug_shader(_fs);
+   rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs);
    pipe->bind_fs_state(pipe,
                        fs);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -427,7 +437,9 @@ rbug_delete_fs_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_shader *rb_shader = rbug_shader(_fs);
 
+   mtx_lock(&rb_pipe->call_mutex);
    rbug_shader_destroy(rb_pipe, rb_shader);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -438,7 +450,10 @@ rbug_create_vs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *result;
 
+   mtx_lock(&rb_pipe->call_mutex);
    result = pipe->create_vs_state(pipe, state);
+   mtx_unlock(&rb_pipe->call_mutex);
+
    if (!result)
       return NULL;
 
@@ -453,10 +468,14 @@ rbug_bind_vs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *vs;
 
+   mtx_lock(&rb_pipe->call_mutex);
+
    vs = rbug_shader_unwrap(_vs);
-   rb_pipe->curr.vs = rbug_shader(_vs);
+   rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs);
    pipe->bind_vs_state(pipe,
                        vs);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -466,7 +485,9 @@ rbug_delete_vs_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_shader *rb_shader = rbug_shader(_vs);
 
+   mtx_unlock(&rb_pipe->call_mutex);
    rbug_shader_destroy(rb_pipe, rb_shader);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -477,7 +498,10 @@ rbug_create_gs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *result;
 
+   mtx_lock(&rb_pipe->call_mutex);
    result = pipe->create_gs_state(pipe, state);
+   mtx_unlock(&rb_pipe->call_mutex);
+
    if (!result)
       return NULL;
 
@@ -492,10 +516,14 @@ rbug_bind_gs_state(struct pipe_context *_pipe,
    struct pipe_context *pipe = rb_pipe->pipe;
    void *gs;
 
+   mtx_lock(&rb_pipe->call_mutex);
+
    gs = rbug_shader_unwrap(_gs);
-   rb_pipe->curr.gs = rbug_shader(_gs);
+   rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs);
    pipe->bind_gs_state(pipe,
                        gs);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -505,7 +533,9 @@ rbug_delete_gs_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_shader *rb_shader = rbug_shader(_gs);
 
+   mtx_lock(&rb_pipe->call_mutex);
    rbug_shader_destroy(rb_pipe, rb_shader);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void *
@@ -515,10 +545,15 @@ rbug_create_vertex_elements_state(struct pipe_context *_pipe,
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
+   void *ret;
 
-   return pipe->create_vertex_elements_state(pipe,
+   mtx_lock(&rb_pipe->call_mutex);
+   ret = pipe->create_vertex_elements_state(pipe,
                                              num_elements,
                                              vertex_elements);
+   mtx_unlock(&rb_pipe->call_mutex);
+
+   return ret;
 }
 
 static void
@@ -528,8 +563,10 @@ rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->bind_vertex_elements_state(pipe,
                                     velems);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -539,8 +576,10 @@ rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->delete_vertex_elements_state(pipe,
                                       velems);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -550,8 +589,10 @@ rbug_set_blend_color(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_blend_color(pipe,
                          blend_color);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -561,8 +602,10 @@ rbug_set_stencil_ref(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_stencil_ref(pipe,
                          stencil_ref);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -572,31 +615,34 @@ rbug_set_clip_state(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_clip_state(pipe,
                         clip);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_set_constant_buffer(struct pipe_context *_pipe,
-                         uint shader,
+                         enum pipe_shader_type shader,
                          uint index,
-                         struct pipe_resource *_resource)
+                         const struct pipe_constant_buffer *_cb)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_resource *unwrapped_resource;
-   struct pipe_resource *resource = NULL;
+   struct pipe_constant_buffer cb;
 
    /* XXX hmm? unwrap the input state */
-   if (_resource) {
-      unwrapped_resource = rbug_resource_unwrap(_resource);
-      resource = unwrapped_resource;
+   if (_cb) {
+      cb = *_cb;
+      cb.buffer = rbug_resource_unwrap(_cb->buffer);
    }
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_constant_buffer(pipe,
                              shader,
                              index,
-                             resource);
+                             _cb ? &cb : NULL);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -609,8 +655,12 @@ rbug_set_framebuffer_state(struct pipe_context *_pipe,
    struct pipe_framebuffer_state *state = NULL;
    unsigned i;
 
+   /* must protect curr status */
+   mtx_lock(&rb_pipe->call_mutex);
+
    rb_pipe->curr.nr_cbufs = 0;
    memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
+   rb_pipe->curr.zsbuf = NULL;
 
    /* unwrap the input state */
    if (_state) {
@@ -623,11 +673,15 @@ rbug_set_framebuffer_state(struct pipe_context *_pipe,
             rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
       }
       unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
+      if (_state->zsbuf)
+         rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
       state = &unwrapped_state;
    }
 
    pipe->set_framebuffer_state(pipe,
                                state);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -637,93 +691,81 @@ rbug_set_polygon_stipple(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_polygon_stipple(pipe,
                              poly_stipple);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
-rbug_set_scissor_state(struct pipe_context *_pipe,
-                       const struct pipe_scissor_state *scissor)
+rbug_set_scissor_states(struct pipe_context *_pipe,
+                        unsigned start_slot,
+                        unsigned num_scissors,
+                        const struct pipe_scissor_state *scissor)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
-   pipe->set_scissor_state(pipe,
-                           scissor);
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
-rbug_set_viewport_state(struct pipe_context *_pipe,
-                        const struct pipe_viewport_state *viewport)
+rbug_set_viewport_states(struct pipe_context *_pipe,
+                         unsigned start_slot,
+                         unsigned num_viewports,
+                         const struct pipe_viewport_state *viewport)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
-   pipe->set_viewport_state(pipe,
-                            viewport);
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
-rbug_set_fragment_sampler_views(struct pipe_context *_pipe,
-                                unsigned num,
-                                struct pipe_sampler_view **_views)
+rbug_set_sampler_views(struct pipe_context *_pipe,
+                       enum pipe_shader_type shader,
+                       unsigned start,
+                       unsigned num,
+                       struct pipe_sampler_view **_views)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
+   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    struct pipe_sampler_view **views = NULL;
    unsigned i;
 
-   rb_pipe->curr.num_fs_views = 0;
-   memset(rb_pipe->curr.fs_views, 0, sizeof(rb_pipe->curr.fs_views));
-   memset(rb_pipe->curr.fs_texs, 0, sizeof(rb_pipe->curr.fs_texs));
-   memset(unwrapped_views, 0, sizeof(unwrapped_views));
-
-   if (_views) {
-      rb_pipe->curr.num_fs_views = num;
-      for (i = 0; i < num; i++) {
-         rb_pipe->curr.fs_views[i] = rbug_sampler_view(_views[i]);
-         rb_pipe->curr.fs_texs[i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
-         unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
-      }
-      views = unwrapped_views;
-   }
-
-   pipe->set_fragment_sampler_views(pipe, num, views);
-}
+   assert(start == 0); /* XXX fix */
 
-static void
-rbug_set_vertex_sampler_views(struct pipe_context *_pipe,
-                              unsigned num,
-                              struct pipe_sampler_view **_views)
-{
-   struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
-   struct pipe_sampler_view **views = NULL;
-   unsigned i;
+   /* must protect curr status */
+   mtx_lock(&rb_pipe->call_mutex);
 
-   rb_pipe->curr.num_vs_views = 0;
-   memset(rb_pipe->curr.vs_views, 0, sizeof(rb_pipe->curr.vs_views));
-   memset(rb_pipe->curr.vs_texs, 0, sizeof(rb_pipe->curr.vs_texs));
+   rb_pipe->curr.num_views[shader] = 0;
+   memset(rb_pipe->curr.views[shader], 0, sizeof(rb_pipe->curr.views[shader]));
+   memset(rb_pipe->curr.texs[shader], 0, sizeof(rb_pipe->curr.texs[shader]));
    memset(unwrapped_views, 0, sizeof(unwrapped_views));
 
    if (_views) {
-      rb_pipe->curr.num_vs_views = num;
+      rb_pipe->curr.num_views[shader] = num;
       for (i = 0; i < num; i++) {
-         rb_pipe->curr.vs_views[i] = rbug_sampler_view(_views[i]);
-         rb_pipe->curr.vs_texs[i] = rbug_resource(_views[i]->texture);
+         rb_pipe->curr.views[shader][i] = rbug_sampler_view(_views[i]);
+         rb_pipe->curr.texs[shader][i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
          unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
       }
       views = unwrapped_views;
    }
 
-   pipe->set_vertex_sampler_views(pipe, num, views);
+   pipe->set_sampler_views(pipe, shader, start, num, views);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_set_vertex_buffers(struct pipe_context *_pipe,
-                        unsigned num_buffers,
+                        unsigned start_slot, unsigned num_buffers,
                         const struct pipe_vertex_buffer *_buffers)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
@@ -732,16 +774,23 @@ rbug_set_vertex_buffers(struct pipe_context *_pipe,
    struct pipe_vertex_buffer *buffers = NULL;
    unsigned i;
 
-   if (num_buffers) {
+   mtx_lock(&rb_pipe->call_mutex);
+
+   if (num_buffers && _buffers) {
       memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
-      for (i = 0; i < num_buffers; i++)
-         unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer);
+      for (i = 0; i < num_buffers; i++) {
+         if (!_buffers[i].is_user_buffer)
+            unwrapped_buffers[i].buffer.resource =
+               rbug_resource_unwrap(_buffers[i].buffer.resource);
+      }
       buffers = unwrapped_buffers;
    }
 
-   pipe->set_vertex_buffers(pipe,
+   pipe->set_vertex_buffers(pipe, start_slot,
                             num_buffers,
                             buffers);
+
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -751,23 +800,64 @@ rbug_set_sample_mask(struct pipe_context *_pipe,
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->set_sample_mask(pipe, sample_mask);
+   mtx_unlock(&rb_pipe->call_mutex);
+}
+
+static struct pipe_stream_output_target *
+rbug_create_stream_output_target(struct pipe_context *_pipe,
+                                 struct pipe_resource *_res,
+                                 unsigned buffer_offset, unsigned buffer_size)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct pipe_context *pipe = rb_pipe->pipe;
+   struct pipe_resource *res = rbug_resource_unwrap(_res);
+   struct pipe_stream_output_target *target;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   target = pipe->create_stream_output_target(pipe, res, buffer_offset,
+                                              buffer_size);
+   mtx_unlock(&rb_pipe->call_mutex);
+   return target;
+}
+
+static void
+rbug_stream_output_target_destroy(struct pipe_context *_pipe,
+                                  struct pipe_stream_output_target *target)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct pipe_context *pipe = rb_pipe->pipe;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->stream_output_target_destroy(pipe, target);
+   mtx_unlock(&rb_pipe->call_mutex);
+}
+
+static void
+rbug_set_stream_output_targets(struct pipe_context *_pipe,
+                               unsigned num_targets,
+                               struct pipe_stream_output_target **targets,
+                               const unsigned *offsets)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct pipe_context *pipe = rb_pipe->pipe;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_resource_copy_region(struct pipe_context *_pipe,
                           struct pipe_resource *_dst,
-                          struct pipe_subresource subdst,
+                          unsigned dst_level,
                           unsigned dstx,
                           unsigned dsty,
                           unsigned dstz,
                           struct pipe_resource *_src,
-                          struct pipe_subresource subsrc,
-                          unsigned srcx,
-                          unsigned srcy,
-                          unsigned srcz,
-                          unsigned width,
-                          unsigned height)
+                          unsigned src_level,
+                          const struct pipe_box *src_box)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
@@ -776,57 +866,95 @@ rbug_resource_copy_region(struct pipe_context *_pipe,
    struct pipe_resource *dst = rb_resource_dst->resource;
    struct pipe_resource *src = rb_resource_src->resource;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->resource_copy_region(pipe,
                               dst,
-                              subdst,
+                              dst_level,
                               dstx,
                               dsty,
                               dstz,
                               src,
-                              subsrc,
-                              srcx,
-                              srcy,
-                              srcz,
-                              width,
-                              height);
+                              src_level,
+                              src_box);
+   mtx_unlock(&rb_pipe->call_mutex);
+}
+
+static void
+rbug_blit(struct pipe_context *_pipe, const struct pipe_blit_info *_blit_info)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct rbug_resource *rb_resource_dst = rbug_resource(_blit_info->dst.resource);
+   struct rbug_resource *rb_resource_src = rbug_resource(_blit_info->src.resource);
+   struct pipe_context *pipe = rb_pipe->pipe;
+   struct pipe_resource *dst = rb_resource_dst->resource;
+   struct pipe_resource *src = rb_resource_src->resource;
+   struct pipe_blit_info blit_info;
+
+   blit_info = *_blit_info;
+   blit_info.dst.resource = dst;
+   blit_info.src.resource = src;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->blit(pipe, &blit_info);
+   mtx_unlock(&rb_pipe->call_mutex);
+}
+
+static void
+rbug_flush_resource(struct pipe_context *_pipe,
+                    struct pipe_resource *_res)
+{
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct rbug_resource *rb_resource_res = rbug_resource(_res);
+   struct pipe_context *pipe = rb_pipe->pipe;
+   struct pipe_resource *res = rb_resource_res->resource;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->flush_resource(pipe, res);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_clear(struct pipe_context *_pipe,
            unsigned buffers,
-           const float *rgba,
+           const union pipe_color_union *color,
            double depth,
            unsigned stencil)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->clear(pipe,
                buffers,
-               rgba,
+               color,
                depth,
                stencil);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_clear_render_target(struct pipe_context *_pipe,
                          struct pipe_surface *_dst,
-                         const float *rgba,
+                         const union pipe_color_union *color,
                          unsigned dstx, unsigned dsty,
-                         unsigned width, unsigned height)
+                         unsigned width, unsigned height,
+                         bool render_condition_enabled)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
    struct pipe_context *pipe = rb_pipe->pipe;
    struct pipe_surface *dst = rb_surface_dst->surface;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->clear_render_target(pipe,
                              dst,
-                             rgba,
+                             color,
                              dstx,
                              dsty,
                              width,
-                             height);
+                             height,
+                             render_condition_enabled);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
@@ -836,13 +964,15 @@ rbug_clear_depth_stencil(struct pipe_context *_pipe,
                          double depth,
                          unsigned stencil,
                          unsigned dstx, unsigned dsty,
-                         unsigned width, unsigned height)
+                         unsigned width, unsigned height,
+                         bool render_condition_enabled)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
    struct pipe_context *pipe = rb_pipe->pipe;
    struct pipe_surface *dst = rb_surface_dst->surface;
 
+   mtx_lock(&rb_pipe->call_mutex);
    pipe->clear_depth_stencil(pipe,
                              dst,
                              clear_flags,
@@ -851,37 +981,22 @@ rbug_clear_depth_stencil(struct pipe_context *_pipe,
                              dstx,
                              dsty,
                              width,
-                             height);
+                             height,
+                             render_condition_enabled);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static void
 rbug_flush(struct pipe_context *_pipe,
-           unsigned flags,
-           struct pipe_fence_handle **fence)
-{
-   struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct pipe_context *pipe = rb_pipe->pipe;
-
-   pipe->flush(pipe,
-               flags,
-               fence);
-}
-
-static unsigned int
-rbug_is_resource_referenced(struct pipe_context *_pipe,
-                            struct pipe_resource *_resource,
-                            unsigned face,
-                            unsigned level)
+           struct pipe_fence_handle **fence,
+           unsigned flags)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
-   struct rbug_resource *rb_resource = rbug_resource(_resource);
    struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_resource *resource = rb_resource->resource;
 
-   return pipe->is_resource_referenced(pipe,
-                                       resource,
-                                       face,
-                                       level);
+   mtx_lock(&rb_pipe->call_mutex);
+   pipe->flush(pipe, fence, flags);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 static struct pipe_sampler_view *
@@ -895,9 +1010,11 @@ rbug_context_create_sampler_view(struct pipe_context *_pipe,
    struct pipe_resource *resource = rb_resource->resource;
    struct pipe_sampler_view *result;
 
+   mtx_lock(&rb_pipe->call_mutex);
    result = pipe->create_sampler_view(pipe,
                                       resource,
                                       templ);
+   mtx_unlock(&rb_pipe->call_mutex);
 
    if (result)
       return rbug_sampler_view_create(rb_pipe, rb_resource, result);
@@ -912,53 +1029,70 @@ rbug_context_sampler_view_destroy(struct pipe_context *_pipe,
                              rbug_sampler_view(_view));
 }
 
-static struct pipe_transfer *
-rbug_context_get_transfer(struct pipe_context *_context,
-                          struct pipe_resource *_resource,
-                          struct pipe_subresource sr,
-                          unsigned usage,
-                          const struct pipe_box *box)
+static struct pipe_surface *
+rbug_context_create_surface(struct pipe_context *_pipe,
+                            struct pipe_resource *_resource,
+                            const struct pipe_surface *surf_tmpl)
 {
-   struct rbug_context *rb_pipe = rbug_context(_context);
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct rbug_resource *rb_resource = rbug_resource(_resource);
-   struct pipe_context *context = rb_pipe->pipe;
+   struct pipe_context *pipe = rb_pipe->pipe;
    struct pipe_resource *resource = rb_resource->resource;
-   struct pipe_transfer *result;
+   struct pipe_surface *result;
 
-   result = context->get_transfer(context,
-                                  resource,
-                                  sr,
-                                  usage,
-                                  box);
+   mtx_lock(&rb_pipe->call_mutex);
+   result = pipe->create_surface(pipe,
+                                 resource,
+                                 surf_tmpl);
+   mtx_unlock(&rb_pipe->call_mutex);
 
    if (result)
-      return rbug_transfer_create(rb_pipe, rb_resource, result);
+      return rbug_surface_create(rb_pipe, rb_resource, result);
    return NULL;
 }
 
 static void
-rbug_context_transfer_destroy(struct pipe_context *_pipe,
-                              struct pipe_transfer *_transfer)
+rbug_context_surface_destroy(struct pipe_context *_pipe,
+                             struct pipe_surface *_surface)
 {
-   rbug_transfer_destroy(rbug_context(_pipe),
-                             rbug_transfer(_transfer));
+   struct rbug_context *rb_pipe = rbug_context(_pipe);
+   struct rbug_surface *rb_surface = rbug_surface(_surface);
+
+   mtx_lock(&rb_pipe->call_mutex);
+   rbug_surface_destroy(rb_pipe,
+                        rb_surface);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
+
+
 static void *
 rbug_context_transfer_map(struct pipe_context *_context,
-                          struct pipe_transfer *_transfer)
+                          struct pipe_resource *_resource,
+                          unsigned level,
+                          unsigned usage,
+                          const struct pipe_box *box,
+                          struct pipe_transfer **transfer)
 {
    struct rbug_context *rb_pipe = rbug_context(_context);
-   struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
+   struct rbug_resource *rb_resource = rbug_resource(_resource);
    struct pipe_context *context = rb_pipe->pipe;
-   struct pipe_transfer *transfer = rb_transfer->transfer;
-
-   return context->transfer_map(context,
-                                transfer);
+   struct pipe_resource *resource = rb_resource->resource;
+   struct pipe_transfer *result;
+   void *map;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   map = context->transfer_map(context,
+                               resource,
+                               level,
+                               usage,
+                               box, &result);
+   mtx_unlock(&rb_pipe->call_mutex);
+
+   *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
+   return *transfer ? map : NULL;
 }
 
-
-
 static void
 rbug_context_transfer_flush_region(struct pipe_context *_context,
                                    struct pipe_transfer *_transfer,
@@ -969,9 +1103,11 @@ rbug_context_transfer_flush_region(struct pipe_context *_context,
    struct pipe_context *context = rb_pipe->pipe;
    struct pipe_transfer *transfer = rb_transfer->transfer;
 
+   mtx_lock(&rb_pipe->call_mutex);
    context->transfer_flush_region(context,
                                   transfer,
                                   box);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 
@@ -984,34 +1120,57 @@ rbug_context_transfer_unmap(struct pipe_context *_context,
    struct pipe_context *context = rb_pipe->pipe;
    struct pipe_transfer *transfer = rb_transfer->transfer;
 
+   mtx_lock(&rb_pipe->call_mutex);
    context->transfer_unmap(context,
                            transfer);
+   rbug_transfer_destroy(rb_pipe,
+                         rb_transfer);
+   mtx_unlock(&rb_pipe->call_mutex);
+}
+
+
+static void
+rbug_context_buffer_subdata(struct pipe_context *_context,
+                            struct pipe_resource *_resource,
+                            unsigned usage, unsigned offset,
+                            unsigned size, const void *data)
+{
+   struct rbug_context *rb_pipe = rbug_context(_context);
+   struct rbug_resource *rb_resource = rbug_resource(_resource);
+   struct pipe_context *context = rb_pipe->pipe;
+   struct pipe_resource *resource = rb_resource->resource;
+
+   mtx_lock(&rb_pipe->call_mutex);
+   context->buffer_subdata(context, resource, usage, offset, size, data);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 
 static void
-rbug_context_transfer_inline_write(struct pipe_context *_context,
-                                   struct pipe_resource *_resource,
-                                   struct pipe_subresource sr,
-                                   unsigned usage,
-                                   const struct pipe_box *box,
-                                   const void *data,
-                                   unsigned stride,
-                                   unsigned slice_stride)
+rbug_context_texture_subdata(struct pipe_context *_context,
+                             struct pipe_resource *_resource,
+                             unsigned level,
+                             unsigned usage,
+                             const struct pipe_box *box,
+                             const void *data,
+                             unsigned stride,
+                             unsigned layer_stride)
 {
    struct rbug_context *rb_pipe = rbug_context(_context);
    struct rbug_resource *rb_resource = rbug_resource(_resource);
    struct pipe_context *context = rb_pipe->pipe;
    struct pipe_resource *resource = rb_resource->resource;
 
-   context->transfer_inline_write(context,
-                                  resource,
-                                  sr,
-                                  usage,
-                                  box,
-                                  data,
-                                  stride,
-                                  slice_stride);
+   mtx_lock(&rb_pipe->call_mutex);
+   context->texture_subdata(context,
+                            resource,
+                            level,
+                            usage,
+                            box,
+                            data,
+                            stride,
+                            layer_stride);
+   mtx_unlock(&rb_pipe->call_mutex);
 }
 
 
@@ -1028,32 +1187,31 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    if (!rb_pipe)
       return NULL;
 
-   pipe_mutex_init(rb_pipe->draw_mutex);
-   pipe_condvar_init(rb_pipe->draw_cond);
-   pipe_mutex_init(rb_pipe->call_mutex);
-   pipe_mutex_init(rb_pipe->list_mutex);
+   (void) mtx_init(&rb_pipe->draw_mutex, mtx_plain);
+   cnd_init(&rb_pipe->draw_cond);
+   (void) mtx_init(&rb_pipe->call_mutex, mtx_plain);
+   (void) mtx_init(&rb_pipe->list_mutex, mtx_plain);
    make_empty_list(&rb_pipe->shaders);
 
-   rb_pipe->base.winsys = NULL;
    rb_pipe->base.screen = _screen;
    rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
    rb_pipe->base.draw = NULL;
+   rb_pipe->base.stream_uploader = pipe->stream_uploader;
+   rb_pipe->base.const_uploader = pipe->const_uploader;
 
    rb_pipe->base.destroy = rbug_destroy;
-   rb_pipe->base.draw_arrays = rbug_draw_arrays;
-   rb_pipe->base.draw_elements = rbug_draw_elements;
-   rb_pipe->base.draw_range_elements = rbug_draw_range_elements;
+   rb_pipe->base.draw_vbo = rbug_draw_vbo;
    rb_pipe->base.create_query = rbug_create_query;
    rb_pipe->base.destroy_query = rbug_destroy_query;
    rb_pipe->base.begin_query = rbug_begin_query;
    rb_pipe->base.end_query = rbug_end_query;
    rb_pipe->base.get_query_result = rbug_get_query_result;
+   rb_pipe->base.set_active_query_state = rbug_set_active_query_state;
    rb_pipe->base.create_blend_state = rbug_create_blend_state;
    rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
    rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
    rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
-   rb_pipe->base.bind_fragment_sampler_states = rbug_bind_fragment_sampler_states;
-   rb_pipe->base.bind_vertex_sampler_states = rbug_bind_vertex_sampler_states;
+   rb_pipe->base.bind_sampler_states = rbug_bind_sampler_states;
    rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
    rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
    rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
@@ -1079,30 +1237,38 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
    rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
    rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
-   rb_pipe->base.set_scissor_state = rbug_set_scissor_state;
-   rb_pipe->base.set_viewport_state = rbug_set_viewport_state;
-   rb_pipe->base.set_fragment_sampler_views = rbug_set_fragment_sampler_views;
-   rb_pipe->base.set_vertex_sampler_views = rbug_set_vertex_sampler_views;
+   rb_pipe->base.set_scissor_states = rbug_set_scissor_states;
+   rb_pipe->base.set_viewport_states = rbug_set_viewport_states;
+   rb_pipe->base.set_sampler_views = rbug_set_sampler_views;
    rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
    rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
+   rb_pipe->base.create_stream_output_target = rbug_create_stream_output_target;
+   rb_pipe->base.stream_output_target_destroy = rbug_stream_output_target_destroy;
+   rb_pipe->base.set_stream_output_targets = rbug_set_stream_output_targets;
    rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
+   rb_pipe->base.blit = rbug_blit;
+   rb_pipe->base.flush_resource = rbug_flush_resource;
    rb_pipe->base.clear = rbug_clear;
    rb_pipe->base.clear_render_target = rbug_clear_render_target;
    rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
    rb_pipe->base.flush = rbug_flush;
-   rb_pipe->base.is_resource_referenced = rbug_is_resource_referenced;
    rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
    rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
-   rb_pipe->base.get_transfer = rbug_context_get_transfer;
-   rb_pipe->base.transfer_destroy = rbug_context_transfer_destroy;
+   rb_pipe->base.create_surface = rbug_context_create_surface;
+   rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
    rb_pipe->base.transfer_map = rbug_context_transfer_map;
    rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
    rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
-   rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write;
+   rb_pipe->base.buffer_subdata = rbug_context_buffer_subdata;
+   rb_pipe->base.texture_subdata = rbug_context_texture_subdata;
 
    rb_pipe->pipe = pipe;
 
    rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
 
+   if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) {
+      rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE;
+   }
+
    return &rb_pipe->base;
 }