NvBlastAsset.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 NVBLASTASSET_H
30 #define NVBLASTASSET_H
31 
32 
33 #include "NvBlastSupportGraph.h"
34 #include "NvBlast.h"
35 #include "NvBlastAssert.h"
36 #include "NvBlastIndexFns.h"
37 #include "NvBlastChunkHierarchy.h"
38 
39 
40 namespace Nv
41 {
42 namespace Blast
43 {
44 
45 class Asset : public NvBlastAsset
46 {
47 public:
48 
53  {
54  enum Enum
55  {
56  Parent = (1 << 0),
57  Support = (1 << 1),
58  SuperSupport = (1 << 2),
59 
60  // Combinations
62  };
63  };
64 
65 
76  static Asset* create(void* mem, const NvBlastAssetDesc* desc, void* scratch, NvBlastLog logFn);
77 
84  static size_t getMemorySize(const NvBlastAssetDesc* desc);
85 
94  static size_t createRequiredScratch(const NvBlastAssetDesc* desc);
95 
96 
102  uint32_t getUpperSupportChunkCount() const;
103 
109  uint32_t getLowerSupportChunkCount() const;
110 
116  uint32_t getBondCount() const;
117 
123  uint32_t getHierarchyCount() const;
124 
132  uint32_t getContiguousLowerSupportIndex(uint32_t chunkIndex) const;
133 
134 
135  // Static functions
136 
156  static bool ensureExactSupportCoverage(uint32_t& supportChunkCount, uint32_t& leafChunkCount, char* chunkAnnotation, uint32_t chunkCount, NvBlastChunkDesc* chunkDescs, bool testOnly, NvBlastLog logFn);
157 
174  static bool testForValidChunkOrder(uint32_t chunkCount, const NvBlastChunkDesc* chunkDescs, const char* chunkAnnotation, void* scratch);
175 
176 
178 
183 
188 
192  uint32_t m_chunkCount;
193 
198 
203 
208 
212  uint32_t m_bondCount;
213 
219  NvBlastBlockArrayData(NvBlastChunk, m_chunksOffset, getChunks, m_chunkCount);
220 
229  NvBlastBlockArrayData(NvBlastBond, m_bondsOffset, getBonds, m_bondCount);
230 
237  NvBlastBlockArrayData(uint32_t, m_subtreeLeafChunkCountsOffset, getSubtreeLeafChunkCounts, m_chunkCount);
238 
244  NvBlastBlockArrayData(uint32_t, m_chunkToGraphNodeMapOffset, getChunkToGraphNodeMap, m_chunkCount);
245 
246 
248 
254  {
255  public:
257  DepthFirstIt(const Asset& asset, uint32_t startChunkIndex, bool upperSupportOnly = false) :
258  ChunkDepthFirstIt(asset.getChunks(), startChunkIndex, upperSupportOnly ? asset.getUpperSupportChunkCount() : asset.m_chunkCount) {}
259  };
260 };
261 
262 
264 
266 {
268 }
269 
270 
272 {
274 }
275 
276 
278 {
279  NVBLAST_ASSERT((m_graph.getAdjacencyPartition()[m_graph.m_nodeCount] & 1) == 0); // The bidirectional graph data should have an even number of edges
280  return m_graph.getAdjacencyPartition()[m_graph.m_nodeCount] / 2; // Directional bonds, divide by two
281 }
282 
283 
285 {
286  const NvBlastChunk* chunks = getChunks();
287  for (uint32_t i = 0; i < m_chunkCount; ++i)
288  {
289  if (!isInvalidIndex(chunks[i].parentChunkIndex))
290  {
291  return i;
292  }
293  }
294  return m_chunkCount;
295 }
296 
297 
298 NV_INLINE uint32_t Asset::getContiguousLowerSupportIndex(uint32_t chunkIndex) const
299 {
300  NVBLAST_ASSERT(chunkIndex < m_chunkCount);
301 
302  return chunkIndex < m_firstSubsupportChunkIndex ? getChunkToGraphNodeMap()[chunkIndex] : (chunkIndex - m_firstSubsupportChunkIndex + m_graph.m_nodeCount);
303 }
304 
305 
306 //JDM: Expose this so serialization layer can use it.
307 NVBLAST_API Asset* initializeAsset(void* mem, NvBlastID id, uint32_t chunkCount, uint32_t graphNodeCount, uint32_t leafChunkCount, uint32_t firstSubsupportChunkIndex, uint32_t bondCount, NvBlastLog logFn);
308 
309 } // namespace Blast
310 } // namespace Nv
311 
312 
313 #endif // ifndef NVBLASTASSET_H
uint32_t m_bondCount
Definition: NvBlastAsset.h:212
static size_t getMemorySize(const NvBlastAssetDesc *desc)
Definition: NvBlastSupportGraph.h:76
Definition: NvBlastTypes.h:189
Enum
Definition: NvBlastAsset.h:54
Definition: NvBlastChunkHierarchy.h:49
Definition: NvBlastAsset.h:52
uint32_t getBondCount() const
Definition: NvBlastAsset.h:277
Definition: NvBlastTypes.h:345
static bool testForValidChunkOrder(uint32_t chunkCount, const NvBlastChunkDesc *chunkDescs, const char *chunkAnnotation, void *scratch)
NV_INLINE bool isInvalidIndex(T index)
Definition: NvBlastIndexFns.h:57
uint32_t m_leafChunkCount
Definition: NvBlastAsset.h:202
Definition: NvBlastAsset.h:56
void(* NvBlastLog)(int type, const char *msg, const char *file, int line)
Definition: NvBlastTypes.h:63
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
static bool ensureExactSupportCoverage(uint32_t &supportChunkCount, uint32_t &leafChunkCount, char *chunkAnnotation, uint32_t chunkCount, NvBlastChunkDesc *chunkDescs, bool testOnly, NvBlastLog logFn)
static size_t createRequiredScratch(const NvBlastAssetDesc *desc)
Definition: NvBlastTypes.h:98
#define NVBLAST_API
Definition: NvBlastPreprocessor.h:37
uint32_t m_firstSubsupportChunkIndex
Definition: NvBlastAsset.h:207
DepthFirstIt(const Asset &asset, uint32_t startChunkIndex, bool upperSupportOnly=false)
Definition: NvBlastAsset.h:257
Definition: NvBlastAsset.h:253
NVBLAST_API Asset * initializeAsset(void *mem, NvBlastID id, uint32_t chunkCount, uint32_t graphNodeCount, uint32_t leafChunkCount, uint32_t firstSubsupportChunkIndex, uint32_t bondCount, NvBlastLog logFn)
#define NV_INLINE
Definition: NvPreprocessor.h:350
uint32_t m_nodeCount
Definition: NvBlastSupportGraph.h:81
Definition: NvBlastTypes.h:69
uint32_t getContiguousLowerSupportIndex(uint32_t chunkIndex) const
Definition: NvBlastAsset.h:298
uint32_t getLowerSupportChunkCount() const
Definition: NvBlastAsset.h:271
NvBlastDataBlock m_header
Definition: NvBlastAsset.h:182
Definition: NvBlastTypes.h:292
Definition: NvBlastTypes.h:152
SupportGraph m_graph
Definition: NvBlastAsset.h:197
Definition: NvBlastTypes.h:286
static Asset * create(void *mem, const NvBlastAssetDesc *desc, void *scratch, NvBlastLog logFn)
NvBlastBlockArrayData(NvBlastChunk, m_chunksOffset, getChunks, m_chunkCount)
NvBlastID m_ID
Definition: NvBlastAsset.h:187
uint32_t getUpperSupportChunkCount() const
Definition: NvBlastAsset.h:265
uint32_t getHierarchyCount() const
Definition: NvBlastAsset.h:284
uint32_t m_chunkCount
Definition: NvBlastAsset.h:192
Definition: NvBlastAsset.h:57
Definition: NvBlastArray.h:37
Definition: NvBlastAsset.h:45