2 * Copyright (C) 2019 Alyssa Rosenzweig
3 * Copyright (C) 2014-2017 Broadcom
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:
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
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
26 #include "pan_context.h"
27 #include "util/hash_table.h"
28 #include "util/ralloc.h"
31 panfrost_create_job(struct panfrost_context
*ctx
)
33 struct panfrost_job
*job
= rzalloc(NULL
, struct panfrost_job
);
37 job
->bos
= _mesa_set_create(job
,
39 _mesa_key_pointer_equal
);
45 panfrost_free_job(struct panfrost_context
*ctx
, struct panfrost_job
*job
)
50 set_foreach(job
->bos
, entry
) {
51 struct panfrost_bo
*bo
= (struct panfrost_bo
*)entry
->key
;
52 panfrost_bo_unreference(ctx
->base
.screen
, bo
);
55 _mesa_hash_table_remove_key(ctx
->jobs
, &job
->key
);
64 panfrost_get_job(struct panfrost_context
*ctx
,
65 struct pipe_surface
**cbufs
, struct pipe_surface
*zsbuf
)
67 /* Lookup the job first */
69 struct panfrost_job_key key
= {
79 struct hash_entry
*entry
= _mesa_hash_table_search(ctx
->jobs
, &key
);
84 /* Otherwise, let's create a job */
86 struct panfrost_job
*job
= panfrost_create_job(ctx
);
88 /* Save the created job */
90 memcpy(&job
->key
, &key
, sizeof(key
));
91 _mesa_hash_table_insert(ctx
->jobs
, &job
->key
, job
);
92 panfrost_job_set_requirements(ctx
, job
);
97 /* Get the job corresponding to the FBO we're currently rendering into */
100 panfrost_get_job_for_fbo(struct panfrost_context
*ctx
)
102 /* If we already began rendering, use that */
107 /* If not, look up the job */
109 struct pipe_surface
**cbufs
= ctx
->pipe_framebuffer
.cbufs
;
110 struct pipe_surface
*zsbuf
= ctx
->pipe_framebuffer
.zsbuf
;
111 struct panfrost_job
*job
= panfrost_get_job(ctx
, cbufs
, zsbuf
);
117 panfrost_job_add_bo(struct panfrost_job
*job
, struct panfrost_bo
*bo
)
122 if (_mesa_set_search(job
->bos
, bo
))
125 panfrost_bo_reference(bo
);
126 _mesa_set_add(job
->bos
, bo
);
130 panfrost_flush_jobs_writing_resource(struct panfrost_context
*panfrost
,
131 struct pipe_resource
*prsc
)
134 struct hash_entry
*entry
= _mesa_hash_table_search(panfrost
->write_jobs
,
137 struct panfrost_job
*job
= entry
->data
;
138 panfrost_job_submit(panfrost
, job
);
145 panfrost_job_submit(struct panfrost_context
*ctx
, struct panfrost_job
*job
)
147 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
148 struct panfrost_screen
*screen
= pan_screen(gallium
->screen
);
151 bool has_draws
= ctx
->draw_count
> 0;
152 bool is_scanout
= panfrost_is_scanout(ctx
);
157 ret
= screen
->driver
->submit_vs_fs_job(ctx
, has_draws
, is_scanout
);
160 fprintf(stderr
, "panfrost_job_submit failed: %d\n", ret
);
162 /* Reset job counters */
164 ctx
->vertex_job_count
= 0;
165 ctx
->tiler_job_count
= 0;
169 panfrost_job_set_requirements(struct panfrost_context
*ctx
,
170 struct panfrost_job
*job
)
172 if (ctx
->rasterizer
&& ctx
->rasterizer
->base
.multisample
)
173 job
->requirements
|= PAN_REQ_MSAA
;
175 if (ctx
->depth_stencil
&& ctx
->depth_stencil
->depth
.writemask
)
176 job
->requirements
|= PAN_REQ_DEPTH_WRITE
;
180 panfrost_flush_jobs_reading_resource(struct panfrost_context
*panfrost
,
181 struct pipe_resource
*prsc
)
183 struct panfrost_resource
*rsc
= pan_resource(prsc
);
185 panfrost_flush_jobs_writing_resource(panfrost
, prsc
);
187 hash_table_foreach(panfrost
->jobs
, entry
) {
188 struct panfrost_job
*job
= entry
->data
;
190 if (_mesa_set_search(job
->bos
, rsc
->bo
)) {
191 printf("TODO: submit job for flush\n");
192 //panfrost_job_submit(panfrost, job);
199 panfrost_job_compare(const void *a
, const void *b
)
201 return memcmp(a
, b
, sizeof(struct panfrost_job_key
)) == 0;
205 panfrost_job_hash(const void *key
)
207 return _mesa_hash_data(key
, sizeof(struct panfrost_job_key
));
211 panfrost_job_init(struct panfrost_context
*ctx
)
213 /* TODO: Don't leak */
214 ctx
->jobs
= _mesa_hash_table_create(NULL
,
216 panfrost_job_compare
);
218 ctx
->write_jobs
= _mesa_hash_table_create(NULL
,
220 _mesa_key_pointer_equal
);