Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "SpuSampleTask.h"
00018 #include "BulletDynamics/Dynamics/btRigidBody.h"
00019 #include "../PlatformDefinitions.h"
00020 #include "../SpuFakeDma.h"
00021 #include "LinearMath/btMinMax.h"
00022
00023 #ifdef __SPU__
00024 #include <spu_printf.h>
00025 #else
00026 #include <stdio.h>
00027 #define spu_printf printf
00028 #endif
00029
00030 #define MAX_NUM_BODIES 8192
00031
00032 struct SampleTask_LocalStoreMemory
00033 {
00034 ATTRIBUTE_ALIGNED16(char gLocalRigidBody [sizeof(btRigidBody)+16]);
00035 ATTRIBUTE_ALIGNED16(void* gPointerArray[MAX_NUM_BODIES]);
00036
00037 };
00038
00039
00040
00041
00042
00043 void processSampleTask(void* userPtr, void* lsMemory)
00044 {
00045
00046
00047 SampleTask_LocalStoreMemory* localMemory = (SampleTask_LocalStoreMemory*)lsMemory;
00048
00049 SpuSampleTaskDesc* taskDescPtr = (SpuSampleTaskDesc*)userPtr;
00050 SpuSampleTaskDesc& taskDesc = *taskDescPtr;
00051
00052 switch (taskDesc.m_sampleCommand)
00053 {
00054 case CMD_SAMPLE_INTEGRATE_BODIES:
00055 {
00056 btTransform predictedTrans;
00057 btCollisionObject** eaPtr = (btCollisionObject**)taskDesc.m_mainMemoryPtr;
00058
00059 int batchSize = taskDesc.m_sampleValue;
00060 if (batchSize>MAX_NUM_BODIES)
00061 {
00062 spu_printf("SPU Error: exceed number of bodies, see MAX_NUM_BODIES in SpuSampleTask.cpp\n");
00063 break;
00064 }
00065 int dmaArraySize = batchSize*sizeof(void*);
00066
00067 uint64_t ppuArrayAddress = reinterpret_cast<uint64_t>(eaPtr);
00068
00069
00070
00071 if (dmaArraySize>=16)
00072 {
00073 cellDmaLargeGet((void*)&localMemory->gPointerArray[0], ppuArrayAddress , dmaArraySize, DMA_TAG(1), 0, 0);
00074 cellDmaWaitTagStatusAll(DMA_MASK(1));
00075 } else
00076 {
00077 stallingUnalignedDmaSmallGet((void*)&localMemory->gPointerArray[0], ppuArrayAddress , dmaArraySize);
00078 }
00079
00080
00081 for ( int i=0;i<batchSize;i++)
00082 {
00084
00085 void* localPtr = &localMemory->gLocalRigidBody[0];
00086 void* shortAdd = localMemory->gPointerArray[i];
00087 uint64_t ppuRigidBodyAddress = reinterpret_cast<uint64_t>(shortAdd);
00088
00089
00090
00091 int dmaBodySize = sizeof(btRigidBody);
00092
00093 cellDmaGet((void*)localPtr, ppuRigidBodyAddress , dmaBodySize, DMA_TAG(1), 0, 0);
00094 cellDmaWaitTagStatusAll(DMA_MASK(1));
00095
00096
00097 float timeStep = 1.f/60.f;
00098
00099 btRigidBody* body = (btRigidBody*) localPtr;
00100 if (body)
00101 {
00102 if (body->isActive() && (!body->isStaticOrKinematicObject()))
00103 {
00104 body->predictIntegratedTransform(timeStep, predictedTrans);
00105 body->proceedToTransform( predictedTrans);
00106 void* ptr = (void*)localPtr;
00107
00108
00109 cellDmaLargePut(ptr, ppuRigidBodyAddress , dmaBodySize, DMA_TAG(1), 0, 0);
00110 cellDmaWaitTagStatusAll(DMA_MASK(1));
00111
00112 }
00113 }
00114
00115 }
00116 break;
00117 }
00118
00119
00120 case CMD_SAMPLE_PREDICT_MOTION_BODIES:
00121 {
00122 btTransform predictedTrans;
00123 btCollisionObject** eaPtr = (btCollisionObject**)taskDesc.m_mainMemoryPtr;
00124
00125 int batchSize = taskDesc.m_sampleValue;
00126 int dmaArraySize = batchSize*sizeof(void*);
00127
00128 if (batchSize>MAX_NUM_BODIES)
00129 {
00130 spu_printf("SPU Error: exceed number of bodies, see MAX_NUM_BODIES in SpuSampleTask.cpp\n");
00131 break;
00132 }
00133
00134 uint64_t ppuArrayAddress = reinterpret_cast<uint64_t>(eaPtr);
00135
00136
00137
00138 if (dmaArraySize>=16)
00139 {
00140 cellDmaLargeGet((void*)&localMemory->gPointerArray[0], ppuArrayAddress , dmaArraySize, DMA_TAG(1), 0, 0);
00141 cellDmaWaitTagStatusAll(DMA_MASK(1));
00142 } else
00143 {
00144 stallingUnalignedDmaSmallGet((void*)&localMemory->gPointerArray[0], ppuArrayAddress , dmaArraySize);
00145 }
00146
00147
00148 for ( int i=0;i<batchSize;i++)
00149 {
00151
00152 void* localPtr = &localMemory->gLocalRigidBody[0];
00153 void* shortAdd = localMemory->gPointerArray[i];
00154 uint64_t ppuRigidBodyAddress = reinterpret_cast<uint64_t>(shortAdd);
00155
00156
00157
00158 int dmaBodySize = sizeof(btRigidBody);
00159
00160 cellDmaGet((void*)localPtr, ppuRigidBodyAddress , dmaBodySize, DMA_TAG(1), 0, 0);
00161 cellDmaWaitTagStatusAll(DMA_MASK(1));
00162
00163
00164 float timeStep = 1.f/60.f;
00165
00166 btRigidBody* body = (btRigidBody*) localPtr;
00167 if (body)
00168 {
00169 if (!body->isStaticOrKinematicObject())
00170 {
00171 if (body->isActive())
00172 {
00173 body->integrateVelocities( timeStep);
00174
00175 body->applyDamping(timeStep);
00176
00177 body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform());
00178
00179 void* ptr = (void*)localPtr;
00180 cellDmaLargePut(ptr, ppuRigidBodyAddress , dmaBodySize, DMA_TAG(1), 0, 0);
00181 cellDmaWaitTagStatusAll(DMA_MASK(1));
00182 }
00183 }
00184 }
00185
00186 }
00187 break;
00188 }
00189
00190
00191
00192 default:
00193 {
00194
00195 }
00196 };
00197 }
00198
00199
00200 #if defined(__CELLOS_LV2__) || defined (LIBSPE2)
00201
00202 ATTRIBUTE_ALIGNED16(SampleTask_LocalStoreMemory gLocalStoreMemory);
00203
00204 void* createSampleLocalStoreMemory()
00205 {
00206 return &gLocalStoreMemory;
00207 }
00208 #else
00209 void* createSampleLocalStoreMemory()
00210 {
00211 return new SampleTask_LocalStoreMemory;
00212 };
00213
00214 #endif