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

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolverLinkData_DX11SIMDAware.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_DX11.h"
 
18
 
 
19
#ifndef BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H
 
20
#define BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H
 
21
 
 
22
struct ID3D11Device;
 
23
struct ID3D11DeviceContext;
 
24
 
 
25
 
 
26
class btSoftBodyLinkDataDX11SIMDAware : public btSoftBodyLinkData
 
27
{
 
28
public:
 
29
        bool                            m_onGPU;
 
30
        ID3D11Device            *m_d3dDevice;
 
31
        ID3D11DeviceContext *m_d3dDeviceContext;
 
32
 
 
33
        const int m_wavefrontSize;
 
34
        const int m_linksPerWorkItem;
 
35
        const int m_maxLinksPerWavefront;
 
36
        int m_maxBatchesWithinWave;
 
37
        int m_maxVerticesWithinWave;
 
38
        int m_numWavefronts;
 
39
 
 
40
        int m_maxVertex;
 
41
 
 
42
        struct NumBatchesVerticesPair
 
43
        {
 
44
                int numBatches;
 
45
                int numVertices;
 
46
        };
 
47
 
 
48
        // Array storing number of links in each wavefront
 
49
        btAlignedObjectArray<int>                                                                       m_linksPerWavefront;
 
50
        btAlignedObjectArray<NumBatchesVerticesPair>                            m_numBatchesAndVerticesWithinWaves;
 
51
        btDX11Buffer< NumBatchesVerticesPair >                                          m_dx11NumBatchesAndVerticesWithinWaves;
 
52
 
 
53
        // All arrays here will contain batches of m_maxLinksPerWavefront links
 
54
        // ordered by wavefront.
 
55
        // with either global vertex pairs or local vertex pairs
 
56
        btAlignedObjectArray< int >                                                                     m_wavefrontVerticesGlobalAddresses; // List of global vertices per wavefront
 
57
        btDX11Buffer<int>                                                                                       m_dx11WavefrontVerticesGlobalAddresses;
 
58
        btAlignedObjectArray< LinkNodePair >                                            m_linkVerticesLocalAddresses; // Vertex pair for the link
 
59
        btDX11Buffer<LinkNodePair>                                                                      m_dx11LinkVerticesLocalAddresses;
 
60
        btDX11Buffer<float>                                                                                     m_dx11LinkStrength;
 
61
        btDX11Buffer<float>                                                                                     m_dx11LinksMassLSC;
 
62
        btDX11Buffer<float>                                                                                     m_dx11LinksRestLengthSquared;
 
63
        btDX11Buffer<float>                                                                                     m_dx11LinksRestLength;
 
64
        btDX11Buffer<float>                                                                                     m_dx11LinksMaterialLinearStiffnessCoefficient;
 
65
 
 
66
        struct BatchPair
 
67
        {
 
68
                int start;
 
69
                int length;
 
70
 
 
71
                BatchPair() :
 
72
                        start(0),
 
73
                        length(0)
 
74
                {
 
75
                }
 
76
 
 
77
                BatchPair( int s, int l ) : 
 
78
                        start( s ),
 
79
                        length( l )
 
80
                {
 
81
                }
 
82
        };
 
83
 
 
84
        /**
 
85
         * Link addressing information for each cloth.
 
86
         * Allows link locations to be computed independently of data batching.
 
87
         */
 
88
        btAlignedObjectArray< int >                                                     m_linkAddresses;
 
89
 
 
90
        /**
 
91
         * Start and length values for computation batches over link data.
 
92
         */
 
93
        btAlignedObjectArray< BatchPair >               m_wavefrontBatchStartLengths;
 
94
 
 
95
 
 
96
        //ID3D11Buffer*               readBackBuffer;
 
97
        
 
98
        btSoftBodyLinkDataDX11SIMDAware( ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext );
 
99
 
 
100
        virtual ~btSoftBodyLinkDataDX11SIMDAware();
 
101
 
 
102
        /** Allocate enough space in all link-related arrays to fit numLinks links */
 
103
        virtual void createLinks( int numLinks );
 
104
        
 
105
        /** Insert the link described into the correct data structures assuming space has already been allocated by a call to createLinks */
 
106
        virtual void setLinkAt( const LinkDescription &link, int linkIndex );
 
107
 
 
108
        virtual bool onAccelerator();
 
109
 
 
110
        virtual bool moveToAccelerator();
 
111
 
 
112
        virtual bool moveFromAccelerator();
 
113
 
 
114
        /**
 
115
         * Generate (and later update) the batching for the entire link set.
 
116
         * This redoes a lot of work because it batches the entire set when each cloth is inserted.
 
117
         * In theory we could delay it until just before we need the cloth.
 
118
         * It's a one-off overhead, though, so that is a later optimisation.
 
119
         */
 
120
        void generateBatches();
 
121
 
 
122
        int getMaxVerticesPerWavefront()
 
123
        {
 
124
                return m_maxVerticesWithinWave;
 
125
        }
 
126
 
 
127
        int getWavefrontSize()
 
128
        {
 
129
                return m_wavefrontSize;
 
130
        }
 
131
 
 
132
        int getLinksPerWorkItem()
 
133
        {
 
134
                return m_linksPerWorkItem;
 
135
        }
 
136
 
 
137
        int getMaxLinksPerWavefront()
 
138
        {
 
139
                return m_maxLinksPerWavefront;
 
140
        }
 
141
 
 
142
        int getMaxBatchesPerWavefront()
 
143
        {
 
144
                return m_maxBatchesWithinWave;
 
145
        }
 
146
 
 
147
        int getNumWavefronts()
 
148
        {
 
149
                return m_numWavefronts;
 
150
        }
 
151
 
 
152
        NumBatchesVerticesPair getNumBatchesAndVerticesWithinWavefront( int wavefront )
 
153
        {
 
154
                return m_numBatchesAndVerticesWithinWaves[wavefront];
 
155
        }
 
156
 
 
157
        int getVertexGlobalAddresses( int vertexIndex )
 
158
        {
 
159
                return m_wavefrontVerticesGlobalAddresses[vertexIndex];
 
160
        }
 
161
 
 
162
        /**
 
163
         * Get post-batching local addresses of the vertex pair for a link assuming all vertices used by a wavefront are loaded locally.
 
164
         */
 
165
        LinkNodePair getVertexPairLocalAddresses( int linkIndex )
 
166
        {
 
167
                return m_linkVerticesLocalAddresses[linkIndex];
 
168
        }
 
169
 
 
170
};
 
171
 
 
172
 
 
173
#endif // #ifndef BT_ACCELERATED_SOFT_BODY_LINK_DATA_DX11_SIMDAWARE_H