00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTASSET_H
00030 #define NVBLASTASSET_H
00031
00032
00033 #include "NvBlastSupportGraph.h"
00034 #include "NvBlast.h"
00035 #include "NvBlastAssert.h"
00036 #include "NvBlastIndexFns.h"
00037 #include "NvBlastChunkHierarchy.h"
00038
00039
00040 namespace Nv
00041 {
00042 namespace Blast
00043 {
00044
00045 class Asset : public NvBlastAsset
00046 {
00047 public:
00048
00052 struct ChunkAnnotation
00053 {
00054 enum Enum
00055 {
00056 Parent = (1 << 0),
00057 Support = (1 << 1),
00058 SuperSupport = (1 << 2),
00059
00060
00061 UpperSupport = Support | SuperSupport
00062 };
00063 };
00064
00065
00076 static Asset* create(void* mem, const NvBlastAssetDesc* desc, void* scratch, NvBlastLog logFn);
00077
00084 static size_t getMemorySize(const NvBlastAssetDesc* desc);
00085
00094 static size_t createRequiredScratch(const NvBlastAssetDesc* desc);
00095
00096
00102 uint32_t getUpperSupportChunkCount() const;
00103
00109 uint32_t getLowerSupportChunkCount() const;
00110
00116 uint32_t getBondCount() const;
00117
00123 uint32_t getHierarchyCount() const;
00124
00132 uint32_t getContiguousLowerSupportIndex(uint32_t chunkIndex) const;
00133
00134
00135
00136
00156 static bool ensureExactSupportCoverage(uint32_t& supportChunkCount, uint32_t& leafChunkCount, char* chunkAnnotation, uint32_t chunkCount, NvBlastChunkDesc* chunkDescs, bool testOnly, NvBlastLog logFn);
00157
00174 static bool testForValidChunkOrder(uint32_t chunkCount, const NvBlastChunkDesc* chunkDescs, const char* chunkAnnotation, void* scratch);
00175
00176
00178
00182 NvBlastDataBlock m_header;
00183
00187 NvBlastID m_ID;
00188
00192 uint32_t m_chunkCount;
00193
00197 SupportGraph m_graph;
00198
00202 uint32_t m_leafChunkCount;
00203
00207 uint32_t m_firstSubsupportChunkIndex;
00208
00212 uint32_t m_bondCount;
00213
00219 NvBlastBlockArrayData(NvBlastChunk, m_chunksOffset, getChunks, m_chunkCount);
00220
00229 NvBlastBlockArrayData(NvBlastBond, m_bondsOffset, getBonds, m_bondCount);
00230
00237 NvBlastBlockArrayData(uint32_t, m_subtreeLeafChunkCountsOffset, getSubtreeLeafChunkCounts, m_chunkCount);
00238
00244 NvBlastBlockArrayData(uint32_t, m_chunkToGraphNodeMapOffset, getChunkToGraphNodeMap, m_chunkCount);
00245
00246
00248
00253 class DepthFirstIt : public ChunkDepthFirstIt
00254 {
00255 public:
00257 DepthFirstIt(const Asset& asset, uint32_t startChunkIndex, bool upperSupportOnly = false) :
00258 ChunkDepthFirstIt(asset.getChunks(), startChunkIndex, upperSupportOnly ? asset.getUpperSupportChunkCount() : asset.m_chunkCount) {}
00259 };
00260 };
00261
00262
00264
00265 NV_INLINE uint32_t Asset::getUpperSupportChunkCount() const
00266 {
00267 return m_firstSubsupportChunkIndex;
00268 }
00269
00270
00271 NV_INLINE uint32_t Asset::getLowerSupportChunkCount() const
00272 {
00273 return m_graph.m_nodeCount + (m_chunkCount - m_firstSubsupportChunkIndex);
00274 }
00275
00276
00277 NV_INLINE uint32_t Asset::getBondCount() const
00278 {
00279 NVBLAST_ASSERT((m_graph.getAdjacencyPartition()[m_graph.m_nodeCount] & 1) == 0);
00280 return m_graph.getAdjacencyPartition()[m_graph.m_nodeCount] / 2;
00281 }
00282
00283
00284 NV_INLINE uint32_t Asset::getHierarchyCount() const
00285 {
00286 const NvBlastChunk* chunks = getChunks();
00287 for (uint32_t i = 0; i < m_chunkCount; ++i)
00288 {
00289 if (!isInvalidIndex(chunks[i].parentChunkIndex))
00290 {
00291 return i;
00292 }
00293 }
00294 return m_chunkCount;
00295 }
00296
00297
00298 NV_INLINE uint32_t Asset::getContiguousLowerSupportIndex(uint32_t chunkIndex) const
00299 {
00300 NVBLAST_ASSERT(chunkIndex < m_chunkCount);
00301
00302 return chunkIndex < m_firstSubsupportChunkIndex ? getChunkToGraphNodeMap()[chunkIndex] : (chunkIndex - m_firstSubsupportChunkIndex + m_graph.m_nodeCount);
00303 }
00304
00305
00306
00307 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);
00308
00309 }
00310 }
00311
00312
00313 #endif // ifndef NVBLASTASSET_H