NvBlastFamily.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 NVBLASTFAMILY_H
30 #define NVBLASTFAMILY_H
31 
32 
33 #include "NvBlastAsset.h"
34 #include "NvBlastPreprocessor.h"
35 #include "NvBlastDLink.h"
36 #include "NvBlastAtomic.h"
37 #include "NvBlastMemory.h"
38 
39 #include <cstring>
40 
41 
42 struct NvBlastAsset;
43 
44 
45 namespace Nv
46 {
47 namespace Blast
48 {
49 
50 // Forward declarations
51 class FamilyGraph;
52 class Actor;
53 class Asset;
54 
55 
62 {
67 
74  NvBlastBlockArrayData(Actor, m_actorsOffset, getActors, m_asset->m_graph.m_nodeCount);
75 
81  NvBlastBlockArrayData(IndexDLink<uint32_t>, m_visibleChunkIndexLinksOffset, getVisibleChunkIndexLinks, m_asset->m_chunkCount);
82 
88  NvBlastBlockArrayData(uint32_t, m_chunkActorIndicesOffset, getChunkActorIndices, m_asset->m_firstSubsupportChunkIndex);
89 
95  NvBlastBlockArrayData(uint32_t, m_graphNodeIndexLinksOffset, getGraphNodeIndexLinks, m_asset->m_graph.m_nodeCount);
96 
104  NvBlastBlockArrayData(float, m_lowerSupportChunkHealthsOffset, getLowerSupportChunkHealths, m_asset->getLowerSupportChunkCount());
105 
114  {
115  NVBLAST_ASSERT(m_asset != nullptr);
116  return (float*)((uintptr_t)this + m_lowerSupportChunkHealthsOffset) + m_asset->m_graph.m_nodeCount;
117  }
118 
124  NvBlastBlockArrayData(float, m_graphBondHealthsOffset, getBondHealths, m_asset->getBondCount());
125 
132  NvBlastBlockData(FamilyGraph, m_familyGraphOffset, getFamilyGraph);
133 
134 
136 
140  volatile uint32_t m_actorCount;
141 
146  union
147  {
148  const Asset* m_asset;
149  uint64_t m_runtimePlaceholder; // Make sure we reserve enough room for an 8-byte pointer
150  };
151 
152 
154 
162  Actor* borrowActor(uint32_t index);
163 
169  void returnActor(Actor& actor);
170 
176  uint32_t getActorBufferSize() const;
177 
183  bool isActorActive(uint32_t index) const;
184 
192  Actor* getActorByIndex(uint32_t index) const;
193 
201  uint32_t getGetChunkActorIndex(uint32_t chunkIndex) const;
202 
210  uint32_t getGetNodeActorIndex(uint32_t nodeIndex) const;
211 
219  Actor* getGetChunkActor(uint32_t chunkIndex) const;
220 
228  Actor* getGetNodeActor(uint32_t nodeIndex) const;
229 
230 
232 
242  void fractureSubSupportNoEvents(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float* chunkHealths, const NvBlastChunk* chunks);
243 
260  void fractureSubSupport(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float* chunkHealths, const NvBlastChunk* chunks, NvBlastChunkFractureData* outBuffer, uint32_t* currentIndex, const uint32_t maxCount);
261 
270  void fractureNoEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData* chunkFractures, Actor* filterActor, NvBlastLog logFn);
271 
286  void fractureWithEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData* commands, NvBlastChunkFractureData* events, uint32_t eventsSize, uint32_t* count, Actor* filterActor, NvBlastLog logFn);
287 
303  void fractureInPlaceEvents(uint32_t chunkFractureCount, NvBlastChunkFractureData* inoutbuffer, uint32_t eventsSize, uint32_t* count, Actor* filterActor, NvBlastLog logFn);
304 
316  void applyFracture(NvBlastFractureBuffers* eventBuffers, const NvBlastFractureBuffers* commands, Actor* filterActor, NvBlastLog logFn, NvBlastTimers* timers);
317 };
318 
319 } // namespace Blast
320 } // namespace Nv
321 
322 
323 #include "NvBlastActor.h"
324 
325 
326 namespace Nv
327 {
328 namespace Blast
329 {
330 
332 
334 {
336  Actor& actor = getActors()[index];
337  if (actor.m_familyOffset == 0)
338  {
339  const uintptr_t offset = (uintptr_t)&actor - (uintptr_t)this;
340  NVBLAST_ASSERT(offset <= UINT32_MAX);
341  actor.m_familyOffset = (uint32_t)offset;
342  atomicIncrement(reinterpret_cast<volatile int32_t*>(&m_actorCount));
343  }
344  return &actor;
345 }
346 
347 
349 {
350  if (actor.m_familyOffset != 0)
351  {
352  actor.m_familyOffset = 0;
353  // The actor count should be positive since this actor was valid. Check to be safe.
355  atomicDecrement(reinterpret_cast<volatile int32_t*>(&m_actorCount));
356  }
357 }
358 
359 
361 {
364 }
365 
366 
367 NV_INLINE bool FamilyHeader::isActorActive(uint32_t index) const
368 {
370  return getActors()[index].m_familyOffset != 0;
371 }
372 
373 
375 {
377  Actor& actor = getActors()[index];
378  return actor.isActive() ? &actor : nullptr;
379 }
380 
381 
382 NV_INLINE uint32_t FamilyHeader::getGetChunkActorIndex(uint32_t chunkIndex) const
383 {
385  NVBLAST_ASSERT(chunkIndex < m_asset->m_chunkCount);
386  if (chunkIndex < m_asset->getUpperSupportChunkCount())
387  {
388  return getChunkActorIndices()[chunkIndex];
389  }
390  else
391  {
392  return chunkIndex - (m_asset->getUpperSupportChunkCount() - m_asset->m_graph.m_nodeCount);
393  }
394 }
395 
396 
397 NV_INLINE uint32_t FamilyHeader::getGetNodeActorIndex(uint32_t nodeIndex) const
398 {
400  NVBLAST_ASSERT(nodeIndex < m_asset->m_graph.m_nodeCount);
401  const uint32_t chunkIndex = m_asset->m_graph.getChunkIndices()[nodeIndex];
402  return isInvalidIndex(chunkIndex) ? chunkIndex : getChunkActorIndices()[chunkIndex];
403 }
404 
405 
406 NV_INLINE Actor* FamilyHeader::getGetChunkActor(uint32_t chunkIndex) const
407 {
408  uint32_t actorIndex = getGetChunkActorIndex(chunkIndex);
409  return !isInvalidIndex(actorIndex) ? getActorByIndex(actorIndex) : nullptr;
410 }
411 
412 
414 {
415  uint32_t actorIndex = getGetNodeActorIndex(nodeIndex);
416  return !isInvalidIndex(actorIndex) ? getActorByIndex(actorIndex) : nullptr;
417 }
418 
419 
421 
428 size_t getFamilyMemorySize(const Asset* asset);
429 
430 } // namespace Blast
431 } // namespace Nv
432 
433 
434 #endif // ifndef NVBLASTFAMILY_H
#define UINT32_MAX
Definition: NvBlastPreprocessorInternal.h:68
void fractureWithEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData *commands, NvBlastChunkFractureData *events, uint32_t eventsSize, uint32_t *count, Actor *filterActor, NvBlastLog logFn)
Definition: NvBlastFamilyGraph.h:58
void fractureSubSupportNoEvents(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float *chunkHealths, const NvBlastChunk *chunks)
bool isActive() const
Definition: NvBlastActor.h:512
void fractureNoEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData *chunkFractures, Actor *filterActor, NvBlastLog logFn)
bool isActorActive(uint32_t index) const
Definition: NvBlastFamily.h:367
uint32_t getGetNodeActorIndex(uint32_t nodeIndex) const
Definition: NvBlastFamily.h:397
uint32_t getBondCount() const
Definition: NvBlastAsset.h:277
NV_INLINE bool isInvalidIndex(T index)
Definition: NvBlastIndexFns.h:57
void(* NvBlastLog)(int type, const char *msg, const char *file, int line)
Definition: NvBlastTypes.h:63
Definition: NvBlastFamily.h:61
volatile uint32_t m_actorCount
Definition: NvBlastFamily.h:140
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
Definition: NvBlastTypes.h:85
NvBlastBlockArrayData(Actor, m_actorsOffset, getActors, m_asset->m_graph.m_nodeCount)
void fractureSubSupport(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float *chunkHealths, const NvBlastChunk *chunks, NvBlastChunkFractureData *outBuffer, uint32_t *currentIndex, const uint32_t maxCount)
Actor * getGetNodeActor(uint32_t nodeIndex) const
Definition: NvBlastFamily.h:413
int32_t atomicIncrement(volatile int32_t *val)
void applyFracture(NvBlastFractureBuffers *eventBuffers, const NvBlastFractureBuffers *commands, Actor *filterActor, NvBlastLog logFn, NvBlastTimers *timers)
Definition: NvBlastTypes.h:98
uint32_t getActorBufferSize() const
Definition: NvBlastFamily.h:360
uint32_t m_firstSubsupportChunkIndex
Definition: NvBlastAsset.h:207
const Asset * m_asset
Definition: NvBlastFamily.h:148
Actor * getActorByIndex(uint32_t index) const
Definition: NvBlastFamily.h:374
Actor * getGetChunkActor(uint32_t chunkIndex) const
Definition: NvBlastFamily.h:406
#define NV_INLINE
Definition: NvPreprocessor.h:350
uint32_t m_nodeCount
Definition: NvBlastSupportGraph.h:81
NvBlastID m_assetID
Definition: NvBlastFamily.h:66
Definition: NvBlastTypes.h:69
uint32_t getLowerSupportChunkCount() const
Definition: NvBlastAsset.h:271
Definition: NvBlastTypes.h:152
Definition: NvBlastTypes.h:439
NvBlastBlockData(FamilyGraph, m_familyGraphOffset, getFamilyGraph)
float * getSubsupportChunkHealths() const
Definition: NvBlastFamily.h:113
SupportGraph m_graph
Definition: NvBlastAsset.h:197
Definition: NvBlastTypes.h:286
Definition: NvBlastTypes.h:468
Definition: NvBlastActor.h:58
uint64_t m_runtimePlaceholder
Definition: NvBlastFamily.h:149
uint32_t getUpperSupportChunkCount() const
Definition: NvBlastAsset.h:265
uint32_t m_chunkCount
Definition: NvBlastAsset.h:192
int32_t atomicDecrement(volatile int32_t *val)
void returnActor(Actor &actor)
Definition: NvBlastFamily.h:348
size_t getFamilyMemorySize(const Asset *asset)
Actor * borrowActor(uint32_t index)
Definition: NvBlastFamily.h:333
Definition: NvBlastArray.h:37
Definition: NvBlastAsset.h:45
void fractureInPlaceEvents(uint32_t chunkFractureCount, NvBlastChunkFractureData *inoutbuffer, uint32_t eventsSize, uint32_t *count, Actor *filterActor, NvBlastLog logFn)
uint32_t getGetChunkActorIndex(uint32_t chunkIndex) const
Definition: NvBlastFamily.h:382