fix padding issue under Linux (where b3Vector3 is not 16-byte aligned)

w
This commit is contained in:
erwincoumans
2013-05-22 17:46:47 -07:00
parent 9365735a8f
commit ee5195d3e8
7 changed files with 76 additions and 48 deletions

View File

@@ -48,7 +48,7 @@ static void MyResizeCallback( float width, float height)
b3gWindowInterface* window=0; b3gWindowInterface* window=0;
GwenUserInterface* gui = 0; GwenUserInterface* gui = 0;
bool gPause = false; bool gPause = true;
bool gReset = false; bool gReset = false;
enum enum
@@ -68,34 +68,34 @@ int selectedDemo = 0;
GpuDemo::CreateFunc* allDemos[]= GpuDemo::CreateFunc* allDemos[]=
{ {
// ConcaveCompound2Scene::MyCreateFunc, // ConcaveCompound2Scene::MyCreateFunc,
GpuConvexScene::MyCreateFunc,
GpuBoxPlaneScene::MyCreateFunc, GpuBoxPlaneScene::MyCreateFunc,
GpuConvexPlaneScene::MyCreateFunc, GpuConvexPlaneScene::MyCreateFunc,
ConcaveSphereScene::MyCreateFunc, ConcaveSphereScene::MyCreateFunc,
GpuCompoundScene::MyCreateFunc, GpuCompoundScene::MyCreateFunc,
GpuConvexScene::MyCreateFunc,
ConcaveSphereScene::MyCreateFunc, ConcaveSphereScene::MyCreateFunc,
ConcaveScene::MyCreateFunc, ConcaveScene::MyCreateFunc,
ConcaveCompoundScene::MyCreateFunc, ConcaveCompoundScene::MyCreateFunc,
GpuCompoundPlaneScene::MyCreateFunc, GpuCompoundPlaneScene::MyCreateFunc,
GpuSphereScene::MyCreateFunc, GpuSphereScene::MyCreateFunc,
GpuSoftClothDemo::MyCreateFunc, GpuSoftClothDemo::MyCreateFunc,
Bullet2FileDemo::MyCreateFunc, Bullet2FileDemo::MyCreateFunc,
PairBench::MyCreateFunc, PairBench::MyCreateFunc,
//GpuRigidBodyDemo::MyCreateFunc, //GpuRigidBodyDemo::MyCreateFunc,
@@ -106,9 +106,9 @@ GpuDemo::CreateFunc* allDemos[]=
//ParticleDemo::MyCreateFunc, //ParticleDemo::MyCreateFunc,
//GpuCompoundDemo::CreateFunc, //GpuCompoundDemo::CreateFunc,
//EmptyDemo::CreateFunc, //EmptyDemo::CreateFunc,
}; };
@@ -204,7 +204,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRender)
struct sth_stash* stash = 0; struct sth_stash* stash = 0;
int datasize; int datasize;
float sx,sy,dx,dy,lh; float sx,sy,dx,dy,lh;
GLuint texture; GLuint texture;
@@ -392,7 +392,7 @@ extern bool useNewBatchingKernel;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
b3Vector3 test(1,2,3); b3Vector3 test(1,2,3);
test.x = 1; test.x = 1;
test.y = 4; test.y = 4;
@@ -408,10 +408,10 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
args.GetCmdLineArgument("selected_demo",selectedDemo); args.GetCmdLineArgument("selected_demo",selectedDemo);
if (args.CheckCmdLineFlag("new_batching")) if (args.CheckCmdLineFlag("new_batching"))
{ {
useNewBatchingKernel = true; useNewBatchingKernel = true;
@@ -600,7 +600,7 @@ int main(int argc, char* argv[])
ci.m_gui = gui; ci.m_gui = gui;
ci.m_instancingRenderer->init(); ci.m_instancingRenderer->init();
ci.m_instancingRenderer->InitShaders(); ci.m_instancingRenderer->InitShaders();
// render.init(); // render.init();
demo->initPhysics(ci); demo->initPhysics(ci);

View File

@@ -28,8 +28,8 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
index+=createDynamicsObjects(ci); index+=createDynamicsObjects(ci);
m_data->m_rigidBodyPipeline->writeAllInstancesToGpu(); m_data->m_rigidBodyPipeline->writeAllInstancesToGpu();
float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0}; float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0};
//float camPos[4]={1,12.5,1.5,0}; //float camPos[4]={1,12.5,1.5,0};
m_instancingRenderer->setCameraTargetPosition(camPos); m_instancingRenderer->setCameraTargetPosition(camPos);
@@ -44,10 +44,15 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
int GpuConvexScene::createDynamicsObjects(const ConstructionInfo& ci) int GpuConvexScene::createDynamicsObjects(const ConstructionInfo& ci)
{ {
int strideInBytes = 9*sizeof(float); /* int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(barrel_vertices)/strideInBytes; int numVertices = sizeof(barrel_vertices)/strideInBytes;
int numIndices = sizeof(barrel_indices)/sizeof(int); int numIndices = sizeof(barrel_indices)/sizeof(int);
return createDynamicsObjects2(ci,barrel_vertices,numVertices,barrel_indices,numIndices); return createDynamicsObjects2(ci,barrel_vertices,numVertices,barrel_indices,numIndices);
*/
int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int);
return createDynamicsObjects2(ci,cube_vertices,numVertices,cube_indices,numIndices);
} }
int GpuBoxPlaneScene::createDynamicsObjects(const ConstructionInfo& ci) int GpuBoxPlaneScene::createDynamicsObjects(const ConstructionInfo& ci)
@@ -67,20 +72,20 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
int group=1; int group=1;
int mask=1; int mask=1;
int index=0; int index=0;
{ {
b3Vector4 colors[4] = b3Vector4 colors[4] =
{ {
b3Vector4(1,0,0,1), b3Vector4(1,0,0,1),
b3Vector4(0,1,0,1), b3Vector4(0,1,0,1),
b3Vector4(0,1,1,1), b3Vector4(0,1,1,1),
b3Vector4(1,1,0,1), b3Vector4(1,1,0,1),
}; };
int curColor = 0; int curColor = 0;
float scaling[4] = {1,1,1,1}; float scaling[4] = {1,1,1,1};
int prevBody = -1; int prevBody = -1;
@@ -100,17 +105,17 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
//mass=0.f; //mass=0.f;
} }
//b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2); //b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
b3Vector3 position(i*2.2,10+j*2.2,k*2.2); b3Vector3 position(i*2.2,10+j*1.9,k*2.2);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color = colors[curColor]; b3Vector4 color = colors[curColor];
curColor++; curColor++;
curColor&=3; curColor&=3;
b3Vector4 scaling(1,1,1,1); b3Vector4 scaling(1,1,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
if (prevBody>=0) if (prevBody>=0)
{ {
@@ -137,19 +142,19 @@ void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci)
int group=1; int group=1;
int mask=1; int mask=1;
int index=0; int index=0;
{ {
b3Vector4 scaling(400,1,400,1); b3Vector4 scaling(400,1,400,1);
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
b3Vector3 position(0,0,0); b3Vector3 position(0,0,0);
b3Quaternion orn(0,0,0,1); b3Quaternion orn(0,0,0,1);
b3Vector4 color(0,0,1,1); b3Vector4 color(0,0,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false);
} }
} }
@@ -168,9 +173,9 @@ void GpuConvexPlaneScene::createStaticEnvironment(const ConstructionInfo& ci)
int numVertices = sizeof(cube_vertices)/strideInBytes; int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int); int numIndices = sizeof(cube_indices)/sizeof(int);
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false); int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index,false);
} }

View File

@@ -42,13 +42,7 @@
files { projectRootDir .. "btgui/OpenGLWindow/GlewWindows/glew.c"} files { projectRootDir .. "btgui/OpenGLWindow/GlewWindows/glew.c"}
end end
if os.is("Linux") then if os.is("Linux") then
--links{"GLEW"} links{"GLEW"}
defines { "GLEW_STATIC"}
includedirs {
projectRootDir .. "btgui/OpenGLWindow/GlewWindows"
}
files { projectRootDir .. "btgui/OpenGLWindow/GlewWindows/glew.c"}
end end
configuration{} configuration{}
end end

View File

@@ -24,6 +24,7 @@ function stringifyKernel(filenameIn, filenameOut, kernelMethod)
end end
oneline = string.sub(lines,startpos,endpos) oneline = string.sub(lines,startpos,endpos)
oneline = string.gsub(oneline,"\n","") oneline = string.gsub(oneline,"\n","")
oneline = string.gsub(oneline,"\"","\\\"");
oneline = '\"' .. oneline .. '\\n\"' oneline = '\"' .. oneline .. '\\n\"'
oneline = string.gsub(oneline,"\\\\n","") oneline = string.gsub(oneline,"\\\\n","")
oneline = oneline .. "\n" oneline = oneline .. "\n"
@@ -75,4 +76,4 @@ function stringifyKernel(filenameIn, filenameOut, kernelMethod)
stringifyKernel( _OPTIONS["kernelfile"] , _OPTIONS["headerfile"], _OPTIONS["stringname"]) stringifyKernel( _OPTIONS["kernelfile"] , _OPTIONS["headerfile"], _OPTIONS["stringname"])
end end
} }

26
build/stringify_linux.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/RadixSort32Kernels.cl" --headerfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/RadixSort32KernelsCL.h" --stringname="radixSort32KernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/BoundSearchKernels.cl" --headerfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/BoundSearchKernelsCL.h" --stringname="boundSearchKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/PrefixScanKernels.cl" --headerfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/PrefixScanKernelsCL.h" --stringname="prefixScanKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/FillKernels.cl" --headerfile="../src/Bullet3OpenCL/ParallelPrimitives/kernels/FillKernelsCL.h" --stringname="fillKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/BroadphaseCollision/kernels/sap.cl" --headerfile="../src/Bullet3OpenCL/BroadphaseCollision/kernels/sapKernels.h" --stringname="sapCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/BroadphaseCollision/kernels/sapFast.cl" --headerfile="../src/Bullet3OpenCL/BroadphaseCollision/kernels/sapFastKernels.h" --stringname="sapFastCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/sat.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satKernels.h" --stringname="satKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.h" --stringname="satClipKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.h" --stringname="primitiveContactsKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.cl" --headerfile="../src/Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.h" --stringname="bvhTraversalKernelCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/integrateKernel.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/integrateKernel.h" --stringname="integrateKernelCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/updateAabbsKernel.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/updateAabbsKernel.h" --stringname="updateAabbsKernelCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solverSetup.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solverSetup.h" --stringname="solverSetupCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solverSetup2.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solverSetup2.h" --stringname="solverSetup2CL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/batchingKernels.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/batchingKernels.h" --stringname="batchingKernelsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/batchingKernelsNew.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/batchingKernelsNew.h" --stringname="batchingKernelsNewCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solverUtils.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solverUtils.h" --stringname="solverUtilsCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solveContact.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solveContact.h" --stringname="solveContactCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solveFriction.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solveFriction.h" --stringname="solveFrictionCL" stringify

View File

@@ -8,6 +8,8 @@ struct b3GpuFace
b3Vector4 m_plane; b3Vector4 m_plane;
int m_indexOffset; int m_indexOffset;
int m_numIndices; int m_numIndices;
int m_unusedPadding1;
int m_unusedPadding2;
}; };
B3_ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL B3_ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
@@ -61,4 +63,4 @@ B3_ATTRIBUTE_ALIGNED16(struct) b3ConvexPolyhedronCL
}; };
#endif //CONVEX_POLYHEDRON_CL #endif //CONVEX_POLYHEDRON_CL