[Mesa-dev] [PATCH 3/5] nvc0: move SW queries to nvc0_query_sw.c/h files

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Oct 5 12:27:27 PDT 2015


Loosely based on freedreno driver.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/gallium/drivers/nouveau/Makefile.sources     |  2 +
 src/gallium/drivers/nouveau/nvc0/nvc0_query.c    | 31 ++++----
 src/gallium/drivers/nouveau/nvc0/nvc0_query.h    | 56 +++------------
 src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c | 92 ++++++++++++++++++++++++
 src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.h | 61 ++++++++++++++++
 5 files changed, 178 insertions(+), 64 deletions(-)
 create mode 100644 src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c
 create mode 100644 src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.h

diff --git a/src/gallium/drivers/nouveau/Makefile.sources b/src/gallium/drivers/nouveau/Makefile.sources
index 350837c..0e1cb19 100644
--- a/src/gallium/drivers/nouveau/Makefile.sources
+++ b/src/gallium/drivers/nouveau/Makefile.sources
@@ -152,6 +152,8 @@ NVC0_C_SOURCES := \
 	nvc0/nvc0_program.h \
 	nvc0/nvc0_query.c \
 	nvc0/nvc0_query.h \
+	nvc0/nvc0_query_sw.c \
+	nvc0/nvc0_query_sw.h \
 	nvc0/nvc0_resource.c \
 	nvc0/nvc0_resource.h \
 	nvc0/nvc0_screen.c \
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_query.c b/src/gallium/drivers/nouveau/nvc0/nvc0_query.c
index 69e9cdb..349140c 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_query.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query.c
@@ -26,6 +26,7 @@
 
 #include "nvc0/nvc0_context.h"
 #include "nvc0/nvc0_query.h"
+#include "nvc0/nvc0_query_sw.h"
 
 #include "nv_object.xml.h"
 #include "nvc0/nve4_compute.xml.h"
@@ -52,16 +53,16 @@ nvc0_query_allocate(struct nvc0_context *nvc0, struct nvc0_query *q, int size)
 
    if (q->bo) {
       nouveau_bo_ref(NULL, &q->bo);
-      if (q->u.mm) {
+      if (q->mm) {
          if (q->state == NVC0_QUERY_STATE_READY)
-            nouveau_mm_free(q->u.mm);
+            nouveau_mm_free(q->mm);
          else
             nouveau_fence_work(screen->base.fence.current,
-                               nouveau_mm_free_work, q->u.mm);
+                               nouveau_mm_free_work, q->mm);
       }
    }
    if (size) {
-      q->u.mm = nouveau_mm_allocate(screen->base.mm_GART, size, &q->bo, &q->base);
+      q->mm = nouveau_mm_allocate(screen->base.mm_GART, size, &q->bo, &q->base);
       if (!q->bo)
          return false;
       q->offset = q->base;
@@ -91,6 +92,10 @@ nvc0_query_create(struct pipe_context *pipe, unsigned type, unsigned index)
    struct nvc0_query *q;
    unsigned space = NVC0_QUERY_ALLOC_SPACE;
 
+   q = nvc0_sw_create_query(nvc0, type, index);
+   if (q)
+      return (struct pipe_query *)q;
+
    q = CALLOC_STRUCT(nvc0_query);
    if (!q)
       return NULL;
@@ -126,14 +131,6 @@ nvc0_query_create(struct pipe_context *pipe, unsigned type, unsigned index)
       space = 16;
       break;
    default:
-#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
-      if (type >= NVC0_QUERY_DRV_STAT(0) && type <= NVC0_QUERY_DRV_STAT_LAST) {
-         space = 0;
-         q->is64bit = true;
-         q->index = type - NVC0_QUERY_DRV_STAT(0);
-         break;
-      } else
-#endif
       if (nvc0->screen->base.device->drm_version >= 0x01000101) {
          if (type >= NVE4_HW_SM_QUERY(0) && type <= NVE4_HW_SM_QUERY_LAST) {
             /* for each MP:
@@ -297,10 +294,7 @@ nvc0_query_begin(struct pipe_context *pipe, struct pipe_query *pq)
 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
       if (q->type >= NVC0_QUERY_DRV_STAT(0) &&
           q->type <= NVC0_QUERY_DRV_STAT_LAST) {
-         if (q->index >= 5)
-            q->u.value = nvc0->screen->base.stats.v[q->index];
-         else
-            q->u.value = 0;
+         return q->funcs->begin_query(nvc0, q);
       } else
 #endif
       if ((q->type >= NVE4_HW_SM_QUERY(0) && q->type <= NVE4_HW_SM_QUERY_LAST) ||
@@ -384,7 +378,7 @@ nvc0_query_end(struct pipe_context *pipe, struct pipe_query *pq)
 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
       if (q->type >= NVC0_QUERY_DRV_STAT(0) &&
           q->type <= NVC0_QUERY_DRV_STAT_LAST) {
-         q->u.value = nvc0->screen->base.stats.v[q->index] - q->u.value;
+         q->funcs->end_query(nvc0, q);
          return;
       } else
 #endif
@@ -425,8 +419,7 @@ nvc0_query_result(struct pipe_context *pipe, struct pipe_query *pq,
 #ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
    if (q->type >= NVC0_QUERY_DRV_STAT(0) &&
        q->type <= NVC0_QUERY_DRV_STAT_LAST) {
-      res64[0] = q->u.value;
-      return true;
+      return q->funcs->get_query_result(nvc0, q, wait, result);
    } else
 #endif
    if ((q->type >= NVE4_HW_SM_QUERY(0) && q->type <= NVE4_HW_SM_QUERY_LAST) ||
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_query.h b/src/gallium/drivers/nouveau/nvc0/nvc0_query.h
index 65858cf..c37c80f 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_query.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query.h
@@ -9,8 +9,18 @@
 #define NVC0_QUERY_TFB_BUFFER_OFFSET (PIPE_QUERY_TYPES + 0)
 
 struct nvc0_context;
+struct nvc0_query;
+
+struct nvc0_query_funcs {
+   void (*destroy_query)(struct nvc0_context *, struct nvc0_query *);
+   boolean (*begin_query)(struct nvc0_context *, struct nvc0_query *);
+   void (*end_query)(struct nvc0_context *, struct nvc0_query *);
+   boolean (*get_query_result)(struct nvc0_context *, struct nvc0_query *,
+                               boolean, union pipe_query_result *);
+};
 
 struct nvc0_query {
+   const struct nvc0_query_funcs *funcs;
    uint32_t *data;
    uint16_t type;
    uint16_t index;
@@ -23,10 +33,7 @@ struct nvc0_query {
    boolean is64bit;
    uint8_t rotate;
    int nesting; /* only used for occlusion queries */
-   union {
-      struct nouveau_mm_allocation *mm;
-      uint64_t value;
-   } u;
+   struct nouveau_mm_allocation *mm;
    struct nouveau_fence *fence;
 };
 
@@ -139,47 +146,6 @@ enum nvc0_pm_queries
    NVC0_HW_SM_QUERY_COUNT
 };
 
-/*
- * Driver statistics queries:
- */
-#define NVC0_QUERY_DRV_STAT(i)    (PIPE_QUERY_DRIVER_SPECIFIC + 1024 + (i))
-#define NVC0_QUERY_DRV_STAT_LAST   NVC0_QUERY_DRV_STAT(NVC0_QUERY_DRV_STAT_COUNT - 1)
-enum nvc0_drv_stats_queries
-{
-#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
-   NVC0_QUERY_DRV_STAT_TEX_OBJECT_CURRENT_COUNT = 0,
-   NVC0_QUERY_DRV_STAT_TEX_OBJECT_CURRENT_BYTES,
-   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_COUNT,
-   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_BYTES_VID,
-   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_BYTES_SYS,
-   NVC0_QUERY_DRV_STAT_TEX_TRANSFERS_READ,
-   NVC0_QUERY_DRV_STAT_TEX_TRANSFERS_WRITE,
-   NVC0_QUERY_DRV_STAT_TEX_COPY_COUNT,
-   NVC0_QUERY_DRV_STAT_TEX_BLIT_COUNT,
-   NVC0_QUERY_DRV_STAT_TEX_CACHE_FLUSH_COUNT,
-   NVC0_QUERY_DRV_STAT_BUF_TRANSFERS_READ,
-   NVC0_QUERY_DRV_STAT_BUF_TRANSFERS_WRITE,
-   NVC0_QUERY_DRV_STAT_BUF_READ_BYTES_STAGING_VID,
-   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_DIRECT,
-   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_STAGING_VID,
-   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_STAGING_SYS,
-   NVC0_QUERY_DRV_STAT_BUF_COPY_BYTES,
-   NVC0_QUERY_DRV_STAT_BUF_NON_KERNEL_FENCE_SYNC_COUNT,
-   NVC0_QUERY_DRV_STAT_ANY_NON_KERNEL_FENCE_SYNC_COUNT,
-   NVC0_QUERY_DRV_STAT_QUERY_SYNC_COUNT,
-   NVC0_QUERY_DRV_STAT_GPU_SERIALIZE_COUNT,
-   NVC0_QUERY_DRV_STAT_DRAW_CALLS_ARRAY,
-   NVC0_QUERY_DRV_STAT_DRAW_CALLS_INDEXED,
-   NVC0_QUERY_DRV_STAT_DRAW_CALLS_FALLBACK_COUNT,
-   NVC0_QUERY_DRV_STAT_USER_BUFFER_UPLOAD_BYTES,
-   NVC0_QUERY_DRV_STAT_CONSTBUF_UPLOAD_COUNT,
-   NVC0_QUERY_DRV_STAT_CONSTBUF_UPLOAD_BYTES,
-   NVC0_QUERY_DRV_STAT_PUSHBUF_COUNT,
-   NVC0_QUERY_DRV_STAT_RESOURCE_VALIDATE_COUNT,
-#endif
-   NVC0_QUERY_DRV_STAT_COUNT
-};
-
 void nvc0_init_query_functions(struct nvc0_context *);
 void nvc0_query_pushbuf_submit(struct nouveau_pushbuf *, struct nvc0_query *,
                                unsigned);
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c b/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c
new file mode 100644
index 0000000..607c78a
--- /dev/null
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2011 Christoph Bumiller
+ * Copyright 2015 Samuel Pitoiset
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "nvc0/nvc0_context.h"
+
+#include "nvc0_query_sw.h"
+
+static void
+nvc0_sw_destroy_query(struct nvc0_context *nvc0, struct nvc0_query *q)
+{
+   struct nvc0_sw_query *sq = nvc0_sw_query(q);
+   FREE(sq);
+}
+
+static boolean
+nvc0_sw_begin_query(struct nvc0_context *nvc0, struct nvc0_query *q)
+{
+   struct nvc0_sw_query *sq = nvc0_sw_query(q);
+
+   if (q->index >= 5) {
+      sq->value = nvc0->screen->base.stats.v[q->index];
+   } else {
+      sq->value = 0;
+   }
+   return true;
+}
+
+static void
+nvc0_sw_end_query(struct nvc0_context *nvc0, struct nvc0_query *q)
+{
+   struct nvc0_sw_query *sq = nvc0_sw_query(q);
+   sq->value = nvc0->screen->base.stats.v[q->index] - sq->value;
+}
+
+static boolean
+nvc0_sw_get_query_result(struct nvc0_context *nvc0, struct nvc0_query *q,
+                         boolean wait, union pipe_query_result *result)
+{
+   struct nvc0_sw_query *sq = nvc0_sw_query(q);
+   uint64_t *res64 = (uint64_t *)result;
+
+   res64[0] = sq->value;
+   return true;
+}
+
+static const struct nvc0_query_funcs sw_query_funcs = {
+   .destroy_query = nvc0_sw_destroy_query,
+   .begin_query = nvc0_sw_begin_query,
+   .end_query = nvc0_sw_end_query,
+   .get_query_result = nvc0_sw_get_query_result,
+};
+
+struct nvc0_query *
+nvc0_sw_create_query(struct nvc0_context *nvcO, unsigned type, unsigned index)
+{
+   struct nvc0_sw_query *sq;
+   struct nvc0_query *q;
+
+   if (type < NVC0_QUERY_DRV_STAT(0) || type > NVC0_QUERY_DRV_STAT_LAST)
+      return NULL;
+
+   sq = CALLOC_STRUCT(nvc0_sw_query);
+   if (!sq)
+      return NULL;
+
+   q = &sq->base;
+   q->funcs = &sw_query_funcs;
+   q->type = type;
+   q->index = type - NVC0_QUERY_DRV_STAT(0);
+
+   return q;
+}
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.h b/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.h
new file mode 100644
index 0000000..a3b6307
--- /dev/null
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.h
@@ -0,0 +1,61 @@
+#ifndef __NVC0_QUERY_SW_H__
+#define __NVC0_QUERY_SW_H__
+
+#include "nvc0_query.h"
+
+struct nvc0_sw_query {
+   struct nvc0_query base;
+   uint64_t value;
+};
+
+static inline struct nvc0_sw_query *
+nvc0_sw_query(struct nvc0_query *q)
+{
+   return (struct nvc0_sw_query *)q;
+}
+
+/*
+ * Driver statistics queries:
+ */
+#define NVC0_QUERY_DRV_STAT(i)    (PIPE_QUERY_DRIVER_SPECIFIC + 1024 + (i))
+#define NVC0_QUERY_DRV_STAT_LAST   NVC0_QUERY_DRV_STAT(NVC0_QUERY_DRV_STAT_COUNT - 1)
+enum nvc0_drv_stats_queries
+{
+#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS
+   NVC0_QUERY_DRV_STAT_TEX_OBJECT_CURRENT_COUNT = 0,
+   NVC0_QUERY_DRV_STAT_TEX_OBJECT_CURRENT_BYTES,
+   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_COUNT,
+   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_BYTES_VID,
+   NVC0_QUERY_DRV_STAT_BUF_OBJECT_CURRENT_BYTES_SYS,
+   NVC0_QUERY_DRV_STAT_TEX_TRANSFERS_READ,
+   NVC0_QUERY_DRV_STAT_TEX_TRANSFERS_WRITE,
+   NVC0_QUERY_DRV_STAT_TEX_COPY_COUNT,
+   NVC0_QUERY_DRV_STAT_TEX_BLIT_COUNT,
+   NVC0_QUERY_DRV_STAT_TEX_CACHE_FLUSH_COUNT,
+   NVC0_QUERY_DRV_STAT_BUF_TRANSFERS_READ,
+   NVC0_QUERY_DRV_STAT_BUF_TRANSFERS_WRITE,
+   NVC0_QUERY_DRV_STAT_BUF_READ_BYTES_STAGING_VID,
+   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_DIRECT,
+   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_STAGING_VID,
+   NVC0_QUERY_DRV_STAT_BUF_WRITE_BYTES_STAGING_SYS,
+   NVC0_QUERY_DRV_STAT_BUF_COPY_BYTES,
+   NVC0_QUERY_DRV_STAT_BUF_NON_KERNEL_FENCE_SYNC_COUNT,
+   NVC0_QUERY_DRV_STAT_ANY_NON_KERNEL_FENCE_SYNC_COUNT,
+   NVC0_QUERY_DRV_STAT_QUERY_SYNC_COUNT,
+   NVC0_QUERY_DRV_STAT_GPU_SERIALIZE_COUNT,
+   NVC0_QUERY_DRV_STAT_DRAW_CALLS_ARRAY,
+   NVC0_QUERY_DRV_STAT_DRAW_CALLS_INDEXED,
+   NVC0_QUERY_DRV_STAT_DRAW_CALLS_FALLBACK_COUNT,
+   NVC0_QUERY_DRV_STAT_USER_BUFFER_UPLOAD_BYTES,
+   NVC0_QUERY_DRV_STAT_CONSTBUF_UPLOAD_COUNT,
+   NVC0_QUERY_DRV_STAT_CONSTBUF_UPLOAD_BYTES,
+   NVC0_QUERY_DRV_STAT_PUSHBUF_COUNT,
+   NVC0_QUERY_DRV_STAT_RESOURCE_VALIDATE_COUNT,
+#endif
+   NVC0_QUERY_DRV_STAT_COUNT
+};
+
+struct nvc0_query *
+nvc0_sw_create_query(struct nvc0_context *, unsigned, unsigned);
+
+#endif
-- 
2.6.0



More information about the mesa-dev mailing list