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 #define PAN_REQ_MSAA (1 << 0)
35 #define PAN_REQ_DEPTH_WRITE (1 << 1)
37 /* A panfrost_batch corresponds to a bound FBO we're rendering to,
38 * collecting over multiple draws. */
40 struct panfrost_batch
{
41 struct panfrost_context
*ctx
;
42 struct pipe_framebuffer_state key
;
44 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
47 /* Packed clear values, indexed by both render target as well as word.
48 * Essentially, a single pixel is packed, with some padding to bring it
49 * up to a 32-bit interval; that pixel is then duplicated over to fill
52 uint32_t clear_color
[PIPE_MAX_COLOR_BUFS
][4];
54 unsigned clear_stencil
;
56 /* Whether this job uses the corresponding requirement (PAN_REQ_*
58 unsigned requirements
;
60 /* The bounding box covered by this job, taking scissors into account.
61 * Basically, the bounding box we have to run fragment shaders for */
66 /* CPU pointers to the job descriptor headers. next_job is only
67 * set at submit time (since only then are all the dependencies
68 * known). The upshot is that this is append-only.
70 * These arrays contain the headers for the "primary batch", our jargon
71 * referring to the part of the panfrost_job that actually contains
72 * meaningful work. In an OpenGL ES setting, that means the
73 * SET_VALUE/VERTEX/TILER jobs. Excluded is specifically the FRAGMENT
74 * job, which is sent on as a secondary batch containing only a single
75 * hardware job. Since there's one and only one FRAGMENT job issued per
76 * panfrost_job, there is no need to do any scoreboarding / management;
77 * it's easy enough to open-code it and it's not like we can get any
79 struct util_dynarray headers
;
81 /* (And the GPU versions; TODO maybe combine) */
82 struct util_dynarray gpu_headers
;
84 /* The last job in the primary batch */
85 struct panfrost_transfer last_job
;
87 /* The first/last tiler job */
88 struct panfrost_transfer first_tiler
;
89 struct panfrost_transfer last_tiler
;
91 /* The first vertex job used as the input to a tiler job */
92 struct panfrost_transfer first_vertex_for_tiler
;
94 /* The first job. Notice we've created a linked list */
95 struct panfrost_transfer first_job
;
97 /* The number of jobs in the primary batch, essentially */
100 /* BOs referenced -- will be used for flushing logic */
101 struct hash_table
*bos
;
103 /* Current transient BO */
104 struct panfrost_bo
*transient_bo
;
106 /* Within the topmost transient BO, how much has been used? */
107 unsigned transient_offset
;
109 /* Polygon list bound to the batch, or NULL if none bound yet */
110 struct panfrost_bo
*polygon_list
;
112 /* Scratchpath BO bound to the batch, or NULL if none bound yet */
113 struct panfrost_bo
*scratchpad
;
115 /* Tiler heap BO bound to the batch, or NULL if none bound yet */
116 struct panfrost_bo
*tiler_heap
;
118 /* Dummy tiler BO bound to the batch, or NULL if none bound yet */
119 struct panfrost_bo
*tiler_dummy
;
121 /* Framebuffer descriptor. */
122 mali_ptr framebuffer
;
125 /* Functions for managing the above */
127 struct panfrost_batch
*
128 panfrost_get_batch_for_fbo(struct panfrost_context
*ctx
);
131 panfrost_batch_init(struct panfrost_context
*ctx
);
134 panfrost_batch_add_bo(struct panfrost_batch
*batch
, struct panfrost_bo
*bo
,
137 void panfrost_batch_add_fbo_bos(struct panfrost_batch
*batch
);
140 panfrost_batch_create_bo(struct panfrost_batch
*batch
, size_t size
,
141 uint32_t create_flags
, uint32_t access_flags
);
144 panfrost_batch_submit(struct panfrost_batch
*batch
);
147 panfrost_batch_set_requirements(struct panfrost_batch
*batch
);
150 panfrost_batch_get_polygon_list(struct panfrost_batch
*batch
, unsigned size
);
153 panfrost_batch_get_scratchpad(struct panfrost_batch
*batch
);
156 panfrost_batch_get_tiler_heap(struct panfrost_batch
*batch
);
159 panfrost_batch_get_tiler_dummy(struct panfrost_batch
*batch
);
162 panfrost_batch_clear(struct panfrost_batch
*batch
,
164 const union pipe_color_union
*color
,
165 double depth
, unsigned stencil
);
168 panfrost_batch_union_scissor(struct panfrost_batch
*batch
,
169 unsigned minx
, unsigned miny
,
170 unsigned maxx
, unsigned maxy
);
173 panfrost_batch_intersection_scissor(struct panfrost_batch
*batch
,
174 unsigned minx
, unsigned miny
,
175 unsigned maxx
, unsigned maxy
);
180 panfrost_scoreboard_queue_compute_job(
181 struct panfrost_batch
*batch
,
182 struct panfrost_transfer job
);
185 panfrost_scoreboard_queue_vertex_job(
186 struct panfrost_batch
*batch
,
187 struct panfrost_transfer vertex
,
188 bool requires_tiling
);
191 panfrost_scoreboard_queue_tiler_job(
192 struct panfrost_batch
*batch
,
193 struct panfrost_transfer tiler
);
196 panfrost_scoreboard_queue_fused_job(
197 struct panfrost_batch
*batch
,
198 struct panfrost_transfer vertex
,
199 struct panfrost_transfer tiler
);
201 panfrost_scoreboard_queue_fused_job_prepend(
202 struct panfrost_batch
*batch
,
203 struct panfrost_transfer vertex
,
204 struct panfrost_transfer tiler
);
207 panfrost_scoreboard_link_batch(struct panfrost_batch
*batch
);
210 panfrost_batch_is_scanout(struct panfrost_batch
*batch
);