blob: fe25f9658ab847ff216c70e0eb544ecea49db444 [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,
130 struct panfrost_bo *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
146extern struct panfrost_format panfrost_pipe_format_table[PIPE_FORMAT_COUNT];
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500147
148bool
149panfrost_is_z24s8_variant(enum pipe_format fmt);
150
Boris Brezillon5d5f7552020-09-08 10:17:40 +0200151enum mali_z_internal_format
152panfrost_get_z_internal_format(enum pipe_format fmt);
153
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500154unsigned
155panfrost_translate_swizzle_4(const unsigned char swizzle[4]);
156
157void
158panfrost_invert_swizzle(const unsigned char *in, unsigned char *out);
159
160static inline unsigned
161panfrost_get_default_swizzle(unsigned components)
162{
163 switch (components) {
164 case 1:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400165 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_0 << 3) |
166 (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500167 case 2:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400168 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
169 (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500170 case 3:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400171 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
172 (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500173 case 4:
Alyssa Rosenzweigcdc32762020-08-12 16:46:07 -0400174 return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) |
175 (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9);
Alyssa Rosenzweigad44f582020-02-18 18:11:42 -0500176 default:
177 unreachable("Invalid number of components");
178 }
179}
180
Tomeu Vizosoc4400b02020-05-01 07:36:31 +0200181static inline unsigned
182panfrost_bifrost_swizzle(unsigned components)
183{
184 /* Set all components to 0 and force w if needed */
185 return components < 4 ? 0x10 : 0x00;
186}
187
Tomeu Vizoso3c98c452020-04-24 08:40:51 +0200188enum mali_format
189panfrost_format_to_bifrost_blend(const struct util_format_description *desc);
190
Alyssa Rosenzweig293f2512020-07-09 13:42:25 -0400191struct pan_pool;
192struct pan_scoreboard;
193
194void
195panfrost_init_blit_shaders(struct panfrost_device *dev);
196
197void
198panfrost_load_midg(
199 struct pan_pool *pool,
200 struct pan_scoreboard *scoreboard,
201 mali_ptr blend_shader,
202 mali_ptr fbd,
203 mali_ptr coordinates, unsigned vertex_count,
204 struct pan_image *image,
205 unsigned loc);
206
Alyssa Rosenzweig965537df2020-07-22 10:23:50 -0400207/* DRM modifier helper */
208
209#define drm_is_afbc(mod) \
210 ((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \
211 (DRM_FORMAT_MOD_VENDOR_ARM << 4)))
212
Alyssa Rosenzweig5ddf7ad2020-02-18 12:07:47 -0500213#endif