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

Signed-off-by: Rhys Perry <pendingchao...@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 371aa0ce36..c7c544aea0 100644
--- a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme
+++ b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme
@@ -563,3 +563,48 @@ qbw_write:
 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 */
diff --git a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h 
b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
index 083692f73a..aa416e6df8 100644
--- a/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
+++ b/src/gallium/drivers/nouveau/nvc0/mme/com9097.mme.h
@@ -379,3 +379,37 @@ uint32_t mme9097_query_buffer_write[] = {
        0x8401c0c2,
        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,
+};
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h 
b/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
index eeacc714f3..2964728a93 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_macros.h
@@ -37,4 +37,6 @@
 
 #define NVC0_CP_MACRO_LAUNCH_GRID_INDIRECT       0x00003860
 
+#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 296cdacb62..f246e2f6f5 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
@@ -374,29 +374,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:
@@ -406,7 +388,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)
@@ -424,10 +405,13 @@ nvc0_hw_get_query_result_resource(struct nvc0_context 
*nvc0,
    if (wait && hq->state != NVC0_HW_QUERY_STATE_READY)
       nvc0_hw_query_fifo_wait(nvc0, q);
 
-   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, 12, 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) {
@@ -443,56 +427,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 b4a2c676f5..5bd016946e 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
@@ -1197,6 +1197,7 @@ nvc0_screen_create(struct nouveau_device *dev)
    MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT_COUNT, 
mme9097_draw_arrays_indirect_count);
    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_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

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to