p_format.h revision 53979d0a352fa74c533200bdba405915582a5974
1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 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: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 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. 25 * 26 **************************************************************************/ 27 28#ifndef PIPE_FORMAT_H 29#define PIPE_FORMAT_H 30 31#include "p_compiler.h" 32#include "p_debug.h" 33 34#include "util/u_string.h" 35 36#ifdef __cplusplus 37extern "C" { 38#endif 39 40/** 41 * The pipe_format enum is a 32-bit wide bitfield that encodes all the 42 * information needed to uniquely describe a pixel format. 43 */ 44 45/** 46 * Possible format layouts are encoded in the first 2 bits. 47 * The interpretation of the remaining 30 bits depends on a particular 48 * format layout. 49 */ 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 54 55static INLINE uint pf_layout(uint f) /**< PIPE_FORMAT_LAYOUT_ */ 56{ 57 return f & 0x3; 58} 59 60/** 61 * RGBAZS Format Layout. 62 */ 63 64/** 65 * Format component selectors for RGBAZS & MIXED layout. 66 */ 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 75 76/** 77 * Format types for RGBAZS layout. 78 */ 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 */ 87 88 89/** 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 92 * vector. 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. 105 */ 106typedef uint pipe_format_rgbazs_t; 107 108static INLINE uint pf_get(pipe_format_rgbazs_t f, uint shift, uint mask) 109{ 110 return (f >> shift) & mask; 111} 112 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_ */ 125 126/** 127 * Helper macro to encode the above structure into a 32-bit value. 128 */ 129#define _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, EXP2, TYPE ) (\ 130 (PIPE_FORMAT_LAYOUT_RGBAZS << 0) |\ 131 ((SWZ) << 2) |\ 132 ((SIZEX) << 14) |\ 133 ((SIZEY) << 17) |\ 134 ((SIZEZ) << 20) |\ 135 ((SIZEW) << 23) |\ 136 ((EXP2) << 26) |\ 137 ((TYPE) << 29) ) 138 139/** 140 * Helper macro to encode the swizzle part of the structure above. 141 */ 142#define _PIPE_FORMAT_SWZ( SWZX, SWZY, SWZZ, SWZW ) (((SWZX) << 0) | ((SWZY) << 3) | ((SWZZ) << 6) | ((SWZW) << 9)) 143 144/** 145 * Shorthand macro for RGBAZS layout with component sizes in 1-bit units. 146 */ 147#define _PIPE_FORMAT_RGBAZS_1( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ 148 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 0, TYPE ) 149 150/** 151 * Shorthand macro for RGBAZS layout with component sizes in 2-bit units. 152 */ 153#define _PIPE_FORMAT_RGBAZS_2( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ 154 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 1, TYPE ) 155 156/** 157 * Shorthand macro for RGBAZS layout with component sizes in 8-bit units. 158 */ 159#define _PIPE_FORMAT_RGBAZS_8( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ 160 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 3, TYPE ) 161 162/** 163 * Shorthand macro for RGBAZS layout with component sizes in 64-bit units. 164 */ 165#define _PIPE_FORMAT_RGBAZS_64( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, TYPE )\ 166 _PIPE_FORMAT_RGBAZS( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, 6, TYPE ) 167 168typedef uint pipe_format_mixed_t; 169 170/* NOTE: Use pf_swizzle_* and pf_size_* macros for swizzles and sizes. 171 */ 172 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) */ 180 181/** 182 * Helper macro to encode the above structure into a 32-bit value. 183 */ 184#define _PIPE_FORMAT_MIXED( SWZ, SIZEX, SIZEY, SIZEZ, SIZEW, SIGNX, SIGNY, SIGNZ, SIGNW, NORMALIZED, SCALE8 ) (\ 185 (PIPE_FORMAT_LAYOUT_MIXED << 0) |\ 186 ((SWZ) << 2) |\ 187 ((SIZEX) << 14) |\ 188 ((SIZEY) << 17) |\ 189 ((SIZEZ) << 20) |\ 190 ((SIZEW) << 23) |\ 191 ((SIGNX) << 26) |\ 192 ((SIGNY) << 27) |\ 193 ((SIGNZ) << 28) |\ 194 ((SIGNW) << 29) |\ 195 ((NORMALIZED) << 30) |\ 196 ((SCALE8) << 31) ) 197 198/** 199 * Shorthand macro for common format swizzles. 200 */ 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 ) 221 222/** 223 * YCBCR Format Layout. 224 */ 225 226/** 227 * This only contains a flag that indicates whether the format is reversed or 228 * not. 229 */ 230typedef uint pipe_format_ycbcr_t; 231 232/** 233 * Helper macro to encode the above structure into a 32-bit value. 234 */ 235#define _PIPE_FORMAT_YCBCR( REV ) (\ 236 (PIPE_FORMAT_LAYOUT_YCBCR << 0) |\ 237 ((REV) << 2) ) 238 239static INLINE uint pf_rev(pipe_format_ycbcr_t f) 240{ 241 return (f >> 2) & 0x1; 242} 243 244 245/** 246 * Compresssed format layouts (this will probably change) 247 */ 248#define _PIPE_FORMAT_DXT( LEVEL, RSIZE, GSIZE, BSIZE, ASIZE ) \ 249 ((PIPE_FORMAT_LAYOUT_DXT << 0) | \ 250 ((LEVEL) << 2) | \ 251 ((RSIZE) << 5) | \ 252 ((GSIZE) << 8) | \ 253 ((BSIZE) << 11) | \ 254 ((ASIZE) << 14) ) 255 256 257 258/** 259 * Texture/surface image formats (preliminary) 260 */ 261 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. 267 */ 268 269enum pipe_format { 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_RGB1, 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 ), 361 /* sRGB formats */ 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 ), 367 368 /* mixed formats */ 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 ), 371 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 ) 377}; 378 379/** 380 * Builds pipe format name from format token. 381 */ 382extern const char *pf_name( enum pipe_format format ); 383 384/** 385 * Return bits for a particular component. 386 * \param comp component index, starting at 0 387 */ 388static INLINE uint pf_get_component_bits( enum pipe_format format, uint comp ) 389{ 390 uint size; 391 392 if (pf_swizzle_x(format) == comp) { 393 size = pf_size_x(format); 394 } 395 else if (pf_swizzle_y(format) == comp) { 396 size = pf_size_y(format); 397 } 398 else if (pf_swizzle_z(format) == comp) { 399 size = pf_size_z(format); 400 } 401 else if (pf_swizzle_w(format) == comp) { 402 size = pf_size_w(format); 403 } 404 else { 405 size = 0; 406 } 407 if (pf_layout( format ) == PIPE_FORMAT_LAYOUT_RGBAZS) 408 return size << pf_exp2( format ); 409 return size << (pf_mixed_scale8( format ) * 3); 410} 411 412/** 413 * Return total bits needed for the pixel format. 414 */ 415static INLINE uint pf_get_bits( enum pipe_format format ) 416{ 417 switch (pf_layout(format)) { 418 case PIPE_FORMAT_LAYOUT_RGBAZS: 419 case PIPE_FORMAT_LAYOUT_MIXED: 420 return 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 */ 432 return 16; 433 default: 434 assert( 0 ); 435 return 0; 436 } 437} 438 439/** 440 * Return bytes per pixel for the given format. 441 */ 442static INLINE uint pf_get_size( enum pipe_format format ) 443{ 444 assert(pf_get_bits(format) % 8 == 0); 445 return pf_get_bits(format) / 8; 446} 447 448/** 449 * Describe accurately the pixel format. 450 * 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. 454 * 455 * Simple pixel formats are effectively a 1x1xcpp block. 456 */ 457struct pipe_format_block 458{ 459 /** Block size in bytes */ 460 unsigned size; 461 462 /** Block width in pixels */ 463 unsigned width; 464 465 /** Block height in pixels */ 466 unsigned height; 467}; 468 469/** 470 * Describe pixel format's block. 471 * 472 * @sa http://msdn2.microsoft.com/en-us/library/ms796147.aspx 473 */ 474static INLINE void 475pf_get_block(enum pipe_format format, struct pipe_format_block *block) 476{ 477 switch(format) { 478 case PIPE_FORMAT_DXT1_RGBA: 479 case PIPE_FORMAT_DXT1_RGB: 480 block->size = 8; 481 block->width = 4; 482 block->height = 4; 483 break; 484 case PIPE_FORMAT_DXT3_RGBA: 485 case PIPE_FORMAT_DXT5_RGBA: 486 block->size = 16; 487 block->width = 4; 488 block->height = 4; 489 break; 490 case PIPE_FORMAT_YCBCR: 491 case PIPE_FORMAT_YCBCR_REV: 492 block->size = 4; /* 2*cpp */ 493 block->width = 2; 494 block->height = 1; 495 break; 496 default: 497 block->size = pf_get_size(format); 498 block->width = 1; 499 block->height = 1; 500 break; 501 } 502} 503 504static INLINE unsigned 505pf_get_nblocksx(const struct pipe_format_block *block, unsigned x) 506{ 507 return (x + block->width - 1)/block->width; 508} 509 510static INLINE unsigned 511pf_get_nblocksy(const struct pipe_format_block *block, unsigned y) 512{ 513 return (y + block->height - 1)/block->height; 514} 515 516static INLINE unsigned 517pf_get_nblocks(const struct pipe_format_block *block, unsigned width, unsigned height) 518{ 519 return pf_get_nblocksx(block, width)*pf_get_nblocksy(block, height); 520} 521 522static INLINE boolean 523pf_is_compressed( enum pipe_format format ) 524{ 525 return pf_layout(format) == PIPE_FORMAT_LAYOUT_DXT ? TRUE : FALSE; 526} 527 528static INLINE boolean 529pf_is_ycbcr( enum pipe_format format ) 530{ 531 return pf_layout(format) == PIPE_FORMAT_LAYOUT_YCBCR ? TRUE : FALSE; 532} 533 534static INLINE boolean 535pf_has_alpha( enum pipe_format format ) 536{ 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) 544 return TRUE; 545 return pf_get_component_bits( format, PIPE_FORMAT_COMP_A ) ? TRUE : FALSE; 546 case PIPE_FORMAT_LAYOUT_YCBCR: 547 return FALSE; 548 case PIPE_FORMAT_LAYOUT_DXT: 549 switch (format) { 550 case PIPE_FORMAT_DXT1_RGBA: 551 case PIPE_FORMAT_DXT3_RGBA: 552 case PIPE_FORMAT_DXT5_RGBA: 553 return TRUE; 554 default: 555 return FALSE; 556 } 557 default: 558 assert( 0 ); 559 return FALSE; 560 } 561} 562 563#ifdef __cplusplus 564} 565#endif 566 567#endif 568