Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_formats.c
4570 views
/*1* Copyright © 2014 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 vc4_formats.c25*26* Contains the table and accessors for VC4 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/format/u_format.h"35#include "util/macros.h"3637#include "vc4_context.h"3839#define RT_NO 040#define RT_RGBA8888 141#define RT_RGB565 24243struct vc4_format {44/** Set if the pipe format is defined in the table. */45bool present;4647/** Set to 0 if unsupported, 1 if RGBA8888, 2 if rgb565. */48uint8_t rt_type;4950/** One of VC4_TEXTURE_TYPE_*. */51uint8_t tex_type;5253/**54* Swizzle to apply to the RGBA shader output for storing to the tile55* buffer, to the RGBA tile buffer to produce shader input (for56* blending), and for turning the rgba8888 texture sampler return57* value into shader rgba values.58*/59uint8_t swizzle[4];60};6162#define SWIZ(x,y,z,w) { \63PIPE_SWIZZLE_##x, \64PIPE_SWIZZLE_##y, \65PIPE_SWIZZLE_##z, \66PIPE_SWIZZLE_##w \67}6869#define FORMAT(pipe, rt, tex, swiz) \70[PIPE_FORMAT_##pipe] = { true, RT_##rt, VC4_TEXTURE_TYPE_##tex, swiz }7172static const struct vc4_format vc4_format_table[] = {73FORMAT(R8G8B8A8_UNORM, RGBA8888, RGBA8888, SWIZ(X, Y, Z, W)),74FORMAT(R8G8B8X8_UNORM, RGBA8888, RGBA8888, SWIZ(X, Y, Z, 1)),75FORMAT(R8G8B8A8_SRGB, RGBA8888, RGBA8888, SWIZ(X, Y, Z, W)),76FORMAT(R8G8B8X8_SRGB, RGBA8888, RGBA8888, SWIZ(X, Y, Z, 1)),7778FORMAT(B8G8R8A8_UNORM, RGBA8888, RGBA8888, SWIZ(Z, Y, X, W)),79FORMAT(B8G8R8X8_UNORM, RGBA8888, RGBA8888, SWIZ(Z, Y, X, 1)),80FORMAT(B8G8R8A8_SRGB, RGBA8888, RGBA8888, SWIZ(Z, Y, X, W)),81FORMAT(B8G8R8X8_SRGB, RGBA8888, RGBA8888, SWIZ(Z, Y, X, 1)),8283FORMAT(B5G6R5_UNORM, RGB565, RGB565, SWIZ(X, Y, Z, 1)),8485FORMAT(ETC1_RGB8, NO, ETC1, SWIZ(X, Y, Z, 1)),8687/* Depth sampling will be handled by doing nearest filtering and not88* unpacking the RGBA value.89*/90FORMAT(S8_UINT_Z24_UNORM, NO, RGBA8888, SWIZ(X, Y, Z, W)),91FORMAT(X8Z24_UNORM, NO, RGBA8888, SWIZ(X, Y, Z, W)),9293FORMAT(B4G4R4A4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, X)),94FORMAT(B4G4R4X4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, 1)),9596FORMAT(A1B5G5R5_UNORM, NO, RGBA5551, SWIZ(X, Y, Z, W)),97FORMAT(X1B5G5R5_UNORM, NO, RGBA5551, SWIZ(X, Y, Z, 1)),9899FORMAT(A8_UNORM, NO, ALPHA, SWIZ(0, 0, 0, W)),100FORMAT(L8_UNORM, NO, ALPHA, SWIZ(W, W, W, 1)),101FORMAT(I8_UNORM, NO, ALPHA, SWIZ(W, W, W, W)),102FORMAT(R8_UNORM, NO, ALPHA, SWIZ(W, 0, 0, 1)),103104FORMAT(L8A8_UNORM, NO, LUMALPHA, SWIZ(X, X, X, W)),105FORMAT(R8G8_UNORM, NO, LUMALPHA, SWIZ(X, W, 0, 1)),106};107108static const struct vc4_format *109get_format(enum pipe_format f)110{111if (f >= ARRAY_SIZE(vc4_format_table) ||112!vc4_format_table[f].present)113return NULL;114else115return &vc4_format_table[f];116}117118bool119vc4_rt_format_supported(enum pipe_format f)120{121const struct vc4_format *vf = get_format(f);122123if (!vf)124return false;125126return vf->rt_type != RT_NO;127}128129bool130vc4_rt_format_is_565(enum pipe_format f)131{132const struct vc4_format *vf = get_format(f);133134if (!vf)135return false;136137return vf->rt_type == RT_RGB565;138}139140bool141vc4_tex_format_supported(enum pipe_format f)142{143const struct vc4_format *vf = get_format(f);144145return vf != NULL;146}147148uint8_t149vc4_get_tex_format(enum pipe_format f)150{151const struct vc4_format *vf = get_format(f);152153if (!vf)154return 0;155156return vf->tex_type;157}158159const uint8_t *160vc4_get_format_swizzle(enum pipe_format f)161{162const struct vc4_format *vf = get_format(f);163static const uint8_t fallback[] = {0, 1, 2, 3};164165if (!vf)166return fallback;167168return vf->swizzle;169}170171172