Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/*
2
 * Copyright © 2014 Broadcom
3
 *
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:
10
 *
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
13
 * Software.
14
 *
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
21
 * IN THE SOFTWARE.
22
 */
23
 
24
/**
25
 * @file vc4_formats.c
26
 *
27
 * Contains the table and accessors for VC4 texture and render target format
28
 * support.
29
 *
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.
33
 */
34
 
35
#include "util/u_format.h"
36
#include "util/macros.h"
37
 
38
#include "vc4_context.h"
39
 
40
#define RT_NO        0
41
#define RT_RGBA8888  1
42
#define RT_RGB565    2
43
 
44
struct vc4_format {
45
        /** Set if the pipe format is defined in the table. */
46
        bool present;
47
 
48
        /** Set to 0 if unsupported, 1 if RGBA8888, 2 if rgb565. */
49
        uint8_t rt_type;
50
 
51
        /** One of VC4_TEXTURE_TYPE_*. */
52
        uint8_t tex_type;
53
 
54
        /**
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.
59
         */
60
        uint8_t swizzle[4];
61
};
62
 
63
#define SWIZ(x,y,z,w) {          \
64
        UTIL_FORMAT_SWIZZLE_##x, \
65
        UTIL_FORMAT_SWIZZLE_##y, \
66
        UTIL_FORMAT_SWIZZLE_##z, \
67
        UTIL_FORMAT_SWIZZLE_##w  \
68
}
69
 
70
#define FORMAT(pipe, rt, tex, swiz)                                     \
71
        [PIPE_FORMAT_##pipe] = { true, RT_##rt, VC4_TEXTURE_TYPE_##tex, swiz }
72
 
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)),
78
 
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)),
83
 
84
        FORMAT(B5G6R5_UNORM, RGB565, RGB565, SWIZ(X, Y, Z, 1)),
85
 
86
        /* Depth sampling will be handled by doing nearest filtering and not
87
         * unpacking the RGBA value.
88
         */
89
        FORMAT(S8_UINT_Z24_UNORM, NO, RGBA8888, SWIZ(X, Y, Z, W)),
90
        FORMAT(X8Z24_UNORM,       NO, RGBA8888, SWIZ(X, Y, Z, W)),
91
 
92
        FORMAT(B4G4R4A4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, X)),
93
        FORMAT(B4G4R4X4_UNORM, NO, RGBA4444, SWIZ(Y, Z, W, 1)),
94
 
95
        /* It looks like 5551 in the hardware is the other way around from
96
         * gallium.
97
         */
98
 
99
        FORMAT(A8_UNORM, NO, ALPHA, SWIZ(0, 0, 0, W)),
100
        FORMAT(L8_UNORM, NO, ALPHA, SWIZ(W, W, W, 1)),
101
        FORMAT(I8_UNORM, NO, ALPHA, SWIZ(W, W, W, W)),
102
        FORMAT(R8_UNORM, NO, ALPHA, SWIZ(W, 0, 0, 1)),
103
 
104
        FORMAT(L8A8_UNORM, NO, LUMALPHA, SWIZ(X, X, X, W)),
105
        FORMAT(R8G8_UNORM, NO, LUMALPHA, SWIZ(X, W, 0, 1)),
106
};
107
 
108
static const struct vc4_format *
109
get_format(enum pipe_format f)
110
{
111
        if (f > ARRAY_SIZE(vc4_format_table) ||
112
            !vc4_format_table[f].present)
113
                return NULL;
114
        else
115
                return &vc4_format_table[f];
116
}
117
 
118
bool
119
vc4_rt_format_supported(enum pipe_format f)
120
{
121
        const struct vc4_format *vf = get_format(f);
122
 
123
        if (!vf)
124
                return false;
125
 
126
        return vf->rt_type != RT_NO;
127
}
128
 
129
bool
130
vc4_rt_format_is_565(enum pipe_format f)
131
{
132
        const struct vc4_format *vf = get_format(f);
133
 
134
        if (!vf)
135
                return false;
136
 
137
        return vf->rt_type == RT_RGB565;
138
}
139
 
140
bool
141
vc4_tex_format_supported(enum pipe_format f)
142
{
143
        const struct vc4_format *vf = get_format(f);
144
 
145
        return vf != NULL;
146
}
147
 
148
uint8_t
149
vc4_get_tex_format(enum pipe_format f)
150
{
151
        const struct vc4_format *vf = get_format(f);
152
 
153
        if (!vf)
154
                return 0;
155
 
156
        return vf->tex_type;
157
}
158
 
159
const uint8_t *
160
vc4_get_format_swizzle(enum pipe_format f)
161
{
162
        const struct vc4_format *vf = get_format(f);
163
        static const uint8_t fallback[] = {0, 1, 2, 3};
164
 
165
        if (!vf)
166
                return fallback;
167
 
168
        return vf->swizzle;
169
}