Newton Dynamics  4.00
ndCudaContextImplement.h
1 /* Copyright (c) <2003-2021> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_CUDA_CONTEXT_IMPLEMENT_H__
23 #define __ND_CUDA_CONTEXT_IMPLEMENT_H__
24 
25 #include "ndCudaStdafx.h"
26 #include "ndCudaUtils.h"
27 #include "ndCudaDevice.h"
28 #include "ndCudaSceneInfo.h"
29 #include "ndCudaBodyProxy.h"
30 #include "ndCudaHostBuffer.h"
31 #include "ndCudaDeviceBuffer.h"
32 
33 #define D_THREADS_PER_BLOCK_BITS 8
34 #define D_THREADS_PER_BLOCK (1<<D_THREADS_PER_BLOCK_BITS)
35 
36 class ndCudaDevice;
37 
39 {
40  public:
41  ndCudaContextImplement(const ndCudaDevice* const device);
43 
44  void Begin();
45  void End();
46  float GetTimeInSeconds() const;
47 
48  void ResizeBuffers(int size);
49  void LoadBodyData(const ndCudaBodyProxy* const src, int size);
50 
51  void InitBodyArray();
52  void UpdateTransform();
53  void ValidateContextBuffers();
54  ndCudaSpatialVector* GetTransformBuffer();
55 
56  void IntegrateBodies(float timestep);
57  void IntegrateUnconstrainedBodies(float timestep);
58 
59  const ndCudaDevice* m_device;
60  ndCudaSceneInfo* m_sceneInfoGpu;
61  ndCudaSceneInfo* m_sceneInfoCpu;
62 
63  // gpu buffers
64  ndCudaDeviceBuffer<unsigned> m_histogram;
68  ndCudaDeviceBuffer<ndCudaBodyAabbCell> m_bodyAabbCellScratch;
69  ndCudaDeviceBuffer<ndCudaSpatialVector> m_transformBuffer0;
70  ndCudaDeviceBuffer<ndCudaSpatialVector> m_transformBuffer1;
71 
72  // host buffers
73  ndCudaHostBuffer<ndCudaSpatialVector> m_transformBufferCpu;
74 
75  cudaStream_t m_solverMemCpuStream;
76  cudaStream_t m_solverComputeStream;
77  double m_timeInSeconds;
78  unsigned m_frameCounter;
79 };
80 
81 #endif
ndCudaDeviceBuffer< unsigned >
ndCudaSceneInfo
Definition: ndCudaSceneInfo.h:32
ndCudaSpatialVector
Definition: ndCudaTypes.h:40
ndCudaHostBuffer< ndCudaSpatialVector >
ndCudaContextImplement
Definition: ndCudaContextImplement.h:39
ndCudaBodyProxy
Definition: ndCudaBodyProxy.h:33
ndCudaDevice
Definition: ndCudaDevice.h:32