RavEngine
Loading...
Searching...
No Matches
PxProfileEventSerialization.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// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_PROFILE_EVENT_SERIALIZATION_H
30#define PX_PROFILE_EVENT_SERIALIZATION_H
31
32#include "PxProfileDataParsing.h"
33#include "PxProfileEvents.h"
34
35namespace physx { namespace profile {
36
42 template<typename TArrayType>
44 {
45 TArrayType* mArray;
46 EventSerializer( TArrayType* inA ) : mArray( inA ) {}
47
48 template<typename TDataType>
49 uint32_t streamify( const char*, const TDataType& inType )
50 {
51 return mArray->write( inType );
52 }
53
54 uint32_t streamify( const char*, const char*& inType )
55 {
56 PX_ASSERT( inType != NULL );
57 uint32_t len( static_cast<uint32_t>( strlen( inType ) ) );
58 ++len; //include the null terminator
59 uint32_t writtenSize = 0;
60 writtenSize = mArray->write(len);
61 writtenSize += mArray->write(inType, len);
62 return writtenSize;
63 }
64
65 uint32_t streamify( const char*, const uint8_t* inData, uint32_t len )
66 {
67 uint32_t writtenSize = mArray->write(len);
68 if ( len )
69 writtenSize += mArray->write(inData, len);
70 return writtenSize;
71 }
72
73 uint32_t streamify( const char* nm, const uint64_t& inType, EventStreamCompressionFlags::Enum inFlags )
74 {
75 uint32_t writtenSize = 0;
76 switch( inFlags )
77 {
78 case EventStreamCompressionFlags::U8:
79 writtenSize = streamify(nm, static_cast<uint8_t>(inType));
80 break;
81 case EventStreamCompressionFlags::U16:
82 writtenSize = streamify(nm, static_cast<uint16_t>(inType));
83 break;
84 case EventStreamCompressionFlags::U32:
85 writtenSize = streamify(nm, static_cast<uint32_t>(inType));
86 break;
87 case EventStreamCompressionFlags::U64:
88 writtenSize = streamify(nm, inType);
89 break;
90 }
91 return writtenSize;
92 }
93
94 uint32_t streamify( const char* nm, const uint32_t& inType, EventStreamCompressionFlags::Enum inFlags )
95 {
96 uint32_t writtenSize = 0;
97 switch( inFlags )
98 {
99 case EventStreamCompressionFlags::U8:
100 writtenSize = streamify(nm, static_cast<uint8_t>(inType));
101 break;
102 case EventStreamCompressionFlags::U16:
103 writtenSize = streamify(nm, static_cast<uint16_t>(inType));
104 break;
105 case EventStreamCompressionFlags::U32:
106 case EventStreamCompressionFlags::U64:
107 writtenSize = streamify(nm, inType);
108 break;
109 }
110 return writtenSize;
111 }
112 };
113
118 template<bool TSwapBytes>
120 {
121 const uint8_t* mData;
122 uint32_t mLength;
123 bool mFail;
124
125 EventDeserializer( const uint8_t* inData, uint32_t inLength )
126 : mData( inData )
127 , mLength( inLength )
128 , mFail( false )
129 {
130 if ( mData == NULL )
131 mLength = 0;
132 }
133
134 bool val() { return TSwapBytes; }
135
136 uint32_t streamify( const char* , uint8_t& inType )
137 {
138 uint8_t* theData = reinterpret_cast<uint8_t*>( &inType ); //type punned pointer...
139 if ( mFail || sizeof( inType ) > mLength )
140 {
141 PX_ASSERT( false );
142 mFail = true;
143 }
144 else
145 {
146 for( uint32_t idx = 0; idx < sizeof( uint8_t ); ++idx, ++mData, --mLength )
147 theData[idx] = *mData;
148 }
149 return 0;
150 }
151
152 //default streamify reads things natively as bytes.
153 template<typename TDataType>
154 uint32_t streamify( const char* , TDataType& inType )
155 {
156 uint8_t* theData = reinterpret_cast<uint8_t*>( &inType ); //type punned pointer...
157 if ( mFail || sizeof( inType ) > mLength )
158 {
159 PX_ASSERT( false );
160 mFail = true;
161 }
162 else
163 {
164 for( uint32_t idx = 0; idx < sizeof( TDataType ); ++idx, ++mData, --mLength )
165 theData[idx] = *mData;
166 bool temp = val();
167 if ( temp )
168 BlockParseFunctions::swapBytes<sizeof(TDataType)>( theData );
169 }
170 return 0;
171 }
172
173 uint32_t streamify( const char*, const char*& inType )
174 {
175 uint32_t theLen;
176 streamify( "", theLen );
177 theLen = PxMin( theLen, mLength );
178 inType = reinterpret_cast<const char*>( mData );
179 mData += theLen;
180 mLength -= theLen;
181 return 0;
182 }
183
184 uint32_t streamify( const char*, const uint8_t*& inData, uint32_t& len )
185 {
186 uint32_t theLen;
187 streamify( "", theLen );
188 theLen = PxMin( theLen, mLength );
189 len = theLen;
190 inData = reinterpret_cast<const uint8_t*>( mData );
191 mData += theLen;
192 mLength -= theLen;
193 return 0;
194 }
195
196 uint32_t streamify( const char* nm, uint64_t& inType, EventStreamCompressionFlags::Enum inFlags )
197 {
198 switch( inFlags )
199 {
200 case EventStreamCompressionFlags::U8:
201 {
202 uint8_t val=0;
203 streamify( nm, val );
204 inType = val;
205 }
206 break;
207 case EventStreamCompressionFlags::U16:
208 {
209 uint16_t val;
210 streamify( nm, val );
211 inType = val;
212 }
213 break;
214 case EventStreamCompressionFlags::U32:
215 {
216 uint32_t val;
217 streamify( nm, val );
218 inType = val;
219 }
220 break;
221 case EventStreamCompressionFlags::U64:
222 streamify( nm, inType );
223 break;
224 }
225 return 0;
226 }
227
228 uint32_t streamify( const char* nm, uint32_t& inType, EventStreamCompressionFlags::Enum inFlags )
229 {
230 switch( inFlags )
231 {
232 case EventStreamCompressionFlags::U8:
233 {
234 uint8_t val=0;
235 streamify( nm, val );
236 inType = val;
237 }
238 break;
239 case EventStreamCompressionFlags::U16:
240 {
241 uint16_t val=0;
242 streamify( nm, val );
243 inType = val;
244 }
245 break;
246 case EventStreamCompressionFlags::U32:
247 case EventStreamCompressionFlags::U64:
248 streamify( nm, inType );
249 break;
250 }
251 return 0;
252 }
253 };
254}}
255#endif
256
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition PxMath.h:88
Definition PxProfileEventSerialization.h:120
Definition PxProfileEventSerialization.h:44