NvBlastExtRTMultithreadedImpl.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTAUTHORINGRTMULTITHREADEDIMPL_H
30 #define NVBLASTAUTHORINGRTMULTITHREADEDIMPL_H
31 
32 #include <NvBlastExtRT.h>
33 #include <NvBlastExtRTImpl.h>
34 #include <thread>
35 #include <mutex>
36 #include <condition_variable>
37 #include <atomic>
38 #include <vector>
39 
40 namespace Nv
41 {
42  namespace Blast
43  {
45  {
46  public:
47  FractureRTMultithreadedImpl(uint32_t threadCount);
48 
49  void release() override;
50  void processMesh(DamagePattern* pattern, const Mesh* msh) override;
51  uint32_t getResultChunkCount() override;
52  Vertex* getVertexBuffer() override;
53  uint32_t* getIndexBuffer() override;
54  uint32_t* getVertexOffset() override;
55  uint32_t* getIndexOffset() override;
57  void dumpChunksToObj(const char* path) override;
58 
59  private:
60  Vertex* vertexBuffer = nullptr;
61  uint32_t* indexBuffer = nullptr;
62 
63  uint32_t* vertexOffsets = nullptr;
64  uint32_t* indexOffsets = nullptr;
65 
66  PerTriangleAdditionalData* adata = nullptr;
67 
68  uint32_t chunkCount;
69 
70 #ifdef USE_MERGED_MESH
71  BooleanToolOutputData* outputData;
72 #endif
73 
74  struct PerThreadToolsAndData
75  {
76  PerThreadToolsAndData();
77  ~PerThreadToolsAndData();
78 
79  Fracturer* f = nullptr;
80  MeshGenerator* mgen = nullptr;
81  Vertex* vertexBuffer = nullptr;
82  uint32_t* indexBuffer = nullptr;
83  uint32_t* indexOffsets = nullptr;
84  uint32_t* vertexOffsets = nullptr;
85  uint32_t* perChunkIds = nullptr;
86  uint32_t chunkCount;
87  PerTriangleAdditionalData* adata = nullptr;
88 
89  SpatialAccelerator* accel = nullptr;
90  BooleanToolOutputData* outputData = nullptr;
91  };
92 
93  struct FractureJob
94  {
95  FractureJob() {};
96  FractureJob(uint32_t chunkId, const Mesh* mesh, Mesh* cell,
97  int32_t stage = FractureRT::Stage::ALL, DamagePattern* pattern = nullptr)
98  : chunkId(chunkId), mesh(mesh), cell(cell), stage(stage), pattern(pattern) {}
99 
100  uint32_t chunkId;
101  const Nv::Blast::Mesh* mesh;
102  Nv::Blast::Mesh* cell;
103  int32_t stage = FractureRT::Stage::ALL;
104  DamagePattern* pattern = nullptr;
105  };
106 
107  std::mutex work_mtx;
108  std::condition_variable hasAJob;
109  std::vector<FractureJob> fractureJobList;
110  std::vector<PerThreadToolsAndData> perThreadTd;
111  std::vector<std::thread> threadPool;
112  std::atomic<int32_t> jobCounter;
113 
114  void waitForJob(int32_t threadId);
115  bool terminateThreads;
116  void pushJob(FractureJob& j);
117  };
118  }
119 }
120 
121 #endif // ifndef NVBLASTAUTHORINGRTMULTITHREADEDIMPL_H
PerTriangleAdditionalData * getPerTriangleData() override
Definition: NvBlastExtRT.h:144
uint32_t * getIndexOffset() override
Definition: NvBlastExtAuthoringAccelerator.h:47
Definition: NvBlastExtAuthoringMesh.h:42
FractureRTMultithreadedImpl(uint32_t threadCount)
uint32_t * getIndexBuffer() override
Definition: NvBlastExtAuthoringPatternGenerator.h:85
Definition: NvBlastExtRT.h:86
uint32_t * getVertexOffset() override
Definition: NvBlastExtRT.h:172
Definition: NvBlastExtRT.h:160
void processMesh(DamagePattern *pattern, const Mesh *msh) override
Definition: NvBlastExtRTMultithreadedImpl.h:44
Definition: NvBlastExtAuthoringTypes.h:67
Definition: NvBlastExtRT.h:126
Definition: NvBlastExtRT.h:120
Definition: NvBlastArray.h:37
void dumpChunksToObj(const char *path) override