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_DX11.h" 00018 00019 #ifndef BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H 00020 #define BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H 00021 00022 struct ID3D11Device; 00023 struct ID3D11DeviceContext; 00024 00025 00026 class btSoftBodyLinkDataDX11SIMDAware : public btSoftBodyLinkData 00027 { 00028 public: 00029 bool m_onGPU; 00030 ID3D11Device *m_d3dDevice; 00031 ID3D11DeviceContext *m_d3dDeviceContext; 00032 00033 const int m_wavefrontSize; 00034 const int m_linksPerWorkItem; 00035 const int m_maxLinksPerWavefront; 00036 int m_maxBatchesWithinWave; 00037 int m_maxVerticesWithinWave; 00038 int m_numWavefronts; 00039 00040 int m_maxVertex; 00041 00042 struct NumBatchesVerticesPair 00043 { 00044 int numBatches; 00045 int numVertices; 00046 }; 00047 00048 // Array storing number of links in each wavefront 00049 btAlignedObjectArray<int> m_linksPerWavefront; 00050 btAlignedObjectArray<NumBatchesVerticesPair> m_numBatchesAndVerticesWithinWaves; 00051 btDX11Buffer< NumBatchesVerticesPair > m_dx11NumBatchesAndVerticesWithinWaves; 00052 00053 // All arrays here will contain batches of m_maxLinksPerWavefront links 00054 // ordered by wavefront. 00055 // with either global vertex pairs or local vertex pairs 00056 btAlignedObjectArray< int > m_wavefrontVerticesGlobalAddresses; // List of global vertices per wavefront 00057 btDX11Buffer<int> m_dx11WavefrontVerticesGlobalAddresses; 00058 btAlignedObjectArray< LinkNodePair > m_linkVerticesLocalAddresses; // Vertex pair for the link 00059 btDX11Buffer<LinkNodePair> m_dx11LinkVerticesLocalAddresses; 00060 btDX11Buffer<float> m_dx11LinkStrength; 00061 btDX11Buffer<float> m_dx11LinksMassLSC; 00062 btDX11Buffer<float> m_dx11LinksRestLengthSquared; 00063 btDX11Buffer<float> m_dx11LinksRestLength; 00064 btDX11Buffer<float> m_dx11LinksMaterialLinearStiffnessCoefficient; 00065 00066 struct BatchPair 00067 { 00068 int start; 00069 int length; 00070 00071 BatchPair() : 00072 start(0), 00073 length(0) 00074 { 00075 } 00076 00077 BatchPair( int s, int l ) : 00078 start( s ), 00079 length( l ) 00080 { 00081 } 00082 }; 00083 00088 btAlignedObjectArray< int > m_linkAddresses; 00089 00093 btAlignedObjectArray< BatchPair > m_wavefrontBatchStartLengths; 00094 00095 00096 //ID3D11Buffer* readBackBuffer; 00097 00098 btSoftBodyLinkDataDX11SIMDAware( ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext ); 00099 00100 virtual ~btSoftBodyLinkDataDX11SIMDAware(); 00101 00103 virtual void createLinks( int numLinks ); 00104 00106 virtual void setLinkAt( const LinkDescription &link, int linkIndex ); 00107 00108 virtual bool onAccelerator(); 00109 00110 virtual bool moveToAccelerator(); 00111 00112 virtual bool moveFromAccelerator(); 00113 00120 void generateBatches(); 00121 00122 int getMaxVerticesPerWavefront() 00123 { 00124 return m_maxVerticesWithinWave; 00125 } 00126 00127 int getWavefrontSize() 00128 { 00129 return m_wavefrontSize; 00130 } 00131 00132 int getLinksPerWorkItem() 00133 { 00134 return m_linksPerWorkItem; 00135 } 00136 00137 int getMaxLinksPerWavefront() 00138 { 00139 return m_maxLinksPerWavefront; 00140 } 00141 00142 int getMaxBatchesPerWavefront() 00143 { 00144 return m_maxBatchesWithinWave; 00145 } 00146 00147 int getNumWavefronts() 00148 { 00149 return m_numWavefronts; 00150 } 00151 00152 NumBatchesVerticesPair getNumBatchesAndVerticesWithinWavefront( int wavefront ) 00153 { 00154 return m_numBatchesAndVerticesWithinWaves[wavefront]; 00155 } 00156 00157 int getVertexGlobalAddresses( int vertexIndex ) 00158 { 00159 return m_wavefrontVerticesGlobalAddresses[vertexIndex]; 00160 } 00161 00165 LinkNodePair getVertexPairLocalAddresses( int linkIndex ) 00166 { 00167 return m_linkVerticesLocalAddresses[linkIndex]; 00168 } 00169 00170 }; 00171 00172 00173 #endif // #ifndef BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H