RavEngine
Loading...
Searching...
No Matches
PxPvdBits.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26
27#ifndef PX_PVD_BITS_H
28#define PX_PVD_BITS_H
29
30#include "PxPvdObjectModelBaseTypes.h"
31
32namespace physx
33{
34namespace pvdsdk
35{
36
37// Marshallers cannot assume src is aligned, but they can assume dest is aligned.
38typedef void (*TSingleMarshaller)(const uint8_t* src, uint8_t* dest);
39typedef void (*TBlockMarshaller)(const uint8_t* src, uint8_t* dest, uint32_t numItems);
40
41template <uint8_t ByteCount>
42static inline void doSwapBytes(uint8_t* __restrict inData)
43{
44 for(uint32_t idx = 0; idx < ByteCount / 2; ++idx)
45 {
46 uint32_t endIdx = ByteCount - idx - 1;
47 uint8_t theTemp = inData[idx];
48 inData[idx] = inData[endIdx];
49 inData[endIdx] = theTemp;
50 }
51}
52
53template <uint8_t ByteCount>
54static inline void doSwapBytes(uint8_t* __restrict inData, uint32_t itemCount)
55{
56 uint8_t* end = inData + itemCount * ByteCount;
57 for(; inData < end; inData += ByteCount)
58 doSwapBytes<ByteCount>(inData);
59}
60
61static inline void swapBytes(uint8_t* __restrict dataPtr, uint32_t numBytes, uint32_t itemWidth)
62{
63 uint32_t numItems = numBytes / itemWidth;
64 switch(itemWidth)
65 {
66 case 1:
67 break;
68 case 2:
69 doSwapBytes<2>(dataPtr, numItems);
70 break;
71 case 4:
72 doSwapBytes<4>(dataPtr, numItems);
73 break;
74 case 8:
75 doSwapBytes<8>(dataPtr, numItems);
76 break;
77 case 16:
78 doSwapBytes<16>(dataPtr, numItems);
79 break;
80 default:
81 PX_ASSERT(false);
82 break;
83 }
84}
85
86static inline void swapBytes(uint8_t&)
87{
88}
89static inline void swapBytes(int8_t&)
90{
91}
92static inline void swapBytes(uint16_t& inData)
93{
94 doSwapBytes<2>(reinterpret_cast<uint8_t*>(&inData));
95}
96static inline void swapBytes(int16_t& inData)
97{
98 doSwapBytes<2>(reinterpret_cast<uint8_t*>(&inData));
99}
100static inline void swapBytes(uint32_t& inData)
101{
102 doSwapBytes<4>(reinterpret_cast<uint8_t*>(&inData));
103}
104static inline void swapBytes(int32_t& inData)
105{
106 doSwapBytes<4>(reinterpret_cast<uint8_t*>(&inData));
107}
108static inline void swapBytes(float& inData)
109{
110 doSwapBytes<4>(reinterpret_cast<uint8_t*>(&inData));
111}
112static inline void swapBytes(uint64_t& inData)
113{
114 doSwapBytes<8>(reinterpret_cast<uint8_t*>(&inData));
115}
116static inline void swapBytes(int64_t& inData)
117{
118 doSwapBytes<8>(reinterpret_cast<uint8_t*>(&inData));
119}
120static inline void swapBytes(double& inData)
121{
122 doSwapBytes<8>(reinterpret_cast<uint8_t*>(&inData));
123}
124
125static inline bool checkLength(const uint8_t* inStart, const uint8_t* inStop, uint32_t inLength)
126{
127 return static_cast<uint32_t>(inStop - inStart) >= inLength;
128}
129}
130}
131#endif
132
uint32 uint32_t
Definition fwd.hpp:131
uint8 uint8_t
Definition fwd.hpp:103
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39