1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * Copyright © 2018 Google, Inc. 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22bf215546Sopenharmony_ci * SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci * Authors: 25bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "drm-uapi/drm_fourcc.h" 29bf215546Sopenharmony_ci#include "pipe/p_screen.h" 30bf215546Sopenharmony_ci#include "util/format/u_format.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "fd6_blitter.h" 33bf215546Sopenharmony_ci#include "fd6_context.h" 34bf215546Sopenharmony_ci#include "fd6_emit.h" 35bf215546Sopenharmony_ci#include "fd6_resource.h" 36bf215546Sopenharmony_ci#include "fd6_screen.h" 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#include "ir3/ir3_compiler.h" 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_cistatic bool 41bf215546Sopenharmony_civalid_sample_count(unsigned sample_count) 42bf215546Sopenharmony_ci{ 43bf215546Sopenharmony_ci switch (sample_count) { 44bf215546Sopenharmony_ci case 0: 45bf215546Sopenharmony_ci case 1: 46bf215546Sopenharmony_ci case 2: 47bf215546Sopenharmony_ci case 4: 48bf215546Sopenharmony_ci // TODO seems 8x works, but increases lrz width or height.. but the 49bf215546Sopenharmony_ci // blob I have doesn't seem to expose any egl configs w/ 8x, so 50bf215546Sopenharmony_ci // just hide it for now and revisit later. 51bf215546Sopenharmony_ci // case 8: 52bf215546Sopenharmony_ci return true; 53bf215546Sopenharmony_ci default: 54bf215546Sopenharmony_ci return false; 55bf215546Sopenharmony_ci } 56bf215546Sopenharmony_ci} 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_cistatic bool 59bf215546Sopenharmony_cifd6_screen_is_format_supported(struct pipe_screen *pscreen, 60bf215546Sopenharmony_ci enum pipe_format format, 61bf215546Sopenharmony_ci enum pipe_texture_target target, 62bf215546Sopenharmony_ci unsigned sample_count, 63bf215546Sopenharmony_ci unsigned storage_sample_count, unsigned usage) 64bf215546Sopenharmony_ci{ 65bf215546Sopenharmony_ci unsigned retval = 0; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci if ((target >= PIPE_MAX_TEXTURE_TYPES) || 68bf215546Sopenharmony_ci !valid_sample_count(sample_count)) { 69bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x", 70bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage); 71bf215546Sopenharmony_ci return false; 72bf215546Sopenharmony_ci } 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 75bf215546Sopenharmony_ci return false; 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci if ((usage & PIPE_BIND_VERTEX_BUFFER) && 78bf215546Sopenharmony_ci (fd6_vertex_format(format) != FMT6_NONE)) { 79bf215546Sopenharmony_ci retval |= PIPE_BIND_VERTEX_BUFFER; 80bf215546Sopenharmony_ci } 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci bool has_color = fd6_color_format(format, TILE6_LINEAR) != FMT6_NONE; 83bf215546Sopenharmony_ci bool has_tex = fd6_texture_format(format, TILE6_LINEAR) != FMT6_NONE; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) && 86bf215546Sopenharmony_ci has_tex && 87bf215546Sopenharmony_ci (target == PIPE_BUFFER || 88bf215546Sopenharmony_ci util_is_power_of_two_or_zero(util_format_get_blocksize(format)))) { 89bf215546Sopenharmony_ci retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE); 90bf215546Sopenharmony_ci } 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (usage & PIPE_BIND_SHADER_IMAGE) { 93bf215546Sopenharmony_ci if (sample_count > 1) 94bf215546Sopenharmony_ci return false; 95bf215546Sopenharmony_ci } 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci if ((usage & 98bf215546Sopenharmony_ci (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 99bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) && 100bf215546Sopenharmony_ci has_color && has_tex) { 101bf215546Sopenharmony_ci retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 102bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | 103bf215546Sopenharmony_ci PIPE_BIND_COMPUTE_RESOURCE); 104bf215546Sopenharmony_ci } 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci /* For ARB_framebuffer_no_attachments: */ 107bf215546Sopenharmony_ci if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) { 108bf215546Sopenharmony_ci retval |= usage & PIPE_BIND_RENDER_TARGET; 109bf215546Sopenharmony_ci } 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci if ((usage & PIPE_BIND_DEPTH_STENCIL) && 112bf215546Sopenharmony_ci (fd6_pipe2depth(format) != (enum a6xx_depth_format) ~0) && has_tex) { 113bf215546Sopenharmony_ci retval |= PIPE_BIND_DEPTH_STENCIL; 114bf215546Sopenharmony_ci } 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci if ((usage & PIPE_BIND_INDEX_BUFFER) && 117bf215546Sopenharmony_ci (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) { 118bf215546Sopenharmony_ci retval |= PIPE_BIND_INDEX_BUFFER; 119bf215546Sopenharmony_ci } 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci if (retval != usage) { 122bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, " 123bf215546Sopenharmony_ci "usage=%x, retval=%x", 124bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage, retval); 125bf215546Sopenharmony_ci } 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci return retval == usage; 128bf215546Sopenharmony_ci} 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci/* clang-format off */ 131bf215546Sopenharmony_cistatic const enum pc_di_primtype primtypes[] = { 132bf215546Sopenharmony_ci [PIPE_PRIM_POINTS] = DI_PT_POINTLIST, 133bf215546Sopenharmony_ci [PIPE_PRIM_LINES] = DI_PT_LINELIST, 134bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, 135bf215546Sopenharmony_ci [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP, 136bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST, 137bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, 138bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, 139bf215546Sopenharmony_ci [PIPE_PRIM_LINES_ADJACENCY] = DI_PT_LINE_ADJ, 140bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP_ADJACENCY] = DI_PT_LINESTRIP_ADJ, 141bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLES_ADJACENCY] = DI_PT_TRI_ADJ, 142bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = DI_PT_TRISTRIP_ADJ, 143bf215546Sopenharmony_ci [PIPE_PRIM_PATCHES] = DI_PT_PATCHES0, 144bf215546Sopenharmony_ci [PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */ 145bf215546Sopenharmony_ci}; 146bf215546Sopenharmony_ci/* clang-format on */ 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_civoid 149bf215546Sopenharmony_cifd6_screen_init(struct pipe_screen *pscreen) 150bf215546Sopenharmony_ci{ 151bf215546Sopenharmony_ci struct fd_screen *screen = fd_screen(pscreen); 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci screen->max_rts = A6XX_MAX_RENDER_TARGETS; 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci screen->ccu_offset_bypass = screen->info->num_ccu * A6XX_CCU_DEPTH_SIZE; 156bf215546Sopenharmony_ci screen->ccu_offset_gmem = (screen->gmemsize_bytes - 157bf215546Sopenharmony_ci screen->info->num_ccu * A6XX_CCU_GMEM_COLOR_SIZE); 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci /* Currently only FB_READ forces GMEM path, mostly because we'd have to 160bf215546Sopenharmony_ci * deal with cmdstream patching otherwise.. 161bf215546Sopenharmony_ci */ 162bf215546Sopenharmony_ci screen->gmem_reason_mask = FD_GMEM_CLEARS_DEPTH_STENCIL | 163bf215546Sopenharmony_ci FD_GMEM_DEPTH_ENABLED | FD_GMEM_STENCIL_ENABLED | 164bf215546Sopenharmony_ci FD_GMEM_BLEND_ENABLED | FD_GMEM_LOGICOP_ENABLED; 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ci pscreen->context_create = fd6_context_create; 167bf215546Sopenharmony_ci pscreen->is_format_supported = fd6_screen_is_format_supported; 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci screen->tile_mode = fd6_tile_mode; 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci fd6_resource_screen_init(pscreen); 172bf215546Sopenharmony_ci fd6_emit_init_screen(pscreen); 173bf215546Sopenharmony_ci ir3_screen_init(pscreen); 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci screen->primtypes = primtypes; 176bf215546Sopenharmony_ci} 177