Alyssa Rosenzweig | 629c516 | 2019-07-08 09:25:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 VMware, Inc. |
| 3 | * Copyright (C) 2014 Broadcom |
| 4 | * Copyright (C) 2018 Alyssa Rosenzweig |
| 5 | * Copyright (C) 2019 Collabora, Ltd. |
Alyssa Rosenzweig | 1697760 | 2019-07-23 10:41:25 -0700 | [diff] [blame] | 6 | * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
Alyssa Rosenzweig | 629c516 | 2019-07-08 09:25:08 -0700 | [diff] [blame] | 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 14 | * |
Alyssa Rosenzweig | 629c516 | 2019-07-08 09:25:08 -0700 | [diff] [blame] | 15 | * The above copyright notice and this permission notice (including the next |
| 16 | * paragraph) shall be included in all copies or substantial portions of the |
| 17 | * Software. |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 18 | * |
Alyssa Rosenzweig | 629c516 | 2019-07-08 09:25:08 -0700 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 26 | * |
Alyssa Rosenzweig | 629c516 | 2019-07-08 09:25:08 -0700 | [diff] [blame] | 27 | */ |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 28 | |
Tomeu Vizoso | 97f2d04 | 2019-03-08 15:24:57 +0100 | [diff] [blame] | 29 | #include "util/u_debug.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 30 | #include "util/u_memory.h" |
Eric Anholt | 882ca6d | 2019-06-27 15:05:31 -0700 | [diff] [blame] | 31 | #include "util/format/u_format.h" |
| 32 | #include "util/format/u_format_s3tc.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 33 | #include "util/u_video.h" |
Alyssa Rosenzweig | 8f4485e | 2019-02-05 02:19:38 +0000 | [diff] [blame] | 34 | #include "util/u_screen.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 35 | #include "util/os_time.h" |
Alyssa Rosenzweig | 1f8b653 | 2019-08-05 08:20:24 -0700 | [diff] [blame] | 36 | #include "util/u_process.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 37 | #include "pipe/p_defines.h" |
| 38 | #include "pipe/p_screen.h" |
| 39 | #include "draw/draw_context.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 40 | |
| 41 | #include <fcntl.h> |
| 42 | |
Eric Engestrom | f137480 | 2019-02-12 18:18:03 +0000 | [diff] [blame] | 43 | #include "drm-uapi/drm_fourcc.h" |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 44 | #include "drm-uapi/panfrost_drm.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 45 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 46 | #include "pan_bo.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 47 | #include "pan_screen.h" |
| 48 | #include "pan_resource.h" |
| 49 | #include "pan_public.h" |
Tomeu Vizoso | 97f2d04 | 2019-03-08 15:24:57 +0100 | [diff] [blame] | 50 | #include "pan_util.h" |
Alyssa Rosenzweig | fc7bcee | 2019-06-11 12:25:35 -0700 | [diff] [blame] | 51 | #include "pandecode/decode.h" |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 52 | |
| 53 | #include "pan_context.h" |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 54 | #include "midgard/midgard_compile.h" |
Tomeu Vizoso | 6887ff4 | 2019-11-28 10:21:06 +0100 | [diff] [blame] | 55 | #include "panfrost-quirks.h" |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 56 | |
Tomeu Vizoso | 97f2d04 | 2019-03-08 15:24:57 +0100 | [diff] [blame] | 57 | static const struct debug_named_value debug_options[] = { |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 58 | {"msgs", PAN_DBG_MSGS, "Print debug messages"}, |
| 59 | {"trace", PAN_DBG_TRACE, "Trace the command stream"}, |
| 60 | {"deqp", PAN_DBG_DEQP, "Hacks for dEQP"}, |
Alyssa Rosenzweig | 5ad00fb | 2019-07-15 14:15:24 -0700 | [diff] [blame] | 61 | {"afbc", PAN_DBG_AFBC, "Enable non-conformant AFBC impl"}, |
Tomeu Vizoso | 63ae9e6 | 2019-12-09 08:39:59 +0100 | [diff] [blame] | 62 | {"sync", PAN_DBG_SYNC, "Wait for each job's completion and check for any GPU fault"}, |
Alyssa Rosenzweig | 271726e | 2019-12-13 15:13:02 -0500 | [diff] [blame] | 63 | {"precompile", PAN_DBG_PRECOMPILE, "Precompile shaders for shader-db"}, |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 64 | {"gles3", PAN_DBG_GLES3, "Enable experimental GLES3 implementation"}, |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 65 | DEBUG_NAMED_VALUE_END |
Tomeu Vizoso | 97f2d04 | 2019-03-08 15:24:57 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | DEBUG_GET_ONCE_FLAGS_OPTION(pan_debug, "PAN_MESA_DEBUG", debug_options, 0) |
| 69 | |
| 70 | int pan_debug = 0; |
| 71 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 72 | static const char * |
| 73 | panfrost_get_name(struct pipe_screen *screen) |
| 74 | { |
Alyssa Rosenzweig | 7c972eb | 2019-12-09 16:02:17 -0500 | [diff] [blame] | 75 | return panfrost_model_name(pan_screen(screen)->gpu_id); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static const char * |
| 79 | panfrost_get_vendor(struct pipe_screen *screen) |
| 80 | { |
Alyssa Rosenzweig | 7c972eb | 2019-12-09 16:02:17 -0500 | [diff] [blame] | 81 | return "Panfrost"; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static const char * |
| 85 | panfrost_get_device_vendor(struct pipe_screen *screen) |
| 86 | { |
| 87 | return "Arm"; |
| 88 | } |
| 89 | |
| 90 | static int |
| 91 | panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param) |
| 92 | { |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 93 | /* We expose in-dev stuff for dEQP that we don't want apps to use yet */ |
| 94 | bool is_deqp = pan_debug & PAN_DBG_DEQP; |
| 95 | |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 96 | /* Our GLES3 implementation is WIP */ |
| 97 | bool is_gles3 = pan_debug & PAN_DBG_GLES3; |
| 98 | is_gles3 |= is_deqp; |
| 99 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 100 | switch (param) { |
| 101 | case PIPE_CAP_NPOT_TEXTURES: |
| 102 | case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: |
| 103 | case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: |
Erik Faye-Lund | 39e7fbf | 2019-07-05 16:36:41 +0200 | [diff] [blame] | 104 | case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD: |
Erik Faye-Lund | 39e7fbf | 2019-07-05 16:36:41 +0200 | [diff] [blame] | 105 | case PIPE_CAP_VERTEX_SHADER_SATURATE: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 106 | case PIPE_CAP_POINT_SPRITE: |
| 107 | return 1; |
| 108 | |
| 109 | case PIPE_CAP_MAX_RENDER_TARGETS: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 110 | return is_gles3 ? 4 : 1; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 111 | |
Alyssa Rosenzweig | 4fee7b3 | 2019-10-15 21:36:48 -0400 | [diff] [blame] | 112 | /* Throttling frames breaks pipelining */ |
| 113 | case PIPE_CAP_THROTTLE: |
| 114 | return 0; |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 115 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 116 | case PIPE_CAP_OCCLUSION_QUERY: |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 117 | return 1; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 118 | case PIPE_CAP_QUERY_TIME_ELAPSED: |
| 119 | case PIPE_CAP_QUERY_PIPELINE_STATISTICS: |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 120 | case PIPE_CAP_QUERY_TIMESTAMP: |
| 121 | case PIPE_CAP_QUERY_SO_OVERFLOW: |
| 122 | return 0; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 123 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 124 | case PIPE_CAP_TEXTURE_SWIZZLE: |
| 125 | return 1; |
| 126 | |
Alyssa Rosenzweig | 5fe5827 | 2019-12-27 12:42:53 -0500 | [diff] [blame] | 127 | case PIPE_CAP_TEXTURE_MIRROR_CLAMP: |
| 128 | case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE: |
| 129 | return 1; |
| 130 | |
Alyssa Rosenzweig | f277bd3 | 2019-03-25 04:57:27 +0000 | [diff] [blame] | 131 | case PIPE_CAP_TGSI_INSTANCEID: |
| 132 | case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: |
Alyssa Rosenzweig | f5b6dfc | 2020-02-20 09:43:34 -0500 | [diff] [blame] | 133 | case PIPE_CAP_PRIMITIVE_RESTART: |
Alyssa Rosenzweig | bef716b | 2020-01-18 09:44:19 -0500 | [diff] [blame] | 134 | return 1; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 135 | |
| 136 | case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 137 | return is_gles3 ? 4 : 0; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 138 | case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: |
| 139 | case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 140 | return is_gles3 ? 64 : 0; |
Alyssa Rosenzweig | 4dba493 | 2019-08-08 09:21:27 -0700 | [diff] [blame] | 141 | case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS: |
| 142 | return 1; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 143 | |
| 144 | case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: |
Alyssa Rosenzweig | bef716b | 2020-01-18 09:44:19 -0500 | [diff] [blame] | 145 | return 256; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 146 | |
| 147 | case PIPE_CAP_GLSL_FEATURE_LEVEL: |
| 148 | case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 149 | return is_gles3 ? 140 : 120; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 150 | case PIPE_CAP_ESSL_FEATURE_LEVEL: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 151 | return is_gles3 ? 300 : 120; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 152 | |
| 153 | case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: |
Alyssa Rosenzweig | bef716b | 2020-01-18 09:44:19 -0500 | [diff] [blame] | 154 | return 16; |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 155 | |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 156 | return is_deqp; |
Alyssa Rosenzweig | f277bd3 | 2019-03-25 04:57:27 +0000 | [diff] [blame] | 157 | |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 158 | case PIPE_CAP_TEXTURE_MULTISAMPLE: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 159 | return is_gles3; |
| 160 | |
| 161 | /* For faking GLES 3.1 for dEQP-GLES31 */ |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 162 | case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS: |
| 163 | case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS: |
| 164 | case PIPE_CAP_IMAGE_LOAD_FORMATTED: |
Alyssa Rosenzweig | 5491a13 | 2020-02-20 09:30:42 -0500 | [diff] [blame] | 165 | case PIPE_CAP_CUBE_MAP_ARRAY: |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 166 | return is_deqp; |
| 167 | |
Alyssa Rosenzweig | c8bc664 | 2019-07-23 09:05:40 -0700 | [diff] [blame] | 168 | /* For faking compute shaders */ |
| 169 | case PIPE_CAP_COMPUTE: |
| 170 | return is_deqp; |
| 171 | |
Alyssa Rosenzweig | 8d74749 | 2019-06-27 14:13:10 -0700 | [diff] [blame] | 172 | /* TODO: Where does this req come from in practice? */ |
| 173 | case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: |
| 174 | return 1; |
| 175 | |
Eric Anholt | 0c31fe9 | 2019-04-29 15:38:24 -0700 | [diff] [blame] | 176 | case PIPE_CAP_MAX_TEXTURE_2D_SIZE: |
| 177 | return 4096; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 178 | case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: |
| 179 | case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: |
| 180 | return 13; |
| 181 | |
| 182 | case PIPE_CAP_BLEND_EQUATION_SEPARATE: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 183 | case PIPE_CAP_INDEP_BLEND_ENABLE: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 184 | case PIPE_CAP_INDEP_BLEND_FUNC: |
| 185 | return 1; |
| 186 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 187 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: |
Alyssa Rosenzweig | 2adf35e | 2019-05-23 03:01:32 +0000 | [diff] [blame] | 188 | /* Hardware is natively upper left */ |
| 189 | return 0; |
| 190 | |
| 191 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 192 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: |
| 193 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: |
Alyssa Rosenzweig | ffcc4d1 | 2019-06-21 13:57:42 -0700 | [diff] [blame] | 194 | case PIPE_CAP_GENERATE_MIPMAP: |
| 195 | return 1; |
| 196 | |
Alyssa Rosenzweig | e913986 | 2019-07-31 12:24:32 -0700 | [diff] [blame] | 197 | /* We would prefer varyings */ |
| 198 | case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL: |
| 199 | case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL: |
| 200 | return 0; |
| 201 | |
Alyssa Rosenzweig | 4b0001c | 2019-08-07 12:00:14 -0700 | [diff] [blame] | 202 | /* I really don't want to set this CAP but let's not swim against the |
| 203 | * tide.. */ |
| 204 | case PIPE_CAP_TGSI_TEXCOORD: |
| 205 | return 1; |
| 206 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 207 | case PIPE_CAP_SEAMLESS_CUBE_MAP: |
| 208 | case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: |
| 209 | return 1; |
| 210 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 211 | case PIPE_CAP_MAX_VERTEX_ELEMENT_SRC_OFFSET: |
| 212 | return 0xffff; |
| 213 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 214 | case PIPE_CAP_TEXTURE_BUFFER_OBJECTS: |
| 215 | return 1; |
| 216 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 217 | case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE: |
| 218 | return 65536; |
| 219 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 220 | case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER: |
| 221 | return 0; |
| 222 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 223 | case PIPE_CAP_ENDIANNESS: |
| 224 | return PIPE_ENDIAN_NATIVE; |
| 225 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 226 | case PIPE_CAP_SAMPLER_VIEW_TARGET: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 227 | return 1; |
| 228 | |
| 229 | case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 230 | return -8; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 231 | |
| 232 | case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 233 | return 7; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 234 | |
| 235 | case PIPE_CAP_VENDOR_ID: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 236 | case PIPE_CAP_DEVICE_ID: |
| 237 | return 0xFFFFFFFF; |
| 238 | |
| 239 | case PIPE_CAP_ACCELERATED: |
Alyssa Rosenzweig | b5de423 | 2019-07-08 08:44:49 -0700 | [diff] [blame] | 240 | case PIPE_CAP_UMA: |
| 241 | case PIPE_CAP_TEXTURE_FLOAT_LINEAR: |
| 242 | case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR: |
| 243 | case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS: |
| 244 | case PIPE_CAP_TGSI_ARRAY_COMPONENTS: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 245 | return 1; |
| 246 | |
| 247 | case PIPE_CAP_VIDEO_MEMORY: { |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 248 | uint64_t system_memory; |
| 249 | |
| 250 | if (!os_get_total_physical_memory(&system_memory)) |
| 251 | return 0; |
| 252 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 253 | return (int)(system_memory >> 20); |
| 254 | } |
| 255 | |
Boris Brezillon | 38c2069 | 2020-01-31 10:55:49 +0100 | [diff] [blame] | 256 | case PIPE_CAP_SHADER_STENCIL_EXPORT: |
| 257 | return 1; |
| 258 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 259 | case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT: |
| 260 | return 4; |
| 261 | |
Karol Herbst | 6010d7b | 2017-08-25 19:22:03 +0200 | [diff] [blame] | 262 | case PIPE_CAP_MAX_VARYINGS: |
| 263 | return 16; |
| 264 | |
Erik Faye-Lund | 2da792d | 2019-10-07 12:07:20 +0200 | [diff] [blame] | 265 | case PIPE_CAP_ALPHA_TEST: |
Alyssa Rosenzweig | 62d056d | 2019-12-27 15:33:33 -0500 | [diff] [blame] | 266 | case PIPE_CAP_FLATSHADE: |
| 267 | case PIPE_CAP_TWO_SIDED_COLOR: |
| 268 | case PIPE_CAP_CLIP_PLANES: |
Erik Faye-Lund | 2da792d | 2019-10-07 12:07:20 +0200 | [diff] [blame] | 269 | return 0; |
| 270 | |
Louis-Francis Ratté-Boulianne | 2d32248 | 2019-10-12 03:04:22 -0400 | [diff] [blame^] | 271 | case PIPE_CAP_PACKED_STREAM_OUTPUT: |
| 272 | return 0; |
| 273 | |
| 274 | case PIPE_CAP_VIEWPORT_TRANSFORM_LOWERED: |
| 275 | case PIPE_CAP_PSIZ_CLAMPED: |
| 276 | return 1; |
| 277 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 278 | default: |
Alyssa Rosenzweig | 8f4485e | 2019-02-05 02:19:38 +0000 | [diff] [blame] | 279 | return u_pipe_screen_get_param_defaults(screen, param); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | static int |
| 284 | panfrost_get_shader_param(struct pipe_screen *screen, |
| 285 | enum pipe_shader_type shader, |
| 286 | enum pipe_shader_cap param) |
| 287 | { |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 288 | bool is_deqp = pan_debug & PAN_DBG_DEQP; |
| 289 | |
Alyssa Rosenzweig | c8bc664 | 2019-07-23 09:05:40 -0700 | [diff] [blame] | 290 | if (shader != PIPE_SHADER_VERTEX && |
| 291 | shader != PIPE_SHADER_FRAGMENT && |
| 292 | !(shader == PIPE_SHADER_COMPUTE && is_deqp)) |
| 293 | return 0; |
| 294 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 295 | /* this is probably not totally correct.. but it's a start: */ |
| 296 | switch (param) { |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 297 | case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: |
| 298 | case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: |
| 299 | case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: |
| 300 | case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: |
| 301 | return 16384; |
| 302 | |
| 303 | case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: |
| 304 | return 1024; |
| 305 | |
| 306 | case PIPE_SHADER_CAP_MAX_INPUTS: |
| 307 | return 16; |
| 308 | |
| 309 | case PIPE_SHADER_CAP_MAX_OUTPUTS: |
Tomeu Vizoso | 843a6db | 2019-12-19 16:01:15 +0100 | [diff] [blame] | 310 | return shader == PIPE_SHADER_FRAGMENT ? 4 : 16; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 311 | |
| 312 | case PIPE_SHADER_CAP_MAX_TEMPS: |
| 313 | return 256; /* GL_MAX_PROGRAM_TEMPORARIES_ARB */ |
| 314 | |
| 315 | case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE: |
| 316 | return 16 * 1024 * sizeof(float); |
| 317 | |
| 318 | case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: |
Alyssa Rosenzweig | fae790e | 2019-07-15 11:30:35 -0700 | [diff] [blame] | 319 | return PAN_MAX_CONST_BUFFERS; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 320 | |
| 321 | case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: |
| 322 | return 0; |
| 323 | |
| 324 | case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: |
Alyssa Rosenzweig | 6a466c0 | 2019-04-20 23:52:42 +0000 | [diff] [blame] | 325 | return 1; |
Alyssa Rosenzweig | 12cd89d | 2019-04-21 05:11:02 +0000 | [diff] [blame] | 326 | case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: |
| 327 | return 0; |
Alyssa Rosenzweig | 6a466c0 | 2019-04-20 23:52:42 +0000 | [diff] [blame] | 328 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 329 | case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: |
| 330 | return 0; |
| 331 | |
| 332 | case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: |
| 333 | return 1; |
| 334 | |
| 335 | case PIPE_SHADER_CAP_SUBROUTINES: |
| 336 | return 0; |
| 337 | |
| 338 | case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED: |
| 339 | return 0; |
| 340 | |
| 341 | case PIPE_SHADER_CAP_INTEGERS: |
| 342 | return 1; |
| 343 | |
| 344 | case PIPE_SHADER_CAP_INT64_ATOMICS: |
| 345 | case PIPE_SHADER_CAP_FP16: |
| 346 | case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED: |
| 347 | case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED: |
| 348 | case PIPE_SHADER_CAP_TGSI_LDEXP_SUPPORTED: |
| 349 | case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED: |
| 350 | case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE: |
| 351 | return 0; |
| 352 | |
| 353 | case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: |
| 354 | case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: |
| 355 | return 16; /* XXX: How many? */ |
| 356 | |
| 357 | case PIPE_SHADER_CAP_PREFERRED_IR: |
| 358 | return PIPE_SHADER_IR_NIR; |
| 359 | |
| 360 | case PIPE_SHADER_CAP_SUPPORTED_IRS: |
Alyssa Rosenzweig | 728a975 | 2019-10-19 17:14:44 -0400 | [diff] [blame] | 361 | return (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_NIR_SERIALIZED); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 362 | |
| 363 | case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT: |
| 364 | return 32; |
| 365 | |
| 366 | case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS: |
| 367 | case PIPE_SHADER_CAP_MAX_SHADER_IMAGES: |
Alyssa Rosenzweig | 995e437 | 2020-02-26 13:37:10 -0500 | [diff] [blame] | 368 | return is_deqp ? 8 : 0; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 369 | case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS: |
| 370 | case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS: |
Alyssa Rosenzweig | 31c9fcb | 2019-07-23 19:18:44 -0700 | [diff] [blame] | 371 | return 0; |
Alyssa Rosenzweig | 2f93ecd | 2019-07-22 20:11:04 -0700 | [diff] [blame] | 372 | |
| 373 | case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS: |
| 374 | case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD: |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 375 | return 0; |
| 376 | |
| 377 | default: |
Tomeu Vizoso | d902e23 | 2020-01-06 10:48:20 +0100 | [diff] [blame] | 378 | DBG("unknown shader param %d\n", param); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static float |
| 386 | panfrost_get_paramf(struct pipe_screen *screen, enum pipe_capf param) |
| 387 | { |
| 388 | switch (param) { |
| 389 | case PIPE_CAPF_MAX_LINE_WIDTH: |
| 390 | |
| 391 | /* fall-through */ |
| 392 | case PIPE_CAPF_MAX_LINE_WIDTH_AA: |
| 393 | return 255.0; /* arbitrary */ |
| 394 | |
| 395 | case PIPE_CAPF_MAX_POINT_WIDTH: |
| 396 | |
| 397 | /* fall-through */ |
| 398 | case PIPE_CAPF_MAX_POINT_WIDTH_AA: |
Alyssa Rosenzweig | bb483a9 | 2019-07-10 11:30:00 -0700 | [diff] [blame] | 399 | return 1024.0; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 400 | |
| 401 | case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: |
| 402 | return 16.0; |
| 403 | |
| 404 | case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: |
| 405 | return 16.0; /* arbitrary */ |
| 406 | |
Tomeu Vizoso | 1b97d9c | 2019-05-09 14:07:45 +0200 | [diff] [blame] | 407 | case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE: |
| 408 | case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE: |
| 409 | case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY: |
| 410 | return 0.0f; |
| 411 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 412 | default: |
| 413 | debug_printf("Unexpected PIPE_CAPF %d query\n", param); |
| 414 | return 0.0; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Query format support for creating a texture, drawing surface, etc. |
| 420 | * \param format the format to test |
| 421 | * \param type one of PIPE_TEXTURE, PIPE_SURFACE |
| 422 | */ |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 423 | static bool |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 424 | panfrost_is_format_supported( struct pipe_screen *screen, |
| 425 | enum pipe_format format, |
| 426 | enum pipe_texture_target target, |
| 427 | unsigned sample_count, |
| 428 | unsigned storage_sample_count, |
| 429 | unsigned bind) |
| 430 | { |
| 431 | const struct util_format_description *format_desc; |
| 432 | |
| 433 | assert(target == PIPE_BUFFER || |
| 434 | target == PIPE_TEXTURE_1D || |
| 435 | target == PIPE_TEXTURE_1D_ARRAY || |
| 436 | target == PIPE_TEXTURE_2D || |
| 437 | target == PIPE_TEXTURE_2D_ARRAY || |
| 438 | target == PIPE_TEXTURE_RECT || |
| 439 | target == PIPE_TEXTURE_3D || |
| 440 | target == PIPE_TEXTURE_CUBE || |
| 441 | target == PIPE_TEXTURE_CUBE_ARRAY); |
| 442 | |
| 443 | format_desc = util_format_description(format); |
| 444 | |
| 445 | if (!format_desc) |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 446 | return false; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 447 | |
Alyssa Rosenzweig | 5c71547 | 2020-01-04 13:23:18 -0500 | [diff] [blame] | 448 | /* MSAA 4x supported, but no more. Technically some revisions of the |
| 449 | * hardware can go up to 16x but we don't support higher modes yet. */ |
| 450 | |
| 451 | if (sample_count > 1 && !(pan_debug & PAN_DBG_DEQP)) |
| 452 | return false; |
| 453 | |
| 454 | if (sample_count > 4) |
| 455 | return false; |
| 456 | |
| 457 | if (MAX2(sample_count, 1) != MAX2(storage_sample_count, 1)) |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 458 | return false; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 459 | |
| 460 | /* Format wishlist */ |
Alyssa Rosenzweig | 0b83005 | 2019-07-15 07:12:47 -0700 | [diff] [blame] | 461 | if (format == PIPE_FORMAT_X8Z24_UNORM) |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 462 | return false; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 463 | |
Alyssa Rosenzweig | 9237204 | 2019-03-29 01:46:17 +0000 | [diff] [blame] | 464 | if (format == PIPE_FORMAT_A1B5G5R5_UNORM || format == PIPE_FORMAT_X1B5G5R5_UNORM) |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 465 | return false; |
Alyssa Rosenzweig | 9237204 | 2019-03-29 01:46:17 +0000 | [diff] [blame] | 466 | |
Alyssa Rosenzweig | 53d6475 | 2019-07-01 11:53:38 -0700 | [diff] [blame] | 467 | /* TODO */ |
| 468 | if (format == PIPE_FORMAT_B5G5R5A1_UNORM) |
| 469 | return FALSE; |
Alyssa Rosenzweig | f8fca4f | 2019-06-28 18:47:10 -0700 | [diff] [blame] | 470 | |
Alyssa Rosenzweig | 53d6475 | 2019-07-01 11:53:38 -0700 | [diff] [blame] | 471 | /* Don't confuse poorly written apps (workaround dEQP bug) that expect |
| 472 | * more alpha than they ask for */ |
Alyssa Rosenzweig | 0b83005 | 2019-07-15 07:12:47 -0700 | [diff] [blame] | 473 | |
Alyssa Rosenzweig | 53d6475 | 2019-07-01 11:53:38 -0700 | [diff] [blame] | 474 | bool scanout = bind & (PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_DISPLAY_TARGET); |
Alyssa Rosenzweig | 0b83005 | 2019-07-15 07:12:47 -0700 | [diff] [blame] | 475 | bool renderable = bind & PIPE_BIND_RENDER_TARGET; |
| 476 | |
| 477 | if (scanout && renderable && !util_format_is_rgba8_variant(format_desc)) |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 478 | return false; |
Alyssa Rosenzweig | f8fca4f | 2019-06-28 18:47:10 -0700 | [diff] [blame] | 479 | |
Icecream95 | 960fe9d | 2020-01-11 20:00:38 +1300 | [diff] [blame] | 480 | switch (format_desc->layout) { |
| 481 | case UTIL_FORMAT_LAYOUT_PLAIN: |
| 482 | case UTIL_FORMAT_LAYOUT_OTHER: |
| 483 | break; |
| 484 | case UTIL_FORMAT_LAYOUT_ETC: |
Icecream95 | 31bd3b5 | 2020-01-11 19:19:45 +1300 | [diff] [blame] | 485 | case UTIL_FORMAT_LAYOUT_ASTC: |
Icecream95 | 960fe9d | 2020-01-11 20:00:38 +1300 | [diff] [blame] | 486 | return true; |
| 487 | default: |
| 488 | return false; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 489 | } |
| 490 | |
Alyssa Rosenzweig | 507e297 | 2019-07-10 14:50:48 -0700 | [diff] [blame] | 491 | /* Internally, formats that are depth/stencil renderable are limited. |
| 492 | * |
| 493 | * In particular: Z16, Z24, Z24S8, S8 are all identical from the GPU |
| 494 | * rendering perspective. That is, we render to Z24S8 (which we can |
| 495 | * AFBC compress), ignore the different when texturing (who cares?), |
| 496 | * and then in the off-chance there's a CPU read we blit back to |
| 497 | * staging. |
| 498 | * |
| 499 | * ...alternatively, we can make the state tracker deal with that. */ |
| 500 | |
| 501 | if (bind & PIPE_BIND_DEPTH_STENCIL) { |
| 502 | switch (format) { |
| 503 | case PIPE_FORMAT_Z24_UNORM_S8_UINT: |
Alyssa Rosenzweig | 0b83005 | 2019-07-15 07:12:47 -0700 | [diff] [blame] | 504 | case PIPE_FORMAT_Z24X8_UNORM: |
| 505 | case PIPE_FORMAT_Z32_UNORM: |
Alyssa Rosenzweig | 676b933 | 2019-07-17 15:49:42 -0700 | [diff] [blame] | 506 | case PIPE_FORMAT_Z32_FLOAT: |
| 507 | case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: |
Alyssa Rosenzweig | 507e297 | 2019-07-10 14:50:48 -0700 | [diff] [blame] | 508 | return true; |
| 509 | |
| 510 | default: |
| 511 | return false; |
| 512 | } |
| 513 | } |
| 514 | |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 515 | return true; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Alyssa Rosenzweig | 1697760 | 2019-07-23 10:41:25 -0700 | [diff] [blame] | 518 | static int |
| 519 | panfrost_get_compute_param(struct pipe_screen *pscreen, enum pipe_shader_ir ir_type, |
| 520 | enum pipe_compute_cap param, void *ret) |
| 521 | { |
| 522 | const char * const ir = "panfrost"; |
| 523 | |
| 524 | if (!(pan_debug & PAN_DBG_DEQP)) |
| 525 | return 0; |
| 526 | |
| 527 | #define RET(x) do { \ |
| 528 | if (ret) \ |
| 529 | memcpy(ret, x, sizeof(x)); \ |
| 530 | return sizeof(x); \ |
| 531 | } while (0) |
| 532 | |
| 533 | switch (param) { |
| 534 | case PIPE_COMPUTE_CAP_ADDRESS_BITS: |
Alyssa Rosenzweig | 8b1548a | 2019-11-06 14:55:41 -0500 | [diff] [blame] | 535 | RET((uint32_t []){ 64 }); |
Alyssa Rosenzweig | 1697760 | 2019-07-23 10:41:25 -0700 | [diff] [blame] | 536 | |
| 537 | case PIPE_COMPUTE_CAP_IR_TARGET: |
| 538 | if (ret) |
| 539 | sprintf(ret, "%s", ir); |
| 540 | return strlen(ir) * sizeof(char); |
| 541 | |
| 542 | case PIPE_COMPUTE_CAP_GRID_DIMENSION: |
| 543 | RET((uint64_t []) { 3 }); |
| 544 | |
| 545 | case PIPE_COMPUTE_CAP_MAX_GRID_SIZE: |
| 546 | RET(((uint64_t []) { 65535, 65535, 65535 })); |
| 547 | |
| 548 | case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE: |
| 549 | RET(((uint64_t []) { 1024, 1024, 64 })); |
| 550 | |
| 551 | case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK: |
| 552 | RET((uint64_t []) { 1024 }); |
| 553 | |
| 554 | case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: |
| 555 | RET((uint64_t []) { 1024*1024*512 /* Maybe get memory */ }); |
| 556 | |
| 557 | case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: |
| 558 | RET((uint64_t []) { 32768 }); |
| 559 | |
| 560 | case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: |
| 561 | case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: |
| 562 | RET((uint64_t []) { 4096 }); |
| 563 | |
| 564 | case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE: |
| 565 | RET((uint64_t []) { 1024*1024*512 /* Maybe get memory */ }); |
| 566 | |
| 567 | case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY: |
| 568 | RET((uint32_t []) { 800 /* MHz -- TODO */ }); |
| 569 | |
| 570 | case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS: |
| 571 | RET((uint32_t []) { 9999 }); // TODO |
| 572 | |
| 573 | case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED: |
| 574 | RET((uint32_t []) { 1 }); // TODO |
| 575 | |
| 576 | case PIPE_COMPUTE_CAP_SUBGROUP_SIZE: |
| 577 | RET((uint32_t []) { 32 }); // TODO |
| 578 | |
| 579 | case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK: |
| 580 | RET((uint64_t []) { 1024 }); // TODO |
| 581 | } |
| 582 | |
| 583 | return 0; |
| 584 | } |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 585 | |
| 586 | static void |
Tomeu Vizoso | 0fcf73b | 2019-06-18 14:24:57 +0200 | [diff] [blame] | 587 | panfrost_destroy_screen(struct pipe_screen *pscreen) |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 588 | { |
Tomeu Vizoso | 0fcf73b | 2019-06-18 14:24:57 +0200 | [diff] [blame] | 589 | struct panfrost_screen *screen = pan_screen(pscreen); |
Alyssa Rosenzweig | f3b7e1d | 2019-07-15 08:22:33 -0700 | [diff] [blame] | 590 | panfrost_bo_cache_evict_all(screen); |
Boris Brezillon | 25059cc | 2019-11-07 08:42:09 +0100 | [diff] [blame] | 591 | pthread_mutex_destroy(&screen->bo_cache.lock); |
Tomeu Vizoso | 82f18b7 | 2019-10-09 10:10:44 +0200 | [diff] [blame] | 592 | pthread_mutex_destroy(&screen->active_bos_lock); |
Tomeu Vizoso | 19afd41 | 2019-07-31 15:00:46 +0200 | [diff] [blame] | 593 | drmFreeVersion(screen->kernel_version); |
Tomeu Vizoso | 0fcf73b | 2019-06-18 14:24:57 +0200 | [diff] [blame] | 594 | ralloc_free(screen); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 597 | static uint64_t |
| 598 | panfrost_get_timestamp(struct pipe_screen *_screen) |
| 599 | { |
| 600 | return os_time_get_nano(); |
| 601 | } |
| 602 | |
| 603 | static void |
Tomeu Vizoso | 756f7b9 | 2019-03-08 10:27:07 +0100 | [diff] [blame] | 604 | panfrost_fence_reference(struct pipe_screen *pscreen, |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 605 | struct pipe_fence_handle **ptr, |
| 606 | struct pipe_fence_handle *fence) |
| 607 | { |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 608 | struct panfrost_fence **p = (struct panfrost_fence **)ptr; |
| 609 | struct panfrost_fence *f = (struct panfrost_fence *)fence; |
| 610 | struct panfrost_fence *old = *p; |
| 611 | |
| 612 | if (pipe_reference(&(*p)->reference, &f->reference)) { |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 613 | util_dynarray_foreach(&old->syncfds, int, fd) |
| 614 | close(*fd); |
| 615 | util_dynarray_fini(&old->syncfds); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 616 | free(old); |
| 617 | } |
| 618 | *p = f; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Ilia Mirkin | 0e30c6b | 2019-07-04 11:41:41 -0400 | [diff] [blame] | 621 | static bool |
Tomeu Vizoso | 756f7b9 | 2019-03-08 10:27:07 +0100 | [diff] [blame] | 622 | panfrost_fence_finish(struct pipe_screen *pscreen, |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 623 | struct pipe_context *ctx, |
| 624 | struct pipe_fence_handle *fence, |
| 625 | uint64_t timeout) |
| 626 | { |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 627 | struct panfrost_screen *screen = pan_screen(pscreen); |
| 628 | struct panfrost_fence *f = (struct panfrost_fence *)fence; |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 629 | struct util_dynarray syncobjs; |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 630 | int ret; |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 631 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 632 | /* All fences were already signaled */ |
| 633 | if (!util_dynarray_num_elements(&f->syncfds, int)) |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 634 | return true; |
| 635 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 636 | util_dynarray_init(&syncobjs, NULL); |
| 637 | util_dynarray_foreach(&f->syncfds, int, fd) { |
| 638 | uint32_t syncobj; |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 639 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 640 | ret = drmSyncobjCreate(screen->fd, 0, &syncobj); |
| 641 | assert(!ret); |
| 642 | |
| 643 | ret = drmSyncobjImportSyncFile(screen->fd, syncobj, *fd); |
| 644 | assert(!ret); |
| 645 | util_dynarray_append(&syncobjs, uint32_t, syncobj); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | uint64_t abs_timeout = os_time_get_absolute_timeout(timeout); |
| 649 | if (abs_timeout == OS_TIMEOUT_INFINITE) |
| 650 | abs_timeout = INT64_MAX; |
| 651 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 652 | ret = drmSyncobjWait(screen->fd, util_dynarray_begin(&syncobjs), |
| 653 | util_dynarray_num_elements(&syncobjs, uint32_t), |
| 654 | abs_timeout, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, |
| 655 | NULL); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 656 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 657 | util_dynarray_foreach(&syncobjs, uint32_t, syncobj) |
| 658 | drmSyncobjDestroy(screen->fd, *syncobj); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 659 | |
| 660 | return ret >= 0; |
| 661 | } |
| 662 | |
| 663 | struct panfrost_fence * |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 664 | panfrost_fence_create(struct panfrost_context *ctx, |
| 665 | struct util_dynarray *fences) |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 666 | { |
| 667 | struct panfrost_screen *screen = pan_screen(ctx->base.screen); |
| 668 | struct panfrost_fence *f = calloc(1, sizeof(*f)); |
| 669 | if (!f) |
| 670 | return NULL; |
| 671 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 672 | util_dynarray_init(&f->syncfds, NULL); |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 673 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 674 | /* Export fences from all pending batches. */ |
| 675 | util_dynarray_foreach(fences, struct panfrost_batch_fence *, fence) { |
| 676 | int fd = -1; |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 677 | |
Boris Brezillon | b5d8f9b | 2019-09-15 18:23:10 +0200 | [diff] [blame] | 678 | /* The fence is already signaled, no need to export it. */ |
| 679 | if ((*fence)->signaled) |
| 680 | continue; |
| 681 | |
| 682 | drmSyncobjExportSyncFile(screen->fd, (*fence)->syncobj, &fd); |
| 683 | if (fd == -1) |
| 684 | fprintf(stderr, "export failed: %m\n"); |
| 685 | |
| 686 | assert(fd != -1); |
| 687 | util_dynarray_append(&f->syncfds, int, fd); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | pipe_reference_init(&f->reference, 1); |
| 691 | |
| 692 | return f; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static const void * |
| 696 | panfrost_screen_get_compiler_options(struct pipe_screen *pscreen, |
| 697 | enum pipe_shader_ir ir, |
| 698 | enum pipe_shader_type shader) |
| 699 | { |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 700 | return &midgard_nir_options; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Tomeu Vizoso | 82f18b7 | 2019-10-09 10:10:44 +0200 | [diff] [blame] | 703 | static uint32_t |
| 704 | panfrost_active_bos_hash(const void *key) |
| 705 | { |
| 706 | const struct panfrost_bo *bo = key; |
| 707 | |
| 708 | return _mesa_hash_data(&bo->gem_handle, sizeof(bo->gem_handle)); |
| 709 | } |
| 710 | |
| 711 | static bool |
| 712 | panfrost_active_bos_cmp(const void *keya, const void *keyb) |
| 713 | { |
| 714 | const struct panfrost_bo *a = keya, *b = keyb; |
| 715 | |
| 716 | return a->gem_handle == b->gem_handle; |
| 717 | } |
| 718 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 719 | struct pipe_screen * |
Alyssa Rosenzweig | 138865e | 2019-03-31 19:06:05 +0000 | [diff] [blame] | 720 | panfrost_create_screen(int fd, struct renderonly *ro) |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 721 | { |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 722 | pan_debug = debug_get_option_pan_debug(); |
Tomeu Vizoso | 97f2d04 | 2019-03-08 15:24:57 +0100 | [diff] [blame] | 723 | |
Alyssa Rosenzweig | 1f8b653 | 2019-08-05 08:20:24 -0700 | [diff] [blame] | 724 | /* Blacklist apps known to be buggy under Panfrost */ |
| 725 | const char *proc = util_get_process_name(); |
| 726 | const char *blacklist[] = { |
| 727 | "chromium", |
| 728 | "chrome", |
| 729 | }; |
| 730 | |
| 731 | for (unsigned i = 0; i < ARRAY_SIZE(blacklist); ++i) { |
| 732 | if ((strcmp(blacklist[i], proc) == 0)) |
| 733 | return NULL; |
| 734 | } |
| 735 | |
| 736 | /* Create the screen */ |
| 737 | struct panfrost_screen *screen = rzalloc(NULL, struct panfrost_screen); |
| 738 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 739 | if (!screen) |
| 740 | return NULL; |
| 741 | |
| 742 | if (ro) { |
| 743 | screen->ro = renderonly_dup(ro); |
| 744 | if (!screen->ro) { |
Tomeu Vizoso | d902e23 | 2020-01-06 10:48:20 +0100 | [diff] [blame] | 745 | DBG("Failed to dup renderonly object\n"); |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 746 | free(screen); |
| 747 | return NULL; |
| 748 | } |
| 749 | } |
| 750 | |
Boris Brezillon | 5f81669 | 2019-06-19 16:06:38 +0200 | [diff] [blame] | 751 | screen->fd = fd; |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 752 | |
Alyssa Rosenzweig | a215289 | 2019-12-09 15:54:09 -0500 | [diff] [blame] | 753 | screen->gpu_id = panfrost_query_gpu_version(screen->fd); |
| 754 | screen->core_count = panfrost_query_core_count(screen->fd); |
| 755 | screen->thread_tls_alloc = panfrost_query_thread_tls_alloc(screen->fd); |
Tomeu Vizoso | 6887ff4 | 2019-11-28 10:21:06 +0100 | [diff] [blame] | 756 | screen->quirks = panfrost_get_quirks(screen->gpu_id); |
Tomeu Vizoso | 19afd41 | 2019-07-31 15:00:46 +0200 | [diff] [blame] | 757 | screen->kernel_version = drmGetVersion(fd); |
Alyssa Rosenzweig | 2f7145a | 2019-07-08 09:14:59 -0700 | [diff] [blame] | 758 | |
Tomeu Vizoso | 5a7688f | 2019-07-11 08:06:41 +0200 | [diff] [blame] | 759 | /* Check if we're loading against a supported GPU model. */ |
Alyssa Rosenzweig | 2f7145a | 2019-07-08 09:14:59 -0700 | [diff] [blame] | 760 | |
| 761 | switch (screen->gpu_id) { |
Tomeu Vizoso | b655be7 | 2019-10-28 09:59:30 +0100 | [diff] [blame] | 762 | case 0x720: /* T720 */ |
Tomeu Vizoso | 5a7688f | 2019-07-11 08:06:41 +0200 | [diff] [blame] | 763 | case 0x750: /* T760 */ |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 764 | case 0x820: /* T820 */ |
| 765 | case 0x860: /* T860 */ |
| 766 | break; |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 767 | default: |
| 768 | /* Fail to load against untested models */ |
Tomeu Vizoso | 6887ff4 | 2019-11-28 10:21:06 +0100 | [diff] [blame] | 769 | debug_printf("panfrost: Unsupported model %X", screen->gpu_id); |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 770 | return NULL; |
Alyssa Rosenzweig | 2f7145a | 2019-07-08 09:14:59 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Tomeu Vizoso | 82f18b7 | 2019-10-09 10:10:44 +0200 | [diff] [blame] | 773 | pthread_mutex_init(&screen->active_bos_lock, NULL); |
| 774 | screen->active_bos = _mesa_set_create(screen, panfrost_active_bos_hash, |
| 775 | panfrost_active_bos_cmp); |
| 776 | |
Boris Brezillon | 25059cc | 2019-11-07 08:42:09 +0100 | [diff] [blame] | 777 | pthread_mutex_init(&screen->bo_cache.lock, NULL); |
Boris Brezillon | ee82f9f | 2019-11-07 09:32:31 +0100 | [diff] [blame] | 778 | list_inithead(&screen->bo_cache.lru); |
Boris Brezillon | 25059cc | 2019-11-07 08:42:09 +0100 | [diff] [blame] | 779 | for (unsigned i = 0; i < ARRAY_SIZE(screen->bo_cache.buckets); ++i) |
| 780 | list_inithead(&screen->bo_cache.buckets[i]); |
Alyssa Rosenzweig | 270733f | 2019-07-15 08:36:19 -0700 | [diff] [blame] | 781 | |
Alyssa Rosenzweig | c46a090 | 2020-02-18 07:50:19 -0500 | [diff] [blame] | 782 | if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) |
Alyssa Rosenzweig | 070bc88 | 2020-02-18 08:05:11 -0500 | [diff] [blame] | 783 | pandecode_initialize(!(pan_debug & PAN_DBG_TRACE)); |
Alyssa Rosenzweig | fc7bcee | 2019-06-11 12:25:35 -0700 | [diff] [blame] | 784 | |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 785 | screen->base.destroy = panfrost_destroy_screen; |
| 786 | |
| 787 | screen->base.get_name = panfrost_get_name; |
| 788 | screen->base.get_vendor = panfrost_get_vendor; |
| 789 | screen->base.get_device_vendor = panfrost_get_device_vendor; |
| 790 | screen->base.get_param = panfrost_get_param; |
| 791 | screen->base.get_shader_param = panfrost_get_shader_param; |
Alyssa Rosenzweig | 1697760 | 2019-07-23 10:41:25 -0700 | [diff] [blame] | 792 | screen->base.get_compute_param = panfrost_get_compute_param; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 793 | screen->base.get_paramf = panfrost_get_paramf; |
| 794 | screen->base.get_timestamp = panfrost_get_timestamp; |
| 795 | screen->base.is_format_supported = panfrost_is_format_supported; |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 796 | screen->base.context_create = panfrost_create_context; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 797 | screen->base.get_compiler_options = panfrost_screen_get_compiler_options; |
| 798 | screen->base.fence_reference = panfrost_fence_reference; |
| 799 | screen->base.fence_finish = panfrost_fence_finish; |
Boris Brezillon | 8d0830d | 2019-10-07 12:24:51 +0200 | [diff] [blame] | 800 | screen->base.set_damage_region = panfrost_resource_set_damage_region; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 801 | |
Alyssa Rosenzweig | 7da251f | 2019-02-05 04:32:27 +0000 | [diff] [blame] | 802 | panfrost_resource_screen_init(screen); |
| 803 | |
| 804 | return &screen->base; |
Alyssa Rosenzweig | 61d3ae6 | 2019-01-29 05:46:07 +0000 | [diff] [blame] | 805 | } |