Main Page Class List Class Members

NvBlastTkGroupImpl.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 NVBLASTTKGROUPIMPL_H
30 #define NVBLASTTKGROUPIMPL_H
31
32
33 #include "NvBlastTkTaskImpl.h"
34 #include "NvBlastTkGroup.h"
35 #include "NvBlastTkTypeImpl.h"
36
37
38 namespace Nv
39 {
40 namespace Blast
41 {
42
43 class TkActorImpl;
44 class TkFamilyImpl;
45
46 NVBLASTTK_IMPL_DECLARE(Group)
47 {
48 ~TkGroupImpl();
49
50 public:
51 TkGroupImpl();
52
53 NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('G', 'R', 'P', '\0');
54
55 static TkGroupImpl* create(const TkGroupDesc& desc);
56
57 // Begin TkGroup
58 virtual bool addActor(TkActor& actor) override;
59
60 virtual uint32_t getActorCount() const override;
61
62 virtual uint32_t getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart = 0) const override;
63
64 virtual uint32_t startProcess() override;
65 virtual bool endProcess() override;
66
67 virtual void getStats(TkGroupStats& stats) const override;
68
69 virtual void setWorkerCount(uint32_t workerCount) override;
70 virtual uint32_t getWorkerCount() const override;
71
72 virtual TkGroupWorker* acquireWorker() override;
73 virtual void returnWorker(TkGroupWorker*) override;
74 // End TkGroup
75
76 // TkGroupImpl API
77
85 bool removeActor(TkActor& actor);
86
91 void enqueue(TkActorImpl* tkActor);
92
98 bool isProcessing() const;
99
100 private:
109 bool setProcessing(bool value);
110
114 SharedMemory* getSharedMemory(TkFamilyImpl* family);
115 void releaseSharedMemory(TkFamilyImpl* fam, SharedMemory* mem);
116
117 // functions to add/remove actors _without_ group-family memory management
118 void addActorInternal(TkActorImpl& tkActor);
119 void addActorsInternal(TkActorImpl** actors, uint32_t numActors);
120 void removeActorInternal(TkActorImpl& tkActor);
121
122
123 uint32_t m_actorCount;
124
125 HashMap<TkFamilyImpl*, SharedMemory*>::type m_sharedMemory;
126
127 // it is assumed no more than the asset's number of bond and chunks fracture commands are produced
128 SharedBlock<NvBlastChunkFractureData> m_chunkTempDataBlock;
129 SharedBlock<NvBlastBondFractureData> m_bondTempDataBlock;
130 SharedBlock<NvBlastChunkFractureData> m_chunkEventDataBlock;
131 SharedBlock<NvBlastBondFractureData> m_bondEventDataBlock;
132 SharedBlock<char> m_splitScratchBlock;
133
134 std::atomic<bool> m_isProcessing;
135
136 Array<TkWorker>::type m_workers;
137
138 Array<TkWorkerJob>::type m_jobs;
139
140 //#if NV_PROFILE
141 TkGroupStats m_stats;
142 //#endif
143
144 std::mutex m_workerMtx;
145
146 friend class TkWorker;
147 };
148
149
150 NV_INLINE bool TkGroupImpl::isProcessing() const
151 {
152 return m_isProcessing.load();
153 }
154
155
156 NV_INLINE void TkGroupImpl::getStats(TkGroupStats& stats) const
157 {
158 #if NV_PROFILE
159 memcpy(&stats, &m_stats, sizeof(TkGroupStats));
160 #else
161 NV_UNUSED(stats);
162 #endif
163 }
164
165
166 NV_INLINE uint32_t TkGroupImpl::getActorCount() const
167 {
168 return m_actorCount;
169 }
170
171
172 NV_INLINE SharedMemory* TkGroupImpl::getSharedMemory(TkFamilyImpl* family)
173 {
174 SharedMemory* mem = m_sharedMemory[family];
175 NVBLAST_ASSERT(mem != nullptr);
176 return mem;
177 }
178
179
180 NV_FORCE_INLINE void operator +=(NvBlastTimers& lhs, const NvBlastTimers& rhs)
181 {
182 lhs.material += rhs.material;
183 lhs.fracture += rhs.fracture;
184 lhs.island += rhs.fracture;
185 lhs.partition += rhs.partition;
186 lhs.visibility += rhs.visibility;
187 }
188
189
190 } // namespace Blast
191 } // namespace Nv
192
193
194 #endif // ifndef NVBLASTTKGROUPIMPL_H
NvBlastTimers::fracture
int64_t fracture
Time spent applying damage.
Definition: NvBlastTypes.h:88
NV_UNUSED
NV_CUDA_CALLABLE NV_INLINE void NV_UNUSED(T const &)
Definition: NvPreprocessor.h:476
Nv::Blast::TkActorImpl
Definition: NvBlastTkActorImpl.h:75
NvBlastTkTaskImpl.h
Nv::Blast::Array::type
physx::shdfnd::Array< T, Allocator > type
Definition: NvBlastArray.h:48
NvBlastTimers::partition
int64_t partition
Time spent partitioning the graph.
Definition: NvBlastTypes.h:90
Nv::Blast::TkActor
Definition: NvBlastTkActor.h:57
NvBlastTimers::material
int64_t material
Time spent in material function.
Definition: NvBlastTypes.h:87
Nv::Blast::TkGroupDesc
Definition: NvBlastTkGroup.h:48
Nv::Blast::operator+=
NV_FORCE_INLINE void operator+=(NvBlastTimers &lhs, const NvBlastTimers &rhs)
Definition: NvBlastTkGroupImpl.h:180
Nv::Blast::TkGroupStats
Definition: NvBlastTkGroup.h:58
Nv::Blast::HashMap::type
physx::shdfnd::HashMap< Key, Value, HashFn, Allocator > type
Definition: NvBlastHashMap.h:48
Nv::Blast::TkWorker
Definition: NvBlastTkTaskImpl.h:346
NVBLAST_ASSERT
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
NvBlastTimers
Definition: NvBlastTypes.h:85
NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE
#define NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE(_id0, _id1, _id2, _id3)
Definition: NvBlastTkCommon.h:91
Nv::Blast::NVBLASTTK_IMPL_DECLARE
NVBLASTTK_IMPL_DECLARE(Asset)
Definition: NvBlastTkAssetImpl.h:52
NV_INLINE
#define NV_INLINE
Definition: NvPreprocessor.h:350
NvBlastTimers::island
int64_t island
Time spent discovering islands.
Definition: NvBlastTypes.h:89
NvBlastTimers::visibility
int64_t visibility
Time spent updating visibility.
Definition: NvBlastTypes.h:91
Nv::Blast::SharedBlock
Definition: NvBlastTkTaskImpl.h:75
Nv::Blast::SharedMemory
Definition: NvBlastTkTaskImpl.h:257
NvBlastTkTypeImpl.h
NvBlastTkGroup.h
Nv::Blast::TkGroupWorker
Definition: NvBlastTkGroup.h:74
Nv
Definition: NvBlastArray.h:37
NV_FORCE_INLINE
#define NV_FORCE_INLINE
Definition: NvPreprocessor.h:365