Alyssa Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 1 | /* |
| 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 Rosenzweig | 965537df | 2020-07-22 10:23:50 -0400 | [diff] [blame] | 32 | #include "drm-uapi/drm_fourcc.h" |
Alyssa Rosenzweig | 58f1401 | 2020-02-18 12:17:59 -0500 | [diff] [blame] | 33 | #include "util/format/u_format.h" |
Alyssa Rosenzweig | 293f251 | 2020-07-09 13:42:25 -0400 | [diff] [blame] | 34 | #include "compiler/shader_enums.h" |
Alyssa Rosenzweig | 88dc4c2 | 2020-08-05 18:13:11 -0400 | [diff] [blame] | 35 | #include "midgard_pack.h" |
Alyssa Rosenzweig | a3d2936 | 2020-04-21 16:08:07 -0400 | [diff] [blame] | 36 | #include "pan_bo.h" |
Alyssa Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 37 | |
Alyssa Rosenzweig | 348d374 | 2020-07-20 18:03:56 -0400 | [diff] [blame] | 38 | #define PAN_MODIFIER_COUNT 4 |
| 39 | extern uint64_t pan_best_modifiers[PAN_MODIFIER_COUNT]; |
| 40 | |
Alyssa Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 41 | struct 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 Vizoso | 4d581a4 | 2020-04-27 16:49:22 +0200 | [diff] [blame] | 54 | struct panfrost_bo *checksum_bo; |
Alyssa Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 55 | |
| 56 | /* Has anything been written to this slice? */ |
| 57 | bool initialized; |
| 58 | }; |
| 59 | |
Alyssa Rosenzweig | 293f251 | 2020-07-09 13:42:25 -0400 | [diff] [blame] | 60 | struct pan_image { |
| 61 | /* Format and size */ |
| 62 | uint16_t width0, height0, depth0, array_size; |
| 63 | enum pipe_format format; |
Alyssa Rosenzweig | f008a63 | 2020-08-11 17:27:36 -0400 | [diff] [blame] | 64 | enum mali_texture_dimension dim; |
Alyssa Rosenzweig | 293f251 | 2020-07-09 13:42:25 -0400 | [diff] [blame] | 65 | 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 Rosenzweig | 965537df | 2020-07-22 10:23:50 -0400 | [diff] [blame] | 71 | uint64_t modifier; |
Alyssa Rosenzweig | 293f251 | 2020-07-09 13:42:25 -0400 | [diff] [blame] | 72 | }; |
| 73 | |
Alyssa Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 74 | unsigned |
| 75 | panfrost_compute_checksum_size( |
| 76 | struct panfrost_slice *slice, |
| 77 | unsigned width, |
| 78 | unsigned height); |
| 79 | |
Alyssa Rosenzweig | 58f1401 | 2020-02-18 12:17:59 -0500 | [diff] [blame] | 80 | /* AFBC */ |
| 81 | |
| 82 | bool |
| 83 | panfrost_format_supports_afbc(enum pipe_format format); |
| 84 | |
| 85 | unsigned |
| 86 | panfrost_afbc_header_size(unsigned width, unsigned height); |
| 87 | |
Alyssa Rosenzweig | d285ea6 | 2020-07-22 11:07:03 -0400 | [diff] [blame] | 88 | bool |
| 89 | panfrost_afbc_can_ytr(enum pipe_format format); |
| 90 | |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 91 | unsigned |
Alyssa Rosenzweig | a3d2936 | 2020-04-21 16:08:07 -0400 | [diff] [blame] | 92 | panfrost_estimate_texture_payload_size( |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 93 | unsigned first_level, unsigned last_level, |
| 94 | unsigned first_layer, unsigned last_layer, |
Alyssa Rosenzweig | 6088891 | 2020-07-15 11:39:08 -0400 | [diff] [blame] | 95 | unsigned nr_samples, |
Alyssa Rosenzweig | f008a63 | 2020-08-11 17:27:36 -0400 | [diff] [blame] | 96 | enum mali_texture_dimension dim, uint64_t modifier); |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 97 | |
| 98 | void |
| 99 | panfrost_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 Rosenzweig | f008a63 | 2020-08-11 17:27:36 -0400 | [diff] [blame] | 104 | enum mali_texture_dimension dim, |
Alyssa Rosenzweig | 965537df | 2020-07-22 10:23:50 -0400 | [diff] [blame] | 105 | uint64_t modifier, |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 106 | unsigned first_level, unsigned last_level, |
| 107 | unsigned first_layer, unsigned last_layer, |
Alyssa Rosenzweig | 41c06de | 2020-06-30 16:43:32 -0400 | [diff] [blame] | 108 | unsigned nr_samples, |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 109 | unsigned cube_stride, |
| 110 | unsigned swizzle, |
| 111 | mali_ptr base, |
| 112 | struct panfrost_slice *slices); |
| 113 | |
Tomeu Vizoso | e41894b | 2020-04-17 14:23:49 +0200 | [diff] [blame] | 114 | void |
| 115 | panfrost_new_texture_bifrost( |
Boris Brezillon | fefb3e9 | 2020-09-23 11:08:02 +0200 | [diff] [blame] | 116 | const struct panfrost_device *dev, |
Alyssa Rosenzweig | ad0b32c | 2020-08-06 18:12:28 -0400 | [diff] [blame] | 117 | struct mali_bifrost_texture_packed *out, |
Tomeu Vizoso | e41894b | 2020-04-17 14:23:49 +0200 | [diff] [blame] | 118 | uint16_t width, uint16_t height, |
| 119 | uint16_t depth, uint16_t array_size, |
| 120 | enum pipe_format format, |
Alyssa Rosenzweig | f008a63 | 2020-08-11 17:27:36 -0400 | [diff] [blame] | 121 | enum mali_texture_dimension dim, |
Alyssa Rosenzweig | 965537df | 2020-07-22 10:23:50 -0400 | [diff] [blame] | 122 | uint64_t modifier, |
Tomeu Vizoso | e41894b | 2020-04-17 14:23:49 +0200 | [diff] [blame] | 123 | unsigned first_level, unsigned last_level, |
| 124 | unsigned first_layer, unsigned last_layer, |
Alyssa Rosenzweig | 41c06de | 2020-06-30 16:43:32 -0400 | [diff] [blame] | 125 | unsigned nr_samples, |
Tomeu Vizoso | e41894b | 2020-04-17 14:23:49 +0200 | [diff] [blame] | 126 | unsigned cube_stride, |
| 127 | unsigned swizzle, |
| 128 | mali_ptr base, |
Alyssa Rosenzweig | a3d2936 | 2020-04-21 16:08:07 -0400 | [diff] [blame] | 129 | struct panfrost_slice *slices, |
Boris Brezillon | 8892c9c | 2020-10-18 10:27:48 +0200 | [diff] [blame] | 130 | const struct panfrost_ptr *payload); |
Tomeu Vizoso | e41894b | 2020-04-17 14:23:49 +0200 | [diff] [blame] | 131 | |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 132 | |
| 133 | unsigned |
| 134 | panfrost_get_layer_stride(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level); |
| 135 | |
| 136 | unsigned |
Alyssa Rosenzweig | 41c06de | 2020-06-30 16:43:32 -0400 | [diff] [blame] | 137 | panfrost_texture_offset(struct panfrost_slice *slices, bool is_3d, unsigned cube_stride, unsigned level, unsigned face, unsigned sample); |
Alyssa Rosenzweig | b929565 | 2020-02-18 14:20:16 -0500 | [diff] [blame] | 138 | |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 139 | /* Formats */ |
| 140 | |
Alyssa Rosenzweig | 861e7dc | 2020-05-15 18:43:41 -0400 | [diff] [blame] | 141 | struct panfrost_format { |
| 142 | enum mali_format hw; |
| 143 | unsigned bind; |
| 144 | }; |
| 145 | |
Alyssa Rosenzweig | d9b16ca | 2020-10-27 18:44:54 -0400 | [diff] [blame] | 146 | struct pan_blendable_format { |
| 147 | enum mali_color_buffer_internal_format internal; |
| 148 | enum mali_mfbd_color_format writeback; |
| 149 | }; |
| 150 | |
| 151 | struct pan_blendable_format |
| 152 | panfrost_blend_format(enum pipe_format format); |
| 153 | |
Alyssa Rosenzweig | 861e7dc | 2020-05-15 18:43:41 -0400 | [diff] [blame] | 154 | extern struct panfrost_format panfrost_pipe_format_table[PIPE_FORMAT_COUNT]; |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 155 | |
| 156 | bool |
| 157 | panfrost_is_z24s8_variant(enum pipe_format fmt); |
| 158 | |
Boris Brezillon | 5d5f755 | 2020-09-08 10:17:40 +0200 | [diff] [blame] | 159 | enum mali_z_internal_format |
| 160 | panfrost_get_z_internal_format(enum pipe_format fmt); |
| 161 | |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 162 | unsigned |
| 163 | panfrost_translate_swizzle_4(const unsigned char swizzle[4]); |
| 164 | |
| 165 | void |
| 166 | panfrost_invert_swizzle(const unsigned char *in, unsigned char *out); |
| 167 | |
| 168 | static inline unsigned |
| 169 | panfrost_get_default_swizzle(unsigned components) |
| 170 | { |
| 171 | switch (components) { |
| 172 | case 1: |
Alyssa Rosenzweig | cdc3276 | 2020-08-12 16:46:07 -0400 | [diff] [blame] | 173 | return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_0 << 3) | |
| 174 | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9); |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 175 | case 2: |
Alyssa Rosenzweig | cdc3276 | 2020-08-12 16:46:07 -0400 | [diff] [blame] | 176 | return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) | |
| 177 | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1 << 9); |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 178 | case 3: |
Alyssa Rosenzweig | cdc3276 | 2020-08-12 16:46:07 -0400 | [diff] [blame] | 179 | return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) | |
| 180 | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1 << 9); |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 181 | case 4: |
Alyssa Rosenzweig | cdc3276 | 2020-08-12 16:46:07 -0400 | [diff] [blame] | 182 | return (MALI_CHANNEL_R << 0) | (MALI_CHANNEL_G << 3) | |
| 183 | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9); |
Alyssa Rosenzweig | ad44f58 | 2020-02-18 18:11:42 -0500 | [diff] [blame] | 184 | default: |
| 185 | unreachable("Invalid number of components"); |
| 186 | } |
| 187 | } |
| 188 | |
Tomeu Vizoso | c4400b0 | 2020-05-01 07:36:31 +0200 | [diff] [blame] | 189 | static inline unsigned |
| 190 | panfrost_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 Vizoso | 3c98c45 | 2020-04-24 08:40:51 +0200 | [diff] [blame] | 196 | enum mali_format |
Alyssa Rosenzweig | 44155fa | 2020-10-27 21:10:27 -0400 | [diff] [blame] | 197 | panfrost_format_to_bifrost_blend(const struct util_format_description *desc, bool dither); |
Tomeu Vizoso | 3c98c45 | 2020-04-24 08:40:51 +0200 | [diff] [blame] | 198 | |
Alyssa Rosenzweig | 293f251 | 2020-07-09 13:42:25 -0400 | [diff] [blame] | 199 | struct pan_pool; |
| 200 | struct pan_scoreboard; |
| 201 | |
| 202 | void |
| 203 | panfrost_init_blit_shaders(struct panfrost_device *dev); |
| 204 | |
| 205 | void |
| 206 | panfrost_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 Brezillon | edd98aa | 2020-10-18 10:37:13 +0200 | [diff] [blame] | 215 | void |
| 216 | panfrost_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 Rosenzweig | 965537df | 2020-07-22 10:23:50 -0400 | [diff] [blame] | 225 | /* 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 Rosenzweig | 5ddf7ad | 2020-02-18 12:07:47 -0500 | [diff] [blame] | 231 | #endif |