rbug: update data structures, functions for future changes
[mesa.git] / src / gallium / drivers / rbug / rbug_context.c
index 6690c0208bd4cdb4cf078beec3db881e83595280..59d5af9590a82b48fe69c86587a3bfec1e364c0f 100644 (file)
@@ -62,17 +62,21 @@ rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
               (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
       int 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;
@@ -81,12 +85,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 < Elements(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;
+               }
             }
          }
       }
@@ -116,9 +121,10 @@ rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
    rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
 
    pipe_mutex_lock(rb_pipe->call_mutex);
-   if (!(rb_pipe->curr.fs && rb_pipe->curr.fs->disabled) &&
-       !(rb_pipe->curr.gs && rb_pipe->curr.gs->disabled) &&
-       !(rb_pipe->curr.vs && rb_pipe->curr.vs->disabled))
+   /* 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);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 
@@ -182,7 +188,7 @@ 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;
@@ -412,7 +418,7 @@ rbug_bind_fs_state(struct pipe_context *_pipe,
    pipe_mutex_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);
 
@@ -460,7 +466,7 @@ rbug_bind_vs_state(struct pipe_context *_pipe,
    pipe_mutex_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);
 
@@ -508,7 +514,7 @@ rbug_bind_gs_state(struct pipe_context *_pipe,
    pipe_mutex_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);
 
@@ -614,24 +620,23 @@ static void
 rbug_set_constant_buffer(struct pipe_context *_pipe,
                          uint shader,
                          uint index,
-                         struct pipe_resource *_resource)
+                         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);
    }
 
    pipe_mutex_lock(rb_pipe->call_mutex);
    pipe->set_constant_buffer(pipe,
                              shader,
                              index,
-                             resource);
+                             _cb ? &cb : NULL);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
 
@@ -714,9 +719,11 @@ rbug_set_viewport_state(struct pipe_context *_pipe,
 }
 
 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,
+                       unsigned 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;
@@ -724,25 +731,36 @@ rbug_set_fragment_sampler_views(struct pipe_context *_pipe,
    struct pipe_sampler_view **views = NULL;
    unsigned i;
 
+   assert(start == 0); /* XXX fix */
+
    /* must protect curr status */
    pipe_mutex_lock(rb_pipe->call_mutex);
 
-   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));
+   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_fs_views = num;
+      rb_pipe->curr.num_views[shader] = 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);
+         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_fragment_sampler_views(pipe, num, views);
+   switch (shader) {
+   case PIPE_SHADER_VERTEX:
+      pipe->set_vertex_sampler_views(pipe, num, views);
+      break;
+   case PIPE_SHADER_FRAGMENT:
+      pipe->set_fragment_sampler_views(pipe, num, views);
+      break;
+   default:
+      assert(0);
+   }
 
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
@@ -752,33 +770,15 @@ 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 */
-   pipe_mutex_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));
-   memset(unwrapped_views, 0, sizeof(unwrapped_views));
-
-   if (_views) {
-      rb_pipe->curr.num_vs_views = 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);
-         unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
-      }
-      views = unwrapped_views;
-   }
-
-   pipe->set_vertex_sampler_views(pipe, num, views);
+   rbug_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, 0, num, _views);
+}
 
-   pipe_mutex_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(_pipe, PIPE_SHADER_FRAGMENT, 0, num, _views);
 }
 
 static void
@@ -1140,21 +1140,6 @@ rbug_context_transfer_inline_write(struct pipe_context *_context,
 }
 
 
-static void rbug_redefine_user_buffer(struct pipe_context *_context,
-                                      struct pipe_resource *_resource,
-                                      unsigned offset, unsigned size)
-{
-   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;
-
-   pipe_mutex_lock(rb_pipe->call_mutex);
-   context->redefine_user_buffer(context, resource, offset, size);
-   pipe_mutex_unlock(rb_pipe->call_mutex);
-}
-
-
 struct pipe_context *
 rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
 {
@@ -1174,7 +1159,6 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    pipe_mutex_init(rb_pipe->list_mutex);
    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;
@@ -1239,11 +1223,14 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    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.redefine_user_buffer = rbug_redefine_user_buffer;
 
    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;
 }