ddebug: handle get_query_result_resource as a GPU call
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 27 Jul 2017 09:59:20 +0000 (11:59 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 2 Aug 2017 07:46:36 +0000 (09:46 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/ddebug/dd_context.c
src/gallium/drivers/ddebug/dd_draw.c
src/gallium/drivers/ddebug/dd_pipe.h

index 6b1ddc9d46be72a7f223e190b64fc7758825a521..5b0b27e006aec484bf04f581080e4f43a1536d5c 100644 (file)
@@ -45,22 +45,6 @@ safe_memcpy(void *dst, const void *src, size_t size)
  * queries
  */
 
-static struct dd_query *
-dd_query(struct pipe_query *query)
-{
-   return (struct dd_query *)query;
-}
-
-static struct pipe_query *
-dd_query_unwrap(struct pipe_query *query)
-{
-   if (query) {
-      return dd_query(query)->query;
-   } else {
-      return NULL;
-   }
-}
-
 static struct pipe_query *
 dd_context_create_query(struct pipe_context *_pipe, unsigned query_type,
                         unsigned index)
@@ -150,21 +134,6 @@ dd_context_get_query_result(struct pipe_context *_pipe,
    return pipe->get_query_result(pipe, dd_query_unwrap(query), wait, result);
 }
 
-static void
-dd_context_get_query_result_resource(struct pipe_context *_pipe,
-                                     struct pipe_query *query,
-                                     boolean wait,
-                                     enum pipe_query_value_type result_type,
-                                     int index,
-                                     struct pipe_resource *resource,
-                                     unsigned offset)
-{
-   struct pipe_context *pipe = dd_context(_pipe)->pipe;
-
-   pipe->get_query_result_resource(pipe, dd_query_unwrap(query), wait,
-                                   result_type, index, resource, offset);
-}
-
 static void
 dd_context_set_active_query_state(struct pipe_context *_pipe, boolean enable)
 {
@@ -847,7 +816,6 @@ dd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe)
    CTX_INIT(begin_query);
    CTX_INIT(end_query);
    CTX_INIT(get_query_result);
-   CTX_INIT(get_query_result_resource);
    CTX_INIT(set_active_query_state);
    CTX_INIT(create_blend_state);
    CTX_INIT(bind_blend_state);
index 81a796873f1f4a7ebcaa8c49e7de9d869533cced..ae8f99bf2b49b81c2ccb04e605add5e17dcac727 100644 (file)
@@ -153,6 +153,12 @@ util_dump_uint(FILE *f, unsigned i)
    fprintf(f, "%u", i);
 }
 
+static void
+util_dump_int(FILE *f, int i)
+{
+   fprintf(f, "%d", i);
+}
+
 static void
 util_dump_hex(FILE *f, unsigned i)
 {
@@ -418,6 +424,18 @@ dd_dump_generate_mipmap(struct dd_draw_state *dstate, FILE *f)
    /* TODO */
 }
 
+static void
+dd_dump_get_query_result_resource(struct call_get_query_result_resource *info, FILE *f)
+{
+   fprintf(f, "%s:\n", __func__ + 8);
+   DUMP_M(query_type, info, query_type);
+   DUMP_M(uint, info, wait);
+   DUMP_M(query_value_type, info, result_type);
+   DUMP_M(int, info, index);
+   DUMP_M(resource, info, resource);
+   DUMP_M(uint, info, offset);
+}
+
 static void
 dd_dump_flush_resource(struct dd_draw_state *dstate, struct pipe_resource *res,
                        FILE *f)
@@ -525,6 +543,9 @@ dd_dump_call(FILE *f, struct dd_draw_state *state, struct dd_call *call)
    case CALL_GENERATE_MIPMAP:
       dd_dump_generate_mipmap(state, f);
       break;
+   case CALL_GET_QUERY_RESULT_RESOURCE:
+      dd_dump_get_query_result_resource(&call->info.get_query_result_resource, f);
+      break;
    }
 }
 
@@ -648,6 +669,9 @@ dd_unreference_copy_of_call(struct dd_call *dst)
    case CALL_GENERATE_MIPMAP:
       pipe_resource_reference(&dst->info.generate_mipmap.res, NULL);
       break;
+   case CALL_GET_QUERY_RESULT_RESOURCE:
+      pipe_resource_reference(&dst->info.get_query_result_resource.resource, NULL);
+      break;
    }
 }
 
@@ -725,6 +749,12 @@ dd_copy_call(struct dd_call *dst, struct dd_call *src)
                               src->info.generate_mipmap.res);
       dst->info.generate_mipmap = src->info.generate_mipmap;
       break;
+   case CALL_GET_QUERY_RESULT_RESOURCE:
+      pipe_resource_reference(&dst->info.get_query_result_resource.resource,
+                              src->info.get_query_result_resource.resource);
+      dst->info.get_query_result_resource = src->info.get_query_result_resource;
+      dst->info.get_query_result_resource.query = NULL;
+      break;
    }
 }
 
@@ -1286,6 +1316,39 @@ dd_context_generate_mipmap(struct pipe_context *_pipe,
    return result;
 }
 
+static void
+dd_context_get_query_result_resource(struct pipe_context *_pipe,
+                                     struct pipe_query *query,
+                                     boolean wait,
+                                     enum pipe_query_value_type result_type,
+                                     int index,
+                                     struct pipe_resource *resource,
+                                     unsigned offset)
+{
+   struct dd_context *dctx = dd_context(_pipe);
+   struct dd_query *dquery = dd_query(query);
+   struct pipe_context *pipe = dctx->pipe;
+   struct dd_call call;
+
+   call.type = CALL_GET_QUERY_RESULT_RESOURCE;
+   call.info.get_query_result_resource.query = query;
+   call.info.get_query_result_resource.wait = wait;
+   call.info.get_query_result_resource.result_type = result_type;
+   call.info.get_query_result_resource.index = index;
+   call.info.get_query_result_resource.resource = resource;
+   call.info.get_query_result_resource.offset = offset;
+
+   /* In pipelined mode, the query may be deleted by the time we need to
+    * print it.
+    */
+   call.info.get_query_result_resource.query_type = dquery->type;
+
+   dd_before_draw(dctx);
+   pipe->get_query_result_resource(pipe, dquery->query, wait,
+                                   result_type, index, resource, offset);
+   dd_after_draw(dctx, &call);
+}
+
 static void
 dd_context_flush_resource(struct pipe_context *_pipe,
                           struct pipe_resource *resource)
@@ -1416,4 +1479,5 @@ dd_init_draw_functions(struct dd_context *dctx)
    CTX_INIT(clear_texture);
    CTX_INIT(flush_resource);
    CTX_INIT(generate_mipmap);
+   CTX_INIT(get_query_result_resource);
 }
index caad45b723ca6a06fb877e24fda8b1d7320d95cf..e21b5fee0864693f5882652777782b894dcbd85a 100644 (file)
@@ -66,6 +66,7 @@ enum call_type
    CALL_CLEAR_RENDER_TARGET,
    CALL_CLEAR_DEPTH_STENCIL,
    CALL_GENERATE_MIPMAP,
+   CALL_GET_QUERY_RESULT_RESOURCE,
 };
 
 struct call_resource_copy_region
@@ -109,6 +110,16 @@ struct call_draw_info {
    struct pipe_draw_indirect_info indirect;
 };
 
+struct call_get_query_result_resource {
+   struct pipe_query *query;
+   enum pipe_query_type query_type;
+   boolean wait;
+   enum pipe_query_value_type result_type;
+   int index;
+   struct pipe_resource *resource;
+   unsigned offset;
+};
+
 struct dd_call
 {
    enum call_type type;
@@ -122,6 +133,7 @@ struct dd_call
       struct call_clear clear;
       struct call_clear_buffer clear_buffer;
       struct call_generate_mipmap generate_mipmap;
+      struct call_get_query_result_resource get_query_result_resource;
    } info;
 };
 
@@ -272,6 +284,22 @@ dd_screen(struct pipe_screen *screen)
    return (struct dd_screen*)screen;
 }
 
+static inline struct dd_query *
+dd_query(struct pipe_query *query)
+{
+   return (struct dd_query *)query;
+}
+
+static inline struct pipe_query *
+dd_query_unwrap(struct pipe_query *query)
+{
+   if (query) {
+      return dd_query(query)->query;
+   } else {
+      return NULL;
+   }
+}
+
 
 #define CTX_INIT(_member) \
    dctx->base._member = dctx->pipe->_member ? dd_context_##_member : NULL