btSoftBodySolverLinkData_OpenCLSIMDAware.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #include "BulletMultiThreaded/GpuSoftBodySolvers/Shared/btSoftBodySolverData.h"
00017 #include "btSoftBodySolverBuffer_OpenCL.h"
00018 
00019 
00020 #ifndef BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H
00021 #define BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H
00022 
00023 
00024 class btSoftBodyLinkDataOpenCLSIMDAware : public btSoftBodyLinkData
00025 {
00026 public:
00027         bool                            m_onGPU;
00028 
00029         cl_command_queue        m_cqCommandQue;
00030 
00031         const int m_wavefrontSize;
00032         const int m_linksPerWorkItem;
00033         const int m_maxLinksPerWavefront;
00034         int m_maxBatchesWithinWave;
00035         int m_maxVerticesWithinWave;
00036         int m_numWavefronts;
00037 
00038         int m_maxVertex;
00039 
00040         struct NumBatchesVerticesPair
00041         {
00042                 int numBatches;
00043                 int numVertices;
00044         };
00045 
00046         btAlignedObjectArray<int>                                                         m_linksPerWavefront;
00047         btAlignedObjectArray<NumBatchesVerticesPair>              m_numBatchesAndVerticesWithinWaves;
00048         btOpenCLBuffer< NumBatchesVerticesPair >                          m_clNumBatchesAndVerticesWithinWaves;
00049 
00050         // All arrays here will contain batches of m_maxLinksPerWavefront links
00051         // ordered by wavefront.
00052         // with either global vertex pairs or local vertex pairs
00053         btAlignedObjectArray< int >                                                       m_wavefrontVerticesGlobalAddresses; // List of global vertices per wavefront
00054         btOpenCLBuffer<int>                                                                       m_clWavefrontVerticesGlobalAddresses;
00055         btAlignedObjectArray< LinkNodePair >                              m_linkVerticesLocalAddresses; // Vertex pair for the link
00056         btOpenCLBuffer<LinkNodePair>                                              m_clLinkVerticesLocalAddresses;
00057         btOpenCLBuffer<float>                                                         m_clLinkStrength;
00058         btOpenCLBuffer<float>                                                             m_clLinksMassLSC;
00059         btOpenCLBuffer<float>                                                             m_clLinksRestLengthSquared;
00060         btOpenCLBuffer<float>                                                             m_clLinksRestLength;
00061         btOpenCLBuffer<float>                                                             m_clLinksMaterialLinearStiffnessCoefficient;
00062 
00063         struct BatchPair
00064         {
00065                 int start;
00066                 int length;
00067 
00068                 BatchPair() :
00069                         start(0),
00070                         length(0)
00071                 {
00072                 }
00073 
00074                 BatchPair( int s, int l ) : 
00075                         start( s ),
00076                         length( l )
00077                 {
00078                 }
00079         };
00080 
00085         btAlignedObjectArray< int >                                                     m_linkAddresses;
00086         
00090         btAlignedObjectArray< BatchPair >               m_wavefrontBatchStartLengths;
00091 
00092         btSoftBodyLinkDataOpenCLSIMDAware(cl_command_queue queue, cl_context ctx);
00093 
00094         virtual ~btSoftBodyLinkDataOpenCLSIMDAware();
00095 
00097         virtual void createLinks( int numLinks );
00098         
00100         virtual void setLinkAt( 
00101                 const LinkDescription &link, 
00102                 int linkIndex );
00103 
00104         virtual bool onAccelerator();
00105 
00106         virtual bool moveToAccelerator();
00107 
00108         virtual bool moveFromAccelerator();
00109 
00116         void generateBatches();
00117 
00118         int getMaxVerticesPerWavefront()
00119         {
00120                 return m_maxVerticesWithinWave;
00121         }
00122 
00123         int getWavefrontSize()
00124         {
00125                 return m_wavefrontSize;
00126         }
00127 
00128         int getLinksPerWorkItem()
00129         {
00130                 return m_linksPerWorkItem;
00131         }
00132 
00133         int getMaxLinksPerWavefront()
00134         {
00135                 return m_maxLinksPerWavefront;
00136         }
00137 
00138         int getMaxBatchesPerWavefront()
00139         {
00140                 return m_maxBatchesWithinWave;
00141         }
00142 
00143         int getNumWavefronts()
00144         {
00145                 return m_numWavefronts;
00146         }
00147 
00148         NumBatchesVerticesPair getNumBatchesAndVerticesWithinWavefront( int wavefront )
00149         {
00150                 return m_numBatchesAndVerticesWithinWaves[wavefront];
00151         }
00152 
00153         int getVertexGlobalAddresses( int vertexIndex )
00154         {
00155                 return m_wavefrontVerticesGlobalAddresses[vertexIndex];
00156         }
00157 
00161         LinkNodePair getVertexPairLocalAddresses( int linkIndex )
00162         {
00163                 return m_linkVerticesLocalAddresses[linkIndex];
00164         }
00165 };
00166 
00167 
00168 
00169 #endif // #ifndef BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H