[Mesa-dev] [PATCH v3 3/3] nvc0: use a macro to write query result availability to a buffer

Rhys Perry pendingchaos02 at gmail.com
Tue May 22 23:15:44 UTC 2018


Both the availability and result paths shared a bit of code so they were
marged.

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
---
 src/gallium/drivers/nouveau/nvc0/mme/com9097.mme   |  45 ++++++++
 src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h |  34 ++++++
 src/gallium/drivers/nouveau/nvc0/nvc0_macros.h     |   2 +
 src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c   | 128 ++++++++++-----------
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c     |   1 +
 5 files changed, 141 insertions(+), 69 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme
index 0e5ad66f56..08dbc941ec 100644
--- a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme
+++ b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme
@@ -564,6 +564,51 @@ qbw_done:
    exit send (extrinsrt 0x0 $r7 0 16 16)
    maddrsend 0x44 /* SERIALIZE */
 
+/* NVC0_3D_MACRO_QUERY_BUFFER_WRITE_AVAIL:
+ *
+ * Like NVC0_3D_MACRO_QUERY_BUFFER_WRITE, this uses the query engine to write
+ * out values.
+ *
+ * arg = write64 ? 1 : 0
+ * parm[0] = desired sequence
+ * parm[1] = actual sequence
+ * parm[2] = LSB of destination address
+ * parm[3] = MSB of destination address
+ */
+.section #mme9097_query_buffer_write_avail
+   parm $r2
+   parm $r3
+   parm $r4
+   parm $r5
+   mov $r6 (sub $r3 $r2)
+   mov $r6 (sbb 0x0 0x0)
+   branz annul $r6 #qbwa_not_avail
+qbwa_avail:
+   mov $r6 0x1
+   bra annul #qbwa_write
+qbwa_not_avail:
+   mov $r6 0x0
+qbwa_write:
+   maddr 0x16c0 /* QUERY_ADDRESS_HIGH */
+   send $r5
+   send $r4
+   send $r6
+   braz $r1 #qbwa_done
+   mov $r7 0x1000
+   send (extrinsrt 0x0 $r7 0 16 16)
+qbwa_high:
+   /* XXX: things seem to mess up if $r6 is replaced with 0x4 in the add */
+   mov $r6 0x4
+   mov $r4 (add $r4 $r6)
+   mov $r5 (adc $r5 0x0)
+   maddr 0x16c0 /* QUERY_ADDRESS_HIGH */
+   send $r5
+   send $r4
+   send 0x0
+qbwa_done:
+   exit send (extrinsrt 0x0 $r7 0 16 16)
+   maddrsend 0x44 /* SERIALIZE */
+
 /* NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE:
  *
  * This sets basically all the conservative rasterization state. It sets
diff --git a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
index 3ebfda47ee..7a8b9b2018 100644
--- a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
+++ b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
@@ -380,6 +380,40 @@ uint32_t mme9097_query_buffer_write[] = {
 	0x00110071,
 };
 
+uint32_t mme9097_query_buffer_write_avail[] = {
+	0x00000201,
+/* 0x0007: qbwa_avail */
+	0x00000301,
+/* 0x0009: qbwa_not_avail */
+/* 0x000a: qbwa_write */
+	0x00000401,
+	0x00000501,
+/* 0x0011: qbwa_high */
+	0x00049e10,
+	0x00060610,
+/* 0x0018: qbwa_done */
+	0x0000f037,
+	0x00004611,
+	0x00008027,
+	0x00000611,
+	0x05b00021,
+	0x00002841,
+	0x00002041,
+	0x00003041,
+	0x00028807,
+	0x04000711,
+	0x8401c042,
+	0x00010611,
+	0x0001a410,
+	0x00022d10,
+	0x05b00021,
+	0x00002841,
+	0x00002041,
+	0x00000041,
+	0x8401c0c2,
+	0x00110071,
+};
+
 uint32_t mme9097_conservative_raster_state[] = {
 	0x07400021,
 	0x00000041,
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h b/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
index 7aa0633795..f662ce06b7 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
@@ -39,4 +39,6 @@
 
 #define NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE			0x00003868
 
+#define NVC0_3D_MACRO_QUERY_BUFFER_WRITE_AVAIL			0x00003870
+
 #endif /* __NVC0_MACROS_H__ */
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c b/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
index 835742bbc6..a7f895444f 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
@@ -380,29 +380,11 @@ nvc0_hw_get_query_result_resource(struct nvc0_context *nvc0,
    struct nouveau_pushbuf *push = nvc0->base.pushbuf;
    struct nvc0_hw_query *hq = nvc0_hw_query(q);
    struct nv04_resource *buf = nv04_resource(resource);
-   unsigned qoffset = 0, stride;
    bool predicate = false;
-   uint32_t arg;
+   uint32_t arg = result_type >= PIPE_QUERY_TYPE_I64 ? 1 : 0;
 
    assert(!hq->funcs || !hq->funcs->get_query_result);
 
-   if (index == -1) {
-      /* TODO: Use a macro to write the availability of the query */
-      if (hq->state != NVC0_HW_QUERY_STATE_READY)
-         nvc0_hw_query_update(nvc0->screen->base.client, q);
-      uint32_t ready[2] = {hq->state == NVC0_HW_QUERY_STATE_READY};
-      nvc0->base.push_cb(&nvc0->base, buf, offset,
-                         result_type >= PIPE_QUERY_TYPE_I64 ? 2 : 1,
-                         ready);
-
-      util_range_add(&buf->valid_buffer_range, offset,
-                     offset + (result_type >= PIPE_QUERY_TYPE_I64 ? 8 : 4));
-
-      nvc0_resource_validate(buf, NOUVEAU_BO_WR);
-
-      return;
-   }
-
    switch (q->type) {
    case PIPE_QUERY_OCCLUSION_PREDICATE:
    case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
@@ -412,7 +394,6 @@ nvc0_hw_get_query_result_resource(struct nvc0_context *nvc0,
       break;
    }
 
-   arg = result_type >= PIPE_QUERY_TYPE_I64 ? 1 : 0;
    /* Only clamp if the output is 32-bit or a predicate, we don't bother
     * clamping 64-bit outputs */
    if ((result_type<PIPE_QUERY_TYPE_I64 || predicate) && index!=-1)
@@ -433,10 +414,13 @@ nvc0_hw_get_query_result_resource(struct nvc0_context *nvc0,
    nouveau_pushbuf_bufctx(push, nvc0->bufctx);
    nouveau_pushbuf_validate(push);
 
-   nouveau_pushbuf_space(push, 32, 2, 0);
-   PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
-   PUSH_REFN (push, buf->bo, buf->domain | NOUVEAU_BO_WR);
-   BEGIN_1IC0(push, NVC0_3D(MACRO_QUERY_BUFFER_WRITE), 10);
+   nouveau_pushbuf_space(push, 20, 0, 5);
+   PUSH_REFN(push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
+   PUSH_REFN(push, buf->bo, buf->domain | NOUVEAU_BO_WR);
+   if (index == -1)
+      BEGIN_1IC0(push, NVC0_3D(MACRO_QUERY_BUFFER_WRITE_AVAIL), 5);
+   else
+      BEGIN_1IC0(push, NVC0_3D(MACRO_QUERY_BUFFER_WRITE), 10);
    PUSH_DATA(push, arg);
 
    if (wait || hq->state == NVC0_HW_QUERY_STATE_READY) {
@@ -452,56 +436,62 @@ nvc0_hw_get_query_result_resource(struct nvc0_context *nvc0,
                            4 | NVC0_IB_ENTRY_1_NO_PREFETCH);
    }
 
-   switch (q->type) {
-   case PIPE_QUERY_SO_STATISTICS:
-      stride = 2;
-      break;
-   case PIPE_QUERY_PIPELINE_STATISTICS:
-      stride = 12;
-      break;
-   case PIPE_QUERY_TIME_ELAPSED:
-   case PIPE_QUERY_TIMESTAMP:
-      qoffset = 8;
-      /* fallthrough */
-   default:
-      assert(index == 0);
-      stride = 1;
-      break;
-   }
+   if (index != -1) {
+      unsigned qoffset = 0, stride;
 
-   /* We need to compute the difference between 2 values, and then store the
-    * result as either a 32- or 64-bit value. As such let's treat all inputs
-    * as 64-bit (and just push an extra 0 for the 32-bit ones), and clamp
-    * the result to an limit if it's 32 bit or a predicate.
-    */
-   if (hq->is64bit || qoffset) {
-      nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset + 16 * index,
-                           8 | NVC0_IB_ENTRY_1_NO_PREFETCH);
-      if (q->type == PIPE_QUERY_TIMESTAMP) {
+      /* We need to compute the difference between 2 values, and then store the
+       * result as either a 32- or 64-bit value. As such let's treat all inputs
+       * as 64-bit (and just push an extra 0 for the 32-bit ones), and clamp
+       * the result to an limit if it's 32 bit or a predicate.
+       */
+      switch (q->type) {
+      case PIPE_QUERY_SO_STATISTICS:
+         stride = 2;
+         break;
+      case PIPE_QUERY_PIPELINE_STATISTICS:
+         stride = 12;
+         break;
+      case PIPE_QUERY_TIME_ELAPSED:
+      case PIPE_QUERY_TIMESTAMP:
+         qoffset = 8;
+         /* fallthrough */
+      default:
+         assert(index == 0);
+         stride = 1;
+         break;
+      }
+
+      /* start and end values */
+      if (hq->is64bit || qoffset) {
+         nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset + 16 * index,
+                              8 | NVC0_IB_ENTRY_1_NO_PREFETCH);
+         if (q->type == PIPE_QUERY_TIMESTAMP) {
+            PUSH_DATA(push, 0);
+            PUSH_DATA(push, 0);
+         } else {
+            nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset +
+                                 16 * (index + stride),
+                                 8 | NVC0_IB_ENTRY_1_NO_PREFETCH);
+         }
+      } else {
+         nouveau_pushbuf_data(push, hq->bo, hq->offset + 4,
+                              4 | NVC0_IB_ENTRY_1_NO_PREFETCH);
          PUSH_DATA(push, 0);
+         nouveau_pushbuf_data(push, hq->bo, hq->offset + 16 + 4,
+                              4 | NVC0_IB_ENTRY_1_NO_PREFETCH);
          PUSH_DATA(push, 0);
-      } else {
-         nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset +
-                              16 * (index + stride),
-                              8 | NVC0_IB_ENTRY_1_NO_PREFETCH);
       }
-   } else {
-      nouveau_pushbuf_data(push, hq->bo, hq->offset + 4,
-                           4 | NVC0_IB_ENTRY_1_NO_PREFETCH);
-      PUSH_DATA(push, 0);
-      nouveau_pushbuf_data(push, hq->bo, hq->offset + 16 + 4,
-                           4 | NVC0_IB_ENTRY_1_NO_PREFETCH);
-      PUSH_DATA(push, 0);
-   }
 
-   if (predicate)
-      PUSH_DATA(push, 0x00000001);
-   else if (result_type == PIPE_QUERY_TYPE_I32)
-      PUSH_DATA(push, 0x7fffffff);
-   else if (result_type == PIPE_QUERY_TYPE_U32)
-      PUSH_DATA(push, 0xffffffff);
-   else
-      PUSH_DATA(push, 0x00000000);
+      /* clamp value */
+      if (predicate)
+         PUSH_DATA(push, 0x00000001);
+      else if (result_type == PIPE_QUERY_TYPE_I32)
+         PUSH_DATA(push, 0x7fffffff);
+      else if (result_type == PIPE_QUERY_TYPE_U32)
+         PUSH_DATA(push, 0xffffffff);
+      else
+         PUSH_DATA(push, 0x00000000);
+   }
 
    PUSH_DATA (push, buf->address + offset);
    PUSH_DATAh(push, buf->address + offset);
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
index e1c7b3a236..8dab692dec 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
@@ -1214,6 +1214,7 @@ nvc0_screen_create(struct nouveau_device *dev)
    MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT_COUNT, mme9097_draw_elts_indirect_count);
    MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE, mme9097_query_buffer_write);
    MK_MACRO(NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE, mme9097_conservative_raster_state);
+   MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE_AVAIL, mme9097_query_buffer_write_avail);
    MK_MACRO(NVC0_CP_MACRO_LAUNCH_GRID_INDIRECT, mme90c0_launch_grid_indirect);
 
    BEGIN_NVC0(push, NVC0_3D(RASTERIZE_ENABLE), 1);
-- 
2.14.3



More information about the mesa-dev mailing list