2
* Copyright © 2014 Broadcom
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
* Contains the table and accessors for VC4 texture and render target format
30
* The hardware has limited support for texture formats, and extremely limited
31
* support for render target formats. As a result, we emulate other formats
32
* in our shader code, and this stores the table for doing so.
35
#include "util/format/u_format.h"
36
#include "util/macros.h"
38
#include "vc4_context.h"
45
/** Set if the pipe format is defined in the table. */
48
/** Set to 0 if unsupported, 1 if RGBA8888, 2 if rgb565. */
51
/** One of VC4_TEXTURE_TYPE_*. */
55
* Swizzle to apply to the RGBA shader output for storing to the tile
56
* buffer, to the RGBA tile buffer to produce shader input (for
57
* blending), and for turning the rgba8888 texture sampler return
58
* value into shader rgba values.
63
#define SWIZ(x,y,z,w) { \
70
#define FORMAT(pipe, rt, tex, swiz) \
71
[PIPE_FORMAT_##pipe] = { true, RT_##rt, VC4_TEXTURE_TYPE_##tex, swiz }
73
static const struct vc4_format vc4_format_table[] = {
74
FORMAT(R8G8B8A8_UNORM, RGBA8888, RGBA8888, SWIZ(X, Y, Z, W)),
75
FORMAT(R8G8B8X8_UNORM, RGBA8888, RGBA8888, SWIZ(X, Y, Z, 1)),
76
FORMAT(R8G8B8A8_SRGB, RGBA8888, RGBA8888, SWIZ(X, Y, Z, W)),
77
FORMAT(R8G8B8X8_SRGB, RGBA8888, RGBA8888, SWIZ(X, Y, Z, 1)),
79
FORMAT(B8G8R8A8_UNORM, RGBA8888, RGBA8888, SWIZ(Z, Y, X, W)),
80
FORMAT(B8G8R8X8_UNORM, RGBA8888, RGBA8888, SWIZ(Z, Y, X, 1)),
81
FORMAT(B8G8R8A8_SRGB, RGBA8888, RGBA8888, SWIZ(Z, Y, X, W)),
82
FORMAT(B8G8R8X8_SRGB, RGBA8888, RGBA8888, SWIZ(Z, Y, X, 1)),
84
FORMAT(B5G6R5_UNORM, RGB565, RGB565, SWIZ(X, Y, Z, 1)),
86
FORMAT(ETC1_RGB8, NO, ETC1, SWIZ(X, Y, Z, 1)),
88
/* Depth sampling will be handled by doing nearest filtering and not
89
* unpacking the RGBA value.
91
FORMAT(S8_UINT_Z24_UNORM, NO, RGBA8888, SWIZ(X, Y, Z, W)),
92
FORMAT(X8Z24_UNORM, NO, RGBA8888, SWIZ(X, Y, Z, W)),
94
FORMAT(B4G4R4A4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, X)),
95
FORMAT(B4G4R4X4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, 1)),
97
FORMAT(A1B5G5R5_UNORM, NO, RGBA5551, SWIZ(X, Y, Z, W)),
98
FORMAT(X1B5G5R5_UNORM, NO, RGBA5551, SWIZ(X, Y, Z, 1)),
100
FORMAT(A8_UNORM, NO, ALPHA, SWIZ(0, 0, 0, W)),
101
FORMAT(L8_UNORM, NO, ALPHA, SWIZ(W, W, W, 1)),
102
FORMAT(I8_UNORM, NO, ALPHA, SWIZ(W, W, W, W)),
103
FORMAT(R8_UNORM, NO, ALPHA, SWIZ(W, 0, 0, 1)),
105
FORMAT(L8A8_UNORM, NO, LUMALPHA, SWIZ(X, X, X, W)),
106
FORMAT(R8G8_UNORM, NO, LUMALPHA, SWIZ(X, W, 0, 1)),
109
static const struct vc4_format *
110
get_format(enum pipe_format f)
112
if (f >= ARRAY_SIZE(vc4_format_table) ||
113
!vc4_format_table[f].present)
116
return &vc4_format_table[f];
120
vc4_rt_format_supported(enum pipe_format f)
122
const struct vc4_format *vf = get_format(f);
127
return vf->rt_type != RT_NO;
131
vc4_rt_format_is_565(enum pipe_format f)
133
const struct vc4_format *vf = get_format(f);
138
return vf->rt_type == RT_RGB565;
142
vc4_tex_format_supported(enum pipe_format f)
144
const struct vc4_format *vf = get_format(f);
150
vc4_get_tex_format(enum pipe_format f)
152
const struct vc4_format *vf = get_format(f);
161
vc4_get_format_swizzle(enum pipe_format f)
163
const struct vc4_format *vf = get_format(f);
164
static const uint8_t fallback[] = {0, 1, 2, 3};