2 * © Copyright 2018 Alyssa Rosenzweig
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:
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
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
28 #define _LARGEFILE64_SOURCE 1
29 #define CACHE_LINE_SIZE 1024 /* TODO */
32 #include "pan_resource.h"
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"
45 #include "midgard/midgard_compile.h"
47 /* Forward declare to avoid extra header dep */
48 struct prim_convert_context
;
50 #define MAX_VARYINGS 4096
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)
63 #define SET_BIT(lval, bit, cond) \
69 struct panfrost_constant_buffer
{
75 struct panfrost_query
{
76 /* Passthrough from Gallium */
80 /* Memory for the GPU to writeback the value of the query */
81 struct panfrost_transfer transfer
;
84 struct panfrost_fence
{
85 struct pipe_reference reference
;
89 #define PANFROST_MAX_TRANSIENT_ENTRIES 64
91 struct panfrost_transient_pool
{
92 /* Memory blocks in the pool */
93 struct panfrost_memory_entry
*entries
[PANFROST_MAX_TRANSIENT_ENTRIES
];
95 /* Number of entries we own */
98 /* Current entry that we are writing to, zero-indexed, strictly less than entry_count */
101 /* Number of bytes into the current entry we are */
104 /* Entry size (all entries must be homogenous) */
108 struct panfrost_context
{
109 /* Gallium context */
110 struct pipe_context base
;
112 /* Bound job and map of panfrost_job_key to jobs */
113 struct panfrost_job
*job
;
114 struct hash_table
*jobs
;
116 /* panfrost_resource -> panfrost_job */
117 struct hash_table
*write_jobs
;
119 /* Bit mask for supported PIPE_DRAW for this hardware */
122 struct pipe_framebuffer_state pipe_framebuffer
;
124 /* The number of concurrent FBOs allowed depends on the number of pools
125 * used; pools are ringed for parallelism opportunities */
127 struct panfrost_transient_pool transient_pools
[2];
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
;
139 struct panfrost_query
*occlusion_query
;
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
;
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. */
149 struct mali_shader_meta fragment_shader_core
;
151 /* Per-draw Dirty flags are setup like any other driver */
154 unsigned vertex_count
;
156 union mali_attr attributes
[PIPE_MAX_ATTRIBS
];
158 unsigned varying_height
;
160 struct mali_single_framebuffer vt_framebuffer_sfbd
;
161 struct bifrost_framebuffer vt_framebuffer_mfbd
;
163 /* TODO: Multiple uniform buffers (index =/= 0), finer updates? */
165 struct panfrost_constant_buffer constant_buffer
[PIPE_SHADER_TYPES
];
168 struct panfrost_rasterizer
*rasterizer
;
170 struct panfrost_shader_variants
*vs
;
171 struct panfrost_shader_variants
*fs
;
173 struct panfrost_vertex_state
*vertex
;
175 struct pipe_vertex_buffer vertex_buffers
[PIPE_MAX_ATTRIBS
];
178 struct panfrost_sampler_state
*samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
179 unsigned sampler_count
[PIPE_SHADER_TYPES
];
181 struct panfrost_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_SAMPLER_VIEWS
];
182 unsigned sampler_view_count
[PIPE_SHADER_TYPES
];
184 struct primconvert_context
*primconvert
;
185 struct blitter_context
*blitter
;
186 struct panfrost_job
*wallpaper_batch
;
188 struct panfrost_blend_state
*blend
;
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
;
196 /* True for t6XX, false for t8xx. */
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 */
209 /* Corresponds to the CSO */
211 struct panfrost_rasterizer
{
212 struct pipe_rasterizer_state base
;
214 /* Bitmask of front face, etc */
215 unsigned tiler_gl_enables
;
218 struct panfrost_blend_state
{
219 struct pipe_blend_state base
;
221 /* Whether a blend shader is in use */
222 bool has_blend_shader
;
224 /* Compiled fixed function command */
225 struct mali_blend_equation equation
;
228 /* Compiled blend shader */
229 mali_ptr blend_shader
;
230 int blend_work_count
;
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
238 /* A shader state corresponds to the actual, current variant of the shader */
239 struct panfrost_shader_state
{
240 struct pipe_shader_state
*base
;
242 /* Compiled, mapped descriptor, ready for the hardware */
244 struct mali_shader_meta
*tripipe
;
245 mali_ptr tripipe_gpu
;
247 /* Non-descript information */
250 bool writes_point_size
;
251 bool reads_point_coord
;
253 struct mali_attr_meta varyings
[PIPE_MAX_ATTRIBS
];
254 gl_varying_slot varyings_loc
[PIPE_MAX_ATTRIBS
];
256 unsigned sysval_count
;
257 unsigned sysval
[MAX_SYSVAL_COUNT
];
259 /* Information on this particular shader variant */
260 struct pipe_alpha_state alpha_state
;
262 uint16_t point_sprite_mask
;
263 unsigned point_sprite_upper_left
: 1;
266 /* A collection of varyings (the CSO) */
267 struct panfrost_shader_variants
{
268 struct pipe_shader_state base
;
270 struct panfrost_shader_state variants
[MAX_SHADER_VARIANTS
];
271 unsigned variant_count
;
273 /* The current active variant */
274 unsigned active_variant
;
277 struct panfrost_vertex_state
{
278 unsigned num_elements
;
280 struct pipe_vertex_element pipe
[PIPE_MAX_ATTRIBS
];
281 struct mali_attr_meta hw
[PIPE_MAX_ATTRIBS
];
284 struct panfrost_sampler_state
{
285 struct pipe_sampler_state base
;
286 struct mali_sampler_descriptor hw
;
289 /* Misnomer: Sampler view corresponds to textures, not samplers */
291 struct panfrost_sampler_view
{
292 struct pipe_sampler_view base
;
293 struct mali_texture_descriptor hw
;
296 static inline struct panfrost_context
*
297 pan_context(struct pipe_context
*pcontext
)
299 return (struct panfrost_context
*) pcontext
;
302 struct pipe_context
*
303 panfrost_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
);
306 panfrost_emit_for_draw(struct panfrost_context
*ctx
, bool with_vertex_data
);
308 struct panfrost_transfer
309 panfrost_vertex_tiler_job(struct panfrost_context
*ctx
, bool is_tiler
);
312 panfrost_get_default_swizzle(unsigned components
);
316 struct pipe_context
*pipe
,
317 struct pipe_fence_handle
**fence
,
321 panfrost_is_scanout(struct panfrost_context
*ctx
);
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
);
326 struct bifrost_framebuffer
327 panfrost_emit_mfbd(struct panfrost_context
*ctx
, unsigned vertex_count
);
329 struct mali_single_framebuffer
330 panfrost_emit_sfbd(struct panfrost_context
*ctx
, unsigned vertex_count
);
333 panfrost_fragment_job(struct panfrost_context
*ctx
, bool has_draws
);
336 panfrost_shader_compile(struct panfrost_context
*ctx
, struct mali_shader_meta
*meta
, const char *src
, int type
, struct panfrost_shader_state
*state
);