home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / math / Simd.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  15KB  |  227 lines

  1. #ifndef __MATH_SIMD_H__
  2. #define __MATH_SIMD_H__
  3.  
  4. /*
  5. ===============================================================================
  6.  
  7.     Single Instruction Multiple Data (SIMD)
  8.  
  9.     For optimal use data should be aligned on a 16 byte boundary.
  10.     All idSIMDProcessor routines are thread safe.
  11.  
  12. ===============================================================================
  13. */
  14.  
  15. class idSIMD {
  16. public:
  17.     static void            Init( void );
  18.     static void            InitProcessor( const char *module, bool forceGeneric );
  19.     static void            Shutdown( void );
  20.     static void            Test_f( const class idCmdArgs &args );
  21. };
  22.  
  23.  
  24. /*
  25. ===============================================================================
  26.  
  27.     virtual base class for different SIMD processors
  28.  
  29. ===============================================================================
  30. */
  31.  
  32. #ifdef _WIN32
  33. #define VPCALL __fastcall
  34. #else
  35. #define VPCALL
  36. #endif
  37.  
  38. class idVec2;
  39. class idVec3;
  40. #ifdef _XENON
  41. class __declspec(align(16)) idVec4;
  42. #else
  43. class idVec4;
  44. #endif
  45. class idVec5;
  46. class idVec6;
  47. class idVecX;
  48. class idMat2;
  49. class idMat3;
  50. class idMat4;
  51. class idMat5;
  52. class idMat6;
  53. class idMatX;
  54. class idPlane;
  55. class idBounds;
  56. class idDrawVert;
  57. class idJointQuat;
  58. class idJointMat;
  59. struct dominantTri_s;
  60. struct jointWeight_t;
  61. struct silEdge_s;
  62.  
  63. // RAVEN BEGIN
  64. // dluetscher: declared new vertex format
  65. #ifdef _MD5R_SUPPORT
  66. class rvSilTraceVertT;
  67. #endif
  68. // RAVEN END
  69.  
  70. const int MIXBUFFER_SAMPLES = 4096;
  71.  
  72. typedef enum {
  73.     SPEAKER_LEFT = 0,
  74.     SPEAKER_RIGHT,
  75.     SPEAKER_CENTER,
  76.     SPEAKER_LFE,
  77.     SPEAKER_BACKLEFT,
  78.     SPEAKER_BACKRIGHT
  79. } speakerLabel;
  80.  
  81.  
  82. // RAVEN BEGIN
  83. // jsinger: forward declare and use a typedef so that xenon doesn't have to use inheritence for the SIMD stuff
  84. #ifdef _XENON
  85. class idSIMD_Xenon;
  86. typedef idSIMD_Xenon idSIMDProcessor;
  87. #else
  88. // RAVEN END
  89. class idSIMDProcessor {
  90. public:
  91.                                     idSIMDProcessor( void ) { cpuid = CPUID_NONE; }
  92.  
  93.     cpuid_t                            cpuid;
  94.  
  95.     virtual const char * VPCALL        GetName( void ) const = 0;
  96.  
  97.     virtual void VPCALL Add( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  98.     virtual void VPCALL Add( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  99.     virtual void VPCALL Sub( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  100.     virtual void VPCALL Sub( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  101.     virtual void VPCALL Mul( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  102.     virtual void VPCALL Mul( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  103.     virtual void VPCALL Div( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  104.     virtual void VPCALL Div( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  105.     virtual void VPCALL MulAdd( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  106.     virtual void VPCALL MulAdd( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  107.     virtual void VPCALL MulSub( float *dst,            const float constant,    const float *src,        const int count ) = 0;
  108.     virtual void VPCALL MulSub( float *dst,            const float *src0,        const float *src1,        const int count ) = 0;
  109.  
  110.     virtual    void VPCALL Dot( float *dst,            const idVec3 &constant,    const idVec3 *src,        const int count ) = 0;
  111.     virtual    void VPCALL Dot( float *dst,            const idVec3 &constant,    const idPlane *src,        const int count ) = 0;
  112.     virtual void VPCALL Dot( float *dst,            const idVec3 &constant,    const idDrawVert *src,    const int count ) = 0;
  113.     virtual    void VPCALL Dot( float *dst,            const idPlane &constant,const idVec3 *src,        const int count ) = 0;
  114.     virtual    void VPCALL Dot( float *dst,            const idPlane &constant,const idPlane *src,        const int count ) = 0;
  115.     virtual void VPCALL Dot( float *dst,            const idPlane &constant,const idDrawVert *src,    const int count ) = 0;
  116.     virtual    void VPCALL Dot( float *dst,            const idVec3 *src0,        const idVec3 *src1,        const int count ) = 0;
  117.     virtual void VPCALL Dot( float &dot,            const float *src1,        const float *src2,        const int count ) = 0;
  118.  
  119.     virtual    void VPCALL CmpGT( byte *dst,            const float *src0,        const float constant,    const int count ) = 0;
  120.     virtual    void VPCALL CmpGT( byte *dst,            const byte bitNum,        const float *src0,        const float constant,    const int count ) = 0;
  121.     virtual    void VPCALL CmpGE( byte *dst,            const float *src0,        const float constant,    const int count ) = 0;
  122.     virtual    void VPCALL CmpGE( byte *dst,            const byte bitNum,        const float *src0,        const float constant,    const int count ) = 0;
  123.     virtual    void VPCALL CmpLT( byte *dst,            const float *src0,        const float constant,    const int count ) = 0;
  124.     virtual    void VPCALL CmpLT( byte *dst,            const byte bitNum,        const float *src0,        const float constant,    const int count ) = 0;
  125.     virtual    void VPCALL CmpLE( byte *dst,            const float *src0,        const float constant,    const int count ) = 0;
  126.     virtual    void VPCALL CmpLE( byte *dst,            const byte bitNum,        const float *src0,        const float constant,    const int count ) = 0;
  127.  
  128.     virtual    void VPCALL MinMax( float &min,            float &max,                const float *src,        const int count ) = 0;
  129.     virtual    void VPCALL MinMax( idVec2 &min,        idVec2 &max,            const idVec2 *src,        const int count ) = 0;
  130.     virtual    void VPCALL MinMax( idVec3 &min,        idVec3 &max,            const idVec3 *src,        const int count ) = 0;
  131.     virtual    void VPCALL MinMax( idVec3 &min,        idVec3 &max,            const idDrawVert *src,    const int count ) = 0;
  132.     virtual    void VPCALL MinMax( idVec3 &min,        idVec3 &max,            const idDrawVert *src,    const int *indexes,        const int count ) = 0;
  133.  
  134.     virtual    void VPCALL Clamp( float *dst,            const float *src,        const float min,        const float max,        const int count ) = 0;
  135.     virtual    void VPCALL ClampMin( float *dst,        const float *src,        const float min,        const int count ) = 0;
  136.     virtual    void VPCALL ClampMax( float *dst,        const float *src,        const float max,        const int count ) = 0;
  137.  
  138.     virtual void VPCALL Memcpy( void *dst,            const void *src,        const int count ) = 0;
  139.     virtual void VPCALL Memset( void *dst,            const int val,            const int count ) = 0;
  140.  
  141.     // these assume 16 byte aligned and 16 byte padded memory
  142.     virtual void VPCALL Zero16( float *dst,            const int count ) = 0;
  143.     virtual void VPCALL Negate16( float *dst,        const int count ) = 0;
  144.     virtual void VPCALL Copy16( float *dst,            const float *src,        const int count ) = 0;
  145.     virtual void VPCALL Add16( float *dst,            const float *src1,        const float *src2,        const int count ) = 0;
  146.     virtual void VPCALL Sub16( float *dst,            const float *src1,        const float *src2,        const int count ) = 0;
  147.     virtual void VPCALL Mul16( float *dst,            const float *src1,        const float constant,    const int count ) = 0;
  148.     virtual void VPCALL AddAssign16( float *dst,    const float *src,        const int count ) = 0;
  149.     virtual void VPCALL SubAssign16( float *dst,    const float *src,        const int count ) = 0;
  150.     virtual void VPCALL MulAssign16( float *dst,    const float constant,    const int count ) = 0;
  151.  
  152.     // idMatX operations
  153.     virtual void VPCALL MatX_MultiplyVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  154.     virtual void VPCALL MatX_MultiplyAddVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  155.     virtual void VPCALL MatX_MultiplySubVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  156.     virtual void VPCALL MatX_TransposeMultiplyVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  157.     virtual void VPCALL MatX_TransposeMultiplyAddVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  158.     virtual void VPCALL MatX_TransposeMultiplySubVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
  159.     virtual void VPCALL MatX_MultiplyMatX( idMatX &dst, const idMatX &m1, const idMatX &m2 ) = 0;
  160.     virtual void VPCALL MatX_TransposeMultiplyMatX( idMatX &dst, const idMatX &m1, const idMatX &m2 ) = 0;
  161.     virtual void VPCALL MatX_LowerTriangularSolve( const idMatX &L, float *x, const float *b, const int n, int skip = 0 ) = 0;
  162.     virtual void VPCALL MatX_LowerTriangularSolveTranspose( const idMatX &L, float *x, const float *b, const int n ) = 0;
  163.     virtual bool VPCALL MatX_LDLTFactor( idMatX &mat, idVecX &invDiag, const int n ) = 0;
  164.  
  165.     // rendering
  166.     virtual void VPCALL BlendJoints( idJointQuat *joints, const idJointQuat *blendJoints, const float lerp, const int *index, const int numJoints ) = 0;
  167.     virtual void VPCALL ConvertJointQuatsToJointMats( idJointMat *jointMats, const idJointQuat *jointQuats, const int numJoints ) = 0;
  168.     virtual void VPCALL ConvertJointMatsToJointQuats( idJointQuat *jointQuats, const idJointMat *jointMats, const int numJoints ) = 0;
  169.     virtual void VPCALL TransformJoints( idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint ) = 0;
  170.     virtual void VPCALL UntransformJoints( idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint ) = 0;
  171.     virtual void VPCALL MultiplyJoints( idJointMat *result, const idJointMat *joints1, const idJointMat *joints2, const int numJoints ) = 0;
  172.     virtual void VPCALL TransformVertsNew( idDrawVert *verts, const int numVerts, idBounds &bounds, const idJointMat *joints, const idVec4 *base, const jointWeight_t *weights, const int numWeights ) = 0;
  173.     virtual void VPCALL TransformVertsAndTangents( idDrawVert *verts, const int numVerts, idBounds &bounds, const idJointMat *joints, const idVec4 *base, const jointWeight_t *weights, const int numWeights ) = 0;
  174.     virtual void VPCALL TransformVertsAndTangentsFast( idDrawVert *verts, const int numVerts, idBounds &bounds, const idJointMat *joints, const idVec4 *base, const jointWeight_t *weights, const int numWeights ) = 0;
  175.     virtual void VPCALL TracePointCull( byte *cullBits, byte &totalOr, const float radius, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
  176.     virtual void VPCALL DecalPointCull( byte *cullBits, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
  177.     virtual void VPCALL OverlayPointCull( byte *cullBits, idVec2 *texCoords, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
  178.     virtual void VPCALL DeriveTriPlanes( idPlane *planes, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
  179.     virtual void VPCALL DeriveTangents( idPlane *planes, idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
  180.     virtual void VPCALL DeriveUnsmoothedTangents( idDrawVert *verts, const dominantTri_s *dominantTris, const int numVerts ) = 0;
  181.     virtual void VPCALL NormalizeTangents( idDrawVert *verts, const int numVerts ) = 0;
  182.     virtual void VPCALL CreateTextureSpaceLightVectors( idVec3 *lightVectors, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
  183.     virtual void VPCALL CreateSpecularTextureCoords( idVec4 *texCoords, const idVec3 &lightOrigin, const idVec3 &viewOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
  184.     virtual int  VPCALL CreateShadowCache( idVec4 *vertexCache, int *vertRemap, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts ) = 0;
  185.     virtual int  VPCALL CreateVertexProgramShadowCache( idVec4 *vertexCache, const idDrawVert *verts, const int numVerts ) = 0;
  186.     virtual int  VPCALL ShadowVolume_CountFacing( const byte *facing, const int numFaces ) = 0;
  187.     virtual int  VPCALL ShadowVolume_CountFacingCull( byte *facing, const int numFaces, const int *indexes, const byte *cull ) = 0;
  188.     virtual int  VPCALL ShadowVolume_CreateSilTriangles( int *shadowIndexes, const byte *facing, const silEdge_s *silEdges, const int numSilEdges ) = 0;
  189.     virtual int  VPCALL ShadowVolume_CreateCapTriangles( int *shadowIndexes, const byte *facing, const int *indexes, const int numIndexes ) = 0;
  190.  
  191.     // sound mixing
  192.     virtual void VPCALL UpSamplePCMTo44kHz( float *dest, const short *pcm, const int numSamples, const int kHz, const int numChannels ) = 0;
  193.     virtual void VPCALL UpSampleOGGTo44kHz( float *dest, const float * const *ogg, const int numSamples, const int kHz, const int numChannels ) = 0;
  194.     virtual void VPCALL MixSoundTwoSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] ) = 0;
  195.     virtual void VPCALL MixSoundTwoSpeakerStereo( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] ) = 0;
  196.     virtual void VPCALL MixSoundSixSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6] ) = 0;
  197.     virtual void VPCALL MixSoundSixSpeakerStereo( float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6] ) = 0;
  198.     virtual void VPCALL MixedSoundToSamples( short *samples, const float *mixBuffer, const int numSamples ) = 0;
  199.  
  200.     // rvSilTraceVertT operations
  201. // RAVEN BEGIN
  202. // dluetscher: added support for operations on idSilTraceVerts
  203. #ifdef _MD5R_SUPPORT
  204.     virtual void VPCALL JointMat_MultiplyMats( float *destMats, const idJointMat *src1Mats, const idJointMat *src2Mats, int *transformPalette, int transformCount ) = 0;
  205.     virtual void VPCALL TransformVertsMinMax4Bone( rvSilTraceVertT *silTraceVertOutputData, idVec3 &min, idVec3 &max, byte *vertexInputData, int vertStride, int numVerts, float *skinToModelTransforms ) = 0; // transforms an array of index-weighted vertices into an array of idSilTraceVerts, while simulatenously calculating the bounds
  206.     virtual void VPCALL TransformVertsMinMax1Bone( rvSilTraceVertT *silTraceVertOutputData, idVec3 &min, idVec3 &max, byte *vertexInputData, int vertStride, int numVerts, float *skinToModelTransforms ) = 0; // transforms an array of index-weighted vertices into an array of idSilTraceVerts, while simulatenously calculating the bounds
  207.     virtual void VPCALL Dot( float *dst, const idVec3 &constant, const rvSilTraceVertT *src,    const int count ) = 0;
  208.     virtual void VPCALL Dot( float *dst, const idPlane &constant, const rvSilTraceVertT *src, const int count ) = 0;
  209.     virtual void VPCALL TracePointCull( byte *cullBits, byte &totalOr, const float radius, const idPlane *planes, const rvSilTraceVertT *verts, const int numVerts ) = 0;
  210.     virtual void VPCALL DecalPointCull( byte *cullBits, const idPlane *planes, const rvSilTraceVertT *verts, const int numVerts ) = 0;
  211.     virtual void VPCALL OverlayPointCull( byte *cullBits, idVec2 *texCoords, const idPlane *planes, const rvSilTraceVertT *verts, const int numVerts ) = 0;
  212.     virtual void VPCALL DeriveTriPlanes( idPlane *planes, const rvSilTraceVertT *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
  213.     virtual void VPCALL DeriveTriPlanes( idPlane *planes, const rvSilTraceVertT *verts, const int numVerts, const unsigned short *indexes, const int numIndexes ) = 0;
  214.     virtual    void VPCALL MinMax( idVec3 &min, idVec3 &max, const rvSilTraceVertT *src, const int count ) = 0;
  215.     virtual    void VPCALL MinMax( idVec3 &min, idVec3 &max, const rvSilTraceVertT *src, const int *indexes, const int count ) = 0;
  216. #endif
  217. // RAVEN END
  218. };
  219. // RAVEN BEGIN
  220. #endif
  221. // RAVEN END
  222.  
  223. // pointer to SIMD processor
  224. extern idSIMDProcessor *SIMDProcessor;
  225.  
  226. #endif /* !__MATH_SIMD_H__ */
  227.