blob: 70f2ca211d60e18de29316d0d89033a8d012b5f6 [file] [log] [blame]
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -05001/*
2 * Copyright (C) 2008 VMware, Inc.
3 * Copyright (C) 2014 Broadcom
4 * Copyright (C) 2018-2019 Alyssa Rosenzweig
5 * Copyright (C) 2019-2020 Collabora, Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 */
27
28#ifndef __PAN_TEXTURE_H
29#define __PAN_TEXTURE_H
30
31#include <stdbool.h>
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -040032#include "drm-uapi/drm_fourcc.h"
Alyssa Rosenzweig58f14012020-02-18 12:17:59 -050033#include "util/format/u_format.h"
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -040034#include "compiler/shader_enums.h"
Alyssa Rosenzweig88dc4c22020-08-05 18:13:11 -040035#include "midgard_pack.h"
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -040036#include "pan_bo.h"
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -050037
Alyssa Rosenzweig348d3742020-07-20 18:03:56 -040038#define PAN_MODIFIER_COUNT 4
39extern uint64_t pan_best_modifiers[PAN_MODIFIER_COUNT];
40
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -050041struct panfrost_slice {
42 unsigned offset;
43 unsigned stride;
44 unsigned size0;
45
46 /* If there is a header preceding each slice, how big is
47 * that header? Used for AFBC */
48 unsigned header_size;
49
50 /* If checksumming is enabled following the slice, what
51 * is its offset/stride? */
52 unsigned checksum_offset;
53 unsigned checksum_stride;
Tomeu Vizoso4d581a42020-04-27 16:49:22 +020054 struct panfrost_bo *checksum_bo;
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -050055
56 /* Has anything been written to this slice? */
57 bool initialized;
58};
59
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -040060struct pan_image {
61 /* Format and size */
62 uint16_t width0, height0, depth0, array_size;
63 enum pipe_format format;
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -040064 enum mali_texture_dimension dim;
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -040065 unsigned first_level, last_level;
66 unsigned first_layer, last_layer;
67 unsigned nr_samples;
68 struct panfrost_bo *bo;
69 struct panfrost_slice *slices;
70 unsigned cubemap_stride;
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -040071 uint64_t modifier;
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -040072};
73
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -050074unsigned
75panfrost_compute_checksum_size(
76 struct panfrost_slice *slice,
77 unsigned width,
78 unsigned height);
79
Alyssa Rosenzweig58f14012020-02-18 12:17:59 -050080/* AFBC */
81
82bool
83panfrost_format_supports_afbc(enum pipe_format format);
84
85unsigned
86panfrost_afbc_header_size(unsigned width, unsigned height);
87
Alyssa Rosenzweigd285ea62020-07-22 11:07:03 -040088bool
89panfrost_afbc_can_ytr(enum pipe_format format);
90
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -050091unsigned
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -040092panfrost_estimate_texture_payload_size(
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -050093 unsigned first_level, unsigned last_level,
94 unsigned first_layer, unsigned last_layer,
Alyssa Rosenzweig60888912020-07-15 11:39:08 -040095 unsigned nr_samples,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -040096 enum mali_texture_dimension dim, uint64_t modifier);
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -050097
98void
99panfrost_new_texture(
100 void *out,
101 uint16_t width, uint16_t height,
102 uint16_t depth, uint16_t array_size,
103 enum pipe_format format,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -0400104 enum mali_texture_dimension dim,
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -0400105 uint64_t modifier,
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -0500106 unsigned first_level, unsigned last_level,
107 unsigned first_layer, unsigned last_layer,
Alyssa Rosenzweig41c06de2020-06-30 16:43:32 -0400108 unsigned nr_samples,
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -0500109 unsigned cube_stride,
110 unsigned swizzle,
111 mali_ptr base,
112 struct panfrost_slice *slices);
113
Tomeu Vizosoe41894b2020-04-17 14:23:49 +0200114void
115panfrost_new_texture_bifrost(
Boris Brezillonfefb3e92020-09-23 11:08:02 +0200116 const struct panfrost_device *dev,
Alyssa Rosenzweigad0b32c2020-08-06 18:12:28 -0400117 struct mali_bifrost_texture_packed *out,
Tomeu Vizosoe41894b2020-04-17 14:23:49 +0200118 uint16_t width, uint16_t height,
119 uint16_t depth, uint16_t array_size,
120 enum pipe_format format,
Alyssa Rosenzweigf008a632020-08-11 17:27:36 -0400121 enum mali_texture_dimension dim,
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -0400122 uint64_t modifier,
Tomeu Vizosoe41894b2020-04-17 14:23:49 +0200123 unsigned first_level, unsigned last_level,
124 unsigned first_layer, unsigned last_layer,
Alyssa Rosenzweig41c06de2020-06-30 16:43:32 -0400125 unsigned nr_samples,
Tomeu Vizosoe41894b2020-04-17 14:23:49 +0200126 unsigned cube_stride,
127 unsigned swizzle,
128 mali_ptr base,
Alyssa Rosenzweiga3d29362020-04-21 16:08:07 -0400129 struct panfrost_slice *slices,
Boris Brezillon8892c9c2020-10-18 10:27:48 +0200130 const struct panfrost_ptr *payload);
Tomeu Vizosoe41894b2020-04-17 14:23:49 +0200131
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -0500132
133unsigned
134panfrost_get_layer_stride(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level);
135
136unsigned
Alyssa Rosenzweig41c06de2020-06-30 16:43:32 -0400137panfrost_texture_offset(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level, unsigned face, unsigned sample);
Alyssa Rosenzweigb9295652020-02-18 14:20:16 -0500138
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500139/* Formats */
140
Alyssa Rosenzweig861e7dc2020-05-15 18:43:41 -0400141struct panfrost_format {
142 enum mali_format hw;
143 unsigned bind;
144};
145
Alyssa Rosenzweigd9b16ca2020-10-27 18:44:54 -0400146struct pan_blendable_format {
147 enum mali_color_buffer_internal_format internal;
148 enum mali_mfbd_color_format writeback;
149};
150
151struct pan_blendable_format
152panfrost_blend_format(enum pipe_format format);
153
Alyssa Rosenzweig861e7dc2020-05-15 18:43:41 -0400154extern struct panfrost_format panfrost_pipe_format_table[PIPE_FORMAT_COUNT];
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500155
156bool
157panfrost_is_z24s8_variant(enum pipe_format fmt);
158
Boris Brezillon5d5f7552020-09-08 10:17:40 +0200159enum mali_z_internal_format
160panfrost_get_z_internal_format(enum pipe_format fmt);
161
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500162unsigned
163panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
164
165void
166panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
167
168static inline unsigned
169panfrost_get_default_swizzle(unsigned components)
170{
171 switch (components) {
172 case 1:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400173 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_0 << 3) |
174 (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500175 case 2:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400176 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
177 (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500178 case 3:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400179 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
180 (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500181 case 4:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400182 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
183 (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500184 default:
185 unreachable("Invalid number of components");
186 }
187}
188
Tomeu Vizosoc4400b02020-05-01 07:36:31 +0200189static inline unsigned
190panfrost_bifrost_swizzle(unsigned components)
191{
192 /* Set all components to 0 and force w if needed */
193 return components < 4 ? 0x10 : 0x00;
194}
195
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200196enum mali_format
Alyssa Rosenzweig44155fa2020-10-27 21:10:27 -0400197panfrost_format_to_bifrost_blend(const struct util_format_description *desc, bool dither);
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200198
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -0400199struct pan_pool;
200struct pan_scoreboard;
201
202void
203panfrost_init_blit_shaders(struct panfrost_device *dev);
204
205void
206panfrost_load_midg(
207 struct pan_pool *pool,
208 struct pan_scoreboard *scoreboard,
209 mali_ptr blend_shader,
210 mali_ptr fbd,
211 mali_ptr coordinates, unsigned vertex_count,
212 struct pan_image *image,
213 unsigned loc);
214
Boris Brezillonedd98aa2020-10-18 10:37:13 +0200215void
216panfrost_load_bifrost(struct pan_pool *pool,
217 struct pan_scoreboard *scoreboard,
218 mali_ptr blend_shader,
219 mali_ptr thread_storage,
220 mali_ptr tiler,
221 mali_ptr coordinates, unsigned vertex_count,
222 struct pan_image *image,
223 unsigned loc);
224
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -0400225/* DRM modifier helper */
226
227#define drm_is_afbc(mod) \
228 ((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \
229 (DRM_FORMAT_MOD_VENDOR_ARM << 4)))
230
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -0500231#endif