1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2012-2015 Etnaviv Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci * of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Wladimir J. van der Laan <laanwj@gmail.com> 25bf215546Sopenharmony_ci * Christian Gmeiner <christian.gmeiner@gmail.com> 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "etnaviv_screen.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "hw/common.xml.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "etnaviv_compiler.h" 33bf215546Sopenharmony_ci#include "etnaviv_context.h" 34bf215546Sopenharmony_ci#include "etnaviv_debug.h" 35bf215546Sopenharmony_ci#include "etnaviv_fence.h" 36bf215546Sopenharmony_ci#include "etnaviv_format.h" 37bf215546Sopenharmony_ci#include "etnaviv_query.h" 38bf215546Sopenharmony_ci#include "etnaviv_resource.h" 39bf215546Sopenharmony_ci#include "etnaviv_translate.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "util/hash_table.h" 42bf215546Sopenharmony_ci#include "util/os_time.h" 43bf215546Sopenharmony_ci#include "util/u_math.h" 44bf215546Sopenharmony_ci#include "util/u_memory.h" 45bf215546Sopenharmony_ci#include "util/u_screen.h" 46bf215546Sopenharmony_ci#include "util/u_string.h" 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci#include "frontend/drm_driver.h" 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ci#include "drm-uapi/drm_fourcc.h" 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci#define ETNA_DRM_VERSION_FENCE_FD ETNA_DRM_VERSION(1, 1) 53bf215546Sopenharmony_ci#define ETNA_DRM_VERSION_PERFMON ETNA_DRM_VERSION(1, 2) 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_cistatic const struct debug_named_value etna_debug_options[] = { 56bf215546Sopenharmony_ci {"dbg_msgs", ETNA_DBG_MSGS, "Print debug messages"}, 57bf215546Sopenharmony_ci {"drm_msgs", ETNA_DRM_MSGS, "Print drm messages"}, 58bf215546Sopenharmony_ci {"frame_msgs", ETNA_DBG_FRAME_MSGS, "Print frame messages"}, 59bf215546Sopenharmony_ci {"resource_msgs", ETNA_DBG_RESOURCE_MSGS, "Print resource messages"}, 60bf215546Sopenharmony_ci {"compiler_msgs", ETNA_DBG_COMPILER_MSGS, "Print compiler messages"}, 61bf215546Sopenharmony_ci {"linker_msgs", ETNA_DBG_LINKER_MSGS, "Print linker messages"}, 62bf215546Sopenharmony_ci {"dump_shaders", ETNA_DBG_DUMP_SHADERS, "Dump shaders"}, 63bf215546Sopenharmony_ci {"no_ts", ETNA_DBG_NO_TS, "Disable TS"}, 64bf215546Sopenharmony_ci {"no_autodisable", ETNA_DBG_NO_AUTODISABLE, "Disable autodisable"}, 65bf215546Sopenharmony_ci {"no_supertile", ETNA_DBG_NO_SUPERTILE, "Disable supertiles"}, 66bf215546Sopenharmony_ci {"no_early_z", ETNA_DBG_NO_EARLY_Z, "Disable early z"}, 67bf215546Sopenharmony_ci {"cflush_all", ETNA_DBG_CFLUSH_ALL, "Flush every cache before state update"}, 68bf215546Sopenharmony_ci {"msaa2x", ETNA_DBG_MSAA_2X, "Force 2x msaa"}, 69bf215546Sopenharmony_ci {"msaa4x", ETNA_DBG_MSAA_4X, "Force 4x msaa"}, 70bf215546Sopenharmony_ci {"flush_all", ETNA_DBG_FLUSH_ALL, "Flush after every rendered primitive"}, 71bf215546Sopenharmony_ci {"zero", ETNA_DBG_ZERO, "Zero all resources after allocation"}, 72bf215546Sopenharmony_ci {"draw_stall", ETNA_DBG_DRAW_STALL, "Stall FE/PE after each rendered primitive"}, 73bf215546Sopenharmony_ci {"shaderdb", ETNA_DBG_SHADERDB, "Enable shaderdb output"}, 74bf215546Sopenharmony_ci {"no_singlebuffer",ETNA_DBG_NO_SINGLEBUF, "Disable single buffer feature"}, 75bf215546Sopenharmony_ci {"deqp", ETNA_DBG_DEQP, "Hacks to run dEQP GLES3 tests"}, /* needs MESA_GLES_VERSION_OVERRIDE=3.0 */ 76bf215546Sopenharmony_ci {"nocache", ETNA_DBG_NOCACHE, "Disable shader cache"}, 77bf215546Sopenharmony_ci {"no_linear_pe", ETNA_DBG_NO_LINEAR_PE, "Disable linear PE"}, 78bf215546Sopenharmony_ci DEBUG_NAMED_VALUE_END 79bf215546Sopenharmony_ci}; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ciDEBUG_GET_ONCE_FLAGS_OPTION(etna_mesa_debug, "ETNA_MESA_DEBUG", etna_debug_options, 0) 82bf215546Sopenharmony_ciint etna_mesa_debug = 0; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_cistatic void 85bf215546Sopenharmony_cietna_screen_destroy(struct pipe_screen *pscreen) 86bf215546Sopenharmony_ci{ 87bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci if (screen->dummy_desc_reloc.bo) 90bf215546Sopenharmony_ci etna_bo_del(screen->dummy_desc_reloc.bo); 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (screen->dummy_rt_reloc.bo) 93bf215546Sopenharmony_ci etna_bo_del(screen->dummy_rt_reloc.bo); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci if (screen->perfmon) 96bf215546Sopenharmony_ci etna_perfmon_del(screen->perfmon); 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci etna_shader_screen_fini(pscreen); 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci if (screen->pipe) 101bf215546Sopenharmony_ci etna_pipe_del(screen->pipe); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci if (screen->gpu) 104bf215546Sopenharmony_ci etna_gpu_del(screen->gpu); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci if (screen->ro) 107bf215546Sopenharmony_ci screen->ro->destroy(screen->ro); 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci if (screen->dev) 110bf215546Sopenharmony_ci etna_device_del(screen->dev); 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci FREE(screen); 113bf215546Sopenharmony_ci} 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_cistatic const char * 116bf215546Sopenharmony_cietna_screen_get_name(struct pipe_screen *pscreen) 117bf215546Sopenharmony_ci{ 118bf215546Sopenharmony_ci struct etna_screen *priv = etna_screen(pscreen); 119bf215546Sopenharmony_ci static char buffer[128]; 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci snprintf(buffer, sizeof(buffer), "Vivante GC%x rev %04x", priv->model, 122bf215546Sopenharmony_ci priv->revision); 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci return buffer; 125bf215546Sopenharmony_ci} 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_cistatic const char * 128bf215546Sopenharmony_cietna_screen_get_vendor(struct pipe_screen *pscreen) 129bf215546Sopenharmony_ci{ 130bf215546Sopenharmony_ci return "etnaviv"; 131bf215546Sopenharmony_ci} 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_cistatic const char * 134bf215546Sopenharmony_cietna_screen_get_device_vendor(struct pipe_screen *pscreen) 135bf215546Sopenharmony_ci{ 136bf215546Sopenharmony_ci return "Vivante"; 137bf215546Sopenharmony_ci} 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_cistatic int 140bf215546Sopenharmony_cietna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) 141bf215546Sopenharmony_ci{ 142bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci switch (param) { 145bf215546Sopenharmony_ci /* Supported features (boolean caps). */ 146bf215546Sopenharmony_ci case PIPE_CAP_POINT_SPRITE: 147bf215546Sopenharmony_ci case PIPE_CAP_BLEND_EQUATION_SEPARATE: 148bf215546Sopenharmony_ci case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT: 149bf215546Sopenharmony_ci case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER: 150bf215546Sopenharmony_ci case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD: 151bf215546Sopenharmony_ci case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES: 152bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_BARRIER: 153bf215546Sopenharmony_ci case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: 154bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: 155bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: 156bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: 157bf215546Sopenharmony_ci case PIPE_CAP_TGSI_TEXCOORD: 158bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: 159bf215546Sopenharmony_ci case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: 160bf215546Sopenharmony_ci case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: 161bf215546Sopenharmony_ci case PIPE_CAP_STRING_MARKER: 162bf215546Sopenharmony_ci case PIPE_CAP_FRONTEND_NOOP: 163bf215546Sopenharmony_ci return 1; 164bf215546Sopenharmony_ci case PIPE_CAP_NATIVE_FENCE_FD: 165bf215546Sopenharmony_ci return screen->drm_version >= ETNA_DRM_VERSION_FENCE_FD; 166bf215546Sopenharmony_ci case PIPE_CAP_FS_POSITION_IS_SYSVAL: 167bf215546Sopenharmony_ci case PIPE_CAP_FS_FACE_IS_INTEGER_SYSVAL: /* note: not integer */ 168bf215546Sopenharmony_ci return 1; 169bf215546Sopenharmony_ci case PIPE_CAP_FS_POINT_IS_SYSVAL: 170bf215546Sopenharmony_ci return 0; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci /* Memory */ 173bf215546Sopenharmony_ci case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: 174bf215546Sopenharmony_ci return 256; 175bf215546Sopenharmony_ci case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: 176bf215546Sopenharmony_ci return 4096; 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci case PIPE_CAP_NPOT_TEXTURES: 179bf215546Sopenharmony_ci return true; /* VIV_FEATURE(priv->dev, chipMinorFeatures1, 180bf215546Sopenharmony_ci NON_POWER_OF_TWO); */ 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci case PIPE_CAP_ANISOTROPIC_FILTER: 183bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_SWIZZLE: 184bf215546Sopenharmony_ci case PIPE_CAP_PRIMITIVE_RESTART: 185bf215546Sopenharmony_ci case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX: 186bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci case PIPE_CAP_ALPHA_TEST: 189bf215546Sopenharmony_ci return !VIV_FEATURE(screen, chipMinorFeatures7, PE_NO_ALPHA_TEST); 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci /* Unsupported features. */ 192bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT: 193bf215546Sopenharmony_ci case PIPE_CAP_TEXRECT: 194bf215546Sopenharmony_ci return 0; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci /* Stream output. */ 197bf215546Sopenharmony_ci case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: 198bf215546Sopenharmony_ci return DBG_ENABLED(ETNA_DBG_DEQP) ? 4 : 0; 199bf215546Sopenharmony_ci case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: 200bf215546Sopenharmony_ci case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: 201bf215546Sopenharmony_ci return 0; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE: 204bf215546Sopenharmony_ci return 128; 205bf215546Sopenharmony_ci case PIPE_CAP_MAX_VERTEX_ELEMENT_SRC_OFFSET: 206bf215546Sopenharmony_ci return 255; 207bf215546Sopenharmony_ci case PIPE_CAP_MAX_VERTEX_BUFFERS: 208bf215546Sopenharmony_ci return screen->specs.stream_count; 209bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: 210bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci /* Texturing. */ 214bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_SHADOW_MAP: 215bf215546Sopenharmony_ci return 1; 216bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_2D_SIZE: 217bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: /* TODO: verify */ 218bf215546Sopenharmony_ci return screen->specs.max_texture_size; 219bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: 220bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: 221bf215546Sopenharmony_ci { 222bf215546Sopenharmony_ci int log2_max_tex_size = util_last_bit(screen->specs.max_texture_size); 223bf215546Sopenharmony_ci assert(log2_max_tex_size > 0); 224bf215546Sopenharmony_ci return log2_max_tex_size; 225bf215546Sopenharmony_ci } 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET: 228bf215546Sopenharmony_ci case PIPE_CAP_MIN_TEXEL_OFFSET: 229bf215546Sopenharmony_ci return -8; 230bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET: 231bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXEL_OFFSET: 232bf215546Sopenharmony_ci return 7; 233bf215546Sopenharmony_ci case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: 234bf215546Sopenharmony_ci return screen->specs.seamless_cube_map; 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci /* Queries. */ 237bf215546Sopenharmony_ci case PIPE_CAP_OCCLUSION_QUERY: 238bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_ci /* Preferences */ 241bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_TRANSFER_MODES: 242bf215546Sopenharmony_ci return 0; 243bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET: { 244bf215546Sopenharmony_ci /* etnaviv is being run on systems as small as 256MB total RAM so 245bf215546Sopenharmony_ci * we need to provide a sane value for such a device. Limit the 246bf215546Sopenharmony_ci * memory budget to min(~3% of pyhiscal memory, 64MB). 247bf215546Sopenharmony_ci * 248bf215546Sopenharmony_ci * a simple divison by 32 provides the numbers we want. 249bf215546Sopenharmony_ci * 256MB / 32 = 8MB 250bf215546Sopenharmony_ci * 2048MB / 32 = 64MB 251bf215546Sopenharmony_ci */ 252bf215546Sopenharmony_ci uint64_t system_memory; 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci if (!os_get_total_physical_memory(&system_memory)) 255bf215546Sopenharmony_ci system_memory = (uint64_t)4096 << 20; 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci return MIN2(system_memory / 32, 64 * 1024 * 1024); 258bf215546Sopenharmony_ci } 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ci case PIPE_CAP_MAX_VARYINGS: 261bf215546Sopenharmony_ci return screen->specs.max_varyings; 262bf215546Sopenharmony_ci 263bf215546Sopenharmony_ci case PIPE_CAP_SUPPORTED_PRIM_MODES: 264bf215546Sopenharmony_ci case PIPE_CAP_SUPPORTED_PRIM_MODES_WITH_RESTART: { 265bf215546Sopenharmony_ci /* Generate the bitmask of supported draw primitives. */ 266bf215546Sopenharmony_ci uint32_t modes = 1 << PIPE_PRIM_POINTS | 267bf215546Sopenharmony_ci 1 << PIPE_PRIM_LINES | 268bf215546Sopenharmony_ci 1 << PIPE_PRIM_LINE_STRIP | 269bf215546Sopenharmony_ci 1 << PIPE_PRIM_TRIANGLES | 270bf215546Sopenharmony_ci 1 << PIPE_PRIM_TRIANGLE_FAN; 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci /* TODO: The bug relates only to indexed draws, but here we signal 273bf215546Sopenharmony_ci * that there is no support for triangle strips at all. This should 274bf215546Sopenharmony_ci * be refined. 275bf215546Sopenharmony_ci */ 276bf215546Sopenharmony_ci if (VIV_FEATURE(screen, chipMinorFeatures2, BUG_FIXES8)) 277bf215546Sopenharmony_ci modes |= 1 << PIPE_PRIM_TRIANGLE_STRIP; 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci if (VIV_FEATURE(screen, chipMinorFeatures2, LINE_LOOP)) 280bf215546Sopenharmony_ci modes |= 1 << PIPE_PRIM_LINE_LOOP; 281bf215546Sopenharmony_ci 282bf215546Sopenharmony_ci return modes; 283bf215546Sopenharmony_ci } 284bf215546Sopenharmony_ci 285bf215546Sopenharmony_ci case PIPE_CAP_PCI_GROUP: 286bf215546Sopenharmony_ci case PIPE_CAP_PCI_BUS: 287bf215546Sopenharmony_ci case PIPE_CAP_PCI_DEVICE: 288bf215546Sopenharmony_ci case PIPE_CAP_PCI_FUNCTION: 289bf215546Sopenharmony_ci return 0; 290bf215546Sopenharmony_ci case PIPE_CAP_ACCELERATED: 291bf215546Sopenharmony_ci return 1; 292bf215546Sopenharmony_ci case PIPE_CAP_VIDEO_MEMORY: 293bf215546Sopenharmony_ci return 0; 294bf215546Sopenharmony_ci case PIPE_CAP_UMA: 295bf215546Sopenharmony_ci return 1; 296bf215546Sopenharmony_ci default: 297bf215546Sopenharmony_ci return u_pipe_screen_get_param_defaults(pscreen, param); 298bf215546Sopenharmony_ci } 299bf215546Sopenharmony_ci} 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_cistatic float 302bf215546Sopenharmony_cietna_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param) 303bf215546Sopenharmony_ci{ 304bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_ci switch (param) { 307bf215546Sopenharmony_ci case PIPE_CAPF_MIN_LINE_WIDTH: 308bf215546Sopenharmony_ci case PIPE_CAPF_MIN_LINE_WIDTH_AA: 309bf215546Sopenharmony_ci case PIPE_CAPF_MIN_POINT_SIZE: 310bf215546Sopenharmony_ci case PIPE_CAPF_MIN_POINT_SIZE_AA: 311bf215546Sopenharmony_ci return 1; 312bf215546Sopenharmony_ci case PIPE_CAPF_POINT_SIZE_GRANULARITY: 313bf215546Sopenharmony_ci case PIPE_CAPF_LINE_WIDTH_GRANULARITY: 314bf215546Sopenharmony_ci return 0.1; 315bf215546Sopenharmony_ci case PIPE_CAPF_MAX_LINE_WIDTH: 316bf215546Sopenharmony_ci case PIPE_CAPF_MAX_LINE_WIDTH_AA: 317bf215546Sopenharmony_ci case PIPE_CAPF_MAX_POINT_SIZE: 318bf215546Sopenharmony_ci case PIPE_CAPF_MAX_POINT_SIZE_AA: 319bf215546Sopenharmony_ci return 8192.0f; 320bf215546Sopenharmony_ci case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: 321bf215546Sopenharmony_ci return 16.0f; 322bf215546Sopenharmony_ci case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: 323bf215546Sopenharmony_ci return util_last_bit(screen->specs.max_texture_size); 324bf215546Sopenharmony_ci case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE: 325bf215546Sopenharmony_ci case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE: 326bf215546Sopenharmony_ci case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY: 327bf215546Sopenharmony_ci return 0.0f; 328bf215546Sopenharmony_ci } 329bf215546Sopenharmony_ci 330bf215546Sopenharmony_ci debug_printf("unknown paramf %d", param); 331bf215546Sopenharmony_ci return 0; 332bf215546Sopenharmony_ci} 333bf215546Sopenharmony_ci 334bf215546Sopenharmony_cistatic int 335bf215546Sopenharmony_cietna_screen_get_shader_param(struct pipe_screen *pscreen, 336bf215546Sopenharmony_ci enum pipe_shader_type shader, 337bf215546Sopenharmony_ci enum pipe_shader_cap param) 338bf215546Sopenharmony_ci{ 339bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 340bf215546Sopenharmony_ci bool ubo_enable = screen->specs.halti >= 2; 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_DEQP)) 343bf215546Sopenharmony_ci ubo_enable = true; 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci switch (shader) { 346bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 347bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 348bf215546Sopenharmony_ci break; 349bf215546Sopenharmony_ci case PIPE_SHADER_COMPUTE: 350bf215546Sopenharmony_ci case PIPE_SHADER_GEOMETRY: 351bf215546Sopenharmony_ci case PIPE_SHADER_TESS_CTRL: 352bf215546Sopenharmony_ci case PIPE_SHADER_TESS_EVAL: 353bf215546Sopenharmony_ci return 0; 354bf215546Sopenharmony_ci default: 355bf215546Sopenharmony_ci DBG("unknown shader type %d", shader); 356bf215546Sopenharmony_ci return 0; 357bf215546Sopenharmony_ci } 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_ci switch (param) { 360bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: 361bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: 362bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: 363bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: 364bf215546Sopenharmony_ci return ETNA_MAX_TOKENS; 365bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: 366bf215546Sopenharmony_ci return ETNA_MAX_DEPTH; /* XXX */ 367bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INPUTS: 368bf215546Sopenharmony_ci /* Maximum number of inputs for the vertex shader is the number 369bf215546Sopenharmony_ci * of vertex elements - each element defines one vertex shader 370bf215546Sopenharmony_ci * input register. For the fragment shader, this is the number 371bf215546Sopenharmony_ci * of varyings. */ 372bf215546Sopenharmony_ci return shader == PIPE_SHADER_FRAGMENT ? screen->specs.max_varyings 373bf215546Sopenharmony_ci : screen->specs.vertex_max_elements; 374bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_OUTPUTS: 375bf215546Sopenharmony_ci return 16; /* see VIVS_VS_OUTPUT */ 376bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEMPS: 377bf215546Sopenharmony_ci return 64; /* Max native temporaries. */ 378bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: 379bf215546Sopenharmony_ci return ubo_enable ? ETNA_MAX_CONST_BUF : 1; 380bf215546Sopenharmony_ci case PIPE_SHADER_CAP_CONT_SUPPORTED: 381bf215546Sopenharmony_ci return 1; 382bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: 383bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: 384bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: 385bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: 386bf215546Sopenharmony_ci return 1; 387bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUBROUTINES: 388bf215546Sopenharmony_ci return 0; 389bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED: 390bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures0, HAS_SQRT_TRIG); 391bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT64_ATOMICS: 392bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16: 393bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_DERIVATIVES: 394bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_CONST_BUFFERS: 395bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT16: 396bf215546Sopenharmony_ci case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS: 397bf215546Sopenharmony_ci return 0; 398bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INTEGERS: 399bf215546Sopenharmony_ci return screen->specs.halti >= 2; 400bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: 401bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: 402bf215546Sopenharmony_ci return shader == PIPE_SHADER_FRAGMENT 403bf215546Sopenharmony_ci ? screen->specs.fragment_sampler_count 404bf215546Sopenharmony_ci : screen->specs.vertex_sampler_count; 405bf215546Sopenharmony_ci case PIPE_SHADER_CAP_PREFERRED_IR: 406bf215546Sopenharmony_ci return PIPE_SHADER_IR_NIR; 407bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE: 408bf215546Sopenharmony_ci if (ubo_enable) 409bf215546Sopenharmony_ci return 16384; /* 16384 so state tracker enables UBOs */ 410bf215546Sopenharmony_ci return shader == PIPE_SHADER_FRAGMENT 411bf215546Sopenharmony_ci ? screen->specs.max_ps_uniforms * sizeof(float[4]) 412bf215546Sopenharmony_ci : screen->specs.max_vs_uniforms * sizeof(float[4]); 413bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DROUND_SUPPORTED: 414bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED: 415bf215546Sopenharmony_ci case PIPE_SHADER_CAP_LDEXP_SUPPORTED: 416bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE: 417bf215546Sopenharmony_ci return false; 418bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUPPORTED_IRS: 419bf215546Sopenharmony_ci return (1 << PIPE_SHADER_IR_TGSI) | 420bf215546Sopenharmony_ci (1 << PIPE_SHADER_IR_NIR); 421bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS: 422bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_IMAGES: 423bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS: 424bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS: 425bf215546Sopenharmony_ci return 0; 426bf215546Sopenharmony_ci } 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci debug_printf("unknown shader param %d", param); 429bf215546Sopenharmony_ci return 0; 430bf215546Sopenharmony_ci} 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_cistatic uint64_t 433bf215546Sopenharmony_cietna_screen_get_timestamp(struct pipe_screen *pscreen) 434bf215546Sopenharmony_ci{ 435bf215546Sopenharmony_ci return os_time_get_nano(); 436bf215546Sopenharmony_ci} 437bf215546Sopenharmony_ci 438bf215546Sopenharmony_cistatic bool 439bf215546Sopenharmony_cigpu_supports_texture_target(struct etna_screen *screen, 440bf215546Sopenharmony_ci enum pipe_texture_target target) 441bf215546Sopenharmony_ci{ 442bf215546Sopenharmony_ci if (target == PIPE_TEXTURE_CUBE_ARRAY) 443bf215546Sopenharmony_ci return false; 444bf215546Sopenharmony_ci 445bf215546Sopenharmony_ci /* pre-halti has no array/3D */ 446bf215546Sopenharmony_ci if (screen->specs.halti < 0 && 447bf215546Sopenharmony_ci (target == PIPE_TEXTURE_1D_ARRAY || 448bf215546Sopenharmony_ci target == PIPE_TEXTURE_2D_ARRAY || 449bf215546Sopenharmony_ci target == PIPE_TEXTURE_3D)) 450bf215546Sopenharmony_ci return false; 451bf215546Sopenharmony_ci 452bf215546Sopenharmony_ci return true; 453bf215546Sopenharmony_ci} 454bf215546Sopenharmony_ci 455bf215546Sopenharmony_cistatic bool 456bf215546Sopenharmony_cigpu_supports_texture_format(struct etna_screen *screen, uint32_t fmt, 457bf215546Sopenharmony_ci enum pipe_format format) 458bf215546Sopenharmony_ci{ 459bf215546Sopenharmony_ci bool supported = true; 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci if (fmt == TEXTURE_FORMAT_ETC1) 462bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipFeatures, ETC1_TEXTURE_COMPRESSION); 463bf215546Sopenharmony_ci 464bf215546Sopenharmony_ci if (fmt >= TEXTURE_FORMAT_DXT1 && fmt <= TEXTURE_FORMAT_DXT4_DXT5) 465bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipFeatures, DXT_TEXTURE_COMPRESSION); 466bf215546Sopenharmony_ci 467bf215546Sopenharmony_ci if (util_format_is_srgb(format)) 468bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 469bf215546Sopenharmony_ci 470bf215546Sopenharmony_ci if (fmt & EXT_FORMAT) 471bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 472bf215546Sopenharmony_ci 473bf215546Sopenharmony_ci if (fmt & ASTC_FORMAT) { 474bf215546Sopenharmony_ci supported = screen->specs.tex_astc; 475bf215546Sopenharmony_ci } 476bf215546Sopenharmony_ci 477bf215546Sopenharmony_ci if (util_format_is_snorm(format)) 478bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipMinorFeatures2, HALTI1); 479bf215546Sopenharmony_ci 480bf215546Sopenharmony_ci if (format != PIPE_FORMAT_S8_UINT_Z24_UNORM && 481bf215546Sopenharmony_ci (util_format_is_pure_integer(format) || util_format_is_float(format))) 482bf215546Sopenharmony_ci supported = VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_ci 485bf215546Sopenharmony_ci if (!supported) 486bf215546Sopenharmony_ci return false; 487bf215546Sopenharmony_ci 488bf215546Sopenharmony_ci if (texture_format_needs_swiz(format)) 489bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 490bf215546Sopenharmony_ci 491bf215546Sopenharmony_ci return true; 492bf215546Sopenharmony_ci} 493bf215546Sopenharmony_ci 494bf215546Sopenharmony_cistatic bool 495bf215546Sopenharmony_cigpu_supports_render_format(struct etna_screen *screen, enum pipe_format format, 496bf215546Sopenharmony_ci unsigned sample_count) 497bf215546Sopenharmony_ci{ 498bf215546Sopenharmony_ci const uint32_t fmt = translate_pe_format(format); 499bf215546Sopenharmony_ci 500bf215546Sopenharmony_ci if (fmt == ETNA_NO_MATCH) 501bf215546Sopenharmony_ci return false; 502bf215546Sopenharmony_ci 503bf215546Sopenharmony_ci /* MSAA is broken */ 504bf215546Sopenharmony_ci if (sample_count > 1) 505bf215546Sopenharmony_ci return false; 506bf215546Sopenharmony_ci 507bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8_UNORM) 508bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures5, HALTI5); 509bf215546Sopenharmony_ci 510bf215546Sopenharmony_ci /* figure out 8bpp RS clear to enable these formats */ 511bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8_SINT || format == PIPE_FORMAT_R8_UINT) 512bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures5, HALTI5); 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_ci if (util_format_is_srgb(format)) 515bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures5, HALTI3); 516bf215546Sopenharmony_ci 517bf215546Sopenharmony_ci if (util_format_is_pure_integer(format) || util_format_is_float(format)) 518bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 519bf215546Sopenharmony_ci 520bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8G8_UNORM) 521bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_ci /* any other extended format is HALTI0 (only R10G10B10A2?) */ 524bf215546Sopenharmony_ci if (fmt >= PE_FORMAT_R16F) 525bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures1, HALTI0); 526bf215546Sopenharmony_ci 527bf215546Sopenharmony_ci return true; 528bf215546Sopenharmony_ci} 529bf215546Sopenharmony_ci 530bf215546Sopenharmony_cistatic bool 531bf215546Sopenharmony_cigpu_supports_vertex_format(struct etna_screen *screen, enum pipe_format format) 532bf215546Sopenharmony_ci{ 533bf215546Sopenharmony_ci if (translate_vertex_format_type(format) == ETNA_NO_MATCH) 534bf215546Sopenharmony_ci return false; 535bf215546Sopenharmony_ci 536bf215546Sopenharmony_ci if (util_format_is_pure_integer(format)) 537bf215546Sopenharmony_ci return VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 538bf215546Sopenharmony_ci 539bf215546Sopenharmony_ci return true; 540bf215546Sopenharmony_ci} 541bf215546Sopenharmony_ci 542bf215546Sopenharmony_cistatic bool 543bf215546Sopenharmony_cietna_screen_is_format_supported(struct pipe_screen *pscreen, 544bf215546Sopenharmony_ci enum pipe_format format, 545bf215546Sopenharmony_ci enum pipe_texture_target target, 546bf215546Sopenharmony_ci unsigned sample_count, 547bf215546Sopenharmony_ci unsigned storage_sample_count, 548bf215546Sopenharmony_ci unsigned usage) 549bf215546Sopenharmony_ci{ 550bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 551bf215546Sopenharmony_ci unsigned allowed = 0; 552bf215546Sopenharmony_ci 553bf215546Sopenharmony_ci if (!gpu_supports_texture_target(screen, target)) 554bf215546Sopenharmony_ci return false; 555bf215546Sopenharmony_ci 556bf215546Sopenharmony_ci if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 557bf215546Sopenharmony_ci return false; 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_ci if (usage & PIPE_BIND_RENDER_TARGET) { 560bf215546Sopenharmony_ci if (gpu_supports_render_format(screen, format, sample_count)) 561bf215546Sopenharmony_ci allowed |= PIPE_BIND_RENDER_TARGET; 562bf215546Sopenharmony_ci } 563bf215546Sopenharmony_ci 564bf215546Sopenharmony_ci if (usage & PIPE_BIND_DEPTH_STENCIL) { 565bf215546Sopenharmony_ci if (translate_depth_format(format) != ETNA_NO_MATCH) 566bf215546Sopenharmony_ci allowed |= PIPE_BIND_DEPTH_STENCIL; 567bf215546Sopenharmony_ci } 568bf215546Sopenharmony_ci 569bf215546Sopenharmony_ci if (usage & PIPE_BIND_SAMPLER_VIEW) { 570bf215546Sopenharmony_ci uint32_t fmt = translate_texture_format(format); 571bf215546Sopenharmony_ci 572bf215546Sopenharmony_ci if (!gpu_supports_texture_format(screen, fmt, format)) 573bf215546Sopenharmony_ci fmt = ETNA_NO_MATCH; 574bf215546Sopenharmony_ci 575bf215546Sopenharmony_ci if (sample_count < 2 && fmt != ETNA_NO_MATCH) 576bf215546Sopenharmony_ci allowed |= PIPE_BIND_SAMPLER_VIEW; 577bf215546Sopenharmony_ci } 578bf215546Sopenharmony_ci 579bf215546Sopenharmony_ci if (usage & PIPE_BIND_VERTEX_BUFFER) { 580bf215546Sopenharmony_ci if (gpu_supports_vertex_format(screen, format)) 581bf215546Sopenharmony_ci allowed |= PIPE_BIND_VERTEX_BUFFER; 582bf215546Sopenharmony_ci } 583bf215546Sopenharmony_ci 584bf215546Sopenharmony_ci if (usage & PIPE_BIND_INDEX_BUFFER) { 585bf215546Sopenharmony_ci /* must be supported index format */ 586bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8_UINT || format == PIPE_FORMAT_R16_UINT || 587bf215546Sopenharmony_ci (format == PIPE_FORMAT_R32_UINT && 588bf215546Sopenharmony_ci VIV_FEATURE(screen, chipFeatures, 32_BIT_INDICES))) { 589bf215546Sopenharmony_ci allowed |= PIPE_BIND_INDEX_BUFFER; 590bf215546Sopenharmony_ci } 591bf215546Sopenharmony_ci } 592bf215546Sopenharmony_ci 593bf215546Sopenharmony_ci /* Always allowed */ 594bf215546Sopenharmony_ci allowed |= 595bf215546Sopenharmony_ci usage & (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED); 596bf215546Sopenharmony_ci 597bf215546Sopenharmony_ci if (usage != allowed) { 598bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, " 599bf215546Sopenharmony_ci "usage=%x, allowed=%x", 600bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage, allowed); 601bf215546Sopenharmony_ci } 602bf215546Sopenharmony_ci 603bf215546Sopenharmony_ci return usage == allowed; 604bf215546Sopenharmony_ci} 605bf215546Sopenharmony_ci 606bf215546Sopenharmony_ciconst uint64_t supported_modifiers[] = { 607bf215546Sopenharmony_ci DRM_FORMAT_MOD_LINEAR, 608bf215546Sopenharmony_ci DRM_FORMAT_MOD_VIVANTE_TILED, 609bf215546Sopenharmony_ci DRM_FORMAT_MOD_VIVANTE_SUPER_TILED, 610bf215546Sopenharmony_ci DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED, 611bf215546Sopenharmony_ci DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED, 612bf215546Sopenharmony_ci}; 613bf215546Sopenharmony_ci 614bf215546Sopenharmony_cistatic bool modifier_num_supported(struct pipe_screen *pscreen, int num) 615bf215546Sopenharmony_ci{ 616bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 617bf215546Sopenharmony_ci 618bf215546Sopenharmony_ci /* don't advertise split tiled formats on single pipe/buffer GPUs */ 619bf215546Sopenharmony_ci if ((screen->specs.pixel_pipes == 1 || screen->specs.single_buffer) && 620bf215546Sopenharmony_ci num >= 3) 621bf215546Sopenharmony_ci return false; 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci return true; 624bf215546Sopenharmony_ci} 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_cistatic void 627bf215546Sopenharmony_cietna_screen_query_dmabuf_modifiers(struct pipe_screen *pscreen, 628bf215546Sopenharmony_ci enum pipe_format format, int max, 629bf215546Sopenharmony_ci uint64_t *modifiers, 630bf215546Sopenharmony_ci unsigned int *external_only, int *count) 631bf215546Sopenharmony_ci{ 632bf215546Sopenharmony_ci int i, num_modifiers = 0; 633bf215546Sopenharmony_ci 634bf215546Sopenharmony_ci if (max > ARRAY_SIZE(supported_modifiers)) 635bf215546Sopenharmony_ci max = ARRAY_SIZE(supported_modifiers); 636bf215546Sopenharmony_ci 637bf215546Sopenharmony_ci if (!max) { 638bf215546Sopenharmony_ci modifiers = NULL; 639bf215546Sopenharmony_ci max = ARRAY_SIZE(supported_modifiers); 640bf215546Sopenharmony_ci } 641bf215546Sopenharmony_ci 642bf215546Sopenharmony_ci for (i = 0; num_modifiers < max; i++) { 643bf215546Sopenharmony_ci if (!modifier_num_supported(pscreen, i)) 644bf215546Sopenharmony_ci break; 645bf215546Sopenharmony_ci 646bf215546Sopenharmony_ci if (modifiers) 647bf215546Sopenharmony_ci modifiers[num_modifiers] = supported_modifiers[i]; 648bf215546Sopenharmony_ci if (external_only) 649bf215546Sopenharmony_ci external_only[num_modifiers] = util_format_is_yuv(format) ? 1 : 0; 650bf215546Sopenharmony_ci num_modifiers++; 651bf215546Sopenharmony_ci } 652bf215546Sopenharmony_ci 653bf215546Sopenharmony_ci *count = num_modifiers; 654bf215546Sopenharmony_ci} 655bf215546Sopenharmony_ci 656bf215546Sopenharmony_cistatic bool 657bf215546Sopenharmony_cietna_screen_is_dmabuf_modifier_supported(struct pipe_screen *pscreen, 658bf215546Sopenharmony_ci uint64_t modifier, 659bf215546Sopenharmony_ci enum pipe_format format, 660bf215546Sopenharmony_ci bool *external_only) 661bf215546Sopenharmony_ci{ 662bf215546Sopenharmony_ci int i; 663bf215546Sopenharmony_ci 664bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(supported_modifiers); i++) { 665bf215546Sopenharmony_ci if (!modifier_num_supported(pscreen, i)) 666bf215546Sopenharmony_ci break; 667bf215546Sopenharmony_ci 668bf215546Sopenharmony_ci if (modifier == supported_modifiers[i]) { 669bf215546Sopenharmony_ci if (external_only) 670bf215546Sopenharmony_ci *external_only = util_format_is_yuv(format) ? 1 : 0; 671bf215546Sopenharmony_ci 672bf215546Sopenharmony_ci return true; 673bf215546Sopenharmony_ci } 674bf215546Sopenharmony_ci } 675bf215546Sopenharmony_ci 676bf215546Sopenharmony_ci return false; 677bf215546Sopenharmony_ci} 678bf215546Sopenharmony_ci 679bf215546Sopenharmony_cistatic void 680bf215546Sopenharmony_cietna_determine_uniform_limits(struct etna_screen *screen) 681bf215546Sopenharmony_ci{ 682bf215546Sopenharmony_ci /* values for the non unified case are taken from 683bf215546Sopenharmony_ci * gcmCONFIGUREUNIFORMS in the Vivante kernel driver file 684bf215546Sopenharmony_ci * drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_base.h. 685bf215546Sopenharmony_ci */ 686bf215546Sopenharmony_ci if (screen->model == chipModel_GC2000 && 687bf215546Sopenharmony_ci (screen->revision == 0x5118 || screen->revision == 0x5140)) { 688bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 256; 689bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 64; 690bf215546Sopenharmony_ci } else if (screen->specs.num_constants == 320) { 691bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 256; 692bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 64; 693bf215546Sopenharmony_ci } else if (screen->specs.num_constants > 256 && 694bf215546Sopenharmony_ci screen->model == chipModel_GC1000) { 695bf215546Sopenharmony_ci /* All GC1000 series chips can only support 64 uniforms for ps on non-unified const mode. */ 696bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 256; 697bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 64; 698bf215546Sopenharmony_ci } else if (screen->specs.num_constants > 256) { 699bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 256; 700bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 256; 701bf215546Sopenharmony_ci } else if (screen->specs.num_constants == 256) { 702bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 256; 703bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 256; 704bf215546Sopenharmony_ci } else { 705bf215546Sopenharmony_ci screen->specs.max_vs_uniforms = 168; 706bf215546Sopenharmony_ci screen->specs.max_ps_uniforms = 64; 707bf215546Sopenharmony_ci } 708bf215546Sopenharmony_ci} 709bf215546Sopenharmony_ci 710bf215546Sopenharmony_cistatic void 711bf215546Sopenharmony_cietna_determine_sampler_limits(struct etna_screen *screen) 712bf215546Sopenharmony_ci{ 713bf215546Sopenharmony_ci /* vertex and fragment samplers live in one address space */ 714bf215546Sopenharmony_ci if (screen->specs.halti >= 1) { 715bf215546Sopenharmony_ci screen->specs.vertex_sampler_offset = 16; 716bf215546Sopenharmony_ci screen->specs.fragment_sampler_count = 16; 717bf215546Sopenharmony_ci screen->specs.vertex_sampler_count = 16; 718bf215546Sopenharmony_ci } else { 719bf215546Sopenharmony_ci screen->specs.vertex_sampler_offset = 8; 720bf215546Sopenharmony_ci screen->specs.fragment_sampler_count = 8; 721bf215546Sopenharmony_ci screen->specs.vertex_sampler_count = 4; 722bf215546Sopenharmony_ci } 723bf215546Sopenharmony_ci 724bf215546Sopenharmony_ci if (screen->model == 0x400) 725bf215546Sopenharmony_ci screen->specs.vertex_sampler_count = 0; 726bf215546Sopenharmony_ci} 727bf215546Sopenharmony_ci 728bf215546Sopenharmony_cistatic bool 729bf215546Sopenharmony_cietna_get_specs(struct etna_screen *screen) 730bf215546Sopenharmony_ci{ 731bf215546Sopenharmony_ci uint64_t val; 732bf215546Sopenharmony_ci uint32_t instruction_count; 733bf215546Sopenharmony_ci 734bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_INSTRUCTION_COUNT, &val)) { 735bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_INSTRUCTION_COUNT"); 736bf215546Sopenharmony_ci goto fail; 737bf215546Sopenharmony_ci } 738bf215546Sopenharmony_ci instruction_count = val; 739bf215546Sopenharmony_ci 740bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE, 741bf215546Sopenharmony_ci &val)) { 742bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_VERTEX_OUTPUT_BUFFER_SIZE"); 743bf215546Sopenharmony_ci goto fail; 744bf215546Sopenharmony_ci } 745bf215546Sopenharmony_ci screen->specs.vertex_output_buffer_size = val; 746bf215546Sopenharmony_ci 747bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_VERTEX_CACHE_SIZE, &val)) { 748bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_VERTEX_CACHE_SIZE"); 749bf215546Sopenharmony_ci goto fail; 750bf215546Sopenharmony_ci } 751bf215546Sopenharmony_ci screen->specs.vertex_cache_size = val; 752bf215546Sopenharmony_ci 753bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_SHADER_CORE_COUNT, &val)) { 754bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_SHADER_CORE_COUNT"); 755bf215546Sopenharmony_ci goto fail; 756bf215546Sopenharmony_ci } 757bf215546Sopenharmony_ci screen->specs.shader_core_count = val; 758bf215546Sopenharmony_ci 759bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_STREAM_COUNT, &val)) { 760bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_STREAM_COUNT"); 761bf215546Sopenharmony_ci goto fail; 762bf215546Sopenharmony_ci } 763bf215546Sopenharmony_ci screen->specs.stream_count = val; 764bf215546Sopenharmony_ci 765bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_REGISTER_MAX, &val)) { 766bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_REGISTER_MAX"); 767bf215546Sopenharmony_ci goto fail; 768bf215546Sopenharmony_ci } 769bf215546Sopenharmony_ci screen->specs.max_registers = val; 770bf215546Sopenharmony_ci 771bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_PIXEL_PIPES, &val)) { 772bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_PIXEL_PIPES"); 773bf215546Sopenharmony_ci goto fail; 774bf215546Sopenharmony_ci } 775bf215546Sopenharmony_ci screen->specs.pixel_pipes = val; 776bf215546Sopenharmony_ci 777bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_NUM_CONSTANTS, &val)) { 778bf215546Sopenharmony_ci DBG("could not get %s", "ETNA_GPU_NUM_CONSTANTS"); 779bf215546Sopenharmony_ci goto fail; 780bf215546Sopenharmony_ci } 781bf215546Sopenharmony_ci if (val == 0) { 782bf215546Sopenharmony_ci fprintf(stderr, "Warning: zero num constants (update kernel?)\n"); 783bf215546Sopenharmony_ci val = 168; 784bf215546Sopenharmony_ci } 785bf215546Sopenharmony_ci screen->specs.num_constants = val; 786bf215546Sopenharmony_ci 787bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_NUM_VARYINGS, &val)) { 788bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_NUM_VARYINGS"); 789bf215546Sopenharmony_ci goto fail; 790bf215546Sopenharmony_ci } 791bf215546Sopenharmony_ci screen->specs.max_varyings = MAX2(val, ETNA_NUM_VARYINGS); 792bf215546Sopenharmony_ci 793bf215546Sopenharmony_ci /* Figure out gross GPU architecture. See rnndb/common.xml for a specific 794bf215546Sopenharmony_ci * description of the differences. */ 795bf215546Sopenharmony_ci if (VIV_FEATURE(screen, chipMinorFeatures5, HALTI5)) 796bf215546Sopenharmony_ci screen->specs.halti = 5; /* New GC7000/GC8x00 */ 797bf215546Sopenharmony_ci else if (VIV_FEATURE(screen, chipMinorFeatures5, HALTI4)) 798bf215546Sopenharmony_ci screen->specs.halti = 4; /* Old GC7000/GC7400 */ 799bf215546Sopenharmony_ci else if (VIV_FEATURE(screen, chipMinorFeatures5, HALTI3)) 800bf215546Sopenharmony_ci screen->specs.halti = 3; /* None? */ 801bf215546Sopenharmony_ci else if (VIV_FEATURE(screen, chipMinorFeatures4, HALTI2)) 802bf215546Sopenharmony_ci screen->specs.halti = 2; /* GC2500/GC3000/GC5000/GC6400 */ 803bf215546Sopenharmony_ci else if (VIV_FEATURE(screen, chipMinorFeatures2, HALTI1)) 804bf215546Sopenharmony_ci screen->specs.halti = 1; /* GC900/GC4000/GC7000UL */ 805bf215546Sopenharmony_ci else if (VIV_FEATURE(screen, chipMinorFeatures1, HALTI0)) 806bf215546Sopenharmony_ci screen->specs.halti = 0; /* GC880/GC2000/GC7000TM */ 807bf215546Sopenharmony_ci else 808bf215546Sopenharmony_ci screen->specs.halti = -1; /* GC7000nanolite / pre-GC2000 except GC880 */ 809bf215546Sopenharmony_ci if (screen->specs.halti >= 0) 810bf215546Sopenharmony_ci DBG("etnaviv: GPU arch: HALTI%d", screen->specs.halti); 811bf215546Sopenharmony_ci else 812bf215546Sopenharmony_ci DBG("etnaviv: GPU arch: pre-HALTI"); 813bf215546Sopenharmony_ci 814bf215546Sopenharmony_ci screen->specs.can_supertile = 815bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures0, SUPER_TILED); 816bf215546Sopenharmony_ci screen->specs.bits_per_tile = 817bf215546Sopenharmony_ci !VIV_FEATURE(screen, chipMinorFeatures0, 2BITPERTILE) || 818bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures6, CACHE128B256BPERLINE) ? 4 : 2; 819bf215546Sopenharmony_ci 820bf215546Sopenharmony_ci screen->specs.ts_clear_value = 821bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures10, DEC400) ? 0xffffffff : 822bf215546Sopenharmony_ci screen->specs.bits_per_tile == 4 ? 0x11111111 : 0x55555555; 823bf215546Sopenharmony_ci 824bf215546Sopenharmony_ci screen->specs.vs_need_z_div = 825bf215546Sopenharmony_ci screen->model < 0x1000 && screen->model != 0x880; 826bf215546Sopenharmony_ci screen->specs.has_sin_cos_sqrt = 827bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures0, HAS_SQRT_TRIG); 828bf215546Sopenharmony_ci screen->specs.has_sign_floor_ceil = 829bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures0, HAS_SIGN_FLOOR_CEIL); 830bf215546Sopenharmony_ci screen->specs.has_shader_range_registers = 831bf215546Sopenharmony_ci screen->model >= 0x1000 || screen->model == 0x880; 832bf215546Sopenharmony_ci screen->specs.npot_tex_any_wrap = 833bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures1, NON_POWER_OF_TWO); 834bf215546Sopenharmony_ci screen->specs.has_new_transcendentals = 835bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures3, HAS_FAST_TRANSCENDENTALS); 836bf215546Sopenharmony_ci screen->specs.has_halti2_instructions = 837bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures4, HALTI2); 838bf215546Sopenharmony_ci screen->specs.has_no_oneconst_limit = 839bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures8, SH_NO_ONECONST_LIMIT); 840bf215546Sopenharmony_ci screen->specs.v4_compression = 841bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures6, V4_COMPRESSION); 842bf215546Sopenharmony_ci screen->specs.seamless_cube_map = 843bf215546Sopenharmony_ci (screen->model != 0x880) && /* Seamless cubemap is broken on GC880? */ 844bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures2, SEAMLESS_CUBE_MAP); 845bf215546Sopenharmony_ci 846bf215546Sopenharmony_ci if (screen->specs.halti >= 5) { 847bf215546Sopenharmony_ci /* GC7000 - this core must load shaders from memory. */ 848bf215546Sopenharmony_ci screen->specs.vs_offset = 0; 849bf215546Sopenharmony_ci screen->specs.ps_offset = 0; 850bf215546Sopenharmony_ci screen->specs.max_instructions = 0; /* Do not program shaders manually */ 851bf215546Sopenharmony_ci screen->specs.has_icache = true; 852bf215546Sopenharmony_ci } else if (VIV_FEATURE(screen, chipMinorFeatures3, INSTRUCTION_CACHE)) { 853bf215546Sopenharmony_ci /* GC3000 - this core is capable of loading shaders from 854bf215546Sopenharmony_ci * memory. It can also run shaders from registers, as a fallback, but 855bf215546Sopenharmony_ci * "max_instructions" does not have the correct value. It has place for 856bf215546Sopenharmony_ci * 2*256 instructions just like GC2000, but the offsets are slightly 857bf215546Sopenharmony_ci * different. 858bf215546Sopenharmony_ci */ 859bf215546Sopenharmony_ci screen->specs.vs_offset = 0xC000; 860bf215546Sopenharmony_ci /* State 08000-0C000 mirrors 0C000-0E000, and the Vivante driver uses 861bf215546Sopenharmony_ci * this mirror for writing PS instructions, probably safest to do the 862bf215546Sopenharmony_ci * same. 863bf215546Sopenharmony_ci */ 864bf215546Sopenharmony_ci screen->specs.ps_offset = 0x8000 + 0x1000; 865bf215546Sopenharmony_ci screen->specs.max_instructions = 256; /* maximum number instructions for non-icache use */ 866bf215546Sopenharmony_ci screen->specs.has_icache = true; 867bf215546Sopenharmony_ci } else { 868bf215546Sopenharmony_ci if (instruction_count > 256) { /* unified instruction memory? */ 869bf215546Sopenharmony_ci screen->specs.vs_offset = 0xC000; 870bf215546Sopenharmony_ci screen->specs.ps_offset = 0xD000; /* like vivante driver */ 871bf215546Sopenharmony_ci screen->specs.max_instructions = 256; 872bf215546Sopenharmony_ci } else { 873bf215546Sopenharmony_ci screen->specs.vs_offset = 0x4000; 874bf215546Sopenharmony_ci screen->specs.ps_offset = 0x6000; 875bf215546Sopenharmony_ci screen->specs.max_instructions = instruction_count; 876bf215546Sopenharmony_ci } 877bf215546Sopenharmony_ci screen->specs.has_icache = false; 878bf215546Sopenharmony_ci } 879bf215546Sopenharmony_ci 880bf215546Sopenharmony_ci if (VIV_FEATURE(screen, chipMinorFeatures1, HALTI0)) { 881bf215546Sopenharmony_ci screen->specs.vertex_max_elements = 16; 882bf215546Sopenharmony_ci } else { 883bf215546Sopenharmony_ci /* Etna_viv documentation seems confused over the correct value 884bf215546Sopenharmony_ci * here so choose the lower to be safe: HALTI0 says 16 i.s.o. 885bf215546Sopenharmony_ci * 10, but VERTEX_ELEMENT_CONFIG register says 16 i.s.o. 12. */ 886bf215546Sopenharmony_ci screen->specs.vertex_max_elements = 10; 887bf215546Sopenharmony_ci } 888bf215546Sopenharmony_ci 889bf215546Sopenharmony_ci etna_determine_uniform_limits(screen); 890bf215546Sopenharmony_ci etna_determine_sampler_limits(screen); 891bf215546Sopenharmony_ci 892bf215546Sopenharmony_ci if (screen->specs.halti >= 5) { 893bf215546Sopenharmony_ci screen->specs.has_unified_uniforms = true; 894bf215546Sopenharmony_ci screen->specs.vs_uniforms_offset = VIVS_SH_HALTI5_UNIFORMS_MIRROR(0); 895bf215546Sopenharmony_ci screen->specs.ps_uniforms_offset = VIVS_SH_HALTI5_UNIFORMS(screen->specs.max_vs_uniforms*4); 896bf215546Sopenharmony_ci } else if (screen->specs.halti >= 1) { 897bf215546Sopenharmony_ci /* unified uniform memory on GC3000 - HALTI1 feature bit is just a guess 898bf215546Sopenharmony_ci */ 899bf215546Sopenharmony_ci screen->specs.has_unified_uniforms = true; 900bf215546Sopenharmony_ci screen->specs.vs_uniforms_offset = VIVS_SH_UNIFORMS(0); 901bf215546Sopenharmony_ci /* hardcode PS uniforms to start after end of VS uniforms - 902bf215546Sopenharmony_ci * for more flexibility this offset could be variable based on the 903bf215546Sopenharmony_ci * shader. 904bf215546Sopenharmony_ci */ 905bf215546Sopenharmony_ci screen->specs.ps_uniforms_offset = VIVS_SH_UNIFORMS(screen->specs.max_vs_uniforms*4); 906bf215546Sopenharmony_ci } else { 907bf215546Sopenharmony_ci screen->specs.has_unified_uniforms = false; 908bf215546Sopenharmony_ci screen->specs.vs_uniforms_offset = VIVS_VS_UNIFORMS(0); 909bf215546Sopenharmony_ci screen->specs.ps_uniforms_offset = VIVS_PS_UNIFORMS(0); 910bf215546Sopenharmony_ci } 911bf215546Sopenharmony_ci 912bf215546Sopenharmony_ci screen->specs.max_texture_size = 913bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures0, TEXTURE_8K) ? 8192 : 2048; 914bf215546Sopenharmony_ci screen->specs.max_rendertarget_size = 915bf215546Sopenharmony_ci VIV_FEATURE(screen, chipMinorFeatures0, RENDERTARGET_8K) ? 8192 : 2048; 916bf215546Sopenharmony_ci 917bf215546Sopenharmony_ci screen->specs.single_buffer = VIV_FEATURE(screen, chipMinorFeatures4, SINGLE_BUFFER); 918bf215546Sopenharmony_ci if (screen->specs.single_buffer) 919bf215546Sopenharmony_ci DBG("etnaviv: Single buffer mode enabled with %d pixel pipes", screen->specs.pixel_pipes); 920bf215546Sopenharmony_ci 921bf215546Sopenharmony_ci screen->specs.tex_astc = VIV_FEATURE(screen, chipMinorFeatures4, TEXTURE_ASTC) && 922bf215546Sopenharmony_ci !VIV_FEATURE(screen, chipMinorFeatures6, NO_ASTC); 923bf215546Sopenharmony_ci 924bf215546Sopenharmony_ci screen->specs.use_blt = VIV_FEATURE(screen, chipMinorFeatures5, BLT_ENGINE); 925bf215546Sopenharmony_ci 926bf215546Sopenharmony_ci /* Only allow fast clear with MC2.0, as the TS unit bypasses the memory 927bf215546Sopenharmony_ci * offset on MC1.0 and we have no way to fixup the address. 928bf215546Sopenharmony_ci */ 929bf215546Sopenharmony_ci if (!VIV_FEATURE(screen, chipMinorFeatures0, MC20)) 930bf215546Sopenharmony_ci screen->features[viv_chipFeatures] &= ~chipFeatures_FAST_CLEAR; 931bf215546Sopenharmony_ci 932bf215546Sopenharmony_ci return true; 933bf215546Sopenharmony_ci 934bf215546Sopenharmony_cifail: 935bf215546Sopenharmony_ci return false; 936bf215546Sopenharmony_ci} 937bf215546Sopenharmony_ci 938bf215546Sopenharmony_cistruct etna_bo * 939bf215546Sopenharmony_cietna_screen_bo_from_handle(struct pipe_screen *pscreen, 940bf215546Sopenharmony_ci struct winsys_handle *whandle) 941bf215546Sopenharmony_ci{ 942bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 943bf215546Sopenharmony_ci struct etna_bo *bo; 944bf215546Sopenharmony_ci 945bf215546Sopenharmony_ci if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) { 946bf215546Sopenharmony_ci bo = etna_bo_from_name(screen->dev, whandle->handle); 947bf215546Sopenharmony_ci } else if (whandle->type == WINSYS_HANDLE_TYPE_FD) { 948bf215546Sopenharmony_ci bo = etna_bo_from_dmabuf(screen->dev, whandle->handle); 949bf215546Sopenharmony_ci } else { 950bf215546Sopenharmony_ci DBG("Attempt to import unsupported handle type %d", whandle->type); 951bf215546Sopenharmony_ci return NULL; 952bf215546Sopenharmony_ci } 953bf215546Sopenharmony_ci 954bf215546Sopenharmony_ci if (!bo) { 955bf215546Sopenharmony_ci DBG("ref name 0x%08x failed", whandle->handle); 956bf215546Sopenharmony_ci return NULL; 957bf215546Sopenharmony_ci } 958bf215546Sopenharmony_ci 959bf215546Sopenharmony_ci return bo; 960bf215546Sopenharmony_ci} 961bf215546Sopenharmony_ci 962bf215546Sopenharmony_cistatic const void * 963bf215546Sopenharmony_cietna_get_compiler_options(struct pipe_screen *pscreen, 964bf215546Sopenharmony_ci enum pipe_shader_ir ir, unsigned shader) 965bf215546Sopenharmony_ci{ 966bf215546Sopenharmony_ci return etna_compiler_get_options(etna_screen(pscreen)->compiler); 967bf215546Sopenharmony_ci} 968bf215546Sopenharmony_ci 969bf215546Sopenharmony_cistatic struct disk_cache * 970bf215546Sopenharmony_cietna_get_disk_shader_cache(struct pipe_screen *pscreen) 971bf215546Sopenharmony_ci{ 972bf215546Sopenharmony_ci struct etna_screen *screen = etna_screen(pscreen); 973bf215546Sopenharmony_ci struct etna_compiler *compiler = screen->compiler; 974bf215546Sopenharmony_ci 975bf215546Sopenharmony_ci return compiler->disk_cache; 976bf215546Sopenharmony_ci} 977bf215546Sopenharmony_ci 978bf215546Sopenharmony_cistruct pipe_screen * 979bf215546Sopenharmony_cietna_screen_create(struct etna_device *dev, struct etna_gpu *gpu, 980bf215546Sopenharmony_ci struct renderonly *ro) 981bf215546Sopenharmony_ci{ 982bf215546Sopenharmony_ci struct etna_screen *screen = CALLOC_STRUCT(etna_screen); 983bf215546Sopenharmony_ci struct pipe_screen *pscreen; 984bf215546Sopenharmony_ci uint64_t val; 985bf215546Sopenharmony_ci 986bf215546Sopenharmony_ci if (!screen) 987bf215546Sopenharmony_ci return NULL; 988bf215546Sopenharmony_ci 989bf215546Sopenharmony_ci pscreen = &screen->base; 990bf215546Sopenharmony_ci screen->dev = dev; 991bf215546Sopenharmony_ci screen->gpu = gpu; 992bf215546Sopenharmony_ci screen->ro = ro; 993bf215546Sopenharmony_ci screen->refcnt = 1; 994bf215546Sopenharmony_ci 995bf215546Sopenharmony_ci screen->drm_version = etnaviv_device_version(screen->dev); 996bf215546Sopenharmony_ci etna_mesa_debug = debug_get_option_etna_mesa_debug(); 997bf215546Sopenharmony_ci 998bf215546Sopenharmony_ci /* Disable autodisable for correct rendering with TS */ 999bf215546Sopenharmony_ci etna_mesa_debug |= ETNA_DBG_NO_AUTODISABLE; 1000bf215546Sopenharmony_ci 1001bf215546Sopenharmony_ci screen->pipe = etna_pipe_new(gpu, ETNA_PIPE_3D); 1002bf215546Sopenharmony_ci if (!screen->pipe) { 1003bf215546Sopenharmony_ci DBG("could not create 3d pipe"); 1004bf215546Sopenharmony_ci goto fail; 1005bf215546Sopenharmony_ci } 1006bf215546Sopenharmony_ci 1007bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_MODEL, &val)) { 1008bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_MODEL"); 1009bf215546Sopenharmony_ci goto fail; 1010bf215546Sopenharmony_ci } 1011bf215546Sopenharmony_ci screen->model = val; 1012bf215546Sopenharmony_ci 1013bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_REVISION, &val)) { 1014bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_REVISION"); 1015bf215546Sopenharmony_ci goto fail; 1016bf215546Sopenharmony_ci } 1017bf215546Sopenharmony_ci screen->revision = val; 1018bf215546Sopenharmony_ci 1019bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_0, &val)) { 1020bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_0"); 1021bf215546Sopenharmony_ci goto fail; 1022bf215546Sopenharmony_ci } 1023bf215546Sopenharmony_ci screen->features[0] = val; 1024bf215546Sopenharmony_ci 1025bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_1, &val)) { 1026bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_1"); 1027bf215546Sopenharmony_ci goto fail; 1028bf215546Sopenharmony_ci } 1029bf215546Sopenharmony_ci screen->features[1] = val; 1030bf215546Sopenharmony_ci 1031bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_2, &val)) { 1032bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_2"); 1033bf215546Sopenharmony_ci goto fail; 1034bf215546Sopenharmony_ci } 1035bf215546Sopenharmony_ci screen->features[2] = val; 1036bf215546Sopenharmony_ci 1037bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_3, &val)) { 1038bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_3"); 1039bf215546Sopenharmony_ci goto fail; 1040bf215546Sopenharmony_ci } 1041bf215546Sopenharmony_ci screen->features[3] = val; 1042bf215546Sopenharmony_ci 1043bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_4, &val)) { 1044bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_4"); 1045bf215546Sopenharmony_ci goto fail; 1046bf215546Sopenharmony_ci } 1047bf215546Sopenharmony_ci screen->features[4] = val; 1048bf215546Sopenharmony_ci 1049bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_5, &val)) { 1050bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_5"); 1051bf215546Sopenharmony_ci goto fail; 1052bf215546Sopenharmony_ci } 1053bf215546Sopenharmony_ci screen->features[5] = val; 1054bf215546Sopenharmony_ci 1055bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_6, &val)) { 1056bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_6"); 1057bf215546Sopenharmony_ci goto fail; 1058bf215546Sopenharmony_ci } 1059bf215546Sopenharmony_ci screen->features[6] = val; 1060bf215546Sopenharmony_ci 1061bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_7, &val)) { 1062bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_7"); 1063bf215546Sopenharmony_ci goto fail; 1064bf215546Sopenharmony_ci } 1065bf215546Sopenharmony_ci screen->features[7] = val; 1066bf215546Sopenharmony_ci 1067bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_8, &val)) { 1068bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_8"); 1069bf215546Sopenharmony_ci goto fail; 1070bf215546Sopenharmony_ci } 1071bf215546Sopenharmony_ci screen->features[8] = val; 1072bf215546Sopenharmony_ci 1073bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_9, &val)) { 1074bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_9"); 1075bf215546Sopenharmony_ci goto fail; 1076bf215546Sopenharmony_ci } 1077bf215546Sopenharmony_ci screen->features[9] = val; 1078bf215546Sopenharmony_ci 1079bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_10, &val)) { 1080bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_10"); 1081bf215546Sopenharmony_ci goto fail; 1082bf215546Sopenharmony_ci } 1083bf215546Sopenharmony_ci screen->features[10] = val; 1084bf215546Sopenharmony_ci 1085bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_11, &val)) { 1086bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_11"); 1087bf215546Sopenharmony_ci goto fail; 1088bf215546Sopenharmony_ci } 1089bf215546Sopenharmony_ci screen->features[11] = val; 1090bf215546Sopenharmony_ci 1091bf215546Sopenharmony_ci if (etna_gpu_get_param(screen->gpu, ETNA_GPU_FEATURES_12, &val)) { 1092bf215546Sopenharmony_ci DBG("could not get ETNA_GPU_FEATURES_12"); 1093bf215546Sopenharmony_ci goto fail; 1094bf215546Sopenharmony_ci } 1095bf215546Sopenharmony_ci screen->features[12] = val; 1096bf215546Sopenharmony_ci 1097bf215546Sopenharmony_ci if (!etna_get_specs(screen)) 1098bf215546Sopenharmony_ci goto fail; 1099bf215546Sopenharmony_ci 1100bf215546Sopenharmony_ci if (screen->specs.halti >= 5 && !etnaviv_device_softpin_capable(dev)) { 1101bf215546Sopenharmony_ci DBG("halti5 requires softpin"); 1102bf215546Sopenharmony_ci goto fail; 1103bf215546Sopenharmony_ci } 1104bf215546Sopenharmony_ci 1105bf215546Sopenharmony_ci /* apply debug options that disable individual features */ 1106bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_EARLY_Z)) 1107bf215546Sopenharmony_ci screen->features[viv_chipFeatures] |= chipFeatures_NO_EARLY_Z; 1108bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_TS)) 1109bf215546Sopenharmony_ci screen->features[viv_chipFeatures] &= ~chipFeatures_FAST_CLEAR; 1110bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_AUTODISABLE)) 1111bf215546Sopenharmony_ci screen->features[viv_chipMinorFeatures1] &= ~chipMinorFeatures1_AUTO_DISABLE; 1112bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_SUPERTILE)) 1113bf215546Sopenharmony_ci screen->specs.can_supertile = 0; 1114bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_SINGLEBUF)) 1115bf215546Sopenharmony_ci screen->specs.single_buffer = 0; 1116bf215546Sopenharmony_ci if (DBG_ENABLED(ETNA_DBG_NO_LINEAR_PE)) 1117bf215546Sopenharmony_ci screen->features[viv_chipMinorFeatures2] &= ~chipMinorFeatures2_LINEAR_PE; 1118bf215546Sopenharmony_ci 1119bf215546Sopenharmony_ci pscreen->destroy = etna_screen_destroy; 1120bf215546Sopenharmony_ci pscreen->get_param = etna_screen_get_param; 1121bf215546Sopenharmony_ci pscreen->get_paramf = etna_screen_get_paramf; 1122bf215546Sopenharmony_ci pscreen->get_shader_param = etna_screen_get_shader_param; 1123bf215546Sopenharmony_ci pscreen->get_compiler_options = etna_get_compiler_options; 1124bf215546Sopenharmony_ci pscreen->get_disk_shader_cache = etna_get_disk_shader_cache; 1125bf215546Sopenharmony_ci 1126bf215546Sopenharmony_ci pscreen->get_name = etna_screen_get_name; 1127bf215546Sopenharmony_ci pscreen->get_vendor = etna_screen_get_vendor; 1128bf215546Sopenharmony_ci pscreen->get_device_vendor = etna_screen_get_device_vendor; 1129bf215546Sopenharmony_ci 1130bf215546Sopenharmony_ci pscreen->get_timestamp = etna_screen_get_timestamp; 1131bf215546Sopenharmony_ci pscreen->context_create = etna_context_create; 1132bf215546Sopenharmony_ci pscreen->is_format_supported = etna_screen_is_format_supported; 1133bf215546Sopenharmony_ci pscreen->query_dmabuf_modifiers = etna_screen_query_dmabuf_modifiers; 1134bf215546Sopenharmony_ci pscreen->is_dmabuf_modifier_supported = etna_screen_is_dmabuf_modifier_supported; 1135bf215546Sopenharmony_ci 1136bf215546Sopenharmony_ci if (!etna_shader_screen_init(pscreen)) 1137bf215546Sopenharmony_ci goto fail; 1138bf215546Sopenharmony_ci 1139bf215546Sopenharmony_ci etna_fence_screen_init(pscreen); 1140bf215546Sopenharmony_ci etna_query_screen_init(pscreen); 1141bf215546Sopenharmony_ci etna_resource_screen_init(pscreen); 1142bf215546Sopenharmony_ci 1143bf215546Sopenharmony_ci util_dynarray_init(&screen->supported_pm_queries, NULL); 1144bf215546Sopenharmony_ci slab_create_parent(&screen->transfer_pool, sizeof(struct etna_transfer), 16); 1145bf215546Sopenharmony_ci 1146bf215546Sopenharmony_ci if (screen->drm_version >= ETNA_DRM_VERSION_PERFMON) 1147bf215546Sopenharmony_ci etna_pm_query_setup(screen); 1148bf215546Sopenharmony_ci 1149bf215546Sopenharmony_ci 1150bf215546Sopenharmony_ci /* create dummy RT buffer, used when rendering with no color buffer */ 1151bf215546Sopenharmony_ci screen->dummy_rt_reloc.bo = etna_bo_new(screen->dev, 64 * 64 * 4, 1152bf215546Sopenharmony_ci DRM_ETNA_GEM_CACHE_WC); 1153bf215546Sopenharmony_ci if (!screen->dummy_rt_reloc.bo) 1154bf215546Sopenharmony_ci goto fail; 1155bf215546Sopenharmony_ci 1156bf215546Sopenharmony_ci screen->dummy_rt_reloc.offset = 0; 1157bf215546Sopenharmony_ci screen->dummy_rt_reloc.flags = ETNA_RELOC_READ | ETNA_RELOC_WRITE; 1158bf215546Sopenharmony_ci 1159bf215546Sopenharmony_ci if (screen->specs.halti >= 5) { 1160bf215546Sopenharmony_ci void *buf; 1161bf215546Sopenharmony_ci 1162bf215546Sopenharmony_ci /* create an empty dummy texture descriptor */ 1163bf215546Sopenharmony_ci screen->dummy_desc_reloc.bo = etna_bo_new(screen->dev, 0x100, 1164bf215546Sopenharmony_ci DRM_ETNA_GEM_CACHE_WC); 1165bf215546Sopenharmony_ci if (!screen->dummy_desc_reloc.bo) 1166bf215546Sopenharmony_ci goto fail; 1167bf215546Sopenharmony_ci 1168bf215546Sopenharmony_ci buf = etna_bo_map(screen->dummy_desc_reloc.bo); 1169bf215546Sopenharmony_ci etna_bo_cpu_prep(screen->dummy_desc_reloc.bo, DRM_ETNA_PREP_WRITE); 1170bf215546Sopenharmony_ci memset(buf, 0, 0x100); 1171bf215546Sopenharmony_ci etna_bo_cpu_fini(screen->dummy_desc_reloc.bo); 1172bf215546Sopenharmony_ci screen->dummy_desc_reloc.offset = 0; 1173bf215546Sopenharmony_ci screen->dummy_desc_reloc.flags = ETNA_RELOC_READ; 1174bf215546Sopenharmony_ci } 1175bf215546Sopenharmony_ci 1176bf215546Sopenharmony_ci return pscreen; 1177bf215546Sopenharmony_ci 1178bf215546Sopenharmony_cifail: 1179bf215546Sopenharmony_ci etna_screen_destroy(pscreen); 1180bf215546Sopenharmony_ci return NULL; 1181bf215546Sopenharmony_ci} 1182