From a4653587cc434e8dbaa2b06cd18c8132ab611f78 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Thu, 25 Apr 2024 09:42:01 +0200
Subject: [PATCH] etnaviv: Add a separate NPU pipe
Add a separate pipe for the NPU device when the primary device is a GPU.
In case of compute-only contexts, prefer to use the separate NPU pipe.
This allows to create a compute-only context that uses the NPU pipe on
a screen that has a 3D GPU as primary device.
Signed-off-by: Philipp Zabel
Reviewed-by: Christian Gmeiner
Part-of:
---
src/gallium/drivers/etnaviv/etnaviv_context.c | 7 +++++--
src/gallium/drivers/etnaviv/etnaviv_screen.c | 11 +++++++++++
src/gallium/drivers/etnaviv/etnaviv_screen.h | 1 +
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c
index baca59116f0..8c9e9cdc576 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -618,6 +618,8 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
struct etna_context *ctx = CALLOC_STRUCT(etna_context);
struct etna_screen *screen;
struct pipe_context *pctx;
+ struct etna_pipe *pipe;
+ bool compute_only = flags & PIPE_CONTEXT_COMPUTE_ONLY;
if (ctx == NULL)
return NULL;
@@ -631,7 +633,8 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
pctx->const_uploader = pctx->stream_uploader;
screen = etna_screen(pscreen);
- ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000,
+ pipe = (compute_only && screen->pipe_nn) ? screen->pipe_nn : screen->pipe;
+ ctx->stream = etna_cmd_stream_new(pipe, 0x2000,
&etna_context_force_flush, pctx);
if (ctx->stream == NULL)
goto fail;
@@ -655,7 +658,7 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
/* need some sane default in case gallium frontends don't set some state: */
ctx->sample_mask = 0xffff;
- ctx->compute_only = flags & PIPE_CONTEXT_COMPUTE_ONLY;
+ ctx->compute_only = compute_only;
/* Set sensible defaults for state */
etna_reset_gpu_state(ctx);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index a3d3bfff6ac..17d5af72cd2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -103,6 +103,9 @@ etna_screen_destroy(struct pipe_screen *pscreen)
etna_shader_screen_fini(pscreen);
+ if (screen->pipe_nn)
+ etna_pipe_del(screen->pipe_nn);
+
if (screen->pipe)
etna_pipe_del(screen->pipe);
@@ -1092,6 +1095,14 @@ etna_screen_create(struct etna_device *dev, struct etna_gpu *gpu,
goto fail;
}
+ if (gpu != npu) {
+ screen->pipe_nn = etna_pipe_new(npu, ETNA_PIPE_3D);
+ if (!screen->pipe_nn) {
+ DBG("could not create nn pipe");
+ goto fail;
+ }
+ }
+
/* apply debug options that disable individual features */
if (DBG_ENABLED(ETNA_DBG_NO_EARLY_Z))
etna_core_disable_feature(screen->info, ETNA_FEATURE_NO_EARLY_Z);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.h b/src/gallium/drivers/etnaviv/etnaviv_screen.h
index d45ce5fdb6a..c2fddd968b4 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.h
@@ -51,6 +51,7 @@ struct etna_screen {
struct etna_gpu *gpu;
struct etna_gpu *npu;
struct etna_pipe *pipe;
+ struct etna_pipe *pipe_nn;
struct etna_perfmon *perfmon;
struct renderonly *ro;