// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved. #ifndef PX_PVD_MARSHALLING_H #define PX_PVD_MARSHALLING_H #include "foundation/PxMathIntrinsics.h" #include "PxPvdObjectModelBaseTypes.h" #include "PxPvdBits.h" namespace physx { namespace pvdsdk { // Define marshalling template struct PvdMarshalling { bool canMarshal; PvdMarshalling() : canMarshal(false) { } }; template static inline void marshalSingleT(const uint8_t* srcData, uint8_t* destData) { smtype incoming; physx::intrinsics::memCopy(&incoming, srcData, sizeof(smtype)); lgtype outgoing = static_cast(incoming); physx::intrinsics::memCopy(destData, &outgoing, sizeof(lgtype)); } template static inline void marshalBlockT(const uint8_t* srcData, uint8_t* destData, uint32_t numBytes) { for(const uint8_t* item = srcData, *end = srcData + numBytes; item < end; item += sizeof(smtype), destData += sizeof(lgtype)) marshalSingleT(item, destData); } #define PVD_TYPE_MARSHALLER(smtype, lgtype) \ template <> \ struct PvdMarshalling \ { \ uint32_t canMarshal; \ static void marshalSingle(const uint8_t* srcData, uint8_t* destData) \ { \ marshalSingleT(srcData, destData); \ } \ static void marshalBlock(const uint8_t* srcData, uint8_t* destData, uint32_t numBytes) \ { \ marshalBlockT(srcData, destData, numBytes); \ } \ }; // define marshalling tables. PVD_TYPE_MARSHALLER(int8_t, int16_t) PVD_TYPE_MARSHALLER(int8_t, uint16_t) PVD_TYPE_MARSHALLER(int8_t, int32_t) PVD_TYPE_MARSHALLER(int8_t, uint32_t) PVD_TYPE_MARSHALLER(int8_t, int64_t) PVD_TYPE_MARSHALLER(int8_t, uint64_t) PVD_TYPE_MARSHALLER(int8_t, PvdF32) PVD_TYPE_MARSHALLER(int8_t, PvdF64) PVD_TYPE_MARSHALLER(uint8_t, int16_t) PVD_TYPE_MARSHALLER(uint8_t, uint16_t) PVD_TYPE_MARSHALLER(uint8_t, int32_t) PVD_TYPE_MARSHALLER(uint8_t, uint32_t) PVD_TYPE_MARSHALLER(uint8_t, int64_t) PVD_TYPE_MARSHALLER(uint8_t, uint64_t) PVD_TYPE_MARSHALLER(uint8_t, PvdF32) PVD_TYPE_MARSHALLER(uint8_t, PvdF64) PVD_TYPE_MARSHALLER(int16_t, int32_t) PVD_TYPE_MARSHALLER(int16_t, uint32_t) PVD_TYPE_MARSHALLER(int16_t, int64_t) PVD_TYPE_MARSHALLER(int16_t, uint64_t) PVD_TYPE_MARSHALLER(int16_t, PvdF32) PVD_TYPE_MARSHALLER(int16_t, PvdF64) PVD_TYPE_MARSHALLER(uint16_t, int32_t) PVD_TYPE_MARSHALLER(uint16_t, uint32_t) PVD_TYPE_MARSHALLER(uint16_t, int64_t) PVD_TYPE_MARSHALLER(uint16_t, uint64_t) PVD_TYPE_MARSHALLER(uint16_t, PvdF32) PVD_TYPE_MARSHALLER(uint16_t, PvdF64) PVD_TYPE_MARSHALLER(int32_t, int64_t) PVD_TYPE_MARSHALLER(int32_t, uint64_t) PVD_TYPE_MARSHALLER(int32_t, PvdF64) PVD_TYPE_MARSHALLER(int32_t, PvdF32) PVD_TYPE_MARSHALLER(uint32_t, int64_t) PVD_TYPE_MARSHALLER(uint32_t, uint64_t) PVD_TYPE_MARSHALLER(uint32_t, PvdF64) PVD_TYPE_MARSHALLER(uint32_t, PvdF32) PVD_TYPE_MARSHALLER(PvdF32, PvdF64) PVD_TYPE_MARSHALLER(PvdF32, uint32_t) PVD_TYPE_MARSHALLER(PvdF32, int32_t) PVD_TYPE_MARSHALLER(uint64_t, PvdF64) PVD_TYPE_MARSHALLER(int64_t, PvdF64) PVD_TYPE_MARSHALLER(PvdF64, uint64_t) PVD_TYPE_MARSHALLER(PvdF64, int64_t) template static inline bool getMarshalOperators(TSingleMarshaller&, TBlockMarshaller&, TMarshaller&, bool) { return false; } template static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, TMarshaller&, uint32_t) { single = TMarshaller::marshalSingle; block = TMarshaller::marshalBlock; return true; } template static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block) { single = NULL; block = NULL; PvdMarshalling marshaller = PvdMarshalling(); return getMarshalOperators(single, block, marshaller, marshaller.canMarshal); } template static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, int32_t lgtypeId) { switch(lgtypeId) { case PvdBaseType::PvdI8: // int8_t: return getMarshalOperators(single, block); case PvdBaseType::PvdU8: // uint8_t: return getMarshalOperators(single, block); case PvdBaseType::PvdI16: // int16_t: return getMarshalOperators(single, block); case PvdBaseType::PvdU16: // uint16_t: return getMarshalOperators(single, block); case PvdBaseType::PvdI32: // int32_t: return getMarshalOperators(single, block); case PvdBaseType::PvdU32: // uint32_t: return getMarshalOperators(single, block); case PvdBaseType::PvdI64: // int64_t: return getMarshalOperators(single, block); case PvdBaseType::PvdU64: // uint64_t: return getMarshalOperators(single, block); case PvdBaseType::PvdF32: return getMarshalOperators(single, block); case PvdBaseType::PvdF64: return getMarshalOperators(single, block); } return false; } static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, int32_t smtypeId, int32_t lgtypeId) { switch(smtypeId) { case PvdBaseType::PvdI8: // int8_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdU8: // uint8_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdI16: // int16_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdU16: // uint16_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdI32: // int32_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdU32: // uint32_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdI64: // int64_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdU64: // uint64_t: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdF32: return getMarshalOperators(single, block, lgtypeId); case PvdBaseType::PvdF64: return getMarshalOperators(single, block, lgtypeId); } return false; } } } #endif