panfrost: Track point sprites in fragment shader key
[mesa.git] / src / gallium / drivers / panfrost / pan_context.h
1 /*
2 * © Copyright 2018 Alyssa Rosenzweig
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 */
24
25 #ifndef __BUILDER_H__
26 #define __BUILDER_H__
27
28 #define _LARGEFILE64_SOURCE 1
29 #define CACHE_LINE_SIZE 1024 /* TODO */
30 #include <sys/mman.h>
31 #include <assert.h>
32 #include "pan_resource.h"
33 #include "pan_job.h"
34
35 #include "pipe/p_compiler.h"
36 #include "pipe/p_config.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39 #include "pipe/p_format.h"
40 #include "pipe/p_screen.h"
41 #include "pipe/p_state.h"
42 #include "util/u_blitter.h"
43 #include "util/hash_table.h"
44
45 #include "midgard/midgard_compile.h"
46
47 /* Forward declare to avoid extra header dep */
48 struct prim_convert_context;
49
50 #define MAX_VARYINGS 4096
51
52 //#define PAN_DIRTY_CLEAR (1 << 0)
53 #define PAN_DIRTY_RASTERIZER (1 << 2)
54 #define PAN_DIRTY_FS (1 << 3)
55 #define PAN_DIRTY_FRAG_CORE (PAN_DIRTY_FS) /* Dirty writes are tied */
56 #define PAN_DIRTY_VS (1 << 4)
57 #define PAN_DIRTY_VERTEX (1 << 5)
58 #define PAN_DIRTY_VERT_BUF (1 << 6)
59 //#define PAN_DIRTY_VIEWPORT (1 << 7)
60 #define PAN_DIRTY_SAMPLERS (1 << 8)
61 #define PAN_DIRTY_TEXTURES (1 << 9)
62
63 #define SET_BIT(lval, bit, cond) \
64 if (cond) \
65 lval |= (bit); \
66 else \
67 lval &= ~(bit);
68
69 struct panfrost_constant_buffer {
70 bool dirty;
71 size_t size;
72 void *buffer;
73 };
74
75 struct panfrost_query {
76 /* Passthrough from Gallium */
77 unsigned type;
78 unsigned index;
79
80 /* Memory for the GPU to writeback the value of the query */
81 struct panfrost_transfer transfer;
82 };
83
84 struct panfrost_fence {
85 struct pipe_reference reference;
86 int fd;
87 };
88
89 #define PANFROST_MAX_TRANSIENT_ENTRIES 64
90
91 struct panfrost_transient_pool {
92 /* Memory blocks in the pool */
93 struct panfrost_memory_entry *entries[PANFROST_MAX_TRANSIENT_ENTRIES];
94
95 /* Number of entries we own */
96 unsigned entry_count;
97
98 /* Current entry that we are writing to, zero-indexed, strictly less than entry_count */
99 unsigned entry_index;
100
101 /* Number of bytes into the current entry we are */
102 off_t entry_offset;
103
104 /* Entry size (all entries must be homogenous) */
105 size_t entry_size;
106 };
107
108 struct panfrost_context {
109 /* Gallium context */
110 struct pipe_context base;
111
112 /* Bound job and map of panfrost_job_key to jobs */
113 struct panfrost_job *job;
114 struct hash_table *jobs;
115
116 /* panfrost_resource -> panfrost_job */
117 struct hash_table *write_jobs;
118
119 /* Bit mask for supported PIPE_DRAW for this hardware */
120 unsigned draw_modes;
121
122 struct pipe_framebuffer_state pipe_framebuffer;
123
124 /* The number of concurrent FBOs allowed depends on the number of pools
125 * used; pools are ringed for parallelism opportunities */
126
127 struct panfrost_transient_pool transient_pools[2];
128 int cmdstream_i;
129
130 struct panfrost_memory cmdstream_persistent;
131 struct panfrost_memory shaders;
132 struct panfrost_memory scratchpad;
133 struct panfrost_memory tiler_heap;
134 struct panfrost_memory varying_mem;
135 struct panfrost_memory tiler_polygon_list;
136 struct panfrost_memory tiler_dummy;
137 struct panfrost_memory depth_stencil_buffer;
138
139 struct panfrost_query *occlusion_query;
140
141 /* Each draw has corresponding vertex and tiler payloads */
142 struct midgard_payload_vertex_tiler payload_vertex;
143 struct midgard_payload_vertex_tiler payload_tiler;
144
145 /* The fragment shader binary itself is pointed here (for the tripipe) but
146 * also everything else in the shader core, including blending, the
147 * stencil/depth tests, etc. Refer to the presentations. */
148
149 struct mali_shader_meta fragment_shader_core;
150
151 /* Per-draw Dirty flags are setup like any other driver */
152 int dirty;
153
154 unsigned vertex_count;
155
156 union mali_attr attributes[PIPE_MAX_ATTRIBS];
157
158 unsigned varying_height;
159
160 struct mali_single_framebuffer vt_framebuffer_sfbd;
161 struct bifrost_framebuffer vt_framebuffer_mfbd;
162
163 /* TODO: Multiple uniform buffers (index =/= 0), finer updates? */
164
165 struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES];
166
167 /* CSOs */
168 struct panfrost_rasterizer *rasterizer;
169
170 struct panfrost_shader_variants *vs;
171 struct panfrost_shader_variants *fs;
172
173 struct panfrost_vertex_state *vertex;
174
175 struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
176 uint32_t vb_mask;
177
178 struct panfrost_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
179 unsigned sampler_count[PIPE_SHADER_TYPES];
180
181 struct panfrost_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
182 unsigned sampler_view_count[PIPE_SHADER_TYPES];
183
184 struct primconvert_context *primconvert;
185 struct blitter_context *blitter;
186 struct panfrost_job *wallpaper_batch;
187
188 struct panfrost_blend_state *blend;
189
190 struct pipe_viewport_state pipe_viewport;
191 struct pipe_scissor_state scissor;
192 struct pipe_blend_color blend_color;
193 struct pipe_depth_stencil_alpha_state *depth_stencil;
194 struct pipe_stencil_ref stencil_ref;
195
196 /* True for t6XX, false for t8xx. */
197 bool is_t6xx;
198
199 /* If set, we'll require the use of single render-target framebuffer
200 * descriptors (SFBD), for older hardware -- specifically, <T760 hardware, If
201 * false, we'll use the MFBD no matter what. New hardware -does- retain support
202 * for SFBD, and in theory we could flip between them on a per-RT basis, but
203 * there's no real advantage to doing so */
204 bool require_sfbd;
205
206 uint32_t out_sync;
207 };
208
209 /* Corresponds to the CSO */
210
211 struct panfrost_rasterizer {
212 struct pipe_rasterizer_state base;
213
214 /* Bitmask of front face, etc */
215 unsigned tiler_gl_enables;
216 };
217
218 struct panfrost_blend_state {
219 struct pipe_blend_state base;
220
221 /* Whether a blend shader is in use */
222 bool has_blend_shader;
223
224 /* Compiled fixed function command */
225 struct mali_blend_equation equation;
226 float constant;
227
228 /* Compiled blend shader */
229 mali_ptr blend_shader;
230 int blend_work_count;
231 };
232
233 /* Variants bundle together to form the backing CSO, bundling multiple
234 * shaders with varying emulated features baked in (alpha test
235 * parameters, etc) */
236 #define MAX_SHADER_VARIANTS 8
237
238 /* A shader state corresponds to the actual, current variant of the shader */
239 struct panfrost_shader_state {
240 struct pipe_shader_state *base;
241
242 /* Compiled, mapped descriptor, ready for the hardware */
243 bool compiled;
244 struct mali_shader_meta *tripipe;
245 mali_ptr tripipe_gpu;
246
247 /* Non-descript information */
248 int uniform_count;
249 bool can_discard;
250 bool writes_point_size;
251 bool reads_point_coord;
252
253 struct mali_attr_meta varyings[PIPE_MAX_ATTRIBS];
254 gl_varying_slot varyings_loc[PIPE_MAX_ATTRIBS];
255
256 unsigned sysval_count;
257 unsigned sysval[MAX_SYSVAL_COUNT];
258
259 /* Information on this particular shader variant */
260 struct pipe_alpha_state alpha_state;
261
262 uint16_t point_sprite_mask;
263 unsigned point_sprite_upper_left : 1;
264 };
265
266 /* A collection of varyings (the CSO) */
267 struct panfrost_shader_variants {
268 struct pipe_shader_state base;
269
270 struct panfrost_shader_state variants[MAX_SHADER_VARIANTS];
271 unsigned variant_count;
272
273 /* The current active variant */
274 unsigned active_variant;
275 };
276
277 struct panfrost_vertex_state {
278 unsigned num_elements;
279
280 struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
281 struct mali_attr_meta hw[PIPE_MAX_ATTRIBS];
282 };
283
284 struct panfrost_sampler_state {
285 struct pipe_sampler_state base;
286 struct mali_sampler_descriptor hw;
287 };
288
289 /* Misnomer: Sampler view corresponds to textures, not samplers */
290
291 struct panfrost_sampler_view {
292 struct pipe_sampler_view base;
293 struct mali_texture_descriptor hw;
294 };
295
296 static inline struct panfrost_context *
297 pan_context(struct pipe_context *pcontext)
298 {
299 return (struct panfrost_context *) pcontext;
300 }
301
302 struct pipe_context *
303 panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags);
304
305 void
306 panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data);
307
308 struct panfrost_transfer
309 panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler);
310
311 unsigned
312 panfrost_get_default_swizzle(unsigned components);
313
314 void
315 panfrost_flush(
316 struct pipe_context *pipe,
317 struct pipe_fence_handle **fence,
318 unsigned flags);
319
320 bool
321 panfrost_is_scanout(struct panfrost_context *ctx);
322
323 mali_ptr panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws);
324 mali_ptr panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws);
325
326 struct bifrost_framebuffer
327 panfrost_emit_mfbd(struct panfrost_context *ctx, unsigned vertex_count);
328
329 struct mali_single_framebuffer
330 panfrost_emit_sfbd(struct panfrost_context *ctx, unsigned vertex_count);
331
332 mali_ptr
333 panfrost_fragment_job(struct panfrost_context *ctx, bool has_draws);
334
335 void
336 panfrost_shader_compile(struct panfrost_context *ctx, struct mali_shader_meta *meta, const char *src, int type, struct panfrost_shader_state *state);
337
338 #endif