SequentialThreadSupport.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #include "SequentialThreadSupport.h"
  14. #include "SpuCollisionTaskProcess.h"
  15. #include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
  16. SequentialThreadSupport::SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo)
  17. {
  18. startThreads(threadConstructionInfo);
  19. }
  20. ///cleanup/shutdown Libspe2
  21. SequentialThreadSupport::~SequentialThreadSupport()
  22. {
  23. stopSPU();
  24. }
  25. #include <stdio.h>
  26. ///send messages to SPUs
  27. void SequentialThreadSupport::sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t taskId)
  28. {
  29. switch (uiCommand)
  30. {
  31. case CMD_GATHER_AND_PROCESS_PAIRLIST:
  32. {
  33. btSpuStatus& spuStatus = m_activeSpuStatus[0];
  34. spuStatus.m_userPtr=(void*)uiArgument0;
  35. spuStatus.m_userThreadFunc(spuStatus.m_userPtr,spuStatus.m_lsMemory);
  36. }
  37. break;
  38. default:
  39. {
  40. ///not implemented
  41. btAssert(0 && "Not implemented");
  42. }
  43. };
  44. }
  45. ///check for messages from SPUs
  46. void SequentialThreadSupport::waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1)
  47. {
  48. btAssert(m_activeSpuStatus.size());
  49. btSpuStatus& spuStatus = m_activeSpuStatus[0];
  50. *puiArgument0 = spuStatus.m_taskId;
  51. *puiArgument1 = spuStatus.m_status;
  52. }
  53. void SequentialThreadSupport::startThreads(SequentialThreadConstructionInfo& threadConstructionInfo)
  54. {
  55. m_activeSpuStatus.resize(1);
  56. printf("STS: Not starting any threads\n");
  57. btSpuStatus& spuStatus = m_activeSpuStatus[0];
  58. spuStatus.m_userPtr = 0;
  59. spuStatus.m_taskId = 0;
  60. spuStatus.m_commandId = 0;
  61. spuStatus.m_status = 0;
  62. spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc();
  63. spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc;
  64. printf("STS: Created local store at %p for task %s\n", spuStatus.m_lsMemory, threadConstructionInfo.m_uniqueName);
  65. }
  66. void SequentialThreadSupport::startSPU()
  67. {
  68. }
  69. void SequentialThreadSupport::stopSPU()
  70. {
  71. m_activeSpuStatus.clear();
  72. }
  73. void SequentialThreadSupport::setNumTasks(int numTasks)
  74. {
  75. printf("SequentialThreadSupport::setNumTasks(%d) is not implemented and has no effect\n",numTasks);
  76. }
  77. class btDummyBarrier : public btBarrier
  78. {
  79. private:
  80. public:
  81. btDummyBarrier()
  82. {
  83. }
  84. virtual ~btDummyBarrier()
  85. {
  86. }
  87. void sync()
  88. {
  89. }
  90. virtual void setMaxCount(int n) {}
  91. virtual int getMaxCount() {return 1;}
  92. };
  93. #ifdef WINRT
  94. __declspec(align(16)) class btDummyCriticalSection : public btCriticalSection
  95. #else
  96. class btDummyCriticalSection : public btCriticalSection
  97. #endif
  98. {
  99. public:
  100. btDummyCriticalSection()
  101. {
  102. }
  103. virtual ~btDummyCriticalSection()
  104. {
  105. }
  106. #ifdef WINRT
  107. void* operator new(size_t i)
  108. {
  109. return _aligned_malloc(i, 16);
  110. }
  111. void operator delete(void* p)
  112. {
  113. _aligned_free(p);
  114. }
  115. #endif
  116. unsigned int getSharedParam(int i)
  117. {
  118. btAssert(i>=0&&i<31);
  119. return mCommonBuff[i+1];
  120. }
  121. void setSharedParam(int i,unsigned int p)
  122. {
  123. btAssert(i>=0&&i<31);
  124. mCommonBuff[i+1] = p;
  125. }
  126. void lock()
  127. {
  128. mCommonBuff[0] = 1;
  129. }
  130. void unlock()
  131. {
  132. mCommonBuff[0] = 0;
  133. }
  134. };
  135. btBarrier* SequentialThreadSupport::createBarrier()
  136. {
  137. return new btDummyBarrier();
  138. }
  139. btCriticalSection* SequentialThreadSupport::createCriticalSection()
  140. {
  141. return new btDummyCriticalSection();
  142. }
  143. void SequentialThreadSupport::deleteBarrier(btBarrier* barrier)
  144. {
  145. delete barrier;
  146. }
  147. void SequentialThreadSupport::deleteCriticalSection(btCriticalSection* criticalSection)
  148. {
  149. delete criticalSection;
  150. }