~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolverLinkData_OpenCLSIMDAware.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Bullet Continuous Collision Detection and Physics Library
 
3
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 
4
 
 
5
This software is provided 'as-is', without any express or implied warranty.
 
6
In no event will the authors be held liable for any damages arising from the use of this software.
 
7
Permission is granted to anyone to use this software for any purpose, 
 
8
including commercial applications, and to alter it and redistribute it freely, 
 
9
subject to the following restrictions:
 
10
 
 
11
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.
 
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 
13
3. This notice may not be removed or altered from any source distribution.
 
14
*/
 
15
 
 
16
#include "BulletMultiThreaded/GpuSoftBodySolvers/CPU/btSoftBodySolverData.h"
 
17
#include "btSoftBodySolverBuffer_OpenCL.h"
 
18
 
 
19
 
 
20
#ifndef BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H
 
21
#define BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H
 
22
 
 
23
 
 
24
class btSoftBodyLinkDataOpenCLSIMDAware : public btSoftBodyLinkData
 
25
{
 
26
public:
 
27
        bool                            m_onGPU;
 
28
 
 
29
        cl_command_queue        m_cqCommandQue;
 
30
 
 
31
        const int m_wavefrontSize;
 
32
        const int m_linksPerWorkItem;
 
33
        const int m_maxLinksPerWavefront;
 
34
        int m_maxBatchesWithinWave;
 
35
        int m_maxVerticesWithinWave;
 
36
        int m_numWavefronts;
 
37
 
 
38
        int m_maxVertex;
 
39
 
 
40
        struct NumBatchesVerticesPair
 
41
        {
 
42
                int numBatches;
 
43
                int numVertices;
 
44
        };
 
45
 
 
46
        btAlignedObjectArray<int>                                                         m_linksPerWavefront;
 
47
        btAlignedObjectArray<NumBatchesVerticesPair>              m_numBatchesAndVerticesWithinWaves;
 
48
        btOpenCLBuffer< NumBatchesVerticesPair >                          m_clNumBatchesAndVerticesWithinWaves;
 
49
 
 
50
        // All arrays here will contain batches of m_maxLinksPerWavefront links
 
51
        // ordered by wavefront.
 
52
        // with either global vertex pairs or local vertex pairs
 
53
        btAlignedObjectArray< int >                                                       m_wavefrontVerticesGlobalAddresses; // List of global vertices per wavefront
 
54
        btOpenCLBuffer<int>                                                                       m_clWavefrontVerticesGlobalAddresses;
 
55
        btAlignedObjectArray< LinkNodePair >                              m_linkVerticesLocalAddresses; // Vertex pair for the link
 
56
        btOpenCLBuffer<LinkNodePair>                                              m_clLinkVerticesLocalAddresses;
 
57
        btOpenCLBuffer<float>                                                         m_clLinkStrength;
 
58
        btOpenCLBuffer<float>                                                             m_clLinksMassLSC;
 
59
        btOpenCLBuffer<float>                                                             m_clLinksRestLengthSquared;
 
60
        btOpenCLBuffer<float>                                                             m_clLinksRestLength;
 
61
        btOpenCLBuffer<float>                                                             m_clLinksMaterialLinearStiffnessCoefficient;
 
62
 
 
63
        struct BatchPair
 
64
        {
 
65
                int start;
 
66
                int length;
 
67
 
 
68
                BatchPair() :
 
69
                        start(0),
 
70
                        length(0)
 
71
                {
 
72
                }
 
73
 
 
74
                BatchPair( int s, int l ) : 
 
75
                        start( s ),
 
76
                        length( l )
 
77
                {
 
78
                }
 
79
        };
 
80
 
 
81
        /**
 
82
         * Link addressing information for each cloth.
 
83
         * Allows link locations to be computed independently of data batching.
 
84
         */
 
85
        btAlignedObjectArray< int >                                                     m_linkAddresses;
 
86
        
 
87
        /**
 
88
         * Start and length values for computation batches over link data.
 
89
         */
 
90
        btAlignedObjectArray< BatchPair >               m_wavefrontBatchStartLengths;
 
91
 
 
92
        btSoftBodyLinkDataOpenCLSIMDAware(cl_command_queue queue, cl_context ctx);
 
93
 
 
94
        virtual ~btSoftBodyLinkDataOpenCLSIMDAware();
 
95
 
 
96
        /** Allocate enough space in all link-related arrays to fit numLinks links */
 
97
        virtual void createLinks( int numLinks );
 
98
        
 
99
        /** Insert the link described into the correct data structures assuming space has already been allocated by a call to createLinks */
 
100
        virtual void setLinkAt( 
 
101
                const LinkDescription &link, 
 
102
                int linkIndex );
 
103
 
 
104
        virtual bool onAccelerator();
 
105
 
 
106
        virtual bool moveToAccelerator();
 
107
 
 
108
        virtual bool moveFromAccelerator();
 
109
 
 
110
        /**
 
111
         * Generate (and later update) the batching for the entire link set.
 
112
         * This redoes a lot of work because it batches the entire set when each cloth is inserted.
 
113
         * In theory we could delay it until just before we need the cloth.
 
114
         * It's a one-off overhead, though, so that is a later optimisation.
 
115
         */
 
116
        void generateBatches();
 
117
 
 
118
        int getMaxVerticesPerWavefront()
 
119
        {
 
120
                return m_maxVerticesWithinWave;
 
121
        }
 
122
 
 
123
        int getWavefrontSize()
 
124
        {
 
125
                return m_wavefrontSize;
 
126
        }
 
127
 
 
128
        int getLinksPerWorkItem()
 
129
        {
 
130
                return m_linksPerWorkItem;
 
131
        }
 
132
 
 
133
        int getMaxLinksPerWavefront()
 
134
        {
 
135
                return m_maxLinksPerWavefront;
 
136
        }
 
137
 
 
138
        int getMaxBatchesPerWavefront()
 
139
        {
 
140
                return m_maxBatchesWithinWave;
 
141
        }
 
142
 
 
143
        int getNumWavefronts()
 
144
        {
 
145
                return m_numWavefronts;
 
146
        }
 
147
 
 
148
        NumBatchesVerticesPair getNumBatchesAndVerticesWithinWavefront( int wavefront )
 
149
        {
 
150
                return m_numBatchesAndVerticesWithinWaves[wavefront];
 
151
        }
 
152
 
 
153
        int getVertexGlobalAddresses( int vertexIndex )
 
154
        {
 
155
                return m_wavefrontVerticesGlobalAddresses[vertexIndex];
 
156
        }
 
157
 
 
158
        /**
 
159
         * Get post-batching local addresses of the vertex pair for a link assuming all vertices used by a wavefront are loaded locally.
 
160
         */
 
161
        LinkNodePair getVertexPairLocalAddresses( int linkIndex )
 
162
        {
 
163
                return m_linkVerticesLocalAddresses[linkIndex];
 
164
        }
 
165
};
 
166
 
 
167
 
 
168
 
 
169
#endif // #ifndef BT_SOFT_BODY_SOLVER_LINK_DATA_OPENCL_SIMDAWARE_H