SpuGatheringCollisionTask.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  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. #ifndef SPU_GATHERING_COLLISION_TASK_H
  14. #define SPU_GATHERING_COLLISION_TASK_H
  15. #include "../PlatformDefinitions.h"
  16. //#define DEBUG_SPU_COLLISION_DETECTION 1
  17. ///Task Description for SPU collision detection
  18. struct SpuGatherAndProcessPairsTaskDesc
  19. {
  20. ppu_address_t m_inPairPtr;//m_pairArrayPtr;
  21. //mutex variable
  22. uint32_t m_someMutexVariableInMainMemory;
  23. ppu_address_t m_dispatcher;
  24. uint32_t numOnLastPage;
  25. uint16_t numPages;
  26. uint16_t taskId;
  27. bool m_useEpa;
  28. struct CollisionTask_LocalStoreMemory* m_lsMemory;
  29. }
  30. #if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
  31. __attribute__ ((aligned (128)))
  32. #endif
  33. ;
  34. void processCollisionTask(void* userPtr, void* lsMemory);
  35. void* createCollisionLocalStoreMemory();
  36. void deleteCollisionLocalStoreMemory();
  37. #if defined(USE_LIBSPE2) && defined(__SPU__)
  38. #include "../SpuLibspe2Support.h"
  39. #include <spu_intrinsics.h>
  40. #include <spu_mfcio.h>
  41. #include <SpuFakeDma.h>
  42. //#define DEBUG_LIBSPE2_SPU_TASK
  43. int main(unsigned long long speid, addr64 argp, addr64 envp)
  44. {
  45. printf("SPU: hello \n");
  46. ATTRIBUTE_ALIGNED128(btSpuStatus status);
  47. ATTRIBUTE_ALIGNED16( SpuGatherAndProcessPairsTaskDesc taskDesc ) ;
  48. unsigned int received_message = Spu_Mailbox_Event_Nothing;
  49. bool shutdown = false;
  50. cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
  51. cellDmaWaitTagStatusAll(DMA_MASK(3));
  52. status.m_status = Spu_Status_Free;
  53. status.m_lsMemory.p = createCollisionLocalStoreMemory();
  54. cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
  55. cellDmaWaitTagStatusAll(DMA_MASK(3));
  56. while ( btLikely( !shutdown ) )
  57. {
  58. received_message = spu_read_in_mbox();
  59. if( btLikely( received_message == Spu_Mailbox_Event_Task ))
  60. {
  61. #ifdef DEBUG_LIBSPE2_SPU_TASK
  62. printf("SPU: received Spu_Mailbox_Event_Task\n");
  63. #endif //DEBUG_LIBSPE2_SPU_TASK
  64. // refresh the status
  65. cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
  66. cellDmaWaitTagStatusAll(DMA_MASK(3));
  67. btAssert(status.m_status==Spu_Status_Occupied);
  68. cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuGatherAndProcessPairsTaskDesc), DMA_TAG(3), 0, 0);
  69. cellDmaWaitTagStatusAll(DMA_MASK(3));
  70. #ifdef DEBUG_LIBSPE2_SPU_TASK
  71. printf("SPU:processCollisionTask\n");
  72. #endif //DEBUG_LIBSPE2_SPU_TASK
  73. processCollisionTask((void*)&taskDesc, taskDesc.m_lsMemory);
  74. #ifdef DEBUG_LIBSPE2_SPU_TASK
  75. printf("SPU:finished processCollisionTask\n");
  76. #endif //DEBUG_LIBSPE2_SPU_TASK
  77. }
  78. else
  79. {
  80. #ifdef DEBUG_LIBSPE2_SPU_TASK
  81. printf("SPU: received ShutDown\n");
  82. #endif //DEBUG_LIBSPE2_SPU_TASK
  83. if( btLikely( received_message == Spu_Mailbox_Event_Shutdown ) )
  84. {
  85. shutdown = true;
  86. }
  87. else
  88. {
  89. //printf("SPU - Sth. recieved\n");
  90. }
  91. }
  92. // set to status free and wait for next task
  93. status.m_status = Spu_Status_Free;
  94. cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
  95. cellDmaWaitTagStatusAll(DMA_MASK(3));
  96. }
  97. printf("SPU: shutdown\n");
  98. return 0;
  99. }
  100. #endif // USE_LIBSPE2
  101. #endif //SPU_GATHERING_COLLISION_TASK_H