Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_screen.c
4574 views
/*1* Copyright (C) 2016 Rob Clark <[email protected]>2* Copyright © 2018 Google, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25*/2627#include "drm-uapi/drm_fourcc.h"28#include "pipe/p_screen.h"29#include "util/format/u_format.h"3031#include "fd6_blitter.h"32#include "fd6_context.h"33#include "fd6_emit.h"34#include "fd6_format.h"35#include "fd6_resource.h"36#include "fd6_screen.h"3738#include "ir3/ir3_compiler.h"3940static bool41valid_sample_count(unsigned sample_count)42{43switch (sample_count) {44case 0:45case 1:46case 2:47case 4:48// TODO seems 8x works, but increases lrz width or height.. but the49// blob I have doesn't seem to expose any egl configs w/ 8x, so50// just hide it for now and revisit later.51// case 8:52return true;53default:54return false;55}56}5758static bool59fd6_screen_is_format_supported(struct pipe_screen *pscreen,60enum pipe_format format,61enum pipe_texture_target target,62unsigned sample_count,63unsigned storage_sample_count, unsigned usage)64{65unsigned retval = 0;6667if ((target >= PIPE_MAX_TEXTURE_TYPES) ||68!valid_sample_count(sample_count)) {69DBG("not supported: format=%s, target=%d, sample_count=%d, usage=%x",70util_format_name(format), target, sample_count, usage);71return false;72}7374if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))75return false;7677if ((usage & PIPE_BIND_VERTEX_BUFFER) &&78(fd6_pipe2vtx(format) != FMT6_NONE)) {79retval |= PIPE_BIND_VERTEX_BUFFER;80}8182if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&83(fd6_pipe2tex(format) != FMT6_NONE) &&84(target == PIPE_BUFFER || util_format_get_blocksize(format) != 12)) {85retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);86}8788if ((usage &89(PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |90PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_COMPUTE_RESOURCE)) &&91(fd6_pipe2color(format) != FMT6_NONE) &&92(fd6_pipe2tex(format) != FMT6_NONE)) {93retval |= usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET |94PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |95PIPE_BIND_COMPUTE_RESOURCE);96}9798/* For ARB_framebuffer_no_attachments: */99if ((usage & PIPE_BIND_RENDER_TARGET) && (format == PIPE_FORMAT_NONE)) {100retval |= usage & PIPE_BIND_RENDER_TARGET;101}102103if ((usage & PIPE_BIND_DEPTH_STENCIL) &&104(fd6_pipe2depth(format) != (enum a6xx_depth_format) ~0) &&105(fd6_pipe2tex(format) != FMT6_NONE)) {106retval |= PIPE_BIND_DEPTH_STENCIL;107}108109if ((usage & PIPE_BIND_INDEX_BUFFER) &&110(fd_pipe2index(format) != (enum pc_di_index_size) ~0)) {111retval |= PIPE_BIND_INDEX_BUFFER;112}113114if (retval != usage) {115DBG("not supported: format=%s, target=%d, sample_count=%d, "116"usage=%x, retval=%x",117util_format_name(format), target, sample_count, usage, retval);118}119120return retval == usage;121}122123void124fd6_screen_init(struct pipe_screen *pscreen)125{126struct fd_screen *screen = fd_screen(pscreen);127128screen->max_rts = A6XX_MAX_RENDER_TARGETS;129130/* Currently only FB_READ forces GMEM path, mostly because we'd have to131* deal with cmdstream patching otherwise..132*/133screen->gmem_reason_mask = FD_GMEM_CLEARS_DEPTH_STENCIL |134FD_GMEM_DEPTH_ENABLED | FD_GMEM_STENCIL_ENABLED |135FD_GMEM_BLEND_ENABLED | FD_GMEM_LOGICOP_ENABLED;136137pscreen->context_create = fd6_context_create;138pscreen->is_format_supported = fd6_screen_is_format_supported;139140screen->tile_mode = fd6_tile_mode;141142fd6_resource_screen_init(pscreen);143fd6_emit_init_screen(pscreen);144ir3_screen_init(pscreen);145}146147148