tsMeshIntrinsics.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "ts/tsMesh.h"
  23. #include "ts/tsMeshIntrinsics.h"
  24. #include "ts/arch/tsMeshIntrinsics.arch.h"
  25. #include "core/module.h"
  26. void (*zero_vert_normal_bulk)(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride) = NULL;
  27. void (*m_matF_x_BatchedVertWeightList)(const MatrixF &mat, const dsize_t count, const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch, U8 * const __restrict outPtr, const dsize_t outStride) = NULL;
  28. //------------------------------------------------------------------------------
  29. // Default C++ Implementations (pretty slow)
  30. //------------------------------------------------------------------------------
  31. void zero_vert_normal_bulk_C(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride)
  32. {
  33. register char *outData = reinterpret_cast<char *>(outPtr);
  34. // TODO: Try prefetch w/ ptr de-reference
  35. for(register S32 i = 0; i < count; i++)
  36. {
  37. TSMesh::__TSMeshVertexBase *outElem = reinterpret_cast<TSMesh::__TSMeshVertexBase *>(outData);
  38. outElem->_vert.zero();
  39. outElem->_normal.zero();
  40. outData += outStride;
  41. }
  42. }
  43. //------------------------------------------------------------------------------
  44. void m_matF_x_BatchedVertWeightList_C(const MatrixF &mat,
  45. const dsize_t count,
  46. const TSSkinMesh::BatchData::BatchedVertWeight * __restrict batch,
  47. U8 * const __restrict outPtr,
  48. const dsize_t outStride)
  49. {
  50. const register MatrixF m = mat;
  51. register Point3F tempPt;
  52. register Point3F tempNrm;
  53. for(register S32 i = 0; i < count; i++)
  54. {
  55. const TSSkinMesh::BatchData::BatchedVertWeight &inElem = batch[i];
  56. TSMesh::__TSMeshVertexBase *outElem = reinterpret_cast<TSMesh::__TSMeshVertexBase *>(outPtr + inElem.vidx * outStride);
  57. m.mulP( inElem.vert, &tempPt );
  58. m.mulV( inElem.normal, &tempNrm );
  59. outElem->_vert += ( tempPt * inElem.weight );
  60. outElem->_normal += ( tempNrm * inElem.weight );
  61. }
  62. }
  63. //------------------------------------------------------------------------------
  64. // Initializer.
  65. //------------------------------------------------------------------------------
  66. MODULE_BEGIN( TSMeshIntrinsics )
  67. MODULE_INIT_AFTER( 3D )
  68. MODULE_INIT
  69. {
  70. // Assign defaults (C++ versions)
  71. zero_vert_normal_bulk = zero_vert_normal_bulk_C;
  72. m_matF_x_BatchedVertWeightList = m_matF_x_BatchedVertWeightList_C;
  73. #if defined(TORQUE_OS_XENON)
  74. zero_vert_normal_bulk = zero_vert_normal_bulk_X360;
  75. m_matF_x_BatchedVertWeightList = m_matF_x_BatchedVertWeightList_X360;
  76. #else
  77. // Find the best implementation for the current CPU
  78. if(Platform::SystemInfo.processor.properties & CPU_PROP_SSE)
  79. {
  80. #if defined(TORQUE_CPU_X86)
  81. zero_vert_normal_bulk = zero_vert_normal_bulk_SSE;
  82. m_matF_x_BatchedVertWeightList = m_matF_x_BatchedVertWeightList_SSE;
  83. /* This code still has a bug left in it
  84. #if (_MSC_VER >= 1500)
  85. if(Platform::SystemInfo.processor.properties & CPU_PROP_SSE4_1)
  86. m_matF_x_BatchedVertWeightList = m_matF_x_BatchedVertWeightList_SSE4;
  87. #endif
  88. */
  89. #endif
  90. }
  91. else if(Platform::SystemInfo.processor.properties & CPU_PROP_ALTIVEC)
  92. {
  93. #if !defined(TORQUE_OS_XENON) && defined(TORQUE_CPU_PPC)
  94. zero_vert_normal_bulk = zero_vert_normal_bulk_gccvec;
  95. m_matF_x_BatchedVertWeightList = m_matF_x_BatchedVertWeightList_gccvec;
  96. #endif
  97. }
  98. #endif
  99. }
  100. MODULE_END;