winsys/radeon: use the common job queue for multithreaded command submission v2
[mesa.git] / src / gallium / drivers / rbug / rbug_core.c
index 13aa95a59b7e210b529b6b8e6366123ef33637be..dedbc14e8d8c5a0d7ba6ec3c57f7c7db160116f5 100644 (file)
@@ -31,7 +31,7 @@
 #include "util/u_string.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
-#include "util/u_simple_list.h"
+#include "util/simple_list.h"
 #include "util/u_network.h"
 #include "os/os_time.h"
 
@@ -47,6 +47,9 @@
 #define U642VOID(x) ((void *)(unsigned long)(x))
 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
 
+#define container_of(ptr, type, field) \
+   (type*)((char*)ptr - offsetof(type, field))
+
 struct rbug_rbug
 {
    struct rbug_screen *rb_screen;
@@ -70,7 +73,7 @@ rbug_get_context_locked(struct rbug_screen *rb_screen, rbug_context_t ctx)
    struct rbug_list *ptr;
 
    foreach(ptr, &rb_screen->contexts) {
-      rb_context = (struct rbug_context *)((char*)ptr - offsetof(struct rbug_context, list));
+      rb_context = container_of(ptr, struct rbug_context, list);
       if (ctx == VOID2U64(rb_context))
          break;
       rb_context = NULL;
@@ -86,7 +89,7 @@ rbug_get_shader_locked(struct rbug_context *rb_context, rbug_shader_t shdr)
    struct rbug_list *ptr;
 
    foreach(ptr, &rb_context->shaders) {
-      tr_shdr = (struct rbug_shader *)((char*)ptr - offsetof(struct rbug_shader, list));
+      tr_shdr = container_of(ptr, struct rbug_shader, list);
       if (shdr == VOID2U64(tr_shdr))
          break;
       tr_shdr = NULL;
@@ -101,7 +104,8 @@ rbug_shader_create_locked(struct pipe_context *pipe,
                           struct tgsi_token *tokens)
 {
    void *state = NULL;
-   struct pipe_shader_state pss = { 0 };
+   struct pipe_shader_state pss;
+   memset(&pss, 0, sizeof(pss));
    pss.tokens = tokens;
 
    switch(rb_shader->type) {
@@ -181,7 +185,7 @@ rbug_texture_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    pipe_mutex_lock(rb_screen->list_mutex);
    texs = MALLOC(rb_screen->num_resources * sizeof(rbug_texture_t));
    foreach(ptr, &rb_screen->resources) {
-      tr_tex = (struct rbug_resource *)((char*)ptr - offsetof(struct rbug_resource, list));
+      tr_tex = container_of(ptr, struct rbug_resource, list);
       texs[i++] = VOID2U64(tr_tex);
    }
    pipe_mutex_unlock(rb_screen->list_mutex);
@@ -200,10 +204,11 @@ rbug_texture_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    struct rbug_proto_texture_info *gpti = (struct rbug_proto_texture_info *)header;
    struct rbug_list *ptr;
    struct pipe_resource *t;
+   unsigned num_layers;
 
    pipe_mutex_lock(rb_screen->list_mutex);
    foreach(ptr, &rb_screen->resources) {
-      tr_tex = (struct rbug_resource *)((char*)ptr - offsetof(struct rbug_resource, list));
+      tr_tex = container_of(ptr, struct rbug_resource, list);
       if (gpti->texture == VOID2U64(tr_tex))
          break;
       tr_tex = NULL;
@@ -215,11 +220,13 @@ rbug_texture_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    }
 
    t = tr_tex->resource;
+   num_layers = util_max_layer(t, 0) + 1;
+
    rbug_send_texture_info_reply(tr_rbug->con, serial,
                                t->target, t->format,
                                &t->width0, 1,
                                &t->height0, 1,
-                               &t->depth0, 1,
+                               &num_layers, 1,
                                util_format_get_blockwidth(t->format),
                                util_format_get_blockheight(t->format),
                                util_format_get_blocksize(t->format),
@@ -250,7 +257,7 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
 
    pipe_mutex_lock(rb_screen->list_mutex);
    foreach(ptr, &rb_screen->resources) {
-      tr_tex = (struct rbug_resource *)((char*)ptr - offsetof(struct rbug_resource, list));
+      tr_tex = container_of(ptr, struct rbug_resource, list);
       if (gptr->texture == VOID2U64(tr_tex))
          break;
       tr_tex = NULL;
@@ -262,12 +269,10 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    }
 
    tex = tr_tex->resource;
-   t = pipe_get_transfer(context, tex,
-                                gptr->face, gptr->level, gptr->zslice,
-                                PIPE_TRANSFER_READ,
-                                gptr->x, gptr->y, gptr->w, gptr->h);
-
-   map = context->transfer_map(context, t);
+   map = pipe_transfer_map(context, tex,
+                           gptr->level, gptr->face + gptr->zslice,
+                           PIPE_TRANSFER_READ,
+                           gptr->x, gptr->y, gptr->w, gptr->h, &t);
 
    rbug_send_texture_read_reply(tr_rbug->con, serial,
                                 t->resource->format,
@@ -276,12 +281,11 @@ rbug_texture_read(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
                                 util_format_get_blocksize(t->resource->format),
                                 (uint8_t*)map,
                                 t->stride * util_format_get_nblocksy(t->resource->format,
-                                                                    t->box.height),
+                                                                     t->box.height),
                                 t->stride,
                                 NULL);
 
    context->transfer_unmap(context, t);
-   context->transfer_destroy(context, t);
 
    pipe_mutex_unlock(rb_screen->list_mutex);
 
@@ -300,7 +304,7 @@ rbug_context_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    pipe_mutex_lock(rb_screen->list_mutex);
    ctxs = MALLOC(rb_screen->num_contexts * sizeof(rbug_context_t));
    foreach(ptr, &rb_screen->contexts) {
-      rb_context = (struct rbug_context *)((char*)ptr - offsetof(struct rbug_context, list));
+      rb_context = container_of(ptr, struct rbug_context, list);
       ctxs[i++] = VOID2U64(rb_context);
    }
    pipe_mutex_unlock(rb_screen->list_mutex);
@@ -319,8 +323,8 @@ rbug_context_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    struct rbug_screen *rb_screen = tr_rbug->rb_screen;
    struct rbug_context *rb_context = NULL;
    rbug_texture_t cbufs[PIPE_MAX_COLOR_BUFS];
-   rbug_texture_t texs[PIPE_MAX_SAMPLERS];
-   int i;
+   rbug_texture_t texs[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   unsigned i;
 
    pipe_mutex_lock(rb_screen->list_mutex);
    rb_context = rbug_get_context_locked(rb_screen, info->context);
@@ -337,12 +341,13 @@ rbug_context_info(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_
    for (i = 0; i < rb_context->curr.nr_cbufs; i++)
       cbufs[i] = VOID2U64(rb_context->curr.cbufs[i]);
 
-   for (i = 0; i < rb_context->curr.num_sampler_views; i++)
-      texs[i] = VOID2U64(rb_context->curr.sampler_views[i]);
+   /* XXX what about vertex/geometry shader texture views? */
+   for (i = 0; i < rb_context->curr.num_views[PIPE_SHADER_FRAGMENT]; i++)
+      texs[i] = VOID2U64(rb_context->curr.texs[PIPE_SHADER_FRAGMENT][i]);
 
    rbug_send_context_info_reply(tr_rbug->con, serial,
-                                VOID2U64(rb_context->curr.vs), VOID2U64(rb_context->curr.fs),
-                                texs, rb_context->curr.num_sampler_views,
+                                VOID2U64(rb_context->curr.shader[PIPE_SHADER_VERTEX]), VOID2U64(rb_context->curr.shader[PIPE_SHADER_FRAGMENT]),
+                                texs, rb_context->curr.num_views[PIPE_SHADER_FRAGMENT],
                                 cbufs, rb_context->curr.nr_cbufs,
                                 VOID2U64(rb_context->curr.zsbuf),
                                 rb_context->draw_blocker, rb_context->draw_blocked, NULL);
@@ -404,9 +409,7 @@ rbug_context_draw_step(struct rbug_rbug *tr_rbug, struct rbug_header *header, ui
    }
    pipe_mutex_unlock(rb_context->draw_mutex);
 
-#ifdef PIPE_THREAD_HAVE_CONDVAR
    pipe_condvar_broadcast(rb_context->draw_cond);
-#endif
 
    pipe_mutex_unlock(rb_screen->list_mutex);
 
@@ -439,9 +442,7 @@ rbug_context_draw_unblock(struct rbug_rbug *tr_rbug, struct rbug_header *header,
    rb_context->draw_blocker &= ~unblock->unblock;
    pipe_mutex_unlock(rb_context->draw_mutex);
 
-#ifdef PIPE_THREAD_HAVE_CONDVAR
    pipe_condvar_broadcast(rb_context->draw_cond);
-#endif
 
    pipe_mutex_unlock(rb_screen->list_mutex);
 
@@ -465,17 +466,15 @@ rbug_context_draw_rule(struct rbug_rbug *tr_rbug, struct rbug_header *header, ui
    }
 
    pipe_mutex_lock(rb_context->draw_mutex);
-   rb_context->draw_rule.vs = U642VOID(rule->vertex);
-   rb_context->draw_rule.fs = U642VOID(rule->fragment);
-   rb_context->draw_rule.sampler_view = U642VOID(rule->texture);
+   rb_context->draw_rule.shader[PIPE_SHADER_VERTEX] = U642VOID(rule->vertex);
+   rb_context->draw_rule.shader[PIPE_SHADER_FRAGMENT] = U642VOID(rule->fragment);
+   rb_context->draw_rule.texture = U642VOID(rule->texture);
    rb_context->draw_rule.surf = U642VOID(rule->surface);
    rb_context->draw_rule.blocker = rule->block;
    rb_context->draw_blocker |= RBUG_BLOCK_RULE;
    pipe_mutex_unlock(rb_context->draw_mutex);
 
-#ifdef PIPE_THREAD_HAVE_CONDVAR
    pipe_condvar_broadcast(rb_context->draw_cond);
-#endif
 
    pipe_mutex_unlock(rb_screen->list_mutex);
 
@@ -501,7 +500,7 @@ rbug_context_flush(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32
    /* protect the pipe context */
    pipe_mutex_lock(rb_context->call_mutex);
 
-   rb_context->pipe->flush(rb_context->pipe, flush->flags, NULL);
+   rb_context->pipe->flush(rb_context->pipe, NULL, 0);
 
    pipe_mutex_unlock(rb_context->call_mutex);
    pipe_mutex_unlock(rb_screen->list_mutex);
@@ -532,7 +531,7 @@ rbug_shader_list(struct rbug_rbug *tr_rbug, struct rbug_header *header, uint32_t
    pipe_mutex_lock(rb_context->list_mutex);
    shdrs = MALLOC(rb_context->num_shaders * sizeof(rbug_shader_t));
    foreach(ptr, &rb_context->shaders) {
-      tr_shdr = (struct rbug_shader *)((char*)ptr - offsetof(struct rbug_shader, list));
+      tr_shdr = container_of(ptr, struct rbug_shader, list);
       shdrs[i++] = VOID2U64(tr_shdr);
    }
 
@@ -667,7 +666,7 @@ rbug_shader_replace(struct rbug_rbug *tr_rbug, struct rbug_header *header)
    /* remove old replaced shader */
    if (tr_shdr->replaced_shader) {
       /* if this shader is bound rebind the original shader */
-      if (rb_context->curr.fs == tr_shdr || rb_context->curr.vs == tr_shdr)
+      if (rb_context->curr.shader[PIPE_SHADER_FRAGMENT] == tr_shdr || rb_context->curr.shader[PIPE_SHADER_VERTEX] == tr_shdr)
          rbug_shader_bind_locked(pipe, tr_shdr, tr_shdr->shader);
 
       FREE(tr_shdr->replaced_tokens);
@@ -689,7 +688,7 @@ rbug_shader_replace(struct rbug_rbug *tr_rbug, struct rbug_header *header)
       goto err;
 
    /* bind new shader if the shader is currently a bound */
-   if (rb_context->curr.fs == tr_shdr || rb_context->curr.vs == tr_shdr)
+   if (rb_context->curr.shader[PIPE_SHADER_FRAGMENT] == tr_shdr || rb_context->curr.shader[PIPE_SHADER_VERTEX] == tr_shdr)
       rbug_shader_bind_locked(pipe, tr_shdr, state);
 
    /* save state */
@@ -814,7 +813,7 @@ PIPE_THREAD_ROUTINE(rbug_thread, void_tr_rbug)
 
    if (s < 0) {
       debug_printf("rbug_rbug - failed to listen\n");
-      return NULL;
+      return 0;
    }
 
    u_socket_block(s, false);
@@ -840,7 +839,7 @@ PIPE_THREAD_ROUTINE(rbug_thread, void_tr_rbug)
 
    u_socket_stop();
 
-   return NULL;
+   return 0;
 }
 
 /**********************************************************