gallium/util: replace pipe_condvar_wait() with cnd_wait()
[mesa.git] / src / gallium / drivers / rbug / rbug_context.c
index 0e7badb1d0fe7abe36cb4311a11846b53982dcd5..e34278e64ff37d66d24e236c0a53674a1784ac86 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;
 
-   remove_from_list(&rb_pipe->list);
+   rbug_screen_remove_from_list(rb_screen, contexts, rb_pipe);
+
    pipe_mutex_lock(rb_pipe->call_mutex);
    pipe->destroy(pipe);
    rb_pipe->pipe = NULL;
@@ -85,7 +87,7 @@ 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 (sh = 0; sh < Elements(rb_pipe->curr.num_views); sh++) {
+         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;
@@ -106,7 +108,7 @@ 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);
    }
 
 }
@@ -134,15 +136,19 @@ rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
 
 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;
+   struct pipe_query *query;
 
    pipe_mutex_lock(rb_pipe->call_mutex);
-   return pipe->create_query(pipe,
-                             query_type);
+   query = pipe->create_query(pipe,
+                              query_type,
+                              index);
    pipe_mutex_unlock(rb_pipe->call_mutex);
+   return query;
 }
 
 static void
@@ -158,30 +164,34 @@ rbug_destroy_query(struct pipe_context *_pipe,
    pipe_mutex_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_mutex_lock(rb_pipe->call_mutex);
-   pipe->begin_query(pipe,
-                     query);
+   ret = pipe->begin_query(pipe, query);
    pipe_mutex_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;
 
    pipe_mutex_lock(rb_pipe->call_mutex);
-   pipe->end_query(pipe,
-                   query);
+   ret = pipe->end_query(pipe,
+                         query);
    pipe_mutex_unlock(rb_pipe->call_mutex);
+
+   return ret;
 }
 
 static boolean
@@ -204,6 +214,17 @@ rbug_get_query_result(struct pipe_context *_pipe,
    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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   pipe->set_active_query_state(pipe, enable);
+   pipe_mutex_unlock(rb_pipe->call_mutex);
+}
+
 static void *
 rbug_create_blend_state(struct pipe_context *_pipe,
                         const struct pipe_blend_state *blend)
@@ -263,7 +284,8 @@ rbug_create_sampler_state(struct pipe_context *_pipe,
 }
 
 static void
-rbug_bind_sampler_states(struct pipe_context *_pipe, unsigned shader,
+rbug_bind_sampler_states(struct pipe_context *_pipe,
+                         enum pipe_shader_type shader,
                          unsigned start, unsigned count,
                          void **samplers)
 {
@@ -603,7 +625,7 @@ static void
 rbug_set_constant_buffer(struct pipe_context *_pipe,
                          uint shader,
                          uint index,
-                         struct pipe_constant_buffer *_cb)
+                         const struct pipe_constant_buffer *_cb)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
@@ -705,7 +727,7 @@ rbug_set_viewport_states(struct pipe_context *_pipe,
 
 static void
 rbug_set_sampler_views(struct pipe_context *_pipe,
-                       unsigned shader,
+                       enum pipe_shader_type shader,
                        unsigned start,
                        unsigned num,
                        struct pipe_sampler_view **_views)
@@ -754,7 +776,7 @@ rbug_set_vertex_buffers(struct pipe_context *_pipe,
 
    pipe_mutex_lock(rb_pipe->call_mutex);
 
-   if (num_buffers) {
+   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);
@@ -799,6 +821,49 @@ rbug_set_sample_mask(struct pipe_context *_pipe,
    pipe_mutex_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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   target = pipe->create_stream_output_target(pipe, res, buffer_offset,
+                                              buffer_size);
+   pipe_mutex_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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   pipe->stream_output_target_destroy(pipe, target);
+   pipe_mutex_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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
+   pipe_mutex_unlock(rb_pipe->call_mutex);
+}
+
 static void
 rbug_resource_copy_region(struct pipe_context *_pipe,
                           struct pipe_resource *_dst,
@@ -830,6 +895,26 @@ rbug_resource_copy_region(struct pipe_context *_pipe,
    pipe_mutex_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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   pipe->blit(pipe, &blit_info);
+   pipe_mutex_unlock(rb_pipe->call_mutex);
+}
+
 static void
 rbug_flush_resource(struct pipe_context *_pipe,
                     struct pipe_resource *_res)
@@ -868,7 +953,8 @@ rbug_clear_render_target(struct pipe_context *_pipe,
                          struct pipe_surface *_dst,
                          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);
@@ -882,7 +968,8 @@ rbug_clear_render_target(struct pipe_context *_pipe,
                              dstx,
                              dsty,
                              width,
-                             height);
+                             height,
+                             render_condition_enabled);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
 
@@ -893,7 +980,8 @@ 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);
@@ -909,7 +997,8 @@ rbug_clear_depth_stencil(struct pipe_context *_pipe,
                              dstx,
                              dsty,
                              width,
-                             height);
+                             height,
+                             render_condition_enabled);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
 
@@ -1057,14 +1146,31 @@ rbug_context_transfer_unmap(struct pipe_context *_context,
 
 
 static void
-rbug_context_transfer_inline_write(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)
+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;
+
+   pipe_mutex_lock(rb_pipe->call_mutex);
+   context->buffer_subdata(context, resource, usage, offset, size, data);
+   pipe_mutex_unlock(rb_pipe->call_mutex);
+}
+
+
+static void
+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);
@@ -1072,14 +1178,14 @@ rbug_context_transfer_inline_write(struct pipe_context *_context,
    struct pipe_resource *resource = rb_resource->resource;
 
    pipe_mutex_lock(rb_pipe->call_mutex);
-   context->transfer_inline_write(context,
-                                  resource,
-                                  level,
-                                  usage,
-                                  box,
-                                  data,
-                                  stride,
-                                  layer_stride);
+   context->texture_subdata(context,
+                            resource,
+                            level,
+                            usage,
+                            box,
+                            data,
+                            stride,
+                            layer_stride);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
 
@@ -1098,7 +1204,7 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
       return NULL;
 
    pipe_mutex_init(rb_pipe->draw_mutex);
-   pipe_condvar_init(rb_pipe->draw_cond);
+   cnd_init(&rb_pipe->draw_cond);
    pipe_mutex_init(rb_pipe->call_mutex);
    pipe_mutex_init(rb_pipe->list_mutex);
    make_empty_list(&rb_pipe->shaders);
@@ -1106,6 +1212,8 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    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_vbo = rbug_draw_vbo;
@@ -1114,6 +1222,7 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    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;
@@ -1150,7 +1259,11 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
    rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
    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;
@@ -1163,7 +1276,8 @@ rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    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;