Main Page Class List Class Members

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
61 struct FamilyHeader : public NvBlastDataBlock
62 {
66 NvBlastID m_assetID;
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
113 float* getSubsupportChunkHealths() const
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
333 NV_INLINE Actor* FamilyHeader::borrowActor(uint32_t index)
334 {
335 NVBLAST_ASSERT(index < getActorBufferSize());
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
348 NV_INLINE void FamilyHeader::returnActor(Actor& actor)
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.
354 NVBLAST_ASSERT(m_actorCount > 0);
355 atomicDecrement(reinterpret_cast<volatile int32_t*>(&m_actorCount));
356 }
357 }
358
359
360 NV_INLINE uint32_t FamilyHeader::getActorBufferSize() const
361 {
362 NVBLAST_ASSERT(m_asset);
363 return m_asset->getLowerSupportChunkCount();
364 }
365
366
367 NV_INLINE bool FamilyHeader::isActorActive(uint32_t index) const
368 {
369 NVBLAST_ASSERT(index < getActorBufferSize());
370 return getActors()[index].m_familyOffset != 0;
371 }
372
373
374 NV_INLINE Actor* FamilyHeader::getActorByIndex(uint32_t index) const
375 {
376 NVBLAST_ASSERT(index < getActorBufferSize());
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 {
384 NVBLAST_ASSERT(m_asset);
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 {
399 NVBLAST_ASSERT(m_asset);
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
413 NV_INLINE Actor* FamilyHeader::getGetNodeActor(uint32_t nodeIndex) const
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
UINT32_MAX
#define UINT32_MAX
Definition: NvBlastPreprocessorInternal.h:68
Nv::Blast::FamilyHeader::fractureWithEvents
void fractureWithEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData *commands, NvBlastChunkFractureData *events, uint32_t eventsSize, uint32_t *count, Actor *filterActor, NvBlastLog logFn)
Nv::Blast::FamilyGraph
Definition: NvBlastFamilyGraph.h:58
Nv::Blast::FamilyHeader::fractureSubSupportNoEvents
void fractureSubSupportNoEvents(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float *chunkHealths, const NvBlastChunk *chunks)
Nv::Blast::Actor::isActive
bool isActive() const
Definition: NvBlastActor.h:512
Nv::Blast::FamilyHeader::fractureNoEvents
void fractureNoEvents(uint32_t chunkFractureCount, const NvBlastChunkFractureData *chunkFractures, Actor *filterActor, NvBlastLog logFn)
Nv::Blast::FamilyHeader::isActorActive
bool isActorActive(uint32_t index) const
Definition: NvBlastFamily.h:367
Nv::Blast::FamilyHeader::getGetNodeActorIndex
uint32_t getGetNodeActorIndex(uint32_t nodeIndex) const
Definition: NvBlastFamily.h:397
Nv::Blast::Asset::getBondCount
uint32_t getBondCount() const
Definition: NvBlastAsset.h:277
NvBlastAsset.h
Nv::Blast::isInvalidIndex
NV_INLINE bool isInvalidIndex(T index)
Definition: NvBlastIndexFns.h:57
NvBlastLog
void(* NvBlastLog)(int type, const char *msg, const char *file, int line)
Definition: NvBlastTypes.h:63
Nv::Blast::FamilyHeader
Definition: NvBlastFamily.h:61
Nv::Blast::FamilyHeader::m_actorCount
volatile uint32_t m_actorCount
Definition: NvBlastFamily.h:140
NVBLAST_ASSERT
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
NvBlastTimers
Definition: NvBlastTypes.h:85
Nv::Blast::FamilyHeader::NvBlastBlockArrayData
NvBlastBlockArrayData(Actor, m_actorsOffset, getActors, m_asset->m_graph.m_nodeCount)
Nv::Blast::FamilyHeader::fractureSubSupport
void fractureSubSupport(uint32_t chunkIndex, uint32_t suboffset, float healthDamage, float *chunkHealths, const NvBlastChunk *chunks, NvBlastChunkFractureData *outBuffer, uint32_t *currentIndex, const uint32_t maxCount)
Nv::Blast::FamilyHeader::getGetNodeActor
Actor * getGetNodeActor(uint32_t nodeIndex) const
Definition: NvBlastFamily.h:413
Nv::Blast::atomicIncrement
int32_t atomicIncrement(volatile int32_t *val)
Nv::Blast::FamilyHeader::applyFracture
void applyFracture(NvBlastFractureBuffers *eventBuffers, const NvBlastFractureBuffers *commands, Actor *filterActor, NvBlastLog logFn, NvBlastTimers *timers)
NvBlastDataBlock
Definition: NvBlastTypes.h:98
NvBlastMemory.h
Nv::Blast::FamilyHeader::getActorBufferSize
uint32_t getActorBufferSize() const
Definition: NvBlastFamily.h:360
Nv::Blast::Asset::m_firstSubsupportChunkIndex
uint32_t m_firstSubsupportChunkIndex
Definition: NvBlastAsset.h:207
Nv::Blast::FamilyHeader::m_asset
const Asset * m_asset
Definition: NvBlastFamily.h:148
NvBlastDLink.h
Nv::Blast::FamilyHeader::getActorByIndex
Actor * getActorByIndex(uint32_t index) const
Definition: NvBlastFamily.h:374
NvBlastAtomic.h
Nv::Blast::FamilyHeader::getGetChunkActor
Actor * getGetChunkActor(uint32_t chunkIndex) const
Definition: NvBlastFamily.h:406
NV_INLINE
#define NV_INLINE
Definition: NvPreprocessor.h:350
Nv::Blast::SupportGraph::m_nodeCount
uint32_t m_nodeCount
Definition: NvBlastSupportGraph.h:81
Nv::Blast::FamilyHeader::m_assetID
NvBlastID m_assetID
Definition: NvBlastFamily.h:66
NvBlastID
Definition: NvBlastTypes.h:69
Nv::Blast::Asset::getLowerSupportChunkCount
uint32_t getLowerSupportChunkCount() const
Definition: NvBlastAsset.h:271
NvBlastChunk
Definition: NvBlastTypes.h:152
NvBlastChunkFractureData
Definition: NvBlastTypes.h:439
Nv::Blast::FamilyHeader::NvBlastBlockData
NvBlastBlockData(FamilyGraph, m_familyGraphOffset, getFamilyGraph)
Nv::Blast::FamilyHeader::getSubsupportChunkHealths
float * getSubsupportChunkHealths() const
Definition: NvBlastFamily.h:113
Nv::Blast::Asset::m_graph
SupportGraph m_graph
Definition: NvBlastAsset.h:197
NvBlastAsset
Definition: NvBlastTypes.h:286
NvBlastFractureBuffers
Definition: NvBlastTypes.h:468
Nv::Blast::Actor
Definition: NvBlastActor.h:58
Nv::Blast::FamilyHeader::m_runtimePlaceholder
uint64_t m_runtimePlaceholder
Definition: NvBlastFamily.h:149
Nv::Blast::Asset::getUpperSupportChunkCount
uint32_t getUpperSupportChunkCount() const
Definition: NvBlastAsset.h:265
NvBlastActor.h
Nv::Blast::Asset::m_chunkCount
uint32_t m_chunkCount
Definition: NvBlastAsset.h:192
Nv::Blast::atomicDecrement
int32_t atomicDecrement(volatile int32_t *val)
Nv::Blast::IndexDLink< uint32_t >
Nv::Blast::FamilyHeader::returnActor
void returnActor(Actor &actor)
Definition: NvBlastFamily.h:348
Nv::Blast::getFamilyMemorySize
size_t getFamilyMemorySize(const Asset *asset)
Nv::Blast::FamilyHeader::borrowActor
Actor * borrowActor(uint32_t index)
Definition: NvBlastFamily.h:333
Nv
Definition: NvBlastArray.h:37
NvBlastPreprocessor.h
Nv::Blast::Asset
Definition: NvBlastAsset.h:45
Nv::Blast::FamilyHeader::fractureInPlaceEvents
void fractureInPlaceEvents(uint32_t chunkFractureCount, NvBlastChunkFractureData *inoutbuffer, uint32_t eventsSize, uint32_t *count, Actor *filterActor, NvBlastLog logFn)
Nv::Blast::FamilyHeader::getGetChunkActorIndex
uint32_t getGetChunkActorIndex(uint32_t chunkIndex) const
Definition: NvBlastFamily.h:382