Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a5xx/fd5_screen.c
4574 views
/*1* Copyright (C) 2016 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#include "pipe/p_screen.h"27#include "util/format/u_format.h"2829#include "fd5_blitter.h"30#include "fd5_context.h"31#include "fd5_emit.h"32#include "fd5_format.h"33#include "fd5_resource.h"34#include "fd5_screen.h"3536#include "ir3/ir3_compiler.h"3738static bool39valid_sample_count(unsigned sample_count)40{41switch (sample_count) {42case 0:43case 1:44case 2:45case 4:46return true;47default:48return false;49}50}5152static bool53fd5_screen_is_format_supported(struct pipe_screen *pscreen,54enum pipe_format format,55enum pipe_texture_target target,56unsigned sample_count,57unsigned storage_sample_count, unsigned usage)58{59unsigned retval = 0;6061if ((target >= PIPE_MAX_TEXTURE_TYPES) ||62!valid_sample_count(sample_count)) {63DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",64util_format_name(format), target, sample_count, usage);65return false;66}6768if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))69return false;7071if ((usage & PIPE_BIND_VERTEX_BUFFER) &&72(fd5_pipe2vtx(format) != VFMT5_NONE)) {73retval |= PIPE_BIND_VERTEX_BUFFER;74}7576if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&77(fd5_pipe2tex(format) != TFMT5_NONE) &&78(target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {79retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);80}8182if ((usage &83(PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |84PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) &&85(fd5_pipe2color(format) != RB5_NONE) &&86(fd5_pipe2tex(format) != TFMT5_NONE)) {87retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |88PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |89PIPE_BIND_COMPUTE_RESOURCE);90}9192/* For ARB_framebuffer_no_attachments: */93if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {94retval |= usage & PIPE_BIND_RENDER_TARGET;95}9697if ((usage & PIPE_BIND_DEPTH_STENCIL) &&98(fd5_pipe2depth(format) != (enum a5xx_depth_format) ~0) &&99(fd5_pipe2tex(format) != TFMT5_NONE)) {100retval |= PIPE_BIND_DEPTH_STENCIL;101}102103if ((usage & PIPE_BIND_INDEX_BUFFER) &&104(fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {105retval |= PIPE_BIND_INDEX_BUFFER;106}107108if (retval != usage) {109DBG("not supported: format=%s, target=%d, sample_count=%d, "110"usage=%x, retval=%x",111util_format_name(format), target, sample_count, usage, retval);112}113114return retval == usage;115}116117void118fd5_screen_init(struct pipe_screen *pscreen)119{120struct fd_screen *screen = fd_screen(pscreen);121screen->max_rts = A5XX_MAX_RENDER_TARGETS;122pscreen->context_create = fd5_context_create;123pscreen->is_format_supported = fd5_screen_is_format_supported;124125screen->setup_slices = fd5_setup_slices;126if (FD_DBG(TTILE))127screen->tile_mode = fd5_tile_mode;128129fd5_emit_init_screen(pscreen);130ir3_screen_init(pscreen);131}132133134