From 59c9623d0a75d5201ad48351af26aad1bc0b7073 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Feb 2019 05:32:16 +0000 Subject: [PATCH] panfrost: Import job data structures from v3d 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 Reviewed-by: Tomeu Vizoso --- src/gallium/drivers/panfrost/meson.build | 1 + src/gallium/drivers/panfrost/pan_context.c | 11 +- src/gallium/drivers/panfrost/pan_context.h | 6 ++ src/gallium/drivers/panfrost/pan_job.c | 112 +++++++++++++++++++++ src/gallium/drivers/panfrost/pan_job.h | 59 +++++++++++ 5 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 src/gallium/drivers/panfrost/pan_job.c create mode 100644 src/gallium/drivers/panfrost/pan_job.h diff --git a/src/gallium/drivers/panfrost/meson.build b/src/gallium/drivers/panfrost/meson.build index 9568247f36d..456782355bb 100644 --- a/src/gallium/drivers/panfrost/meson.build +++ b/src/gallium/drivers/panfrost/meson.build @@ -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', diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 0676ef0497a..257482f9006 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -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); diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 48cce72a303..06c8e69bbe9 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -30,6 +30,7 @@ #include #include #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 index 00000000000..66a8b0d4b07 --- /dev/null +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -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 index 00000000000..2e6062112b3 --- /dev/null +++ b/src/gallium/drivers/panfrost/pan_job.h @@ -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 -- 2.30.2