diff options
Diffstat (limited to 'sdk/toolkit/source')
23 files changed, 958 insertions, 1600 deletions
diff --git a/sdk/toolkit/source/NvBlastTkActorImpl.cpp b/sdk/toolkit/source/NvBlastTkActorImpl.cpp index 028e0f1..e6c6ec7 100644 --- a/sdk/toolkit/source/NvBlastTkActorImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkActorImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastPreprocessor.h" @@ -22,12 +40,8 @@ #include "NvBlastMemory.h" #include "Px.h" -#include "PxFileBuf.h" -#include "PxAllocatorCallback.h" #include "PxTransform.h" -using namespace physx::general_PxIOStream2; - namespace Nv { @@ -41,11 +55,11 @@ TkActorImpl* TkActorImpl::create(const TkActorDesc& desc) TkFamilyImpl* family = TkFamilyImpl::create(asset); NvBlastFamily* familyLL = family->getFamilyLLInternal(); - TkArray<char>::type scratch((uint32_t)NvBlastFamilyGetRequiredScratchForCreateFirstActor(familyLL, TkFrameworkImpl::get()->log)); - NvBlastActor* actorLL = NvBlastFamilyCreateFirstActor(familyLL, &desc, scratch.begin(), TkFrameworkImpl::get()->log); + Array<char>::type scratch((uint32_t)NvBlastFamilyGetRequiredScratchForCreateFirstActor(familyLL, logLL)); + NvBlastActor* actorLL = NvBlastFamilyCreateFirstActor(familyLL, &desc, scratch.begin(), logLL); if (actorLL == nullptr) { - NVBLASTTK_LOG_ERROR("TkActorImpl::create: low-level actor could not be created."); + NVBLAST_LOG_ERROR("TkActorImpl::create: low-level actor could not be created."); return nullptr; } @@ -126,7 +140,7 @@ void TkActorImpl::release() if (m_actorLL != nullptr) { - NvBlastActorDeactivate(m_actorLL, TkFrameworkImpl::get()->log); + NvBlastActorDeactivate(m_actorLL, logLL); } if (m_family != nullptr) @@ -170,13 +184,13 @@ TkGroup* TkActorImpl::removeFromGroup() { if (m_group == nullptr) { - NVBLASTTK_LOG_WARNING("TkActorImpl::removeFromGroup: actor not in a group."); + NVBLAST_LOG_WARNING("TkActorImpl::removeFromGroup: actor not in a group."); return nullptr; } if (m_group->isProcessing()) { - NVBLASTTK_LOG_ERROR("TkActorImpl::removeFromGroup: cannot alter Group while processing."); + NVBLAST_LOG_ERROR("TkActorImpl::removeFromGroup: cannot alter Group while processing."); return nullptr; } @@ -200,37 +214,37 @@ const TkAsset* TkActorImpl::getAsset() const uint32_t TkActorImpl::getVisibleChunkCount() const { - return NvBlastActorGetVisibleChunkCount(m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetVisibleChunkCount(m_actorLL, logLL); } uint32_t TkActorImpl::getVisibleChunkIndices(uint32_t* visibleChunkIndices, uint32_t visibleChunkIndicesSize) const { - return NvBlastActorGetVisibleChunkIndices(visibleChunkIndices, visibleChunkIndicesSize, m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetVisibleChunkIndices(visibleChunkIndices, visibleChunkIndicesSize, m_actorLL, logLL); } uint32_t TkActorImpl::getGraphNodeCount() const { - return NvBlastActorGetGraphNodeCount(m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetGraphNodeCount(m_actorLL, logLL); } uint32_t TkActorImpl::getGraphNodeIndices(uint32_t* graphNodeIndices, uint32_t graphNodeIndicesSize) const { - return NvBlastActorGetGraphNodeIndices(graphNodeIndices, graphNodeIndicesSize, m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetGraphNodeIndices(graphNodeIndices, graphNodeIndicesSize, m_actorLL, logLL); } const float* TkActorImpl::getBondHealths() const { - return NvBlastActorGetBondHealths(m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetBondHealths(m_actorLL, logLL); } uint32_t TkActorImpl::getSplitMaxActorCount() const { - return NvBlastActorGetMaxActorCountForSplit(m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetMaxActorCountForSplit(m_actorLL, logLL); } @@ -268,21 +282,21 @@ TkActorImpl::operator Nv::Blast::TkActorData() const void TkActorImpl::damage(const NvBlastDamageProgram& program, const NvBlastProgramParams* programParams) { - PERF_SCOPE_L("TkActor::damage"); + BLAST_PROFILE_SCOPE_L("TkActor::damage"); if (m_group == nullptr) { - NVBLASTTK_LOG_WARNING("TkActor::damage: actor is not in a group, cannot fracture."); + NVBLAST_LOG_WARNING("TkActor::damage: actor is not in a group, cannot fracture."); return; } if (m_group->isProcessing()) { - NVBLASTTK_LOG_WARNING("TkActor::damage: group is being processed, cannot fracture this actor."); + NVBLAST_LOG_WARNING("TkActor::damage: group is being processed, cannot fracture this actor."); return; } - if (NvBlastActorCanFracture(m_actorLL, TkFrameworkImpl::get()->log)) + if (NvBlastActorCanFracture(m_actorLL, logLL)) { m_damageBuffer.pushBack(DamageData(program, programParams)); makePending(); @@ -298,21 +312,21 @@ void TkActorImpl::damage(const NvBlastDamageProgram& program, const void* damage void TkActorImpl::damage(const NvBlastDamageProgram& program, const void* damageDesc, uint32_t descSize, const void* material) { - PERF_SCOPE_L("TkActor::damage"); + BLAST_PROFILE_SCOPE_L("TkActor::damage"); if (m_group == nullptr) { - NVBLASTTK_LOG_WARNING("TkActor::damage: actor is not in a group, cannot fracture."); + NVBLAST_LOG_WARNING("TkActor::damage: actor is not in a group, cannot fracture."); return; } if (m_group->isProcessing()) { - NVBLASTTK_LOG_WARNING("TkActor::damage: group is being processed, cannot fracture this actor."); + NVBLAST_LOG_WARNING("TkActor::damage: group is being processed, cannot fracture this actor."); return; } - if (NvBlastActorCanFracture(m_actorLL, TkFrameworkImpl::get()->log)) + if (NvBlastActorCanFracture(m_actorLL, logLL)) { bool appended = false; for (auto& damageData : m_damageBuffer) @@ -336,30 +350,30 @@ void TkActorImpl::damage(const NvBlastDamageProgram& program, const void* damage void TkActorImpl::generateFracture(NvBlastFractureBuffers* commands, const NvBlastDamageProgram& program, const NvBlastProgramParams* programParams) const { - PERF_SCOPE_L("TkActor::generateFracture"); + BLAST_PROFILE_SCOPE_L("TkActor::generateFracture"); if (m_group && m_group->isProcessing()) { - NVBLASTTK_LOG_WARNING("TkActor::generateFracture: group is being processed, cannot fracture this actor."); + NVBLAST_LOG_WARNING("TkActor::generateFracture: group is being processed, cannot fracture this actor."); return; } // const context, must make m_timers mutable otherwise - NvBlastActorGenerateFracture(commands, m_actorLL, program, programParams, TkFrameworkImpl::get()->log, const_cast<NvBlastTimers*>(&m_timers)); + NvBlastActorGenerateFracture(commands, m_actorLL, program, programParams, logLL, const_cast<NvBlastTimers*>(&m_timers)); } void TkActorImpl::applyFracture(NvBlastFractureBuffers* eventBuffers, const NvBlastFractureBuffers* commands) { - PERF_SCOPE_L("TkActor::applyFracture"); + BLAST_PROFILE_SCOPE_L("TkActor::applyFracture"); if (m_group && m_group->isProcessing()) { - NVBLASTTK_LOG_WARNING("TkActor::applyFracture: group is being processed, cannot fracture this actor."); + NVBLAST_LOG_WARNING("TkActor::applyFracture: group is being processed, cannot fracture this actor."); return; } - NvBlastActorApplyFracture(eventBuffers, m_actorLL, commands, TkFrameworkImpl::get()->log, &m_timers); + NvBlastActorApplyFracture(eventBuffers, m_actorLL, commands, logLL, &m_timers); if (commands->chunkFractureCount > 0 || commands->bondFractureCount > 0) { @@ -393,6 +407,12 @@ uint32_t TkActorImpl::getJoints(TkJoint** joints, uint32_t jointsSize) const } +bool TkActorImpl::isBoundToWorld() const +{ + return NvBlastActorIsBoundToWorld(m_actorLL, logLL); +} + + //////// TkActorImpl::DamageData methods //////// static bool operator==(const NvBlastDamageProgram& lhs, const NvBlastDamageProgram& rhs) diff --git a/sdk/toolkit/source/NvBlastTkActorImpl.h b/sdk/toolkit/source/NvBlastTkActorImpl.h index 4d65660..33fde68 100644 --- a/sdk/toolkit/source/NvBlastTkActorImpl.h +++ b/sdk/toolkit/source/NvBlastTkActorImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKACTORIMPL_H #define NVBLASTTKACTORIMPL_H @@ -98,6 +116,8 @@ public: virtual uint32_t getJointCount() const override; virtual uint32_t getJoints(TkJoint** joints, uint32_t jointsSize) const override; + + virtual bool isBoundToWorld() const override; // End TkActor // Begin TkObject @@ -215,7 +235,7 @@ private: const void* m_material; //!< for Buffered type const NvBlastProgramParams* m_programParams; //!< for Plain type }; - TkArray<char>::type m_damageDescs; + Array<char>::type m_damageDescs; uint32_t m_damageDescCount; }; @@ -247,7 +267,7 @@ private: TkGroupImpl* m_group; //!< The TkGroupImpl (if any) to which this actor belongs uint32_t m_groupJobIndex; //!< The index of this actor's job within its group's job list physx::PxFlags<TkActorFlag::Enum, char> m_flags; //!< Status flags for this actor - TkArray<DamageData>::type m_damageBuffer; //!< Buffered damage input + Array<DamageData>::type m_damageBuffer; //!< Buffered damage input uint32_t m_jointCount; //!< The number of joints referenced in m_jointList DList m_jointList; //!< A doubly-linked list of joint references @@ -276,7 +296,7 @@ NV_INLINE TkFamilyImpl& TkActorImpl::getFamilyImpl() const NV_INLINE uint32_t TkActorImpl::getIndexInternal() const { NVBLAST_ASSERT(isActive()); - return NvBlastActorGetIndex(m_actorLL, TkFrameworkImpl::get()->log); + return NvBlastActorGetIndex(m_actorLL, logLL); } @@ -343,7 +363,7 @@ NV_INLINE void TkActorImpl::DamageData::generateFracture(NvBlastFractureBuffers* { if (getType() == Plain) { - NvBlastActorGenerateFracture(commandBuffers, actorLL, m_program, m_programParams, TkFrameworkImpl::get()->log, timers); + NvBlastActorGenerateFracture(commandBuffers, actorLL, m_program, m_programParams, logLL, timers); } else { @@ -352,7 +372,7 @@ NV_INLINE void TkActorImpl::DamageData::generateFracture(NvBlastFractureBuffers* m_damageDescCount, m_material, }; - NvBlastActorGenerateFracture(commandBuffers, actorLL, m_program, &programParams, TkFrameworkImpl::get()->log, timers); + NvBlastActorGenerateFracture(commandBuffers, actorLL, m_program, &programParams, logLL, timers); } } diff --git a/sdk/toolkit/source/NvBlastTkAllocator.cpp b/sdk/toolkit/source/NvBlastTkAllocator.cpp deleted file mode 100644 index b1c2c65..0000000 --- a/sdk/toolkit/source/NvBlastTkAllocator.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ - -#include "NvBlastTkAllocator.h" - - -namespace Nv -{ -namespace Blast -{ - -physx::PxAllocatorCallback* TkAllocator::s_allocatorCallback = nullptr; - -} // namespace Blast -} // namespace Nv diff --git a/sdk/toolkit/source/NvBlastTkAllocator.h b/sdk/toolkit/source/NvBlastTkAllocator.h deleted file mode 100644 index abc7b16..0000000 --- a/sdk/toolkit/source/NvBlastTkAllocator.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ - -#ifndef NVBLASTTKALLOCATOR_H -#define NVBLASTTKALLOCATOR_H - -#include "PxAllocatorCallback.h" - - -namespace Nv -{ -namespace Blast -{ - -/** -An allocator which can be used in PxShared containers. -*/ -class TkAllocator -{ -public: - TkAllocator(const char* = 0) - { - } - - void* allocate(size_t size, const char* file, int line) - { - return s_allocatorCallback->allocate(size, nullptr, file, line); - } - - void deallocate(void* ptr) - { - return s_allocatorCallback->deallocate(ptr); - } - - static physx::PxAllocatorCallback* s_allocatorCallback; -}; - -} // namespace Blast -} // namespace Nv - - -#endif // #ifndef NVBLASTTKALLOCATOR_H diff --git a/sdk/toolkit/source/NvBlastTkArray.h b/sdk/toolkit/source/NvBlastTkArray.h deleted file mode 100644 index c07dc11..0000000 --- a/sdk/toolkit/source/NvBlastTkArray.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ - -#ifndef NVBLASTTKARRAY_H -#define NVBLASTTKARRAY_H - - -#include "NvBlastTkAllocator.h" -#include "PsInlineArray.h" - - -namespace Nv -{ -namespace Blast -{ - -template <class T> -struct TkArray -{ - typedef physx::shdfnd::Array<T, TkAllocator> type; -}; - - -template <class T, uint32_t N> -struct TkInlineArray -{ - typedef physx::shdfnd::InlineArray<T, N, TkAllocator> type; -}; - -} // namespace Blast -} // namespace Nv - - -#endif // #ifndef NVBLASTTKARRAY_H diff --git a/sdk/toolkit/source/NvBlastTkAssetImpl.cpp b/sdk/toolkit/source/NvBlastTkAssetImpl.cpp index 577d46b..2088ce8 100644 --- a/sdk/toolkit/source/NvBlastTkAssetImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkAssetImpl.cpp @@ -1,12 +1,29 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. #include "NvBlastTkFrameworkImpl.h" @@ -17,11 +34,6 @@ #include "NvBlastMemory.h" #include "Px.h" -#include "PxFileBuf.h" -#include "PxAllocatorCallback.h" - - -using namespace physx::general_PxIOStream2; namespace Nv @@ -31,7 +43,7 @@ namespace Blast //////// Static data //////// -NVBLASTTK_DEFINE_TYPE_SERIALIZABLE(Asset); +NVBLASTTK_DEFINE_TYPE_IDENTIFIABLE(Asset); //////// Member functions //////// @@ -52,7 +64,7 @@ TkAssetImpl::~TkAssetImpl() { if (m_assetLL != nullptr && m_ownsAsset) { - TkFrameworkImpl::get()->free(m_assetLL); + NVBLAST_FREE(m_assetLL); } } @@ -65,43 +77,43 @@ const NvBlastAsset* TkAssetImpl::getAssetLL() const uint32_t TkAssetImpl::getChunkCount() const { - return NvBlastAssetGetChunkCount(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetChunkCount(m_assetLL, logLL); } uint32_t TkAssetImpl::getLeafChunkCount() const { - return NvBlastAssetGetLeafChunkCount(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetLeafChunkCount(m_assetLL, logLL); } uint32_t TkAssetImpl::getBondCount() const { - return NvBlastAssetGetBondCount(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetBondCount(m_assetLL, logLL); } const NvBlastChunk* TkAssetImpl::getChunks() const { - return NvBlastAssetGetChunks(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetChunks(m_assetLL, logLL); } const NvBlastBond* TkAssetImpl::getBonds() const { - return NvBlastAssetGetBonds(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetBonds(m_assetLL, logLL); } const NvBlastSupportGraph TkAssetImpl::getGraph() const { - return NvBlastAssetGetSupportGraph(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetSupportGraph(m_assetLL, logLL); } uint32_t TkAssetImpl::getDataSize() const { - return NvBlastAssetGetSize(m_assetLL, TkFrameworkImpl::get()->log); + return NvBlastAssetGetSize(m_assetLL, logLL); } @@ -124,7 +136,7 @@ void TkAssetImpl::release() if (num) { - TkArray<TkIdentifiable*>::type dependents(num); + Array<TkIdentifiable*>::type dependents(num); TkFrameworkImpl::get()->getObjects(dependents.begin(), dependents.size(), tkType); for (TkObject* o : dependents) @@ -137,93 +149,22 @@ void TkAssetImpl::release() } } - NVBLASTTK_DELETE(this, TkAssetImpl); -} - - -bool TkAssetImpl::serialize(PxFileBuf& stream) const -{ - TkFrameworkImpl::get()->serializeHeader(*this, stream); - - // Asset data - const uint32_t assetSize = NvBlastAssetGetSize(m_assetLL, TkFrameworkImpl::get()->log); - stream.storeDword(assetSize); - stream.write(m_assetLL, assetSize); - - // Joint descs - stream.storeDword((uint32_t)m_jointDescs.size()); - for (uint32_t i = 0; i < m_jointDescs.size(); ++i) - { - const TkAssetJointDesc& jointDesc = m_jointDescs[i]; - stream.storeDword(jointDesc.nodeIndices[0]); - stream.storeDword(jointDesc.nodeIndices[1]); - stream.storeFloat(jointDesc.attachPositions[0].x); - stream.storeFloat(jointDesc.attachPositions[0].y); - stream.storeFloat(jointDesc.attachPositions[0].z); - stream.storeFloat(jointDesc.attachPositions[1].x); - stream.storeFloat(jointDesc.attachPositions[1].y); - stream.storeFloat(jointDesc.attachPositions[1].z); - } - - return true; + NVBLAST_DELETE(this, TkAssetImpl); } //////// Static functions //////// -TkSerializable* TkAssetImpl::deserialize(PxFileBuf& stream, const NvBlastID& id) -{ - // Allocate - TkAssetImpl* asset = NVBLASTTK_NEW(TkAssetImpl)(id); - if (asset == nullptr) - { - NVBLASTTK_LOG_ERROR("TkAssetImpl::deserialize: asset allocation failed."); - return nullptr; - } - - // Asset data - const uint32_t assetSize = stream.readDword(); - asset->m_assetLL = static_cast<NvBlastAsset*>(TkFrameworkImpl::get()->alloc(assetSize)); - asset->m_ownsAsset = true; - stream.read(asset->m_assetLL, assetSize); - - // Joint descs - const uint32_t jointDescCount = stream.readDword(); - asset->m_jointDescs.resize(jointDescCount); - for (uint32_t i = 0; i < asset->m_jointDescs.size(); ++i) - { - TkAssetJointDesc& jointDesc = asset->m_jointDescs[i]; - jointDesc.nodeIndices[0] = stream.readDword(); - jointDesc.nodeIndices[1] = stream.readDword(); - jointDesc.attachPositions[0].x = stream.readFloat(); - jointDesc.attachPositions[0].y = stream.readFloat(); - jointDesc.attachPositions[0].z = stream.readFloat(); - jointDesc.attachPositions[1].x = stream.readFloat(); - jointDesc.attachPositions[1].y = stream.readFloat(); - jointDesc.attachPositions[1].z = stream.readFloat(); - } - - - if (asset->m_assetLL == nullptr) - { - asset->release(); - asset = nullptr; - } - - return asset; -} - - TkAssetImpl* TkAssetImpl::create(const TkAssetDesc& desc) { - TkAssetImpl* asset = NVBLASTTK_NEW(TkAssetImpl); + TkAssetImpl* asset = NVBLAST_NEW(TkAssetImpl); - TkArray<char>::type scratch((uint32_t)NvBlastGetRequiredScratchForCreateAsset(&desc, TkFrameworkImpl::get()->log)); - void* mem = TkFrameworkImpl::get()->alloc(NvBlastGetAssetMemorySize(&desc, TkFrameworkImpl::get()->log)); - asset->m_assetLL = NvBlastCreateAsset(mem, &desc, scratch.begin(), TkFrameworkImpl::get()->log); + Array<char>::type scratch((uint32_t)NvBlastGetRequiredScratchForCreateAsset(&desc, logLL)); + void* mem = NVBLAST_ALLOC_NAMED(NvBlastGetAssetMemorySize(&desc, logLL), "TkAssetImpl::create"); + asset->m_assetLL = NvBlastCreateAsset(mem, &desc, scratch.begin(), logLL); if (asset->m_assetLL == nullptr) { - NVBLASTTK_LOG_ERROR("TkAssetImpl::create: low-level asset could not be created."); + NVBLAST_LOG_ERROR("TkAssetImpl::create: low-level asset could not be created."); asset->release(); return nullptr; } @@ -239,20 +180,20 @@ TkAssetImpl* TkAssetImpl::create(const TkAssetDesc& desc) const uint32_t c1 = bondDesc.chunkIndices[1]; if (c0 >= desc.chunkCount || c1 >= desc.chunkCount) { - NVBLASTTK_LOG_WARNING("TkAssetImpl::create: joint flag set for badly described bond. No joint descriptor created."); + NVBLAST_LOG_WARNING("TkAssetImpl::create: joint flag set for badly described bond. No joint descriptor created."); continue; } if (!asset->addJointDesc(c0, c1)) { - NVBLASTTK_LOG_WARNING("TkAssetImpl::create: no bond corresponds to the user-described bond indices. No joint descriptor created."); + NVBLAST_LOG_WARNING("TkAssetImpl::create: no bond corresponds to the user-described bond indices. No joint descriptor created."); } } } } asset->m_ownsAsset = true; -// asset->setID(NvBlastAssetGetID(asset->m_assetLL, TkFrameworkImpl::get()->log)); // Keeping LL and Tk IDs distinct +// asset->setID(NvBlastAssetGetID(asset->m_assetLL, logLL)); // Keeping LL and Tk IDs distinct return asset; } @@ -260,19 +201,19 @@ TkAssetImpl* TkAssetImpl::create(const TkAssetDesc& desc) TkAssetImpl* TkAssetImpl::create(const NvBlastAsset* assetLL, Nv::Blast::TkAssetJointDesc* jointDescs, uint32_t jointDescCount, bool ownsAsset) { - TkAssetImpl* asset = NVBLASTTK_NEW(TkAssetImpl); + TkAssetImpl* asset = NVBLAST_NEW(TkAssetImpl); //NOTE: Why are we passing in a const NvBlastAsset* and then discarding the const? asset->m_assetLL = const_cast<NvBlastAsset*>(assetLL); if (asset->m_assetLL == nullptr) { - NVBLASTTK_LOG_ERROR("TkAssetImpl::create: low-level asset could not be created."); + NVBLAST_LOG_ERROR("TkAssetImpl::create: low-level asset could not be created."); asset->release(); return nullptr; } asset->m_ownsAsset = ownsAsset; - asset->setID(NvBlastAssetGetID(asset->m_assetLL, TkFrameworkImpl::get()->log)); + asset->setID(NvBlastAssetGetID(asset->m_assetLL, logLL)); asset->m_jointDescs.resize(jointDescCount); for (uint32_t i = 0; i < asset->m_jointDescs.size(); ++i) @@ -290,16 +231,16 @@ bool TkAssetImpl::addJointDesc(uint32_t chunkIndex0, uint32_t chunkIndex1) return false; } - const uint32_t upperSupportChunkCount = NvBlastAssetGetFirstSubsupportChunkIndex(m_assetLL, TkFrameworkImpl::get()->log); + const uint32_t upperSupportChunkCount = NvBlastAssetGetFirstSubsupportChunkIndex(m_assetLL, logLL); if (chunkIndex0 >= upperSupportChunkCount || chunkIndex1 >= upperSupportChunkCount) { return false; } - const uint32_t* chunkToGraphNodeMap = NvBlastAssetGetChunkToGraphNodeMap(m_assetLL, TkFrameworkImpl::get()->log); + const uint32_t* chunkToGraphNodeMap = NvBlastAssetGetChunkToGraphNodeMap(m_assetLL, logLL); const uint32_t node0 = chunkToGraphNodeMap[chunkIndex0]; const uint32_t node1 = chunkToGraphNodeMap[chunkIndex1]; - const NvBlastSupportGraph graph = NvBlastAssetGetSupportGraph(m_assetLL, TkFrameworkImpl::get()->log); + const NvBlastSupportGraph graph = NvBlastAssetGetSupportGraph(m_assetLL, logLL); if (node0 >= graph.nodeCount && node1 >= graph.nodeCount) { return false; @@ -317,12 +258,12 @@ bool TkAssetImpl::addJointDesc(uint32_t chunkIndex0, uint32_t chunkIndex1) } } - if (bondIndex >= NvBlastAssetGetBondCount(m_assetLL, TkFrameworkImpl::get()->log)) + if (bondIndex >= NvBlastAssetGetBondCount(m_assetLL, logLL)) { return false; } - const NvBlastBond& bond = NvBlastAssetGetBonds(m_assetLL, TkFrameworkImpl::get()->log)[bondIndex]; + const NvBlastBond& bond = NvBlastAssetGetBonds(m_assetLL, logLL)[bondIndex]; TkAssetJointDesc jointDesc; jointDesc.attachPositions[0] = jointDesc.attachPositions[1] = physx::PxVec3(bond.centroid[0], bond.centroid[1], bond.centroid[2]); diff --git a/sdk/toolkit/source/NvBlastTkAssetImpl.h b/sdk/toolkit/source/NvBlastTkAssetImpl.h index ae68af8..491263a 100644 --- a/sdk/toolkit/source/NvBlastTkAssetImpl.h +++ b/sdk/toolkit/source/NvBlastTkAssetImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKASSETIMPL_H #define NVBLASTTKASSETIMPL_H @@ -16,7 +34,7 @@ #include "NvBlastTkJoint.h" #include "NvBlastTkAsset.h" #include "NvBlastTkTypeImpl.h" -#include "NvBlastTkArray.h" +#include "NvBlastArray.h" // Forward declarations @@ -34,28 +52,11 @@ Implementation of TkAsset NVBLASTTK_IMPL_DECLARE(Asset) { public: - /** - Enum which keeps track of the serialized data format. - */ - enum Version - { - /** Initial version */ - Initial, - - // New formats must come before Count. They should be given descriptive names with more information in comments. - - /** The number of serialized formats. */ - Count, - - /** The current version. This should always be Count-1 */ - Current = Count - 1 - }; - TkAssetImpl(); TkAssetImpl(const NvBlastID& id); ~TkAssetImpl(); - NVBLASTTK_IMPL_DEFINE_SERIALIZABLE('A', 'S', 'S', 'T'); + NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('A', 'S', 'S', 'T'); // Public methods @@ -131,7 +132,7 @@ private: bool addJointDesc(uint32_t chunkIndex0, uint32_t chunkIndex1); NvBlastAsset* m_assetLL; //!< The underlying low-level asset. - TkArray<TkAssetJointDesc>::type m_jointDescs; //!< The array of internal joint descriptors. + Array<TkAssetJointDesc>::type m_jointDescs; //!< The array of internal joint descriptors. bool m_ownsAsset; //!< Whether or not this asset should release its low-level asset upon its own release. }; diff --git a/sdk/toolkit/source/NvBlastTkCommon.h b/sdk/toolkit/source/NvBlastTkCommon.h index edc1a91..31eac7a 100644 --- a/sdk/toolkit/source/NvBlastTkCommon.h +++ b/sdk/toolkit/source/NvBlastTkCommon.h @@ -1,25 +1,39 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKCOMMON_H #define NVBLASTTKCOMMON_H -#include "NvPreprocessor.h" +#include "NvBlastGlobals.h" #include "NvBlastTkGUID.h" -// Macro to load a uint32_t (or larger) with four characters -#define NVBLASTTK_FOURCC(_a, _b, _c, _d) ( (uint32_t)(_a) | (uint32_t)(_b)<<8 | (uint32_t)(_c)<<16 | (uint32_t)(_d)<<24 ) - - // Macro to define standard object classes. An intermediate class is defined which holds common implementations. #define NVBLASTTK_IMPL_DECLARE(_name) \ class Tk##_name##Type : public Tk##_name \ @@ -82,29 +96,12 @@ class Tk##_name##Impl final : public Tk##_name##Type /* Enums */ \ \ /* Generate a ClassID enum used to identify this TkIdentifiable. */ \ - enum { ClassID = NVBLASTTK_FOURCC(_id0, _id1, _id2, _id3) } - - -// Macro to declare standard object interfaces, enums, etc (serializable version) -#define NVBLASTTK_IMPL_DEFINE_SERIALIZABLE(_id0, _id1, _id2, _id3) \ - NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE(_id0, _id1, _id2, _id3); \ - \ - /* Begin TkSerializable */ \ - virtual bool serialize(physx::general_PxIOStream2::PxFileBuf& stream) const override; \ - /* End TkSerializable */ \ - \ - /* Static deserialization function, called by TkFrameworkImpl::deserialize after header data */ \ - static TkSerializable* deserialize(physx::general_PxIOStream2::PxFileBuf& stream, const NvBlastID& id) + enum { ClassID = NVBLAST_FOURCC(_id0, _id1, _id2, _id3) } // Macro to define class type data #define NVBLASTTK_DEFINE_TYPE_IDENTIFIABLE(_name) \ - TkTypeImpl Tk##_name##Type::s_type("Tk" #_name, Tk##_name##Impl::ClassID, 0, nullptr) - - -// Macro to define class type data (serializable version) -#define NVBLASTTK_DEFINE_TYPE_SERIALIZABLE(_name) \ - TkTypeImpl Tk##_name##Type::s_type("Tk" #_name, Tk##_name##Impl::ClassID, Tk##_name##Impl::Version::Current, Tk##_name##Impl::deserialize) + TkTypeImpl Tk##_name##Type::s_type("Tk" #_name, Tk##_name##Impl::ClassID, 0) #endif // ifndef NVBLASTTKCOMMON_H diff --git a/sdk/toolkit/source/NvBlastTkEventQueue.h b/sdk/toolkit/source/NvBlastTkEventQueue.h index 00a1a61..9422111 100644 --- a/sdk/toolkit/source/NvBlastTkEventQueue.h +++ b/sdk/toolkit/source/NvBlastTkEventQueue.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKEVENTQUEUE_H #define NVBLASTTKEVENTQUEUE_H @@ -17,7 +35,6 @@ #include <mutex> #include <atomic> -#include "PxAllocatorCallback.h" #include "NvBlastTkFrameworkImpl.h" #include "NvBlastAssert.h" @@ -50,7 +67,7 @@ public: Peek events queue for dispatch. Do not use in protected state. */ - operator const TkArray<TkEvent>::type&() + operator const Array<TkEvent>::type&() { NVBLAST_ASSERT(m_allowAllocs); NVBLAST_ASSERT(m_currentEvent == m_events.size()); @@ -83,7 +100,7 @@ public: m_currentEvent = 0; for (void* mem : m_memory) { - NVBLASTTK_FREE(mem); + NVBLAST_FREE(mem); } m_memory.clear(); m_currentData = 0; @@ -186,13 +203,13 @@ public: /** Proxy function to dispatch events to this queue's listeners. */ - void dispatch(const TkArray<TkEvent>::type& events) const + void dispatch(const Array<TkEvent>::type& events) const { if (events.size()) { for (TkEventListener* l : m_listeners) { - PERF_SCOPE_M("TkEventQueue::dispatch"); + BLAST_PROFILE_SCOPE_M("TkEventQueue::dispatch"); l->receive(events.begin(), events.size()); } } @@ -207,21 +224,21 @@ private: void* memory = nullptr; if (size > 0) { - memory = NVBLASTTK_ALLOC(size, "TkEventQueue Data"); + memory = NVBLAST_ALLOC_NAMED(size, "TkEventQueue Data"); m_memory.pushBack(memory); } return memory; } - TkArray<TkEvent>::type m_events; //!< holds events - TkArray<void*>::type m_memory; //!< holds allocated data memory blocks + Array<TkEvent>::type m_events; //!< holds events + Array<void*>::type m_memory; //!< holds allocated data memory blocks std::atomic<uint32_t> m_currentEvent; //!< reference index for event insertion std::atomic<uint32_t> m_currentData; //!< reference index for data insertion size_t m_poolCapacity; //!< size of the currently active memory block (m_pool) uint8_t* m_pool; //!< the current memory block allocData() uses bool m_allowAllocs; //!< assert guard - TkInlineArray<TkEventListener*,4>::type m_listeners; //!< objects to dispatch to + InlineArray<TkEventListener*,4>::type m_listeners; //!< objects to dispatch to }; } // namespace Blast diff --git a/sdk/toolkit/source/NvBlastTkFamilyImpl.cpp b/sdk/toolkit/source/NvBlastTkFamilyImpl.cpp index 33baafe..4879535 100644 --- a/sdk/toolkit/source/NvBlastTkFamilyImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkFamilyImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastTkFrameworkImpl.h" #include "NvBlastTkFamilyImpl.h" @@ -16,14 +34,10 @@ #include "NvBlastTkJointImpl.h" #include "Px.h" -#include "PxFileBuf.h" -#include "PxAllocatorCallback.h" #include "NvBlastIndexFns.h" #include "NvBlastMemory.h" -using namespace physx::general_PxIOStream2; - namespace Nv { @@ -32,7 +46,7 @@ namespace Blast //////// Static data //////// -NVBLASTTK_DEFINE_TYPE_SERIALIZABLE(Family); +NVBLASTTK_DEFINE_TYPE_IDENTIFIABLE(Family); //////// Member functions //////// @@ -51,12 +65,12 @@ TkFamilyImpl::~TkFamilyImpl() { if (m_familyLL != nullptr) { - uint32_t familyActorCount = NvBlastFamilyGetActorCount(m_familyLL, TkFrameworkImpl::get()->log); + uint32_t familyActorCount = NvBlastFamilyGetActorCount(m_familyLL, logLL); if (familyActorCount != 0) { - NVBLASTTK_LOG_WARNING("TkFamilyImpl::~TkFamilyImpl(): family actor count is not 0."); + NVBLAST_LOG_WARNING("TkFamilyImpl::~TkFamilyImpl(): family actor count is not 0."); } - TkFrameworkImpl::get()->free(m_familyLL); + NVBLAST_FREE(m_familyLL); } } @@ -73,7 +87,7 @@ void TkFamilyImpl::release() m_actors.clear(); - NVBLASTTK_DELETE(this, TkFamilyImpl); + NVBLAST_DELETE(this, TkFamilyImpl); } @@ -112,7 +126,7 @@ uint32_t TkFamilyImpl::getActors(TkActor** buffer, uint32_t bufferSize, uint32_t uint32_t actorCount = getActorCount(); if (actorCount <= indexStart) { - NVBLASTTK_LOG_WARNING("TkFamilyImpl::getActors: indexStart beyond end of actor list."); + NVBLAST_LOG_WARNING("TkFamilyImpl::getActors: indexStart beyond end of actor list."); return 0; } @@ -146,22 +160,22 @@ uint32_t TkFamilyImpl::getActors(TkActor** buffer, uint32_t bufferSize, uint32_t } -NV_INLINE bool areLLActorsEqual(const NvBlastActor* actor0, const NvBlastActor* actor1, TkArray<uint32_t>::type& scratch) +NV_INLINE bool areLLActorsEqual(const NvBlastActor* actor0, const NvBlastActor* actor1, Array<uint32_t>::type& scratch) { - if (NvBlastActorGetGraphNodeCount(actor0, TkFrameworkImpl::get()->log) != NvBlastActorGetGraphNodeCount(actor1, TkFrameworkImpl::get()->log)) + if (NvBlastActorGetGraphNodeCount(actor0, logLL) != NvBlastActorGetGraphNodeCount(actor1, logLL)) { return false; } - const uint32_t chunkCount = NvBlastActorGetVisibleChunkCount(actor0, TkFrameworkImpl::get()->log); - if (chunkCount != NvBlastActorGetVisibleChunkCount(actor1, TkFrameworkImpl::get()->log)) + const uint32_t chunkCount = NvBlastActorGetVisibleChunkCount(actor0, logLL); + if (chunkCount != NvBlastActorGetVisibleChunkCount(actor1, logLL)) { return false; } scratch.resize(chunkCount * 2); - NvBlastActorGetVisibleChunkIndices(scratch.begin(), chunkCount, actor0, TkFrameworkImpl::get()->log); - NvBlastActorGetVisibleChunkIndices(scratch.begin() + chunkCount, chunkCount, actor1, TkFrameworkImpl::get()->log); + NvBlastActorGetVisibleChunkIndices(scratch.begin(), chunkCount, actor0, logLL); + NvBlastActorGetVisibleChunkIndices(scratch.begin() + chunkCount, chunkCount, actor1, logLL); return memcmp(scratch.begin(), scratch.begin() + chunkCount, chunkCount * sizeof(uint32_t)) == 0; } @@ -170,21 +184,21 @@ void TkFamilyImpl::reinitialize(const NvBlastFamily* newFamily, TkGroup* group) { NVBLAST_ASSERT(newFamily); #if NV_ENABLE_ASSERTS - NvBlastID id0 = NvBlastFamilyGetAssetID(m_familyLL, TkFrameworkImpl::get()->log); - NvBlastID id1 = NvBlastFamilyGetAssetID(newFamily, TkFrameworkImpl::get()->log); + NvBlastID id0 = NvBlastFamilyGetAssetID(m_familyLL, logLL); + NvBlastID id1 = NvBlastFamilyGetAssetID(newFamily, logLL); NVBLAST_ASSERT(TkGUIDsEqual(&id0, &id1)); #endif - NVBLAST_ASSERT(NvBlastFamilyGetSize(m_familyLL, TkFrameworkImpl::get()->log) == NvBlastFamilyGetSize(newFamily, TkFrameworkImpl::get()->log)); + NVBLAST_ASSERT(NvBlastFamilyGetSize(m_familyLL, logLL) == NvBlastFamilyGetSize(newFamily, logLL)); // alloc and init new family - const uint32_t blockSize = NvBlastFamilyGetSize(newFamily, TkFrameworkImpl::get()->log); - NvBlastFamily* newFamilyCopy = (NvBlastFamily*)TkFrameworkImpl::get()->alloc(blockSize); + const uint32_t blockSize = NvBlastFamilyGetSize(newFamily, logLL); + NvBlastFamily* newFamilyCopy = (NvBlastFamily*)NVBLAST_ALLOC_NAMED(blockSize, "TkFamilyImpl::reinitialize"); memcpy(newFamilyCopy, newFamily, blockSize); - NvBlastFamilySetAsset(newFamilyCopy, m_asset->getAssetLL(), TkFrameworkImpl::get()->log); + NvBlastFamilySetAsset(newFamilyCopy, m_asset->getAssetLL(), logLL); // get actors from new family - TkArray<NvBlastActor*>::type newLLActors(NvBlastFamilyGetActorCount(newFamilyCopy, TkFrameworkImpl::get()->log)); - uint32_t actorCount = NvBlastFamilyGetActors(newLLActors.begin(), newLLActors.size(), newFamilyCopy, TkFrameworkImpl::get()->log); + Array<NvBlastActor*>::type newLLActors(NvBlastFamilyGetActorCount(newFamilyCopy, logLL)); + uint32_t actorCount = NvBlastFamilyGetActors(newLLActors.begin(), newLLActors.size(), newFamilyCopy, logLL); // reset actor families to nullptr (we use it as a flag later) for (TkActorImpl& actor : m_actors) @@ -197,17 +211,17 @@ void TkFamilyImpl::reinitialize(const NvBlastFamily* newFamily, TkGroup* group) // prepare split event with new actors auto newActorsSplitEvent = getQueue().allocData<TkSplitEvent>(); - TkArray<TkActor*>::type children(actorCount); + Array<TkActor*>::type children(actorCount); children.resizeUninitialized(0); newActorsSplitEvent->children = children.begin(); // scratch - TkArray<uint32_t>::type scratch(m_asset->getChunkCount()); + Array<uint32_t>::type scratch(m_asset->getChunkCount()); for (uint32_t i = 0; i < actorCount; ++i) { NvBlastActor* newLLActor = newLLActors[i]; - uint32_t actorIndex = NvBlastActorGetIndex(newLLActor, TkFrameworkImpl::get()->log); + uint32_t actorIndex = NvBlastActorGetIndex(newLLActor, logLL); TkActorImpl& tkActor = *getActorByIndex(actorIndex); tkActor.m_family = this; @@ -281,7 +295,7 @@ void TkFamilyImpl::reinitialize(const NvBlastFamily* newFamily, TkGroup* group) } // replace family - TkFrameworkImpl::get()->free(m_familyLL); + NVBLAST_FREE(m_familyLL); m_familyLL = newFamilyCopy; // update joints @@ -299,13 +313,13 @@ void TkFamilyImpl::reinitialize(const NvBlastFamily* newFamily, TkGroup* group) TkActorImpl* TkFamilyImpl::getActorByChunk(uint32_t chunk) { - if (chunk >= NvBlastAssetGetChunkCount(m_asset->getAssetLLInternal(), TkFrameworkImpl::get()->log)) + if (chunk >= NvBlastAssetGetChunkCount(m_asset->getAssetLLInternal(), logLL)) { - NVBLASTTK_LOG_WARNING("TkFamilyImpl::getActorByChunk: invalid chunk index. Returning NULL."); + NVBLAST_LOG_WARNING("TkFamilyImpl::getActorByChunk: invalid chunk index. Returning NULL."); return nullptr; } - NvBlastActor* actorLL = NvBlastFamilyGetChunkActor(m_familyLL, chunk, TkFrameworkImpl::get()->log); + NvBlastActor* actorLL = NvBlastFamilyGetChunkActor(m_familyLL, chunk, logLL); return actorLL ? getActorByActorLL(actorLL) : nullptr; } @@ -441,293 +455,24 @@ const TkAsset* TkFamilyImpl::getAsset() const } -bool TkFamilyImpl::serialize(PxFileBuf& stream) const -{ - TkFrameworkImpl::get()->serializeHeader(*this, stream); - - if (m_material != nullptr) - { - NVBLASTTK_LOG_WARNING("TkFamilyImpl::serialize(): Material pointer is not nullptr, it will be lost during serialization."); - } - - NVBLASTTK_CHECK_ERROR(m_asset != nullptr, "TkFamilyImpl::serialize(): TkFamily asset is nullptr, can't be serialized.", return false); - NVBLASTTK_CHECK_ERROR(m_familyLL != nullptr, "TkFamilyImpl::serialize(): TkFamily family is nullptr, can't be serialized.", return false); - - // Asset ID - const NvBlastID& assetID = m_asset->getID(); - NVBLASTTK_CHECK_ERROR(!TkGUIDIsZero(&assetID), "TkFamilyImpl::serialize(): Associated asset doesn't have an ID set.", return false); - stream.write(&assetID, sizeof(NvBlastID)); - - // Family - const uint32_t familySize = NvBlastFamilyGetSize(m_familyLL, TkFrameworkImpl::get()->log); - stream.storeDword(familySize); - stream.write(m_familyLL, familySize); - - //// Joints //// - - // Internal joint data - stream.storeDword(m_internalJointCount); - - // External joint family ID list - stream.storeDword(m_jointSets.size()); - for (uint32_t i = 0; i < m_jointSets.size(); ++i) - { - const JointSet* jointSet = m_jointSets[i]; - stream.write(&jointSet->m_familyID, sizeof(NvBlastID)); - } - - // Actor joint lists - TkJointImpl* internalJoints = getInternalJoints(); - for (uint32_t actorNum = 0; actorNum < m_actors.size(); ++actorNum) - { - const TkActorImpl& actor = m_actors[actorNum]; - if (!actor.isActive()) - { - continue; // We may need a better way of iterating through active actors - } - - stream.storeDword(actor.getJointCount()); - - for (TkActorImpl::JointIt j(actor); (bool)j; ++j) - { - TkJointImpl* joint = *j; - - const TkJointData& jointData = joint->getDataInternal(); - NVBLAST_ASSERT(jointData.actors[0] == &actor || jointData.actors[1] == &actor); - - const uint32_t attachmentFlags = (uint32_t)(jointData.actors[0] == &actor) | (uint32_t)(jointData.actors[1] == &actor) << 1; - stream.storeDword(attachmentFlags); - - const TkActorImpl* otherActor = static_cast<const TkActorImpl*>(jointData.actors[(attachmentFlags >> 1) ^ 1]); - - if (joint->m_owner == this) - { - // Internal joint - write internal joint index - const uint32_t jointIndex = static_cast<uint32_t>(joint - internalJoints); - stream.storeDword(jointIndex); - if (otherActor != nullptr && otherActor->getIndexInternal() < actorNum) // No need to write the joint data, it has already been written - { - continue; - } - } - else - { - // External joint - write external family index and joint information - stream.storeDword(invalidIndex<uint32_t>()); // Denotes external joint - - const FamilyIDMap::Entry* e = m_familyIDMap.find(getFamilyID(otherActor)); - NVBLASTTK_CHECK_ERROR(e != nullptr, "TkFamilyImpl::deserialize(): Bad data - attached family's ID not recorded.", return false); - - stream.storeDword(e->second); // Write family ID index - } - - // Write joint data - for (int side = 0; side < 2; ++side) - { - stream.storeDword(jointData.chunkIndices[side]); - const physx::PxVec3& attachPosition = jointData.attachPositions[side]; - stream.storeFloat(attachPosition.x); stream.storeFloat(attachPosition.y); stream.storeFloat(attachPosition.z); - } - } - } - - return true; -} - - //////// Static functions //////// -TkSerializable* TkFamilyImpl::deserialize(PxFileBuf& stream, const NvBlastID& id) -{ - // Asset resolve - NvBlastID assetID; - stream.read(&assetID, sizeof(NvBlastID)); - TkIdentifiable* object = TkFrameworkImpl::get()->findObjectByIDInternal(assetID); - NVBLASTTK_CHECK_ERROR(object && object->getType() == TkAssetImpl::s_type, "TkFamilyImpl::deserialize: can't find asset with corresponding ID.", return nullptr); - TkAssetImpl* asset = static_cast<TkAssetImpl*>(object); - - // Allocate - TkFamilyImpl* family = NVBLASTTK_NEW(TkFamilyImpl)(id); - NVBLASTTK_CHECK_ERROR(family != nullptr, "TkFamilyImpl::deserialize: family allocation failed.", return nullptr); - - // associate with found asset - family->m_asset = asset; - - // Family - const uint32_t familySize = stream.readDword(); - family->m_familyLL = static_cast<NvBlastFamily*>(TkFrameworkImpl::get()->alloc(familySize)); - stream.read(family->m_familyLL, familySize); - - if (family->m_familyLL == nullptr) - { - NVBLASTTK_LOG_ERROR("TkFamilyImpl::deserialize: low-level family could not be created."); - family->release(); - return nullptr; - } - -#if NV_ENABLE_ASSERTS && 0 - NvBlastID id = NvBlastFamilyGetAssetID(family->m_familyLL, TkFrameworkImpl::get()->log); - NVBLAST_ASSERT(TkGUIDsEqual(&id, &assetID)); -#endif - - // preallocate actors - uint32_t maxActorCount = NvBlastFamilyGetMaxActorCount(family->m_familyLL, TkFrameworkImpl::get()->log); - family->m_actors.resize(maxActorCount); - - // get actors from family - TkArray<NvBlastActor*>::type newLLActors(NvBlastFamilyGetActorCount(family->m_familyLL, TkFrameworkImpl::get()->log)); - uint32_t actorCount = NvBlastFamilyGetActors(newLLActors.begin(), newLLActors.size(), family->m_familyLL, TkFrameworkImpl::get()->log); - - // fill actors - for (uint32_t i = 0; i < actorCount; ++i) - { - NvBlastActor* newLLActor = newLLActors[i]; - uint32_t actorIndex = NvBlastActorGetIndex(newLLActor, TkFrameworkImpl::get()->log); - TkActorImpl& tkActor = *family->getActorByIndex(actorIndex); - - tkActor.m_family = family; - tkActor.m_actorLL = newLLActor; - } - - //// Create joints //// - - // internal - family->m_internalJointCount = stream.readDword(); - family->m_internalJointBuffer.resize(family->m_internalJointCount * sizeof(TkJointImpl), '\0'); - TkJointImpl* internalJoints = family->getInternalJoints(); - - // external joint family ID list - const uint32_t jointSetCount = stream.readDword(); - family->m_jointSets.resize(jointSetCount); - for (uint32_t i = 0; i < jointSetCount; ++i) - { - family->m_jointSets[i] = NVBLASTTK_NEW(JointSet); - stream.read(&family->m_jointSets[i]->m_familyID, sizeof(NvBlastID)); - family->m_familyIDMap[family->m_jointSets[i]->m_familyID] = i; - } - - // fill actor joint lists - for (uint32_t actorNum = 0; actorNum < family->m_actors.size(); ++actorNum) - { - TkActorImpl& actor = family->m_actors[actorNum]; - if (!actor.isActive()) - { - continue; // We may need a better way of iterating through active actors - } - - // Read joint information - uint32_t jointCount = stream.readDword(); - while (jointCount--) - { - const uint32_t attachmentFlags = stream.readDword(); - const uint32_t jointIndex = stream.readDword(); - if (!isInvalidIndex(jointIndex)) - { - // Internal joint - TkJointImpl& joint = internalJoints[jointIndex]; - TkJointData& jointData = joint.getDataWritable(); - - // Initialize joint if it has not been encountered yet - NVBLAST_ASSERT((joint.m_links[0].m_joint == nullptr) == (joint.m_links[1].m_joint == nullptr)); - if (joint.m_links[0].m_joint == nullptr) - { - new (&joint) TkJointImpl; - joint.m_owner = family; - for (int side = 0; side < 2; ++side) - { - jointData.chunkIndices[side] = stream.readDword(); - physx::PxVec3& attachPosition = jointData.attachPositions[side]; - attachPosition.x = stream.readFloat(); attachPosition.y = stream.readFloat(); attachPosition.z = stream.readFloat(); - } - } - - if (attachmentFlags & 1) - { - jointData.actors[0] = &actor; - actor.addJoint(joint.m_links[0]); - } - - if (attachmentFlags & 2) - { - jointData.actors[1] = &actor; - if (jointData.actors[0] != jointData.actors[1]) - { - actor.addJoint(joint.m_links[1]); - } - } - } - else - { - // External joint - const uint32_t otherFamilyIndex = stream.readDword(); - NVBLASTTK_CHECK_ERROR(otherFamilyIndex < family->m_jointSets.size(), "TkFamilyImpl::deserialize: family allocation failed.", return nullptr); - const NvBlastID& otherFamilyID = family->m_jointSets[otherFamilyIndex]->m_familyID; - TkFamilyImpl* otherFamily = static_cast<TkFamilyImpl*>(TkFrameworkImpl::get()->findObjectByIDInternal(otherFamilyID)); - - TkJointDesc jointDesc; - for (int side = 0; side < 2; ++side) - { - jointDesc.chunkIndices[side] = stream.readDword(); - physx::PxVec3& attachPosition = jointDesc.attachPositions[side]; - attachPosition.x = stream.readFloat(); attachPosition.y = stream.readFloat(); attachPosition.z = stream.readFloat(); - } - - NVBLASTTK_CHECK_ERROR(attachmentFlags != 3, "TkFamilyImpl::deserialize: both attached actors are the same in an external joint.", return nullptr); - - const uint32_t attachmentIndex = attachmentFlags >> 1; - - TkJointImpl** jointHandle = family->createExternalJointHandle(otherFamilyID, jointDesc.chunkIndices[attachmentIndex], jointDesc.chunkIndices[attachmentIndex ^ 1]); - NVBLASTTK_CHECK_ERROR(jointHandle != nullptr, "TkFamilyImpl::deserialize: joint handle could not be created.", return nullptr); - - if (otherFamily == nullptr) - { - // Other family does not exist yet, we'll create the joint - jointDesc.families[attachmentIndex] = family; - jointDesc.families[attachmentIndex ^ 1] = nullptr; - - TkJointImpl* joint = NVBLASTTK_NEW(TkJointImpl)(jointDesc, nullptr); - NVBLASTTK_CHECK_ERROR(joint != nullptr, "TkFamilyImpl::deserialize: joint createion failed.", return nullptr); - - *jointHandle = joint; - - actor.addJoint(joint->m_links[attachmentIndex]); - } - else - { - // Other family exists, and should have created the joint - TkJointImpl* joint = otherFamily->findExternalJoint(family, ExternalJointKey(jointDesc.chunkIndices[attachmentIndex ^ 1], jointDesc.chunkIndices[attachmentIndex])); - NVBLASTTK_CHECK_ERROR(joint != nullptr, "TkFamilyImpl::deserialize: other family should have created joint, but did not.", return nullptr); - - *jointHandle = joint; - - // Add the joint to its actor(s) - joint->getDataWritable().actors[attachmentIndex] = &actor; - actor.addJoint(joint->m_links[attachmentIndex]); - } - } - } - } - - return family; -} - - TkFamilyImpl* TkFamilyImpl::create(const TkAssetImpl* asset) { - TkFamilyImpl* family = NVBLASTTK_NEW(TkFamilyImpl); + TkFamilyImpl* family = NVBLAST_NEW(TkFamilyImpl); family->m_asset = asset; - void* mem = TkFrameworkImpl::get()->alloc(NvBlastAssetGetFamilyMemorySize(asset->getAssetLL(), TkFrameworkImpl::get()->log)); - family->m_familyLL = NvBlastAssetCreateFamily(mem, asset->getAssetLL(), TkFrameworkImpl::get()->log); + void* mem = NVBLAST_ALLOC_NAMED(NvBlastAssetGetFamilyMemorySize(asset->getAssetLL(), logLL), "TkFamilyImpl::create"); + family->m_familyLL = NvBlastAssetCreateFamily(mem, asset->getAssetLL(), logLL); //family->addListener(*TkFrameworkImpl::get()); if (family->m_familyLL == nullptr) { - NVBLASTTK_LOG_ERROR("TkFamilyImpl::create: low-level family could not be created."); + NVBLAST_LOG_ERROR("TkFamilyImpl::create: low-level family could not be created."); family->release(); return nullptr; } - uint32_t maxActorCount = NvBlastFamilyGetMaxActorCount(family->m_familyLL, TkFrameworkImpl::get()->log); + uint32_t maxActorCount = NvBlastFamilyGetMaxActorCount(family->m_familyLL, logLL); family->m_actors.resize(maxActorCount); family->m_internalJointBuffer.resize(asset->getJointDescCountInternal() * sizeof(TkJointImpl), 0); @@ -749,8 +494,8 @@ TkJointImpl** TkFamilyImpl::createExternalJointHandle(const NvBlastID& otherFami } else { - jointSet = NVBLASTTK_NEW(JointSet); - NVBLASTTK_CHECK_ERROR(jointSet != nullptr, "TkFamilyImpl::addExternalJoint: failed to create joint set for other family ID.", return nullptr); + jointSet = NVBLAST_NEW(JointSet); + NVBLAST_CHECK_ERROR(jointSet != nullptr, "TkFamilyImpl::addExternalJoint: failed to create joint set for other family ID.", return nullptr); jointSet->m_familyID = otherFamilyID; otherFamilyIndex = m_jointSets.size(); m_familyIDMap[otherFamilyID] = otherFamilyIndex; @@ -759,7 +504,7 @@ TkJointImpl** TkFamilyImpl::createExternalJointHandle(const NvBlastID& otherFami const ExternalJointKey key(chunkIndex0, chunkIndex1); const bool jointExists = jointSet->m_joints.find(key) != nullptr; - NVBLASTTK_CHECK_WARNING(!jointExists, "TkFamilyImpl::addExternalJoint: joint already added.", return nullptr); + NVBLAST_CHECK_WARNING(!jointExists, "TkFamilyImpl::addExternalJoint: joint already added.", return nullptr); return &jointSet->m_joints[key]; } @@ -771,13 +516,13 @@ bool TkFamilyImpl::deleteExternalJointHandle(TkJointImpl*& joint, const NvBlastI if (jointSetIndexEntry != nullptr) { const uint32_t jointSetIndex = jointSetIndexEntry->second; - TkHashMap<ExternalJointKey, TkJointImpl*>::type::Entry e; + HashMap<ExternalJointKey, TkJointImpl*>::type::Entry e; if (m_jointSets[jointSetIndex]->m_joints.erase(ExternalJointKey(chunkIndex0, chunkIndex1), e)) { // Delete the joint set if it is empty if (m_jointSets[jointSetIndex]->m_joints.size() == 0) { - NVBLASTTK_DELETE(m_jointSets[jointSetIndex], JointSet); + NVBLAST_DELETE(m_jointSets[jointSetIndex], JointSet); m_jointSets.replaceWithLast(jointSetIndex); m_familyIDMap.erase(otherFamilyID); if (jointSetIndex < m_jointSets.size()) @@ -801,7 +546,7 @@ TkJointImpl* TkFamilyImpl::findExternalJoint(const TkFamilyImpl* otherFamily, Ex const FamilyIDMap::Entry* jointSetIndexEntry = m_familyIDMap.find(getFamilyID(otherFamily)); if (jointSetIndexEntry != nullptr) { - const TkHashMap<ExternalJointKey, TkJointImpl*>::type::Entry* e = m_jointSets[jointSetIndexEntry->second]->m_joints.find(key); + const HashMap<ExternalJointKey, TkJointImpl*>::type::Entry* e = m_jointSets[jointSetIndexEntry->second]->m_joints.find(key); if (e != nullptr) { return e->second; diff --git a/sdk/toolkit/source/NvBlastTkFamilyImpl.h b/sdk/toolkit/source/NvBlastTkFamilyImpl.h index 571ee75..577326b 100644 --- a/sdk/toolkit/source/NvBlastTkFamilyImpl.h +++ b/sdk/toolkit/source/NvBlastTkFamilyImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKFAMILYIMPL_H #define NVBLASTTKFAMILYIMPL_H @@ -18,8 +36,8 @@ #include "NvBlastTkActorImpl.h" #include "NvBlastTkEventQueue.h" -#include "NvBlastTkHashSet.h" -#include "NvBlastTkHashMap.h" +#include "NvBlastHashSet.h" +#include "NvBlastHashMap.h" #include "NvBlast.h" #include "NvBlastAssert.h" @@ -42,28 +60,11 @@ class TkAssetImpl; NVBLASTTK_IMPL_DECLARE(Family) { public: - /** - Enum which keeps track of the serialized data format. - */ - enum Version - { - /** Initial version */ - Initial, - - // New formats must come before Count. They should be given descriptive names with more information in comments. - - /** The number of serialized formats. */ - Count, - - /** The current version. This should always be Count-1 */ - Current = Count - 1 - }; - TkFamilyImpl(); TkFamilyImpl(const NvBlastID& id); ~TkFamilyImpl(); - NVBLASTTK_IMPL_DEFINE_SERIALIZABLE('A', 'C', 'T', 'F'); + NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('A', 'C', 'T', 'F'); // Begin TkFamily virtual const NvBlastFamily* getFamilyLL() const override; @@ -108,7 +109,7 @@ public: void updateJoints(TkActorImpl* actor, TkEventQueue* alternateQueue = nullptr); - TkArray<TkActorImpl>::type& getActorsInternal(); + Array<TkActorImpl>::type& getActorsInternal(); uint32_t getInternalJointCount() const; @@ -122,7 +123,7 @@ public: TkActorImpl* getActorByChunk(uint32_t chunkIndex); - typedef physx::shdfnd::Pair<uint32_t, uint32_t> ExternalJointKey; //!< The chunk indices within the TkFamily joined by the joint. This chunks will be a supports chunks. + typedef physx::shdfnd::Pair<uint32_t, uint32_t> ExternalJointKey; //!< The chunk indices within the TkFamily objects joined by the joint. These chunks will be support chunks. TkJointImpl* findExternalJoint(const TkFamilyImpl* otherFamily, ExternalJointKey key) const; @@ -132,16 +133,16 @@ private: struct JointSet { NvBlastID m_familyID; - TkHashMap<ExternalJointKey, TkJointImpl*>::type m_joints; + HashMap<ExternalJointKey, TkJointImpl*>::type m_joints; }; - typedef TkHashMap<NvBlastID, uint32_t>::type FamilyIDMap; + typedef HashMap<NvBlastID, uint32_t>::type FamilyIDMap; NvBlastFamily* m_familyLL; - TkArray<TkActorImpl>::type m_actors; + Array<TkActorImpl>::type m_actors; uint32_t m_internalJointCount; - TkArray<uint8_t>::type m_internalJointBuffer; - TkArray<JointSet*>::type m_jointSets; + Array<uint8_t>::type m_internalJointBuffer; + Array<JointSet*>::type m_jointSets; FamilyIDMap m_familyIDMap; const TkAssetImpl* m_asset; const void* m_material; @@ -168,7 +169,7 @@ NV_INLINE uint32_t TkFamilyImpl::getActorCountInternal() const { NVBLAST_ASSERT(m_familyLL != nullptr); - return NvBlastFamilyGetActorCount(m_familyLL, TkFrameworkImpl::get()->log); + return NvBlastFamilyGetActorCount(m_familyLL, logLL); } @@ -181,7 +182,7 @@ NV_INLINE TkActorImpl* TkFamilyImpl::getActorByIndex(uint32_t index) NV_INLINE TkActorImpl* TkFamilyImpl::getActorByActorLL(const NvBlastActor* actorLL) { - uint32_t index = NvBlastActorGetIndex(actorLL, TkFrameworkImpl::get()->log); + uint32_t index = NvBlastActorGetIndex(actorLL, logLL); return getActorByIndex(index); } @@ -198,7 +199,7 @@ NV_INLINE void TkFamilyImpl::setMaterial(const void* material) } -NV_INLINE TkArray<TkActorImpl>::type& TkFamilyImpl::getActorsInternal() +NV_INLINE Array<TkActorImpl>::type& TkFamilyImpl::getActorsInternal() { return m_actors; } diff --git a/sdk/toolkit/source/NvBlastTkFrameworkImpl.cpp b/sdk/toolkit/source/NvBlastTkFrameworkImpl.cpp index 6201101..f409785 100644 --- a/sdk/toolkit/source/NvBlastTkFrameworkImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkFrameworkImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastAssert.h" @@ -18,16 +36,13 @@ #include "NvBlastTkJointImpl.h" #include "NvBlastTkTypeImpl.h" -#include "PxAllocatorCallback.h" -#include "PxErrorCallback.h" -#include "PxFileBuf.h" +#include "NvBlastGlobals.h" #include <algorithm> using namespace physx; using namespace physx::shdfnd; -using namespace physx::general_PxIOStream2; NV_INLINE bool operator < (const NvBlastID& id1, const NvBlastID& id2) @@ -83,13 +98,11 @@ bool TkFrameworkImpl::set(TkFrameworkImpl* framework) { if (framework != nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::set: framework already set. Pass NULL to this function to destroy framework."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::set: framework already set. Pass NULL to this function to destroy framework."); return false; } - PxAllocatorCallback& allocator = s_framework->getAllocatorCallbackInternal(); - s_framework->~TkFrameworkImpl(); - allocator.deallocate(s_framework); + NVBLAST_DELETE(s_framework, TkFrameworkImpl); } s_framework = framework; @@ -98,70 +111,11 @@ bool TkFrameworkImpl::set(TkFrameworkImpl* framework) } -void TkFrameworkImpl::log(int type, const char* msg, const char* file, int line) -{ - if (s_framework == nullptr) - { - return; - } - - PxErrorCode::Enum pxErrorCode = PxErrorCode::eNO_ERROR; - switch (type) - { - case NvBlastMessage::Error: pxErrorCode = PxErrorCode::eINVALID_OPERATION; break; - case NvBlastMessage::Warning: pxErrorCode = PxErrorCode::eDEBUG_WARNING; break; - case NvBlastMessage::Info: pxErrorCode = PxErrorCode::eDEBUG_INFO; break; - case NvBlastMessage::Debug: pxErrorCode = PxErrorCode::eNO_ERROR; break; - } - - s_framework->getErrorCallback().reportError(pxErrorCode, msg, file, line); -} - - -void* TkFrameworkImpl::alloc(size_t size) -{ - if (s_framework == nullptr) - { - return nullptr; - } - - NV_COMPILE_TIME_ASSERT(Alignment > 0 && Alignment <= 256); - - unsigned char* mem = reinterpret_cast<unsigned char*>(s_framework->m_allocatorCallback->allocate(size + (size_t)Alignment, "NvBlast", __FILE__, __LINE__)); - - const unsigned char offset = (unsigned char)((uintptr_t)Alignment - (uintptr_t)mem % (size_t)Alignment - 1); - mem += offset; - *mem++ = offset; - - return mem; -} - - -void TkFrameworkImpl::free(void* mem) -{ - if (s_framework == nullptr) - { - return; - } - - unsigned char* ptr = reinterpret_cast<unsigned char*>(mem); - const unsigned char offset = *--ptr; - - return s_framework->m_allocatorCallback->deallocate(ptr - offset); -} - - //////// TkFrameworkImpl methods //////// -TkFrameworkImpl::TkFrameworkImpl(const TkFrameworkDesc& desc) +TkFrameworkImpl::TkFrameworkImpl() : TkFramework() - , m_errorCallback(desc.errorCallback) - , m_allocatorCallback(desc.allocatorCallback) { - // Static create() function should ensure these pointers are not NULL - NVBLAST_ASSERT(m_errorCallback != nullptr); - NVBLAST_ASSERT(m_allocatorCallback != nullptr); - // Register types m_types.resize(TkTypeIndex::TypeCount); m_objects.resize(TkTypeIndex::TypeCount); @@ -179,7 +133,7 @@ TkFrameworkImpl::~TkFrameworkImpl() void TkFrameworkImpl::release() { // Special release of joints, which are not TkIdentifiable: - TkArray<TkJointImpl*>::type joints; // Since the EraseIterator is not exposed + Array<TkJointImpl*>::type joints; // Since the EraseIterator is not exposed joints.reserve(m_joints.size()); for (auto j = m_joints.getIterator(); !j.done(); ++j) { @@ -195,75 +149,6 @@ void TkFrameworkImpl::release() NVBLASTTK_RELEASE_TYPE(Group); NVBLASTTK_RELEASE_TYPE(Asset); set(nullptr); - Nv::Blast::TkAllocator::s_allocatorCallback = nullptr; -} - - -physx::PxErrorCallback& TkFrameworkImpl::getErrorCallback() const -{ - return getErrorCallbackInternal(); -} - - -physx::PxAllocatorCallback& TkFrameworkImpl::getAllocatorCallback() const -{ - return getAllocatorCallbackInternal(); -} - - -NvBlastLog TkFrameworkImpl::getLogFn() const -{ - return TkFrameworkImpl::log; -} - - -TkSerializable* TkFrameworkImpl::deserialize(PxFileBuf& stream) -{ - // Read framework ID - if (stream.readDword() != ClassID) - { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::deserialize: stream does not contain a BlastTk object."); - return nullptr; - } - - // Read object class ID and get class type data - const auto it = m_typeIDToIndex.find(stream.readDword()); - if (it == nullptr) - { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::deserialize: BlastTk object type unrecognized."); - return nullptr; - } - - const uint32_t index = (*it).second; - NVBLAST_ASSERT(index < m_types.size()); - - const TkTypeImpl* type = m_types[index]; - - // Read object class version and ensure it's current - if (stream.readDword() != type->getVersionInternal()) - { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::deserialize: BlastTk object version does not equal the current version for the loaded type."); - return nullptr; - } - - // Object ID - NvBlastID id; - stream.read(&id, sizeof(NvBlastID)); - - // Serializable user data - const uint32_t lsq = stream.readDword(); - const uint32_t msq = stream.readDword(); - - // All checks out, deserialize - TkSerializable* object = type->getDeserializeFn()(stream, id); - - // Set serializable user data if deserialization was successful - if (object != nullptr) - { - object->userIntData = static_cast<uint64_t>(msq) << 32 | static_cast<uint64_t>(lsq); - } - - return object; } @@ -271,7 +156,7 @@ const TkType* TkFrameworkImpl::getType(TkTypeIndex::Enum typeIndex) const { if (typeIndex < 0 || typeIndex >= TkTypeIndex::TypeCount) { - NVBLASTTK_LOG_WARNING("TkFrameworkImpl::getType: invalid typeIndex."); + NVBLAST_LOG_WARNING("TkFrameworkImpl::getType: invalid typeIndex."); return nullptr; } @@ -285,7 +170,7 @@ TkIdentifiable* TkFrameworkImpl::findObjectByID(const NvBlastID& id) const if (object == nullptr) { - NVBLASTTK_LOG_WARNING("TkFrameworkImpl::findObjectByID: object not found."); + NVBLAST_LOG_WARNING("TkFrameworkImpl::findObjectByID: object not found."); } return object; @@ -298,7 +183,7 @@ uint32_t TkFrameworkImpl::getObjectCount(const TkType& type) const if (index >= m_objects.size()) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::getObjectCount: BlastTk object type unrecognized."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::getObjectCount: BlastTk object type unrecognized."); return 0; } @@ -313,7 +198,7 @@ uint32_t TkFrameworkImpl::getObjects(TkIdentifiable** buffer, uint32_t bufferSiz if (index >= m_objects.size()) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::getObjectCount: BlastTk object type unrecognized."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::getObjectCount: BlastTk object type unrecognized."); return 0; } @@ -322,7 +207,7 @@ uint32_t TkFrameworkImpl::getObjects(TkIdentifiable** buffer, uint32_t bufferSiz uint32_t objectCount = objectArray.size(); if (objectCount <= indexStart) { - NVBLASTTK_LOG_WARNING("TkFrameworkImpl::getObjects: indexStart beyond end of object list."); + NVBLAST_LOG_WARNING("TkFrameworkImpl::getObjects: indexStart beyond end of object list."); return 0; } @@ -338,15 +223,15 @@ uint32_t TkFrameworkImpl::getObjects(TkIdentifiable** buffer, uint32_t bufferSiz } -bool TkFrameworkImpl::reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount, NvBlastBondDesc* bondDescs, uint32_t bondCount, uint32_t* chunkReorderMap /*= nullptr*/) const +bool TkFrameworkImpl::reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount, NvBlastBondDesc* bondDescs, uint32_t bondCount, uint32_t* chunkReorderMap /*= nullptr*/, bool keepBondNormalChunkOrder /*= false*/) const { - uint32_t* map = chunkReorderMap != nullptr ? chunkReorderMap : static_cast<uint32_t*>(NVBLASTTK_ALLOC(chunkCount * sizeof(uint32_t), "reorderAssetDescChunks:chunkReorderMap")); - void* scratch = NVBLASTTK_ALLOC(chunkCount * sizeof(NvBlastChunkDesc), "reorderAssetDescChunks:scratch"); - const bool result = NvBlastReorderAssetDescChunks(chunkDescs, chunkCount, bondDescs, bondCount, map, scratch, log); - NVBLASTTK_FREE(scratch); + uint32_t* map = chunkReorderMap != nullptr ? chunkReorderMap : static_cast<uint32_t*>(NVBLAST_ALLOC_NAMED(chunkCount * sizeof(uint32_t), "reorderAssetDescChunks:chunkReorderMap")); + void* scratch = NVBLAST_ALLOC_NAMED(chunkCount * sizeof(NvBlastChunkDesc), "reorderAssetDescChunks:scratch"); + const bool result = NvBlastReorderAssetDescChunks(chunkDescs, chunkCount, bondDescs, bondCount, map, keepBondNormalChunkOrder, scratch, logLL); + NVBLAST_FREE(scratch); if (chunkReorderMap == nullptr) { - NVBLASTTK_FREE(map); + NVBLAST_FREE(map); } return result; } @@ -354,9 +239,9 @@ bool TkFrameworkImpl::reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint3 bool TkFrameworkImpl::ensureAssetExactSupportCoverage(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount) const { - void* scratch = NVBLASTTK_ALLOC(chunkCount, "ensureAssetExactSupportCoverage:scratch"); - const bool result = NvBlastEnsureAssetExactSupportCoverage(chunkDescs, chunkCount, scratch, log); - NVBLASTTK_FREE(scratch); + void* scratch = NVBLAST_ALLOC_NAMED(chunkCount, "ensureAssetExactSupportCoverage:scratch"); + const bool result = NvBlastEnsureAssetExactSupportCoverage(chunkDescs, chunkCount, scratch, logLL); + NVBLAST_FREE(scratch); return result; } @@ -366,7 +251,7 @@ TkAsset* TkFrameworkImpl::createAsset(const TkAssetDesc& desc) TkAssetImpl* asset = TkAssetImpl::create(desc); if (asset == nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::createAsset: failed to create asset."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::createAsset: failed to create asset."); } return asset; @@ -378,7 +263,7 @@ TkAsset* TkFrameworkImpl::createAsset(const NvBlastAsset* assetLL, Nv::Blast::Tk TkAssetImpl* asset = TkAssetImpl::create(assetLL, jointDescs, jointDescCount, ownsAsset); if (asset == nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::createAsset: failed to create asset."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::createAsset: failed to create asset."); } return asset; @@ -390,7 +275,7 @@ TkGroup* TkFrameworkImpl::createGroup(const TkGroupDesc& desc) TkGroupImpl* group = TkGroupImpl::create(desc); if (group == nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::createGroup: failed to create group."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::createGroup: failed to create group."); } return group; @@ -402,7 +287,7 @@ TkActor* TkFrameworkImpl::createActor(const TkActorDesc& desc) TkActor* actor = TkActorImpl::create(desc); if (actor == nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::createActor: failed to create actor."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::createActor: failed to create actor."); } return actor; @@ -417,35 +302,35 @@ TkJoint* TkFrameworkImpl::createJoint(const TkJointDesc& desc) TkFamilyImpl* family0 = static_cast<TkFamilyImpl*>(desc.families[0]); TkFamilyImpl* family1 = static_cast<TkFamilyImpl*>(desc.families[1]); - NVBLASTTK_CHECK_ERROR(family0 != nullptr || family1 != nullptr, "TkFrameworkImpl::createJoint: at least one family in the TkJointDesc must be valid.", return nullptr); + NVBLAST_CHECK_ERROR(family0 != nullptr || family1 != nullptr, "TkFrameworkImpl::createJoint: at least one family in the TkJointDesc must be valid.", return nullptr); - NVBLASTTK_CHECK_ERROR(family0 == nullptr || desc.chunkIndices[0] < family0->getAssetImpl()->getChunkCount(), "TkFrameworkImpl::createJoint: desc.chunkIndices[0] is invalid.", return nullptr); - NVBLASTTK_CHECK_ERROR(family1 == nullptr || desc.chunkIndices[1] < family1->getAssetImpl()->getChunkCount(), "TkFrameworkImpl::createJoint: desc.chunkIndices[1] is invalid.", return nullptr); + NVBLAST_CHECK_ERROR(family0 == nullptr || desc.chunkIndices[0] < family0->getAssetImpl()->getChunkCount(), "TkFrameworkImpl::createJoint: desc.chunkIndices[0] is invalid.", return nullptr); + NVBLAST_CHECK_ERROR(family1 == nullptr || desc.chunkIndices[1] < family1->getAssetImpl()->getChunkCount(), "TkFrameworkImpl::createJoint: desc.chunkIndices[1] is invalid.", return nullptr); const bool actorsAreTheSame = family0 == family1 && family0->getActorByChunk(desc.chunkIndices[0]) == family1->getActorByChunk(desc.chunkIndices[1]); - NVBLASTTK_CHECK_ERROR(!actorsAreTheSame, "TkFrameworkImpl::createJoint: the chunks listed in the TkJointDesc must be in different actors.", return nullptr); + NVBLAST_CHECK_ERROR(!actorsAreTheSame, "TkFrameworkImpl::createJoint: the chunks listed in the TkJointDesc must be in different actors.", return nullptr); if (family0 != nullptr) { - const bool isSupportChunk = !isInvalidIndex(NvBlastAssetGetChunkToGraphNodeMap(family0->getAssetImpl()->getAssetLLInternal(), log)[desc.chunkIndices[0]]); - NVBLASTTK_CHECK_ERROR(isSupportChunk, "TkFrameworkImpl::createJoint: desc.chunkIndices[0] is not a support chunk in the asset for desc.families[0]. Joint not created.", return nullptr); + const bool isSupportChunk = !isInvalidIndex(NvBlastAssetGetChunkToGraphNodeMap(family0->getAssetImpl()->getAssetLLInternal(), logLL)[desc.chunkIndices[0]]); + NVBLAST_CHECK_ERROR(isSupportChunk, "TkFrameworkImpl::createJoint: desc.chunkIndices[0] is not a support chunk in the asset for desc.families[0]. Joint not created.", return nullptr); handle0 = family0->createExternalJointHandle(getFamilyID(family1), desc.chunkIndices[0], desc.chunkIndices[1]); - NVBLASTTK_CHECK_ERROR(handle0 != nullptr, "TkFrameworkImpl::createJoint: could not create joint handle in family[0]. Joint not created.", return nullptr); + NVBLAST_CHECK_ERROR(handle0 != nullptr, "TkFrameworkImpl::createJoint: could not create joint handle in family[0]. Joint not created.", return nullptr); } if (family1 != nullptr) { - const bool isSupportChunk = !isInvalidIndex(NvBlastAssetGetChunkToGraphNodeMap(family1->getAssetImpl()->getAssetLLInternal(), log)[desc.chunkIndices[1]]); - NVBLASTTK_CHECK_ERROR(isSupportChunk, "TkFrameworkImpl::createJoint: desc.chunkIndices[1] is not a support chunk in the asset for desc.families[1]. Joint not created.", return nullptr); + const bool isSupportChunk = !isInvalidIndex(NvBlastAssetGetChunkToGraphNodeMap(family1->getAssetImpl()->getAssetLLInternal(), logLL)[desc.chunkIndices[1]]); + NVBLAST_CHECK_ERROR(isSupportChunk, "TkFrameworkImpl::createJoint: desc.chunkIndices[1] is not a support chunk in the asset for desc.families[1]. Joint not created.", return nullptr); if (family1 != family0) { handle1 = family1->createExternalJointHandle(getFamilyID(family0), desc.chunkIndices[1], desc.chunkIndices[0]); - NVBLASTTK_CHECK_ERROR(handle1 != nullptr, "TkFrameworkImpl::createJoint: could not create joint handle in family[1]. Joint not created.", return nullptr); + NVBLAST_CHECK_ERROR(handle1 != nullptr, "TkFrameworkImpl::createJoint: could not create joint handle in family[1]. Joint not created.", return nullptr); } } - TkJointImpl* joint = NVBLASTTK_NEW(TkJointImpl)(desc, nullptr); - NVBLASTTK_CHECK_ERROR(joint != nullptr, "TkFrameworkImpl::createJoint: failed to create joint.", return nullptr); + TkJointImpl* joint = NVBLAST_NEW(TkJointImpl)(desc, nullptr); + NVBLAST_CHECK_ERROR(joint != nullptr, "TkFrameworkImpl::createJoint: failed to create joint.", return nullptr); const TkJointData& jointData = joint->getDataInternal(); @@ -468,28 +353,6 @@ TkJoint* TkFrameworkImpl::createJoint(const TkJointDesc& desc) } -bool TkFrameworkImpl::serializeHeader(const TkSerializable& object, PxFileBuf& stream) -{ - const TkTypeImpl& type = static_cast<const TkTypeImpl&>(object.getType()); - - // Tk framework identifier - stream.storeDword(ClassID); - - // Object header - stream.storeDword(type.getID()); - stream.storeDword(type.getVersionInternal()); - - // Object ID - stream.write(&object.getID(), sizeof(NvBlastID)); - - // Serializable user data - stream.storeDword(static_cast<uint32_t>(object.userIntData & 0xFFFFFFFF)); - stream.storeDword(static_cast<uint32_t>(object.userIntData >> 32)); - - return true; -} - - void TkFrameworkImpl::onCreate(TkIdentifiable& object) { const TkTypeImpl& type = static_cast<const TkTypeImpl&>(object.getType()); @@ -500,7 +363,7 @@ void TkFrameworkImpl::onCreate(TkIdentifiable& object) { if (!isInvalidIndex(index)) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::addObject: object type unrecognized."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::addObject: object type unrecognized."); } return; } @@ -529,7 +392,7 @@ void TkFrameworkImpl::onDestroy(TkIdentifiable& object) { if (!isInvalidIndex(index)) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::removeObject: object type unrecognized."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::removeObject: object type unrecognized."); } return; } @@ -541,13 +404,13 @@ void TkFrameworkImpl::onDestroy(TkIdentifiable& object) void TkFrameworkImpl::onCreate(TkJointImpl& joint) { - NVBLASTTK_CHECK_ERROR(m_joints.insert(&joint), "TkFrameworkImpl::onCreate: Joint already tracked.", return); + NVBLAST_CHECK_ERROR(m_joints.insert(&joint), "TkFrameworkImpl::onCreate: Joint already tracked.", return); } void TkFrameworkImpl::onDestroy(TkJointImpl& joint) { - NVBLASTTK_CHECK_ERROR(m_joints.erase(&joint), "TkFrameworkImpl::onDestroy: Joint not tracked.", return); + NVBLAST_CHECK_ERROR(m_joints.erase(&joint), "TkFrameworkImpl::onDestroy: Joint not tracked.", return); } @@ -557,7 +420,7 @@ void TkFrameworkImpl::onIDChange(TkIdentifiable& object, const NvBlastID& IDPrev { if (!m_IDToObject.erase(IDPrev)) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::reportIDChanged: object with previous ID doesn't exist."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::reportIDChanged: object with previous ID doesn't exist."); } } @@ -566,7 +429,7 @@ void TkFrameworkImpl::onIDChange(TkIdentifiable& object, const NvBlastID& IDPrev auto& value = m_IDToObject[IDCurr]; if (value != nullptr) { - NVBLASTTK_LOG_ERROR("TkFrameworkImpl::reportIDChanged: object with new ID already exists."); + NVBLAST_LOG_ERROR("TkFrameworkImpl::reportIDChanged: object with new ID already exists."); return; } value = &object; @@ -579,28 +442,15 @@ void TkFrameworkImpl::onIDChange(TkIdentifiable& object, const NvBlastID& IDPrev //////// Global API implementation //////// -Nv::Blast::TkFramework* NvBlastTkFrameworkCreate(const Nv::Blast::TkFrameworkDesc& desc) +Nv::Blast::TkFramework* NvBlastTkFrameworkCreate() { - if (desc.errorCallback == nullptr) - { - return nullptr; - } - - if (desc.allocatorCallback == nullptr) - { - desc.errorCallback->reportError(PxErrorCode::eINVALID_OPERATION, "TkFramework::create: NULL allocator given in descriptor.", __FILE__, __LINE__); - return nullptr; - } - if (Nv::Blast::TkFrameworkImpl::get() != nullptr) { - desc.errorCallback->reportError(PxErrorCode::eINVALID_OPERATION, "TkFramework::create: framework already created. Use TkFramework::get() to access.", __FILE__, __LINE__); + NVBLAST_LOG_ERROR("TkFramework::create: framework already created. Use TkFramework::get() to access."); return nullptr; } - Nv::Blast::TkAllocator::s_allocatorCallback = desc.allocatorCallback; - - Nv::Blast::TkFrameworkImpl* framework = new (desc.allocatorCallback->allocate(sizeof(Nv::Blast::TkFrameworkImpl), "TkFrameworkImpl", __FILE__, __LINE__)) Nv::Blast::TkFrameworkImpl(desc); + Nv::Blast::TkFrameworkImpl* framework = NVBLAST_NEW(Nv::Blast::TkFrameworkImpl) (); Nv::Blast::TkFrameworkImpl::set(framework); return Nv::Blast::TkFrameworkImpl::get(); diff --git a/sdk/toolkit/source/NvBlastTkFrameworkImpl.h b/sdk/toolkit/source/NvBlastTkFrameworkImpl.h index ceeff06..98fd4da 100644 --- a/sdk/toolkit/source/NvBlastTkFrameworkImpl.h +++ b/sdk/toolkit/source/NvBlastTkFrameworkImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKFRAMEWORKIMPL_H #define NVBLASTTKFRAMEWORKIMPL_H @@ -16,45 +34,9 @@ #include "NvBlastTkCommon.h" -#include "NvBlastTkArray.h" -#include "NvBlastTkHashMap.h" -#include "NvBlastTkHashSet.h" - - -//////// Log macros that use the TkFrameworkImpl::log function //////// - -#define NVBLASTTK_LOG_ERROR(_msg) NVBLAST_LOG_ERROR(TkFrameworkImpl::log, _msg) -#define NVBLASTTK_LOG_WARNING(_msg) NVBLAST_LOG_WARNING(TkFrameworkImpl::log, _msg) -#define NVBLASTTK_LOG_INFO(_msg) NVBLAST_LOG_INFO(TkFrameworkImpl::log, _msg) -#define NVBLASTTK_LOG_DEBUG(_msg) NVBLAST_LOG_DEBUG(TkFrameworkImpl::log, _msg) - -#define NVBLASTTK_CHECK(_expr, _messageType, _msg, _onFail) \ - { \ - if(!(_expr)) \ - { \ - TkFrameworkImpl::log(_messageType, _msg, __FILE__, __LINE__); \ - { _onFail; }; \ - } \ - } - -#define NVBLASTTK_CHECK_ERROR(_expr, _msg, _onFail) NVBLASTTK_CHECK(_expr, NvBlastMessage::Error, _msg, _onFail) -#define NVBLASTTK_CHECK_WARNING(_expr, _msg, _onFail) NVBLASTTK_CHECK(_expr, NvBlastMessage::Warning, _msg, _onFail) -#define NVBLASTTK_CHECK_INFO(_expr, _msg, _onFail) NVBLASTTK_CHECK(_expr, NvBlastMessage::Info, _msg, _onFail) -#define NVBLASTTK_CHECK_DEBUG(_expr, _msg, _onFail) NVBLASTTK_CHECK(_expr, NvBlastMessage::Debug, _msg, _onFail) - - -//////// Allocator macros //////// - -#define NVBLASTTK_ALLOC(_size, _name) TkFrameworkImpl::get()->getAllocatorCallbackInternal().allocate(_size, _name, __FILE__, __LINE__) -#define NVBLASTTK_FREE(_mem) TkFrameworkImpl::get()->getAllocatorCallbackInternal().deallocate(_mem) - -#define NVBLASTTK_NEW(T) new (NVBLASTTK_ALLOC(sizeof(T), #T)) T -#define NVBLASTTK_DELETE(obj, T) \ - (obj)->~T(); \ - NVBLASTTK_FREE(obj) - - - +#include "NvBlastArray.h" +#include "NvBlastHashMap.h" +#include "NvBlastHashSet.h" namespace Nv @@ -72,20 +54,12 @@ Implementation of TkFramework class TkFrameworkImpl : public TkFramework { public: - TkFrameworkImpl(const TkFrameworkDesc& desc); + TkFrameworkImpl(); ~TkFrameworkImpl(); // Begin TkFramework virtual void release() override; - virtual physx::PxErrorCallback& getErrorCallback() const override; - - virtual physx::PxAllocatorCallback& getAllocatorCallback() const override; - - virtual NvBlastLog getLogFn() const override; - - virtual TkSerializable* deserialize(physx::general_PxIOStream2::PxFileBuf& stream) override; - virtual const TkType* getType(TkTypeIndex::Enum typeIndex) const override; virtual TkIdentifiable* findObjectByID(const NvBlastID& id) const override; @@ -94,7 +68,7 @@ public: virtual uint32_t getObjects(TkIdentifiable** buffer, uint32_t bufferSize, const TkType& type, uint32_t indexStart = 0) const override; - virtual bool reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount, NvBlastBondDesc* bondDescs, uint32_t bondCount, uint32_t* chunkReorderMap = nullptr) const override; + virtual bool reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount, NvBlastBondDesc* bondDescs, uint32_t bondCount, uint32_t* chunkReorderMap = nullptr, bool keepBondNormalChunkOrder = false) const override; virtual bool ensureAssetExactSupportCoverage(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount) const override; @@ -111,16 +85,6 @@ public: // Public methods /** - Access to the error callback set by the user. - */ - physx::PxErrorCallback& getErrorCallbackInternal() const; - - /** - Access to the allocator callback set by the user. - */ - physx::PxAllocatorCallback& getAllocatorCallbackInternal() const; - - /** To be called by any TkIdentifiable object when it is created, so the framework can track it. */ void onCreate(TkIdentifiable& object); @@ -150,11 +114,6 @@ public: */ TkIdentifiable* findObjectByIDInternal(const NvBlastID& id) const; - /** - Serialize a TkSerializable's standard header data, including its type ID, type version, object ID, and TkObject::userIntData. - */ - bool serializeHeader(const TkSerializable& object, physx::general_PxIOStream2::PxFileBuf& stream); - // Access to singleton /** Retrieve the global singleton. */ @@ -163,50 +122,28 @@ public: /** Set the global singleton, if it's not already set, or set it to NULL. Returns true iff successful. */ static bool set(TkFrameworkImpl* framework); - // Blast LL context functions - static void log(int type, const char* msg, const char* file, int line); //!< A function with the NvBlastLog signature which can be used in NvBlast low-level function calls - static void* alloc(size_t size); //!< A function with the std::malloc signature which returns 16-byte aligned memory - static void free(void* mem); //!< A function with the std::free signature which can deallocate memory created by alloc - private: // Enums - enum { Alignment = 16 }; //!< Memory alignment used for allocations - enum { ClassID = NVBLASTTK_FOURCC('T', 'K', 'F', 'W') }; //!< TkFramework identifier token, used in serialization + enum { ClassID = NVBLAST_FOURCC('T', 'K', 'F', 'W') }; //!< TkFramework identifier token, used in serialization // Static data static TkFrameworkImpl* s_framework; //!< Global (singleton) object pointer - // Callbacks - physx::PxErrorCallback* m_errorCallback; //!< User-supplied error callback - physx::PxAllocatorCallback* m_allocatorCallback; //!< User-supplied allocator callback - // Types - TkInlineArray<const TkTypeImpl*, TkTypeIndex::TypeCount>::type m_types; //!< TkIdentifiable static type data - TkHashMap<uint32_t, uint32_t>::type m_typeIDToIndex; //!< Map to type data keyed by ClassID + InlineArray<const TkTypeImpl*, TkTypeIndex::TypeCount>::type m_types; //!< TkIdentifiable static type data + HashMap<uint32_t, uint32_t>::type m_typeIDToIndex; //!< Map to type data keyed by ClassID // Objects and object names - TkHashMap<NvBlastID, TkIdentifiable*>::type m_IDToObject; //!< Map to all TkIdentifiable objects, keyed by NvBlastID - TkInlineArray<TkArray<TkIdentifiable*>::type, TkTypeIndex::TypeCount>::type m_objects; //!< Catalog of all TkIdentifiable objects, grouped by type. (Revisit implementation.) + HashMap<NvBlastID, TkIdentifiable*>::type m_IDToObject; //!< Map to all TkIdentifiable objects, keyed by NvBlastID + InlineArray<Array<TkIdentifiable*>::type, TkTypeIndex::TypeCount>::type m_objects; //!< Catalog of all TkIdentifiable objects, grouped by type. (Revisit implementation.) // Track external joints (to do: make this a pool) - TkHashSet<TkJointImpl*>::type m_joints; //!< All internal joints + HashSet<TkJointImpl*>::type m_joints; //!< All internal joints }; //////// TkFrameworkImpl inline methods //////// -NV_INLINE physx::PxErrorCallback& TkFrameworkImpl::getErrorCallbackInternal() const -{ - return *m_errorCallback; -} - - -NV_INLINE physx::PxAllocatorCallback& TkFrameworkImpl::getAllocatorCallbackInternal() const -{ - return *m_allocatorCallback; -} - - NV_INLINE TkIdentifiable* TkFrameworkImpl::findObjectByIDInternal(const NvBlastID& id) const { const auto entry = m_IDToObject.find(id); diff --git a/sdk/toolkit/source/NvBlastTkGUID.h b/sdk/toolkit/source/NvBlastTkGUID.h index a770092..c11b48b 100644 --- a/sdk/toolkit/source/NvBlastTkGUID.h +++ b/sdk/toolkit/source/NvBlastTkGUID.h @@ -3,15 +3,28 @@ // // Notice // NVIDIA Corporation and its licensors retain all intellectual property and -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKGUID_H #define NVBLASTTKGUID_H diff --git a/sdk/toolkit/source/NvBlastTkGroupImpl.cpp b/sdk/toolkit/source/NvBlastTkGroupImpl.cpp index d9a4b29..caa2e76 100644 --- a/sdk/toolkit/source/NvBlastTkGroupImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkGroupImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvPreprocessor.h" @@ -20,17 +38,11 @@ #include "NvBlastTkAssetImpl.h" #include "NvBlastTkTaskImpl.h" -#include "Px.h" -#include "PxFileBuf.h" -#include "PxAllocatorCallback.h" -#include "task/PxCpuDispatcher.h" - #undef max #undef min #include <algorithm> using namespace physx; -using namespace physx::general_PxIOStream2; namespace Nv @@ -43,19 +55,9 @@ namespace Blast NVBLASTTK_DEFINE_TYPE_IDENTIFIABLE(Group); -//////// Local (static) functions //////// - -static uint32_t getNumThreads(PxTaskManager* tm) -{ - if (tm == nullptr) return 0; - if (tm->getCpuDispatcher() == nullptr) return 0; - return tm->getCpuDispatcher()->getWorkerCount(); -} - - //////// Member functions //////// -TkGroupImpl::TkGroupImpl() : m_actorCount(0), m_isProcessing(false), m_sync(0) +TkGroupImpl::TkGroupImpl() : m_actorCount(0), m_isProcessing(false) { #if NV_PROFILE memset(&m_stats, 0, sizeof(TkGroupStats)); @@ -75,7 +77,7 @@ void TkGroupImpl::release() if (isProcessing()) { // abort all processing? - NVBLASTTK_LOG_ERROR("TkGroup::release: cannot release Group while processing."); + NVBLAST_LOG_ERROR("TkGroup::release: cannot release Group while processing."); NVBLAST_ALWAYS_ASSERT_MESSAGE("TkGroup::release: cannot release Group while processing."); return; } @@ -92,7 +94,7 @@ void TkGroupImpl::release() } SharedMemory* mem = it->second; mem->release(); - NVBLASTTK_DELETE(mem, SharedMemory); + NVBLAST_DELETE(mem, SharedMemory); } m_sharedMemory.clear(); @@ -102,7 +104,7 @@ void TkGroupImpl::release() m_chunkEventDataBlock.release(); m_splitScratchBlock.release(); - NVBLASTTK_DELETE(this, TkGroupImpl); + NVBLAST_DELETE(this, TkGroupImpl); } @@ -128,13 +130,13 @@ bool TkGroupImpl::addActor(TkActor& actor) TkActorImpl& tkActor = static_cast<TkActorImpl&>(actor); if (tkActor.getGroup() != nullptr) { - NVBLASTTK_LOG_ERROR("TkGroup::addActor: actor already belongs to a Group. Remove from current group first."); + NVBLAST_LOG_ERROR("TkGroup::addActor: actor already belongs to a Group. Remove from current group first."); return false; } if (isProcessing()) { - NVBLASTTK_LOG_ERROR("TkGroup::addActor: cannot alter Group while processing."); + NVBLAST_LOG_ERROR("TkGroup::addActor: cannot alter Group while processing."); return false; } @@ -155,29 +157,24 @@ bool TkGroupImpl::addActor(TkActor& actor) // the actor belongs to a family not involved in this group yet // shared memory must be allocated and temporary buffers adjusted accordingly - PERF_ZONE_BEGIN("family memory"); - mem = NVBLASTTK_NEW(SharedMemory); + BLAST_PROFILE_ZONE_BEGIN("family memory"); + mem = NVBLAST_NEW(SharedMemory); mem->allocate(family); m_sharedMemory[&family] = mem; - PERF_ZONE_END("family memory"); + BLAST_PROFILE_ZONE_END("family memory"); - PERF_ZONE_BEGIN("group memory"); + BLAST_PROFILE_ZONE_BEGIN("group memory"); - const uint32_t numThreads = getNumThreads(m_pxTaskManager); - // one worker always exists, even if it is the main thread (when numThreads is 0) - const uint32_t numWorkers = std::max(numThreads, (uint32_t)1); - - // the number of threads could have changed, however this is unexpected and handled in process() + const uint32_t workerCount = m_workers.size(); - - NvBlastLog theLog = TkFrameworkImpl::get()->log; + NvBlastLog theLog = logLL; // this group's tasks will use one temporary buffer each, which is of max size of, for all families involved const size_t requiredScratch = NvBlastActorGetRequiredScratchForSplit(tkActor.getActorLL(), theLog); if (static_cast<size_t>(m_splitScratchBlock.numElementsPerBlock()) < requiredScratch) { m_splitScratchBlock.release(); - m_splitScratchBlock.allocate(static_cast<uint32_t>(requiredScratch), numWorkers); + m_splitScratchBlock.allocate(static_cast<uint32_t>(requiredScratch), workerCount); } // generate and apply fracture may create an entry for each bond @@ -185,9 +182,9 @@ bool TkGroupImpl::addActor(TkActor& actor) if (m_bondTempDataBlock.numElementsPerBlock() < bondCount) { m_bondTempDataBlock.release(); - m_bondTempDataBlock.allocate(bondCount, numWorkers); + m_bondTempDataBlock.allocate(bondCount, workerCount); m_bondEventDataBlock.release(); - m_bondEventDataBlock.allocate(bondCount, numWorkers); + m_bondEventDataBlock.allocate(bondCount, workerCount); } // apply fracture may create an entry for each lower-support chunk @@ -199,11 +196,11 @@ bool TkGroupImpl::addActor(TkActor& actor) if (m_chunkTempDataBlock.numElementsPerBlock() < chunkCount) { m_chunkTempDataBlock.release(); - m_chunkTempDataBlock.allocate(chunkCount, numWorkers); + m_chunkTempDataBlock.allocate(chunkCount, workerCount); m_chunkEventDataBlock.release(); - m_chunkEventDataBlock.allocate(chunkCount, numWorkers); + m_chunkEventDataBlock.allocate(chunkCount, workerCount); } - PERF_ZONE_END("group memory"); + BLAST_PROFILE_ZONE_END("group memory"); } mem->addReference(); @@ -213,12 +210,12 @@ bool TkGroupImpl::addActor(TkActor& actor) uint32_t TkGroupImpl::getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart /* = 0 */) const { - PERF_SCOPE_L("TkGroup::getActors"); + BLAST_PROFILE_SCOPE_L("TkGroup::getActors"); uint32_t actorCount = m_actorCount; if (actorCount <= indexStart) { - NVBLASTTK_LOG_WARNING("TkGroup::getActors: indexStart beyond end of actor list."); + NVBLAST_LOG_WARNING("TkGroup::getActors: indexStart beyond end of actor list."); return 0; } @@ -269,7 +266,7 @@ void TkGroupImpl::releaseSharedMemory(TkFamilyImpl* fam, SharedMemory* mem) NVBLAST_ASSERT(mem != nullptr && m_sharedMemory[fam] == mem); mem->release(); m_sharedMemory.erase(fam); - NVBLASTTK_DELETE(mem, SharedMemory); + NVBLAST_DELETE(mem, SharedMemory); } @@ -279,13 +276,13 @@ bool TkGroupImpl::removeActor(TkActor& actor) if (tkActor.getGroup() != this) { - NVBLASTTK_LOG_ERROR("TkGroup::removeActor: actor does not belong to this Group."); + NVBLAST_LOG_ERROR("TkGroup::removeActor: actor does not belong to this Group."); return false; } if (isProcessing()) { - NVBLASTTK_LOG_ERROR("TkGroup::removeActor: cannot alter Group while processing."); + NVBLAST_LOG_ERROR("TkGroup::removeActor: cannot alter Group while processing."); return false; } @@ -320,65 +317,86 @@ bool TkGroupImpl::removeActor(TkActor& actor) TkGroupImpl* TkGroupImpl::create(const TkGroupDesc& desc) { - if (desc.pxTaskManager == nullptr) - { - NVBLASTTK_LOG_WARNING("TkGroup::create: attempting to create a Group with a NULL pxTaskManager."); - } - - TkGroupImpl* group = NVBLASTTK_NEW(TkGroupImpl); + TkGroupImpl* group = NVBLAST_NEW(TkGroupImpl); - group->m_pxTaskManager = desc.pxTaskManager; - group->m_initialNumThreads = getNumThreads(group->m_pxTaskManager); + group->setWorkerCount(desc.workerCount); return group; } -bool TkGroupImpl::process() +void TkGroupImpl::setWorkerCount(uint32_t workerCount) { - PERF_SCOPE_L("TkGroup::process"); - - if (!setProcessing(true)) + if (isProcessing()) { - NVBLASTTK_LOG_WARNING("TkGroup::process: Group is still processing, call TkGroup::sync first."); - return false; + NVBLAST_LOG_WARNING("TkGroup::setWorkerCount: Group is still processing, call TkGroup::endProcess first."); + return; } - if (m_jobs.size() > 0) + if (workerCount == 0) { - PERF_ZONE_BEGIN("task setup"); + NVBLAST_LOG_WARNING("TkGroup: attempting to create a Group with 0 workers. Forced to 1."); + workerCount = 1; + } - PERF_ZONE_BEGIN("task memory"); - const uint32_t numThreads = getNumThreads(m_pxTaskManager); - // one worker always exists, even if it is the main thread (when numThreads is 0) - const uint32_t numWorkers = std::max(numThreads, (uint32_t)1); + if (workerCount != m_workers.size()) + { + m_workers.resize(workerCount); - if (numThreads != m_initialNumThreads) + uint32_t workerId = 0; + for (auto& worker : m_workers) { - NVBLASTTK_LOG_WARNING("TkGroup::process: number of threads has changed, memory is being reallocated."); - m_initialNumThreads = numThreads; + worker.m_id = workerId++; + worker.m_group = this; + } - const uint32_t bondCount = m_bondTempDataBlock.numElementsPerBlock(); - if (bondCount > 0) - { - m_bondTempDataBlock.release(); - m_bondTempDataBlock.allocate(bondCount, numWorkers); - m_bondEventDataBlock.release(); - m_bondEventDataBlock.allocate(bondCount, numWorkers); - } - const uint32_t chunkCount = m_chunkTempDataBlock.numElementsPerBlock(); + const uint32_t bondCount = m_bondTempDataBlock.numElementsPerBlock(); + if (bondCount > 0) + { + m_bondTempDataBlock.release(); + m_bondTempDataBlock.allocate(bondCount, workerCount); + m_bondEventDataBlock.release(); + m_bondEventDataBlock.allocate(bondCount, workerCount); + } + const uint32_t chunkCount = m_chunkTempDataBlock.numElementsPerBlock(); + if (chunkCount > 0) + { m_chunkTempDataBlock.release(); - m_chunkTempDataBlock.allocate(chunkCount, numWorkers); + m_chunkTempDataBlock.allocate(chunkCount, workerCount); m_chunkEventDataBlock.release(); - m_chunkEventDataBlock.allocate(chunkCount, numWorkers); - const uint32_t scratchSize = m_splitScratchBlock.numElementsPerBlock(); + m_chunkEventDataBlock.allocate(chunkCount, workerCount); + } + const uint32_t scratchSize = m_splitScratchBlock.numElementsPerBlock(); + if (scratchSize > 0) + { m_splitScratchBlock.release(); - m_splitScratchBlock.allocate(scratchSize, numWorkers); + m_splitScratchBlock.allocate(scratchSize, workerCount); } - PERF_ZONE_END("task memory"); + } +} + + +NV_INLINE uint32_t TkGroupImpl::getWorkerCount() const +{ + return m_workers.size(); +} + + +uint32_t TkGroupImpl::startProcess() +{ + BLAST_PROFILE_SCOPE_L("TkGroup::startProcess"); + if (!setProcessing(true)) + { + NVBLAST_LOG_WARNING("TkGroup::process: Group is still processing, call TkGroup::endProcess first."); + return 0; + } + + if (m_jobs.size() > 0) + { + BLAST_PROFILE_ZONE_BEGIN("task setup"); - PERF_ZONE_BEGIN("setup job queue"); + BLAST_PROFILE_ZONE_BEGIN("setup job queue"); for (const auto& job : m_jobs) { const TkActorImpl* a = job.m_tkActor; @@ -400,9 +418,9 @@ bool TkGroupImpl::process() // (two TkFracture* events per damage plus one TkSplitEvent) mem->m_eventsCount += 2 * damageCount + 1; } - PERF_ZONE_END("setup job queue"); + BLAST_PROFILE_ZONE_END("setup job queue"); - PERF_ZONE_BEGIN("memory protect"); + BLAST_PROFILE_ZONE_BEGIN("memory protect"); for (auto it = m_sharedMemory.getIterator(); !it.done(); ++it) { // preallocate the event memory for TkWorkers @@ -418,67 +436,38 @@ bool TkGroupImpl::process() // switch to parallel mode mem->m_events.protect(true); } - PERF_ZONE_END("memory protect"); - - PERF_ZONE_END("task setup"); + BLAST_PROFILE_ZONE_END("memory protect"); - // ready queue for the workers - const uint32_t numJobs = m_jobs.size(); - m_jobQueue.init(m_jobs.begin(), numJobs); + BLAST_PROFILE_ZONE_END("task setup"); - // do not start more workers than there are jobs - const uint32_t workersToRun = std::min(numWorkers, numJobs); - m_workers.resize(workersToRun); - m_sync.setCount(workersToRun); - uint32_t workerId = 0; - if (numThreads > 0) - { - for (auto& task : m_workers) - { - PERF_SCOPE_M("task release"); - task.m_id = workerId++; - task.m_group = this; - task.setContinuation(*m_pxTaskManager, nullptr); - // mind m_sync.setCount above, immediately removing reference would not work with a continuation task - task.removeReference(); - } - } - else + for (auto&worker : m_workers) { - // let this thread do the work - NVBLAST_ASSERT(m_workers.size() == 1); - for (auto& task : m_workers) - { - task.m_id = workerId++; - task.m_group = this; - task.run(); - task.release(); - } + worker.initialize(); } - } - - return true; + return m_jobs.size(); + } + else + { + bool success = setProcessing(false); + NVBLAST_ASSERT(success); + NV_UNUSED(success); + return 0; + } } -bool TkGroupImpl::sync(bool block /*= true*/) +bool TkGroupImpl::endProcess() { - if (!m_sync.isDone() && block) - { - PERF_SCOPE_L("TkGroupImpl::sync wait"); - m_sync.wait(); - } - - if (isProcessing() && m_sync.isDone()) + if (isProcessing()) { - PERF_SCOPE_L("TkGroupImpl::sync finalize"); + BLAST_PROFILE_SCOPE_L("TkGroupImpl::endProcess"); if (m_jobs.size() > 0) { #if NV_PROFILE - PERF_ZONE_BEGIN("accumulate timers"); + BLAST_PROFILE_ZONE_BEGIN("accumulate timers"); NvBlastTimers accumulated; NvBlastTimersReset(&accumulated); uint32_t jobCount = 0; @@ -492,10 +481,10 @@ bool TkGroupImpl::sync(bool block /*= true*/) m_stats.timers = accumulated; m_stats.processedActorsCount = jobCount; m_stats.workerTime = workerTime; - PERF_ZONE_END("accumulate timers"); + BLAST_PROFILE_ZONE_END("accumulate timers"); #endif - PERF_ZONE_BEGIN("job update"); + BLAST_PROFILE_ZONE_BEGIN("job update"); for (auto& j : m_jobs) { if (j.m_newActorsCount) @@ -511,21 +500,26 @@ bool TkGroupImpl::sync(bool block /*= true*/) // Update joints mem->m_events.protect(false); // allow allocations again + BLAST_PROFILE_ZONE_BEGIN("updateJoints"); fam->updateJoints(j.m_tkActor, &mem->m_events); + BLAST_PROFILE_ZONE_END("updateJoints"); } // virtually dequeue the actor // the queue itself is cleared right after this loop j.m_tkActor->m_flags.clear(TkActorFlag::PENDING); j.m_tkActor->m_groupJobIndex = invalidIndex<uint32_t>(); + BLAST_PROFILE_ZONE_BEGIN("damageBuffer.clear"); j.m_tkActor->m_damageBuffer.clear(); + BLAST_PROFILE_ZONE_END("damageBuffer.clear"); } m_jobs.clear(); - PERF_ZONE_END("job update"); + BLAST_PROFILE_ZONE_END("job update"); - PERF_ZONE_BEGIN("event dispatch"); + BLAST_PROFILE_ZONE_BEGIN("event dispatch"); for (auto it = m_sharedMemory.getIterator(); !it.done(); ++it) { + BLAST_PROFILE_SCOPE_L("event dispatch"); TkFamilyImpl* family = it->first; SharedMemory* mem = it->second; @@ -542,15 +536,15 @@ bool TkGroupImpl::sync(bool block /*= true*/) mem->m_events.reset(); mem->reset(); } - PERF_ZONE_END("event dispatch"); + BLAST_PROFILE_ZONE_END("event dispatch"); - PERF_ZONE_BEGIN("event memory release"); + BLAST_PROFILE_ZONE_BEGIN("event memory release"); for (auto& worker : m_workers) { worker.m_bondBuffer.clear(); worker.m_chunkBuffer.clear(); } - PERF_ZONE_END("event memory release"); + BLAST_PROFILE_ZONE_END("event memory release"); } bool success = setProcessing(false); @@ -588,5 +582,31 @@ void TkGroupImpl::enqueue(TkActorImpl* tkActor) } +TkGroupWorker* TkGroupImpl::acquireWorker() +{ + BLAST_PROFILE_SCOPE_L("TkGroupImpl::acquireWorker"); + std::unique_lock<std::mutex> lk(m_workerMtx); + for (auto& worker:m_workers) + { + if (!worker.m_isBusy) + { + worker.m_isBusy = true; + return &worker; + } + } + return nullptr; +} + + +void TkGroupImpl::returnWorker(TkGroupWorker* worker) +{ + BLAST_PROFILE_SCOPE_L("TkGroupImpl::returnWorker"); + std::unique_lock<std::mutex> lk(m_workerMtx); + auto w = static_cast<TkWorker*>(worker); + NVBLAST_CHECK_WARNING(w->m_group == this, "TkGroup::returnWorker worker does not belong to this group.", return); + w->m_isBusy = false; +} + + } // namespace Blast } // namespace Nv diff --git a/sdk/toolkit/source/NvBlastTkGroupImpl.h b/sdk/toolkit/source/NvBlastTkGroupImpl.h index db7e7c1..ea5b926 100644 --- a/sdk/toolkit/source/NvBlastTkGroupImpl.h +++ b/sdk/toolkit/source/NvBlastTkGroupImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKGROUPIMPL_H #define NVBLASTTKGROUPIMPL_H @@ -34,20 +52,25 @@ public: NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('G', 'R', 'P', '\0'); - static TkGroupImpl* create(const TkGroupDesc& desc); + static TkGroupImpl* create(const TkGroupDesc& desc); // Begin TkGroup - virtual bool addActor(TkActor& actor) override; + virtual bool addActor(TkActor& actor) override; + + virtual uint32_t getActorCount() const override; - virtual uint32_t getActorCount() const override; + virtual uint32_t getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart = 0) const override; - virtual uint32_t getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart = 0) const override; + virtual uint32_t startProcess() override; + virtual bool endProcess() override; - virtual bool process() override; + virtual void getStats(TkGroupStats& stats) const override; - virtual bool sync(bool block = true) override; + virtual void setWorkerCount(uint32_t workerCount) override; + virtual uint32_t getWorkerCount() const override; - virtual void getStats(TkGroupStats& stats) const override; + virtual TkGroupWorker* acquireWorker() override; + virtual void returnWorker(TkGroupWorker*) override; // End TkGroup // TkGroupImpl API @@ -55,54 +78,51 @@ public: /** Remove the actor from this group if the actor actually belongs to it and the group is not processing. - \param[in] actor The TkActor to remove. + \param[in] actor The TkActor to remove. - \return true if removing succeeded, false otherwise + \return true if removing succeeded, false otherwise */ - bool removeActor(TkActor& actor); + bool removeActor(TkActor& actor); /** Add the actor to this group's job queue. It is the caller's responsibility to add an actor only once. This condition is checked in debug builds. */ - void enqueue(TkActorImpl* tkActor); + void enqueue(TkActorImpl* tkActor); /** Atomically check if this group is processing actors. @see setProcessing() \return true between process() and sync() calls, false otherwise */ - bool isProcessing() const; + bool isProcessing() const; private: /** Atomically set the processing state. This function checks for the current state before changing it. @see isProcessing() - \param[in] value the value of the new state + \param[in] value the value of the new state - \return true if the new state could be set, false otherwise + \return true if the new state could be set, false otherwise */ - bool setProcessing(bool value); + bool setProcessing(bool value); /** Get the group-family shared memory for the specified family. To be used when the memory is expected to already exist. */ - SharedMemory* getSharedMemory(TkFamilyImpl* family); - void releaseSharedMemory(TkFamilyImpl* fam, SharedMemory* mem); + SharedMemory* getSharedMemory(TkFamilyImpl* family); + void releaseSharedMemory(TkFamilyImpl* fam, SharedMemory* mem); // functions to add/remove actors _without_ group-family memory management - void addActorInternal(TkActorImpl& tkActor); - void addActorsInternal(TkActorImpl** actors, uint32_t numActors); - void removeActorInternal(TkActorImpl& tkActor); + void addActorInternal(TkActorImpl& tkActor); + void addActorsInternal(TkActorImpl** actors, uint32_t numActors); + void removeActorInternal(TkActorImpl& tkActor); - physx::PxTaskManager* m_pxTaskManager; //!< the task manager used to dispatch workers - uint32_t m_initialNumThreads; //!< tracks the number of worker threads - uint32_t m_actorCount; //!< number of actors in this group - TkHashMap<TkFamilyImpl*, SharedMemory*>::type m_sharedMemory; //!< memory sharable by actors in the same family in this group + HashMap<TkFamilyImpl*, SharedMemory*>::type m_sharedMemory; //!< memory sharable by actors in the same family in this group // it is assumed no more than the asset's number of bond and chunks fracture commands are produced SharedBlock<NvBlastChunkFractureData> m_chunkTempDataBlock; //!< chunk data for damage/fracture @@ -112,17 +132,17 @@ private: SharedBlock<char> m_splitScratchBlock; //!< split scratch memory std::atomic<bool> m_isProcessing; //!< true while workers are processing - TaskSync m_sync; //!< keeps track of finished workers - TkArray<TkWorker>::type m_workers; //!< this group's workers - TkAtomicJobQueue m_jobQueue; //!< shared job queue for workers + Array<TkWorker>::type m_workers; //!< this group's workers - TkArray<TkWorkerJob>::type m_jobs; //!< this group's process jobs + Array<TkWorkerJob>::type m_jobs; //!< this group's process jobs //#if NV_PROFILE TkGroupStats m_stats; //!< accumulated group's worker stats //#endif + std::mutex m_workerMtx; + friend class TkWorker; }; diff --git a/sdk/toolkit/source/NvBlastTkHashMap.h b/sdk/toolkit/source/NvBlastTkHashMap.h deleted file mode 100644 index 14730c6..0000000 --- a/sdk/toolkit/source/NvBlastTkHashMap.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ - -#ifndef NVBLASTTKHASHMAP_H -#define NVBLASTTKHASHMAP_H - - -#include "NvBlastTkAllocator.h" -#include "PsHashMap.h" - - -namespace Nv -{ -namespace Blast -{ - -template <class Key, class Value, class HashFn = physx::shdfnd::Hash<Key>> -struct TkHashMap -{ - typedef physx::shdfnd::HashMap<Key, Value, HashFn, TkAllocator> type; -}; - -} // namespace Blast -} // namespace Nv - - -#endif // #ifndef NVBLASTTKHASHMAP_H diff --git a/sdk/toolkit/source/NvBlastTkHashSet.h b/sdk/toolkit/source/NvBlastTkHashSet.h deleted file mode 100644 index 4a3a3a0..0000000 --- a/sdk/toolkit/source/NvBlastTkHashSet.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ - -#ifndef NVBLASTTKHASHSET_H -#define NVBLASTTKHASHSET_H - - -#include "NvBlastTkAllocator.h" -#include "PsHashSet.h" - - -namespace Nv -{ -namespace Blast -{ - -template <class Key, class HashFn = physx::shdfnd::Hash<Key>> -struct TkHashSet -{ - typedef physx::shdfnd::HashSet<Key, HashFn, TkAllocator> type; -}; - -} // namespace Blast -} // namespace Nv - - -#endif // #ifndef NVBLASTTKHASHSET_H diff --git a/sdk/toolkit/source/NvBlastTkJointImpl.cpp b/sdk/toolkit/source/NvBlastTkJointImpl.cpp index 46d6378..9c92b2d 100644 --- a/sdk/toolkit/source/NvBlastTkJointImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkJointImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastTkFrameworkImpl.h" #include "NvBlastTkJointImpl.h" @@ -15,10 +33,6 @@ #include "NvBlastTkFamilyImpl.h" #include "Px.h" -#include "PxFileBuf.h" -#include "PxAllocatorCallback.h" - -using namespace physx::general_PxIOStream2; namespace Nv @@ -68,7 +82,7 @@ void TkJointImpl::release() // External joint removeReferencesInFamilies(); TkFrameworkImpl::get()->onDestroy(*this); - NVBLASTTK_DELETE(this, TkJointImpl); + NVBLAST_DELETE(this, TkJointImpl); } } diff --git a/sdk/toolkit/source/NvBlastTkJointImpl.h b/sdk/toolkit/source/NvBlastTkJointImpl.h index ec57309..09bae43 100644 --- a/sdk/toolkit/source/NvBlastTkJointImpl.h +++ b/sdk/toolkit/source/NvBlastTkJointImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKJOINTIMPL_H #define NVBLASTTKJOINTIMPL_H diff --git a/sdk/toolkit/source/NvBlastTkTaskImpl.cpp b/sdk/toolkit/source/NvBlastTkTaskImpl.cpp index 3249928..e08986a 100644 --- a/sdk/toolkit/source/NvBlastTkTaskImpl.cpp +++ b/sdk/toolkit/source/NvBlastTkTaskImpl.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastTime.h" @@ -26,7 +44,7 @@ void SharedMemory::allocate(TkFamilyImpl& tkFamily) // at most leafChunkCount actors can be created within a family // tasks will grab their portion out of these memory blocks - uint32_t leafChunkCount = NvBlastAssetGetLeafChunkCount(assetLL, TkFrameworkImpl::get()->log); + uint32_t leafChunkCount = NvBlastAssetGetLeafChunkCount(assetLL, logLL); m_newActorBuffers.allocate(2 * leafChunkCount); // GWD-167 workaround (2*) m_newTkActorBuffers.allocate(leafChunkCount); } @@ -107,157 +125,147 @@ NV_FORCE_INLINE void reportFractureEvents( } -void TkWorker::run() +void TkWorker::initialize() { - PERF_SCOPE_L("TkWorker Task"); - - NvBlastTimers* timers = nullptr; - -#if NV_PROFILE - NvBlastTimers myTimers; - timers = &myTimers; - NvBlastTimersReset(timers); - uint32_t jobCount = 0; - Time workTime; -#endif - // temporary memory used to generate and apply fractures // it must fit for the largest family involved in the group that owns this worker NvBlastBondFractureData* bondFractureData = m_group->m_bondTempDataBlock.getBlock(m_id); uint32_t bondFractureCount = m_group->m_bondTempDataBlock.numElementsPerBlock(); NvBlastChunkFractureData* chunkFractureData = m_group->m_chunkTempDataBlock.getBlock(m_id); uint32_t chunkFractureCount = m_group->m_chunkTempDataBlock.numElementsPerBlock(); - const NvBlastFractureBuffers tempBuffer = { bondFractureCount, chunkFractureCount, bondFractureData, chunkFractureData }; + m_tempBuffer = { bondFractureCount, chunkFractureCount, bondFractureData, chunkFractureData }; // temporary memory used to split the actor // large enough for the largest family involved - void* splitScratch = m_group->m_splitScratchBlock.getBlock(m_id); + m_splitScratch = m_group->m_splitScratchBlock.getBlock(m_id); // to avoid unnecessary allocations, preallocated memory exists to fit all chunks and bonds taking damage once // where multiple damage occurs, more memory will be allocated on demand (this may thwart other threads doing the same) m_bondBuffer.initialize(m_group->m_bondEventDataBlock.getBlock(m_id), m_group->m_bondEventDataBlock.numElementsPerBlock()); m_chunkBuffer.initialize(m_group->m_chunkEventDataBlock.getBlock(m_id), m_group->m_chunkEventDataBlock.numElementsPerBlock()); - TkAtomicJobQueue& q = m_group->m_jobQueue; - TkWorkerJob* j; +#if NV_PROFILE + NvBlastTimersReset(&m_stats.timers); + m_stats.processedActorsCount = 0; +#endif +} - while ((j = q.next()) != nullptr) - { - PERF_SCOPE_M("TkActor"); +void TkWorker::process(TkWorkerJob& j) +{ + NvBlastTimers* timers = nullptr; + + BLAST_PROFILE_SCOPE_M("TkActor"); - TkActorImpl* tkActor = j->m_tkActor; - const uint32_t tkActorIndex = tkActor->getIndex(); - NvBlastActor* actorLL = tkActor->getActorLLInternal(); - TkFamilyImpl& family = tkActor->getFamilyImpl(); - SharedMemory* mem = m_group->getSharedMemory(&family); - TkEventQueue& events = mem->m_events; + TkActorImpl* tkActor = j.m_tkActor; + const uint32_t tkActorIndex = tkActor->getIndex(); + NvBlastActor* actorLL = tkActor->getActorLLInternal(); + TkFamilyImpl& family = tkActor->getFamilyImpl(); + SharedMemory* mem = m_group->getSharedMemory(&family); + TkEventQueue& events = mem->m_events; - NVBLAST_ASSERT(tkActor->getGroupImpl() == m_group); + NVBLAST_ASSERT(tkActor->getGroupImpl() == m_group); + NVBLAST_ASSERT(tkActor->m_flags.isSet(TkActorFlag::PENDING)); #if NV_PROFILE - *timers += tkActor->m_timers; - NvBlastTimersReset(&tkActor->m_timers); - jobCount++; + timers = &m_stats.timers; + *timers += tkActor->m_timers; + NvBlastTimersReset(&tkActor->m_timers); + m_stats.processedActorsCount++; #endif - // generate and apply fracture for all damage requested on this actor - // and queue events accordingly - for (const auto& damage : tkActor->m_damageBuffer) + // generate and apply fracture for all damage requested on this actor + // and queue events accordingly + for (const auto& damage : tkActor->m_damageBuffer) + { + NvBlastFractureBuffers commandBuffer = m_tempBuffer; + + BLAST_PROFILE_ZONE_BEGIN("Material"); + damage.generateFracture(&commandBuffer, actorLL, timers); + BLAST_PROFILE_ZONE_END("Material"); + + if (commandBuffer.chunkFractureCount > 0 || commandBuffer.bondFractureCount > 0) { - NvBlastFractureBuffers commandBuffer = tempBuffer; - - PERF_ZONE_BEGIN("Material"); - damage.generateFracture(&commandBuffer, actorLL, timers); - PERF_ZONE_END("Material"); - - if (commandBuffer.chunkFractureCount > 0 || commandBuffer.bondFractureCount > 0) - { - PERF_SCOPE_M("Fill Command Events"); - reportFractureCommands(commandBuffer, m_bondBuffer, m_chunkBuffer, events, tkActor); - } - - NvBlastFractureBuffers eventBuffer = tempBuffer; - - PERF_ZONE_BEGIN("Fracture"); - NvBlastActorApplyFracture(&eventBuffer, actorLL, &commandBuffer, TkFrameworkImpl::get()->log, timers); - PERF_ZONE_END("Fracture"); - - if (eventBuffer.chunkFractureCount > 0 || eventBuffer.bondFractureCount > 0) - { - PERF_SCOPE_M("Fill Fracture Events"); - tkActor->m_flags |= (TkActorFlag::DAMAGED); - reportFractureEvents(eventBuffer, m_bondBuffer, m_chunkBuffer, events, tkActor); - } + BLAST_PROFILE_SCOPE_M("Fill Command Events"); + reportFractureCommands(commandBuffer, m_bondBuffer, m_chunkBuffer, events, tkActor); } + NvBlastFractureBuffers eventBuffer = m_tempBuffer; - // split the actor, which could have been damaged directly though the TkActor's fracture functions - // i.e. it did not have damage queued for the above loop + BLAST_PROFILE_ZONE_BEGIN("Fracture"); + NvBlastActorApplyFracture(&eventBuffer, actorLL, &commandBuffer, logLL, timers); + BLAST_PROFILE_ZONE_END("Fracture"); - NvBlastActorSplitEvent splitEvent = { nullptr, nullptr }; - if (tkActor->isDamaged()) - { - PERF_ZONE_BEGIN("Split Memory"); - uint32_t maxActorCount = NvBlastActorGetMaxActorCountForSplit(actorLL, TkFrameworkImpl::get()->log); - splitEvent.newActors = mem->reserveNewActors(maxActorCount); - PERF_ZONE_END("Split Memory"); - PERF_ZONE_BEGIN("Split"); - j->m_newActorsCount = NvBlastActorSplit(&splitEvent, actorLL, maxActorCount, splitScratch, TkFrameworkImpl::get()->log, timers); - PERF_ZONE_END("Split"); - - tkActor->m_flags.clear(TkActorFlag::DAMAGED); - } - else + if (eventBuffer.chunkFractureCount > 0 || eventBuffer.bondFractureCount > 0) { - j->m_newActorsCount = 0; + BLAST_PROFILE_SCOPE_M("Fill Fracture Events"); + tkActor->m_flags |= (TkActorFlag::DAMAGED); + reportFractureEvents(eventBuffer, m_bondBuffer, m_chunkBuffer, events, tkActor); } + } - // update the TkActor according to the LL split results and queue events accordingly - if (j->m_newActorsCount > 0) - { - NVBLAST_ASSERT(splitEvent.deletedActor == tkActor->getActorLL()); + // split the actor, which could have been damaged directly though the TkActor's fracture functions + // i.e. it did not have damage queued for the above loop - PERF_ZONE_BEGIN("memory new actors"); + NvBlastActorSplitEvent splitEvent = { nullptr, nullptr }; + if (tkActor->isDamaged()) + { + BLAST_PROFILE_ZONE_BEGIN("Split Memory"); + uint32_t maxActorCount = NvBlastActorGetMaxActorCountForSplit(actorLL, logLL); + splitEvent.newActors = mem->reserveNewActors(maxActorCount); + BLAST_PROFILE_ZONE_END("Split Memory"); + BLAST_PROFILE_ZONE_BEGIN("Split"); + j.m_newActorsCount = NvBlastActorSplit(&splitEvent, actorLL, maxActorCount, m_splitScratch, logLL, timers); + BLAST_PROFILE_ZONE_END("Split"); + + tkActor->m_flags.clear(TkActorFlag::DAMAGED); + } + else + { + j.m_newActorsCount = 0; + } - auto tkSplitEvent = events.allocData<TkSplitEvent>(); - tkSplitEvent->children = mem->reserveNewTkActors(j->m_newActorsCount); - tkSplitEvent->numChildren = j->m_newActorsCount; + // update the TkActor according to the LL split results and queue events accordingly + if (j.m_newActorsCount > 0) + { + NVBLAST_ASSERT(splitEvent.deletedActor == tkActor->getActorLL()); + + BLAST_PROFILE_ZONE_BEGIN("memory new actors"); - tkSplitEvent->parentData.family = &family; - tkSplitEvent->parentData.userData = tkActor->userData; - tkSplitEvent->parentData.index = tkActorIndex; - family.removeActor(tkActor); + auto tkSplitEvent = events.allocData<TkSplitEvent>(); - PERF_ZONE_END("memory new actors"); + tkSplitEvent->children = mem->reserveNewTkActors(j.m_newActorsCount); + tkSplitEvent->numChildren = j.m_newActorsCount; + tkSplitEvent->parentData.family = &family; + tkSplitEvent->parentData.userData = tkActor->userData; + tkSplitEvent->parentData.index = tkActorIndex; + family.removeActor(tkActor); - PERF_ZONE_BEGIN("create new actors"); - for (uint32_t i = 0; i < j->m_newActorsCount; ++i) - { - TkActorImpl* newActor = family.addActor(splitEvent.newActors[i]); - tkSplitEvent->children[i] = newActor; - } - j->m_newActors = reinterpret_cast<TkActorImpl**>(tkSplitEvent->children); - PERF_ZONE_END("create new actors"); + BLAST_PROFILE_ZONE_END("memory new actors"); - PERF_ZONE_BEGIN("split event"); - events.addEvent(tkSplitEvent); - PERF_ZONE_END("split event"); + + BLAST_PROFILE_ZONE_BEGIN("create new actors"); + for (uint32_t i = 0; i < j.m_newActorsCount; ++i) + { + TkActorImpl* newActor = family.addActor(splitEvent.newActors[i]); + tkSplitEvent->children[i] = newActor; } + j.m_newActors = reinterpret_cast<TkActorImpl**>(tkSplitEvent->children); + BLAST_PROFILE_ZONE_END("create new actors"); + + BLAST_PROFILE_ZONE_BEGIN("split event"); + events.addEvent(tkSplitEvent); + BLAST_PROFILE_ZONE_END("split event"); } -#if NV_PROFILE - PERF_ZONE_BEGIN("write timers"); - m_stats.timers = *timers; - m_stats.processedActorsCount = jobCount; - m_stats.workerTime = workTime.getElapsedTicks(); - PERF_ZONE_END("write timers"); -#endif + j.m_tkActor->m_flags.clear(TkActorFlag::PENDING); } -void TkWorker::release() + +void TkWorker::process(uint32_t jobID) { - m_group->m_sync.notify(); + TkWorkerJob& j = m_group->m_jobs[jobID]; + process(j); } diff --git a/sdk/toolkit/source/NvBlastTkTaskImpl.h b/sdk/toolkit/source/NvBlastTkTaskImpl.h index 75f92f8..4b7ef98 100644 --- a/sdk/toolkit/source/NvBlastTkTaskImpl.h +++ b/sdk/toolkit/source/NvBlastTkTaskImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKTASKIMPL_H #define NVBLASTTKTASKIMPL_H @@ -15,13 +33,12 @@ #include "NvBlastTkFrameworkImpl.h" #include "NvBlastTkEventQueue.h" -#include "NvBlastTkArray.h" +#include "NvBlastArray.h" #include <atomic> #include <mutex> #include <condition_variable> -#include "task/PxTask.h" #include "NvBlastAssert.h" #include "NvBlastTkGroup.h" // TkGroupStats @@ -48,63 +65,7 @@ struct TkWorkerJob }; -/** -Counting synchronization object for waiting on TkWorkers to finish. -*/ -class TaskSync -{ -public: - /** - Initializes with an expected number of notifications. - */ - TaskSync(uint32_t count) : m_count(count) {} - - /** - Blocks until the expected number of notifications happened. - */ - void wait() - { - std::unique_lock<std::mutex> lk(m_mutex); - m_cv.wait(lk, [&]{ return m_count == 0; }); - } - - /** - Decrement the wait() count by one. - */ - void notify() - { - PERF_SCOPE_H("TaskSync::notify"); - std::unique_lock<std::mutex> lk(m_mutex); - m_count--; - if (m_count == 0) - { - lk.unlock(); - m_cv.notify_one(); - } - } - - /** - Peek if notifications are pending. - */ - bool isDone() - { - std::unique_lock<std::mutex> lk(m_mutex); - return m_count == 0; - } - - /** - Sets the expected number of notifications for wait() to unblock. - */ - void setCount(uint32_t count) - { - m_count = count; - } -private: - std::mutex m_mutex; - std::condition_variable m_cv; - uint32_t m_count; -}; /** @@ -124,7 +85,7 @@ public: { NVBLAST_ASSERT(elementsPerBlock > 0 && numBlocks > 0); - m_buffer = reinterpret_cast<T*>(NVBLASTTK_ALLOC(elementsPerBlock*numBlocks*sizeof(T), "SharedBlock")); + m_buffer = reinterpret_cast<T*>(NVBLAST_ALLOC_NAMED(elementsPerBlock*numBlocks*sizeof(T), "SharedBlock")); m_numElementsPerBlock = elementsPerBlock; m_numBlocks = numBlocks; } @@ -153,7 +114,7 @@ public: { m_numBlocks = 0; m_numElementsPerBlock = 0; - NVBLASTTK_FREE(m_buffer); + NVBLAST_FREE(m_buffer); m_buffer = nullptr; } @@ -192,7 +153,7 @@ public: void allocate(size_t capacity) { NVBLAST_ASSERT(m_buffer == nullptr); - m_buffer = reinterpret_cast<T*>(NVBLASTTK_ALLOC(capacity*sizeof(T), "SplitMemory")); + m_buffer = reinterpret_cast<T*>(NVBLAST_ALLOC_NAMED(capacity*sizeof(T), "SplitMemory")); m_capacity = capacity; } @@ -210,7 +171,7 @@ public: void release() { NVBLAST_ASSERT(m_buffer != nullptr); - NVBLASTTK_FREE(m_buffer); + NVBLAST_FREE(m_buffer); m_buffer = nullptr; m_capacity = m_used = 0; } @@ -254,7 +215,7 @@ public: { for (void* block : m_memoryBlocks) { - NVBLASTTK_FREE(block); + NVBLAST_FREE(block); } m_memoryBlocks.clear(); } @@ -276,14 +237,14 @@ private: */ void allocateNewBlock(size_t capacity) { - PERF_SCOPE_L("Local Buffer allocation"); + BLAST_PROFILE_SCOPE_L("Local Buffer allocation"); m_capacity = capacity; - m_currentBlock = static_cast<T*>(NVBLASTTK_ALLOC(capacity*sizeof(T), "Blast LocalBuffer")); + m_currentBlock = static_cast<T*>(NVBLAST_ALLOC_NAMED(capacity*sizeof(T), "Blast LocalBuffer")); m_memoryBlocks.pushBack(m_currentBlock); m_used = 0; } - TkInlineArray<void*, 4>::type m_memoryBlocks; //!< storage for memory blocks + InlineArray<void*, 4>::type m_memoryBlocks; //!< storage for memory blocks T* m_currentBlock; //!< memory block used to allocate from size_t m_used; //!< elements used in current block size_t m_capacity; //!< elements available in current block @@ -379,54 +340,18 @@ private: /** -Shared job queue from which TkWorkers atomically fetch the next job. -*/ -template <typename T> -class TkAtomicQueue -{ -public: - /** - Initialize for a new batch of jobs. - */ - void init(TkWorkerJob* jobs, uint32_t numJobs) - { - m_jobs = jobs; - m_maxCount = numJobs; - m_current = 0; - } - - /** - Fetch a pointer to the next job. Returns nullptr when exhausted. - */ - T* next() - { - size_t index = m_current.fetch_add(1, std::memory_order_relaxed); - if (index < m_maxCount) - { - return &m_jobs[index]; - } - return nullptr; - } - -private: - T* m_jobs; //!< the list of jobs - size_t m_maxCount; //!< number of jobs available in the list - std::atomic<size_t> m_current; //!< current job counter -}; - -typedef TkAtomicQueue<TkWorkerJob> TkAtomicJobQueue; - - -/** Thread worker fracturing and splitting actors sequentially. The list of actual jobs is provided by the group owning this worker. */ -class TkWorker : public physx::PxLightCpuTask +class TkWorker final : public TkGroupWorker { public: - void run(); - void release(); - const char* getName() const { return "TkWorker"; } + TkWorker() : m_id(~(uint32_t)0), m_group(nullptr), m_isBusy(false) {} + + void process(uint32_t jobID); + void initialize(); + + void process(TkWorkerJob& job); uint32_t m_id; //!< this worker's id TkGroupImpl* m_group; //!< the group owning this worker @@ -434,6 +359,10 @@ public: LocalBuffer<NvBlastChunkFractureData> m_chunkBuffer; //!< memory manager for chunk event data LocalBuffer<NvBlastBondFractureData> m_bondBuffer; //!< memory manager for bonds event data + void* m_splitScratch; + NvBlastFractureBuffers m_tempBuffer; + bool m_isBusy; + #if NV_PROFILE TkGroupStats m_stats; #endif diff --git a/sdk/toolkit/source/NvBlastTkTypeImpl.h b/sdk/toolkit/source/NvBlastTkTypeImpl.h index a29c32f..ea27619 100644 --- a/sdk/toolkit/source/NvBlastTkTypeImpl.h +++ b/sdk/toolkit/source/NvBlastTkTypeImpl.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. -* -* NVIDIA CORPORATION and its licensors retain all intellectual property -* and proprietary rights in and to this software, related documentation -* and any modifications thereto. Any use, reproduction, disclosure or -* distribution of this software and related documentation without an express -* license agreement from NVIDIA CORPORATION is strictly prohibited. -*/ +// This code contains NVIDIA Confidential Information and is disclosed to you +// under a form of NVIDIA software license agreement provided separately to you. +// +// Notice +// NVIDIA Corporation and its licensors retain all intellectual property and +// proprietary rights in and to this software and related documentation and +// any modifications thereto. Any use, reproduction, disclosure, or +// distribution of this software and related documentation without an express +// license agreement from NVIDIA Corporation is strictly prohibited. +// +// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES +// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO +// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, +// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. +// +// Information and code furnished is believed to be accurate and reliable. +// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such +// information or for any infringement of patents or other rights of third parties that may +// result from its use. No license is granted by implication or otherwise under any patent +// or patent rights of NVIDIA Corporation. Details are subject to change without notice. +// This code supersedes and replaces all information previously supplied. +// NVIDIA Corporation products are not authorized for use as critical +// components in life support devices or systems without express written approval of +// NVIDIA Corporation. +// +// Copyright (c) 2016-2017 NVIDIA Corporation. All rights reserved. + #ifndef NVBLASTTKTYPEIMPL_H #define NVBLASTTKTYPEIMPL_H @@ -17,36 +35,18 @@ #include "NvBlastTkType.h" -// Forward declarations -namespace physx -{ -namespace general_PxIOStream2 -{ -class PxFileBuf; -} -} - - namespace Nv { namespace Blast { -// Forward declarations -class TkSerializable; - - -// Serialization function signature -typedef TkSerializable* (*TkDeserializeFn)(physx::general_PxIOStream2::PxFileBuf&, const NvBlastID& id); - - /** Implementation of TkType, storing class information for TkIdentifiable-derived classes. */ class TkTypeImpl : public TkType { public: - TkTypeImpl(const char* typeName, uint32_t typeID, uint32_t version, TkDeserializeFn deserializeFn); + TkTypeImpl(const char* typeName, uint32_t typeID, uint32_t version); // Begin TkType virtual const char* getName() const override { return getNameInternal(); } @@ -64,25 +64,20 @@ public: const char* getNameInternal() const; /** - Access to the data format version for the class (used if it TkSerializable-derived). + Access to the data format version for the class. \return the data format version. */ uint32_t getVersionInternal() const; /** - Access to a unique identifier for the class (set using the NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE or NVBLASTTK_IMPL_DEFINE_SERIALIZABLE macro). + Access to a unique identifier for the class (set using the NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE macro). \return the class's unique identifier. */ uint32_t getID() const; /** - \return the class's deserialization function. - */ - TkDeserializeFn getDeserializeFn() const; - - /** Access to a runtime-unique small index for the class. \return the index for the class. @@ -107,7 +102,6 @@ private: const char* m_name; //!< The name of the class, set by the constructor. uint32_t m_ID; //!< The unique identifier for the class, set by the constructor. uint32_t m_version; //!< The data format version for the class, set by the constructor. - TkDeserializeFn m_deserializeFn; //!< The class deserialization function, set by the constructor. uint32_t m_index; //!< The index set for this class, set using setIndex(). friend class TkFrameworkImpl; @@ -116,11 +110,10 @@ private: //////// TkTypeImpl inline methods //////// -NV_INLINE TkTypeImpl::TkTypeImpl(const char* typeName, uint32_t typeID, uint32_t version, TkDeserializeFn deserializeFn) +NV_INLINE TkTypeImpl::TkTypeImpl(const char* typeName, uint32_t typeID, uint32_t version) : m_name(typeName) , m_ID(typeID) , m_version(version) - , m_deserializeFn(deserializeFn) , m_index((uint32_t)InvalidIndex) { } @@ -144,12 +137,6 @@ NV_INLINE uint32_t TkTypeImpl::getID() const } -NV_INLINE TkDeserializeFn TkTypeImpl::getDeserializeFn() const -{ - return m_deserializeFn; -} - - NV_INLINE uint32_t TkTypeImpl::getIndex() const { return m_index; |