Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

359 lines
14 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BONE_UTILS_PS3_H
  8. #define BONE_UTILS_PS3_H
  9. #ifndef _PS3
  10. #error "This header is for PS3 target only"
  11. #endif
  12. #include "vjobs_interface.h"
  13. #if defined(__SPU__)
  14. #include "ps3/spu_job_shared.h"
  15. #include "cell/dma.h"
  16. #endif
  17. #if 1
  18. #define DotProduct_PS3 DotProduct
  19. #define MatrixAngles_PS3 MatrixAngles
  20. #define VectorRotate_PS3 VectorRotate
  21. #define VectorSubtract_PS3 VectorSubtract
  22. #define MatrixPosition_PS3 MatrixPosition
  23. #define _VMX_VectorNormalize_PS3 _VMX_VectorNormalize
  24. #define VectorNormalize_PS3 VectorNormalize
  25. #define VectorMultiply_PS3 VectorMultiply
  26. #define VectorScale_PS3 VectorScale
  27. #define VectorMAInline_PS3 VectorMAInline
  28. #define VectorMA_PS3 VectorMA
  29. #define SimpleSpline_PS3 SimpleSpline
  30. #define ConcatTransforms_PS3 ConcatTransforms
  31. #define ConcatTransforms_Aligned_PS3 ConcatTransforms_Aligned
  32. //#define QuaternionMatrix_PS3 QuaternionMatrix
  33. //#define QuaternionAlign_PS3 QuaternionAlign
  34. //#define QuaternionSlerp_PS3 QuaternionSlerp
  35. //#define QuaternionSlerpNoAlign_PS3 QuaternionSlerpNoAlign
  36. //#define QuaternionNormalize_PS3 QuaternionNormalize
  37. //#define QuaternionBlend_PS3 QuaternionBlend
  38. //#define QuaternionBlendNoAlign_PS3 QuaternionBlendNoAlign
  39. //#define QuaternionIdentityBlend_PS3 QuaternionIdentityBlend
  40. //#define QuaternionScale_PS3 QuaternionScale
  41. //#define QuaternionAdd_PS3 QuaternionAdd
  42. //#define QuaternionDotProduct_PS3 QuaternionDotProduct
  43. //#define QuaternionMult_PS3 QuaternionMult
  44. #define MatrixSetColumn_PS3 MatrixSetColumn
  45. #define MatrixGetColumn_PS3 MatrixGetColumn
  46. #define MatrixInvert_PS3 MatrixInvert
  47. #define VectorRotate_PS3 VectorRotate
  48. #define AngleMatrix_PS3 AngleMatrix
  49. #define AngleQuaternion_PS3 AngleQuaternion
  50. #define Hermite_Spline_PS3 Hermite_Spline
  51. #define Hermite_SplineBasis_PS3 Hermite_SplineBasis
  52. #define SetIdentityMatrix_PS3 SetIdentityMatrix
  53. FORCEINLINE Vector Lerp_PS3( float flPercent, Vector const &A, Vector const &B )
  54. {
  55. return A + (B - A) * flPercent;
  56. }
  57. #endif
  58. // from mathlib.h, mathlib_base.cpp
  59. #if 0
  60. FORCEINLINE float DotProduct_PS3(const Vector& a, const Vector& b)
  61. {
  62. // return( a.x*b.x + a.y*b.y + a.z*b.z );
  63. return a.Dot(b);
  64. }
  65. FORCEINLINE float DotProduct_PS3(const float* a, const float* b)
  66. {
  67. return( a[0]*b[0] + a[1]*b[1] + a[2]*b[2] );
  68. }
  69. void ConcatTransforms_PS3( const matrix3x4a_t &m0, const matrix3x4a_t &m1, matrix3x4a_t &out );
  70. void ConcatTransforms_Aligned_PS3( const matrix3x4a_t &m0, const matrix3x4a_t &m1, matrix3x4a_t &out );
  71. void MatrixAngles_PS3( const matrix3x4_t & matrix, float *angles ); // !!!!
  72. void MatrixAngles_PS3( const matrix3x4_t& matrix, RadianEuler &angles, Vector &position );
  73. void MatrixAngles_PS3( const matrix3x4_t &matrix, Quaternion &q, Vector &pos );
  74. inline void MatrixAngles_PS3( const matrix3x4_t &matrix, RadianEuler &angles )
  75. {
  76. MatrixAngles_PS3( matrix, &angles.x );
  77. angles.Init( DEG2RAD( angles.z ), DEG2RAD( angles.x ), DEG2RAD( angles.y ) );
  78. }
  79. void MatrixGetColumn_PS3( const matrix3x4_t& in, int column, Vector &out );
  80. void MatrixSetColumn_PS3( const Vector &in, int column, matrix3x4_t& out );
  81. void MatrixInvert_PS3( const matrix3x4_t& in, matrix3x4_t& out );
  82. void VectorRotate_PS3( const float *in1, const matrix3x4_t & in2, float *out);
  83. inline void VectorRotate_PS3( const Vector& in1, const matrix3x4_t &in2, Vector &out)
  84. {
  85. VectorRotate_PS3( &in1.x, in2, &out.x );
  86. }
  87. FORCEINLINE void VectorSubtract_PS3( const Vector& a, const Vector& b, Vector& c )
  88. {
  89. c.x = a.x - b.x;
  90. c.y = a.y - b.y;
  91. c.z = a.z - b.z;
  92. }
  93. inline void MatrixPosition_PS3( const matrix3x4_t &matrix, Vector &position )
  94. {
  95. position[0] = matrix[0][3];
  96. position[1] = matrix[1][3];
  97. position[2] = matrix[2][3];
  98. }
  99. FORCEINLINE float _VMX_VectorNormalize_PS3( Vector &vec )
  100. {
  101. vec_float4 vIn;
  102. vec_float4 v0, v1;
  103. vector unsigned char permMask;
  104. v0 = vec_ld( 0, vec.Base() );
  105. permMask = vec_lvsl( 0, vec.Base() );
  106. v1 = vec_ld( 11, vec.Base() );
  107. vIn = vec_perm(v0, v1, permMask);
  108. float mag = vmathV3Length((VmathVector3 *)&vIn);
  109. float den = 1.f / (mag + FLT_EPSILON );
  110. vec.x *= den;
  111. vec.y *= den;
  112. vec.z *= den;
  113. return mag;
  114. }
  115. FORCEINLINE float VectorNormalize_PS3( Vector& v )
  116. {
  117. return _VMX_VectorNormalize_PS3( v );
  118. }
  119. FORCEINLINE void VectorMultiply_PS3( const Vector& a, float b, Vector& c )
  120. {
  121. c.x = a.x * b;
  122. c.y = a.y * b;
  123. c.z = a.z * b;
  124. }
  125. FORCEINLINE void VectorMultiply_PS3( const Vector& a, const Vector& b, Vector& c )
  126. {
  127. c.x = a.x * b.x;
  128. c.y = a.y * b.y;
  129. c.z = a.z * b.z;
  130. }
  131. inline void VectorScale_PS3 ( const Vector& in, float scale, Vector& result )
  132. {
  133. VectorMultiply_PS3( in, scale, result );
  134. }
  135. FORCEINLINE Vector Lerp_PS3( float flPercent, Vector const &A, Vector const &B )
  136. {
  137. return A + (B - A) * flPercent;
  138. }
  139. FORCEINLINE void VectorMAInline_PS3( const float* start, float scale, const float* direction, float* dest )
  140. {
  141. dest[0]=start[0]+direction[0]*scale;
  142. dest[1]=start[1]+direction[1]*scale;
  143. dest[2]=start[2]+direction[2]*scale;
  144. }
  145. FORCEINLINE void VectorMAInline_PS3( const Vector& start, float scale, const Vector& direction, Vector& dest )
  146. {
  147. dest.x=start.x+direction.x*scale;
  148. dest.y=start.y+direction.y*scale;
  149. dest.z=start.z+direction.z*scale;
  150. }
  151. FORCEINLINE void VectorMA_PS3( const Vector& start, float scale, const Vector& direction, Vector& dest )
  152. {
  153. VectorMAInline_PS3(start, scale, direction, dest);
  154. }
  155. FORCEINLINE void VectorMA_PS3( const float * start, float scale, const float *direction, float *dest )
  156. {
  157. VectorMAInline_PS3(start, scale, direction, dest);
  158. }
  159. void AngleMatrix_PS3( RadianEuler const &angles, const Vector &position, matrix3x4_t& matrix );
  160. void AngleMatrix_PS3( const RadianEuler& angles, matrix3x4_t& matrix );
  161. void AngleMatrix_PS3( const QAngle &angles, const Vector &position, matrix3x4_t& matrix );
  162. void AngleMatrix_PS3( const QAngle &angles, matrix3x4_t& matrix );
  163. void AngleQuaternion_PS3( const RadianEuler &angles, Quaternion &outQuat );
  164. void Hermite_Spline_PS3( const Vector &p1, const Vector &p2, const Vector &d1, const Vector &d2, float t, Vector& output );
  165. float Hermite_Spline_PS3( float p1, float p2, float d1, float d2, float t );
  166. void Hermite_SplineBasis_PS3( float t, float basis[4] );
  167. void Hermite_Spline_PS3( const Vector &p0, const Vector &p1, const Vector &p2, float t, Vector& output );
  168. float Hermite_Spline_PS3( float p0, float p1, float p2, float t );
  169. void Hermite_Spline_PS3( const Quaternion &q0, const Quaternion &q1, const Quaternion &q2, float t, Quaternion &output );
  170. inline float SimpleSpline_PS3( float value )
  171. {
  172. float valueSquared = value * value;
  173. // Nice little ease-in, ease-out spline-like curve
  174. return (3.0f * valueSquared - 2.0f * valueSquared * value);
  175. }
  176. #endif
  177. void QuaternionMatrix_PS3( const Quaternion &q, const Vector &pos, matrix3x4a_t& matrix );
  178. void QuaternionAlign_PS3( const Quaternion &p, const Quaternion &q, QuaternionAligned &qt );
  179. void QuaternionSlerp_PS3( const Quaternion &p, const Quaternion &q, float t, Quaternion &qt );
  180. void QuaternionSlerpNoAlign_PS3( const Quaternion &p, const Quaternion &q, float t, Quaternion &qt );
  181. float QuaternionNormalize_PS3( Quaternion &q );
  182. void QuaternionBlend_PS3( const Quaternion &p, const Quaternion &q, float t, Quaternion &qt );
  183. void QuaternionBlendNoAlign_PS3( const Quaternion &p, const Quaternion &q, float t, Quaternion &qt );
  184. void QuaternionIdentityBlend_PS3( const Quaternion &p, float t, Quaternion &qt );
  185. void QuaternionScale_PS3( const Quaternion &p, float t, Quaternion &q );
  186. void QuaternionAdd_PS3( const Quaternion &p, const Quaternion &q, Quaternion &qt );
  187. float QuaternionDotProduct_PS3( const Quaternion &p, const Quaternion &q );
  188. void QuaternionMult_PS3( const Quaternion &p, const Quaternion &q, Quaternion &qt );
  189. void AddDependencies_SPU( bonejob_SPU *pBonejobSPU, accumposeentry_SPU *pPoseEntry, float flWeight = 1.0f );
  190. //void AddDependencies_PPU( CStudioHdr *pHdr, float m_flTime, int m_boneMask, mstudioseqdesc_t &seqdesc, int iSequence, float flCycle, const float poseParameters[], float flWeight );
  191. void GetBoneMapBoneWeight_SPU( bonejob_SPU *pSPUJob, accumposeentry_SPU *pPoseEntry, int *&pLS_boneMap, float *&pLS_boneWeight );
  192. void CalcDecompressedAnimation_PS3( void *pEA_Compressed, const mstudiocompressedikerror_t_PS3 *pLS_Compressed, int iFrame, float fraq, BoneVector &pos, BoneQuaternion &q );
  193. void QuaternionAccumulate_PS3( const Quaternion &p, float s, const Quaternion &q, Quaternion &qt );
  194. void CalcAnimation_PS3( const bonejob_SPU *pBonejob, const accumposeentry_SPU *pPoseEntry, BoneVector *pos, BoneQuaternion *q, const int *boneMap, const float *boneWeight, int animIndex, float cycle, int boneMask );
  195. void BlendBones_PS3( const bonejob_SPU *pBonejob, const accumposeentry_SPU *pPoseEntry, BoneQuaternion *q1, BoneVector *pos1, const int *boneMap, const float *boneWeight, const BoneQuaternion *q2, const BoneVector *pos2, float s, int boneMask );
  196. void ScaleBones_PS3( const bonejob_SPU *pBonejob, const accumposeentry_SPU *pPoseEntry, BoneQuaternion *q1, BoneVector *pos1, const int *boneMap, const float *boneWeight, float s, int boneMask );
  197. // void CalcPose( const CStudioHdr *pStudioHdr, CIKContext *pIKContext, Vector pos[], BoneQuaternion q[], int sequence, float cycle, const float poseParameter[], int boneMask, float flWeight = 1.0f, float flTime = 0.0f );
  198. //bool CalcPoseSingle( const CStudioHdr *pStudioHdr, Vector pos[], BoneQuaternion q[], mstudioseqdesc_t &seqdesc, int sequence, float cycle, const float poseParameter[], int boneMask, float flTime );
  199. // void CalcBoneAdj( const CStudioHdr *pStudioHdr, Vector pos[], Quaternion q[], const float controllers[], int boneMask );
  200. void BuildBoneChainPartial_PS3(
  201. const int *pBoneParent,
  202. const matrix3x4a_t &rootxform,
  203. const BoneVector pos[],
  204. const BoneQuaternion q[],
  205. int iBone,
  206. matrix3x4a_t *pBoneToWorld,
  207. CBoneBitList_PS3 &boneComputed,
  208. int iRoot );
  209. struct PS3BoneJobData;
  210. #define BONEJOB_ERROR_EXCEEDEDPQSTACK (1<<0)
  211. #define BONEJOB_ERROR_EXCEEDEDMAXCALLS (1<<1)
  212. #define BONEJOB_ERROR_LOCALHIER (1<<2)
  213. #if !defined(__SPU__)
  214. class CBoneSetup_PS3
  215. {
  216. public:
  217. CBoneSetup_PS3( const CStudioHdr *pStudioHdr, int boneMask, const float poseParameter[], bonejob_SPU *pBoneJobSPU );
  218. void CalcAutoplaySequences_AddPoseCalls( float flRealTime );
  219. void AccumulatePose_AddToBoneJob( bonejob_SPU* pSPUJob, int sequence, float cycle, float flWeight, CIKContext *pIKContext, int pqStackLevel );
  220. int RunAccumulatePoseJobs_PPU( bonejob_SPU *pBoneJob );
  221. int RunAccumulatePoseJobs_SPU( bonejob_SPU *pBoneJob, job_accumpose::JobDescriptor_t *pJobDescriptor );
  222. private:
  223. bool SetAnimData( accumposeentry_SPU *pPoseEntry, const CStudioHdr *pStudioHdr, mstudioseqdesc_t &seqdesc, int sequence, int x, int y, int animIndex, float weight );
  224. bool CalcPoseSingle( accumposeentry_SPU *pPoseEntry, const CStudioHdr *pStudioHdr, mstudioseqdesc_t &seqdesc, int sequence, float cycle, const float poseParameter[], float flTime );
  225. int AddSequenceLayers( bonejob_SPU *pSPUJob, mstudioseqdesc_t &seqdesc, int sequence, float cycle, float flWeight, CIKContext *pIKContext, int pqStackLevel );
  226. int AddLocalLayers( bonejob_SPU *pSPUJob, mstudioseqdesc_t &seqdesc, int sequence, float cycle, float flWeight, CIKContext *pIKContext, int pqStackLevel );
  227. public:
  228. const CStudioHdr *m_pStudioHdr;
  229. int m_boneMask;
  230. const float *m_flPoseParameter;
  231. bonejob_SPU *m_pBoneJobSPU;
  232. int m_errorFlags; // accpose call failure flags (if so do not run on SPU, could be for a number of reasons, right now => exceeded PQ stack, or an anim uses the local hierarchy path
  233. };
  234. #endif // #if !defined(__SPU__)
  235. //-------------------------------------------------------------------------------------------------------------
  236. // SPU dummy funcs
  237. //-------------------------------------------------------------------------------------------------------------
  238. #define DMATAG_ANIM_SYNC_BONEMAPWEIGHT (DMATAG_ANIM+1)
  239. #define DMATAG_ANIM_SYNC_POSQ (DMATAG_ANIM+2)
  240. FORCEINLINE void *SPUmemcpy_UnalignedGet( void *ls, uint32 ea, uint32_t size )
  241. {
  242. void *aligned_ls;
  243. aligned_ls = (void *)((uint32)ls | (ea & 0xf)); // + 0xf in case ls not 16B aligned
  244. #if defined(__SPU__)
  245. //spu_printf("GET ls:0x%x, ea:0x%x, size:%d\n", (uint32_t)aligned_ls, ea, size);
  246. // SPU
  247. cellDmaUnalignedGet( aligned_ls, ea, size, DMATAG_SYNC, 0, 0 );
  248. cellDmaWaitTagStatusAny( 1 << DMATAG_SYNC );
  249. #else
  250. // PPU
  251. memcpy( aligned_ls, (void *)ea, size );
  252. #endif
  253. return aligned_ls;
  254. }
  255. FORCEINLINE void *SPUmemcpy_UnalignedGet_MustSync( void *ls, uint32 ea, uint32_t size, uint32_t dmatag )
  256. {
  257. void *aligned_ls;
  258. aligned_ls = (void *)((uint32)ls | (ea & 0xf)); // + 0xf in case ls not 16B aligned
  259. #if defined(__SPU__)
  260. //spu_printf("GET ls:0x%x, ea:0x%x, size:%d\n", (uint32_t)aligned_ls, ea, size);
  261. // SPU
  262. cellDmaUnalignedGet( aligned_ls, ea, size, dmatag, 0, 0 );
  263. #else
  264. // PPU
  265. memcpy( aligned_ls, (void *)ea, size );
  266. #endif
  267. return aligned_ls;
  268. }
  269. FORCEINLINE void SPUmemcpy_Sync( uint32_t dmatag )
  270. {
  271. #if defined(__SPU__)
  272. // cellDmaWaitTagStatusAll( 1 << dmatag );
  273. cellDmaWaitTagStatusAll( dmatag );
  274. #endif
  275. }
  276. FORCEINLINE void SPUmemcpy_UnalignedPut( void *ls, uint32 ea, uint32_t size )
  277. {
  278. #if defined(__SPU__)
  279. //spu_printf("PUT ls:0x%x, ea:0x%x, size:%d\n", (uint32_t)ls, ea, size);
  280. // SPU
  281. cellDmaUnalignedPut( ls, ea, size, DMATAG_SYNC, 0, 0 );
  282. cellDmaWaitTagStatusAny( 1 << DMATAG_SYNC );
  283. #else
  284. Assert(((uint32)ls&0xf) == ea&0xf);
  285. // PPU
  286. memcpy( (void *)ea, ls, size );
  287. #endif
  288. }
  289. //=============================================================================//
  290. //
  291. //
  292. //
  293. //
  294. //
  295. //=============================================================================//
  296. #endif