Main Page Class List Class Members

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
52 struct ChunkAnnotation
53 {
54 enum Enum
55 {
56 Parent = (1 << 0),
57 Support = (1 << 1),
58 SuperSupport = (1 << 2),
59
60 // Combinations
61 UpperSupport = Support | SuperSupport
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
182 NvBlastDataBlock m_header;
183
187 NvBlastID m_ID;
188
192 uint32_t m_chunkCount;
193
197 SupportGraph m_graph;
198
202 uint32_t m_leafChunkCount;
203
207 uint32_t m_firstSubsupportChunkIndex;
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
253 class DepthFirstIt : public ChunkDepthFirstIt
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
265 NV_INLINE uint32_t Asset::getUpperSupportChunkCount() const
266 {
267 return m_firstSubsupportChunkIndex;
268 }
269
270
271 NV_INLINE uint32_t Asset::getLowerSupportChunkCount() const
272 {
273 return m_graph.m_nodeCount + (m_chunkCount - m_firstSubsupportChunkIndex);
274 }
275
276
277 NV_INLINE uint32_t Asset::getBondCount() const
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
284 NV_INLINE uint32_t Asset::getHierarchyCount() const
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
Nv::Blast::Asset::m_bondCount
uint32_t m_bondCount
Definition: NvBlastAsset.h:212
NvBlast.h
Nv::Blast::Asset::getMemorySize
static size_t getMemorySize(const NvBlastAssetDesc *desc)
Nv::Blast::SupportGraph
Definition: NvBlastSupportGraph.h:76
NvBlastBond
Definition: NvBlastTypes.h:189
Nv::Blast::Asset::ChunkAnnotation::Enum
Enum
Definition: NvBlastAsset.h:54
Nv::Blast::ChunkDepthFirstIt
Definition: NvBlastChunkHierarchy.h:49
Nv::Blast::Asset::ChunkAnnotation
Definition: NvBlastAsset.h:52
Nv::Blast::Asset::getBondCount
uint32_t getBondCount() const
Definition: NvBlastAsset.h:277
NvBlastAssetDesc
Definition: NvBlastTypes.h:345
NvBlastSupportGraph.h
Nv::Blast::Asset::testForValidChunkOrder
static bool testForValidChunkOrder(uint32_t chunkCount, const NvBlastChunkDesc *chunkDescs, const char *chunkAnnotation, void *scratch)
Nv::Blast::isInvalidIndex
NV_INLINE bool isInvalidIndex(T index)
Definition: NvBlastIndexFns.h:57
Nv::Blast::Asset::m_leafChunkCount
uint32_t m_leafChunkCount
Definition: NvBlastAsset.h:202
Nv::Blast::Asset::ChunkAnnotation::Parent
Definition: NvBlastAsset.h:56
NvBlastLog
void(* NvBlastLog)(int type, const char *msg, const char *file, int line)
Definition: NvBlastTypes.h:63
NVBLAST_ASSERT
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
Nv::Blast::Asset::ensureExactSupportCoverage
static bool ensureExactSupportCoverage(uint32_t &supportChunkCount, uint32_t &leafChunkCount, char *chunkAnnotation, uint32_t chunkCount, NvBlastChunkDesc *chunkDescs, bool testOnly, NvBlastLog logFn)
Nv::Blast::Asset::createRequiredScratch
static size_t createRequiredScratch(const NvBlastAssetDesc *desc)
NvBlastIndexFns.h
NvBlastDataBlock
Definition: NvBlastTypes.h:98
NvBlastChunkHierarchy.h
NVBLAST_API
#define NVBLAST_API
Definition: NvBlastPreprocessor.h:37
Nv::Blast::Asset::m_firstSubsupportChunkIndex
uint32_t m_firstSubsupportChunkIndex
Definition: NvBlastAsset.h:207
Nv::Blast::Asset::DepthFirstIt::DepthFirstIt
DepthFirstIt(const Asset &asset, uint32_t startChunkIndex, bool upperSupportOnly=false)
Definition: NvBlastAsset.h:257
Nv::Blast::Asset::DepthFirstIt
Definition: NvBlastAsset.h:253
Nv::Blast::initializeAsset
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)
NV_INLINE
#define NV_INLINE
Definition: NvPreprocessor.h:350
Nv::Blast::SupportGraph::m_nodeCount
uint32_t m_nodeCount
Definition: NvBlastSupportGraph.h:81
NvBlastID
Definition: NvBlastTypes.h:69
Nv::Blast::Asset::getContiguousLowerSupportIndex
uint32_t getContiguousLowerSupportIndex(uint32_t chunkIndex) const
Definition: NvBlastAsset.h:298
Nv::Blast::Asset::getLowerSupportChunkCount
uint32_t getLowerSupportChunkCount() const
Definition: NvBlastAsset.h:271
Nv::Blast::Asset::m_header
NvBlastDataBlock m_header
Definition: NvBlastAsset.h:182
Nv::Blast::Asset::ChunkAnnotation::UpperSupport
Definition: NvBlastAsset.h:61
NvBlastChunkDesc
Definition: NvBlastTypes.h:292
NvBlastChunk
Definition: NvBlastTypes.h:152
Nv::Blast::Asset::m_graph
SupportGraph m_graph
Definition: NvBlastAsset.h:197
NvBlastAsset
Definition: NvBlastTypes.h:286
Nv::Blast::Asset::create
static Asset * create(void *mem, const NvBlastAssetDesc *desc, void *scratch, NvBlastLog logFn)
Nv::Blast::Asset::ChunkAnnotation::SuperSupport
Definition: NvBlastAsset.h:58
Nv::Blast::Asset::NvBlastBlockArrayData
NvBlastBlockArrayData(NvBlastChunk, m_chunksOffset, getChunks, m_chunkCount)
Nv::Blast::Asset::m_ID
NvBlastID m_ID
Definition: NvBlastAsset.h:187
Nv::Blast::Asset::getUpperSupportChunkCount
uint32_t getUpperSupportChunkCount() const
Definition: NvBlastAsset.h:265
Nv::Blast::Asset::getHierarchyCount
uint32_t getHierarchyCount() const
Definition: NvBlastAsset.h:284
Nv::Blast::Asset::m_chunkCount
uint32_t m_chunkCount
Definition: NvBlastAsset.h:192
Nv::Blast::Asset::ChunkAnnotation::Support
Definition: NvBlastAsset.h:57
Nv
Definition: NvBlastArray.h:37
NvBlastAssert.h
Nv::Blast::Asset
Definition: NvBlastAsset.h:45