1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "p_compiler.h"
34 #include "util/u_string.h"
41 * The pipe_format enum is a 32-bit wide bitfield that encodes all the
42 * information needed to uniquely describe a pixel format.
46 * Possible format layouts are encoded in the first 2 bits.
47 * The interpretation of the remaining 30 bits depends on a particular
50 #define PIPE_FORMAT_LAYOUT_RGBAZS 0
51 #define PIPE_FORMAT_LAYOUT_YCBCR 1
52 #define PIPE_FORMAT_LAYOUT_DXT 2 /**< XXX temporary? */
53 #define PIPE_FORMAT_LAYOUT_MIXED 3
55 static INLINE uint
pf_layout(uint f
) /**< PIPE_FORMAT_LAYOUT_ */
61 * RGBAZS Format Layout.
65 * Format component selectors for RGBAZS & MIXED layout.
67 #define PIPE_FORMAT_COMP_R 0
68 #define PIPE_FORMAT_COMP_G 1
69 #define PIPE_FORMAT_COMP_B 2
70 #define PIPE_FORMAT_COMP_A 3
71 #define PIPE_FORMAT_COMP_0 4
72 #define PIPE_FORMAT_COMP_1 5
73 #define PIPE_FORMAT_COMP_Z 6
74 #define PIPE_FORMAT_COMP_S 7
77 * Format types for RGBAZS layout.
79 #define PIPE_FORMAT_TYPE_UNKNOWN 0
80 #define PIPE_FORMAT_TYPE_FLOAT 1 /**< 16/32/64-bit/channel formats */
81 #define PIPE_FORMAT_TYPE_UNORM 2 /**< uints, normalized to [0,1] */
82 #define PIPE_FORMAT_TYPE_SNORM 3 /**< ints, normalized to [-1,1] */
83 #define PIPE_FORMAT_TYPE_USCALED 4 /**< uints, not normalized */
84 #define PIPE_FORMAT_TYPE_SSCALED 5 /**< ints, not normalized */
85 #define PIPE_FORMAT_TYPE_SRGB 6 /**< sRGB colorspace */
86 #define PIPE_FORMAT_TYPE_FIXED 7 /**< 16.16 fixed point */
90 * Because the destination vector is assumed to be RGBA FLOAT, we
91 * need to know how to swizzle and expand components from the source
93 * Let's take U_A1_R5_G5_B5 as an example. X swizzle is A, X size
94 * is 1 bit and type is UNORM. So we take the most significant bit
95 * from source vector, convert 0 to 0.0 and 1 to 1.0 and save it
96 * in the last component of the destination RGBA component.
97 * Next, Y swizzle is R, Y size is 5 and type is UNORM. We normalize
98 * those 5 bits into [0.0; 1.0] range and put it into second
99 * component of the destination vector. Rinse and repeat for
100 * components Z and W.
101 * If any of size fields is zero, it means the source format contains
102 * less than four components.
103 * If any swizzle is 0 or 1, the corresponding destination component
104 * should be filled with 0.0 and 1.0, respectively.
106 typedef uint pipe_format_rgbazs_t
;
108 static INLINE uint
pf_get(pipe_format_rgbazs_t f
, uint shift
, uint mask
)
110 return (f
>> shift
) & mask
;
113 #define pf_swizzle_x(f) pf_get(f, 2, 0x7) /**< PIPE_FORMAT_COMP_ */
114 #define pf_swizzle_y(f) pf_get(f, 5, 0x7) /**< PIPE_FORMAT_COMP_ */
115 #define pf_swizzle_z(f) pf_get(f, 8, 0x7) /**< PIPE_FORMAT_COMP_ */
116 #define pf_swizzle_w(f) pf_get(f, 11, 0x7) /**< PIPE_FORMAT_COMP_ */
117 #define pf_swizzle_xyzw(f,i) pf_get(f, 2+((i)*3), 0x7)
118 #define pf_size_x(f) pf_get(f, 14, 0x7) /**< Size of X */
119 #define pf_size_y(f) pf_get(f, 17, 0x7) /**< Size of Y */
120 #define pf_size_z(f) pf_get(f, 20, 0x7) /**< Size of Z */
121 #define pf_size_w(f) pf_get(f, 23, 0x7) /**< Size of W */
122 #define pf_size_xyzw(f,i) pf_get(f, 14+((i)*3), 0x7)
123 #define pf_exp2(f) pf_get(f, 26, 0x7) /**< Scale size by 2 ^ exp2 */
124 #define pf_type(f) pf_get(f, 29, 0x7) /**< PIPE_FORMAT_TYPE_ */
127 * Helper macro to encode the above structure into a 32-bit value.
129 #define _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, EXP2, TYPE ) (\
130 (PIPE_FORMAT_LAYOUT_RGBAZS << 0) |\
140 * Helper macro to encode the swizzle part of the structure above.
142 #define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 0) | ((SWZY) << 3) | ((SWZZ) << 6) | ((SWZW) << 9))
145 * Shorthand macro for RGBAZS layout with component sizes in 1-bit units.
147 #define _PIPE_FORMAT_RGBAZS_1( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\
148 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 0, TYPE )
151 * Shorthand macro for RGBAZS layout with component sizes in 2-bit units.
153 #define _PIPE_FORMAT_RGBAZS_2( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\
154 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 1, TYPE )
157 * Shorthand macro for RGBAZS layout with component sizes in 8-bit units.
159 #define _PIPE_FORMAT_RGBAZS_8( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\
160 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 3, TYPE )
163 * Shorthand macro for RGBAZS layout with component sizes in 64-bit units.
165 #define _PIPE_FORMAT_RGBAZS_64( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\
166 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 6, TYPE )
168 typedef uint pipe_format_mixed_t
;
170 /* NOTE: Use pf_swizzle_* and pf_size_* macros for swizzles and sizes.
173 #define pf_mixed_sign_x(f) pf_get( f, 26, 0x1 ) /*< Sign of X */
174 #define pf_mixed_sign_y(f) pf_get( f, 27, 0x1 ) /*< Sign of Y */
175 #define pf_mixed_sign_z(f) pf_get( f, 28, 0x1 ) /*< Sign of Z */
176 #define pf_mixed_sign_w(f) pf_get( f, 29, 0x1 ) /*< Sign of W */
177 #define pf_mixed_sign_xyzw(f, i) pf_get( f, 26 + (i), 0x1 )
178 #define pf_mixed_normalized(f) pf_get( f, 30, 0x1 ) /*< Type is NORM (1) or SCALED (0) */
179 #define pf_mixed_scale8(f) pf_get( f, 31, 0x1 ) /*< Scale size by either one (0) or eight (1) */
182 * Helper macro to encode the above structure into a 32-bit value.
184 #define _PIPE_FORMAT_MIXED( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, SIGNX, SIGNY, SIGNZ, SIGNW, NORMALIZED, SCALE8 ) (\
185 (PIPE_FORMAT_LAYOUT_MIXED << 0) |\
195 ((NORMALIZED) << 30) |\
199 * Shorthand macro for common format swizzles.
201 #define _PIPE_FORMAT_R001 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 )
202 #define _PIPE_FORMAT_RG01 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_1 )
203 #define _PIPE_FORMAT_RGB1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_1 )
204 #define _PIPE_FORMAT_RGBA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_A )
205 #define _PIPE_FORMAT_ARGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B )
206 #define _PIPE_FORMAT_ABGR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_A, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R )
207 #define _PIPE_FORMAT_BGRA _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_A )
208 #define _PIPE_FORMAT_1RGB _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_1, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_B )
209 #define _PIPE_FORMAT_1BGR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_1, PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R )
210 #define _PIPE_FORMAT_BGR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_B, PIPE_FORMAT_COMP_G, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 )
211 #define _PIPE_FORMAT_0000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
212 #define _PIPE_FORMAT_000R _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_R )
213 #define _PIPE_FORMAT_RRR1 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_1 )
214 #define _PIPE_FORMAT_RRRR _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R )
215 #define _PIPE_FORMAT_RRRG _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_R, PIPE_FORMAT_COMP_G )
216 #define _PIPE_FORMAT_Z000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
217 #define _PIPE_FORMAT_0Z00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
218 #define _PIPE_FORMAT_SZ00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
219 #define _PIPE_FORMAT_ZS00 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_Z, PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
220 #define _PIPE_FORMAT_S000 _PIPE_FORMAT_SWZ( PIPE_FORMAT_COMP_S, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0, PIPE_FORMAT_COMP_0 )
223 * YCBCR Format Layout.
227 * This only contains a flag that indicates whether the format is reversed or
230 typedef uint pipe_format_ycbcr_t
;
233 * Helper macro to encode the above structure into a 32-bit value.
235 #define _PIPE_FORMAT_YCBCR( REV ) (\
236 (PIPE_FORMAT_LAYOUT_YCBCR << 0) |\
239 static INLINE uint
pf_rev(pipe_format_ycbcr_t f
)
241 return (f
>> 2) & 0x1;
246 * Compresssed format layouts (this will probably change)
248 #define _PIPE_FORMAT_DXT( LEVEL, RSIZE, GSIZE, BSIZE, ASIZE ) \
249 ((PIPE_FORMAT_LAYOUT_DXT << 0) | \
259 * Texture/surface image formats (preliminary)
262 /* KW: Added lots of surface formats to support vertex element layout
263 * definitions, and eventually render-to-vertex-buffer. Could
264 * consider making float/int/uint/scaled/normalized a separate
265 * parameter, but on the other hand there are special cases like
266 * z24s8, compressed textures, ycbcr, etc that won't fit that model.
270 PIPE_FORMAT_NONE
= _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_0000
, 0, 0, 0, 0, PIPE_FORMAT_TYPE_UNKNOWN
),
271 PIPE_FORMAT_A8R8G8B8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ARGB
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
272 PIPE_FORMAT_X8R8G8B8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_1RGB
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
273 PIPE_FORMAT_B8G8R8A8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
274 PIPE_FORMAT_B8G8R8X8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGR1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
275 PIPE_FORMAT_A1R5G5B5_UNORM
= _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB
, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM
),
276 PIPE_FORMAT_A4R4G4B4_UNORM
= _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_ARGB
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM
),
277 PIPE_FORMAT_R5G6B5_UNORM
= _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_RGB1
, 5, 6, 5, 0, PIPE_FORMAT_TYPE_UNORM
),
278 PIPE_FORMAT_A2B10G10R10_UNORM
= _PIPE_FORMAT_RGBAZS_2 ( _PIPE_FORMAT_ABGR
, 1, 5, 5, 5, PIPE_FORMAT_TYPE_UNORM
),
279 PIPE_FORMAT_L8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM
), /**< ubyte luminance */
280 PIPE_FORMAT_A8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_000R
, 0, 0, 0, 1, PIPE_FORMAT_TYPE_UNORM
), /**< ubyte alpha */
281 PIPE_FORMAT_I8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRR
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
), /**< ubyte intensity */
282 PIPE_FORMAT_A8L8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
), /**< ubyte alpha, luminance */
283 PIPE_FORMAT_L16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1
, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM
), /**< ushort luminance */
284 PIPE_FORMAT_YCBCR
= _PIPE_FORMAT_YCBCR( 0 ),
285 PIPE_FORMAT_YCBCR_REV
= _PIPE_FORMAT_YCBCR( 1 ),
286 PIPE_FORMAT_Z16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000
, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
287 PIPE_FORMAT_Z32_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
288 PIPE_FORMAT_Z32_FLOAT
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT
),
289 PIPE_FORMAT_S8Z24_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_SZ00
, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
290 PIPE_FORMAT_Z24S8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_ZS00
, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
291 PIPE_FORMAT_X8Z24_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_0Z00
, 1, 3, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
292 PIPE_FORMAT_Z24X8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_Z000
, 3, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
293 PIPE_FORMAT_S8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_S000
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
), /**< ubyte stencil */
294 PIPE_FORMAT_R64_FLOAT
= _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_R001
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT
),
295 PIPE_FORMAT_R64G64_FLOAT
= _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RG01
, 1, 1, 0, 0, PIPE_FORMAT_TYPE_FLOAT
),
296 PIPE_FORMAT_R64G64B64_FLOAT
= _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_FLOAT
),
297 PIPE_FORMAT_R64G64B64A64_FLOAT
= _PIPE_FORMAT_RGBAZS_64( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_FLOAT
),
298 PIPE_FORMAT_R32_FLOAT
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FLOAT
),
299 PIPE_FORMAT_R32G32_FLOAT
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FLOAT
),
300 PIPE_FORMAT_R32G32B32_FLOAT
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FLOAT
),
301 PIPE_FORMAT_R32G32B32A32_FLOAT
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FLOAT
),
302 PIPE_FORMAT_R32_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
303 PIPE_FORMAT_R32G32_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
304 PIPE_FORMAT_R32G32B32_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_UNORM
),
305 PIPE_FORMAT_R32G32B32A32_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_UNORM
),
306 PIPE_FORMAT_R32_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
307 PIPE_FORMAT_R32G32_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
308 PIPE_FORMAT_R32G32B32_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_USCALED
),
309 PIPE_FORMAT_R32G32B32A32_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_USCALED
),
310 PIPE_FORMAT_R32_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
311 PIPE_FORMAT_R32G32_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
312 PIPE_FORMAT_R32G32B32_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SNORM
),
313 PIPE_FORMAT_R32G32B32A32_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SNORM
),
314 PIPE_FORMAT_R32_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
315 PIPE_FORMAT_R32G32_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
316 PIPE_FORMAT_R32G32B32_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_SSCALED
),
317 PIPE_FORMAT_R32G32B32A32_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_SSCALED
),
318 PIPE_FORMAT_R16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 2, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
319 PIPE_FORMAT_R16G16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 2, 2, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
320 PIPE_FORMAT_R16G16B16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 2, 2, 2, 0, PIPE_FORMAT_TYPE_UNORM
),
321 PIPE_FORMAT_R16G16B16A16_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 2, 2, 2, 2, PIPE_FORMAT_TYPE_UNORM
),
322 PIPE_FORMAT_R16_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 2, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
323 PIPE_FORMAT_R16G16_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 2, 2, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
324 PIPE_FORMAT_R16G16B16_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 2, 2, 2, 0, PIPE_FORMAT_TYPE_USCALED
),
325 PIPE_FORMAT_R16G16B16A16_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 2, 2, 2, 2, PIPE_FORMAT_TYPE_USCALED
),
326 PIPE_FORMAT_R16_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
327 PIPE_FORMAT_R16G16_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
328 PIPE_FORMAT_R16G16B16_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SNORM
),
329 PIPE_FORMAT_R16G16B16A16_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SNORM
),
330 PIPE_FORMAT_R16_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 2, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
331 PIPE_FORMAT_R16G16_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 2, 2, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
332 PIPE_FORMAT_R16G16B16_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 2, 2, 2, 0, PIPE_FORMAT_TYPE_SSCALED
),
333 PIPE_FORMAT_R16G16B16A16_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 2, 2, 2, 2, PIPE_FORMAT_TYPE_SSCALED
),
334 PIPE_FORMAT_R8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
335 PIPE_FORMAT_R8G8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 1, 1, 0, 0, PIPE_FORMAT_TYPE_UNORM
),
336 PIPE_FORMAT_R8G8B8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_UNORM
),
337 PIPE_FORMAT_R8G8B8A8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
338 PIPE_FORMAT_R8G8B8X8_UNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_UNORM
),
339 PIPE_FORMAT_R8_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
340 PIPE_FORMAT_R8G8_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 1, 1, 0, 0, PIPE_FORMAT_TYPE_USCALED
),
341 PIPE_FORMAT_R8G8B8_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_USCALED
),
342 PIPE_FORMAT_R8G8B8A8_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED
),
343 PIPE_FORMAT_R8G8B8X8_USCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_USCALED
),
344 PIPE_FORMAT_R8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
345 PIPE_FORMAT_R8G8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SNORM
),
346 PIPE_FORMAT_R8G8B8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SNORM
),
347 PIPE_FORMAT_R8G8B8A8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM
),
348 PIPE_FORMAT_R8G8B8X8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM
),
349 PIPE_FORMAT_B6G5R5_SNORM
= _PIPE_FORMAT_RGBAZS_1 ( _PIPE_FORMAT_BGR1
, 6, 5, 5, 0, PIPE_FORMAT_TYPE_SNORM
),
350 PIPE_FORMAT_A8B8G8R8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGRA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM
),
351 PIPE_FORMAT_X8B8G8R8_SNORM
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_BGR1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SNORM
),
352 PIPE_FORMAT_R8_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 1, 0, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
353 PIPE_FORMAT_R8G8_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 1, 1, 0, 0, PIPE_FORMAT_TYPE_SSCALED
),
354 PIPE_FORMAT_R8G8B8_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SSCALED
),
355 PIPE_FORMAT_R8G8B8A8_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED
),
356 PIPE_FORMAT_R8G8B8X8_SSCALED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SSCALED
),
357 PIPE_FORMAT_R32_FIXED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_R001
, 4, 0, 0, 0, PIPE_FORMAT_TYPE_FIXED
),
358 PIPE_FORMAT_R32G32_FIXED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RG01
, 4, 4, 0, 0, PIPE_FORMAT_TYPE_FIXED
),
359 PIPE_FORMAT_R32G32B32_FIXED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 4, 4, 4, 0, PIPE_FORMAT_TYPE_FIXED
),
360 PIPE_FORMAT_R32G32B32A32_FIXED
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 4, 4, 4, 4, PIPE_FORMAT_TYPE_FIXED
),
362 PIPE_FORMAT_L8_SRGB
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRR1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB
),
363 PIPE_FORMAT_A8_L8_SRGB
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RRRG
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB
),
364 PIPE_FORMAT_R8G8B8_SRGB
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 0, PIPE_FORMAT_TYPE_SRGB
),
365 PIPE_FORMAT_R8G8B8A8_SRGB
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGBA
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB
),
366 PIPE_FORMAT_R8G8B8X8_SRGB
= _PIPE_FORMAT_RGBAZS_8 ( _PIPE_FORMAT_RGB1
, 1, 1, 1, 1, PIPE_FORMAT_TYPE_SRGB
),
369 PIPE_FORMAT_X8UB8UG8SR8S_NORM
= _PIPE_FORMAT_MIXED( _PIPE_FORMAT_1BGR
, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1 ),
370 PIPE_FORMAT_B6UG5SR5S_NORM
= _PIPE_FORMAT_MIXED( _PIPE_FORMAT_BGR1
, 6, 5, 5, 0, 0, 1, 1, 0, 1, 0 ),
372 /* compressed formats */
373 PIPE_FORMAT_DXT1_RGB
= _PIPE_FORMAT_DXT( 1, 8, 8, 8, 0 ),
374 PIPE_FORMAT_DXT1_RGBA
= _PIPE_FORMAT_DXT( 1, 8, 8, 8, 8 ),
375 PIPE_FORMAT_DXT3_RGBA
= _PIPE_FORMAT_DXT( 3, 8, 8, 8, 8 ),
376 PIPE_FORMAT_DXT5_RGBA
= _PIPE_FORMAT_DXT( 5, 8, 8, 8, 8 )
380 * Builds pipe format name from format token.
382 extern const char *pf_name( enum pipe_format format
);
385 * Return bits for a particular component.
386 * \param comp component index, starting at 0
388 static INLINE uint
pf_get_component_bits( enum pipe_format format
, uint comp
)
392 if (pf_swizzle_x(format
) == comp
) {
393 size
= pf_size_x(format
);
395 else if (pf_swizzle_y(format
) == comp
) {
396 size
= pf_size_y(format
);
398 else if (pf_swizzle_z(format
) == comp
) {
399 size
= pf_size_z(format
);
401 else if (pf_swizzle_w(format
) == comp
) {
402 size
= pf_size_w(format
);
407 if (pf_layout( format
) == PIPE_FORMAT_LAYOUT_RGBAZS
)
408 return size
<< pf_exp2( format
);
409 return size
<< (pf_mixed_scale8( format
) * 3);
413 * Return total bits needed for the pixel format.
415 static INLINE uint
pf_get_bits( enum pipe_format format
)
417 switch (pf_layout(format
)) {
418 case PIPE_FORMAT_LAYOUT_RGBAZS
:
419 case PIPE_FORMAT_LAYOUT_MIXED
:
421 pf_get_component_bits( format
, PIPE_FORMAT_COMP_0
) +
422 pf_get_component_bits( format
, PIPE_FORMAT_COMP_1
) +
423 pf_get_component_bits( format
, PIPE_FORMAT_COMP_R
) +
424 pf_get_component_bits( format
, PIPE_FORMAT_COMP_G
) +
425 pf_get_component_bits( format
, PIPE_FORMAT_COMP_B
) +
426 pf_get_component_bits( format
, PIPE_FORMAT_COMP_A
) +
427 pf_get_component_bits( format
, PIPE_FORMAT_COMP_Z
) +
428 pf_get_component_bits( format
, PIPE_FORMAT_COMP_S
);
429 case PIPE_FORMAT_LAYOUT_YCBCR
:
430 assert( format
== PIPE_FORMAT_YCBCR
|| format
== PIPE_FORMAT_YCBCR_REV
);
431 /* return effective bits per pixel */
440 * Return bytes per pixel for the given format.
442 static INLINE uint
pf_get_size( enum pipe_format format
)
444 assert(pf_get_bits(format
) % 8 == 0);
445 return pf_get_bits(format
) / 8;
449 * Describe accurately the pixel format.
451 * The chars-per-pixel concept falls apart with compressed and yuv images, where
452 * more than one pixel are coded in a single data block. This structure
453 * describes that block.
455 * Simple pixel formats are effectively a 1x1xcpp block.
457 struct pipe_format_block
459 /** Block size in bytes */
462 /** Block width in pixels */
465 /** Block height in pixels */
470 * Describe pixel format's block.
472 * @sa http://msdn2.microsoft.com/en-us/library/ms796147.aspx
475 pf_get_block(enum pipe_format format
, struct pipe_format_block
*block
)
478 case PIPE_FORMAT_DXT1_RGBA
:
479 case PIPE_FORMAT_DXT1_RGB
:
484 case PIPE_FORMAT_DXT3_RGBA
:
485 case PIPE_FORMAT_DXT5_RGBA
:
490 case PIPE_FORMAT_YCBCR
:
491 case PIPE_FORMAT_YCBCR_REV
:
492 block
->size
= 4; /* 2*cpp */
497 block
->size
= pf_get_size(format
);
504 static INLINE
unsigned
505 pf_get_nblocksx(const struct pipe_format_block
*block
, unsigned x
)
507 return (x
+ block
->width
- 1)/block
->width
;
510 static INLINE
unsigned
511 pf_get_nblocksy(const struct pipe_format_block
*block
, unsigned y
)
513 return (y
+ block
->height
- 1)/block
->height
;
516 static INLINE
unsigned
517 pf_get_nblocks(const struct pipe_format_block
*block
, unsigned width
, unsigned height
)
519 return pf_get_nblocksx(block
, width
)*pf_get_nblocksy(block
, height
);
522 static INLINE boolean
523 pf_is_compressed( enum pipe_format format
)
525 return pf_layout(format
) == PIPE_FORMAT_LAYOUT_DXT
? TRUE
: FALSE
;
528 static INLINE boolean
529 pf_is_ycbcr( enum pipe_format format
)
531 return pf_layout(format
) == PIPE_FORMAT_LAYOUT_YCBCR
? TRUE
: FALSE
;
534 static INLINE boolean
535 pf_has_alpha( enum pipe_format format
)
537 switch (pf_layout(format
)) {
538 case PIPE_FORMAT_LAYOUT_RGBAZS
:
539 case PIPE_FORMAT_LAYOUT_MIXED
:
540 /* FIXME: pf_get_component_bits( PIPE_FORMAT_A8L8_UNORM, PIPE_FORMAT_COMP_A ) should not return 0 right? */
541 if(format
== PIPE_FORMAT_A8_UNORM
||
542 format
== PIPE_FORMAT_A8L8_UNORM
||
543 format
== PIPE_FORMAT_A8_L8_SRGB
)
545 return pf_get_component_bits( format
, PIPE_FORMAT_COMP_A
) ? TRUE
: FALSE
;
546 case PIPE_FORMAT_LAYOUT_YCBCR
:
548 case PIPE_FORMAT_LAYOUT_DXT
:
550 case PIPE_FORMAT_DXT1_RGBA
:
551 case PIPE_FORMAT_DXT3_RGBA
:
552 case PIPE_FORMAT_DXT5_RGBA
: