RavEngine
Loading...
Searching...
No Matches
PxPvdMarshalling.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_MARSHALLING_H
28#define PX_PVD_MARSHALLING_H
29
30#include "foundation/PxMathIntrinsics.h"
31
32#include "PxPvdObjectModelBaseTypes.h"
33#include "PxPvdBits.h"
34
35namespace physx
36{
37namespace pvdsdk
38{
39
40// Define marshalling
41
42template <typename TSmallerType, typename TLargerType>
44{
45 bool canMarshal;
46 PvdMarshalling() : canMarshal(false)
47 {
48 }
49};
50
51template <typename smtype, typename lgtype>
52static inline void marshalSingleT(const uint8_t* srcData, uint8_t* destData)
53{
54 smtype incoming;
55
56 physx::intrinsics::memCopy(&incoming, srcData, sizeof(smtype));
57 lgtype outgoing = static_cast<lgtype>(incoming);
58 physx::intrinsics::memCopy(destData, &outgoing, sizeof(lgtype));
59}
60
61template <typename smtype, typename lgtype>
62static inline void marshalBlockT(const uint8_t* srcData, uint8_t* destData, uint32_t numBytes)
63{
64 for(const uint8_t* item = srcData, *end = srcData + numBytes; item < end;
65 item += sizeof(smtype), destData += sizeof(lgtype))
66 marshalSingleT<smtype, lgtype>(item, destData);
67}
68
69#define PVD_TYPE_MARSHALLER(smtype, lgtype) \
70 template <> \
71 struct PvdMarshalling<smtype, lgtype> \
72 { \
73 uint32_t canMarshal; \
74 static void marshalSingle(const uint8_t* srcData, uint8_t* destData) \
75 { \
76 marshalSingleT<smtype, lgtype>(srcData, destData); \
77 } \
78 static void marshalBlock(const uint8_t* srcData, uint8_t* destData, uint32_t numBytes) \
79 { \
80 marshalBlockT<smtype, lgtype>(srcData, destData, numBytes); \
81 } \
82 };
83
84// define marshalling tables.
85PVD_TYPE_MARSHALLER(int8_t, int16_t)
86PVD_TYPE_MARSHALLER(int8_t, uint16_t)
87PVD_TYPE_MARSHALLER(int8_t, int32_t)
88PVD_TYPE_MARSHALLER(int8_t, uint32_t)
89PVD_TYPE_MARSHALLER(int8_t, int64_t)
90PVD_TYPE_MARSHALLER(int8_t, uint64_t)
91PVD_TYPE_MARSHALLER(int8_t, PvdF32)
92PVD_TYPE_MARSHALLER(int8_t, PvdF64)
93
94PVD_TYPE_MARSHALLER(uint8_t, int16_t)
95PVD_TYPE_MARSHALLER(uint8_t, uint16_t)
96PVD_TYPE_MARSHALLER(uint8_t, int32_t)
97PVD_TYPE_MARSHALLER(uint8_t, uint32_t)
98PVD_TYPE_MARSHALLER(uint8_t, int64_t)
99PVD_TYPE_MARSHALLER(uint8_t, uint64_t)
100PVD_TYPE_MARSHALLER(uint8_t, PvdF32)
101PVD_TYPE_MARSHALLER(uint8_t, PvdF64)
102
103PVD_TYPE_MARSHALLER(int16_t, int32_t)
104PVD_TYPE_MARSHALLER(int16_t, uint32_t)
105PVD_TYPE_MARSHALLER(int16_t, int64_t)
106PVD_TYPE_MARSHALLER(int16_t, uint64_t)
107PVD_TYPE_MARSHALLER(int16_t, PvdF32)
108PVD_TYPE_MARSHALLER(int16_t, PvdF64)
109
110PVD_TYPE_MARSHALLER(uint16_t, int32_t)
111PVD_TYPE_MARSHALLER(uint16_t, uint32_t)
112PVD_TYPE_MARSHALLER(uint16_t, int64_t)
113PVD_TYPE_MARSHALLER(uint16_t, uint64_t)
114PVD_TYPE_MARSHALLER(uint16_t, PvdF32)
115PVD_TYPE_MARSHALLER(uint16_t, PvdF64)
116
117PVD_TYPE_MARSHALLER(int32_t, int64_t)
118PVD_TYPE_MARSHALLER(int32_t, uint64_t)
119PVD_TYPE_MARSHALLER(int32_t, PvdF64)
120PVD_TYPE_MARSHALLER(int32_t, PvdF32)
121
122PVD_TYPE_MARSHALLER(uint32_t, int64_t)
123PVD_TYPE_MARSHALLER(uint32_t, uint64_t)
124PVD_TYPE_MARSHALLER(uint32_t, PvdF64)
125PVD_TYPE_MARSHALLER(uint32_t, PvdF32)
126
127PVD_TYPE_MARSHALLER(PvdF32, PvdF64)
128PVD_TYPE_MARSHALLER(PvdF32, uint32_t)
129PVD_TYPE_MARSHALLER(PvdF32, int32_t)
130
131PVD_TYPE_MARSHALLER(uint64_t, PvdF64)
132PVD_TYPE_MARSHALLER(int64_t, PvdF64)
133PVD_TYPE_MARSHALLER(PvdF64, uint64_t)
134PVD_TYPE_MARSHALLER(PvdF64, int64_t)
135
136template <typename TMarshaller>
137static inline bool getMarshalOperators(TSingleMarshaller&, TBlockMarshaller&, TMarshaller&, bool)
138{
139 return false;
140}
141
142template <typename TMarshaller>
143static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, TMarshaller&, uint32_t)
144{
145 single = TMarshaller::marshalSingle;
146 block = TMarshaller::marshalBlock;
147 return true;
148}
149
150template <typename smtype, typename lgtype>
151static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block)
152{
153 single = NULL;
154 block = NULL;
155 PvdMarshalling<smtype, lgtype> marshaller = PvdMarshalling<smtype, lgtype>();
156 return getMarshalOperators(single, block, marshaller, marshaller.canMarshal);
157}
158
159template <typename smtype>
160static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, int32_t lgtypeId)
161{
162 switch(lgtypeId)
163 {
164 case PvdBaseType::PvdI8: // int8_t:
165 return getMarshalOperators<smtype, int8_t>(single, block);
166 case PvdBaseType::PvdU8: // uint8_t:
167 return getMarshalOperators<smtype, uint8_t>(single, block);
168 case PvdBaseType::PvdI16: // int16_t:
169 return getMarshalOperators<smtype, int16_t>(single, block);
170 case PvdBaseType::PvdU16: // uint16_t:
171 return getMarshalOperators<smtype, uint16_t>(single, block);
172 case PvdBaseType::PvdI32: // int32_t:
173 return getMarshalOperators<smtype, int32_t>(single, block);
174 case PvdBaseType::PvdU32: // uint32_t:
175 return getMarshalOperators<smtype, uint32_t>(single, block);
176 case PvdBaseType::PvdI64: // int64_t:
177 return getMarshalOperators<smtype, int64_t>(single, block);
178 case PvdBaseType::PvdU64: // uint64_t:
179 return getMarshalOperators<smtype, uint64_t>(single, block);
180 case PvdBaseType::PvdF32:
181 return getMarshalOperators<smtype, PvdF32>(single, block);
182 case PvdBaseType::PvdF64:
183 return getMarshalOperators<smtype, PvdF64>(single, block);
184 }
185 return false;
186}
187
188static inline bool getMarshalOperators(TSingleMarshaller& single, TBlockMarshaller& block, int32_t smtypeId,
189 int32_t lgtypeId)
190{
191 switch(smtypeId)
192 {
193 case PvdBaseType::PvdI8: // int8_t:
194 return getMarshalOperators<int8_t>(single, block, lgtypeId);
195 case PvdBaseType::PvdU8: // uint8_t:
196 return getMarshalOperators<uint8_t>(single, block, lgtypeId);
197 case PvdBaseType::PvdI16: // int16_t:
198 return getMarshalOperators<int16_t>(single, block, lgtypeId);
199 case PvdBaseType::PvdU16: // uint16_t:
200 return getMarshalOperators<uint16_t>(single, block, lgtypeId);
201 case PvdBaseType::PvdI32: // int32_t:
202 return getMarshalOperators<int32_t>(single, block, lgtypeId);
203 case PvdBaseType::PvdU32: // uint32_t:
204 return getMarshalOperators<uint32_t>(single, block, lgtypeId);
205 case PvdBaseType::PvdI64: // int64_t:
206 return getMarshalOperators<int64_t>(single, block, lgtypeId);
207 case PvdBaseType::PvdU64: // uint64_t:
208 return getMarshalOperators<uint64_t>(single, block, lgtypeId);
209 case PvdBaseType::PvdF32:
210 return getMarshalOperators<PvdF32>(single, block, lgtypeId);
211 case PvdBaseType::PvdF64:
212 return getMarshalOperators<PvdF64>(single, block, lgtypeId);
213 }
214 return false;
215}
216}
217}
218
219#endif
220
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxPvdMarshalling.h:44