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
29 #include "util/u_dynarray.h"
30 #include "pipe/p_state.h"
31 #include "pan_allocate.h"
32 #include "pan_resource.h"
34 /* Used as a hash table key */
36 struct panfrost_job_key
{
37 struct pipe_surface
*cbufs
[4];
38 struct pipe_surface
*zsbuf
;
41 #define PAN_REQ_MSAA (1 << 0)
42 #define PAN_REQ_DEPTH_WRITE (1 << 1)
44 /* A panfrost_job corresponds to a bound FBO we're rendering to,
45 * collecting over multiple draws. */
48 struct panfrost_context
*ctx
;
49 struct panfrost_job_key key
;
51 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
54 /* Packed clear values, indexed by both render target as well as word.
55 * Essentially, a single pixel is packed, with some padding to bring it
56 * up to a 32-bit interval; that pixel is then duplicated over to fill
59 uint32_t clear_color
[PIPE_MAX_COLOR_BUFS
][4];
61 unsigned clear_stencil
;
63 /* Whether this job uses the corresponding requirement (PAN_REQ_*
65 unsigned requirements
;
67 /* The bounding box covered by this job, taking scissors into account.
68 * Basically, the bounding box we have to run fragment shaders for */
73 /* CPU pointers to the job descriptor headers. next_job is only
74 * set at submit time (since only then are all the dependencies
75 * known). The upshot is that this is append-only.
77 * These arrays contain the headers for the "primary batch", our jargon
78 * referring to the part of the panfrost_job that actually contains
79 * meaningful work. In an OpenGL ES setting, that means the
80 * SET_VALUE/VERTEX/TILER jobs. Excluded is specifically the FRAGMENT
81 * job, which is sent on as a secondary batch containing only a single
82 * hardware job. Since there's one and only one FRAGMENT job issued per
83 * panfrost_job, there is no need to do any scoreboarding / management;
84 * it's easy enough to open-code it and it's not like we can get any
86 struct util_dynarray headers
;
88 /* (And the GPU versions; TODO maybe combine) */
89 struct util_dynarray gpu_headers
;
91 /* The last job in the primary batch */
92 struct panfrost_transfer last_job
;
94 /* The first/last tiler job */
95 struct panfrost_transfer first_tiler
;
96 struct panfrost_transfer last_tiler
;
98 /* The first vertex job used as the input to a tiler job */
99 struct panfrost_transfer first_vertex_for_tiler
;
101 /* The first job. Notice we've created a linked list */
102 struct panfrost_transfer first_job
;
104 /* The number of jobs in the primary batch, essentially */
107 /* BOs referenced -- will be used for flushing logic */
110 /* Indices of transient BOs referenced */
111 struct util_dynarray transient_indices
;
113 /* Within the topmost transient BO, how much has been used? */
114 unsigned transient_offset
;
117 /* Functions for managing the above */
119 struct panfrost_job
*
120 panfrost_create_job(struct panfrost_context
*ctx
);
123 panfrost_free_job(struct panfrost_context
*ctx
, struct panfrost_job
*job
);
125 struct panfrost_job
*
126 panfrost_get_job(struct panfrost_context
*ctx
,
127 struct pipe_surface
**cbufs
, struct pipe_surface
*zsbuf
);
129 struct panfrost_job
*
130 panfrost_get_job_for_fbo(struct panfrost_context
*ctx
);
133 panfrost_job_init(struct panfrost_context
*ctx
);
136 panfrost_job_add_bo(struct panfrost_job
*job
, struct panfrost_bo
*bo
);
139 panfrost_flush_jobs_writing_resource(struct panfrost_context
*panfrost
,
140 struct pipe_resource
*prsc
);
143 panfrost_flush_jobs_reading_resource(struct panfrost_context
*panfrost
,
144 struct pipe_resource
*prsc
);
147 panfrost_job_submit(struct panfrost_context
*ctx
, struct panfrost_job
*job
);
150 panfrost_job_set_requirements(struct panfrost_context
*ctx
,
151 struct panfrost_job
*job
);
154 panfrost_job_clear(struct panfrost_context
*ctx
,
155 struct panfrost_job
*job
,
157 const union pipe_color_union
*color
,
158 double depth
, unsigned stencil
);
161 panfrost_job_union_scissor(struct panfrost_job
*job
,
162 unsigned minx
, unsigned miny
,
163 unsigned maxx
, unsigned maxy
);
168 panfrost_scoreboard_queue_compute_job(
169 struct panfrost_job
*batch
,
170 struct panfrost_transfer job
);
173 panfrost_scoreboard_queue_vertex_job(
174 struct panfrost_job
*batch
,
175 struct panfrost_transfer vertex
,
176 bool requires_tiling
);
179 panfrost_scoreboard_queue_tiler_job(
180 struct panfrost_job
*batch
,
181 struct panfrost_transfer tiler
);
184 panfrost_scoreboard_queue_fused_job(
185 struct panfrost_job
*batch
,
186 struct panfrost_transfer vertex
,
187 struct panfrost_transfer tiler
);
189 panfrost_scoreboard_queue_fused_job_prepend(
190 struct panfrost_job
*batch
,
191 struct panfrost_transfer vertex
,
192 struct panfrost_transfer tiler
);
195 panfrost_scoreboard_link_batch(struct panfrost_job
*batch
);