Synchronize changes from branches/GpuClothAMD to trunk

Main improvements are: GPU cloth collision detection against a capsule shape
,OpenCL-OpenGL interoperability (keeping data buffers on GPU), and bug fixes
Thanks to Lee Howes
This commit is contained in:
erwin.coumans
2011-02-27 09:07:07 +00:00
parent ec1bd45f4f
commit d52f58edd8
37 changed files with 3267 additions and 2481 deletions

View File

@@ -13,6 +13,8 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef CAP_H
#define CAP_H
class cap
{
@@ -35,7 +37,7 @@ class cap
void set_collision_object(btCollisionObject* co)
{
collisionObject = co;
collisionObject = co;
}
void set_collision_shape(btCollisionShape* cs)
@@ -56,12 +58,20 @@ class cap
void destroy()
{
SAFE_RELEASE( g_pIndexBuffer );
SAFE_RELEASE( pVB[0] );
SAFE_RELEASE( texture2D );
SAFE_RELEASE( texture2D_view );
}
void draw(void)
{
if (!collisionObject)
return;
ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
D3DXMATRIX mWorldViewProjection;
@@ -113,6 +123,7 @@ class cap
btTransform trans = collisionObject->getWorldTransform();
@@ -204,86 +215,84 @@ class cap
vertex_struct *vertices = new vertex_struct[width*height];
btCapsuleShape* cs = static_cast<btCapsuleShape*>(collisionShape);
float radius = cs->getRadius();
float halfHeight = cs->getHalfHeight();
if (top)
if (cs)
{
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
float X = (x/((float)(width-1)))*3.14159;
float Y = (y/((float)(height-1)))*3.14159;
float z_coord = radius*cos(X)*sin(Y);
float y_coord = radius*sin(X)*sin(Y) + halfHeight;
float x_coord = radius*cos(Y);
vertices[y*width+x].Pos = D3DXVECTOR3(x_coord, y_coord, z_coord);
vertices[y*width+x].Normal = D3DXVECTOR3(x_coord,y_coord-halfHeight,z_coord);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
float radius = cs->getRadius();
float halfHeight = cs->getHalfHeight();
}
else
{
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
float X = (x/((float)(width-1)))*3.14159;
float Y = (y/((float)(height-1)))*3.14159;
float z_coord = radius*cos(X)*sin(Y);
float y_coord = -radius*sin(X)*sin(Y) - halfHeight;
float x_coord = radius*cos(Y);
vertices[y*width+x].Pos = D3DXVECTOR3(x_coord, y_coord, z_coord);
vertices[y*width+x].Normal = D3DXVECTOR3(x_coord,y_coord+halfHeight,z_coord);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
}
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
HRESULT hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &pVB[0]);
//What is this vertex stride thing all about?
Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 );
Offsets[0] = 0;
unsigned int* indices = new unsigned int[width*3*2+2 + height*width*3*2];
for(int y = 0; y < height-1; y++)
{
for(int x = 0; x < width-1; x++)
if (top)
{
indices[x*3*2 + y*width*3*2] = x + y*width;
indices[x*3*2+1 + y*width*3*2] = x+1 + y*width;
indices[x*3*2+2 + y*width*3*2] = x+width + y*width;
indices[x*3*2 + 3 + y*width*3*2] = x + 1 + y*width;
indices[x*3*2 + 4 + y*width*3*2] = x+(width+1) + y*width;
indices[x*3*2 + 5 + y*width*3*2] = x+width + y*width;
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
float X = (x/((float)(width-1)))*3.14159;
float Y = (y/((float)(height-1)))*3.14159;
float z_coord = radius*cos(X)*sin(Y);
float y_coord = radius*sin(X)*sin(Y) + halfHeight;
float x_coord = radius*cos(Y);
vertices[y*width+x].Pos = D3DXVECTOR3(x_coord, y_coord, z_coord);
vertices[y*width+x].Normal = D3DXVECTOR3(x_coord,y_coord-halfHeight,z_coord);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
} else {
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
float X = (x/((float)(width-1)))*3.14159;
float Y = (y/((float)(height-1)))*3.14159;
float z_coord = radius*cos(X)*sin(Y);
float y_coord = -radius*sin(X)*sin(Y) - halfHeight;
float x_coord = radius*cos(Y);
vertices[y*width+x].Pos = D3DXVECTOR3(x_coord, y_coord, z_coord);
vertices[y*width+x].Normal = D3DXVECTOR3(x_coord,y_coord+halfHeight,z_coord);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
}
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
HRESULT hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &pVB[0]);
//What is this vertex stride thing all about?
Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 );
Offsets[0] = 0;
unsigned int* indices = new unsigned int[width*3*2+2 + height*width*3*2];
for(int y = 0; y < height-1; y++)
{
for(int x = 0; x < width-1; x++)
{
indices[x*3*2 + y*width*3*2] = x + y*width;
indices[x*3*2+1 + y*width*3*2] = x+1 + y*width;
indices[x*3*2+2 + y*width*3*2] = x+width + y*width;
indices[x*3*2 + 3 + y*width*3*2] = x + 1 + y*width;
indices[x*3*2 + 4 + y*width*3*2] = x+(width+1) + y*width;
indices[x*3*2 + 5 + y*width*3*2] = x+width + y*width;
}
}
bufferDesc.ByteWidth = sizeof(unsigned int)*(width*3*2+2 + height*width*3*2);
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
InitData.pSysMem = indices;
hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &g_pIndexBuffer);
hr = hr;
}
bufferDesc.ByteWidth = sizeof(unsigned int)*(width*3*2+2 + height*width*3*2);
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
InitData.pSysMem = indices;
hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &g_pIndexBuffer);
hr = hr;
}
};
#endif CAP_H

View File

@@ -13,6 +13,8 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef CLOTH_H
#define CLOTH_H
#include <fstream>
#include <iostream>
@@ -304,3 +306,6 @@ public:
}
};
#endif //CLOTH_H

View File

@@ -38,15 +38,18 @@ class btDX11SIMDAwareSoftBodySolver;
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#define USE_SIMDAWARE_SOLVER
//#define USE_GPU_SOLVER
#define USE_GPU_SOLVER
#define USE_GPU_COPY
const int numFlags = 5;
const int clothWidth = 40;
const int clothHeight = 60;//60;
const int clothHeight = 60;
float _windAngle = 1.0;//0.4;
float _windStrength = 15;
//#define TABLETEST
#include <fstream>
#include <cmath>
@@ -171,21 +174,20 @@ struct vertex_struct
#include "capsule.h"
#include "cap.h"
#include "cylinder.h"
#include "cloth.h"
//#include "capsule.h"
//cylinder cyl_1;
//cap cap_1;
btRigidBody *capCollider;
capsule my_capsule;
btAlignedObjectArray<piece_of_cloth> cloths;
//capsule my_capsule;
//////////////////////////////////////////
// Bullet globals
@@ -205,6 +207,8 @@ btCPUSoftBodySolver *g_cpuSolver = NULL;
btDX11SoftBodySolver *g_dx11Solver = NULL;
btDX11SIMDAwareSoftBodySolver *g_dx11SIMDSolver = NULL;
btSoftBodySolverOutput *g_softBodyOutput = NULL;
btSoftBodySolver *g_solver = NULL;
// End bullet globals
@@ -359,13 +363,23 @@ void createFlag( int width, int height, btAlignedObjectArray<btSoftBody *> &flag
defaultRotate[0] = btVector3(cos(rotateAngleRoundZ), sin(rotateAngleRoundZ), 0.f);
defaultRotate[1] = btVector3(-sin(rotateAngleRoundZ), cos(rotateAngleRoundZ), 0.f);
defaultRotate[2] = btVector3(0.f, 0.f, 1.f);
//btMatrix3x3 defaultRotateAndScale( (defaultRotateX*defaultRotate) );
#ifdef TABLETEST
btMatrix3x3 defaultRotateX;
rotateAngleRoundX = 3.141592654/2;
defaultRotateX[0] = btVector3(1.f, 0.f, 0.f);
defaultRotateX[1] = btVector3( 0.f, cos(rotateAngleRoundX), sin(rotateAngleRoundX));
defaultRotateX[2] = btVector3(0.f, -sin(rotateAngleRoundX), cos(rotateAngleRoundX));
btMatrix3x3 defaultRotateAndScale( (defaultRotateX) );
#else
btMatrix3x3 defaultRotateX;
defaultRotateX[0] = btVector3(1.f, 0.f, 0.f);
defaultRotateX[1] = btVector3( 0.f, cos(rotateAngleRoundX), sin(rotateAngleRoundX));
defaultRotateX[2] = btVector3(0.f, -sin(rotateAngleRoundX), cos(rotateAngleRoundX));
//btMatrix3x3 defaultRotateAndScale( (defaultRotateX*defaultRotate) );
btMatrix3x3 defaultRotateAndScale( (defaultRotateX) );
#endif
// Construct the sequence flags applying a slightly different translation to each one to arrange them
@@ -387,10 +401,12 @@ void createFlag( int width, int height, btAlignedObjectArray<btSoftBody *> &flag
softBody->setMass(i, 10.f/mesh.m_numVertices);
}
#ifndef TABLETEST
// Set the fixed points
softBody->setMass((height-1)*(width), 0.f);
softBody->setMass((height-1)*(width) + width - 1, 0.f);
softBody->setMass((height-1)*width + width/2, 0.f);
#endif
softBody->m_cfg.collisions = btSoftBody::fCollision::CL_SS+btSoftBody::fCollision::CL_RS;
softBody->m_cfg.kLF = 0.0005f;
@@ -401,7 +417,7 @@ void createFlag( int width, int height, btAlignedObjectArray<btSoftBody *> &flag
flags.push_back( softBody );
softBody->transform( transform );
softBody->setFriction( 0.8f );
m_dynamicsWorld->addSoftBody( softBody );
}
@@ -437,11 +453,15 @@ void updatePhysicsWorld()
cloth->setWindVelocity( btVector3(xCoordinate, 0, zCoordinate) );
}
}
#ifndef TABLETEST
if (capCollider)
{
btVector3 origin( capCollider->getWorldTransform().getOrigin() );
origin.setZ( origin.getZ() + 0.01 );
capCollider->getWorldTransform().setOrigin( origin );
}
#endif
//btVector3 origin( capCollider->getWorldTransform().getOrigin() );
//origin.setX( origin.getX() + 0.05 );
//capCollider->getWorldTransform().setOrigin( origin );
counter++;
}
@@ -452,13 +472,25 @@ void initBullet(void)
#ifdef USE_GPU_SOLVER
g_dx11Solver = new btDX11SoftBodySolver( g_pd3dDevice, DXUTGetD3D11DeviceContext() );
g_solver = g_dx11Solver;
#ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputDXtoDX( g_pd3dDevice, DXUTGetD3D11DeviceContext() );
#else // #ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputDXtoCPU;
#endif // #ifdef USE_GPU_COPY
#else
#ifdef USE_SIMDAWARE_SOLVER
g_dx11SIMDSolver = new btDX11SIMDAwareSoftBodySolver( g_pd3dDevice, DXUTGetD3D11DeviceContext() );
g_solver = g_dx11SIMDSolver;
g_softBodyOutput = new btSoftBodySolverOutputDXtoCPU;
#ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputDXtoDX( g_pd3dDevice, DXUTGetD3D11DeviceContext() );
#else // #ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputDXtoCPU;
#endif // #ifdef USE_GPU_COPY
#else
g_cpuSolver = new btCPUSoftBodySolver;
g_solver = g_cpuSolver;
g_softBodyOutput = new btSoftBodySolverOutputCPUtoCPU;
//g_defaultSolver = new btDefaultSoftBodySolver;
//g_solver = g_defaultSolver;
#endif
@@ -519,7 +551,8 @@ void initBullet(void)
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btCollisionShape *capsuleShape = new btCapsuleShape(5, 30);
btCollisionShape *capsuleShape = new btCapsuleShape(5, 10);
capsuleShape->setMargin( 0.5 );
@@ -532,11 +565,21 @@ void initBullet(void)
m_collisionShapes.push_back(capsuleShape);
btTransform capsuleTransform;
capsuleTransform.setIdentity();
capsuleTransform.setOrigin(btVector3(0, 10, 0));
#ifdef TABLETEST
capsuleTransform.setOrigin(btVector3(0, 10, -11));
const btScalar pi = 3.141592654;
capsuleTransform.setRotation(btQuaternion(0, 0, pi/2));
#else
capsuleTransform.setOrigin(btVector3(0, 20, -10));
const btScalar pi = 3.141592654;
//capsuleTransform.setRotation(btQuaternion(0, 0, pi/2));
capsuleTransform.setRotation(btQuaternion(0, 0, 0));
#endif
btDefaultMotionState* myMotionState = new btDefaultMotionState(capsuleTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,capsuleShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setFriction( 0.8f );
my_capsule.set_collision_object(body);
m_dynamicsWorld->addRigidBody(body);
@@ -644,6 +687,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode ( _CRT_ERROR, _CRTDBG_MODE_DEBUG);
#endif
// DXUT will create and use the best device (either D3D9 or D3D11)
@@ -694,10 +738,10 @@ void InitApp()
g_SampleUI.Init( &g_DialogResourceManager );
g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
//restart is broken, @todo: fix
// g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 23 );
// g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += 26, 170, 23, VK_F3 );
// g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 26, 170, 23, VK_F2 );
g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 23 );
g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += 26, 170, 23, VK_F3 );
g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 26, 170, 23, VK_F2 );
g_HUD.AddButton( IDC_PAUSE, L"Pause", 0, iY += 26, 170, 23 );
g_HUD.AddButton( IDC_WIREFRAME, L"Wire frame", 0, iY += 26, 170, 23 );
@@ -1020,8 +1064,8 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
// Setup the camera's view parameters
D3DXVECTOR3 vecEye( 30.0f, -10.0f, -80.0f );
D3DXVECTOR3 vecAt ( 0.0f, 20.0f, -0.0f );
D3DXVECTOR3 vecEye( 0.0f, 0.0f, -100.0f );
D3DXVECTOR3 vecAt ( 0.0f, 0.0f, -0.0f );
g_Camera.SetViewParams( &vecEye, &vecAt );
@@ -1035,25 +1079,12 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
initBullet();
//my_capsule.create_buffers(50,40);
std::wstring flagTexsName[] = {
L"atiFlag.bmp",
std::wstring flagTexs[] = {
L"amdFlag.bmp",
L"atiFlag.bmp",
};
int numFlagTexs = 2;
WCHAR flagTexs[2][MAX_PATH];
HRESULT res = DXUTFindDXSDKMediaFileCch(flagTexs[0],MAX_PATH, flagTexsName[0].c_str());
res = DXUTFindDXSDKMediaFileCch(flagTexs[1],MAX_PATH, flagTexsName[1].c_str());
for( int flagIndex = 0; flagIndex < numFlags; ++flagIndex )
{
cloths[flagIndex].create_texture(flagTexs[flagIndex % numFlagTexs]);
@@ -1062,12 +1093,10 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA
cloths[flagIndex].z_offset = 0;
}
//cap_1.create_texture();
//cap_1.x_offset = 0;
//cap_1.y_offset = 0;
//cap_1.z_offset = 0;
//my_capsule.create_texture();
my_capsule.create_buffers(50,40);
my_capsule.create_texture();
//Turn off backface culling
D3D11_RASTERIZER_DESC rsDesc;
@@ -1142,10 +1171,7 @@ HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapCha
}
#ifndef BT_NO_PROFILE
btClock m_clock;
#endif //BT_NO_PROFILE
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
@@ -1157,12 +1183,8 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext*
//float ms = getDeltaTimeMicroseconds();
#ifndef BT_NO_PROFILE
btScalar dt = (btScalar)m_clock.getTimeMicroseconds();
m_clock.reset();
#else
btScalar dt = 1000000.f/60.f;
#endif //BT_NO_PROFILE
///step the simulation
if (m_dynamicsWorld && !paused)
@@ -1198,12 +1220,11 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext*
for( int flagIndex = 0; flagIndex < m_flags.size(); ++flagIndex )
{
g_solver->copySoftBodyToVertexBuffer( m_flags[flagIndex], cloths[flagIndex].m_vertexBufferDescriptor );
g_softBodyOutput->copySoftBodyToVertexBuffer( m_flags[flagIndex], cloths[flagIndex].m_vertexBufferDescriptor );
cloths[flagIndex].draw();
}
//my_capsule.draw();
//cap_1.draw();
my_capsule.draw();
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
@@ -1265,6 +1286,8 @@ void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
cloths[flagIndex].destroy();
}
my_capsule.destroy();
// Shouldn't need to delete this as it's just a soft body and will be deleted later by the collision object cleanup.
//for( int flagIndex = 0; flagIndex < m_flags.size(); ++flagIndex )
//{
@@ -1280,6 +1303,8 @@ void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
delete g_dx11Solver;
if( g_dx11SIMDSolver )
delete g_dx11SIMDSolver;
if( g_softBodyOutput )
delete g_softBodyOutput;
for(int i=0; i< m_collisionShapes.size(); i++)

View File

@@ -13,6 +13,8 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef CYLINDER_H
#define CYLINDER_H
class cylinder
{
@@ -48,7 +50,15 @@ class cylinder
collisionShape = cs;
}
void destroy()
{
SAFE_RELEASE( g_pIndexBuffer );
SAFE_RELEASE( pVB[0] );
SAFE_RELEASE( texture2D );
SAFE_RELEASE( texture2D_view );
}
void create_texture(void)
{
@@ -58,13 +68,14 @@ class cylinder
loadInfo.Format = DXGI_FORMAT_BC1_UNORM;
HRESULT hr = D3DX11CreateShaderResourceViewFromFile(g_pd3dDevice, L"texture.bmp", &loadInfo, NULL, &texture2D_view, NULL);
hr = hr;
}
void draw(void)
{
if (!collisionObject)
return;
ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
D3DXMATRIX mWorldViewProjection;
@@ -204,79 +215,83 @@ class cylinder
vertex_struct *vertices = new vertex_struct[width*height];
btCapsuleShape* cs = static_cast<btCapsuleShape*>(collisionShape);
float radius = cs->getRadius();
float halfHeight = cs->getHalfHeight();
for(int y = 0; y < height; y++)
if (cs)
{
for(int x = 0; x < width; x++)
float radius = cs->getRadius();
float halfHeight = cs->getHalfHeight();
for(int y = 0; y < height; y++)
{
double coord_2 = sin(2.2*3.141159*y/(float)height)*radius;
double coord_1 = cos(2.2*3.141159*y/(float)height)*radius;
//double coord_2 = (y/((float)(height-1)))*1000;
//coord = sin(y/);
for(int x = 0; x < width; x++)
{
double coord_2 = sin(2.2*3.141159*y/(float)height)*radius;
double coord_1 = cos(2.2*3.141159*y/(float)height)*radius;
//double coord_2 = (y/((float)(height-1)))*1000;
//coord = sin(y/);
vertices[y*width+x].Pos = D3DXVECTOR3(coord_1, ((x/((float)(width-1)))-.5)*halfHeight*2, coord_2);
vertices[y*width+x].Normal = D3DXVECTOR3(coord_1,0,coord_2);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
vertices[y*width+x].Pos = D3DXVECTOR3(coord_1, ((x/((float)(width-1)))-.5)*halfHeight*2, coord_2);
vertices[y*width+x].Normal = D3DXVECTOR3(coord_1,0,coord_2);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
}
/*
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
/*
for(int y = 0; y < height; y++)
{
double coord = sin(x/5.0)*50;
//coord = sin(y/);
for(int x = 0; x < width; x++)
{
double coord = sin(x/5.0)*50;
//coord = sin(y/);
vertices[y*width+x].Pos = D3DXVECTOR3( (x/((float)(width-1)))*1000, coord, (y/((float)(height-1)))*1000);
vertices[y*width+x].Normal = D3DXVECTOR3(1,0,0);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
vertices[y*width+x].Pos = D3DXVECTOR3( (x/((float)(width-1)))*1000, coord, (y/((float)(height-1)))*1000);
vertices[y*width+x].Normal = D3DXVECTOR3(1,0,0);
vertices[y*width+x].Texcoord = D3DXVECTOR2(x/( (float)(width-1)), y/((float)(height-1)));
}
}
}
*/
*/
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
D3D11_SUBRESOURCE_DATA InitData;
InitData.pSysMem = vertices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;
HRESULT hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &pVB[0]);
//What is this vertex stride thing all about?
Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 );
Offsets[0] = 0;
HRESULT hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &pVB[0]);
//What is this vertex stride thing all about?
Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 );
Offsets[0] = 0;
//unsigned int indices[] = {0,1,2, 1,3,2};
unsigned int* indices = new unsigned int[width*3*2+2 + height*width*3*2];
//unsigned int indices[] = {0,1,2, 1,3,2};
unsigned int* indices = new unsigned int[width*3*2+2 + height*width*3*2];
for(int y = 0; y < height-1; y++)
{
for(int x = 0; x < width-1; x++)
for(int y = 0; y < height-1; y++)
{
indices[x*3*2 + y*width*3*2] = x + y*width;
indices[x*3*2+1 + y*width*3*2] = x+1 + y*width;
indices[x*3*2+2 + y*width*3*2] = x+width + y*width;
for(int x = 0; x < width-1; x++)
{
indices[x*3*2 + y*width*3*2] = x + y*width;
indices[x*3*2+1 + y*width*3*2] = x+1 + y*width;
indices[x*3*2+2 + y*width*3*2] = x+width + y*width;
indices[x*3*2 + 3 + y*width*3*2] = x + 1 + y*width;
indices[x*3*2 + 4 + y*width*3*2] = x+(width+1) + y*width;
indices[x*3*2 + 5 + y*width*3*2] = x+width + y*width;
indices[x*3*2 + 3 + y*width*3*2] = x + 1 + y*width;
indices[x*3*2 + 4 + y*width*3*2] = x+(width+1) + y*width;
indices[x*3*2 + 5 + y*width*3*2] = x+width + y*width;
}
}
bufferDesc.ByteWidth = sizeof(unsigned int)*(width*3*2+2 + height*width*3*2);
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
InitData.pSysMem = indices;
hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &g_pIndexBuffer);
hr = hr;
}
bufferDesc.ByteWidth = sizeof(unsigned int)*(width*3*2+2 + height*width*3*2);
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
InitData.pSysMem = indices;
hr = g_pd3dDevice->CreateBuffer(&bufferDesc, &InitData, &g_pIndexBuffer);
hr = hr;
}
};
#endif CYLINDER_H

View File

@@ -42,12 +42,14 @@ IF (USE_GLUT)
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
# ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL/GLDebugDrawer.cpp
../gl_win.cpp
../clstuff.cpp
../bmpLoader.cpp
../bmpLoader.h
../clstuff.h
../gl_win.h
../cloth.h
)
ELSE (USE_GLUT)

View File

@@ -17,12 +17,22 @@ subject to the following restrictions:
#include <GL/glew.h>
#endif
#ifndef USE_MINICL
#define USE_SIMDAWARE_SOLVER
#define USE_GPU_SOLVER
#define USE_GPU_COPY
#endif //USE_MINICL
#include "clstuff.h"
#include "gl_win.h"
#include "cloth.h"
#define USE_GPU_SOLVER
#include "../OpenGL/GLDebugDrawer.h"
GLDebugDrawer debugDraw;
const int numFlags = 5;
const int clothWidth = 40;
@@ -32,8 +42,8 @@ float _windStrength = 15;
#include <iostream>
using namespace std;
@@ -44,6 +54,13 @@ using namespace std;
#include "vectormath/vmInclude.h"
#include "BulletMultiThreaded/GpuSoftBodySolvers/CPU/btSoftBodySolver_CPU.h"
#include "BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.h"
#include "BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.h"
#include "BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolverVertexBuffer_OpenGL.h"
#include "BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolverOutputCLtoGL.h"
btRigidBody *capCollider;
using Vectormath::Aos::Vector3;
@@ -56,6 +73,8 @@ class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
namespace Vectormath
{
namespace Aos
@@ -73,16 +92,19 @@ btDefaultCollisionConfiguration* m_collisionConfiguration;
btCPUSoftBodySolver *g_cpuSolver = NULL;
btOpenCLSoftBodySolver *g_openCLSolver = NULL;
btOpenCLSoftBodySolverSIMDAware *g_openCLSIMDSolver = NULL;
btSoftBodySolver *g_solver = NULL;
btSoftBodySolverOutput *g_softBodyOutput = NULL;
btAlignedObjectArray<btSoftBody *> m_flags;
btSoftRigidDynamicsWorld* m_dynamicsWorld;
btAlignedObjectArray<piece_of_cloth> cloths;
extern cl_context g_cxMainContext;
extern cl_device_id g_cdDevice;
extern cl_command_queue g_cqCommandQue;
extern cl_device_id g_cdDevice;
extern cl_command_queue g_cqCommandQue;
const float flagSpacing = 30.f;
@@ -254,6 +276,7 @@ void createFlag( btSoftBodySolver &solver, int width, int height, btAlignedObjec
btVector3 defaultTranslate(0.f, 20.f, zTranslate);
btTransform transform( defaultRotateAndScale, defaultTranslate );
transform.setOrigin(defaultTranslate);
btSoftBody *softBody = createFromIndexedMesh( vertexArray, mesh.m_numVertices, triangleVertexIndexArray, mesh.m_numTriangles, true );
@@ -268,6 +291,11 @@ void createFlag( btSoftBodySolver &solver, int width, int height, btAlignedObjec
softBody->setMass((height-1)*width + width/2, 0.f);
softBody->m_cfg.collisions = btSoftBody::fCollision::CL_SS+btSoftBody::fCollision::CL_RS;
softBody->m_cfg.kLF = 0.0005f;
softBody->m_cfg.kVCF = 0.001f;
softBody->m_cfg.kDP = 0.f;
softBody->m_cfg.kDG = 0.f;
flags.push_back( softBody );
@@ -283,7 +311,7 @@ void createFlag( btSoftBodySolver &solver, int width, int height, btAlignedObjec
void updatePhysicsWorld()
{
static int counter = 0;
static int counter = 1;
// Change wind velocity a bit based on a frame counter
if( (counter % 400) == 0 )
@@ -317,16 +345,33 @@ void initBullet(void)
{
#ifdef USE_GPU_SOLVER
g_openCLSolver = new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext);
//g_openCLSolver->setDefaultWorkgroupSize(32);
#ifdef USE_SIMDAWARE_SOLVER
g_openCLSIMDSolver = new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue, g_cxMainContext);
g_solver = g_openCLSIMDSolver;
#ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputCLtoGL(g_cqCommandQue, g_cxMainContext);
#else // #ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputCLtoCPU;
#endif // #ifdef USE_GPU_COPY
#else
g_openCLSolver = new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext );
g_solver = g_openCLSolver;
#ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputCLtoGL(g_cqCommandQue, g_cxMainContext);
#else // #ifdef USE_GPU_COPY
g_softBodyOutput = new btSoftBodySolverOutputCLtoCPU;
#endif // #ifdef USE_GPU_COPY
#endif
#else
g_cpuSolver = new btCPUSoftBodySolver;
g_solver = g_cpuSolver;
g_softBodyOutput = new btSoftBodySolverOutputCPUtoCPU;
#endif
m_collisionConfiguration = new btDefaultCollisionConfiguration();
//m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_broadphase = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
@@ -376,6 +421,51 @@ void initBullet(void)
#endif
#if 1
{
btScalar mass(0.);
//btScalar mass(1.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btCollisionShape *capsuleShape = new btCapsuleShape(5, 10);
capsuleShape->setMargin( 0.5 );
btVector3 localInertia(0,0,0);
if (isDynamic)
capsuleShape->calculateLocalInertia(mass,localInertia);
m_collisionShapes.push_back(capsuleShape);
btTransform capsuleTransform;
capsuleTransform.setIdentity();
#ifdef TABLETEST
capsuleTransform.setOrigin(btVector3(0, 10, -11));
const btScalar pi = 3.141592654;
capsuleTransform.setRotation(btQuaternion(0, 0, pi/2));
#else
capsuleTransform.setOrigin(btVector3(0, 0, 0));
const btScalar pi = 3.141592654;
//capsuleTransform.setRotation(btQuaternion(0, 0, pi/2));
capsuleTransform.setRotation(btQuaternion(0, 0, 0));
#endif
btDefaultMotionState* myMotionState = new btDefaultMotionState(capsuleTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,capsuleShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setFriction( 0.8f );
m_dynamicsWorld->addRigidBody(body);
//cap_1.collisionShape = body;
capCollider = body;
}
#endif
#ifdef USE_GPU_SOLVER
createFlag( *g_openCLSolver, clothWidth, clothHeight, m_flags );
#else
@@ -391,7 +481,12 @@ void initBullet(void)
// In this case we have a DX11 output buffer with a vertex at index 0, 8, 16 and so on as well as a normal at 3, 11, 19 etc.
// Copies will be performed GPU-side directly into the output buffer
#ifdef USE_GPU_COPY
GLuint targetVBO = cloths[flagIndex].getVBO();
btOpenGLInteropVertexBufferDescriptor *vertexBufferDescriptor = new btOpenGLInteropVertexBufferDescriptor(g_cqCommandQue, g_cxMainContext, targetVBO, 0, 8, 3, 8);
#else
btCPUVertexBufferDescriptor *vertexBufferDescriptor = new btCPUVertexBufferDescriptor(reinterpret_cast< float* >(cloths[flagIndex].cpu_buffer), 0, 8, 3, 8);
#endif
cloths[flagIndex].m_vertexBufferDescriptor = vertexBufferDescriptor;
}
@@ -402,40 +497,49 @@ void initBullet(void)
#ifndef BT_NO_PROFILE
btClock m_clock;
#endif //BT_NO_PROFILE
void doFlags()
{
//float ms = getDeltaTimeMicroseconds();
#ifndef BT_NO_PROFILE
btScalar dt = (btScalar)m_clock.getTimeMicroseconds();
m_clock.reset();
#else
btScalar dt = 1000000.f/60.f;
#endif
///step the simulation
if( m_dynamicsWorld )
{
m_dynamicsWorld->stepSimulation(dt/1000000.);
static int frameCount = 0;
frameCount++;
if (frameCount==100)
{
m_dynamicsWorld->stepSimulation(1./60.,0);
#ifndef BT_NO_PROFILE
btDefaultSerializer* serializer = new btDefaultSerializer();
m_dynamicsWorld->serialize(serializer);
FILE* file = fopen("testFile.bullet","wb");
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
fclose(file);
CProfileManager::dumpAll();
#endif //BT_NO_PROFILE
}
updatePhysicsWorld();
//m_dynamicsWorld->setDebugDrawer(&debugDraw);
//debugDraw.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
//g_solver->copyBackToSoftBodies();
//m_dynamicsWorld->debugDrawWorld();
}
for( int flagIndex = 0; flagIndex < m_flags.size(); ++flagIndex )
{
g_solver->copySoftBodyToVertexBuffer( m_flags[flagIndex], cloths[flagIndex].m_vertexBufferDescriptor );
g_softBodyOutput->copySoftBodyToVertexBuffer( m_flags[flagIndex], cloths[flagIndex].m_vertexBufferDescriptor );
cloths[flagIndex].draw();
}
}
@@ -444,9 +548,25 @@ void doFlags()
int main(int argc, char *argv[])
{
preInitGL(argc, argv);
glewInit();
#ifdef USE_GPU_COPY
#ifdef _WIN32
HGLRC glCtx = wglGetCurrentContext();
#else //!_WIN32
GLXContext glCtx = glXGetCurrentContext();
#endif //!_WIN32
HDC glDC = wglGetCurrentDC();
initCL(glCtx, glDC);
#else
initCL();
#endif
cloths.resize(numFlags);
for( int flagIndex = 0; flagIndex < numFlags; ++flagIndex )
@@ -457,8 +577,6 @@ int main(int argc, char *argv[])
initBullet();
m_dynamicsWorld->stepSimulation(1./60.,0);
preInitGL(argc, argv);
std::string flagTexs[] = {
"atiFlag.bmp",
"amdFlag.bmp",
@@ -474,6 +592,16 @@ int main(int argc, char *argv[])
}
goGL();
if( g_cpuSolver )
delete g_cpuSolver;
if( g_openCLSolver )
delete g_openCLSolver;
if( g_openCLSIMDSolver )
delete g_openCLSIMDSolver;
if( g_softBodyOutput )
delete g_softBodyOutput;
return 0;
}

View File

@@ -49,6 +49,7 @@ class piece_of_cloth
created = false;
cpu_buffer = NULL;
m_vertexBufferDescriptor = NULL;
clothVBO = 0;
}
bool created;
@@ -63,6 +64,13 @@ class piece_of_cloth
int height;
GLuint m_texture;
GLuint clothVBO;
GLuint getVBO()
{
return clothVBO;
}
void draw(void)
{
@@ -73,22 +81,41 @@ class piece_of_cloth
glColor3f(0.0f, 1.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
int error = 0;
glBindBuffer(GL_ARRAY_BUFFER, clothVBO);
#ifndef USE_GPU_COPY
// Upload data to VBO
// Needed while we're not doing interop
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW);
#endif
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, m_texture);
glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].pos[0])) );
//glNormalPointer( 3, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].normal[0])) );
glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), reinterpret_cast< GLvoid* >(&(cpu_buffer[0].texcoord[0])) );
error = glGetError();
// VBO version
glVertexPointer( 3, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)0 );
error = glGetError();
glNormalPointer( GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)(sizeof(float)*3) );
error = glGetError();
glTexCoordPointer( 2, GL_FLOAT, sizeof(vertex_struct), (const GLvoid *)(sizeof(float)*6) );
error = glGetError();
glDrawElements(GL_TRIANGLES, (height-1 )*(width-1)*3*2, GL_UNSIGNED_INT, indices);
// glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
error = glGetError();
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
error = glGetError();
}
void create_texture(std::string filename)
@@ -221,5 +248,16 @@ class piece_of_cloth
indices[baseIndex+5] = x+width + y*width;
}
}
// Construct VBO
glGenBuffers(1, &clothVBO);
glBindBuffer(GL_ARRAY_BUFFER, clothVBO);
// Do initial upload to ensure that the buffer exists on the device
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_struct)*width*height, &(cpu_buffer[0]), GL_DYNAMIC_DRAW);
int error = glGetError();
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
};

View File

@@ -13,7 +13,7 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include "clstuff.h"
#include "gl_win.h"
@@ -27,9 +27,20 @@ cl_context g_cxMainContext;
cl_device_id g_cdDevice;
cl_command_queue g_cqCommandQue;
void initCL(void)
void initCL( void* glCtx, void* glDC )
{
int ciErrNum = 0;
#if defined(CL_PLATFORM_MINI_CL)
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
#elif defined(CL_PLATFORM_AMD)
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
#elif defined(CL_PLATFORM_NVIDIA)
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
#else
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
#endif
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum);
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_GPU, &ciErrNum);
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_CPU, &ciErrNum);
@@ -37,9 +48,9 @@ void initCL(void)
//#ifdef USE_MINICL
// g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_DEBUG, &ciErrNum);
//#else
g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum);
g_cxMainContext = btOclCommon::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
//#endif
oclCHECKERROR(ciErrNum, CL_SUCCESS);

View File

@@ -4,7 +4,8 @@
void initCL(void);
// OpenCL initialization.
// Takes an optional GL context which, if passed, will create an interop-enabled CL context.
void initCL( void* glContext = 0, void* glDC = 0 );
#endif //__CLSTUFF_HDR__

View File

@@ -1,6 +1,6 @@
#define STRINGIFY(A) #A
#ifdef USE_AMD_OPENCL
//use most up-to-date AMD Radeon drivers to make point sprites work
//see also http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=129431
// vertex shader
const char *vertexShader = STRINGIFY(
uniform float pointRadius; // point size in world space
@@ -14,35 +14,7 @@ void main()
posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
float dist = length(posEye);
gl_PointSize = pointRadius * (pointScale / dist);
// gl_PointSize = 4.0;
//hack around latest AMD graphics cards having troubles with point sprite rendering
//the problem is still unresolved on the 5870 card, and results in a black screen
//see also http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=129431
gl_TexCoord = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
gl_FrontColor = gl_Color;
}
);
#else
// vertex shader
const char *vertexShader = STRINGIFY(
uniform float pointRadius; // point size in world space
uniform float pointScale; // scale to calculate size in pixels
uniform float densityScale;
uniform float densityOffset;
varying vec3 posEye;
void main()
{
// calculate window-space point size
posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
float dist = length(posEye);
gl_PointSize = pointRadius * (pointScale / dist);
// gl_PointSize = 4.0;
//hack around latest AMD graphics cards having troubles with point sprite rendering
//the problem is still unresolved on the 5870 card, and results in a black screen
//see also http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=129431
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
@@ -51,7 +23,7 @@ void main()
}
);
#endif
// pixel shader for rendering points as shaded spheres
const char *spherePixelShader = STRINGIFY(

View File

@@ -29,10 +29,11 @@ static char* spPlatformVendor =
"Unknown Vendor";
#endif
#ifndef CL_PLATFORM_MINI_CL
#include "CL/cl_gl.h"
#endif
cl_context btOclCommon::createContextFromType(cl_device_type deviceType, cl_int* pErrNum)
cl_context btOclCommon::createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC )
{
cl_uint numPlatforms;
cl_platform_id platform = NULL;
@@ -76,12 +77,27 @@ cl_context btOclCommon::createContextFromType(cl_device_type deviceType, cl_int*
* If we could find our platform, use it. Otherwise pass a NULL and get whatever the
* implementation thinks we should be using.
*/
cl_context_properties cps[3] =
cl_context_properties cps[7] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)platform,
0
(cl_context_properties)platform,
0,
0,
0,
0,
0
};
#ifndef CL_PLATFORM_MINI_CL
// If we have a gl context then enable interop
if( pGLContext )
{
cps[2] = CL_GL_CONTEXT_KHR;
cps[3] = (cl_context_properties)pGLContext;
cps[4] = CL_WGL_HDC_KHR;
cps[5] = (cl_context_properties)pGLDC;
}
#endif //CL_PLATFORM_MINI_CL
/* Use NULL for backward compatibility */
cl_context_properties* cprops = (NULL == platform) ? NULL : cps;
cl_context retContext = clCreateContextFromType(cprops,

View File

@@ -34,7 +34,10 @@ subject to the following restrictions:
class btOclCommon
{
public:
static cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum);
// CL Context optionally takes a GL context. This is a generic type because we don't really want this code
// to have to understand GL types.
// It is a HGLRC in _WIN32 or a GLXContext otherwise.
static cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0);
};

View File

@@ -87,7 +87,32 @@ cl_device_id btOclGetMaxFlopsDev(cl_context cxMainContext)
cl_uint clock_frequency;
clGetDeviceInfo(cdDevices[current_device], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(clock_frequency), &clock_frequency, NULL);
max_flops = compute_units * clock_frequency;
cl_device_type device_type;
clGetDeviceInfo(cdDevices[current_device], CL_DEVICE_TYPE, sizeof(device_type), &device_type, NULL);
int SIMDmultiplier = 1;
if( device_type == CL_DEVICE_TYPE_CPU )
{
// For simplicity assume that the CPU is running single SSE instructions
// This will of course depend on the kernel
SIMDmultiplier = 4;
} else if( device_type == CL_DEVICE_TYPE_GPU ) {
// Approximation to GPU compute power
// As long as this beats the CPU number that's the important thing, really
#if defined(CL_PLATFORM_AMD)
// 16 processing elements, 5 ALUs each
SIMDmultiplier = 80;
#elif defined(CL_PLATFORM_NVIDIA)
// 8 processing elements, dual issue - pre-Fermi at least
SIMDmultiplier = 16;
#else
SIMDmultiplier = 1;
#endif
}
max_flops = compute_units * clock_frequency * SIMDmultiplier;
++current_device;
while( current_device < device_count )