panfrost: Import job data structures from v3d
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Feb 2019 05:32:16 +0000 (05:32 +0000)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 4 Mar 2019 04:58:15 +0000 (04:58 +0000)
At the moment, Panfrost state is ad hoc, which creates issues for FBOs.
This commit imports the skeleton of the v3d_job structure as
panfrost_job, in preparation for refactors to organize this state.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
src/gallium/drivers/panfrost/meson.build
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_job.c [new file with mode: 0644]
src/gallium/drivers/panfrost/pan_job.h [new file with mode: 0644]

index 9568247f36d71ae290cd6150ba35724efb1ac90c..456782355bbe1f34d84b7336c4c28d22ec953b7e 100644 (file)
@@ -31,6 +31,7 @@ files_panfrost = files(
   'midgard/disassemble.c',
 
   'pan_context.c',
+  'pan_job.c',
   'pan_trace.c',
   'pan_drm.c',
   'pan_allocate.c',
index 0676ef0497af4016ae934b0467eaa25889012287..257482f900668662e93f4fe84bdec0a7cb49b8b7 100644 (file)
@@ -1712,11 +1712,6 @@ panfrost_get_index_buffer_mapped(struct panfrost_context *ctx, const struct pipe
         }
 }
 
-static void
-panfrost_draw_vbo(
-        struct pipe_context *pipe,
-        const struct pipe_draw_info *info);
-
 #define CALCULATE_MIN_MAX_INDEX(T, buffer, start, count) \
         for (unsigned _idx = (start); _idx < (start + count); ++_idx) { \
                 T idx = buffer[_idx]; \
@@ -1753,6 +1748,11 @@ panfrost_draw_vbo(
                 }
         }
 
+        /* Now that we have a guaranteed terminating path, find the job.
+         * Assignment commented out to prevent unused warning */
+
+        /* struct panfrost_job *job = */ panfrost_get_job_for_fbo(ctx);
+
         ctx->payload_tiler.prefix.draw_mode = g2m_draw_mode(mode);
 
         ctx->vertex_count = info->count;
@@ -2843,6 +2843,7 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
 
         /* Prepare for render! */
 
+        panfrost_job_init(ctx);
         panfrost_emit_vertex_payload(ctx);
         panfrost_emit_tiler_payload(ctx);
         panfrost_invalidate_frame(ctx);
index 48cce72a30329293e418332e041268a8566f6656..06c8e69bbe98efec9cd0c6edb433d72a5f857117 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/mman.h>
 #include <assert.h>
 #include "pan_resource.h"
+#include "pan_job.h"
 
 #include "pipe/p_compiler.h"
 #include "pipe/p_config.h"
@@ -39,6 +40,7 @@
 #include "pipe/p_screen.h"
 #include "pipe/p_state.h"
 #include "util/u_blitter.h"
+#include "util/hash_table.h"
 
 /* Forward declare to avoid extra header dep */
 struct prim_convert_context;
@@ -95,6 +97,10 @@ struct panfrost_context {
         /* Gallium context */
         struct pipe_context base;
 
+        /* Bound job and map of panfrost_job_key to jobs */
+        struct panfrost_job *job;
+        struct hash_table *jobs;
+
         /* Bit mask for supported PIPE_DRAW for this hardware */
         unsigned draw_modes;
 
diff --git a/src/gallium/drivers/panfrost/pan_job.c b/src/gallium/drivers/panfrost/pan_job.c
new file mode 100644 (file)
index 0000000..66a8b0d
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2019 Alyssa Rosenzweig
+ * Copyright (C) 2014-2017 Broadcom
+ *
+ * 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, sublicense,
+ * 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 NONINFRINGEMENT.  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.
+ *
+ */
+
+#include "pan_context.h"
+#include "util/hash_table.h"
+#include "util/ralloc.h"
+
+struct panfrost_job *
+panfrost_create_job(struct panfrost_context *ctx)
+{
+        /* TODO: Don't leak */
+        struct panfrost_job *job = rzalloc(NULL, struct panfrost_job);
+
+        job->ctx = ctx;
+
+        return job;
+}
+
+struct panfrost_job *
+panfrost_get_job(struct panfrost_context *ctx,
+                struct pipe_surface **cbufs, struct pipe_surface *zsbuf)
+{
+        /* Lookup the job first */
+
+        struct panfrost_job_key key = {
+                .cbufs = {
+                        cbufs[0],
+                        cbufs[1],
+                        cbufs[2],
+                        cbufs[3],
+                },
+                .zsbuf = zsbuf
+        };
+        
+        struct hash_entry *entry = _mesa_hash_table_search(ctx->jobs, &key);
+
+        if (entry)
+                return entry->data;
+
+        /* Otherwise, let's create a job */
+
+        struct panfrost_job *job = panfrost_create_job(ctx);
+
+        /* Save the created job */
+
+        memcpy(&job->key, &key, sizeof(key));
+        _mesa_hash_table_insert(ctx->jobs, &job->key, job);
+
+        return job;
+}
+
+/* Get the job corresponding to the FBO we're currently rendering into */
+
+struct panfrost_job *
+panfrost_get_job_for_fbo(struct panfrost_context *ctx)
+{
+        /* If we already began rendering, use that */
+
+        if (ctx->job)
+                return ctx->job;
+
+        /* If not, look up the job */
+
+        struct pipe_surface **cbufs = ctx->pipe_framebuffer.cbufs;
+        struct pipe_surface *zsbuf = ctx->pipe_framebuffer.zsbuf;
+        struct panfrost_job *job = panfrost_get_job(ctx, cbufs, zsbuf);
+
+        return job;
+}
+
+static bool
+panfrost_job_compare(const void *a, const void *b)
+{
+        return memcmp(a, b, sizeof(struct panfrost_job_key)) == 0;
+}
+
+static uint32_t
+panfrost_job_hash(const void *key)
+{
+        return _mesa_hash_data(key, sizeof(struct panfrost_job_key));
+}
+
+void
+panfrost_job_init(struct panfrost_context *ctx)
+{
+        /* TODO: Don't leak */
+        ctx->jobs = _mesa_hash_table_create(NULL,
+                                            panfrost_job_hash,
+                                            panfrost_job_compare);
+}
diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h
new file mode 100644 (file)
index 0000000..2e60621
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 Alyssa Rosenzweig
+ * Copyright (C) 2014-2017 Broadcom
+ *
+ * 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, sublicense,
+ * 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 NONINFRINGEMENT.  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.
+ *
+ */
+
+#ifndef __PAN_JOB_H__
+#define __PAN_JOB_H__
+
+/* Used as a hash table key */
+
+struct panfrost_job_key {
+        struct pipe_surface *cbufs[4];
+        struct pipe_surface *zsbuf;
+};
+
+/* A panfrost_job corresponds to a bound FBO we're rendering to,
+ * collecting over multiple draws. */
+
+struct panfrost_job {
+        struct panfrost_context *ctx;
+        struct panfrost_job_key key;
+};
+
+/* Functions for managing the above */
+
+struct panfrost_job *
+panfrost_create_job(struct panfrost_context *ctx);
+
+struct panfrost_job *
+panfrost_get_job(struct panfrost_context *ctx,
+                struct pipe_surface **cbufs, struct pipe_surface *zsbuf);
+
+struct panfrost_job *
+panfrost_get_job_for_fbo(struct panfrost_context *ctx);
+
+void
+panfrost_job_init(struct panfrost_context *ctx);
+
+#endif