1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2016 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 "fd5_blitter.h" 31bf215546Sopenharmony_ci#include "fd5_context.h" 32bf215546Sopenharmony_ci#include "fd5_emit.h" 33bf215546Sopenharmony_ci#include "fd5_format.h" 34bf215546Sopenharmony_ci#include "fd5_resource.h" 35bf215546Sopenharmony_ci#include "fd5_screen.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include "ir3/ir3_compiler.h" 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistatic bool 40bf215546Sopenharmony_civalid_sample_count(unsigned sample_count) 41bf215546Sopenharmony_ci{ 42bf215546Sopenharmony_ci switch (sample_count) { 43bf215546Sopenharmony_ci case 0: 44bf215546Sopenharmony_ci case 1: 45bf215546Sopenharmony_ci case 2: 46bf215546Sopenharmony_ci case 4: 47bf215546Sopenharmony_ci return true; 48bf215546Sopenharmony_ci default: 49bf215546Sopenharmony_ci return false; 50bf215546Sopenharmony_ci } 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cistatic bool 54bf215546Sopenharmony_cifd5_screen_is_format_supported(struct pipe_screen *pscreen, 55bf215546Sopenharmony_ci enum pipe_format format, 56bf215546Sopenharmony_ci enum pipe_texture_target target, 57bf215546Sopenharmony_ci unsigned sample_count, 58bf215546Sopenharmony_ci unsigned storage_sample_count, unsigned usage) 59bf215546Sopenharmony_ci{ 60bf215546Sopenharmony_ci unsigned retval = 0; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci if ((target >= PIPE_MAX_TEXTURE_TYPES) || 63bf215546Sopenharmony_ci !valid_sample_count(sample_count)) { 64bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x", 65bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage); 66bf215546Sopenharmony_ci return false; 67bf215546Sopenharmony_ci } 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 70bf215546Sopenharmony_ci return false; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci if ((usage & PIPE_BIND_VERTEX_BUFFER) && 73bf215546Sopenharmony_ci (fd5_pipe2vtx(format) != VFMT5_NONE)) { 74bf215546Sopenharmony_ci retval |= PIPE_BIND_VERTEX_BUFFER; 75bf215546Sopenharmony_ci } 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) && 78bf215546Sopenharmony_ci (fd5_pipe2tex(format) != TFMT5_NONE) && 79bf215546Sopenharmony_ci (target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) { 80bf215546Sopenharmony_ci retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE); 81bf215546Sopenharmony_ci } 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci if ((usage & 84bf215546Sopenharmony_ci (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 85bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) && 86bf215546Sopenharmony_ci (fd5_pipe2color(format) != RB5_NONE) && 87bf215546Sopenharmony_ci (fd5_pipe2tex(format) != TFMT5_NONE)) { 88bf215546Sopenharmony_ci retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | 89bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | 90bf215546Sopenharmony_ci PIPE_BIND_COMPUTE_RESOURCE); 91bf215546Sopenharmony_ci } 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci if (usage & PIPE_BIND_SHADER_IMAGE) { 94bf215546Sopenharmony_ci if (sample_count > 1) 95bf215546Sopenharmony_ci return false; 96bf215546Sopenharmony_ci } 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci /* For ARB_framebuffer_no_attachments: */ 99bf215546Sopenharmony_ci if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) { 100bf215546Sopenharmony_ci retval |= usage & PIPE_BIND_RENDER_TARGET; 101bf215546Sopenharmony_ci } 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci if ((usage & PIPE_BIND_DEPTH_STENCIL) && 104bf215546Sopenharmony_ci (fd5_pipe2depth(format) != (enum a5xx_depth_format) ~0) && 105bf215546Sopenharmony_ci (fd5_pipe2tex(format) != TFMT5_NONE)) { 106bf215546Sopenharmony_ci retval |= PIPE_BIND_DEPTH_STENCIL; 107bf215546Sopenharmony_ci } 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci if ((usage & PIPE_BIND_INDEX_BUFFER) && 110bf215546Sopenharmony_ci (fd_pipe2index(format) != (enum pc_di_index_size) ~0)) { 111bf215546Sopenharmony_ci retval |= PIPE_BIND_INDEX_BUFFER; 112bf215546Sopenharmony_ci } 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci if (retval != usage) { 115bf215546Sopenharmony_ci DBG("not supported: format=%s, target=%d, sample_count=%d, " 116bf215546Sopenharmony_ci "usage=%x, retval=%x", 117bf215546Sopenharmony_ci util_format_name(format), target, sample_count, usage, retval); 118bf215546Sopenharmony_ci } 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci return retval == usage; 121bf215546Sopenharmony_ci} 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci/* clang-format off */ 124bf215546Sopenharmony_cistatic const enum pc_di_primtype primtypes[] = { 125bf215546Sopenharmony_ci [PIPE_PRIM_POINTS] = DI_PT_POINTLIST, 126bf215546Sopenharmony_ci [PIPE_PRIM_LINES] = DI_PT_LINELIST, 127bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP, 128bf215546Sopenharmony_ci [PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP, 129bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST, 130bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP, 131bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN, 132bf215546Sopenharmony_ci [PIPE_PRIM_MAX] = DI_PT_RECTLIST, /* internal clear blits */ 133bf215546Sopenharmony_ci}; 134bf215546Sopenharmony_ci/* clang-format on */ 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_civoid 137bf215546Sopenharmony_cifd5_screen_init(struct pipe_screen *pscreen) 138bf215546Sopenharmony_ci{ 139bf215546Sopenharmony_ci struct fd_screen *screen = fd_screen(pscreen); 140bf215546Sopenharmony_ci screen->max_rts = A5XX_MAX_RENDER_TARGETS; 141bf215546Sopenharmony_ci pscreen->context_create = fd5_context_create; 142bf215546Sopenharmony_ci pscreen->is_format_supported = fd5_screen_is_format_supported; 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci screen->setup_slices = fd5_setup_slices; 145bf215546Sopenharmony_ci if (FD_DBG(TTILE)) 146bf215546Sopenharmony_ci screen->tile_mode = fd5_tile_mode; 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci fd5_emit_init_screen(pscreen); 149bf215546Sopenharmony_ci ir3_screen_init(pscreen); 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_ci screen->primtypes = primtypes; 152bf215546Sopenharmony_ci} 153