panfrost: Implement missing texture formats
[mesa.git] / src / gallium / drivers / panfrost / pan_job.c
1 /*
2 * Copyright (C) 2019 Alyssa Rosenzweig
3 * Copyright (C) 2014-2017 Broadcom
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #include "pan_context.h"
27 #include "util/hash_table.h"
28 #include "util/ralloc.h"
29
30 struct panfrost_job *
31 panfrost_create_job(struct panfrost_context *ctx)
32 {
33 /* TODO: Don't leak */
34 struct panfrost_job *job = rzalloc(NULL, struct panfrost_job);
35
36 job->ctx = ctx;
37
38 return job;
39 }
40
41 struct panfrost_job *
42 panfrost_get_job(struct panfrost_context *ctx,
43 struct pipe_surface **cbufs, struct pipe_surface *zsbuf)
44 {
45 /* Lookup the job first */
46
47 struct panfrost_job_key key = {
48 .cbufs = {
49 cbufs[0],
50 cbufs[1],
51 cbufs[2],
52 cbufs[3],
53 },
54 .zsbuf = zsbuf
55 };
56
57 struct hash_entry *entry = _mesa_hash_table_search(ctx->jobs, &key);
58
59 if (entry)
60 return entry->data;
61
62 /* Otherwise, let's create a job */
63
64 struct panfrost_job *job = panfrost_create_job(ctx);
65
66 /* Save the created job */
67
68 memcpy(&job->key, &key, sizeof(key));
69 _mesa_hash_table_insert(ctx->jobs, &job->key, job);
70
71 return job;
72 }
73
74 /* Get the job corresponding to the FBO we're currently rendering into */
75
76 struct panfrost_job *
77 panfrost_get_job_for_fbo(struct panfrost_context *ctx)
78 {
79 /* If we already began rendering, use that */
80
81 if (ctx->job)
82 return ctx->job;
83
84 /* If not, look up the job */
85
86 struct pipe_surface **cbufs = ctx->pipe_framebuffer.cbufs;
87 struct pipe_surface *zsbuf = ctx->pipe_framebuffer.zsbuf;
88 struct panfrost_job *job = panfrost_get_job(ctx, cbufs, zsbuf);
89
90 return job;
91 }
92
93 static bool
94 panfrost_job_compare(const void *a, const void *b)
95 {
96 return memcmp(a, b, sizeof(struct panfrost_job_key)) == 0;
97 }
98
99 static uint32_t
100 panfrost_job_hash(const void *key)
101 {
102 return _mesa_hash_data(key, sizeof(struct panfrost_job_key));
103 }
104
105 void
106 panfrost_job_init(struct panfrost_context *ctx)
107 {
108 /* TODO: Don't leak */
109 ctx->jobs = _mesa_hash_table_create(NULL,
110 panfrost_job_hash,
111 panfrost_job_compare);
112 }