updated multi threading shared code on multiple platforms.
This commit is contained in:
@@ -25,15 +25,18 @@
|
|||||||
#else
|
#else
|
||||||
#if defined (__CELLOS_LV2__)
|
#if defined (__CELLOS_LV2__)
|
||||||
///Playstation 3 Cell SDK
|
///Playstation 3 Cell SDK
|
||||||
|
#include <spu_printf.h>
|
||||||
#else
|
#else
|
||||||
//non-windows systems
|
//non-windows systems
|
||||||
|
|
||||||
#define USE_PTHREADS 1
|
#define USE_PTHREADS 1
|
||||||
|
|
||||||
|
|
||||||
#endif //__CELLOS_LV2__
|
#endif //__CELLOS_LV2__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h> //for memcpy
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ subject to the following restrictions:
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
//#ifdef __CELLOS_LV2__???
|
|
||||||
#ifdef USE_WIN32_THREADING
|
#ifdef USE_WIN32_THREADING
|
||||||
Win32ThreadSupport gMidphaseSPU(Win32ThreadSupport::Win32ThreadConstructionInfo("collision",
|
Win32ThreadSupport gMidphaseSPU(Win32ThreadSupport::Win32ThreadConstructionInfo("collision",
|
||||||
processCollisionTask,
|
processCollisionTask,
|
||||||
@@ -44,12 +43,9 @@ Win32ThreadSupport gMidphaseSPU(Win32ThreadSupport::Win32ThreadConstructionInfo(
|
|||||||
MIDPHASE_NUM_WORKUNIT_TASKS));
|
MIDPHASE_NUM_WORKUNIT_TASKS));
|
||||||
#elif defined(USE_LIBSPE2)
|
#elif defined(USE_LIBSPE2)
|
||||||
SpuLibspe2Support gMidphaseSPU(SPU_ELF_COLLISION_DETECTION,MIDPHASE_NUM_WORKUNIT_TASKS);
|
SpuLibspe2Support gMidphaseSPU(SPU_ELF_COLLISION_DETECTION,MIDPHASE_NUM_WORKUNIT_TASKS);
|
||||||
#endif
|
#elif defined (__CELLOS_LV2__)
|
||||||
|
#include "CellSPURSSupport.ppu.h"
|
||||||
#ifdef __CELLOS_LV2__
|
CellSPURSSupport gMidphaseSPU(SPU_ELF_MID_PHASE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct SpuGatherAndProcessPairsTaskDesc
|
|||||||
uint16_t numPages;
|
uint16_t numPages;
|
||||||
uint16_t taskId;
|
uint16_t taskId;
|
||||||
|
|
||||||
struct CollisionTask_LocalStoreMemory* m_lsMemory;
|
// struct CollisionTask_LocalStoreMemory* m_lsMemory;
|
||||||
}
|
}
|
||||||
#ifdef __CELLOS_LV2__
|
#ifdef __CELLOS_LV2__
|
||||||
__attribute__ ((aligned (16)))
|
__attribute__ ((aligned (16)))
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
#ifndef DOUBLE_BUFFER_H
|
#ifndef DOUBLE_BUFFER_H
|
||||||
#define DOUBLE_BUFFER_H
|
#define DOUBLE_BUFFER_H
|
||||||
|
|
||||||
#ifdef __CELLOS_LV2__
|
|
||||||
|
|
||||||
#include <cell/dma.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#else
|
|
||||||
#include "SpuFakeDma.h"
|
#include "SpuFakeDma.h"
|
||||||
#endif //
|
|
||||||
|
|
||||||
|
|
||||||
///DoubleBuffer
|
///DoubleBuffer
|
||||||
|
|||||||
@@ -5,10 +5,23 @@
|
|||||||
|
|
||||||
#include "PlatformDefinitions.h"
|
#include "PlatformDefinitions.h"
|
||||||
|
|
||||||
|
|
||||||
#include <LinearMath/btScalar.h> //for definition of uint64_t,uint32_t
|
#include <LinearMath/btScalar.h> //for definition of uint64_t,uint32_t
|
||||||
|
|
||||||
|
#ifdef __CELLOS_LV2__
|
||||||
|
|
||||||
|
#include <cell/dma.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define DMA_TAG(xfer) (xfer + 1)
|
||||||
|
#define DMA_MASK(xfer) (1 << DMA_TAG(xfer))
|
||||||
|
|
||||||
|
#elif defined (WIN32)
|
||||||
|
|
||||||
#define DMA_TAG(a) (a)
|
#define DMA_TAG(a) (a)
|
||||||
#define DMA_MASK(a) (a)
|
#define DMA_MASK(a) (a)
|
||||||
|
|
||||||
|
|
||||||
/// cellDmaLargeGet Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy)
|
/// cellDmaLargeGet Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy)
|
||||||
int cellDmaLargeGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
int cellDmaLargeGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
||||||
int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
||||||
@@ -16,6 +29,7 @@ int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid,
|
|||||||
int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid);
|
||||||
/// cellDmaWaitTagStatusAll Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy)
|
/// cellDmaWaitTagStatusAll Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy)
|
||||||
void cellDmaWaitTagStatusAll(int ignore);
|
void cellDmaWaitTagStatusAll(int ignore);
|
||||||
|
#endif //WIN32
|
||||||
|
|
||||||
|
|
||||||
#endif //FAKE_DMA_H
|
#endif //FAKE_DMA_H
|
||||||
@@ -23,13 +23,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#include "../SpuDoubleBuffer.h"
|
||||||
#include "SpuDoubleBuffer.h"
|
|
||||||
#else
|
|
||||||
#include "SPU_Common/SpuDefines.h"
|
|
||||||
#include "SPU_Common/SpuDoubleBuffer.h"
|
|
||||||
#include <spu_printf.h>
|
|
||||||
#endif //WIN32
|
|
||||||
|
|
||||||
|
|
||||||
#include "LinearMath/btTransform.h"
|
#include "LinearMath/btTransform.h"
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "SpuGatheringCollisionTask.h"
|
#include "SpuGatheringCollisionTask.h"
|
||||||
|
|
||||||
#include "SpuDoubleBuffer.h"
|
#include "../SpuDoubleBuffer.h"
|
||||||
|
|
||||||
#include "../SpuCollisionTaskProcess.h"
|
#include "../SpuCollisionTaskProcess.h"
|
||||||
#include "../SpuGatheringCollisionDispatcher.h" //for SPU_BATCHSIZE_BROADPHASE_PAIRS
|
#include "../SpuGatheringCollisionDispatcher.h" //for SPU_BATCHSIZE_BROADPHASE_PAIRS
|
||||||
|
|
||||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
||||||
#include "SpuContactManifoldCollisionAlgorithm.h"
|
#include "../SpuContactManifoldCollisionAlgorithm.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||||
#include "SpuContactResult.h"
|
#include "SpuContactResult.h"
|
||||||
#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
|
#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
|
||||||
@@ -78,13 +78,23 @@ struct CollisionTask_LocalStoreMemory
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
void* createCollisionLocalStoreMemory()
|
void* createCollisionLocalStoreMemory()
|
||||||
{
|
{
|
||||||
return new CollisionTask_LocalStoreMemory;
|
return new CollisionTask_LocalStoreMemory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#elif defined(__CELLOS_LV2__)
|
||||||
|
|
||||||
|
CollisionTask_LocalStoreMemory gLocalStoreMemory;
|
||||||
|
void* createCollisionLocalStoreMemory()
|
||||||
|
{
|
||||||
|
return &gLocalStoreMemory;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void ProcessSpuConvexConvexCollision(SpuCollisionPairInput* wuInput, CollisionTask_LocalStoreMemory* lsMemPtr, SpuContactResult& spuContacts);
|
void ProcessSpuConvexConvexCollision(SpuCollisionPairInput* wuInput, CollisionTask_LocalStoreMemory* lsMemPtr, SpuContactResult& spuContacts);
|
||||||
|
|
||||||
|
|
||||||
@@ -654,6 +664,8 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
|
|||||||
CollisionTask_LocalStoreMemory* colMemPtr = (CollisionTask_LocalStoreMemory*)lsMemPtr;
|
CollisionTask_LocalStoreMemory* colMemPtr = (CollisionTask_LocalStoreMemory*)lsMemPtr;
|
||||||
CollisionTask_LocalStoreMemory& lsMem = *(colMemPtr);
|
CollisionTask_LocalStoreMemory& lsMem = *(colMemPtr);
|
||||||
|
|
||||||
|
spu_printf("taskDescPtr=%llx\n",taskDescPtr);
|
||||||
|
|
||||||
SpuContactResult spuContacts;
|
SpuContactResult spuContacts;
|
||||||
|
|
||||||
uint64_t dmaInPtr = taskDesc.inPtr;
|
uint64_t dmaInPtr = taskDesc.inPtr;
|
||||||
@@ -667,6 +679,7 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < numPages; i++)
|
for (unsigned int i = 0; i < numPages; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
// wait for back buffer dma and swap buffers
|
// wait for back buffer dma and swap buffers
|
||||||
unsigned char *inputPtr = lsMem.g_workUnitTaskBuffers.swapBuffers();
|
unsigned char *inputPtr = lsMem.g_workUnitTaskBuffers.swapBuffers();
|
||||||
|
|
||||||
@@ -688,6 +701,8 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
|
|||||||
|
|
||||||
for (j = 0; j < numOnPage; j++)
|
for (j = 0; j < numOnPage; j++)
|
||||||
{
|
{
|
||||||
|
spu_printf("numOnPage=%d\n",numOnPage);
|
||||||
|
|
||||||
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
#ifdef DEBUG_SPU_COLLISION_DETECTION
|
||||||
printMidphaseInput(&wuInputs[j]);
|
printMidphaseInput(&wuInputs[j]);
|
||||||
#endif //DEBUG_SPU_COLLISION_DETECTION
|
#endif //DEBUG_SPU_COLLISION_DETECTION
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ subject to the following restrictions:
|
|||||||
#include "SpuLocalSupport.h"
|
#include "SpuLocalSupport.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(DEBUG) || defined (_DEBUG)
|
#if defined(DEBUG) || defined (_DEBUG)
|
||||||
#include <stdio.h> //for debug printf
|
#include <stdio.h> //for debug printf
|
||||||
#ifdef __SPU__
|
#ifdef __SPU__
|
||||||
|
|||||||
@@ -42,13 +42,19 @@ void* SamplelsMemoryFunc()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_IBM_CELL_SDK
|
||||||
//SpuLibspe2Support gSampleSPU(SPU_ELF_SAMPLE,SAMPLE_NUM_WORKUNIT_TASKS);
|
//SpuLibspe2Support gSampleSPU(SPU_ELF_SAMPLE,SAMPLE_NUM_WORKUNIT_TASKS);
|
||||||
|
#elif defined(WIN32)
|
||||||
Win32ThreadSupport gSampleSPU(Win32ThreadSupport::Win32ThreadConstructionInfo("sample",
|
Win32ThreadSupport gSampleSPU(Win32ThreadSupport::Win32ThreadConstructionInfo("sample",
|
||||||
SampleThreadFunc,
|
SampleThreadFunc,
|
||||||
SamplelsMemoryFunc,
|
SamplelsMemoryFunc,
|
||||||
SAMPLE_NUM_WORKUNIT_TASKS));
|
SAMPLE_NUM_WORKUNIT_TASKS));
|
||||||
|
#elif defined(__CELLOS_LV2__)
|
||||||
|
|
||||||
|
#include "CellSPURSSupport.ppu.h"
|
||||||
|
CellSPURSSupport gSampleSPU(SPU_ELF_SAMPLE);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern char SPU_SAMPLE_ELF_SYMBOL[];
|
extern char SPU_SAMPLE_ELF_SYMBOL[];
|
||||||
@@ -62,10 +68,10 @@ SpuSampleTaskDesc g_spuSampleTaskDesc[SAMPLE_NUM_WORKUNIT_TASKS];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SpuSampleTaskProcess::SpuSampleTaskProcess(Win32ThreadSupport::Win32ThreadConstructionInfo& threadConstructionInfo)
|
SpuSampleTaskProcess::SpuSampleTaskProcess()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < threadConstructionInfo.m_numThreads; i++)
|
for (int i = 0; i < SAMPLE_NUM_WORKUNIT_TASKS; i++)
|
||||||
{
|
{
|
||||||
m_taskBusy[i] = false;
|
m_taskBusy[i] = false;
|
||||||
}
|
}
|
||||||
@@ -74,14 +80,20 @@ SpuSampleTaskProcess::SpuSampleTaskProcess(Win32ThreadSupport::Win32ThreadConstr
|
|||||||
|
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
|
|
||||||
gSampleSPU.startSPUs(threadConstructionInfo);
|
#ifdef WIN32
|
||||||
|
Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo(
|
||||||
|
"sample",SampleThreadFunc,SamplelsMemoryFunc);
|
||||||
|
|
||||||
|
gSampleSPU.startSPU(threadConstructionInfo);
|
||||||
|
#else
|
||||||
|
gSampleSPU.startSPU();
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpuSampleTaskProcess::~SpuSampleTaskProcess()
|
SpuSampleTaskProcess::~SpuSampleTaskProcess()
|
||||||
{
|
{
|
||||||
|
gSampleSPU.stopSPU();
|
||||||
gSampleSPU.stopSPUs();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class SpuSampleTaskProcess
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SpuSampleTaskProcess(Win32ThreadSupport::Win32ThreadConstructionInfo& ci);
|
SpuSampleTaskProcess();
|
||||||
|
|
||||||
~SpuSampleTaskProcess();
|
~SpuSampleTaskProcess();
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ subject to the following restrictions:
|
|||||||
///Setup and initialize SPU/CELL/Libspe2
|
///Setup and initialize SPU/CELL/Libspe2
|
||||||
Win32ThreadSupport::Win32ThreadSupport(Win32ThreadConstructionInfo& threadConstructionInfo)
|
Win32ThreadSupport::Win32ThreadSupport(Win32ThreadConstructionInfo& threadConstructionInfo)
|
||||||
{
|
{
|
||||||
startSPUs(threadConstructionInfo);
|
startSPU(threadConstructionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
///cleanup/shutdown Libspe2
|
///cleanup/shutdown Libspe2
|
||||||
Win32ThreadSupport::~Win32ThreadSupport()
|
Win32ThreadSupport::~Win32ThreadSupport()
|
||||||
{
|
{
|
||||||
stopSPUs();
|
stopSPU();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ void Win32ThreadSupport::waitForResponse(unsigned int *puiArgument0, unsigned in
|
|||||||
|
|
||||||
|
|
||||||
///start the spus group (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
|
///start the spus group (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
|
||||||
void Win32ThreadSupport::startSPUs(Win32ThreadConstructionInfo& threadConstructionInfo)
|
void Win32ThreadSupport::startSPU(Win32ThreadConstructionInfo& threadConstructionInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_activeSpuStatus.resize(threadConstructionInfo.m_numThreads);
|
m_activeSpuStatus.resize(threadConstructionInfo.m_numThreads);
|
||||||
@@ -215,7 +215,7 @@ void Win32ThreadSupport::startSPUs(Win32ThreadConstructionInfo& threadConstructi
|
|||||||
}
|
}
|
||||||
|
|
||||||
///tell the task scheduler we are done with the SPU tasks
|
///tell the task scheduler we are done with the SPU tasks
|
||||||
void Win32ThreadSupport::stopSPUs()
|
void Win32ThreadSupport::stopSPU()
|
||||||
{
|
{
|
||||||
// m_activeSpuStatus.pop_back();
|
// m_activeSpuStatus.pop_back();
|
||||||
// WaitForSingleObject(spuStatus.bla, INFINITE);
|
// WaitForSingleObject(spuStatus.bla, INFINITE);
|
||||||
|
|||||||
@@ -104,10 +104,10 @@ public:
|
|||||||
void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
|
void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
|
||||||
|
|
||||||
///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
|
///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
|
||||||
void startSPUs(Win32ThreadConstructionInfo& threadConstructionInfo);
|
void startSPU(Win32ThreadConstructionInfo& threadConstructionInfo);
|
||||||
|
|
||||||
///tell the task scheduler we are done with the SPU tasks
|
///tell the task scheduler we are done with the SPU tasks
|
||||||
void stopSPUs();
|
void stopSPU();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user