etnaviv: extend acc sample provide with an allocate(..)
authorChristian Gmeiner <christian.gmeiner@gmail.com>
Wed, 31 Jul 2019 20:40:45 +0000 (22:40 +0200)
committerMarge Bot <eric+marge@anholt.net>
Sun, 5 Apr 2020 18:01:43 +0000 (18:01 +0000)
We might be able to sub-class etna_acc_query.

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1530>

src/gallium/drivers/etnaviv/Makefile.sources
src/gallium/drivers/etnaviv/etnaviv_query_acc.c
src/gallium/drivers/etnaviv/etnaviv_query_acc.h
src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c [new file with mode: 0644]
src/gallium/drivers/etnaviv/meson.build

index b71bff63e2af03a114a970d6fd41077706184cd3..a28ab1bb09927dfbb92c616afb5f8b6862f16f8e 100644 (file)
@@ -36,6 +36,7 @@ C_SOURCES :=  \
        etnaviv_internal.h \
        etnaviv_query.c \
        etnaviv_query.h \
+       etnaviv_query_acc_occlusion.c \
        etnaviv_query_acc.c \
        etnaviv_query_acc.h \
        etnaviv_query_sw.c \
index 094c7c841258701a4ae25cdb9f504d3f2fea7e77..3c8dd30420472ef763d049b5739e9fed417a778f 100644 (file)
 #include "etnaviv_query_acc.h"
 #include "etnaviv_screen.h"
 
-/*
- * Occlusion Query:
- *
- * OCCLUSION_COUNTER and OCCLUSION_PREDICATE differ only in how they
- * interpret results
- */
-
-static bool
-occlusion_supports(unsigned query_type)
-{
-   switch (query_type) {
-   case PIPE_QUERY_OCCLUSION_COUNTER:
-      /* fallthrough */
-   case PIPE_QUERY_OCCLUSION_PREDICATE:
-      /* fallthrough */
-   case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
-      return true;
-   default:
-      return false;
-   }
-}
 
-static void
-occlusion_resume(struct etna_acc_query *aq, struct etna_context *ctx)
-{
-   struct etna_resource *rsc = etna_resource(aq->prsc);
-   struct etna_reloc r = {
-      .bo = rsc->bo,
-      .flags = ETNA_RELOC_WRITE
-   };
-
-   if (aq->samples > 63) {
-      aq->samples = 63;
-      BUG("samples overflow");
-   }
-
-   r.offset = aq->samples * 8; /* 64bit value */
-
-   etna_set_state_reloc(ctx->stream, VIVS_GL_OCCLUSION_QUERY_ADDR, &r);
-   resource_written(ctx, aq->prsc);
-}
-
-static void
-occlusion_suspend(struct etna_acc_query *aq, struct etna_context *ctx)
-{
-   /* 0x1DF5E76 is the value used by blob - but any random value will work */
-   etna_set_state(ctx->stream, VIVS_GL_OCCLUSION_QUERY_CONTROL, 0x1DF5E76);
-   resource_written(ctx, aq->prsc);
-}
+extern const struct etna_acc_sample_provider occlusion_provider;
 
-static bool
-occlusion_result(struct etna_acc_query *aq, void *buf,
-                 union pipe_query_result *result)
+static const struct etna_acc_sample_provider *acc_sample_provider[] =
 {
-   uint64_t sum = 0;
-   uint64_t *ptr = (uint64_t *)buf;
-
-   for (unsigned i = 0; i < aq->samples; i++)
-      sum += *(ptr + i);
-
-   if (aq->base.type == PIPE_QUERY_OCCLUSION_COUNTER)
-      result->u64 = sum;
-   else
-      result->b = !!sum;
-
-   return true;
-}
+   &occlusion_provider,
+};
 
 static void
 etna_acc_destroy_query(struct etna_context *ctx, struct etna_query *q)
@@ -114,18 +54,6 @@ etna_acc_destroy_query(struct etna_context *ctx, struct etna_query *q)
    FREE(aq);
 }
 
-static const struct etna_acc_sample_provider occlusion_provider = {
-   .supports = occlusion_supports,
-   .suspend = occlusion_suspend,
-   .resume = occlusion_resume,
-   .result = occlusion_result,
-};
-
-static const struct etna_acc_sample_provider *acc_sample_provider[] =
-{
-   &occlusion_provider,
-};
-
 static void
 realloc_query_bo(struct etna_context *ctx, struct etna_acc_query *aq)
 {
@@ -253,7 +181,7 @@ etna_acc_create_query(struct etna_context *ctx, unsigned query_type)
    if (!p)
       return NULL;
 
-   aq = CALLOC_STRUCT(etna_acc_query);
+   aq = p->allocate(ctx, query_type);
    if (!aq)
       return NULL;
 
index 8dd4bae5b71b73d80152782ee5b85c29a6aae4ee..526513af12aff2b894d8dfd70932228e185d5bd3 100644 (file)
@@ -35,6 +35,7 @@ struct etna_acc_query;
 
 struct etna_acc_sample_provider {
    bool (*supports)(unsigned query_type);
+   struct etna_acc_query * (*allocate)(struct etna_context *ctx, unsigned query_type);
 
    void (*resume)(struct etna_acc_query *aq, struct etna_context *ctx);
    void (*suspend)(struct etna_acc_query *aq, struct etna_context *ctx);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c b/src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c
new file mode 100644 (file)
index 0000000..1094053
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2017 Etnaviv Project
+ * Copyright (C) 2017 Zodiac Inflight Innovations
+ *
+ * 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, sub license,
+ * 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT. 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.
+ *
+ * Authors:
+ *    Rob Clark <robclark@freedesktop.org>
+ *    Christian Gmeiner <christian.gmeiner@gmail.com>
+ */
+
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
+
+#include "etnaviv_context.h"
+#include "etnaviv_debug.h"
+#include "etnaviv_emit.h"
+#include "etnaviv_query_acc.h"
+#include "etnaviv_screen.h"
+
+/*
+ * Occlusion Query:
+ *
+ * OCCLUSION_COUNTER and OCCLUSION_PREDICATE differ only in how they
+ * interpret results
+ */
+
+static bool
+occlusion_supports(unsigned query_type)
+{
+   switch (query_type) {
+   case PIPE_QUERY_OCCLUSION_COUNTER:
+      /* fallthrough */
+   case PIPE_QUERY_OCCLUSION_PREDICATE:
+      /* fallthrough */
+   case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
+      return true;
+   default:
+      return false;
+   }
+}
+
+static struct etna_acc_query *
+occlusion_allocate(struct etna_context *ctx, ASSERTED unsigned query_type)
+{
+   return CALLOC_STRUCT(etna_acc_query);
+}
+
+static void
+occlusion_resume(struct etna_acc_query *aq, struct etna_context *ctx)
+{
+   struct etna_resource *rsc = etna_resource(aq->prsc);
+   struct etna_reloc r = {
+      .bo = rsc->bo,
+      .flags = ETNA_RELOC_WRITE
+   };
+
+   if (aq->samples > 63) {
+      aq->samples = 63;
+      BUG("samples overflow");
+   }
+
+   r.offset = aq->samples * 8; /* 64bit value */
+
+   etna_set_state_reloc(ctx->stream, VIVS_GL_OCCLUSION_QUERY_ADDR, &r);
+   resource_written(ctx, aq->prsc);
+}
+
+static void
+occlusion_suspend(struct etna_acc_query *aq, struct etna_context *ctx)
+{
+   /* 0x1DF5E76 is the value used by blob - but any random value will work */
+   etna_set_state(ctx->stream, VIVS_GL_OCCLUSION_QUERY_CONTROL, 0x1DF5E76);
+   resource_written(ctx, aq->prsc);
+}
+
+static bool
+occlusion_result(struct etna_acc_query *aq, void *buf,
+                 union pipe_query_result *result)
+{
+   uint64_t sum = 0;
+   uint64_t *ptr = (uint64_t *)buf;
+
+   for (unsigned i = 0; i < aq->samples; i++)
+      sum += *(ptr + i);
+
+   if (aq->base.type == PIPE_QUERY_OCCLUSION_COUNTER)
+      result->u64 = sum;
+   else
+      result->b = !!sum;
+
+   return true;
+}
+
+const struct etna_acc_sample_provider occlusion_provider = {
+   .supports = occlusion_supports,
+   .allocate = occlusion_allocate,
+   .suspend = occlusion_suspend,
+   .resume = occlusion_resume,
+   .result = occlusion_result,
+};
index 578d94838925d0725eb0dc3ae331ba8cbd3fa7ff..a64b10ba1b31a7be5d230eaa032a24505c7ce028 100644 (file)
@@ -55,6 +55,7 @@ files_etnaviv = files(
   'etnaviv_internal.h',
   'etnaviv_query.c',
   'etnaviv_query.h',
+  'etnaviv_query_acc_occlusion.c',
   'etnaviv_query_acc.c',
   'etnaviv_query_acc.h',
   'etnaviv_query_sw.c',