spu_util.c

Go to the documentation of this file.
00001 
00002 #include "cell/common.h"
00003 #include "pipe/p_shader_tokens.h"
00004 #include "pipe/p_debug.h"
00005 #include "tgsi/tgsi_parse.h"
00006 //#include "tgsi_build.h"
00007 #include "tgsi/tgsi_util.h"
00008 
00009 unsigned
00010 tgsi_util_get_src_register_swizzle(
00011    const struct tgsi_src_register *reg,
00012    unsigned component )
00013 {
00014    switch( component ) {
00015    case 0:
00016       return reg->SwizzleX;
00017    case 1:
00018       return reg->SwizzleY;
00019    case 2:
00020       return reg->SwizzleZ;
00021    case 3:
00022       return reg->SwizzleW;
00023    default:
00024       ASSERT( 0 );
00025    }
00026    return 0;
00027 }
00028 
00029 unsigned
00030 tgsi_util_get_src_register_extswizzle(
00031    const struct tgsi_src_register_ext_swz *reg,
00032    unsigned component )
00033 {
00034    switch( component ) {
00035    case 0:
00036       return reg->ExtSwizzleX;
00037    case 1:
00038       return reg->ExtSwizzleY;
00039    case 2:
00040       return reg->ExtSwizzleZ;
00041    case 3:
00042       return reg->ExtSwizzleW;
00043    default:
00044       ASSERT( 0 );
00045    }
00046    return 0;
00047 }
00048 
00049 unsigned
00050 tgsi_util_get_full_src_register_extswizzle(
00051    const struct tgsi_full_src_register  *reg,
00052    unsigned component )
00053 {
00054    unsigned swizzle;
00055 
00056    /*
00057     * First, calculate  the   extended swizzle for a given channel. This will give
00058     * us either a channel index into the simple swizzle or  a constant 1 or   0.
00059     */
00060    swizzle = tgsi_util_get_src_register_extswizzle(
00061       &reg->SrcRegisterExtSwz,
00062       component );
00063 
00064    ASSERT (TGSI_SWIZZLE_X == TGSI_EXTSWIZZLE_X);
00065    ASSERT (TGSI_SWIZZLE_Y == TGSI_EXTSWIZZLE_Y);
00066    ASSERT (TGSI_SWIZZLE_Z == TGSI_EXTSWIZZLE_Z);
00067    ASSERT (TGSI_SWIZZLE_W == TGSI_EXTSWIZZLE_W);
00068    ASSERT (TGSI_EXTSWIZZLE_ZERO > TGSI_SWIZZLE_W);
00069    ASSERT (TGSI_EXTSWIZZLE_ONE > TGSI_SWIZZLE_W);
00070 
00071    /*
00072     * Second, calculate the simple  swizzle  for   the   unswizzled channel index.
00073     * Leave the constants intact, they are   not   affected by the   simple swizzle.
00074     */
00075    if( swizzle <= TGSI_SWIZZLE_W ) {
00076       swizzle = tgsi_util_get_src_register_swizzle(
00077          &reg->SrcRegister,
00078          component );
00079    }
00080 
00081    return swizzle;
00082 }
00083 
00084 unsigned
00085 tgsi_util_get_src_register_extnegate(
00086    const  struct tgsi_src_register_ext_swz *reg,
00087    unsigned component )
00088 {
00089    switch( component ) {
00090    case 0:
00091       return reg->NegateX;
00092    case 1:
00093       return reg->NegateY;
00094    case 2:
00095       return reg->NegateZ;
00096    case 3:
00097       return reg->NegateW;
00098    default:
00099       ASSERT( 0 );
00100    }
00101    return 0;
00102 }
00103 
00104 void
00105 tgsi_util_set_src_register_extnegate(
00106    struct tgsi_src_register_ext_swz *reg,
00107    unsigned negate,
00108    unsigned component )
00109 {
00110    switch( component ) {
00111    case 0:
00112       reg->NegateX = negate;
00113       break;
00114    case 1:
00115       reg->NegateY = negate;
00116       break;
00117    case 2:
00118       reg->NegateZ = negate;
00119       break;
00120    case 3:
00121       reg->NegateW = negate;
00122       break;
00123    default:
00124       ASSERT( 0 );
00125    }
00126 }
00127 
00128 unsigned
00129 tgsi_util_get_full_src_register_sign_mode(
00130    const struct  tgsi_full_src_register *reg,
00131    unsigned component )
00132 {
00133    unsigned sign_mode;
00134 
00135    if( reg->SrcRegisterExtMod.Absolute ) {
00136       /* Consider only the post-abs negation. */
00137 
00138       if( reg->SrcRegisterExtMod.Negate ) {
00139          sign_mode = TGSI_UTIL_SIGN_SET;
00140       }
00141       else {
00142          sign_mode = TGSI_UTIL_SIGN_CLEAR;
00143       }
00144    }
00145    else {
00146       /* Accumulate the three negations. */
00147 
00148       unsigned negate;
00149 
00150       negate = reg->SrcRegister.Negate;
00151       if( tgsi_util_get_src_register_extnegate( &reg->SrcRegisterExtSwz, component ) ) {
00152          negate = !negate;
00153       }
00154       if( reg->SrcRegisterExtMod.Negate ) {
00155          negate = !negate;
00156       }
00157 
00158       if( negate ) {
00159          sign_mode = TGSI_UTIL_SIGN_TOGGLE;
00160       }
00161       else {
00162          sign_mode = TGSI_UTIL_SIGN_KEEP;
00163       }
00164    }
00165 
00166    return sign_mode;
00167 }

Generated on Tue Sep 29 06:25:16 2009 for Gallium3D by  doxygen 1.5.4