Path: blob/21.2-virgl/src/gallium/drivers/v3d/v3d_formats.c
4570 views
/*1* Copyright © 2014-2017 Broadcom2*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, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223/**24* @file v3d_formats.c25*26* Contains the table and accessors for V3D texture and render target format27* support.28*29* The hardware has limited support for texture formats, and extremely limited30* support for render target formats. As a result, we emulate other formats31* in our shader code, and this stores the table for doing so.32*/3334#include "util/macros.h"3536#include "v3d_context.h"37#include "v3d_format_table.h"3839/* The format internal types are the same across V3D versions */40#define V3D_VERSION 3341#include "broadcom/cle/v3dx_pack.h"4243static const struct v3d_format *44get_format(const struct v3d_device_info *devinfo, enum pipe_format f)45{46if (devinfo->ver >= 41)47return v3d41_get_format_desc(f);48else49return v3d33_get_format_desc(f);50}5152bool53v3d_rt_format_supported(const struct v3d_device_info *devinfo,54enum pipe_format f)55{56const struct v3d_format *vf = get_format(devinfo, f);5758if (!vf)59return false;6061return vf->rt_type != V3D_OUTPUT_IMAGE_FORMAT_NO;62}6364uint8_t65v3d_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f)66{67const struct v3d_format *vf = get_format(devinfo, f);6869if (!vf)70return 0;7172return vf->rt_type;73}7475bool76v3d_tex_format_supported(const struct v3d_device_info *devinfo,77enum pipe_format f)78{79const struct v3d_format *vf = get_format(devinfo, f);8081return vf != NULL;82}8384uint8_t85v3d_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f)86{87const struct v3d_format *vf = get_format(devinfo, f);8889if (!vf)90return 0;9192return vf->tex_type;93}9495uint8_t96v3d_get_tex_return_size(const struct v3d_device_info *devinfo,97enum pipe_format f, enum pipe_tex_compare compare)98{99const struct v3d_format *vf = get_format(devinfo, f);100101if (!vf)102return 0;103104if (compare == PIPE_TEX_COMPARE_R_TO_TEXTURE)105return 16;106107return vf->return_size;108}109110uint8_t111v3d_get_tex_return_channels(const struct v3d_device_info *devinfo,112enum pipe_format f)113{114const struct v3d_format *vf = get_format(devinfo, f);115116if (!vf)117return 0;118119return vf->return_channels;120}121122const uint8_t *123v3d_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f)124{125const struct v3d_format *vf = get_format(devinfo, f);126static const uint8_t fallback[] = {0, 1, 2, 3};127128if (!vf)129return fallback;130131return vf->swizzle;132}133134void135v3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo,136uint32_t format,137uint32_t *type,138uint32_t *bpp)139{140if (devinfo->ver >= 41) {141return v3d41_get_internal_type_bpp_for_output_format(format,142type, bpp);143} else {144return v3d33_get_internal_type_bpp_for_output_format(format,145type, bpp);146}147}148149bool150v3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo,151uint32_t tex_format,152bool for_mipmap)153{154if (devinfo->ver >= 41) {155return v3d41_tfu_supports_tex_format(tex_format, for_mipmap);156} else {157return v3d33_tfu_supports_tex_format(tex_format, for_mipmap);158}159}160161bool162v3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo,163enum pipe_format f)164{165uint32_t internal_type;166uint32_t internal_bpp;167168const struct v3d_format *vf = get_format(devinfo, f);169170if (!vf)171return false;172173v3d_get_internal_type_bpp_for_output_format(devinfo,174vf->rt_type,175&internal_type,176&internal_bpp);177178return internal_type == V3D_INTERNAL_TYPE_8 ||179internal_type == V3D_INTERNAL_TYPE_16F;180}181182183