1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org> 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, sublicense, 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 next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * 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 NONINFRINGEMENT. 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 FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "pipe/p_screen.h" 28bf215546Sopenharmony_ci#include "util/format/u_format.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "fd2_context.h" 31bf215546Sopenharmony_ci#include "fd2_emit.h" 32bf215546Sopenharmony_ci#include "fd2_resource.h" 33bf215546Sopenharmony_ci#include "fd2_screen.h" 34bf215546Sopenharmony_ci#include "fd2_util.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_cistatic bool 37bf215546Sopenharmony_cifd2_screen_is_format_supported(struct pipe_screen *pscreen, 38bf215546Sopenharmony_ci enum pipe_format format, 39bf215546Sopenharmony_ci enum pipe_texture_target target, 40bf215546Sopenharmony_ci unsigned sample_count, 41bf215546Sopenharmony_ci unsigned storage_sample_count, unsigned usage) 42bf215546Sopenharmony_ci{ 43bf215546Sopenharmony_ci unsigned retval = 0; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci if ((target >= PIPE_MAX_TEXTURE_TYPES) || 46bf215546Sopenharmony_ci (sample_count > 1)) { /* TODO add MSAA */ 47bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x", 48bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage); 49bf215546Sopenharmony_ci return false; 50bf215546Sopenharmony_ci } 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 53bf215546Sopenharmony_ci return false; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci if ((usage & PIPE_BIND_RENDER_TARGET) && 56bf215546Sopenharmony_ci fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0) { 57bf215546Sopenharmony_ci retval |= PIPE_BIND_RENDER_TARGET; 58bf215546Sopenharmony_ci } 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_VERTEX_BUFFER)) && 61bf215546Sopenharmony_ci !util_format_is_srgb(format) && !util_format_is_pure_integer(format) && 62bf215546Sopenharmony_ci fd2_pipe2surface(format).format != FMT_INVALID) { 63bf215546Sopenharmony_ci retval |= usage & PIPE_BIND_VERTEX_BUFFER; 64bf215546Sopenharmony_ci /* the only npot blocksize supported texture format is R32G32B32_FLOAT */ 65bf215546Sopenharmony_ci if (util_is_power_of_two_or_zero(util_format_get_blocksize(format)) || 66bf215546Sopenharmony_ci format == PIPE_FORMAT_R32G32B32_FLOAT) 67bf215546Sopenharmony_ci retval |= usage & PIPE_BIND_SAMPLER_VIEW; 68bf215546Sopenharmony_ci } 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci if ((usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 71bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) && 72bf215546Sopenharmony_ci (fd2_pipe2color(format) != (enum a2xx_colorformatx) ~0)) { 73bf215546Sopenharmony_ci retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 74bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED); 75bf215546Sopenharmony_ci } 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci if ((usage & PIPE_BIND_DEPTH_STENCIL) && 78bf215546Sopenharmony_ci (fd_pipe2depth(format) != (enum adreno_rb_depth_format) ~0)) { 79bf215546Sopenharmony_ci retval |= PIPE_BIND_DEPTH_STENCIL; 80bf215546Sopenharmony_ci } 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci if ((usage & PIPE_BIND_INDEX_BUFFER) && 83bf215546Sopenharmony_ci (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) { 84bf215546Sopenharmony_ci retval |= PIPE_BIND_INDEX_BUFFER; 85bf215546Sopenharmony_ci } 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci if (retval != usage) { 88bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, " 89bf215546Sopenharmony_ci "usage=%x, retval=%x", 90bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage, retval); 91bf215546Sopenharmony_ci } 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci return retval == usage; 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci/* clang-format off */ 97bf215546Sopenharmony_cistatic const enum pc_di_primtype a22x_primtypes[PIPE_PRIM_MAX] = { 98bf215546Sopenharmony_ci [PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE, 99bf215546Sopenharmony_ci [PIPE_PRIM_LINES] = DI_PT_LINELIST, 100bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, 101bf215546Sopenharmony_ci [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP, 102bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST, 103bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, 104bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, 105bf215546Sopenharmony_ci}; 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_cistatic const enum pc_di_primtype a20x_primtypes[PIPE_PRIM_MAX] = { 108bf215546Sopenharmony_ci [PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE, 109bf215546Sopenharmony_ci [PIPE_PRIM_LINES] = DI_PT_LINELIST, 110bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, 111bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST, 112bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, 113bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, 114bf215546Sopenharmony_ci}; 115bf215546Sopenharmony_ci/* clang-format on */ 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_civoid 118bf215546Sopenharmony_cifd2_screen_init(struct pipe_screen *pscreen) 119bf215546Sopenharmony_ci{ 120bf215546Sopenharmony_ci struct fd_screen *screen = fd_screen(pscreen); 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci screen->max_rts = 1; 123bf215546Sopenharmony_ci pscreen->context_create = fd2_context_create; 124bf215546Sopenharmony_ci pscreen->is_format_supported = fd2_screen_is_format_supported; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci screen->setup_slices = fd2_setup_slices; 127bf215546Sopenharmony_ci if (FD_DBG(TTILE)) 128bf215546Sopenharmony_ci screen->tile_mode = fd2_tile_mode; 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci fd2_emit_init_screen(pscreen); 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_ci if (screen->gpu_id >= 220) { 133bf215546Sopenharmony_ci screen->primtypes = a22x_primtypes; 134bf215546Sopenharmony_ci } else { 135bf215546Sopenharmony_ci screen->primtypes = a20x_primtypes; 136bf215546Sopenharmony_ci } 137bf215546Sopenharmony_ci} 138