diff options
| author | Anton Novoselov <[email protected]> | 2017-08-01 12:53:38 +0300 |
|---|---|---|
| committer | Anton Novoselov <[email protected]> | 2017-08-01 12:53:38 +0300 |
| commit | 236f03c0b9a4982328ed1201978f7f69d192d9b2 (patch) | |
| tree | e486f2fa39dba203563895541e92c60ed3e25759 /sdk/extensions/serialization/source | |
| parent | Added screens to welcome page (diff) | |
| download | blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.tar.xz blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.zip | |
Blast 1.1 release (windows / linux)
see docs/release_notes.txt for details
Diffstat (limited to 'sdk/extensions/serialization/source')
62 files changed, 4074 insertions, 2118 deletions
diff --git a/sdk/extensions/serialization/source/BlastSerialization.capn b/sdk/extensions/serialization/source/BlastSerialization.capn deleted file mode 100644 index 49b1dbb..0000000 --- a/sdk/extensions/serialization/source/BlastSerialization.capn +++ /dev/null @@ -1,162 +0,0 @@ -@0xaffe4498f275ee58; - -using Cxx = import "/capnp/c++.capnp"; - -$Cxx.namespace("Nv::Blast::Serialization"); - -struct Asset -{ - header @0 :NvBlastDataBlock; - - iD @1 :UUID; - - chunkCount @2 :UInt32; - - graph @3 :NvBlastSupportGraph; - - leafChunkCount @4 :UInt32; - - firstSubsupportChunkIndex @5 :UInt32; - - bondCount @6 :UInt32; - - chunks @7: List(NvBlastChunk); - - bonds @8: List(NvBlastBond); - - subtreeLeafChunkCounts @9: List(UInt32); - - chunkToGraphNodeMap @10: List(UInt32); -} - -struct TkAsset -{ - assetLL @0 :Asset; - - jointDescs @1 :List(TkAssetJointDesc); - -} - -struct ExtPxAsset -{ - asset @0 :TkAsset; - chunks @1 :List(ExtPxChunk); - subchunks @2 :List(ExtPxSubchunk); -} - -struct ExtPxChunk -{ - firstSubchunkIndex @0 :UInt32; - subchunkCount @1 :UInt32; - isStatic @2 :Bool; -} - -struct ExtPxSubchunk -{ - transform @0 :PxTransform; - geometry @1 :PxConvexMeshGeometry; -} - -struct PxConvexMeshGeometry -{ - scale @0 :PxMeshScale; - convexMesh @1 :Data; - meshFlags @2 :UInt8; - - enum Type - { - eSPHERE @0; - ePLANE @1; - eCAPSULE @2; - eBOX @3; - eCONVEXMESH @4; - eTRIANGLEMESH @5; - eHEIGHTFIELD @6; - } - - type @3 :Type; -} - -struct NvBlastDataBlock -{ - enum Type - { - assetDataBlock @0; - instanceDataBlock @1; - } - - dataType @0 :Type; - - formatVersion @1 :UInt32; - - size @2 :UInt32; -} - -struct NvBlastChunk -{ - centroid @0 :List(Float32); - - volume @1 :Float32; - - parentChunkIndex @2 :UInt32; - firstChildIndex @3 :UInt32; - childIndexStop @4 :UInt32; - userData @5 :UInt32; -} - -struct NvBlastBond -{ - normal @0 :List(Float32); - area @1 :Float32; - centroid @2 :List(Float32); - userData @3 :UInt32; -} - -struct TkAssetJointDesc -{ - nodeIndices @0 :List(UInt32); - attachPositions @1 :List(PxVec3); -} - -struct PxVec3 -{ - x @0 :Float32; - y @1 :Float32; - z @2 :Float32; -} - -struct PxQuat -{ - x @0 :Float32; - y @1 :Float32; - z @2 :Float32; - w @3 :Float32; -} - -struct PxMeshScale -{ - scale @0 :PxVec3; - rotation @1 :PxQuat; -} - -struct PxTransform -{ - q @0 :PxQuat; - p @1 :PxVec3; -} - -struct NvBlastSupportGraph -{ - nodeCount @0 : UInt32; - - chunkIndices @1 : List(UInt32); - adjacencyPartition @2 : List(UInt32); - adjacentNodeIndices @3 : List(UInt32); - adjacentBondIndices @4 : List(UInt32); -} - -struct UUID -{ - value @0 : Data; -} - diff --git a/sdk/extensions/serialization/source/DTO/AssetDTO.cpp b/sdk/extensions/serialization/source/DTO/AssetDTO.cpp index 8d035fc..b500fe6 100644 --- a/sdk/extensions/serialization/source/DTO/AssetDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/AssetDTO.cpp @@ -1,187 +1,202 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "AssetDTO.h" +#include "NvBlastGlobals.h" #include "NvBlastIDDTO.h" #include "NvBlastChunkDTO.h" #include "NvBlastBondDTO.h" #include "NvBlastAsset.h" -#include "NvBlastExtSerializationLLImpl.h" -#include "NvBlastExtGlobals.h" -#if !defined(BLAST_LL_ALLOC) -#include "NvBlastExtAllocator.h" -#endif namespace Nv { - namespace Blast +namespace Blast +{ + +bool AssetDTO::serialize(Nv::Blast::Serialization::Asset::Builder builder, const Nv::Blast::Asset * poco) +{ + NvBlastIDDTO::serialize(builder.initID(), &poco->m_ID); + + builder.setLeafChunkCount(poco->m_leafChunkCount); + + builder.setFirstSubsupportChunkIndex(poco->m_firstSubsupportChunkIndex); + + capnp::List<Nv::Blast::Serialization::NvBlastChunk>::Builder chunks = builder.initChunks(poco->m_chunkCount); + + builder.setChunkCount(poco->m_chunkCount); + + NVBLAST_ASSERT_WITH_MESSAGE(builder.getChunkCount() == poco->m_chunkCount, "WTF"); + + for (uint32_t i = 0; i < poco->m_chunkCount; i++) + { + NvBlastChunk& chunk = poco->getChunks()[i]; + + NvBlastChunkDTO::serialize(chunks[i], &chunk); + } + + NVBLAST_ASSERT_WITH_MESSAGE(builder.getChunkCount() == poco->m_chunkCount, "WTF"); + + capnp::List<Nv::Blast::Serialization::NvBlastBond>::Builder bonds = builder.initBonds(poco->m_bondCount); + + builder.setBondCount(poco->m_bondCount); + + for (uint32_t i = 0; i < poco->m_bondCount; i++) + { + NvBlastBond& bond = poco->getBonds()[i]; + + NvBlastBondDTO::serialize(bonds[i], &bond); + } + + kj::ArrayPtr<uint32_t> stlcArray(poco->getSubtreeLeafChunkCounts(), poco->m_chunkCount); + builder.initSubtreeLeafChunkCounts(poco->m_chunkCount); + builder.setSubtreeLeafChunkCounts(stlcArray); + + kj::ArrayPtr<uint32_t> ctgnArray(poco->getChunkToGraphNodeMap(), poco->m_chunkCount); + builder.setChunkToGraphNodeMap(ctgnArray); + + Nv::Blast::Serialization::NvBlastSupportGraph::Builder graphBulder = builder.initGraph(); + + graphBulder.setNodeCount(poco->m_graph.m_nodeCount); + + uint32_t* ciPtr = poco->m_graph.getChunkIndices(); + + kj::ArrayPtr<const uint32_t> ciArray(ciPtr, poco->m_graph.m_nodeCount); + graphBulder.setChunkIndices(ciArray); + + kj::ArrayPtr<const uint32_t> adjPart(poco->m_graph.getAdjacencyPartition(), poco->m_graph.m_nodeCount + 1); + graphBulder.setAdjacencyPartition(adjPart); + + NVBLAST_ASSERT(graphBulder.getAdjacencyPartition().size() == poco->m_graph.m_nodeCount + 1); + + kj::ArrayPtr<const uint32_t> nodeIndices(poco->m_graph.getAdjacentNodeIndices(), poco->m_bondCount * 2); + graphBulder.setAdjacentNodeIndices(nodeIndices); + + NVBLAST_ASSERT(graphBulder.getAdjacentNodeIndices().size() == poco->m_bondCount * 2); + + kj::ArrayPtr<const uint32_t> bondIndices(poco->m_graph.getAdjacentBondIndices(), poco->m_bondCount * 2); + graphBulder.setAdjacentBondIndices(bondIndices); + + return true; +} + + +Nv::Blast::Asset* AssetDTO::deserialize(Nv::Blast::Serialization::Asset::Reader reader) +{ + NvBlastID EmptyId; + memset(EmptyId.data, 0, sizeof(NvBlastID)); + + void* mem = NVBLAST_ALLOC(reader.totalSize().wordCount * sizeof(uint64_t)); + + auto asset = Nv::Blast::initializeAsset(mem, EmptyId, reader.getChunkCount(), reader.getGraph().getNodeCount(), reader.getLeafChunkCount(), reader.getFirstSubsupportChunkIndex(), reader.getBondCount(), logLL); + + bool result = deserializeInto(reader, asset); + + return result ? asset : nullptr; +} + + +bool AssetDTO::deserializeInto(Nv::Blast::Serialization::Asset::Reader reader, Nv::Blast::Asset * poco) +{ + NvBlastIDDTO::deserializeInto(reader.getID(), &poco->m_ID); + + NvBlastBond* bonds = poco->getBonds(); + + uint32_t bondCount = reader.getBondCount(); + auto readerBonds = reader.getBonds(); + for (uint32_t i = 0; i < bondCount; i++) + { + auto bondReader = readerBonds[i]; + + NvBlastBondDTO::deserializeInto(bondReader, &bonds[i]); + } + + NvBlastChunk* chunks = poco->getChunks(); + + uint32_t chunkCount = reader.getChunkCount(); + auto readerChunks = reader.getChunks(); + for (uint32_t i = 0; i < chunkCount; i++) + { + auto chunkReader = readerChunks[i]; + + NvBlastChunkDTO::deserializeInto(chunkReader, &chunks[i]); + } + + poco->m_graph.m_nodeCount = reader.getGraph().getNodeCount(); + + NVBLAST_ASSERT(reader.getSubtreeLeafChunkCounts().size() == poco->m_chunkCount); + auto readerSubtreeLeafChunkCounts = reader.getSubtreeLeafChunkCounts(); + for (uint32_t i = 0; i < poco->m_chunkCount; i++) { - bool AssetDTO::serialize(Nv::Blast::Serialization::Asset::Builder builder, const Nv::Blast::Asset * poco) - { - NvBlastIDDTO::serialize(builder.initID(), &poco->m_ID); - - builder.setLeafChunkCount(poco->m_leafChunkCount); - - builder.setFirstSubsupportChunkIndex(poco->m_firstSubsupportChunkIndex); - - capnp::List<Nv::Blast::Serialization::NvBlastChunk>::Builder chunks = builder.initChunks(poco->m_chunkCount); - - builder.setChunkCount(poco->m_chunkCount); - - NVBLAST_ASSERT_WITH_MESSAGE(builder.getChunkCount() == poco->m_chunkCount, "WTF"); - - for (uint32_t i = 0; i < poco->m_chunkCount; i++) - { - NvBlastChunk& chunk = poco->getChunks()[i]; - - NvBlastChunkDTO::serialize(chunks[i], &chunk); - } - - NVBLAST_ASSERT_WITH_MESSAGE(builder.getChunkCount() == poco->m_chunkCount, "WTF"); - - capnp::List<Nv::Blast::Serialization::NvBlastBond>::Builder bonds = builder.initBonds(poco->m_bondCount); - - builder.setBondCount(poco->m_bondCount); - - for (uint32_t i = 0; i < poco->m_bondCount; i++) - { - NvBlastBond& bond = poco->getBonds()[i]; - - NvBlastBondDTO::serialize(bonds[i], &bond); - } - - kj::ArrayPtr<uint32_t> stlcArray(poco->getSubtreeLeafChunkCounts(), poco->m_chunkCount); - builder.initSubtreeLeafChunkCounts(poco->m_chunkCount); - builder.setSubtreeLeafChunkCounts(stlcArray); - - kj::ArrayPtr<uint32_t> ctgnArray(poco->getChunkToGraphNodeMap(), poco->m_chunkCount); - builder.setChunkToGraphNodeMap(ctgnArray); - - Nv::Blast::Serialization::NvBlastSupportGraph::Builder graphBulder = builder.initGraph(); - - graphBulder.setNodeCount(poco->m_graph.m_nodeCount); - - uint32_t* ciPtr = poco->m_graph.getChunkIndices(); - - kj::ArrayPtr<const uint32_t> ciArray(ciPtr, poco->m_graph.m_nodeCount); - graphBulder.setChunkIndices(ciArray); - - kj::ArrayPtr<const uint32_t> adjPart(poco->m_graph.getAdjacencyPartition(), poco->m_graph.m_nodeCount + 1); - graphBulder.setAdjacencyPartition(adjPart); - - NVBLAST_ASSERT(graphBulder.getAdjacencyPartition().size() == poco->m_graph.m_nodeCount + 1); - - kj::ArrayPtr<const uint32_t> nodeIndices(poco->m_graph.getAdjacentNodeIndices(), poco->m_bondCount * 2); - graphBulder.setAdjacentNodeIndices(nodeIndices); - - NVBLAST_ASSERT(graphBulder.getAdjacentNodeIndices().size() == poco->m_bondCount * 2); - - kj::ArrayPtr<const uint32_t> bondIndices(poco->m_graph.getAdjacentBondIndices(), poco->m_bondCount * 2); - graphBulder.setAdjacentBondIndices(bondIndices); - - return true; - } - - Nv::Blast::Asset* AssetDTO::deserialize(Nv::Blast::Serialization::Asset::Reader reader) - { - NvBlastID EmptyId = {}; - - NvBlastExtAlloc allocFn = gAlloc; - NvBlastLog logFn = gLog; - -#if !defined(BLAST_LL_ALLOC) - allocFn = ExtAllocator::alignedAlloc16; - logFn = NvBlastTkFrameworkGet()->getLogFn(); -#endif - - void* mem = allocFn(reader.totalSize().wordCount * sizeof(uint64_t)); - - auto asset = Nv::Blast::initializeAsset(mem, EmptyId, reader.getChunkCount(), reader.getGraph().getNodeCount(), reader.getLeafChunkCount(), reader.getFirstSubsupportChunkIndex(), reader.getBondCount(), - logFn); - - bool result = deserializeInto(reader, asset); - - return result ? asset : nullptr; - } - - bool AssetDTO::deserializeInto(Nv::Blast::Serialization::Asset::Reader reader, Nv::Blast::Asset * poco) - { - NvBlastIDDTO::deserializeInto(reader.getID(), &poco->m_ID); - - NvBlastBond* bonds = poco->getBonds(); - - uint32_t bondCount = reader.getBondCount(); - for (uint32_t i = 0; i < bondCount; i++) - { - auto bondReader = reader.getBonds()[i]; - - NvBlastBondDTO::deserializeInto(bondReader, &bonds[i]); - } - - NvBlastChunk* chunks = poco->getChunks(); - - uint32_t chunkCount = reader.getChunkCount(); - for (uint32_t i = 0; i < chunkCount; i++) - { - auto chunkReader = reader.getChunks()[i]; - - NvBlastChunkDTO::deserializeInto(chunkReader, &chunks[i]); - } - - poco->m_graph.m_nodeCount = reader.getGraph().getNodeCount(); - - NVBLAST_ASSERT(reader.getSubtreeLeafChunkCounts().size() == poco->m_chunkCount); - for (uint32_t i = 0; i < poco->m_chunkCount; i++) - { - poco->getSubtreeLeafChunkCounts()[i] = reader.getSubtreeLeafChunkCounts()[i]; - } - - for (uint32_t i = 0; i < chunkCount; i++) - { - poco->getChunkToGraphNodeMap()[i] = reader.getChunkToGraphNodeMap()[i]; - } - - uint32_t* ciPtr = poco->m_graph.getChunkIndices(); - - NVBLAST_ASSERT(reader.getGraph().getChunkIndices().size() == poco->m_graph.m_nodeCount); - for (uint32_t i = 0; i < poco->m_graph.m_nodeCount; i++) - { - ciPtr[i] = reader.getGraph().getChunkIndices()[i]; - } - - uint32_t* adjPartition = poco->m_graph.getAdjacencyPartition(); - uint32_t idx = 0; - - for (uint32_t adjPartIndex : reader.getGraph().getAdjacencyPartition()) - { - adjPartition[idx++] = adjPartIndex; - } - - uint32_t* adjNodes = poco->m_graph.getAdjacentNodeIndices(); - idx = 0; - - for (uint32_t adjNodeIndex : reader.getGraph().getAdjacentNodeIndices()) - { - adjNodes[idx++] = adjNodeIndex; - } - - uint32_t* adjBonds = poco->m_graph.getAdjacentBondIndices(); - idx = 0; - - for (uint32_t adjBondIndex : reader.getGraph().getAdjacentBondIndices()) - { - adjBonds[idx++] = adjBondIndex; - } - - return true; - } + poco->getSubtreeLeafChunkCounts()[i] = readerSubtreeLeafChunkCounts[i]; } + + auto readerChunkToGraphNodeMap = reader.getChunkToGraphNodeMap(); + for (uint32_t i = 0; i < chunkCount; i++) + { + poco->getChunkToGraphNodeMap()[i] = readerChunkToGraphNodeMap[i]; + } + + uint32_t* ciPtr = poco->m_graph.getChunkIndices(); + + NVBLAST_ASSERT(reader.getGraph().getChunkIndices().size() == poco->m_graph.m_nodeCount); + auto readerGraphChunkIndices = reader.getGraph().getChunkIndices(); + for (uint32_t i = 0; i < poco->m_graph.m_nodeCount; i++) + { + ciPtr[i] = readerGraphChunkIndices[i]; + } + + uint32_t* adjPartition = poco->m_graph.getAdjacencyPartition(); + const uint32_t graphAdjacencyPartitionSize = reader.getGraph().getAdjacencyPartition().size(); + auto readerGraphAdjacencyPartition = reader.getGraph().getAdjacencyPartition(); + for (uint32_t i = 0; i < graphAdjacencyPartitionSize; ++i) + { + adjPartition[i] = readerGraphAdjacencyPartition[i]; + } + + uint32_t* adjNodes = poco->m_graph.getAdjacentNodeIndices(); + const uint32_t graphAdjacentNodeIndicesSize = reader.getGraph().getAdjacentNodeIndices().size(); + auto readerGraphAdjacentNodeIndices = reader.getGraph().getAdjacentNodeIndices(); + for (uint32_t i = 0; i < graphAdjacentNodeIndicesSize; ++i) + { + adjNodes[i] = readerGraphAdjacentNodeIndices[i]; + } + + uint32_t* adjBonds = poco->m_graph.getAdjacentBondIndices(); + const uint32_t graphAdjacentBondIndicesSize = reader.getGraph().getAdjacentBondIndices().size(); + auto readerGraphAdjacentBondIndices = reader.getGraph().getAdjacentBondIndices(); + for (uint32_t i = 0; i < graphAdjacentBondIndicesSize; ++i) + { + adjBonds[i] = readerGraphAdjacentBondIndices[i]; + } + + return true; } + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/AssetDTO.h b/sdk/extensions/serialization/source/DTO/AssetDTO.h index c090b5f..492e847 100644 --- a/sdk/extensions/serialization/source/DTO/AssetDTO.h +++ b/sdk/extensions/serialization/source/DTO/AssetDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastAsset.h" -#include "generated/NvBlastExtSerializationLL.capn.h" +#include "generated/NvBlastExtLlSerialization.capn.h" -DTO_CLASS_LL(Asset, Nv::Blast::Asset, Nv::Blast::Serialization::Asset) +DTO_CLASS(Asset, Nv::Blast::Asset, Nv::Blast::Serialization::Asset) diff --git a/sdk/extensions/serialization/source/DTO/DTOMacros.h b/sdk/extensions/serialization/source/DTO/DTOMacros.h index a234aec..b3b71ef 100644 --- a/sdk/extensions/serialization/source/DTO/DTOMacros.h +++ b/sdk/extensions/serialization/source/DTO/DTOMacros.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once @@ -16,29 +34,10 @@ namespace Blast { \ class _NAME ## DTO \ { \ public: \ - static class physx::PxCooking* Cooking; \ - static class physx::PxPhysics* Physics; \ - \ - static bool serialize(_SERIALIZER::Builder builder, const _POCO * poco); \ - static _POCO* deserialize(_SERIALIZER::Reader reader); \ - static bool deserializeInto(_SERIALIZER::Reader reader, _POCO * poco); \ -}; \ -} \ -} \ - \ - -#define DTO_CLASS_LL(_NAME, _POCO, _SERIALIZER) \ -namespace Nv { \ -namespace Blast { \ -class _NAME ## DTO \ -{ \ -public: \ \ static bool serialize(_SERIALIZER::Builder builder, const _POCO * poco); \ static _POCO* deserialize(_SERIALIZER::Reader reader); \ static bool deserializeInto(_SERIALIZER::Reader reader, _POCO * poco); \ }; \ } \ -} \ - \ - +} diff --git a/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.cpp b/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.cpp index cf4cadc..865f141 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "ExtPxAssetDTO.h" #include "TkAssetDTO.h" @@ -14,65 +32,127 @@ #include "ExtPxSubchunkDTO.h" #include "physics/NvBlastExtPxAssetImpl.h" #include "NvBlastAssert.h" +#include "NvBlast.h" + namespace Nv { - namespace Blast +namespace Blast +{ + +bool ExtPxAssetDTO::serialize(Nv::Blast::Serialization::ExtPxAsset::Builder builder, const Nv::Blast::ExtPxAsset * poco) +{ + TkAssetDTO::serialize(builder.getAsset(), &poco->getTkAsset()); + + auto chunks = builder.initChunks(poco->getChunkCount()); + + for (uint32_t i = 0; i <poco->getChunkCount(); i++) { - bool ExtPxAssetDTO::serialize(Nv::Blast::Serialization::ExtPxAsset::Builder builder, const Nv::Blast::ExtPxAsset * poco) - { - TkAssetDTO::serialize(builder.getAsset(), &poco->getTkAsset()); - - auto chunks = builder.initChunks(poco->getChunkCount()); - - for (uint32_t i = 0; i <poco->getChunkCount(); i++) - { - ExtPxChunkDTO::serialize(chunks[i], &poco->getChunks()[i]); - } - - auto subchunks = builder.initSubchunks(poco->getSubchunkCount()); - - for (uint32_t i = 0; i < poco->getSubchunkCount(); i++) - { - ExtPxSubchunkDTO::serialize(subchunks[i], &poco->getSubchunks()[i]); - } - - return true; - } - - Nv::Blast::ExtPxAsset* ExtPxAssetDTO::deserialize(Nv::Blast::Serialization::ExtPxAsset::Reader reader) + ExtPxChunkDTO::serialize(chunks[i], &poco->getChunks()[i]); + } + + auto subchunks = builder.initSubchunks(poco->getSubchunkCount()); + + for (uint32_t i = 0; i < poco->getSubchunkCount(); i++) + { + ExtPxSubchunkDTO::serialize(subchunks[i], &poco->getSubchunks()[i]); + } + + const NvBlastActorDesc& actorDesc = poco->getDefaultActorDesc(); + + builder.setUniformInitialBondHealth(actorDesc.uniformInitialBondHealth); + + if (actorDesc.initialBondHealths != nullptr) + { + const uint32_t bondCount = poco->getTkAsset().getBondCount(); + kj::ArrayPtr<const float> bondHealthArray(actorDesc.initialBondHealths, bondCount); + builder.initBondHealths(bondCount); + builder.setBondHealths(bondHealthArray); + } + + builder.setUniformInitialLowerSupportChunkHealth(actorDesc.uniformInitialLowerSupportChunkHealth); + + if (actorDesc.initialSupportChunkHealths != nullptr) + { + const uint32_t supportChunkCount = NvBlastAssetGetSupportChunkCount(poco->getTkAsset().getAssetLL(), logLL); + kj::ArrayPtr<const float> supportChunkHealthArray(actorDesc.initialSupportChunkHealths, supportChunkCount); + builder.initSupportChunkHealths(supportChunkCount); + builder.setSupportChunkHealths(supportChunkHealthArray); + } + + return true; +} + + +Nv::Blast::ExtPxAsset* ExtPxAssetDTO::deserialize(Nv::Blast::Serialization::ExtPxAsset::Reader reader) +{ + auto tkAsset = TkAssetDTO::deserialize(reader.getAsset()); + + Nv::Blast::ExtPxAssetImpl* asset = reinterpret_cast<Nv::Blast::ExtPxAssetImpl*>(Nv::Blast::ExtPxAsset::create(tkAsset)); + + NVBLAST_ASSERT(asset != nullptr); + + auto& chunks = asset->getChunksArray(); + const uint32_t chunkCount = reader.getChunks().size(); + chunks.resize(chunkCount); + auto readerChunks = reader.getChunks(); + for (uint32_t i = 0; i < chunkCount; i++) + { + ExtPxChunkDTO::deserializeInto(readerChunks[i], &chunks[i]); + } + + auto& subchunks = asset->getSubchunksArray(); + const uint32_t subChunkCount = reader.getSubchunks().size(); + subchunks.resize(subChunkCount); + auto readerSubchunks = reader.getSubchunks(); + for (uint32_t i = 0; i < subChunkCount; i++) + { + ExtPxSubchunkDTO::deserializeInto(readerSubchunks[i], &subchunks[i]); + } + + NvBlastActorDesc& actorDesc = asset->getDefaultActorDesc(); + + actorDesc.uniformInitialBondHealth = reader.getUniformInitialBondHealth(); + + actorDesc.initialBondHealths = nullptr; + if (reader.hasBondHealths()) + { + const uint32_t bondCount = asset->getTkAsset().getBondCount(); + Nv::Blast::Array<float>::type& bondHealths = asset->getBondHealthsArray(); + bondHealths.resize(bondCount); + auto readerBondHealths = reader.getBondHealths(); + for (uint32_t i = 0; i < bondCount; ++i) { - auto tkAsset = TkAssetDTO::deserialize(reader.getAsset()); - - Nv::Blast::ExtPxAssetImpl* asset = reinterpret_cast<Nv::Blast::ExtPxAssetImpl*>(Nv::Blast::ExtPxAsset::create(tkAsset)); - - NVBLAST_ASSERT(asset != nullptr); - - auto chunks = asset->getChunksArray(); - - chunks.resize(reader.getChunks().size()); - for (uint32_t i = 0; i < reader.getChunks().size(); i++) - { - ExtPxChunkDTO::deserializeInto(reader.getChunks()[i], &chunks[i]); - } - - auto subchunks = asset->getSubchunksArray(); - - subchunks.resize(reader.getSubchunks().size()); - for (uint32_t i = 0; i < reader.getSubchunks().size(); i++) - { - ExtPxSubchunkDTO::deserializeInto(reader.getSubchunks()[i], &subchunks[i]); - } - - return asset; + bondHealths[i] = readerBondHealths[i]; } - - bool ExtPxAssetDTO::deserializeInto(Nv::Blast::Serialization::ExtPxAsset::Reader reader, Nv::Blast::ExtPxAsset * poco) + } + + actorDesc.uniformInitialLowerSupportChunkHealth = reader.getUniformInitialLowerSupportChunkHealth(); + + actorDesc.initialSupportChunkHealths = nullptr; + if (reader.hasSupportChunkHealths()) + { + const uint32_t supportChunkCount = NvBlastAssetGetSupportChunkCount(asset->getTkAsset().getAssetLL(), logLL); + Nv::Blast::Array<float>::type& supportChunkHealths = asset->getSupportChunkHealthsArray(); + supportChunkHealths.resize(supportChunkCount); + auto readerSupportChunkHealths = reader.getSupportChunkHealths(); + for (uint32_t i = 0; i < supportChunkCount; ++i) { - reader = reader; - poco = nullptr; - //NOTE: Because of the way this is structured, can't do this. - return false; + supportChunkHealths[i] = readerSupportChunkHealths[i]; } } + + return asset; +} + + +bool ExtPxAssetDTO::deserializeInto(Nv::Blast::Serialization::ExtPxAsset::Reader reader, Nv::Blast::ExtPxAsset * poco) +{ + reader = reader; + poco = nullptr; + //NOTE: Because of the way this is structured, can't do this. + return false; } + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.h b/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.h index a35d38a..9729ec9 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.h +++ b/sdk/extensions/serialization/source/DTO/ExtPxAssetDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "NvBlastBondDTO.h" #include "NvBlastExtPxAsset.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" DTO_CLASS(ExtPxAsset, Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset) diff --git a/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.cpp b/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.cpp index e096bc1..74333b6 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.cpp @@ -1,43 +1,65 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "ExtPxChunkDTO.h" namespace Nv { - namespace Blast - { - bool ExtPxChunkDTO::serialize(Nv::Blast::Serialization::ExtPxChunk::Builder builder, const Nv::Blast::ExtPxChunk * poco) - { - builder.setFirstSubchunkIndex(poco->firstSubchunkIndex); - builder.setSubchunkCount(poco->subchunkCount); - builder.setIsStatic(poco->isStatic); - - return true; - } - - Nv::Blast::ExtPxChunk* ExtPxChunkDTO::deserialize(Nv::Blast::Serialization::ExtPxChunk::Reader reader) - { - reader = reader; - //TODO: Allocate with ExtContext and return - - return nullptr; - } - - bool ExtPxChunkDTO::deserializeInto(Nv::Blast::Serialization::ExtPxChunk::Reader reader, Nv::Blast::ExtPxChunk * poco) - { - poco->firstSubchunkIndex = reader.getFirstSubchunkIndex(); - poco->subchunkCount = reader.getSubchunkCount(); - poco->isStatic = reader.getIsStatic(); - - return true; - } - } -}
\ No newline at end of file +namespace Blast +{ + +bool ExtPxChunkDTO::serialize(Nv::Blast::Serialization::ExtPxChunk::Builder builder, const Nv::Blast::ExtPxChunk * poco) +{ + builder.setFirstSubchunkIndex(poco->firstSubchunkIndex); + builder.setSubchunkCount(poco->subchunkCount); + builder.setIsStatic(poco->isStatic); + + return true; +} + + +Nv::Blast::ExtPxChunk* ExtPxChunkDTO::deserialize(Nv::Blast::Serialization::ExtPxChunk::Reader reader) +{ + reader = reader; + //TODO: Allocate with ExtContext and return + + return nullptr; +} + + +bool ExtPxChunkDTO::deserializeInto(Nv::Blast::Serialization::ExtPxChunk::Reader reader, Nv::Blast::ExtPxChunk * poco) +{ + poco->firstSubchunkIndex = reader.getFirstSubchunkIndex(); + poco->subchunkCount = reader.getSubchunkCount(); + poco->isStatic = reader.getIsStatic(); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.h b/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.h index 1ff36df..e9935c3 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.h +++ b/sdk/extensions/serialization/source/DTO/ExtPxChunkDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastExtPxAsset.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" DTO_CLASS(ExtPxChunk, Nv::Blast::ExtPxChunk, Nv::Blast::Serialization::ExtPxChunk) diff --git a/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.cpp b/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.cpp index cc2be96..c3e290b 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.cpp @@ -1,43 +1,66 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "ExtPxSubchunkDTO.h" #include "PxTransformDTO.h" #include "PxConvexMeshGeometryDTO.h" + namespace Nv { - namespace Blast - { - bool ExtPxSubchunkDTO::serialize(Nv::Blast::Serialization::ExtPxSubchunk::Builder builder, const Nv::Blast::ExtPxSubchunk * poco) - { - PxTransformDTO::serialize(builder.getTransform(), &poco->transform); - PxConvexMeshGeometryDTO::serialize(builder.getGeometry(), &poco->geometry); - - return true; - } - - Nv::Blast::ExtPxSubchunk* ExtPxSubchunkDTO::deserialize(Nv::Blast::Serialization::ExtPxSubchunk::Reader reader) - { - reader = reader; - //TODO: Allocate with ExtContext and return - - return nullptr; - } - - bool ExtPxSubchunkDTO::deserializeInto(Nv::Blast::Serialization::ExtPxSubchunk::Reader reader, Nv::Blast::ExtPxSubchunk * poco) - { - PxTransformDTO::deserializeInto(reader.getTransform(), &poco->transform); - - return true; - } - - } +namespace Blast +{ + +bool ExtPxSubchunkDTO::serialize(Nv::Blast::Serialization::ExtPxSubchunk::Builder builder, const Nv::Blast::ExtPxSubchunk * poco) +{ + PxTransformDTO::serialize(builder.getTransform(), &poco->transform); + PxConvexMeshGeometryDTO::serialize(builder.getGeometry(), &poco->geometry); + + return true; } + + +Nv::Blast::ExtPxSubchunk* ExtPxSubchunkDTO::deserialize(Nv::Blast::Serialization::ExtPxSubchunk::Reader reader) +{ + reader = reader; + //TODO: Allocate with ExtContext and return + + return nullptr; +} + + +bool ExtPxSubchunkDTO::deserializeInto(Nv::Blast::Serialization::ExtPxSubchunk::Reader reader, Nv::Blast::ExtPxSubchunk * poco) +{ + PxTransformDTO::deserializeInto(reader.getTransform(), &poco->transform); + PxConvexMeshGeometryDTO::deserializeInto(reader.getGeometry(), &poco->geometry); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.h b/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.h index 91f78e0..72b6c24 100644 --- a/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.h +++ b/sdk/extensions/serialization/source/DTO/ExtPxSubchunkDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "NvBlastExtPxAsset.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" #include "DTOMacros.h" DTO_CLASS(ExtPxSubchunk, Nv::Blast::ExtPxSubchunk, Nv::Blast::Serialization::ExtPxSubchunk) diff --git a/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.cpp b/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.cpp index 27cbb11..7865eb3 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.cpp @@ -1,63 +1,86 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastBondDTO.h" #include "NvBlastAssert.h" namespace Nv { - namespace Blast - { - - bool NvBlastBondDTO::serialize(Nv::Blast::Serialization::NvBlastBond::Builder builder, const NvBlastBond * poco) - { - NVBLAST_ASSERT(poco != nullptr); - - kj::ArrayPtr<const float> normArray(poco->normal, 3); - - builder.setNormal(normArray); - - builder.setArea(poco->area); - - kj::ArrayPtr<const float> centArray(poco->centroid, 3); - - builder.setCentroid(centArray); - - builder.setUserData(poco->userData); - - return true; - } - - NvBlastBond* NvBlastBondDTO::deserialize(Nv::Blast::Serialization::NvBlastBond::Reader reader) - { - //FIXME - reader = reader; - //TODO: Allocate with ExtContext and return - return nullptr; - } - - bool NvBlastBondDTO::deserializeInto(Nv::Blast::Serialization::NvBlastBond::Reader reader, NvBlastBond * poco) - { - poco->area = reader.getArea(); - - poco->centroid[0] = reader.getCentroid()[0]; - poco->centroid[1] = reader.getCentroid()[1]; - poco->centroid[2] = reader.getCentroid()[2]; - - poco->normal[0] = reader.getNormal()[0]; - poco->normal[1] = reader.getNormal()[1]; - poco->normal[2] = reader.getNormal()[2]; - - poco->userData = reader.getUserData(); - - return true; - } - } +namespace Blast +{ + +bool NvBlastBondDTO::serialize(Nv::Blast::Serialization::NvBlastBond::Builder builder, const NvBlastBond * poco) +{ + NVBLAST_ASSERT(poco != nullptr); + + kj::ArrayPtr<const float> normArray(poco->normal, 3); + + builder.setNormal(normArray); + + builder.setArea(poco->area); + + kj::ArrayPtr<const float> centArray(poco->centroid, 3); + + builder.setCentroid(centArray); + + builder.setUserData(poco->userData); + + return true; +} + + +NvBlastBond* NvBlastBondDTO::deserialize(Nv::Blast::Serialization::NvBlastBond::Reader reader) +{ + //FIXME + reader = reader; + //TODO: Allocate with ExtContext and return + return nullptr; +} + + +bool NvBlastBondDTO::deserializeInto(Nv::Blast::Serialization::NvBlastBond::Reader reader, NvBlastBond * poco) +{ + poco->area = reader.getArea(); + + auto readerCentroid = reader.getCentroid(); + poco->centroid[0] = readerCentroid[0]; + poco->centroid[1] = readerCentroid[1]; + poco->centroid[2] = readerCentroid[2]; + + auto readerNormal = reader.getNormal(); + poco->normal[0] = readerNormal[0]; + poco->normal[1] = readerNormal[1]; + poco->normal[2] = readerNormal[2]; + + poco->userData = reader.getUserData(); + + return true; } + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.h b/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.h index 8b67bd7..3a8e0d1 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.h +++ b/sdk/extensions/serialization/source/DTO/NvBlastBondDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastTypes.h" -#include "generated/NvBlastExtSerializationLL.capn.h" +#include "generated/NvBlastExtLlSerialization.capn.h" -DTO_CLASS_LL(NvBlastBond, NvBlastBond, Nv::Blast::Serialization::NvBlastBond) +DTO_CLASS(NvBlastBond, NvBlastBond, Nv::Blast::Serialization::NvBlastBond) diff --git a/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.cpp b/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.cpp index 38814ed..71924f3 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.cpp @@ -1,60 +1,83 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastChunkDTO.h" #include "NvBlastAssert.h" namespace Nv { - namespace Blast - { - bool NvBlastChunkDTO::serialize(Nv::Blast::Serialization::NvBlastChunk::Builder builder, const NvBlastChunk* poco) - { - NVBLAST_ASSERT(poco != nullptr); - - kj::ArrayPtr<const float> centArray(poco->centroid, 3); - builder.setCentroid(centArray); - - builder.setVolume(poco->volume); - - builder.setParentChunkIndex(poco->parentChunkIndex); - builder.setFirstChildIndex(poco->firstChildIndex); - builder.setChildIndexStop(poco->childIndexStop); - builder.setUserData(poco->userData); - - return true; - } - - NvBlastChunk* NvBlastChunkDTO::deserialize(Nv::Blast::Serialization::NvBlastChunk::Reader reader) - { - //FIXME - reader = reader; - - return nullptr; - } - - bool NvBlastChunkDTO::deserializeInto(Nv::Blast::Serialization::NvBlastChunk::Reader reader, NvBlastChunk* target) - { - NVBLAST_ASSERT(target != nullptr); - - target->centroid[0] = reader.getCentroid()[0]; - target->centroid[1] = reader.getCentroid()[1]; - target->centroid[2] = reader.getCentroid()[2]; - - target->childIndexStop = reader.getChildIndexStop(); - target->firstChildIndex = reader.getFirstChildIndex(); - target->parentChunkIndex = reader.getParentChunkIndex(); - target->userData = reader.getUserData(); - target->volume = reader.getVolume(); - - return true; - } - } +namespace Blast +{ + +bool NvBlastChunkDTO::serialize(Nv::Blast::Serialization::NvBlastChunk::Builder builder, const NvBlastChunk* poco) +{ + NVBLAST_ASSERT(poco != nullptr); + + kj::ArrayPtr<const float> centArray(poco->centroid, 3); + builder.setCentroid(centArray); + + builder.setVolume(poco->volume); + + builder.setParentChunkIndex(poco->parentChunkIndex); + builder.setFirstChildIndex(poco->firstChildIndex); + builder.setChildIndexStop(poco->childIndexStop); + builder.setUserData(poco->userData); + + return true; } + + +NvBlastChunk* NvBlastChunkDTO::deserialize(Nv::Blast::Serialization::NvBlastChunk::Reader reader) +{ + //FIXME + reader = reader; + + return nullptr; +} + + +bool NvBlastChunkDTO::deserializeInto(Nv::Blast::Serialization::NvBlastChunk::Reader reader, NvBlastChunk* target) +{ + NVBLAST_ASSERT(target != nullptr); + + auto readerCentroid = reader.getCentroid(); + target->centroid[0] = readerCentroid[0]; + target->centroid[1] = readerCentroid[1]; + target->centroid[2] = readerCentroid[2]; + + target->childIndexStop = reader.getChildIndexStop(); + target->firstChildIndex = reader.getFirstChildIndex(); + target->parentChunkIndex = reader.getParentChunkIndex(); + target->userData = reader.getUserData(); + target->volume = reader.getVolume(); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.h b/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.h index 5fec498..e4c3f1f 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.h +++ b/sdk/extensions/serialization/source/DTO/NvBlastChunkDTO.h @@ -1,18 +1,36 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastTypes.h" -#include "generated/NvBlastExtSerializationLL.capn.h" +#include "generated/NvBlastExtLlSerialization.capn.h" -DTO_CLASS_LL(NvBlastChunk, NvBlastChunk, Nv::Blast::Serialization::NvBlastChunk) +DTO_CLASS(NvBlastChunk, NvBlastChunk, Nv::Blast::Serialization::NvBlastChunk) diff --git a/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.cpp b/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.cpp index e540cd8..0be5863 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.cpp @@ -1,48 +1,70 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastIDDTO.h" #include "NvBlastTypes.h" #include "NvBlastAssert.h" -#include "generated/NvBlastExtSerializationLL.capn.h" +#include "generated/NvBlastExtLlSerialization.capn.h" namespace Nv { - namespace Blast - { - - bool NvBlastIDDTO::serialize(Nv::Blast::Serialization::UUID::Builder builder, const NvBlastID * poco) - { - capnp::Data::Reader idArrayReader((unsigned char *)poco->data, 16); - builder.setValue(idArrayReader); - - return true; - } - - NvBlastID* NvBlastIDDTO::deserialize(Nv::Blast::Serialization::UUID::Reader reader) - { - //FIXME - reader = reader; - //TODO: Allocate with ExtContext and return - - return nullptr; - } - - bool NvBlastIDDTO::deserializeInto(Nv::Blast::Serialization::UUID::Reader reader, NvBlastID * poco) - { - NVBLAST_ASSERT_WITH_MESSAGE(reader.getValue().size() == 16, "BlastID must be 16 bytes"); - - memcpy(poco, reader.getValue().begin(), 16); - - return true; - } - } -}
\ No newline at end of file +namespace Blast +{ + + +bool NvBlastIDDTO::serialize(Nv::Blast::Serialization::UUID::Builder builder, const NvBlastID * poco) +{ + capnp::Data::Reader idArrayReader((unsigned char *)poco->data, 16); + builder.setValue(idArrayReader); + + return true; +} + + +NvBlastID* NvBlastIDDTO::deserialize(Nv::Blast::Serialization::UUID::Reader reader) +{ + //FIXME + reader = reader; + //TODO: Allocate with ExtContext and return + + return nullptr; +} + + +bool NvBlastIDDTO::deserializeInto(Nv::Blast::Serialization::UUID::Reader reader, NvBlastID * poco) +{ + NVBLAST_ASSERT_WITH_MESSAGE(reader.getValue().size() == 16, "BlastID must be 16 bytes"); + + memcpy(poco, reader.getValue().begin(), 16); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.h b/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.h index afe6cf0..ac4b1c0 100644 --- a/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.h +++ b/sdk/extensions/serialization/source/DTO/NvBlastIDDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "NvBlastTypes.h" -#include "generated/NvBlastExtSerializationLL.capn.h" +#include "generated/NvBlastExtLlSerialization.capn.h" #include "DTOMacros.h" -DTO_CLASS_LL(NvBlastID, NvBlastID, ::Nv::Blast::Serialization::UUID) +DTO_CLASS(NvBlastID, NvBlastID, ::Nv::Blast::Serialization::UUID) diff --git a/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.cpp b/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.cpp index 1c46f9e..099e458 100644 --- a/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "PxConvexMeshGeometryDTO.h" #include "PxMeshScaleDTO.h" @@ -17,111 +35,108 @@ #include "NvBlastExtSerialization.h" #include "PxVec3.h" #include <algorithm> +#include <vector> #include "PxPhysics.h" +#include "NvBlastPxCallbacks.h" +#include "PxDefaultStreams.h" namespace Nv { - namespace Blast - { - physx::PxCooking* PxConvexMeshGeometryDTO::Cooking = nullptr; - physx::PxPhysics* PxConvexMeshGeometryDTO::Physics = nullptr; +namespace Blast +{ + +extern physx::PxPhysics* sExtPxSerializerPhysics; +extern physx::PxCooking* sExtPxSerializerCooking; + + +bool PxConvexMeshGeometryDTO::serialize(Nv::Blast::Serialization::PxConvexMeshGeometry::Builder builder, const physx::PxConvexMeshGeometry * poco) +{ + NVBLAST_ASSERT(sExtPxSerializerCooking != nullptr); + + PxMeshScaleDTO::serialize(builder.getScale(), &poco->scale); + + //TODO: Use cooking.cookConvexMesh to cook the mesh to a stream - then get that backing buffer and put it into the Data field - bool PxConvexMeshGeometryDTO::serialize(Nv::Blast::Serialization::PxConvexMeshGeometry::Builder builder, const physx::PxConvexMeshGeometry * poco) + physx::PxConvexMeshDesc desc; + desc.points.data = poco->convexMesh->getVertices(); + desc.points.count = poco->convexMesh->getNbVertices(); + desc.points.stride = sizeof(physx::PxVec3); + + std::vector<uint32_t> indicesScratch; + std::vector<physx::PxHullPolygon> hullPolygonsScratch; + + hullPolygonsScratch.resize(poco->convexMesh->getNbPolygons()); + + uint32_t indexCount = 0; + for (uint32_t i = 0; i < hullPolygonsScratch.size(); i++) + { + physx::PxHullPolygon polygon; + poco->convexMesh->getPolygonData(i, polygon); + if (polygon.mNbVerts) { - PxMeshScaleDTO::serialize(builder.getScale(), &poco->scale); - - //TODO: Use cooking.cookConvexMesh to cook the mesh to a stream - then get that backing buffer and put it into the Data field - - physx::PxConvexMeshDesc desc; - desc.points.data = poco->convexMesh->getVertices(); - desc.points.count = poco->convexMesh->getNbVertices(); - desc.points.stride = sizeof(physx::PxVec3); - - std::vector<uint32_t> indicesScratch; - std::vector<physx::PxHullPolygon> hullPolygonsScratch; - - hullPolygonsScratch.resize(poco->convexMesh->getNbPolygons()); - - uint32_t indexCount = 0; - for (uint32_t i = 0; i < hullPolygonsScratch.size(); i++) - { - physx::PxHullPolygon polygon; - poco->convexMesh->getPolygonData(i, polygon); - if (polygon.mNbVerts) - { - indexCount = std::max<uint32_t>(indexCount, polygon.mIndexBase + polygon.mNbVerts); - } - } - indicesScratch.resize(indexCount); - - for (uint32_t i = 0; i < hullPolygonsScratch.size(); i++) - { - physx::PxHullPolygon polygon; - poco->convexMesh->getPolygonData(i, polygon); - for (uint32_t j = 0; j < polygon.mNbVerts; j++) - { - indicesScratch[polygon.mIndexBase + j] = poco->convexMesh->getIndexBuffer()[polygon.mIndexBase + j]; - } - - hullPolygonsScratch[i] = polygon; - } - - desc.indices.count = indexCount; - desc.indices.data = indicesScratch.data(); - desc.indices.stride = sizeof(uint32_t); - - desc.polygons.count = poco->convexMesh->getNbPolygons(); - desc.polygons.data = hullPolygonsScratch.data(); - desc.polygons.stride = sizeof(physx::PxHullPolygon); - - - std::vector<unsigned char> buffer; - buffer.resize(16 * 1024 * 1024); // No idea how much memory is needed! Allocate 16MB - kj::ArrayPtr<unsigned char> bufferArray(buffer.data(), buffer.size()); - - Nv::Blast::ExtKJPxOutputStream outputStream(bufferArray); - - bool cookResult = Cooking->cookConvexMesh(desc, outputStream); - - if (!cookResult) - { - return false; - } - - kj::ArrayPtr<unsigned char> cookedBuffer(outputStream.getBuffer().begin(), outputStream.getWrittenBytes()); - - builder.setConvexMesh(cookedBuffer); - - // builder.getConvexMesh(). - - return true; + indexCount = std::max<uint32_t>(indexCount, polygon.mIndexBase + polygon.mNbVerts); } - - physx::PxConvexMeshGeometry* PxConvexMeshGeometryDTO::deserialize(Nv::Blast::Serialization::PxConvexMeshGeometry::Reader reader) - { - NVBLAST_ASSERT(PxConvexMeshGeometryDTO::Cooking != nullptr); - - reader = reader; - - return nullptr; - } - - bool PxConvexMeshGeometryDTO::deserializeInto(Nv::Blast::Serialization::PxConvexMeshGeometry::Reader reader, physx::PxConvexMeshGeometry * poco) + } + indicesScratch.resize(indexCount); + + for (uint32_t i = 0; i < hullPolygonsScratch.size(); i++) + { + physx::PxHullPolygon polygon; + poco->convexMesh->getPolygonData(i, polygon); + for (uint32_t j = 0; j < polygon.mNbVerts; j++) { - NVBLAST_ASSERT(PxConvexMeshGeometryDTO::Cooking != nullptr); - - PxMeshScaleDTO::deserializeInto(reader.getScale(), &poco->scale); - - Nv::Blast::ExtKJPxInputStream inputStream(reader.getConvexMesh()); - - //NOTE: Naive approach, no shared convex hulls - poco->convexMesh = Physics->createConvexMesh(inputStream); - - return false; + indicesScratch[polygon.mIndexBase + j] = poco->convexMesh->getIndexBuffer()[polygon.mIndexBase + j]; } + + hullPolygonsScratch[i] = polygon; + } + + desc.indices.count = indexCount; + desc.indices.data = indicesScratch.data(); + desc.indices.stride = sizeof(uint32_t); + + desc.polygons.count = poco->convexMesh->getNbPolygons(); + desc.polygons.data = hullPolygonsScratch.data(); + desc.polygons.stride = sizeof(physx::PxHullPolygon); - - + physx::PxDefaultMemoryOutputStream outStream(NvBlastGetPxAllocatorCallback()); + if (!sExtPxSerializerCooking->cookConvexMesh(desc, outStream)) + { + return false; } + + kj::ArrayPtr<unsigned char> cookedBuffer(outStream.getData(), outStream.getSize()); + + builder.setConvexMesh(cookedBuffer); + + return true; } + + +physx::PxConvexMeshGeometry* PxConvexMeshGeometryDTO::deserialize(Nv::Blast::Serialization::PxConvexMeshGeometry::Reader reader) +{ + NVBLAST_ASSERT(sExtPxSerializerCooking != nullptr); + + reader = reader; + + return nullptr; +} + + +bool PxConvexMeshGeometryDTO::deserializeInto(Nv::Blast::Serialization::PxConvexMeshGeometry::Reader reader, physx::PxConvexMeshGeometry * poco) +{ + NVBLAST_ASSERT(sExtPxSerializerPhysics != nullptr); + + PxMeshScaleDTO::deserializeInto(reader.getScale(), &poco->scale); + + Nv::Blast::ExtKJPxInputStream inputStream(reader.getConvexMesh()); + + //NOTE: Naive approach, no shared convex hulls + poco->convexMesh = sExtPxSerializerPhysics->createConvexMesh(inputStream); + + return poco->convexMesh != nullptr; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.h b/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.h index 27b3754..0628518 100644 --- a/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.h +++ b/sdk/extensions/serialization/source/DTO/PxConvexMeshGeometryDTO.h @@ -1,16 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" #include "PxConvexMeshGeometry.h" #include "PxCooking.h" diff --git a/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.cpp b/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.cpp index 8fee6ad..76f0d90 100644 --- a/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.cpp @@ -1,42 +1,64 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "PxMeshScaleDTO.h" #include "PxVec3DTO.h" #include "PxQuatDTO.h" + namespace Nv { - namespace Blast - { - bool PxMeshScaleDTO::serialize(Nv::Blast::Serialization::PxMeshScale::Builder builder, const physx::PxMeshScale * poco) - { - PxVec3DTO::serialize(builder.getScale(), &poco->scale); - PxQuatDTO::serialize(builder.getRotation(), &poco->rotation); - - return true; - } - - physx::PxMeshScale* PxMeshScaleDTO::deserialize(Nv::Blast::Serialization::PxMeshScale::Reader reader) - { - reader = reader; - return nullptr; - } - - bool PxMeshScaleDTO::deserializeInto(Nv::Blast::Serialization::PxMeshScale::Reader reader, physx::PxMeshScale * poco) - { - PxVec3DTO::deserializeInto(reader.getScale(), &poco->scale); - PxQuatDTO::deserializeInto(reader.getRotation(), &poco->rotation); - - return true; - } - } +namespace Blast +{ + +bool PxMeshScaleDTO::serialize(Nv::Blast::Serialization::PxMeshScale::Builder builder, const physx::PxMeshScale * poco) +{ + PxVec3DTO::serialize(builder.getScale(), &poco->scale); + PxQuatDTO::serialize(builder.getRotation(), &poco->rotation); + + return true; +} + + +physx::PxMeshScale* PxMeshScaleDTO::deserialize(Nv::Blast::Serialization::PxMeshScale::Reader reader) +{ + reader = reader; + return nullptr; +} + + +bool PxMeshScaleDTO::deserializeInto(Nv::Blast::Serialization::PxMeshScale::Reader reader, physx::PxMeshScale * poco) +{ + PxVec3DTO::deserializeInto(reader.getScale(), &poco->scale); + PxQuatDTO::deserializeInto(reader.getRotation(), &poco->rotation); + + return true; } +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.h b/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.h index 7b758c8..bf3c521 100644 --- a/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.h +++ b/sdk/extensions/serialization/source/DTO/PxMeshScaleDTO.h @@ -1,17 +1,35 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "PxMeshScale.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" #include "PxCooking.h" DTO_CLASS(PxMeshScale, physx::PxMeshScale, Nv::Blast::Serialization::PxMeshScale) diff --git a/sdk/extensions/serialization/source/DTO/PxQuatDTO.cpp b/sdk/extensions/serialization/source/DTO/PxQuatDTO.cpp index 8faeaa6..05490af 100644 --- a/sdk/extensions/serialization/source/DTO/PxQuatDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/PxQuatDTO.cpp @@ -1,45 +1,65 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "PxQuatDTO.h" namespace Nv { - namespace Blast - { - - bool PxQuatDTO::serialize(Nv::Blast::Serialization::PxQuat::Builder builder, const physx::PxQuat * poco) - { - builder.setX(poco->x); - builder.setY(poco->y); - builder.setZ(poco->z); - builder.setW(poco->w); - - return true; - } - - physx::PxQuat* PxQuatDTO::deserialize(Nv::Blast::Serialization::PxQuat::Reader reader) - { - reader = reader; - return nullptr; - } - - bool PxQuatDTO::deserializeInto(Nv::Blast::Serialization::PxQuat::Reader reader, physx::PxQuat * poco) - { - poco->x = reader.getX(); - poco->y = reader.getY(); - poco->z = reader.getZ(); - poco->w = reader.getW(); - - return true; - } - - } +namespace Blast +{ + +bool PxQuatDTO::serialize(Nv::Blast::Serialization::PxQuat::Builder builder, const physx::PxQuat * poco) +{ + builder.setX(poco->x); + builder.setY(poco->y); + builder.setZ(poco->z); + builder.setW(poco->w); + + return true; } + + +physx::PxQuat* PxQuatDTO::deserialize(Nv::Blast::Serialization::PxQuat::Reader reader) +{ + reader = reader; + return nullptr; +} + + +bool PxQuatDTO::deserializeInto(Nv::Blast::Serialization::PxQuat::Reader reader, physx::PxQuat * poco) +{ + poco->x = reader.getX(); + poco->y = reader.getY(); + poco->z = reader.getZ(); + poco->w = reader.getW(); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/PxQuatDTO.h b/sdk/extensions/serialization/source/DTO/PxQuatDTO.h index 460d6c5..b7d15b9 100644 --- a/sdk/extensions/serialization/source/DTO/PxQuatDTO.h +++ b/sdk/extensions/serialization/source/DTO/PxQuatDTO.h @@ -1,17 +1,35 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "PxQuat.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" #include "PxCooking.h" DTO_CLASS(PxQuat, physx::PxQuat, Nv::Blast::Serialization::PxQuat) diff --git a/sdk/extensions/serialization/source/DTO/PxTransformDTO.cpp b/sdk/extensions/serialization/source/DTO/PxTransformDTO.cpp index 20a7cbb..0b1a240 100644 --- a/sdk/extensions/serialization/source/DTO/PxTransformDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/PxTransformDTO.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "PxTransformDTO.h" #include "PxQuatDTO.h" @@ -14,29 +32,32 @@ namespace Nv { - namespace Blast - { - - bool PxTransformDTO::serialize(Nv::Blast::Serialization::PxTransform::Builder builder, const physx::PxTransform * poco) - { - PxQuatDTO::serialize(builder.getQ(), &poco->q); - PxVec3DTO::serialize(builder.getP(), &poco->p); - - return true; - } - - physx::PxTransform* PxTransformDTO::deserialize(Nv::Blast::Serialization::PxTransform::Reader reader) - { - reader = reader; - return nullptr; - } - - bool PxTransformDTO::deserializeInto(Nv::Blast::Serialization::PxTransform::Reader reader, physx::PxTransform * poco) - { - PxQuatDTO::deserializeInto(reader.getQ(), &poco->q); - PxVec3DTO::deserializeInto(reader.getP(), &poco->p); +namespace Blast +{ - return true; - } - } +bool PxTransformDTO::serialize(Nv::Blast::Serialization::PxTransform::Builder builder, const physx::PxTransform * poco) +{ + PxQuatDTO::serialize(builder.getQ(), &poco->q); + PxVec3DTO::serialize(builder.getP(), &poco->p); + + return true; +} + + +physx::PxTransform* PxTransformDTO::deserialize(Nv::Blast::Serialization::PxTransform::Reader reader) +{ + reader = reader; + return nullptr; } + + +bool PxTransformDTO::deserializeInto(Nv::Blast::Serialization::PxTransform::Reader reader, physx::PxTransform * poco) +{ + PxQuatDTO::deserializeInto(reader.getQ(), &poco->q); + PxVec3DTO::deserializeInto(reader.getP(), &poco->p); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/PxTransformDTO.h b/sdk/extensions/serialization/source/DTO/PxTransformDTO.h index 49a6b73..3523375 100644 --- a/sdk/extensions/serialization/source/DTO/PxTransformDTO.h +++ b/sdk/extensions/serialization/source/DTO/PxTransformDTO.h @@ -1,17 +1,35 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "PxTransform.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" #include "PxCooking.h" DTO_CLASS(PxTransform, physx::PxTransform, Nv::Blast::Serialization::PxTransform) diff --git a/sdk/extensions/serialization/source/DTO/PxVec3DTO.cpp b/sdk/extensions/serialization/source/DTO/PxVec3DTO.cpp index 9827cd0..995bb44 100644 --- a/sdk/extensions/serialization/source/DTO/PxVec3DTO.cpp +++ b/sdk/extensions/serialization/source/DTO/PxVec3DTO.cpp @@ -1,45 +1,65 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "PxVec3DTO.h" #include "NvBlastAssert.h" namespace Nv { - namespace Blast - { - bool PxVec3DTO::serialize(Nv::Blast::Serialization::PxVec3::Builder builder, const physx::PxVec3 * poco) - { - NVBLAST_ASSERT(poco != nullptr); - - builder.setX(poco->x); - builder.setY(poco->y); - builder.setZ(poco->z); - - return true; - } - - physx::PxVec3* PxVec3DTO::deserialize(Nv::Blast::Serialization::PxVec3::Reader reader) - { - //TODO: Allocate using ExtContext and return - reader = reader; - return nullptr; - } - - bool PxVec3DTO::deserializeInto(Nv::Blast::Serialization::PxVec3::Reader reader, physx::PxVec3* target) - { - target->x = reader.getX(); - target->y = reader.getY(); - target->z = reader.getZ(); - - return true; - } - } +namespace Blast +{ + +bool PxVec3DTO::serialize(Nv::Blast::Serialization::PxVec3::Builder builder, const physx::PxVec3 * poco) +{ + NVBLAST_ASSERT(poco != nullptr); + + builder.setX(poco->x); + builder.setY(poco->y); + builder.setZ(poco->z); + + return true; +} + +physx::PxVec3* PxVec3DTO::deserialize(Nv::Blast::Serialization::PxVec3::Reader reader) +{ + //TODO: Allocate using ExtContext and return + reader = reader; + return nullptr; } + +bool PxVec3DTO::deserializeInto(Nv::Blast::Serialization::PxVec3::Reader reader, physx::PxVec3* target) +{ + target->x = reader.getX(); + target->y = reader.getY(); + target->z = reader.getZ(); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/PxVec3DTO.h b/sdk/extensions/serialization/source/DTO/PxVec3DTO.h index 8a04c8b..84fce39 100644 --- a/sdk/extensions/serialization/source/DTO/PxVec3DTO.h +++ b/sdk/extensions/serialization/source/DTO/PxVec3DTO.h @@ -1,17 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtTkSerialization.capn.h" #include "PxVec3.h" -#include "PxCooking.h" DTO_CLASS(PxVec3, physx::PxVec3, Nv::Blast::Serialization::PxVec3) diff --git a/sdk/extensions/serialization/source/DTO/TkAssetDTO.cpp b/sdk/extensions/serialization/source/DTO/TkAssetDTO.cpp index acc55ba..7ba6d4f 100644 --- a/sdk/extensions/serialization/source/DTO/TkAssetDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/TkAssetDTO.cpp @@ -1,67 +1,94 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "TkAssetDTO.h" #include "AssetDTO.h" #include "TkAssetJointDescDTO.h" #include <vector> #include "NvBlastTkFramework.h" - +#include "NvBlastGlobals.h" namespace Nv { - namespace Blast +namespace Blast +{ + +extern TkFramework* sExtTkSerializerFramework; + + +bool TkAssetDTO::serialize(Nv::Blast::Serialization::TkAsset::Builder builder, const Nv::Blast::TkAsset * poco) +{ + const Asset* assetLL = reinterpret_cast<const Nv::Blast::Asset*>(poco->getAssetLL()); + + Nv::Blast::AssetDTO::serialize(builder.getAssetLL(), assetLL); + + uint32_t jointDescCount = poco->getJointDescCount(); + + capnp::List<Nv::Blast::Serialization::TkAssetJointDesc>::Builder jointDescs = builder.initJointDescs(jointDescCount); + + for (uint32_t i = 0; i < jointDescCount; i++) { - bool TkAssetDTO::serialize(Nv::Blast::Serialization::TkAsset::Builder builder, const Nv::Blast::TkAsset * poco) - { - const Asset* assetLL = reinterpret_cast<const Nv::Blast::Asset*>(poco->getAssetLL()); - - Nv::Blast::AssetDTO::serialize(builder.getAssetLL(), assetLL); - - uint32_t jointDescCount = poco->getJointDescCount(); - - capnp::List<Nv::Blast::Serialization::TkAssetJointDesc>::Builder jointDescs = builder.initJointDescs(jointDescCount); - - for (uint32_t i = 0; i < jointDescCount; i++) - { - TkAssetJointDescDTO::serialize(jointDescs[i], &poco->getJointDescs()[i]); - } - - return true; - } - - Nv::Blast::TkAsset* TkAssetDTO::deserialize(Nv::Blast::Serialization::TkAsset::Reader reader) - { - const NvBlastAsset* assetLL = reinterpret_cast<const NvBlastAsset*>(AssetDTO::deserialize(reader.getAssetLL())); - - std::vector<Nv::Blast::TkAssetJointDesc> jointDescs; - jointDescs.resize(reader.getJointDescs().size()); - - for (uint32_t i = 0; i < jointDescs.size(); i++) - { - TkAssetJointDescDTO::deserializeInto(reader.getJointDescs()[i], &jointDescs[i]); - } - - // Make sure to set ownsAsset to true - this is serialization and no one else owns it. - Nv::Blast::TkAsset* asset = NvBlastTkFrameworkGet()->createAsset(assetLL, jointDescs.data(), jointDescs.size(), true); - - return asset; - } - - bool TkAssetDTO::deserializeInto(Nv::Blast::Serialization::TkAsset::Reader reader, Nv::Blast::TkAsset * poco) - { - reader = reader; - poco = nullptr; - // NOTE: Because of the way TkAsset is currently structured, this won't work. - return false; - } + TkAssetJointDescDTO::serialize(jointDescs[i], &poco->getJointDescs()[i]); } + + return true; } + + +Nv::Blast::TkAsset* TkAssetDTO::deserialize(Nv::Blast::Serialization::TkAsset::Reader reader) +{ + const NvBlastAsset* assetLL = reinterpret_cast<const NvBlastAsset*>(AssetDTO::deserialize(reader.getAssetLL())); + + std::vector<Nv::Blast::TkAssetJointDesc> jointDescs; + + const uint32_t jointDescCount = reader.getJointDescs().size(); + jointDescs.resize(jointDescCount); + auto readerJointDescs = reader.getJointDescs(); + for (uint32_t i = 0; i < jointDescCount; i++) + { + TkAssetJointDescDTO::deserializeInto(readerJointDescs[i], &jointDescs[i]); + } + + // Make sure to set ownsAsset to true - this is serialization and no one else owns it. + Nv::Blast::TkAsset* asset = NvBlastTkFrameworkGet()->createAsset(assetLL, jointDescs.data(), jointDescCount, true); + + return asset; +} + + +bool TkAssetDTO::deserializeInto(Nv::Blast::Serialization::TkAsset::Reader reader, Nv::Blast::TkAsset * poco) +{ + reader = reader; + poco = nullptr; + // NOTE: Because of the way TkAsset is currently structured, this won't work. + return false; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/TkAssetDTO.h b/sdk/extensions/serialization/source/DTO/TkAssetDTO.h index 1b21eba..d0eceea 100644 --- a/sdk/extensions/serialization/source/DTO/TkAssetDTO.h +++ b/sdk/extensions/serialization/source/DTO/TkAssetDTO.h @@ -1,17 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastTkAsset.h" -#include "generated/NvBlastExtSerialization.capn.h" -#include "PxCooking.h" +#include "generated/NvBlastExtTkSerialization.capn.h" DTO_CLASS(TkAsset, Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset) diff --git a/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.cpp b/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.cpp index 9118d19..cbc1ef8 100644 --- a/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.cpp +++ b/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.cpp @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "TkAssetJointDescDTO.h" #include "PxVec3DTO.h" @@ -14,40 +32,45 @@ namespace Nv { - namespace Blast +namespace Blast +{ + +bool TkAssetJointDescDTO::serialize(Nv::Blast::Serialization::TkAssetJointDesc::Builder builder, const Nv::Blast::TkAssetJointDesc * poco) +{ + kj::ArrayPtr<const uint32_t> nodeIndices(poco->nodeIndices, 2); + builder.setNodeIndices(nodeIndices); + + for (int i = 0; i < 2; i++) { - - bool TkAssetJointDescDTO::serialize(Nv::Blast::Serialization::TkAssetJointDesc::Builder builder, const Nv::Blast::TkAssetJointDesc * poco) - { - kj::ArrayPtr<const uint32_t> nodeIndices(poco->nodeIndices, 2); - builder.setNodeIndices(nodeIndices); - - for (int i = 0; i < 2; i++) - { - PxVec3DTO::serialize(builder.getAttachPositions()[i], &poco->attachPositions[i]); - } - - return true; - } - - Nv::Blast::TkAssetJointDesc* TkAssetJointDescDTO::deserialize(Nv::Blast::Serialization::TkAssetJointDesc::Reader reader) - { - //TODO: Allocate with ExtContent and return - - reader = reader; - - return nullptr; - } - - bool TkAssetJointDescDTO::deserializeInto(Nv::Blast::Serialization::TkAssetJointDesc::Reader reader, Nv::Blast::TkAssetJointDesc * poco) - { - PxVec3DTO::deserializeInto(reader.getAttachPositions()[0], &poco->attachPositions[0]); - PxVec3DTO::deserializeInto(reader.getAttachPositions()[1], &poco->attachPositions[1]); - - poco->nodeIndices[0] = reader.getNodeIndices()[0]; - poco->nodeIndices[1] = reader.getNodeIndices()[1]; - - return true; - } + PxVec3DTO::serialize(builder.getAttachPositions()[i], &poco->attachPositions[i]); } -}
\ No newline at end of file + + return true; +} + + +Nv::Blast::TkAssetJointDesc* TkAssetJointDescDTO::deserialize(Nv::Blast::Serialization::TkAssetJointDesc::Reader reader) +{ + //TODO: Allocate with ExtContent and return + + reader = reader; + + return nullptr; +} + + +bool TkAssetJointDescDTO::deserializeInto(Nv::Blast::Serialization::TkAssetJointDesc::Reader reader, Nv::Blast::TkAssetJointDesc * poco) +{ + auto readerAttachPositions = reader.getAttachPositions(); + PxVec3DTO::deserializeInto(readerAttachPositions[0], &poco->attachPositions[0]); + PxVec3DTO::deserializeInto(readerAttachPositions[1], &poco->attachPositions[1]); + + auto readerNodeIndices = reader.getNodeIndices(); + poco->nodeIndices[0] = readerNodeIndices[0]; + poco->nodeIndices[1] = readerNodeIndices[1]; + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.h b/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.h index 88364bd..1dca2f9 100644 --- a/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.h +++ b/sdk/extensions/serialization/source/DTO/TkAssetJointDescDTO.h @@ -1,17 +1,34 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "DTOMacros.h" #include "NvBlastTkAsset.h" -#include "generated/NvBlastExtSerialization.capn.h" -#include "PxCooking.h" +#include "generated/NvBlastExtTkSerialization.capn.h" DTO_CLASS(TkAssetJointDesc, Nv::Blast::TkAssetJointDesc, Nv::Blast::Serialization::TkAssetJointDesc) diff --git a/sdk/extensions/serialization/source/NvBlastExtGlobals.h b/sdk/extensions/serialization/source/NvBlastExtGlobals.h deleted file mode 100644 index dd50afd..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtGlobals.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -/** -Function pointer type for allocation - has same signature as stdlib malloc. -*/ -typedef void* (*NvBlastExtAlloc)(size_t size); - -extern NvBlastExtAlloc gAlloc; -extern NvBlastLog gLog; - diff --git a/sdk/extensions/serialization/source/NvBlastExtInputStream.cpp b/sdk/extensions/serialization/source/NvBlastExtInputStream.cpp index 7ef9b62..805990d 100644 --- a/sdk/extensions/serialization/source/NvBlastExtInputStream.cpp +++ b/sdk/extensions/serialization/source/NvBlastExtInputStream.cpp @@ -1,17 +1,35 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastExtInputStream.h" -Nv::Blast::ExtInputStream::ExtInputStream(std::istream &inputStream): +Nv::Blast::ExtInputStream::ExtInputStream(std::istream &inputStream) : m_inputStream(inputStream) { @@ -25,13 +43,13 @@ size_t Nv::Blast::ExtInputStream::tryRead(void* buffer, size_t /*minBytes*/, siz if (m_inputStream.fail()) { // Throw exception, log error -// NVBLASTEXT_LOG_ERROR("Failure when reading from stream"); +// NVBLAST_LOG_ERROR("Failure when reading from stream"); } // Since we're using a blocking read above, if we don't have maxBytes we're probably done if ((size_t) m_inputStream.gcount() < maxBytes) { -// NVBLASTEXT_LOG_ERROR("Failed to read requested number of bytes during blocking read."); +// NVBLAST_LOG_ERROR("Failed to read requested number of bytes during blocking read."); } return m_inputStream.gcount(); diff --git a/sdk/extensions/serialization/source/NvBlastExtInputStream.h b/sdk/extensions/serialization/source/NvBlastExtInputStream.h index 9b19d9c..cd36e9e 100644 --- a/sdk/extensions/serialization/source/NvBlastExtInputStream.h +++ b/sdk/extensions/serialization/source/NvBlastExtInputStream.h @@ -1,32 +1,53 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "kj/io.h" #include <istream> + namespace Nv { - namespace Blast - { - class ExtInputStream : public kj::InputStream - { - public: - ExtInputStream() = delete; - ExtInputStream(std::istream &inputStream); - - // Returns a read of maxBytes. This is supposed to be happy doing partial reads, but currently isn't. - virtual size_t tryRead(void* buffer, size_t minBytes, size_t maxBytes) override; - - private: - std::istream &m_inputStream; - }; - } -}
\ No newline at end of file +namespace Blast +{ + +class ExtInputStream : public kj::InputStream +{ +public: + ExtInputStream() = delete; + ExtInputStream(std::istream &inputStream); + + // Returns a read of maxBytes. This is supposed to be happy doing partial reads, but currently isn't. + virtual size_t tryRead(void* buffer, size_t minBytes, size_t maxBytes) override; + +private: + std::istream &m_inputStream; +}; + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.cpp b/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.cpp index 9af13a9..cc73e6b 100644 --- a/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.cpp +++ b/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.cpp @@ -1,32 +1,53 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastExtKJPxInputStream.h" namespace Nv { - namespace Blast - { - ExtKJPxInputStream::ExtKJPxInputStream(capnp::Data::Reader inReader) : - dataReader(inReader), - inputStream(nullptr) - { - kj::ArrayPtr<const unsigned char> buffer(inReader.begin(), inReader.size()); - - inputStream = std::make_shared<kj::ArrayInputStream>(buffer); - } - - uint32_t ExtKJPxInputStream::read(void* dest, uint32_t count) - { - return inputStream->tryRead(dest, count, count); - } - } +namespace Blast +{ + +ExtKJPxInputStream::ExtKJPxInputStream(capnp::Data::Reader inReader) : +dataReader(inReader), +inputStream(nullptr) +{ + kj::ArrayPtr<const unsigned char> buffer(inReader.begin(), inReader.size()); + + inputStream = std::make_shared<kj::ArrayInputStream>(buffer); +} + + +uint32_t ExtKJPxInputStream::read(void* dest, uint32_t count) +{ + return inputStream->tryRead(dest, count, count); } +} // namespace Blast +} // namespace Nv + diff --git a/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.h b/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.h index 452892d..bc0074a 100644 --- a/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.h +++ b/sdk/extensions/serialization/source/NvBlastExtKJPxInputStream.h @@ -1,41 +1,62 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "PxIO.h" #include "capnp/common.h" #include "kj/io.h" #include <memory> -#include "generated/NvBlastExtSerialization.capn.h" +#include "generated/NvBlastExtPxSerialization.capn.h" + namespace Nv { - namespace Blast - { - /* - A wrapper around a Capn Proto Data reader. - - Since it needs to behave like a stream, it's internally wrapped in a stream. - - */ - class ExtKJPxInputStream : public physx::PxInputStream - { - public: - ExtKJPxInputStream(capnp::Data::Reader inReader); - ~ExtKJPxInputStream() = default; - - virtual uint32_t read(void* dest, uint32_t count) override; - - private: - capnp::Data::Reader dataReader; - std::shared_ptr<kj::ArrayInputStream> inputStream; - }; - } -} +namespace Blast +{ + +/* +A wrapper around a Capn Proto Data reader. + +Since it needs to behave like a stream, it's internally wrapped in a stream. + +*/ +class ExtKJPxInputStream : public physx::PxInputStream +{ +public: + ExtKJPxInputStream(capnp::Data::Reader inReader); + ~ExtKJPxInputStream() = default; + + virtual uint32_t read(void* dest, uint32_t count) override; + +private: + capnp::Data::Reader dataReader; + std::shared_ptr<kj::ArrayInputStream> inputStream; +}; + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.cpp b/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.cpp index 0f17a01..d1ea822 100644 --- a/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.cpp +++ b/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.cpp @@ -1,35 +1,55 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #include "NvBlastExtKJPxOutputStream.h" namespace Nv { - namespace Blast - { - ExtKJPxOutputStream::ExtKJPxOutputStream(kj::ArrayPtr<unsigned char> inBuffer) : - writtenBytes(0), - Buffer(inBuffer), - outputStream(nullptr) - { - outputStream = std::make_shared<kj::ArrayOutputStream>(inBuffer); - } - - uint32_t ExtKJPxOutputStream::write(const void* src, uint32_t count) - { - outputStream->write(src, count); - - writtenBytes += count; - - return count; - } - } +namespace Blast +{ + +ExtKJPxOutputStream::ExtKJPxOutputStream(kj::ArrayPtr<unsigned char> inBuffer) : +writtenBytes(0), +Buffer(inBuffer), +outputStream(nullptr) +{ + outputStream = std::make_shared<kj::ArrayOutputStream>(inBuffer); +} + + +uint32_t ExtKJPxOutputStream::write(const void* src, uint32_t count) +{ + outputStream->write(src, count); + + writtenBytes += count; + + return count; } +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.h b/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.h index 0ed563f..325a65a 100644 --- a/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.h +++ b/sdk/extensions/serialization/source/NvBlastExtKJPxOutputStream.h @@ -1,12 +1,30 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "PxIO.h" @@ -14,27 +32,30 @@ #include <memory> #include "kj/io.h" + namespace Nv { - namespace Blast - { - class ExtKJPxOutputStream : public physx::PxOutputStream - { - public: - ExtKJPxOutputStream(kj::ArrayPtr<unsigned char> inBuffer); - ~ExtKJPxOutputStream() = default; +namespace Blast +{ + +class ExtKJPxOutputStream : public physx::PxOutputStream +{ +public: + ExtKJPxOutputStream(kj::ArrayPtr<unsigned char> inBuffer); + ~ExtKJPxOutputStream() = default; + + virtual uint32_t write(const void* src, uint32_t count) override; - virtual uint32_t write(const void* src, uint32_t count) override; + uint32_t getWrittenBytes() { return writtenBytes; } - uint32_t getWrittenBytes() { return writtenBytes; } + kj::ArrayPtr<unsigned char> getBuffer() { return Buffer; } - kj::ArrayPtr<unsigned char> getBuffer() { return Buffer; } +private: + uint32_t writtenBytes; - private: - uint32_t writtenBytes; + kj::ArrayPtr<unsigned char> Buffer; + std::shared_ptr<kj::ArrayOutputStream> outputStream; +}; - kj::ArrayPtr<unsigned char> Buffer; - std::shared_ptr<kj::ArrayOutputStream> outputStream; - }; - } -} +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtLlSerialization.capn b/sdk/extensions/serialization/source/NvBlastExtLlSerialization.capn new file mode 100644 index 0000000..31c1db4 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtLlSerialization.capn @@ -0,0 +1,108 @@ +# 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) 2017 NVIDIA Corporation. All rights reserved. + + +@0x9a4a58fac38375e0; + +using Cxx = import "/capnp/c++.capnp"; + +$Cxx.namespace("Nv::Blast::Serialization"); + +struct Asset +{ + header @0 :NvBlastDataBlock; + + iD @1 :UUID; + + chunkCount @2 :UInt32; + + graph @3 :NvBlastSupportGraph; + + leafChunkCount @4 :UInt32; + + firstSubsupportChunkIndex @5 :UInt32; + + bondCount @6 :UInt32; + + chunks @7: List(NvBlastChunk); + + bonds @8: List(NvBlastBond); + + subtreeLeafChunkCounts @9: List(UInt32); + + chunkToGraphNodeMap @10: List(UInt32); +} + +struct NvBlastDataBlock +{ + enum Type + { + assetDataBlock @0; + instanceDataBlock @1; + } + + dataType @0 :Type; + + formatVersion @1 :UInt32; + + size @2 :UInt32; +} + +struct NvBlastChunk +{ + centroid @0 :List(Float32); + + volume @1 :Float32; + + parentChunkIndex @2 :UInt32; + firstChildIndex @3 :UInt32; + childIndexStop @4 :UInt32; + userData @5 :UInt32; +} + +struct NvBlastBond +{ + normal @0 :List(Float32); + area @1 :Float32; + centroid @2 :List(Float32); + userData @3 :UInt32; +} + +struct NvBlastSupportGraph +{ + nodeCount @0 : UInt32; + + chunkIndices @1 : List(UInt32); + adjacencyPartition @2 : List(UInt32); + adjacentNodeIndices @3 : List(UInt32); + adjacentBondIndices @4 : List(UInt32); +} + +struct UUID +{ + value @0 : Data; +} diff --git a/sdk/extensions/serialization/source/NvBlastExtLlSerialization.cpp b/sdk/extensions/serialization/source/NvBlastExtLlSerialization.cpp new file mode 100644 index 0000000..b9c261b --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtLlSerialization.cpp @@ -0,0 +1,136 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerializationInternal.h" +#include "NvBlastExtLlSerialization.h" +#include "NvBlastExtLlSerializerCAPN.h" + + +namespace Nv +{ +namespace Blast +{ + +class ExtLlSerializerAsset_CPNB : public ExtSerializer +{ +public: + ExtSerializerBoilerplate("LLAsset_CPNB", "Blast low-level asset (NvBlastAsset) serialization using Cap'n Proto binary format.", LlObjectTypeID::Asset, ExtSerialization::EncodingID::CapnProtoBinary); + ExtSerializerDefaultFactoryAndRelease(ExtLlSerializerAsset_CPNB); + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + return ExtSerializationCAPN<Asset, Serialization::Asset::Reader, Serialization::Asset::Builder>::deserializeFromBuffer(reinterpret_cast<const unsigned char*>(buffer), size); + } + + virtual uint64_t serializeIntoBuffer(void*& buffer, ExtSerialization::BufferProvider& bufferProvider, const void* object, uint64_t offset = 0) override + { + uint64_t usedSize; + if (!ExtSerializationCAPN<Asset, Serialization::Asset::Reader, Serialization::Asset::Builder>::serializeIntoBuffer(reinterpret_cast<const Asset*>(object), + reinterpret_cast<unsigned char*&>(buffer), usedSize, &bufferProvider, offset)) + { + return 0; + } + return usedSize; + } +}; + + +class ExtLlSerializerObject_RAW : public ExtSerializer +{ +public: + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + const NvBlastDataBlock* block = reinterpret_cast<const NvBlastDataBlock*>(buffer); + if (static_cast<uint64_t>(block->size) > size) + { + return nullptr; + } + void* llobject = NVBLAST_ALLOC(block->size); + return memcpy(llobject, block, block->size); + } + + virtual uint64_t serializeIntoBuffer(void*& buffer, ExtSerialization::BufferProvider& bufferProvider, const void* object, uint64_t offset = 0) override + { + const NvBlastDataBlock* block = reinterpret_cast<const NvBlastDataBlock*>(object); + const uint64_t size = block->size + offset; + buffer = bufferProvider.requestBuffer(size); + if (buffer == nullptr) + { + return 0; + } + memcpy(static_cast<char*>(buffer) + offset, object, block->size); + return size; + } +}; + + +class ExtLlSerializerAsset_RAW : public ExtLlSerializerObject_RAW +{ +public: + ExtSerializerBoilerplate("LLAsset_RAW", "Blast low-level asset (NvBlastAsset) serialization using raw memory format.", LlObjectTypeID::Asset, ExtSerialization::EncodingID::RawBinary); + ExtSerializerDefaultFactoryAndRelease(ExtLlSerializerAsset_RAW); +}; + + +class ExtLlSerializerFamily_RAW : public ExtLlSerializerObject_RAW +{ +public: + ExtSerializerBoilerplate("LLFamily_RAW", "Blast low-level family (NvBlastFamily) serialization using raw memory format.", LlObjectTypeID::Family, ExtSerialization::EncodingID::RawBinary); + ExtSerializerDefaultFactoryAndRelease(ExtLlSerializerFamily_RAW); +}; + +} // namespace Blast +} // namespace Nv + + +/////////////////////////////////////// + + +size_t NvBlastExtLlSerializerLoadSet(Nv::Blast::ExtSerialization& serialization) +{ + Nv::Blast::ExtSerializer* (*factories[])() = + { + Nv::Blast::ExtLlSerializerAsset_CPNB::create, + Nv::Blast::ExtLlSerializerAsset_RAW::create, + Nv::Blast::ExtLlSerializerFamily_RAW::create + }; + + return Nv::Blast::ExtSerializationLoadSet(static_cast<Nv::Blast::ExtSerializationInternal&>(serialization), factories); +} + + +uint64_t NvBlastExtSerializationSerializeAssetIntoBuffer(void*& buffer, Nv::Blast::ExtSerialization& serialization, const NvBlastAsset* asset) +{ + return serialization.serializeIntoBuffer(buffer, asset, Nv::Blast::LlObjectTypeID::Asset); +} + + +uint64_t NvBlastExtSerializationSerializeFamilyIntoBuffer(void*& buffer, Nv::Blast::ExtSerialization& serialization, const NvBlastFamily* family) +{ + return serialization.serializeIntoBuffer(buffer, family, Nv::Blast::LlObjectTypeID::Family); +} diff --git a/sdk/extensions/serialization/source/NvBlastExtLlSerializerCAPN.h b/sdk/extensions/serialization/source/NvBlastExtLlSerializerCAPN.h new file mode 100644 index 0000000..1e4bbc2 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtLlSerializerCAPN.h @@ -0,0 +1,72 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + +#include "NvBlastExtSerializationCAPN.h" +#include "NvBlastAsset.h" +#include "AssetDTO.h" + + +/** +Specializations of ExtSerializationCAPN for Blast LL +*/ + +namespace Nv +{ +namespace Blast +{ + +//// Nv::Blast::Asset //// + +template<> +NV_INLINE bool ExtSerializationCAPN<Asset, Serialization::Asset::Reader, Serialization::Asset::Builder>::serializeIntoBuilder(Serialization::Asset::Builder& assetBuilder, const Asset* asset) +{ + return AssetDTO::serialize(assetBuilder, asset); +} + + +template<> +NV_INLINE bool ExtSerializationCAPN<Asset, Serialization::Asset::Reader, Serialization::Asset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const Asset* asset) +{ + Serialization::Asset::Builder assetBuilder = message.initRoot<Serialization::Asset>(); + + return serializeIntoBuilder(assetBuilder, asset); +} + + +template<> +NV_INLINE Asset* ExtSerializationCAPN<Asset, Serialization::Asset::Reader, Serialization::Asset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) +{ + Serialization::Asset::Reader reader = message.getRoot<Serialization::Asset>(); + + return AssetDTO::deserialize(reader); +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtOutputStream.cpp b/sdk/extensions/serialization/source/NvBlastExtOutputStream.cpp index cf6e31f..c270fa8 100644 --- a/sdk/extensions/serialization/source/NvBlastExtOutputStream.cpp +++ b/sdk/extensions/serialization/source/NvBlastExtOutputStream.cpp @@ -1,15 +1,32 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. -#include "NvBlastExtOutputStream.h" +#include "NvBlastExtOutputStream.h" Nv::Blast::ExtOutputStream::ExtOutputStream(std::ostream &outputStream): diff --git a/sdk/extensions/serialization/source/NvBlastExtOutputStream.h b/sdk/extensions/serialization/source/NvBlastExtOutputStream.h index ba0044e..89b19a9 100644 --- a/sdk/extensions/serialization/source/NvBlastExtOutputStream.h +++ b/sdk/extensions/serialization/source/NvBlastExtOutputStream.h @@ -1,31 +1,52 @@ -/* -* Copyright (c) 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) 2017 NVIDIA Corporation. All rights reserved. + #pragma once #include "kj/io.h" #include <ostream> + namespace Nv { - namespace Blast - { - class ExtOutputStream : public kj::OutputStream - { - - public: - ExtOutputStream() = delete; - ExtOutputStream(std::ostream &outputStream); - - virtual void write(const void* buffer, size_t size) override; - private: - std::ostream &m_outputStream; - }; - } -} +namespace Blast +{ + +class ExtOutputStream : public kj::OutputStream +{ +public: + ExtOutputStream() = delete; + ExtOutputStream(std::ostream &outputStream); + + virtual void write(const void* buffer, size_t size) override; + +private: + std::ostream &m_outputStream; +}; + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtPxSerialization.capn b/sdk/extensions/serialization/source/NvBlastExtPxSerialization.capn new file mode 100644 index 0000000..802898f --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtPxSerialization.capn @@ -0,0 +1,99 @@ +# 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) 2017 NVIDIA Corporation. All rights reserved. + + +@0xf4df9a42d5842b01; + +using Cxx = import "/capnp/c++.capnp"; + +using TK = import "NvBlastExtTkSerialization.capn"; + +$Cxx.namespace("Nv::Blast::Serialization"); + +struct ExtPxAsset +{ + asset @0 :TK.TkAsset; + chunks @1 :List(ExtPxChunk); + subchunks @2 :List(ExtPxSubchunk); + uniformInitialBondHealth @3 :Float32; + bondHealths @4 :List(Float32); + uniformInitialLowerSupportChunkHealth @5 :Float32; + supportChunkHealths @6 :List(Float32); +} + +struct ExtPxChunk +{ + firstSubchunkIndex @0 :UInt32; + subchunkCount @1 :UInt32; + isStatic @2 :Bool; +} + +struct ExtPxSubchunk +{ + transform @0 :PxTransform; + geometry @1 :PxConvexMeshGeometry; +} + +struct PxConvexMeshGeometry +{ + scale @0 :PxMeshScale; + convexMesh @1 :Data; + meshFlags @2 :UInt8; + + enum Type + { + eSPHERE @0; + ePLANE @1; + eCAPSULE @2; + eBOX @3; + eCONVEXMESH @4; + eTRIANGLEMESH @5; + eHEIGHTFIELD @6; + } + + type @3 :Type; +} + +struct PxQuat +{ + x @0 :Float32; + y @1 :Float32; + z @2 :Float32; + w @3 :Float32; +} + +struct PxMeshScale +{ + scale @0 :TK.PxVec3; + rotation @1 :PxQuat; +} + +struct PxTransform +{ + q @0 :PxQuat; + p @1 :TK.PxVec3; +} diff --git a/sdk/extensions/serialization/source/NvBlastExtPxSerialization.cpp b/sdk/extensions/serialization/source/NvBlastExtPxSerialization.cpp new file mode 100644 index 0000000..d48213d --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtPxSerialization.cpp @@ -0,0 +1,109 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerializationInternal.h" +#include "NvBlastExtPxSerialization.h" +#include "NvBlastExtPxSerializerCAPN.h" +#include "NvBlastExtPxSerializerRAW.h" + + +namespace Nv +{ +namespace Blast +{ + +TkFramework* sExtPxSerializerFramework = nullptr; +physx::PxPhysics* sExtPxSerializerPhysics = nullptr; +physx::PxCooking* sExtPxSerializerCooking = nullptr; + + +class ExtPxSerializerAsset_CPNB : public ExtSerializer +{ +public: + ExtSerializerBoilerplate("ExtPxAsset_CPNB", "Blast PhysX extension asset (Nv::Blast::ExtPxAsset) serialization using Cap'n Proto binary format.", ExtPxObjectTypeID::Asset, ExtSerialization::EncodingID::CapnProtoBinary); + ExtSerializerDefaultFactoryAndRelease(ExtPxSerializerAsset_CPNB); + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + return ExtSerializationCAPN<ExtPxAsset, Serialization::ExtPxAsset::Reader, Serialization::ExtPxAsset::Builder>::deserializeFromBuffer(reinterpret_cast<const unsigned char*>(buffer), size); + } + + virtual uint64_t serializeIntoBuffer(void*& buffer, ExtSerialization::BufferProvider& bufferProvider, const void* object, uint64_t offset = 0) override + { + uint64_t usedSize; + if (!ExtSerializationCAPN<ExtPxAsset, Serialization::ExtPxAsset::Reader, Serialization::ExtPxAsset::Builder>::serializeIntoBuffer(reinterpret_cast<const ExtPxAsset*>(object), + reinterpret_cast<unsigned char*&>(buffer), usedSize, &bufferProvider, offset)) + { + return 0; + } + return usedSize; + } +}; + + +class ExtPxSerializerAsset_RAW : public ExtSerializer +{ +public: + ExtSerializerBoilerplate("ExtPxAsset_RAW", "Blast PhysX extension asset (Nv::Blast::TkAsset) serialization using raw memory format.", ExtPxObjectTypeID::Asset, ExtSerialization::EncodingID::RawBinary); + ExtSerializerDefaultFactoryAndRelease(ExtPxSerializerAsset_RAW); + ExtSerializerReadOnly(ExtPxSerializerAsset_RAW); + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + ExtIStream stream(buffer, size); + return deserializeExtPxAsset(stream, *sExtPxSerializerFramework, *sExtPxSerializerPhysics); + } +}; + +} // namespace Blast +} // namespace Nv + + +/////////////////////////////////////// + + +size_t NvBlastExtPxSerializerLoadSet(Nv::Blast::TkFramework& framework, physx::PxPhysics& physics, physx::PxCooking& cooking, Nv::Blast::ExtSerialization& serialization) +{ + Nv::Blast::sExtPxSerializerFramework = &framework; + Nv::Blast::sExtPxSerializerPhysics = &physics; + Nv::Blast::sExtPxSerializerCooking = &cooking; + + Nv::Blast::ExtSerializer* (*factories[])() = + { + Nv::Blast::ExtPxSerializerAsset_CPNB::create, + Nv::Blast::ExtPxSerializerAsset_RAW::create + }; + + return Nv::Blast::ExtSerializationLoadSet(static_cast<Nv::Blast::ExtSerializationInternal&>(serialization), factories); +} + + +uint64_t NvBlastExtSerializationSerializeExtPxAssetIntoBuffer(void*& buffer, Nv::Blast::ExtSerialization& serialization, const Nv::Blast::ExtPxAsset* asset) +{ + return serialization.serializeIntoBuffer(buffer, asset, Nv::Blast::ExtPxObjectTypeID::Asset); +} diff --git a/sdk/extensions/serialization/source/NvBlastExtPxSerializerCAPN.h b/sdk/extensions/serialization/source/NvBlastExtPxSerializerCAPN.h new file mode 100644 index 0000000..cd0e45f --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtPxSerializerCAPN.h @@ -0,0 +1,70 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + +#include "NvBlastExtSerializationCAPN.h" +#include "NvBlastExtPxAsset.h" +#include "ExtPxAssetDTO.h" + + +/** +Specializations of ExtSerializationCAPN for BlastExtPx +*/ + +namespace Nv +{ +namespace Blast +{ + +//// Nv::Blast::ExtPxAsset //// + +template<> +NV_INLINE bool ExtSerializationCAPN<ExtPxAsset, Serialization::ExtPxAsset::Reader, Serialization::ExtPxAsset::Builder>::serializeIntoBuilder(Serialization::ExtPxAsset::Builder& assetBuilder, const ExtPxAsset* asset) +{ + return ExtPxAssetDTO::serialize(assetBuilder, asset); +} + +template<> +NV_INLINE ExtPxAsset* ExtSerializationCAPN<ExtPxAsset, Serialization::ExtPxAsset::Reader, Serialization::ExtPxAsset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) +{ + Serialization::ExtPxAsset::Reader reader = message.getRoot<Serialization::ExtPxAsset>(); + + return ExtPxAssetDTO::deserialize(reader); +} + +template<> +NV_INLINE bool ExtSerializationCAPN<ExtPxAsset, Serialization::ExtPxAsset::Reader, Serialization::ExtPxAsset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const ExtPxAsset* asset) +{ + Serialization::ExtPxAsset::Builder assetBuilder = message.initRoot<Serialization::ExtPxAsset>(); + + return serializeIntoBuilder(assetBuilder, asset); +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.cpp b/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.cpp new file mode 100644 index 0000000..526b148 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.cpp @@ -0,0 +1,220 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerialization.h" +#include "NvBlastExtTkSerializerRAW.h" +#include "NvBlastExtPxAsset.h" +#include "NvBlastTkAsset.h" +#include "physics/NvBlastExtPxAssetImpl.h" +#include "NvBlastIndexFns.h" +#include "NvBlastAssert.h" +#include "NvBlastExtSerializationInternal.h" + +#include "PxPhysics.h" +#include "PsMemoryBuffer.h" +#include "PxIO.h" + + +namespace Nv +{ +namespace Blast +{ + +// Legacy IDs +struct ExtPxSerializationLegacyID +{ + enum Enum + { + Asset = NVBLAST_FOURCC('B', 'P', 'X', 'A'), //!< ExtPxAsset identifier token, used in serialization + }; +}; + + +// Legacy object format versions +struct ExtPxSerializationLegacyAssetVersion +{ + enum Enum + { + /** 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 + }; +}; + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Helpers/Wrappers +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class FileBufToPxInputStream final : public PxInputStream +{ +public: + FileBufToPxInputStream(PxFileBuf& filebuf) : m_filebuf(filebuf) {} + + virtual uint32_t read(void* dest, uint32_t count) + { + return m_filebuf.read(dest, count); + } + +private: + FileBufToPxInputStream& operator=(const FileBufToPxInputStream&); + + PxFileBuf& m_filebuf; +}; + + +class FileBufToPxOutputStream final : public PxOutputStream +{ +public: + FileBufToPxOutputStream(PxFileBuf& filebuf) : m_filebuf(filebuf) {} + + virtual uint32_t write(const void* src, uint32_t count) override + { + return m_filebuf.write(src, count); + } + +private: + FileBufToPxOutputStream& operator=(const FileBufToPxOutputStream&); + + PxFileBuf& m_filebuf; +}; + + +ExtPxAsset* deserializeExtPxAsset(ExtIStream& stream, TkFramework& framework, physx::PxPhysics& physics) +{ + // Read header + struct LegacyAssetDataHeader + { + uint32_t dataType; + uint32_t version; + }; + LegacyAssetDataHeader header; + stream >> header.dataType; + stream >> header.version; + NVBLAST_CHECK_ERROR(header.dataType == ExtPxSerializationLegacyID::Asset, "deserializeExtPxAsset: wrong data type in filebuf stream.", return nullptr); + NVBLAST_CHECK_ERROR(header.version == ExtPxSerializationLegacyAssetVersion::Current, "deserializeExtPxAsset: wrong data version in filebuf stream.", return nullptr); + + // Read initial TkAsset + TkAsset* tkAsset = deserializeTkAsset(stream, framework); + NVBLAST_CHECK_ERROR(tkAsset != nullptr, "ExtPxAsset::deserialize: failed to deserialize TkAsset.", return nullptr); + + // Create ExtPxAsset + ExtPxAssetImpl* asset = reinterpret_cast<ExtPxAssetImpl*>(ExtPxAsset::create(tkAsset)); + + // Fill arrays + auto& chunks = asset->getChunksArray(); + chunks.resize(tkAsset->getChunkCount()); + const uint32_t chunkCount = chunks.size(); + for (uint32_t i = 0; i < chunkCount; ++i) + { + ExtPxChunk& chunk = chunks[i]; + stream >> chunk.firstSubchunkIndex; + stream >> chunk.subchunkCount; + uint32_t val; + stream >> val; + chunk.isStatic = 0 != val; + } + + auto& subchunks = asset->getSubchunksArray(); + uint32_t subchunkCount; + stream >> subchunkCount; + subchunks.resize(subchunkCount); + for (uint32_t i = 0; i < subchunkCount; ++i) + { + ExtPxSubchunk& subchunk = subchunks[i]; + + // Subchunk transform + stream >> subchunk.transform.q.x >> subchunk.transform.q.y >> subchunk.transform.q.z >> subchunk.transform.q.w; + stream >> subchunk.transform.p.x >> subchunk.transform.p.y >> subchunk.transform.p.z; + + // Subchunk scale + stream >> subchunk.geometry.scale.scale.x >> subchunk.geometry.scale.scale.y >> subchunk.geometry.scale.scale.z; + stream >> subchunk.geometry.scale.rotation.x >> subchunk.geometry.scale.rotation.y >> subchunk.geometry.scale.rotation.z >> subchunk.geometry.scale.rotation.w; + + uint32_t convexReuseIndex; + stream >> convexReuseIndex; + if (isInvalidIndex(convexReuseIndex)) + { + physx::PsMemoryBuffer memBuf(stream.view(), stream.left()); + FileBufToPxInputStream inputStream(memBuf); + subchunk.geometry.convexMesh = physics.createConvexMesh(inputStream); + stream.advance(memBuf.tellRead()); + } + else + { + NVBLAST_ASSERT_WITH_MESSAGE(convexReuseIndex < i, "ExtPxAsset::deserialize: wrong convexReuseIndex."); + subchunk.geometry.convexMesh = subchunks[convexReuseIndex].geometry.convexMesh; + } + if (!subchunk.geometry.convexMesh) + { + NVBLAST_LOG_ERROR("ExtPxAsset::deserialize: failed to deserialize convex mesh."); + return nullptr; + } + } + + // checking if it's the end, so it will be binary compatible with asset before m_defaultActorDesc was added + if (!stream.eof()) + { + auto& defaultActorDesc = asset->getDefaultActorDesc(); + + stream >> defaultActorDesc.uniformInitialBondHealth; + stream >> defaultActorDesc.uniformInitialLowerSupportChunkHealth; + + auto& bondHealths = asset->getBondHealthsArray(); + uint32_t bondHealthCount; + stream >> bondHealthCount; + bondHealths.resize(bondHealthCount); + for (uint32_t i = 0; i < bondHealths.size(); ++i) + { + stream >> bondHealths[i]; + } + defaultActorDesc.initialBondHealths = bondHealthCount ? bondHealths.begin() : nullptr; + + auto& supportChunkHealths = asset->getBondHealthsArray(); + uint32_t supportChunkHealthCount; + stream >> supportChunkHealthCount; + supportChunkHealths.resize(supportChunkHealthCount); + for (uint32_t i = 0; i < supportChunkHealths.size(); ++i) + { + stream >> supportChunkHealths[i]; + } + defaultActorDesc.initialSupportChunkHealths = supportChunkHealthCount ? supportChunkHealths.begin() : nullptr; + } + + return asset; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.h b/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.h new file mode 100644 index 0000000..1e287c5 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtPxSerializerRAW.h @@ -0,0 +1,61 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + + +/** +Raw serialization function declarations for BlastExtPx +*/ + +#include <stdint.h> + + +// Forward declarations +namespace physx +{ +class PxPhysics; +} + +namespace Nv +{ +namespace Blast +{ + +// Forward declarations +class ExtPxAsset; +class TkFramework; +class ExtIStream; + + +//// Nv::Blast::TkAsset //// + +ExtPxAsset* deserializeExtPxAsset(ExtIStream& stream, TkFramework& framework, physx::PxPhysics& physics); + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtSerialization.capn b/sdk/extensions/serialization/source/NvBlastExtSerialization.capn deleted file mode 100644 index ddc439a..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerialization.capn +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (c) 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. - -@0xaffe4498f275ee58; - -using Cxx = import "/capnp/c++.capnp"; - -using LL = import "NvBlastExtSerializationLL.capn"; - -$Cxx.namespace("Nv::Blast::Serialization"); - -struct TkAsset -{ - assetLL @0 :LL.Asset; - - jointDescs @1 :List(TkAssetJointDesc); -} - -struct ExtPxAsset -{ - asset @0 :TkAsset; - chunks @1 :List(ExtPxChunk); - subchunks @2 :List(ExtPxSubchunk); -} - -struct ExtPxChunk -{ - firstSubchunkIndex @0 :UInt32; - subchunkCount @1 :UInt32; - isStatic @2 :Bool; -} - -struct ExtPxSubchunk -{ - transform @0 :PxTransform; - geometry @1 :PxConvexMeshGeometry; -} - -struct PxConvexMeshGeometry -{ - scale @0 :PxMeshScale; - convexMesh @1 :Data; - meshFlags @2 :UInt8; - - enum Type - { - eSPHERE @0; - ePLANE @1; - eCAPSULE @2; - eBOX @3; - eCONVEXMESH @4; - eTRIANGLEMESH @5; - eHEIGHTFIELD @6; - } - - type @3 :Type; -} - -struct TkAssetJointDesc -{ - nodeIndices @0 :List(UInt32); - attachPositions @1 :List(PxVec3); -} - -struct PxVec3 -{ - x @0 :Float32; - y @1 :Float32; - z @2 :Float32; -} - -struct PxQuat -{ - x @0 :Float32; - y @1 :Float32; - z @2 :Float32; - w @3 :Float32; -} - -struct PxMeshScale -{ - scale @0 :PxVec3; - rotation @1 :PxQuat; -} - -struct PxTransform -{ - q @0 :PxQuat; - p @1 :PxVec3; -} diff --git a/sdk/extensions/serialization/source/NvBlastExtSerialization.cpp b/sdk/extensions/serialization/source/NvBlastExtSerialization.cpp index 28a1553..77ecdf6 100644 --- a/sdk/extensions/serialization/source/NvBlastExtSerialization.cpp +++ b/sdk/extensions/serialization/source/NvBlastExtSerialization.cpp @@ -1,146 +1,401 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + #include "NvBlastExtSerialization.h" -#include "BlastSerialization.h" -#include <memory> -#include "PxPhysicsVersion.h" -#include "PxConvexMeshGeometryDTO.h" -#include "NvBlastExtDefs.h" +#include "NvBlastExtLlSerialization.h" +#include "NvBlastHashMap.h" +#include "NvBlastExtSerializationInternal.h" + + +namespace Nv +{ +namespace Blast +{ + +class ExtSerializationImpl : public ExtSerializationInternal +{ +public: + // Default buffer provider + class AllocBufferProvider : public ExtSerialization::BufferProvider + { + public: + virtual void* requestBuffer(size_t size) override; + }; + + + ExtSerializationImpl(); + ~ExtSerializationImpl(); + + // ExtSerialization interface begin + virtual bool setSerializationEncoding(uint32_t encodingID) override; + virtual uint32_t getSerializationEncoding() const override; + + virtual void setBufferProvider(BufferProvider* bufferProvider) override; + + virtual bool peekHeader(uint32_t* objectTypeID, uint32_t* encodingID, uint64_t* dataSize, const void* buffer, uint64_t bufferSize) override; + virtual const void* skipObject(uint64_t& bufferSize, const void* buffer) override; + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size, uint32_t* objectTypeIDPtr = nullptr) override; + virtual uint64_t serializeIntoBuffer(void*& buffer, const void* object, uint32_t objectTypeID) override; + virtual void release() override; + // ExtSerialization interface end -// This is terrible. -physx::PxPhysics* g_Physics = nullptr; + // ExtSerializationInternal interface begin + virtual bool registerSerializer(ExtSerializer& serializer) override; + virtual bool unregisterSerializer(ExtSerializer& serializer) override; + + virtual ExtSerializer* findSerializer(uint32_t objectTypeID, uint32_t encodingID) override; + // ExtSerializationInternal interface end + +private: + char* writeHeaderIntoBuffer(char* buffer, uint64_t bufferSize, uint32_t objectTypeID, uint32_t encodingID, uint64_t dataSize) const; + const char* readHeaderFromBuffer(uint32_t* objectTypeID, uint32_t* encodingID, uint64_t* dataSize, const char* buffer, uint64_t bufferSize) const; + + //// Static data //// + static const char* s_identifier; + static const char* s_version; + static AllocBufferProvider s_defaultBufferProvider; + + //// Member data //// + HashMap<uint64_t, ExtSerializer*>::type m_serializers; + uint32_t m_serializationEncoding; + BufferProvider* m_bufferProvider; +}; + + +//////// ExtSerializationImpl static member variables //////// + +/** Module identifying header. This should never change. */ +const char* ExtSerializationImpl::s_identifier = "NVidia(r) GameWorks Blast(tm) v."; + +const char* ExtSerializationImpl::s_version = "1"; + +ExtSerializationImpl::AllocBufferProvider ExtSerializationImpl::s_defaultBufferProvider; + + +//////// Local utility functions //////// + +static NV_INLINE uint64_t generateKey(uint32_t objectTypeID, uint32_t encodingID) +{ + return static_cast<uint64_t>(encodingID) << 32 | static_cast<uint64_t>(objectTypeID); +} -std::shared_ptr<physx::PxCooking> getCooking() +static NV_INLINE uint64_t generateKey(const ExtSerializer& serializer) { - physx::PxCookingParams cookingParams(g_Physics->getTolerancesScale()); - cookingParams.buildGPUData = true; + return generateKey(serializer.getObjectTypeID(), serializer.getEncodingID()); +} + - std::shared_ptr<physx::PxCooking> m_Cooking = std::shared_ptr<physx::PxCooking>(PxCreateCooking(PX_PHYSICS_VERSION, g_Physics->getFoundation(), cookingParams), [=](physx::PxCooking* cooking) +static NV_INLINE void writeIDToBuffer(char* buffer, uint32_t id) +{ + for (int i = 0; i < 4; ++i, id >>= 8) { - cooking->release(); - }); + *buffer++ = static_cast<char>(id & 0xFF); + } +} - NVBLASTEXT_CHECK_ERROR(m_Cooking, "Error: failed to create PhysX Cooking\n", return nullptr); - return m_Cooking; +static NV_INLINE uint32_t readIDFromBuffer(const char* buffer) +{ + return NVBLAST_FOURCC(buffer[0], buffer[1], buffer[2], buffer[3]); } -extern "C" +static NV_INLINE void writeU64InHexToBuffer(char* buffer, uint64_t val) { - NVBLAST_API void setPhysXSDK(physx::PxPhysics* physXSDK) + for (char* curr = buffer + 16; curr-- > buffer; val >>= 4) { - g_Physics = physXSDK; + *curr = "0123456789ABCDEF"[val & 0xF]; } +} + - NVBLAST_API NvBlastAsset* deserializeAsset(const unsigned char* input, uint32_t size) +static NV_INLINE uint64_t readU64InHexFromBuffer(const char* buffer) +{ + uint64_t val = 0; + for (const char* curr = buffer; curr < buffer + 16; ++curr) { - return Nv::Blast::BlastSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::deserialize(input, size); + const char c = *curr; + const char msn = c >> 4; + const char mask = ((88 >> msn) & 1) - 1; + const unsigned char digit = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xA\xB\xC\xD\xE\xF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"[((msn - 3) & 1) << 4 | (c & 0xF)] | mask; + if (digit == 0xFF) + { + return 0; // Not a hexidecimal digit + } + val = val << 4 | digit; } + return val; +} + + +//////// ExtSerialization member functions //////// + +ExtSerializationImpl::ExtSerializationImpl() : m_serializationEncoding(EncodingID::CapnProtoBinary), m_bufferProvider(&s_defaultBufferProvider) +{ +} - NVBLAST_API NvBlastAsset* deserializeAssetFromStream(std::istream &inputStream) + +ExtSerializationImpl::~ExtSerializationImpl() +{ + // Release and remove all registered serializers + auto it = m_serializers.getEraseIterator(); + while (auto entry = it.eraseCurrentGetNext(true)) { - return Nv::Blast::BlastSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::deserializeFromStream(inputStream); + entry->second->release(); } - - NVBLAST_API bool serializeAssetIntoStream(const NvBlastAsset *asset, std::ostream &outputStream) +} + + +char* ExtSerializationImpl::writeHeaderIntoBuffer(char* buffer, uint64_t bufferSize, uint32_t objectTypeID, uint32_t encodingID, uint64_t dataSize) const +{ + if (bufferSize < HeaderSize) { - return Nv::Blast::BlastSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::Asset *>(asset), outputStream); + return nullptr; } - NVBLAST_API bool serializeAssetIntoNewBuffer(const NvBlastAsset *asset, unsigned char **outBuffer, uint32_t &outSize) + char* stop = buffer + HeaderSize; + + size_t versionLen = strlen(s_version); + if (versionLen > 63) { - return Nv::Blast::BlastSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::Asset *>(asset), outBuffer, outSize); + versionLen = 63; } - NVBLAST_API bool serializeAssetIntoExistingBuffer(const NvBlastAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) + memset(buffer, ' ', HeaderSize); + memcpy(buffer, s_identifier, 32); buffer += 32; + memcpy(buffer, s_version, versionLen); buffer += 64; + writeIDToBuffer(buffer, objectTypeID); buffer += 5; + writeIDToBuffer(buffer, encodingID); buffer += 5; + writeU64InHexToBuffer(buffer, dataSize); buffer += 16; + *(stop - 1) = '\n'; + + return stop; +} + + +const char* ExtSerializationImpl::readHeaderFromBuffer(uint32_t* objectTypeID, uint32_t* encodingID, uint64_t* dataSize, const char* buffer, uint64_t bufferSize) const +{ + if (bufferSize < HeaderSize) { - return Nv::Blast::BlastSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::Asset *>(asset), buffer, maxSize, usedSize); + NVBLAST_LOG_ERROR("ExtSerializationImpl::readHeaderFromBuffer: header terminator not found."); + return nullptr; } - ////////////////////////////////////////////////////////////////////////// - // TkAsset - ////////////////////////////////////////////////////////////////////////// + const char* stop = buffer + HeaderSize; - NVBLAST_API Nv::Blast::TkAsset* deserializeTkAsset(const unsigned char* input, uint32_t size) + if (memcmp(buffer, s_identifier, 32)) { - return Nv::Blast::BlastSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::deserialize(input, size); + NVBLAST_LOG_ERROR("ExtSerializationImpl::readHeaderFromBuffer: file identifier does not match expected value."); + return nullptr; } + buffer += 32; - NVBLAST_API Nv::Blast::TkAsset* deserializeTkAssetFromStream(std::istream &inputStream) + const char* s = strchr(buffer, ' '); + if (s == nullptr) + { + NVBLAST_LOG_ERROR("ExtSerializationImpl::readHeaderFromBuffer: file format error reading serializer library version."); + } + if (memcmp(buffer, s_version, s - buffer)) { - return Nv::Blast::BlastSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::deserializeFromStream(inputStream); + NVBLAST_LOG_ERROR("ExtSerializationImpl::readHeaderFromBuffer: file version does not match serializer library version."); + return nullptr; } + buffer += 64; - NVBLAST_API bool serializeTkAssetIntoStream(const Nv::Blast::TkAsset *asset, std::ostream &outputStream) + if (objectTypeID != nullptr) { - return Nv::Blast::BlastSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), outputStream); + *objectTypeID = readIDFromBuffer(buffer); } + buffer += 5; - NVBLAST_API bool serializeTkAssetIntoNewBuffer(const Nv::Blast::TkAsset *asset, unsigned char **outBuffer, uint32_t &outSize) + if (encodingID != nullptr) { - return Nv::Blast::BlastSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), outBuffer, outSize); + *encodingID = readIDFromBuffer(buffer); } + buffer += 5; - NVBLAST_API bool serializeTkAssetIntoExistingBuffer(const Nv::Blast::TkAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) + if (dataSize != nullptr) { - return Nv::Blast::BlastSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), buffer, maxSize, usedSize); + *dataSize = readU64InHexFromBuffer(buffer); } + buffer += 16; - ////////////////////////////////////////////////////////////////////////// - // ExtPxAsset - ////////////////////////////////////////////////////////////////////////// + return stop; +} - NVBLAST_API Nv::Blast::ExtPxAsset* deserializeExtPxAsset(const unsigned char* input, uint32_t size) - { - NVBLAST_ASSERT(g_Physics != nullptr); - return Nv::Blast::BlastSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::deserialize(input, size); - } +bool ExtSerializationImpl::registerSerializer(ExtSerializer& serializer) +{ + return m_serializers.insert(generateKey(serializer), &serializer); +} - NVBLAST_API Nv::Blast::ExtPxAsset* deserializeExtPxAssetFromStream(std::istream &inputStream) - { - NVBLAST_ASSERT(g_Physics != nullptr); - return Nv::Blast::BlastSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::deserializeFromStream(inputStream); +bool ExtSerializationImpl::unregisterSerializer(ExtSerializer& serializer) +{ + const uint64_t key = generateKey(serializer); + const auto entry = m_serializers.find(key); + if (entry == nullptr) + { + return false; } + entry->second->release(); + return m_serializers.erase(key); +} + - NVBLAST_API bool serializeExtPxAssetIntoStream(const Nv::Blast::ExtPxAsset *asset, std::ostream &outputStream) +ExtSerializer* ExtSerializationImpl::findSerializer(uint32_t objectTypeID, uint32_t encodingID) +{ + auto entry = m_serializers.find(generateKey(objectTypeID, encodingID)); + return entry != nullptr ? entry->second : nullptr; +} + + +bool ExtSerializationImpl::setSerializationEncoding(uint32_t encodingID) +{ + m_serializationEncoding = encodingID; + + return true; +} + + +uint32_t ExtSerializationImpl::getSerializationEncoding() const +{ + return m_serializationEncoding; +} + + +void ExtSerializationImpl::setBufferProvider(BufferProvider* bufferProvider) +{ + m_bufferProvider = bufferProvider != nullptr ? bufferProvider : &s_defaultBufferProvider; +} + + +bool ExtSerializationImpl::peekHeader(uint32_t* objectTypeID, uint32_t* encodingID, uint64_t* dataSize, const void* buffer, uint64_t bufferSize) +{ + return nullptr != readHeaderFromBuffer(objectTypeID, encodingID, dataSize, reinterpret_cast<const char*>(buffer), bufferSize); +} + + +const void* ExtSerializationImpl::skipObject(uint64_t& bufferSize, const void* buffer) +{ + uint64_t dataSize; + const char* next = readHeaderFromBuffer(nullptr, nullptr, &dataSize, static_cast<const char*>(buffer), bufferSize); + if (next == nullptr) { - NVBLAST_ASSERT(g_Physics != nullptr); + return nullptr; + } + next += dataSize; + const uint64_t skipSize = next - static_cast<const char*>(buffer); + NVBLAST_CHECK_ERROR(skipSize <= bufferSize, "Object size in buffer is too large for given buffer size.", return nullptr); + bufferSize -= skipSize; + return next; +} - auto cooking = getCooking(); - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; +void* ExtSerializationImpl::deserializeFromBuffer(const void* buffer, uint64_t bufferSize, uint32_t* objectTypeIDPtr) +{ + uint32_t objectTypeID; + uint32_t encodingID; + uint64_t dataSize; + void* result = nullptr; - return Nv::Blast::BlastSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), outputStream); + buffer = readHeaderFromBuffer(&objectTypeID, &encodingID, &dataSize, reinterpret_cast<const char*>(buffer), bufferSize); + if (buffer != nullptr) + { + auto entry = m_serializers.find(generateKey(objectTypeID, encodingID)); + if (entry != nullptr && entry->second != nullptr) + { + result = entry->second->deserializeFromBuffer(buffer, dataSize); + } } - NVBLAST_API bool serializeExtPxAssetIntoNewBuffer(const Nv::Blast::ExtPxAsset *asset, unsigned char **outBuffer, uint32_t &outSize) + if (objectTypeIDPtr != nullptr) { - NVBLAST_ASSERT(g_Physics != nullptr); + *objectTypeIDPtr = result != nullptr ? objectTypeID : 0; + } - auto cooking = getCooking(); + return result; +} - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; - return Nv::Blast::BlastSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), outBuffer, outSize); +uint64_t ExtSerializationImpl::serializeIntoBuffer(void*& buffer, const void* object, uint32_t objectTypeID) +{ + if (!m_serializationEncoding) + { + NVBLAST_LOG_ERROR("ExtSerializationImpl::serializeIntoBuffer: no serialization encoding has been set."); + return false; // No encoding available + } + + auto entry = m_serializers.find(generateKey(objectTypeID, m_serializationEncoding)); + if (entry == nullptr || entry->second == nullptr) + { + return false; } - NVBLAST_API bool serializeExtPxAssetIntoExistingBuffer(const Nv::Blast::ExtPxAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) + const uint64_t size = entry->second->serializeIntoBuffer(buffer, *m_bufferProvider, object, HeaderSize); + if (size < HeaderSize) { - NVBLAST_ASSERT(g_Physics != nullptr); + NVBLAST_LOG_ERROR("ExtSerializationImpl::serializeIntoBuffer: failed to write data to buffer."); + return 0; + } + + writeHeaderIntoBuffer(reinterpret_cast<char*>(buffer), HeaderSize, objectTypeID, m_serializationEncoding, size - HeaderSize); - auto cooking = getCooking(); + return size; +} - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; - return Nv::Blast::BlastSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), buffer, maxSize, usedSize); - } +void ExtSerializationImpl::release() +{ + NVBLAST_DELETE(this, ExtSerializationImpl); +} + +//////// ExtSerializationImpl::AllocBufferProvider member functions //////// +void* ExtSerializationImpl::AllocBufferProvider::requestBuffer(size_t size) +{ + return NVBLAST_ALLOC(size); } +} // namespace Blast +} // namespace Nv + + +Nv::Blast::ExtSerialization* NvBlastExtSerializationCreate() +{ + Nv::Blast::ExtSerializationImpl* serialization = NVBLAST_NEW(Nv::Blast::ExtSerializationImpl) (); + + // Automatically load LL serializers + NvBlastExtLlSerializerLoadSet(*serialization); + + return serialization; +} diff --git a/sdk/extensions/serialization/source/NvBlastExtSerialization.h b/sdk/extensions/serialization/source/NvBlastExtSerialization.h deleted file mode 100644 index 5d44554..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerialization.h +++ /dev/null @@ -1,172 +0,0 @@ -/* -* Copyright (c) 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. -*/ - -#pragma once -#include "kj/io.h" -#include "capnp/serialize.h" -#include "generated/NvBlastExtSerializationLL.capn.h" -#include <vector> -#include "NvBlastExtInputStream.h" -#include "NvBlastExtOutputStream.h" - -#if !defined(BLAST_LL_ALLOC) -#include "NvBlastExtAllocator.h" -#endif -#include "NvBlastExtGlobals.h" - -namespace Nv -{ - namespace Blast - { - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - class ExtSerialization - { - public: - static TAsset* deserialize(const unsigned char* input, uint32_t size); - static TAsset* deserializeFromStream(std::istream &inputStream); - - static bool serializeIntoExistingBuffer(const TAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize); - static bool serializeIntoNewBuffer(const TAsset *asset, unsigned char **outBuffer, uint32_t &outSize); - static bool serializeIntoStream(const TAsset *asset, std::ostream &outputStream); - - private: - - static void serializeMessageIntoNewBuffer(capnp::MallocMessageBuilder& message, unsigned char ** outBuffer, uint32_t &outSize); - - // Specialized - static bool serializeIntoBuilder(TSerializationBuilder& assetBuilder, const TAsset* asset); - static bool serializeIntoMessage(capnp::MallocMessageBuilder& message, const TAsset* asset); - static TAsset* deserializeFromStreamReader(capnp::InputStreamMessageReader &message); - }; - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - TAsset* ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::deserialize(const unsigned char* input, uint32_t size) - { - kj::ArrayPtr<const unsigned char> source(input, size); - - kj::ArrayInputStream inputStream(source); - - std::vector<uint64_t> scratch; - scratch.resize(size); - kj::ArrayPtr<capnp::word> scratchArray((capnp::word*) scratch.data(), size); - - capnp::InputStreamMessageReader message(inputStream, capnp::ReaderOptions(), scratchArray); - - return deserializeFromStreamReader(message); - } - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - TAsset* ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::deserializeFromStream(std::istream &inputStream) - { - Nv::Blast::ExtInputStream readStream(inputStream); - - capnp::InputStreamMessageReader message(readStream); - - return deserializeFromStreamReader(message); - } - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - bool ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::serializeIntoExistingBuffer(const TAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) - { - capnp::MallocMessageBuilder message; - - bool result = serializeIntoMessage(message, asset); - - if (result == false) - { - usedSize = 0; - return false; - } - - uint32_t messageSize = computeSerializedSizeInWords(message) * sizeof(uint64_t); - - if (maxSize < messageSize) - { - NvBlastLog logFn = gLog; - -#if !defined(BLAST_LL_ALLOC) - logFn = NvBlastTkFrameworkGet()->getLogFn(); -#endif - - NVBLAST_LOG_ERROR(logFn, "When attempting to serialize into an existing buffer, the provided buffer was too small."); - usedSize = 0; - return false; - } - - kj::ArrayPtr<unsigned char> outputBuffer(buffer, maxSize); - kj::ArrayOutputStream outputStream(outputBuffer); - - capnp::writeMessage(outputStream, message); - - usedSize = messageSize;; - return true; - } - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - bool ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::serializeIntoNewBuffer(const TAsset *asset, unsigned char **outBuffer, uint32_t &outSize) - { - capnp::MallocMessageBuilder message; - - bool result = serializeIntoMessage(message, asset); - - if (result == false) - { - *outBuffer = nullptr; - outSize = 0; - return false; - } - - serializeMessageIntoNewBuffer(message, outBuffer, outSize); - - return true; - } - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - bool ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::serializeIntoStream(const TAsset *asset, std::ostream &outputStream) - { - capnp::MallocMessageBuilder message; - - bool result = serializeIntoMessage(message, asset); - - if (result == false) - { - return false; - } - - Nv::Blast::ExtOutputStream blastOutputStream(outputStream); - - writeMessage(blastOutputStream, message); - - return true; - } - - template<typename TAsset, typename TSerializationReader, typename TSerializationBuilder> - void ExtSerialization<TAsset, TSerializationReader, TSerializationBuilder>::serializeMessageIntoNewBuffer(capnp::MallocMessageBuilder& message, unsigned char ** outBuffer, uint32_t &outSize) - { - uint32_t messageSize = computeSerializedSizeInWords(message) * sizeof(uint64_t); - - NvBlastExtAlloc allocFn = gAlloc; - -#if !defined(BLAST_LL_ALLOC) - allocFn = ExtAllocator::alignedAlloc16; -#endif - - unsigned char* buffer = static_cast<unsigned char *>(allocFn(messageSize)); - - kj::ArrayPtr<unsigned char> outputBuffer(buffer, messageSize); - kj::ArrayOutputStream outputStream(outputBuffer); - - capnp::writeMessage(outputStream, message); - - *outBuffer = buffer; - outSize = messageSize; - } - } -} diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationCAPN.h b/sdk/extensions/serialization/source/NvBlastExtSerializationCAPN.h new file mode 100644 index 0000000..fe261e6 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtSerializationCAPN.h @@ -0,0 +1,188 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + +#include "capnp/serialize.h" +#include "NvBlastExtInputStream.h" +#include "NvBlastExtOutputStream.h" +#include "NvBlastArray.h" +#include "NvBlastExtSerialization.h" + + +namespace Nv +{ +namespace Blast +{ + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +class ExtSerializationCAPN +{ +public: + static TObject* deserializeFromBuffer(const unsigned char* input, uint64_t size); + static TObject* deserializeFromStream(std::istream& inputStream); + + static uint64_t serializationBufferSize(const TObject* object); + + static bool serializeIntoBuffer(const TObject* object, unsigned char* buffer, uint64_t maxSize, uint64_t& usedSize); + static bool serializeIntoBuffer(const TObject *object, unsigned char*& buffer, uint64_t& size, ExtSerialization::BufferProvider* bufferProvider = nullptr, uint64_t offset = 0); + static bool serializeIntoStream(const TObject* object, std::ostream& outputStream); + +private: + // Specialized + static bool serializeIntoBuilder(TSerializationBuilder& objectBuilder, const TObject* object); + static bool serializeIntoMessage(capnp::MallocMessageBuilder& message, const TObject* object); + static TObject* deserializeFromStreamReader(capnp::InputStreamMessageReader& message); +}; + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +TObject* ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::deserializeFromBuffer(const unsigned char* input, uint64_t size) +{ + kj::ArrayPtr<const unsigned char> source(input, size); + + kj::ArrayInputStream inputStream(source); + + Nv::Blast::Array<uint64_t>::type scratch(static_cast<uint32_t>(size)); + kj::ArrayPtr<capnp::word> scratchArray((capnp::word*) scratch.begin(), size); + + capnp::InputStreamMessageReader message(inputStream, capnp::ReaderOptions(), scratchArray); + + return deserializeFromStreamReader(message); +} + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +TObject* ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::deserializeFromStream(std::istream& inputStream) +{ + ExtInputStream readStream(inputStream); + + capnp::InputStreamMessageReader message(readStream); + + return deserializeFromStreamReader(message); +} + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +uint64_t ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::serializationBufferSize(const TObject* object) +{ + capnp::MallocMessageBuilder message; + + bool result = serializeIntoMessage(message, object); + + if (result == false) + { + return 0; + } + + return computeSerializedSizeInWords(message) * sizeof(uint64_t); +} + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +bool ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::serializeIntoBuffer(const TObject* object, unsigned char* buffer, uint64_t maxSize, uint64_t& usedSize) +{ + capnp::MallocMessageBuilder message; + + bool result = serializeIntoMessage(message, object); + + if (result == false) + { + usedSize = 0; + return false; + } + + uint64_t messageSize = computeSerializedSizeInWords(message) * sizeof(uint64_t); + + if (maxSize < messageSize) + { + NVBLAST_LOG_ERROR("When attempting to serialize into an existing buffer, the provided buffer was too small."); + usedSize = 0; + return false; + } + + kj::ArrayPtr<unsigned char> outputBuffer(buffer, maxSize); + kj::ArrayOutputStream outputStream(outputBuffer); + + capnp::writeMessage(outputStream, message); + + usedSize = messageSize; + return true; +} + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +bool ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::serializeIntoBuffer(const TObject *object, unsigned char*& buffer, uint64_t& size, ExtSerialization::BufferProvider* bufferProvider, uint64_t offset) +{ + capnp::MallocMessageBuilder message; + + bool result = serializeIntoMessage(message, object); + + if (result == false) + { + buffer = nullptr; + size = 0; + return false; + } + + const uint64_t blockSize = computeSerializedSizeInWords(message) * sizeof(uint64_t); + + size = blockSize + offset; + + buffer = static_cast<unsigned char *>(bufferProvider != nullptr ? bufferProvider->requestBuffer(size) : NVBLAST_ALLOC(size)); + + kj::ArrayPtr<unsigned char> outputBuffer(buffer + offset, blockSize); + kj::ArrayOutputStream outputStream(outputBuffer); + + capnp::writeMessage(outputStream, message); + + return true; +} + + +template<typename TObject, typename TSerializationReader, typename TSerializationBuilder> +bool ExtSerializationCAPN<TObject, TSerializationReader, TSerializationBuilder>::serializeIntoStream(const TObject* object, std::ostream& outputStream) +{ + capnp::MallocMessageBuilder message; + + bool result = serializeIntoMessage(message, object); + + if (result == false) + { + return false; + } + + ExtOutputStream blastOutputStream(outputStream); + + writeMessage(blastOutputStream, message); + + return true; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationImpl.h b/sdk/extensions/serialization/source/NvBlastExtSerializationImpl.h deleted file mode 100644 index 7f9fbc9..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerializationImpl.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright (c) 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. -*/ - -#pragma once - -#include "NvBlastExtSerialization.h" -#include "NvBlastTkAsset.h" -#include "NvBlastExtPxAsset.h" -#include "TkAssetDTO.h" -#include "ExtPxAssetDTO.h" - -namespace Nv -{ - namespace Blast - { - /* - Specializations here - one set for each top level asset. (TkAsset, ExtPxAsset) - */ - - - // TkAsset - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoBuilder(Nv::Blast::Serialization::TkAsset::Builder& assetBuilder, const Nv::Blast::TkAsset* asset) - { - return TkAssetDTO::serialize(assetBuilder, asset); - } - - template<> - NV_INLINE Nv::Blast::TkAsset* ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) - { - Nv::Blast::Serialization::TkAsset::Reader reader = message.getRoot<Nv::Blast::Serialization::TkAsset>(); - - return TkAssetDTO::deserialize(reader); - } - - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const Nv::Blast::TkAsset* asset) - { - Nv::Blast::Serialization::TkAsset::Builder assetBuilder = message.initRoot<Nv::Blast::Serialization::TkAsset>(); - - return serializeIntoBuilder(assetBuilder, asset); - } - - - //ExtPxAsset - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoBuilder(Nv::Blast::Serialization::ExtPxAsset::Builder& assetBuilder, const Nv::Blast::ExtPxAsset* asset) - { - return ExtPxAssetDTO::serialize(assetBuilder, asset); - } - - template<> - NV_INLINE Nv::Blast::ExtPxAsset* ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) - { - Nv::Blast::Serialization::ExtPxAsset::Reader reader = message.getRoot<Nv::Blast::Serialization::ExtPxAsset>(); - - return ExtPxAssetDTO::deserialize(reader); - } - - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const Nv::Blast::ExtPxAsset* asset) - { - Nv::Blast::Serialization::ExtPxAsset::Builder assetBuilder = message.initRoot<Nv::Blast::Serialization::ExtPxAsset>(); - - return serializeIntoBuilder(assetBuilder, asset); - } - } -} diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationInterface.cpp b/sdk/extensions/serialization/source/NvBlastExtSerializationInterface.cpp deleted file mode 100644 index bebee5b..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerializationInterface.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -* Copyright (c) 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 "NvBlastExtSerializationImpl.h" -#include <memory> -#include "PxPhysicsVersion.h" -#include "PxConvexMeshGeometryDTO.h" -#include "NvBlastExtDefs.h" -#include "PxPhysics.h" -#include "NvBlastAssert.h" - - -// This is terrible. -physx::PxPhysics* g_Physics = nullptr; - -using namespace Nv::Blast; - -std::shared_ptr<physx::PxCooking> getCooking() -{ - physx::PxCookingParams cookingParams(g_Physics->getTolerancesScale()); - cookingParams.buildGPUData = true; - - std::shared_ptr<physx::PxCooking> m_Cooking = std::shared_ptr<physx::PxCooking>(PxCreateCooking(PX_PHYSICS_VERSION, g_Physics->getFoundation(), cookingParams), [=](physx::PxCooking* cooking) - { - cooking->release(); - }); - - NVBLASTEXT_CHECK_ERROR(m_Cooking, "Error: failed to create PhysX Cooking\n", return nullptr); - - return m_Cooking; -} - - -extern "C" -{ - NVBLAST_API void setPhysXSDK(physx::PxPhysics* physXSDK) - { - g_Physics = physXSDK; - } - - ////////////////////////////////////////////////////////////////////////// - // TkAsset - ////////////////////////////////////////////////////////////////////////// - - NVBLAST_API Nv::Blast::TkAsset* deserializeTkAsset(const unsigned char* input, uint32_t size) - { - return Nv::Blast::ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::deserialize(input, size); - } - - NVBLAST_API Nv::Blast::TkAsset* deserializeTkAssetFromStream(std::istream &inputStream) - { - return Nv::Blast::ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::deserializeFromStream(inputStream); - } - - NVBLAST_API bool serializeTkAssetIntoStream(const Nv::Blast::TkAsset *asset, std::ostream &outputStream) - { - return Nv::Blast::ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), outputStream); - } - - NVBLAST_API bool serializeTkAssetIntoNewBuffer(const Nv::Blast::TkAsset *asset, unsigned char **outBuffer, uint32_t &outSize) - { - return Nv::Blast::ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), outBuffer, outSize); - } - - NVBLAST_API bool serializeTkAssetIntoExistingBuffer(const Nv::Blast::TkAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) - { - return Nv::Blast::ExtSerialization<Nv::Blast::TkAsset, Nv::Blast::Serialization::TkAsset::Reader, Nv::Blast::Serialization::TkAsset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::TkAsset *>(asset), buffer, maxSize, usedSize); - } - - ////////////////////////////////////////////////////////////////////////// - // ExtPxAsset - ////////////////////////////////////////////////////////////////////////// - - NVBLAST_API Nv::Blast::ExtPxAsset* deserializeExtPxAsset(const unsigned char* input, uint32_t size) - { - NVBLAST_ASSERT(g_Physics != nullptr); - - return Nv::Blast::ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::deserialize(input, size); - } - - NVBLAST_API Nv::Blast::ExtPxAsset* deserializeExtPxAssetFromStream(std::istream &inputStream) - { - NVBLAST_ASSERT(g_Physics != nullptr); - - return Nv::Blast::ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::deserializeFromStream(inputStream); - } - - NVBLAST_API bool serializeExtPxAssetIntoStream(const Nv::Blast::ExtPxAsset *asset, std::ostream &outputStream) - { - NVBLAST_ASSERT(g_Physics != nullptr); - - auto cooking = getCooking(); - - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; - - return Nv::Blast::ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), outputStream); - } - - NVBLAST_API bool serializeExtPxAssetIntoNewBuffer(const Nv::Blast::ExtPxAsset *asset, unsigned char **outBuffer, uint32_t &outSize) - { - NVBLAST_ASSERT(g_Physics != nullptr); - - auto cooking = getCooking(); - - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; - - return Nv::Blast::ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), outBuffer, outSize); - } - - NVBLAST_API bool serializeExtPxAssetIntoExistingBuffer(const Nv::Blast::ExtPxAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) - { - NVBLAST_ASSERT(g_Physics != nullptr); - - auto cooking = getCooking(); - - PxConvexMeshGeometryDTO::Cooking = cooking.get(); - PxConvexMeshGeometryDTO::Physics = g_Physics; - - return Nv::Blast::ExtSerialization<Nv::Blast::ExtPxAsset, Nv::Blast::Serialization::ExtPxAsset::Reader, Nv::Blast::Serialization::ExtPxAsset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::ExtPxAsset *>(asset), buffer, maxSize, usedSize); - } - - -} - diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationInternal.h b/sdk/extensions/serialization/source/NvBlastExtSerializationInternal.h new file mode 100644 index 0000000..117280a --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtSerializationInternal.h @@ -0,0 +1,291 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + +#include "NvBlastExtSerialization.h" + +#include <cstring> + +#define ExtSerializerBoilerplate(_name, _description, _objectTypeID, _encodingID) \ +virtual const char* getName() const override { return _name; } \ +virtual const char* getDescription() const override { return _description; } \ +virtual uint32_t getObjectTypeID() const override { return _objectTypeID; } \ +virtual uint32_t getEncodingID() const override { return _encodingID; } + + +#define ExtSerializerReadOnly(_name) \ +virtual bool isReadOnly() const override { return true; } \ +virtual uint64_t serializeIntoBuffer \ +( \ + void*& buffer, \ + ExtSerialization::BufferProvider& bufferProvider, \ + const void* object, \ + uint64_t offset = 0 \ +) override \ +{ \ + NVBLAST_LOG_WARNING(#_name "::serializeIntoBuffer: ExtPxAsset_RAW serializer is read-only."); \ + NV_UNUSED(buffer); \ + NV_UNUSED(bufferProvider); \ + NV_UNUSED(object); \ + NV_UNUSED(offset); \ + return 0; \ +} + + +#define ExtSerializerDefaultFactoryAndRelease(_classname) \ +static ExtSerializer* create() \ +{ \ + return NVBLAST_NEW(_classname) (); \ +} \ +virtual void release() override \ +{ \ + NVBLAST_DELETE(this, _classname); \ +} + + +namespace Nv +{ +namespace Blast +{ + +/** +Serializer internal interface +*/ +class ExtSerializer +{ +public: + virtual ~ExtSerializer() {} + + /** + return the name of this serializer. + */ + virtual const char* getName() const = 0; + + /** + return a description of this serializer. + */ + virtual const char* getDescription() const = 0; + + /** + return an identifier for the type of object handled. + */ + virtual uint32_t getObjectTypeID() const = 0; + + /** + return an identifier for serialization format. + */ + virtual uint32_t getEncodingID() const = 0; + + /** + Whether or not this serializer supports writing. Legacy formats, for example, may not. + + \return true iff this serialization does not support writing. + */ + virtual bool isReadOnly() const { return false; } + + /** + Deserialize from a buffer into a newly allocated object. + + \param[in] buffer Pointer to the buffer to read. + \param[in] size Size of the buffer to read. + \return object pointer; returns null if failed to deserialize. + */ + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) = 0; + + /** + Serialize into a buffer. Allocates the buffer internally using the ExtSerialization::BufferProvider callack interface. + + \param[out] buffer Pointer to the buffer created. + \param[in] bufferProvider The buffer provider callback interface to use. + \param[in] object Object pointer. + + \return the number of bytes serialized into the buffer (zero if unsuccessful). + */ + virtual uint64_t serializeIntoBuffer(void*& buffer, ExtSerialization::BufferProvider& bufferProvider, const void* object, uint64_t offset = 0) = 0; + + /** + Release the serializer and free associated memory. + */ + virtual void release() = 0; +}; + + +/** +Internal serialization manager interface +*/ +class ExtSerializationInternal : public ExtSerialization +{ +public: + /** + Internal interfaces to register and unregister a serializer, used by modules to automatically + register all of their serializers with a serialization manager. + */ + virtual bool registerSerializer(ExtSerializer& serializer) = 0; + virtual bool unregisterSerializer(ExtSerializer& serializer) = 0; + + /** + Find a registered serializer for the given object type and encoding. + + \param[in] objectTypeID ID for the requested object type. + \param[in] encodingID ID for the requested encoding (see EncodingID). + + \return a registered serializer if found, NULL otherwise. + */ + virtual ExtSerializer* findSerializer(uint32_t objectTypeID, uint32_t encodingID) = 0; + + //// Enums //// + enum { HeaderSize = 128 }; +}; + + +template<typename Factory, size_t N> +size_t ExtSerializationLoadSet(Nv::Blast::ExtSerializationInternal& serialization, Factory(&factories)[N]) +{ + size_t count = 0; + + for (auto f : factories) + { + Nv::Blast::ExtSerializer* serializer = f(); + if (serializer != nullptr) + { + if (serialization.registerSerializer(*serializer)) + { + ++count; + } + else + { + NVBLAST_LOG_ERROR("Nv::Blast::ExtSerializationLoadSet: failed to register serailizer:"); + NVBLAST_LOG_ERROR(serializer->getName()); + serializer->release(); + } + } + else + { + NVBLAST_LOG_ERROR("Nv::Blast::ExtSerializationLoadSet: failed to create serailizer."); + } + } + + return count; +} + + +class ExtIStream +{ +public: + enum Flags + { + LittleEndian = (1 << 0), + Fail = (1 << 1) + }; + + ExtIStream(const void* buffer, size_t size) : m_buf(reinterpret_cast<const char*>(buffer)), m_flags(0) + { + m_cur = m_buf; + m_end = m_buf + size; + const uint16_t x = LittleEndian; + m_flags = *reinterpret_cast<const char*>(&x); + } + + bool advance(ptrdiff_t diff) + { + m_cur += diff; + if (m_cur < m_buf) + { + m_cur = m_buf; + m_flags |= Fail; + return false; + } + else + if (m_cur > m_end) + { + m_cur = m_end; + m_flags |= Fail; + return false; + } + return true; + } + + const void* view() + { + return m_cur; + } + + bool read(void* buffer, size_t size) + { + if (!canRead(size)) return false; + std::memcpy(buffer, m_cur, size); + m_cur += size; + return true; + } + + size_t tellg() const { return m_cur - m_buf; } + size_t left() const { return m_end - m_cur; } + + bool eof() const { return m_cur >= m_end; } + bool fail() const { return (m_flags & Fail) != 0; } + +private: + const char* m_buf; + const char* m_cur; + const char* m_end; + uint32_t m_flags; + + bool isLittleEndian() const { return (m_flags & LittleEndian) != 0; } + + bool canRead(size_t size) const { return m_cur + size <= m_end; } + + template<typename T> + friend ExtIStream& operator >> (ExtIStream& s, T& x); +}; + +template<typename T> +NV_INLINE ExtIStream& operator >> (ExtIStream& s, T& x) +{ + if (s.canRead(sizeof(T))) + { + if (s.isLittleEndian()) + { + x = *reinterpret_cast<const T*>(s.m_cur); + s.m_cur += sizeof(T); + } + else + { + char* b = reinterpret_cast<char*>(&x) + sizeof(T); + for (size_t n = sizeof(T); n--;) *--b = *s.m_cur++; + } + } + else + { + s.m_flags |= ExtIStream::Fail; + } + return s; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationLL.capn b/sdk/extensions/serialization/source/NvBlastExtSerializationLL.capn deleted file mode 100644 index 026056f..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerializationLL.capn +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright (c) 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. - -@0x9a4a58fac38375e0; - -using Cxx = import "/capnp/c++.capnp"; - -$Cxx.namespace("Nv::Blast::Serialization"); - -struct Asset -{ - header @0 :NvBlastDataBlock; - - iD @1 :UUID; - - chunkCount @2 :UInt32; - - graph @3 :NvBlastSupportGraph; - - leafChunkCount @4 :UInt32; - - firstSubsupportChunkIndex @5 :UInt32; - - bondCount @6 :UInt32; - - chunks @7: List(NvBlastChunk); - - bonds @8: List(NvBlastBond); - - subtreeLeafChunkCounts @9: List(UInt32); - - chunkToGraphNodeMap @10: List(UInt32); -} - -struct NvBlastDataBlock -{ - enum Type - { - assetDataBlock @0; - instanceDataBlock @1; - } - - dataType @0 :Type; - - formatVersion @1 :UInt32; - - size @2 :UInt32; -} - -struct NvBlastChunk -{ - centroid @0 :List(Float32); - - volume @1 :Float32; - - parentChunkIndex @2 :UInt32; - firstChildIndex @3 :UInt32; - childIndexStop @4 :UInt32; - userData @5 :UInt32; -} - -struct NvBlastBond -{ - normal @0 :List(Float32); - area @1 :Float32; - centroid @2 :List(Float32); - userData @3 :UInt32; -} - -struct NvBlastSupportGraph -{ - nodeCount @0 : UInt32; - - chunkIndices @1 : List(UInt32); - adjacencyPartition @2 : List(UInt32); - adjacentNodeIndices @3 : List(UInt32); - adjacentBondIndices @4 : List(UInt32); -} - -struct UUID -{ - value @0 : Data; -} - diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationLLImpl.h b/sdk/extensions/serialization/source/NvBlastExtSerializationLLImpl.h deleted file mode 100644 index d7595ba..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerializationLLImpl.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Copyright (c) 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. -*/ - -#pragma once - -#include "NvBlastExtSerialization.h" -#include "NvBlastAsset.h" -#include "AssetDTO.h" - -namespace Nv -{ - namespace Blast - { - /* - Specializations here - LL asset only - */ - - // Asset - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoBuilder(Nv::Blast::Serialization::Asset::Builder& assetBuilder, const Nv::Blast::Asset* asset) - { - return AssetDTO::serialize(assetBuilder, asset); - } - - template<> - NV_INLINE Nv::Blast::Asset* ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) - { - Nv::Blast::Serialization::Asset::Reader reader = message.getRoot<Nv::Blast::Serialization::Asset>(); - - return AssetDTO::deserialize(reader); - } - - template<> - NV_INLINE bool ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const Nv::Blast::Asset* asset) - { - Nv::Blast::Serialization::Asset::Builder assetBuilder = message.initRoot<Nv::Blast::Serialization::Asset>(); - - return serializeIntoBuilder(assetBuilder, asset); - } - } -} diff --git a/sdk/extensions/serialization/source/NvBlastExtSerializationLLInterface.cpp b/sdk/extensions/serialization/source/NvBlastExtSerializationLLInterface.cpp deleted file mode 100644 index 26d8667..0000000 --- a/sdk/extensions/serialization/source/NvBlastExtSerializationLLInterface.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* -* Copyright (c) 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 "NvBlastExtSerializationLLInterface.h" -#include "NvBlastExtSerializationLLImpl.h" -#include <memory> -#include "NvBlastExtSerialization.h" -#include "NvBlastAsset.h" -#include <iostream> -#include "NvBlastExtGlobals.h" - - -NvBlastExtAlloc gAlloc = nullptr; -NvBlastLog gLog = nullptr; - -extern "C" -{ - NVBLAST_API void setAllocator(NvBlastExtAlloc alloc) - { - gAlloc = alloc; - } - - NVBLAST_API void setLog(NvBlastLog log) - { - gLog = log; - } - - NVBLAST_API NvBlastAsset* deserializeAsset(const unsigned char* input, uint32_t size) - { -#if defined(BLAST_LL_ALLOC) - if (gAlloc == nullptr || gLog == nullptr) - { - std::cerr << "Must set allocator and log when using low level serialization library. See setAllocator() and setLog() functions." << std::endl; - return nullptr; - } -#endif - - return Nv::Blast::ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::deserialize(input, size); - } - - NVBLAST_API NvBlastAsset* deserializeAssetFromStream(std::istream &inputStream) - { -#if defined(BLAST_LL_ALLOC) - if (gAlloc == nullptr || gLog == nullptr) - { - std::cerr << "Must set allocator and log when using low level serialization library. See setAllocator() and setLog() functions." << std::endl; - return nullptr; - } -#endif - - return Nv::Blast::ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::deserializeFromStream(inputStream); - } - - NVBLAST_API bool serializeAssetIntoStream(const NvBlastAsset *asset, std::ostream &outputStream) - { -#if defined(BLAST_LL_ALLOC) - if (gAlloc == nullptr || gLog == nullptr) - { - std::cerr << "Must set allocator and log when using low level serialization library. See setAllocator() and setLog() functions." << std::endl; - return false; - } -#endif - - return Nv::Blast::ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoStream(reinterpret_cast<const Nv::Blast::Asset *>(asset), outputStream); - } - - NVBLAST_API bool serializeAssetIntoNewBuffer(const NvBlastAsset *asset, unsigned char **outBuffer, uint32_t &outSize) - { -#if defined(BLAST_LL_ALLOC) - if (gAlloc == nullptr || gLog == nullptr) - { - std::cerr << "Must set allocator and log when using low level serialization library. See setAllocator() and setLog() functions." << std::endl; - return false; - } -#endif - - return Nv::Blast::ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoNewBuffer(reinterpret_cast<const Nv::Blast::Asset *>(asset), outBuffer, outSize); - } - - NVBLAST_API bool serializeAssetIntoExistingBuffer(const NvBlastAsset *asset, unsigned char *buffer, uint32_t maxSize, uint32_t &usedSize) - { -#if defined(BLAST_LL_ALLOC) - if (gAlloc == nullptr || gLog == nullptr) - { - std::cerr << "Must set allocator and log when using low level serialization library. See setAllocator() and setLog() functions." << std::endl; - return false; - } -#endif - - return Nv::Blast::ExtSerialization<Nv::Blast::Asset, Nv::Blast::Serialization::Asset::Reader, Nv::Blast::Serialization::Asset::Builder>::serializeIntoExistingBuffer(reinterpret_cast<const Nv::Blast::Asset *>(asset), buffer, maxSize, usedSize); - } - -} - diff --git a/sdk/extensions/serialization/source/NvBlastExtTkSerialization.capn b/sdk/extensions/serialization/source/NvBlastExtTkSerialization.capn new file mode 100644 index 0000000..5605863 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtTkSerialization.capn @@ -0,0 +1,55 @@ +# 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) 2017 NVIDIA Corporation. All rights reserved. + + +@0xaffe4498f275ee58; + +using Cxx = import "/capnp/c++.capnp"; + +using LL = import "NvBlastExtLlSerialization.capn"; + +$Cxx.namespace("Nv::Blast::Serialization"); + +struct TkAsset +{ + assetLL @0 :LL.Asset; + + jointDescs @1 :List(TkAssetJointDesc); +} + +struct TkAssetJointDesc +{ + nodeIndices @0 :List(UInt32); + attachPositions @1 :List(PxVec3); +} + +struct PxVec3 +{ + x @0 :Float32; + y @1 :Float32; + z @2 :Float32; +} diff --git a/sdk/extensions/serialization/source/NvBlastExtTkSerialization.cpp b/sdk/extensions/serialization/source/NvBlastExtTkSerialization.cpp new file mode 100644 index 0000000..4ecc920 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtTkSerialization.cpp @@ -0,0 +1,105 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerializationInternal.h" +#include "NvBlastExtTkSerialization.h" +#include "NvBlastExtTkSerializerCAPN.h" +#include "NvBlastExtTkSerializerRAW.h" + + +namespace Nv +{ +namespace Blast +{ + +TkFramework* sExtTkSerializerFramework = nullptr; + + +class ExtTkSerializerAsset_CPNB : public ExtSerializer +{ +public: + ExtSerializerBoilerplate("TkAsset_CPNB", "Blast high-level asset (Nv::Blast::TkAsset) serialization using Cap'n Proto binary format.", TkObjectTypeID::Asset, ExtSerialization::EncodingID::CapnProtoBinary); + ExtSerializerDefaultFactoryAndRelease(ExtTkSerializerAsset_CPNB); + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + return ExtSerializationCAPN<TkAsset, Serialization::TkAsset::Reader, Serialization::TkAsset::Builder>::deserializeFromBuffer(reinterpret_cast<const unsigned char*>(buffer), size); + } + + virtual uint64_t serializeIntoBuffer(void*& buffer, ExtSerialization::BufferProvider& bufferProvider, const void* object, uint64_t offset = 0) override + { + uint64_t usedSize; + if (!ExtSerializationCAPN<TkAsset, Serialization::TkAsset::Reader, Serialization::TkAsset::Builder>::serializeIntoBuffer(reinterpret_cast<const TkAsset*>(object), + reinterpret_cast<unsigned char*&>(buffer), usedSize, &bufferProvider, offset)) + { + return 0; + } + return usedSize; + } +}; + + +class ExTkSerializerAsset_RAW : public ExtSerializer +{ +public: + ExtSerializerBoilerplate("TkAsset_RAW", "Blast high-level asset (Nv::Blast::TkAsset) serialization using raw memory format.", TkObjectTypeID::Asset, ExtSerialization::EncodingID::RawBinary); + ExtSerializerDefaultFactoryAndRelease(ExTkSerializerAsset_RAW); + ExtSerializerReadOnly(ExTkSerializerAsset_RAW); + + virtual void* deserializeFromBuffer(const void* buffer, uint64_t size) override + { + ExtIStream stream(buffer, size); + return deserializeTkAsset(stream, *sExtTkSerializerFramework); + } +}; + +} // namespace Blast +} // namespace Nv + + +/////////////////////////////////////// + + +size_t NvBlastExtTkSerializerLoadSet(Nv::Blast::TkFramework& framework, Nv::Blast::ExtSerialization& serialization) +{ + Nv::Blast::sExtTkSerializerFramework = &framework; + + Nv::Blast::ExtSerializer* (*factories[])() = + { + Nv::Blast::ExtTkSerializerAsset_CPNB::create, + Nv::Blast::ExTkSerializerAsset_RAW::create + }; + + return Nv::Blast::ExtSerializationLoadSet(static_cast<Nv::Blast::ExtSerializationInternal&>(serialization), factories); +} + + +uint64_t NvBlastExtSerializationSerializeTkAssetIntoBuffer(void*& buffer, Nv::Blast::ExtSerialization& serialization, const Nv::Blast::TkAsset* asset) +{ + return serialization.serializeIntoBuffer(buffer, asset, Nv::Blast::TkObjectTypeID::Asset); +} diff --git a/sdk/extensions/serialization/source/NvBlastExtTkSerializerCAPN.h b/sdk/extensions/serialization/source/NvBlastExtTkSerializerCAPN.h new file mode 100644 index 0000000..7922338 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtTkSerializerCAPN.h @@ -0,0 +1,70 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + +#include "NvBlastExtSerializationCAPN.h" +#include "NvBlastTkAsset.h" +#include "TkAssetDTO.h" + + +/** +Specializations of ExtSerializationCAPN for BlastTk +*/ + +namespace Nv +{ +namespace Blast +{ + +//// Nv::Blast::TkAsset //// + +template<> +NV_INLINE bool ExtSerializationCAPN<TkAsset, Serialization::TkAsset::Reader, Serialization::TkAsset::Builder>::serializeIntoBuilder(Serialization::TkAsset::Builder& assetBuilder, const TkAsset* asset) +{ + return TkAssetDTO::serialize(assetBuilder, asset); +} + +template<> +NV_INLINE TkAsset* ExtSerializationCAPN<TkAsset, Serialization::TkAsset::Reader, Serialization::TkAsset::Builder>::deserializeFromStreamReader(capnp::InputStreamMessageReader &message) +{ + Serialization::TkAsset::Reader reader = message.getRoot<Serialization::TkAsset>(); + + return TkAssetDTO::deserialize(reader); +} + +template<> +NV_INLINE bool ExtSerializationCAPN<TkAsset, Serialization::TkAsset::Reader, Serialization::TkAsset::Builder>::serializeIntoMessage(capnp::MallocMessageBuilder& message, const TkAsset* asset) +{ + Serialization::TkAsset::Builder assetBuilder = message.initRoot<Serialization::TkAsset>(); + + return serializeIntoBuilder(assetBuilder, asset); +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.cpp b/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.cpp new file mode 100644 index 0000000..ed5ce00 --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.cpp @@ -0,0 +1,184 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#include "NvBlastExtSerializationInternal.h" +#include "NvBlastTkFramework.h" +#include "NvBlastTkAsset.h" +#include "NvBlast.h" + + +namespace Nv +{ +namespace Blast +{ + +// Legacy IDs +struct ExtTkSerializationLegacyID +{ + enum Enum + { + Framework = NVBLAST_FOURCC('T', 'K', 'F', 'W'), //!< TkFramework identifier token, used in serialization + Asset = NVBLAST_FOURCC('A', 'S', 'S', 'T'), //!< TkAsset identifier token, used in serialization + Family = NVBLAST_FOURCC('A', 'C', 'T', 'F'), //!< TkFamily identifier token, used in serialization + }; +}; + + +// Legacy object format versions +struct ExtTkSerializationLegacyAssetVersion +{ + enum Enum + { + /** 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 + }; +}; + +struct ExtTkSerializationLegacyFamilyVersion +{ + enum Enum + { + /** 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 + }; +}; + + +static bool deserializeTkObjectHeader(uint32_t& legacyTypeID, uint32_t& legacyVersion, NvBlastID& objID, uint64_t& userIntData, ExtIStream& stream) +{ + // Read framework ID + uint32_t fwkID; + stream >> fwkID; + if (fwkID != ExtTkSerializationLegacyID::Framework) + { + NVBLAST_LOG_ERROR("deserializeTkObjectHeader: stream does not contain a BlastTk legacy object."); + return false; + } + + // Read object class ID + stream >> legacyTypeID; + + // Read object class version and ensure it's current + stream >> legacyVersion; + + // Object ID + stream.read(objID.data, sizeof(NvBlastID)); + + // Serializable user data + uint32_t lsd, msd; + stream >> lsd >> msd; + userIntData = static_cast<uint64_t>(msd) << 32 | static_cast<uint64_t>(lsd); + + return !stream.fail(); +} + + +TkAsset* deserializeTkAsset(ExtIStream& stream, TkFramework& framework) +{ + // Deserializer header + uint32_t legacyTypeID; + uint32_t legacyVersion; + NvBlastID objID; + uint64_t userIntData; + if (!deserializeTkObjectHeader(legacyTypeID, legacyVersion, objID, userIntData, stream)) + { + return nullptr; + } + + if (legacyTypeID != ExtTkSerializationLegacyID::Asset) + { + NVBLAST_LOG_ERROR("deserializeTkAsset: stream does not contain a BlastTk legacy asset."); + return nullptr; + } + + if (legacyVersion > ExtTkSerializationLegacyAssetVersion::Current) + { + NVBLAST_LOG_ERROR("deserializeTkAsset: stream contains a BlastTk legacy asset which is in an unknown version."); + return nullptr; + } + + // LL asset + uint32_t assetSize; + stream >> assetSize; + NvBlastAsset* llAsset = static_cast<NvBlastAsset*>(NVBLAST_ALLOC_NAMED(assetSize, "deserializeTkAsset")); + stream.read(reinterpret_cast<char*>(llAsset), assetSize); + + // Joint descs + uint32_t jointDescCount; + stream >> jointDescCount; + std::vector<TkAssetJointDesc> jointDescs(jointDescCount); + for (uint32_t i = 0; i < jointDescs.size(); ++i) + { + TkAssetJointDesc& jointDesc = jointDescs[i]; + stream >> jointDesc.nodeIndices[0]; + stream >> jointDesc.nodeIndices[1]; + stream >> jointDesc.attachPositions[0].x; + stream >> jointDesc.attachPositions[0].y; + stream >> jointDesc.attachPositions[0].z; + stream >> jointDesc.attachPositions[1].x; + stream >> jointDesc.attachPositions[1].y; + stream >> jointDesc.attachPositions[1].z; + } + + if (stream.fail()) + { + NVBLAST_FREE(llAsset); + return nullptr; + } + + TkAsset* asset = framework.createAsset(llAsset, jointDescs.data(), (uint32_t)jointDescs.size(), true); + + NvBlastID zeroID; + memset(zeroID.data, 0, sizeof(zeroID)); + if (!memcmp(zeroID.data, objID.data, sizeof(NvBlastID))) + { + asset->setID(objID); + } + asset->userIntData = userIntData; + + return asset; +} + +} // namespace Blast +} // namespace Nv diff --git a/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.h b/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.h new file mode 100644 index 0000000..74006ee --- /dev/null +++ b/sdk/extensions/serialization/source/NvBlastExtTkSerializerRAW.h @@ -0,0 +1,54 @@ +// 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) 2017 NVIDIA Corporation. All rights reserved. + + +#pragma once + + +/** +Raw serialization function declarations for BlastTk +*/ + +#include <stdint.h> + + +namespace Nv +{ +namespace Blast +{ + +// Forward declarations +class TkAsset; +class TkFramework; +class ExtIStream; + +//// Nv::Blast::TkAsset //// + +TkAsset* deserializeTkAsset(ExtIStream& stream, TkFramework& framework); + +} // namespace Blast +} // namespace Nv |