[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 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. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "LinearMath/btScalar.h" |
---|
| 17 | #include "PlatformDefinitions.h" |
---|
| 18 | |
---|
| 19 | #ifdef USE_WIN32_THREADING //platform specific defines are defined in PlatformDefinitions.h |
---|
| 20 | |
---|
| 21 | #ifndef WIN32_THREAD_SUPPORT_H |
---|
| 22 | #define WIN32_THREAD_SUPPORT_H |
---|
| 23 | |
---|
| 24 | #include "LinearMath/btAlignedObjectArray.h" |
---|
| 25 | |
---|
| 26 | #include "btThreadSupportInterface.h" |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory); |
---|
| 30 | typedef void* (*Win32lsMemorySetupFunc)(); |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | ///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication |
---|
| 38 | class Win32ThreadSupport : public btThreadSupportInterface |
---|
| 39 | { |
---|
| 40 | public: |
---|
| 41 | ///placeholder, until libspe2 support is there |
---|
| 42 | struct btSpuStatus |
---|
| 43 | { |
---|
| 44 | uint32_t m_taskId; |
---|
| 45 | uint32_t m_commandId; |
---|
| 46 | uint32_t m_status; |
---|
| 47 | |
---|
| 48 | Win32ThreadFunc m_userThreadFunc; |
---|
| 49 | void* m_userPtr; //for taskDesc etc |
---|
| 50 | void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc |
---|
| 51 | |
---|
| 52 | void* m_threadHandle; //this one is calling 'Win32ThreadFunc' |
---|
| 53 | |
---|
| 54 | void* m_eventStartHandle; |
---|
| 55 | char m_eventStartHandleName[32]; |
---|
| 56 | |
---|
| 57 | void* m_eventCompletetHandle; |
---|
| 58 | char m_eventCompletetHandleName[32]; |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | }; |
---|
| 62 | private: |
---|
| 63 | |
---|
| 64 | btAlignedObjectArray<btSpuStatus> m_activeSpuStatus; |
---|
| 65 | btAlignedObjectArray<void*> m_completeHandles; |
---|
| 66 | |
---|
| 67 | public: |
---|
| 68 | ///Setup and initialize SPU/CELL/Libspe2 |
---|
| 69 | |
---|
| 70 | struct Win32ThreadConstructionInfo |
---|
| 71 | { |
---|
| 72 | Win32ThreadConstructionInfo(char* uniqueName, |
---|
| 73 | Win32ThreadFunc userThreadFunc, |
---|
| 74 | Win32lsMemorySetupFunc lsMemoryFunc, |
---|
| 75 | int numThreads=1, |
---|
| 76 | int threadStackSize=65535 |
---|
| 77 | ) |
---|
| 78 | :m_uniqueName(uniqueName), |
---|
| 79 | m_userThreadFunc(userThreadFunc), |
---|
| 80 | m_lsMemoryFunc(lsMemoryFunc), |
---|
| 81 | m_numThreads(numThreads), |
---|
| 82 | m_threadStackSize(threadStackSize) |
---|
| 83 | { |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | char* m_uniqueName; |
---|
| 88 | Win32ThreadFunc m_userThreadFunc; |
---|
| 89 | Win32lsMemorySetupFunc m_lsMemoryFunc; |
---|
| 90 | int m_numThreads; |
---|
| 91 | int m_threadStackSize; |
---|
| 92 | |
---|
| 93 | }; |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | Win32ThreadSupport(const Win32ThreadConstructionInfo& threadConstructionInfo); |
---|
| 98 | |
---|
| 99 | ///cleanup/shutdown Libspe2 |
---|
| 100 | virtual ~Win32ThreadSupport(); |
---|
| 101 | |
---|
| 102 | void startThreads(const Win32ThreadConstructionInfo& threadInfo); |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | ///send messages to SPUs |
---|
| 106 | virtual void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1); |
---|
| 107 | |
---|
| 108 | ///check for messages from SPUs |
---|
| 109 | virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1); |
---|
| 110 | |
---|
| 111 | ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) |
---|
| 112 | virtual void startSPU(); |
---|
| 113 | |
---|
| 114 | ///tell the task scheduler we are done with the SPU tasks |
---|
| 115 | virtual void stopSPU(); |
---|
| 116 | |
---|
| 117 | virtual void setNumTasks(int numTasks) |
---|
| 118 | { |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | #endif //WIN32_THREAD_SUPPORT_H |
---|
| 124 | |
---|
| 125 | #endif //USE_WIN32_THREADING |
---|