diff options
author | Christian Gmeiner <[email protected]> | 2019-07-31 22:40:45 +0200 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-04-05 18:01:43 +0000 |
commit | c111f79b1ce962a9ef138d0d5c894258961e83a5 (patch) | |
tree | 7a68bf9f929bab9605db2e9fe9bfe1f135e1b767 /src | |
parent | e0bc251ef8918dd4fe89604941d8d5a0c482aae7 (diff) |
etnaviv: extend acc sample provide with an allocate(..)
We might be able to sub-class etna_acc_query.
Signed-off-by: Christian Gmeiner <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1530>
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/etnaviv/Makefile.sources | 1 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_query_acc.c | 82 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_query_acc.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c | 118 | ||||
-rw-r--r-- | src/gallium/drivers/etnaviv/meson.build | 1 |
5 files changed, 126 insertions, 77 deletions
diff --git a/src/gallium/drivers/etnaviv/Makefile.sources b/src/gallium/drivers/etnaviv/Makefile.sources index b71bff63e2a..a28ab1bb099 100644 --- a/src/gallium/drivers/etnaviv/Makefile.sources +++ b/src/gallium/drivers/etnaviv/Makefile.sources @@ -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 \ diff --git a/src/gallium/drivers/etnaviv/etnaviv_query_acc.c b/src/gallium/drivers/etnaviv/etnaviv_query_acc.c index 094c7c84125..3c8dd304204 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_query_acc.c +++ b/src/gallium/drivers/etnaviv/etnaviv_query_acc.c @@ -35,73 +35,13 @@ #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; diff --git a/src/gallium/drivers/etnaviv/etnaviv_query_acc.h b/src/gallium/drivers/etnaviv/etnaviv_query_acc.h index 8dd4bae5b71..526513af12a 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_query_acc.h +++ b/src/gallium/drivers/etnaviv/etnaviv_query_acc.h @@ -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 index 00000000000..1094053afa4 --- /dev/null +++ b/src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c @@ -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 <[email protected]> + * Christian Gmeiner <[email protected]> + */ + +#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, +}; diff --git a/src/gallium/drivers/etnaviv/meson.build b/src/gallium/drivers/etnaviv/meson.build index 578d9483892..a64b10ba1b3 100644 --- a/src/gallium/drivers/etnaviv/meson.build +++ b/src/gallium/drivers/etnaviv/meson.build @@ -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', |