1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2014-2017 Broadcom 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 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci/** 25bf215546Sopenharmony_ci * @file v3d_formats.c 26bf215546Sopenharmony_ci * 27bf215546Sopenharmony_ci * Contains the table and accessors for V3D texture and render target format 28bf215546Sopenharmony_ci * support. 29bf215546Sopenharmony_ci * 30bf215546Sopenharmony_ci * The hardware has limited support for texture formats, and extremely limited 31bf215546Sopenharmony_ci * support for render target formats. As a result, we emulate other formats 32bf215546Sopenharmony_ci * in our shader code, and this stores the table for doing so. 33bf215546Sopenharmony_ci */ 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#include "util/macros.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include "v3d_context.h" 38bf215546Sopenharmony_ci#include "v3d_format_table.h" 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci/* The format internal types are the same across V3D versions */ 41bf215546Sopenharmony_ci#define V3D_VERSION 33 42bf215546Sopenharmony_ci#include "broadcom/cle/v3dx_pack.h" 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_cistatic const struct v3d_format * 45bf215546Sopenharmony_ciget_format(const struct v3d_device_info *devinfo, enum pipe_format f) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci if (devinfo->ver >= 41) 48bf215546Sopenharmony_ci return v3d41_get_format_desc(f); 49bf215546Sopenharmony_ci else 50bf215546Sopenharmony_ci return v3d33_get_format_desc(f); 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cibool 54bf215546Sopenharmony_civ3d_rt_format_supported(const struct v3d_device_info *devinfo, 55bf215546Sopenharmony_ci enum pipe_format f) 56bf215546Sopenharmony_ci{ 57bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci if (!vf) 60bf215546Sopenharmony_ci return false; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci return vf->rt_type != V3D_OUTPUT_IMAGE_FORMAT_NO; 63bf215546Sopenharmony_ci} 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ciuint8_t 66bf215546Sopenharmony_civ3d_get_rt_format(const struct v3d_device_info *devinfo, enum pipe_format f) 67bf215546Sopenharmony_ci{ 68bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci if (!vf) 71bf215546Sopenharmony_ci return 0; 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci return vf->rt_type; 74bf215546Sopenharmony_ci} 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_cibool 77bf215546Sopenharmony_civ3d_tex_format_supported(const struct v3d_device_info *devinfo, 78bf215546Sopenharmony_ci enum pipe_format f) 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci return vf != NULL; 83bf215546Sopenharmony_ci} 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ciuint8_t 86bf215546Sopenharmony_civ3d_get_tex_format(const struct v3d_device_info *devinfo, enum pipe_format f) 87bf215546Sopenharmony_ci{ 88bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci if (!vf) 91bf215546Sopenharmony_ci return 0; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci return vf->tex_type; 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ciuint8_t 97bf215546Sopenharmony_civ3d_get_tex_return_size(const struct v3d_device_info *devinfo, 98bf215546Sopenharmony_ci enum pipe_format f, enum pipe_tex_compare compare) 99bf215546Sopenharmony_ci{ 100bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci if (!vf) 103bf215546Sopenharmony_ci return 0; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci if (unlikely(V3D_DEBUG & V3D_DEBUG_TMU_16BIT)) 106bf215546Sopenharmony_ci return 16; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci if (unlikely(V3D_DEBUG & V3D_DEBUG_TMU_32BIT)) 109bf215546Sopenharmony_ci return 32; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci if (compare == PIPE_TEX_COMPARE_R_TO_TEXTURE) 112bf215546Sopenharmony_ci return 16; 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci return vf->return_size; 115bf215546Sopenharmony_ci} 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ciuint8_t 118bf215546Sopenharmony_civ3d_get_tex_return_channels(const struct v3d_device_info *devinfo, 119bf215546Sopenharmony_ci enum pipe_format f) 120bf215546Sopenharmony_ci{ 121bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci if (!vf) 124bf215546Sopenharmony_ci return 0; 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_ci return vf->return_channels; 127bf215546Sopenharmony_ci} 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ciconst uint8_t * 130bf215546Sopenharmony_civ3d_get_format_swizzle(const struct v3d_device_info *devinfo, enum pipe_format f) 131bf215546Sopenharmony_ci{ 132bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 133bf215546Sopenharmony_ci static const uint8_t fallback[] = {0, 1, 2, 3}; 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci if (!vf) 136bf215546Sopenharmony_ci return fallback; 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci return vf->swizzle; 139bf215546Sopenharmony_ci} 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_civoid 142bf215546Sopenharmony_civ3d_get_internal_type_bpp_for_output_format(const struct v3d_device_info *devinfo, 143bf215546Sopenharmony_ci uint32_t format, 144bf215546Sopenharmony_ci uint32_t *type, 145bf215546Sopenharmony_ci uint32_t *bpp) 146bf215546Sopenharmony_ci{ 147bf215546Sopenharmony_ci if (devinfo->ver >= 41) { 148bf215546Sopenharmony_ci return v3d41_get_internal_type_bpp_for_output_format(format, 149bf215546Sopenharmony_ci type, bpp); 150bf215546Sopenharmony_ci } else { 151bf215546Sopenharmony_ci return v3d33_get_internal_type_bpp_for_output_format(format, 152bf215546Sopenharmony_ci type, bpp); 153bf215546Sopenharmony_ci } 154bf215546Sopenharmony_ci} 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_cibool 157bf215546Sopenharmony_civ3d_tfu_supports_tex_format(const struct v3d_device_info *devinfo, 158bf215546Sopenharmony_ci uint32_t tex_format, 159bf215546Sopenharmony_ci bool for_mipmap) 160bf215546Sopenharmony_ci{ 161bf215546Sopenharmony_ci if (devinfo->ver >= 41) { 162bf215546Sopenharmony_ci return v3d41_tfu_supports_tex_format(tex_format, for_mipmap); 163bf215546Sopenharmony_ci } else { 164bf215546Sopenharmony_ci return v3d33_tfu_supports_tex_format(tex_format, for_mipmap); 165bf215546Sopenharmony_ci } 166bf215546Sopenharmony_ci} 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_cibool 169bf215546Sopenharmony_civ3d_format_supports_tlb_msaa_resolve(const struct v3d_device_info *devinfo, 170bf215546Sopenharmony_ci enum pipe_format f) 171bf215546Sopenharmony_ci{ 172bf215546Sopenharmony_ci uint32_t internal_type; 173bf215546Sopenharmony_ci uint32_t internal_bpp; 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci const struct v3d_format *vf = get_format(devinfo, f); 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci if (!vf) 178bf215546Sopenharmony_ci return false; 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci v3d_get_internal_type_bpp_for_output_format(devinfo, 181bf215546Sopenharmony_ci vf->rt_type, 182bf215546Sopenharmony_ci &internal_type, 183bf215546Sopenharmony_ci &internal_bpp); 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci return internal_type == V3D_INTERNAL_TYPE_8 || 186bf215546Sopenharmony_ci internal_type == V3D_INTERNAL_TYPE_16F; 187bf215546Sopenharmony_ci} 188