RavEngine
Loading...
Searching...
No Matches
NvFlowReflect.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) 2014-2022 NVIDIA Corporation. All rights reserved.
26
27#ifndef NV_FLOW_REFLECT_H
28#define NV_FLOW_REFLECT_H
29
30#include "NvFlowTypes.h"
31
33
34NV_FLOW_INLINE int NvFlowReflectStringCompare(const char* a, const char* b)
35{
36 a = a ? a : "\0";
37 b = b ? b : "\0";
38 int idx = 0;
39 while (a[idx] || b[idx])
40 {
41 if (a[idx] != b[idx])
42 {
43 return a[idx] < b[idx] ? -1 : +1;
44 }
45 idx++;
46 }
47 return 0;
48}
49
50NV_FLOW_INLINE const char* NvFlowTypeToString(NvFlowType type)
51{
52 switch (type)
53 {
54 case eNvFlowType_unknown: return "unknown";
55 case eNvFlowType_void: return "void";
56 case eNvFlowType_function: return "function";
57 case eNvFlowType_struct: return "struct";
58 case eNvFlowType_int: return "int";
59 case eNvFlowType_int2: return "int2";
60 case eNvFlowType_int3: return "int3";
61 case eNvFlowType_int4: return "int4";
62 case eNvFlowType_uint: return "uint";
63 case eNvFlowType_uint2: return "uint2";
64 case eNvFlowType_uint3: return "uint3";
65 case eNvFlowType_uint4: return "uint4";
66 case eNvFlowType_float: return "float";
67 case eNvFlowType_float2: return "float2";
68 case eNvFlowType_float3: return "float3";
69 case eNvFlowType_float4: return "float4";
70 case eNvFlowType_float4x4: return "float4x4";
71 case eNvFlowType_bool32: return "bool32";
72 case eNvFlowType_uint8: return "uint8";
73 case eNvFlowType_uint16: return "uint16";
74 case eNvFlowType_uint64: return "uint64";
75 case eNvFlowType_char: return "char";
76 case eNvFlowType_double: return "double";
77 default: return "unknown";
78 }
79}
80
81NV_FLOW_INLINE NvFlowType NvFlowTypeFromString(const char* name)
82{
83 if (NvFlowReflectStringCompare(name, "unknown") == 0) { return eNvFlowType_unknown; }
84 else if (NvFlowReflectStringCompare(name, "struct") == 0) { return eNvFlowType_struct; }
85 else if (NvFlowReflectStringCompare(name, "void") == 0) { return eNvFlowType_void; }
86 else if (NvFlowReflectStringCompare(name, "function") == 0) { return eNvFlowType_function; }
87 else if (NvFlowReflectStringCompare(name, "int") == 0) { return eNvFlowType_int; }
88 else if (NvFlowReflectStringCompare(name, "int2") == 0) { return eNvFlowType_int2; }
89 else if (NvFlowReflectStringCompare(name, "int3") == 0) { return eNvFlowType_int3; }
90 else if (NvFlowReflectStringCompare(name, "int4") == 0) { return eNvFlowType_int4; }
91 else if (NvFlowReflectStringCompare(name, "uint") == 0) { return eNvFlowType_uint; }
92 else if (NvFlowReflectStringCompare(name, "uint2") == 0) { return eNvFlowType_uint2; }
93 else if (NvFlowReflectStringCompare(name, "uint3") == 0) { return eNvFlowType_uint3; }
94 else if (NvFlowReflectStringCompare(name, "uint4") == 0) { return eNvFlowType_uint4; }
95 else if (NvFlowReflectStringCompare(name, "float") == 0) { return eNvFlowType_float; }
96 else if (NvFlowReflectStringCompare(name, "float2") == 0) { return eNvFlowType_float2; }
97 else if (NvFlowReflectStringCompare(name, "float3") == 0) { return eNvFlowType_float3; }
98 else if (NvFlowReflectStringCompare(name, "float4") == 0) { return eNvFlowType_float4; }
99 else if (NvFlowReflectStringCompare(name, "float4x4") == 0) { return eNvFlowType_float4x4; }
100 else if (NvFlowReflectStringCompare(name, "bool32") == 0) { return eNvFlowType_bool32; }
101 else if (NvFlowReflectStringCompare(name, "uint8") == 0) { return eNvFlowType_uint8; }
102 else if (NvFlowReflectStringCompare(name, "uint16") == 0) { return eNvFlowType_uint16; }
103 else if (NvFlowReflectStringCompare(name, "uint64") == 0) { return eNvFlowType_uint64; }
104 else if (NvFlowReflectStringCompare(name, "char") == 0) { return eNvFlowType_char; }
105 else if (NvFlowReflectStringCompare(name, "double") == 0) { return eNvFlowType_double; }
106 else return eNvFlowType_unknown;
107}
108
109NV_FLOW_INLINE void NvFlowReflectMemcpy(void* dst, const void* src, NvFlowUint64 numBytes)
110{
111 for (NvFlowUint64 byteIdx = 0u; byteIdx < numBytes; byteIdx++)
112 {
113 ((NvFlowUint8*)dst)[byteIdx] = ((const NvFlowUint8*)src)[byteIdx];
114 }
115}
116
117NV_FLOW_INLINE void NvFlowReflectClear(void* dst, NvFlowUint64 numBytes)
118{
119 for (NvFlowUint64 byteIdx = 0u; byteIdx < numBytes; byteIdx++)
120 {
121 ((NvFlowUint8*)dst)[byteIdx] = 0;
122 }
123}
124
125typedef NvFlowUint NvFlowReflectHintFlags;
126
127typedef enum NvFlowReflectHint
128{
129 eNvFlowReflectHint_none = 0x00,
130
131 eNvFlowReflectHint_transient = 0x00000001, // Hint to not serialize
132 eNvFlowReflectHint_noEdit = 0x00000002, // Hint to not expose to editor
133 eNvFlowReflectHint_transientNoEdit = 0x00000003,
134
135 eNvFlowReflectHint_resource = 0x0000000C, // Mask for resource hints
136 eNvFlowReflectHint_asset = 0x0000000C, // Hint to serialize as external asset, instead of inlined
137 eNvFlowReflectHint_bufferId = 0x00000004, // Hint to treat NvFlowUint64 as bufferId, allowing conversion from paths to ids
138 eNvFlowReflectHint_textureId = 0x00000008, // Hint to treat NvFlowUint64 as textureId, allowing conversion from paths to ids
139
140 eNvFlowReflectHint_pinEnabled = 0x00010000,
141 eNvFlowReflectHint_pinGlobal = 0x00020000,
142 eNvFlowReflectHint_pinEnabledGlobal = 0x00030000,
143 eNvFlowReflectHint_pinMutable = 0x00040000,
144 eNvFlowReflectHint_pinEnabledMutable = 0x00050000,
145 eNvFlowReflectHint_pinGroup = 0x00080000,
146
147 eNvFlowReflectHint_maxEnum = 0x7FFFFFFF
148}NvFlowReflectHint;
149
150typedef NvFlowUint NvFlowReflectModeFlags;
151
152typedef enum NvFlowReflectMode
153{
154 eNvFlowReflectMode_value = 0x00,
155 eNvFlowReflectMode_pointer = 0x01,
156 eNvFlowReflectMode_array = 0x02,
157 eNvFlowReflectMode_pointerArray = 0x03,
158 eNvFlowReflectMode_valueVersioned = 0x04,
159 eNvFlowReflectMode_pointerVersioned = 0x05,
160 eNvFlowReflectMode_arrayVersioned = 0x06,
161 eNvFlowReflectMode_pointerArrayVersioned = 0x07,
162
163 eNvFlowReflectMode_maxEnum = 0x7FFFFFFF
164}NvFlowReflectMode;
165
168
169typedef struct NvFlowReflectData
170{
171 NvFlowReflectHintFlags reflectHints;
172 NvFlowReflectModeFlags reflectMode;
173 const NvFlowReflectDataType* dataType;
174 const char* name;
175 NvFlowUint64 dataOffset;
176 NvFlowUint64 arraySizeOffset;
177 NvFlowUint64 versionOffset;
178 const char* metadata;
180
182{
183 NvFlowType dataType;
184 NvFlowUint64 elementSize;
185 const char* structTypename;
186 const NvFlowReflectData* childReflectDatas;
187 NvFlowUint64 childReflectDataCount;
188 const void* defaultValue;
190
191typedef void(NV_FLOW_ABI* NvFlowReflectProcess_t)(NvFlowUint8* data, const NvFlowReflectDataType* dataType, void* userdata);
192
193NV_FLOW_INLINE void NvFlowReflectCopyByName(
194 void* dstData, const NvFlowReflectDataType* dstType,
195 const void* srcData, const NvFlowReflectDataType* srcType
196)
197{
198 NvFlowUint8* dstData8 = (NvFlowUint8*)dstData;
199 const NvFlowUint8* srcData8 = (const NvFlowUint8*)srcData;
200
201 // For safety, take min of elementSize
202 NvFlowUint64 safeCopySize = srcType->elementSize < dstType->elementSize ? srcType->elementSize : dstType->elementSize;
203
204 // Start with raw copy, to potential cover non-reflect data
205 NvFlowReflectMemcpy(dstData, srcData, safeCopySize);
206
207 // Single level copy by name, enough to cover interfaces
208 if (dstType != srcType)
209 {
210 NvFlowUint64 srcIdx = 0u;
211 for (NvFlowUint64 dstIdx = 0u; dstIdx < dstType->childReflectDataCount; dstIdx++)
212 {
213 for (NvFlowUint64 srcCount = 0u; srcCount < srcType->childReflectDataCount; srcCount++)
214 {
215 const NvFlowReflectData* childDst = dstType->childReflectDatas + dstIdx;
216 const NvFlowReflectData* childSrc = srcType->childReflectDatas + srcIdx;
217 if (childDst->name == childSrc->name ||
218 NvFlowReflectStringCompare(childDst->name, childSrc->name) == 0)
219 {
220 // only copy if not covered by bulk memcpy
221 if (childDst->dataOffset != childSrc->dataOffset)
222 {
223 NvFlowReflectMemcpy(
224 dstData8 + childDst->dataOffset,
225 srcData8 + childSrc->dataOffset,
226 (childDst->reflectMode & eNvFlowReflectMode_pointerArray) ? sizeof(void*) : childDst->dataType->elementSize
227 );
228 }
229 if (childDst->reflectMode & eNvFlowReflectMode_array)
230 {
231 if (childDst->arraySizeOffset != childSrc->arraySizeOffset)
232 {
233 NvFlowReflectMemcpy(
234 dstData8 + childDst->arraySizeOffset,
235 srcData8 + childSrc->arraySizeOffset,
236 sizeof(NvFlowUint64)
237 );
238 }
239 }
240 if (childDst->reflectMode & eNvFlowReflectMode_valueVersioned)
241 {
242 if (childDst->versionOffset != childSrc->versionOffset)
243 {
244 NvFlowReflectMemcpy(
245 dstData8 + childDst->versionOffset,
246 srcData8 + childSrc->versionOffset,
247 sizeof(NvFlowUint64)
248 );
249 }
250 }
251 srcCount = srcType->childReflectDataCount - 1u;
252 }
253 srcIdx++;
254 if (srcIdx >= srcType->childReflectDataCount)
255 {
256 srcIdx = 0u;
257 }
258 }
259 }
260 }
261}
262
263// Reflect blocks must start with #define NV_FLOW_REFLECT_TYPE typename
264// And end with #undef NV_FLOW_REFLECT_TYPE
265
266#define NV_FLOW_REFLECT_XSTR(X) NV_FLOW_REFLECT_STR(X)
267#define NV_FLOW_REFLECT_STR(X) #X
268
269#define NV_FLOW_REFLECT_XCONCAT(A, B) NV_FLOW_REFLECT_CONCAT(A, B)
270#define NV_FLOW_REFLECT_CONCAT(A, B) A##B
271
272#define NV_FLOW_REFLECT_VALIDATE(type) \
273 NV_FLOW_INLINE type* NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtr)(const type* v) { return (type*)v; } \
274 NV_FLOW_INLINE type** NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtr)(const type* const * v) { return (type**)v; } \
275 NV_FLOW_INLINE type*** NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtrPtr)(const type*const *const * v) { return (type***)v; }
276
277#if defined(__cplusplus)
278#define NV_FLOW_REFLECT_VALIDATE_value(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
279#define NV_FLOW_REFLECT_VALIDATE_pointer(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
280#define NV_FLOW_REFLECT_VALIDATE_array(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
281#define NV_FLOW_REFLECT_VALIDATE_pointerArray(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
282#define NV_FLOW_REFLECT_VALIDATE_valueVersioned(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
283#define NV_FLOW_REFLECT_VALIDATE_pointerVersioned(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
284#define NV_FLOW_REFLECT_VALIDATE_arrayVersioned(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
285#define NV_FLOW_REFLECT_VALIDATE_pointerArrayVersioned(type, name) NV_FLOW_REFLECT_XCONCAT(type,_NvFlowValidatePtrPtrPtr)(&((NV_FLOW_REFLECT_TYPE*)0)->name)
286#else
287#define NV_FLOW_REFLECT_VALIDATE_value(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
288#define NV_FLOW_REFLECT_VALIDATE_pointer(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
289#define NV_FLOW_REFLECT_VALIDATE_array(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
290#define NV_FLOW_REFLECT_VALIDATE_pointerArray(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
291#define NV_FLOW_REFLECT_VALIDATE_valueVersioned(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
292#define NV_FLOW_REFLECT_VALIDATE_pointerVersioned(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
293#define NV_FLOW_REFLECT_VALIDATE_arrayVersioned(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
294#define NV_FLOW_REFLECT_VALIDATE_pointerArrayVersioned(type, name) (&((NV_FLOW_REFLECT_TYPE*)0)->name)
295#endif
296
297#define NV_FLOW_REFLECT_BUILTIN_IMPL(enumName, typeName) \
298 static const NvFlowReflectDataType NV_FLOW_REFLECT_XCONCAT(typeName,_NvFlowReflectDataType) = { enumName, sizeof(typeName), 0, 0, 0, 0 }; \
299 NV_FLOW_REFLECT_VALIDATE(typeName)
300
301#define NV_FLOW_REFLECT_STRUCT_OPAQUE_IMPL(name) \
302 static const NvFlowReflectDataType NV_FLOW_REFLECT_XCONCAT(name,_NvFlowReflectDataType) = { eNvFlowType_struct, 0llu, #name, 0, 0, 0 }; \
303 NV_FLOW_REFLECT_VALIDATE(name)
304
305#define NV_FLOW_REFLECT_BEGIN() \
306 static const NvFlowReflectData NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_reflectDatas)[] = {
307
308#define NV_FLOW_REFLECT_END(defaultValue) \
309 }; \
310 static const NvFlowReflectDataType NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_NvFlowReflectDataType) = { \
311 eNvFlowType_struct, \
312 sizeof(NV_FLOW_REFLECT_TYPE), \
313 NV_FLOW_REFLECT_XSTR(NV_FLOW_REFLECT_TYPE), \
314 NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_reflectDatas), \
315 sizeof(NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_reflectDatas)) / sizeof(NvFlowReflectData), \
316 defaultValue \
317 }; \
318 NV_FLOW_REFLECT_VALIDATE(NV_FLOW_REFLECT_TYPE)
319
320#define NV_FLOW_REFLECT_TYPE_ALIAS(SRC, DST) \
321 typedef SRC DST; \
322 static const NvFlowReflectDataType NV_FLOW_REFLECT_XCONCAT(DST,_NvFlowReflectDataType) = { \
323 eNvFlowType_struct, \
324 sizeof(SRC), \
325 #DST, \
326 NV_FLOW_REFLECT_XCONCAT(SRC,_reflectDatas), \
327 sizeof(NV_FLOW_REFLECT_XCONCAT(SRC,_reflectDatas)) / sizeof(NvFlowReflectData), \
328 &NV_FLOW_REFLECT_XCONCAT(SRC,_default) \
329 }; \
330 NV_FLOW_REFLECT_VALIDATE(DST)
331
332NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_int, int)
333NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_int2, NvFlowInt2)
334NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_int3, NvFlowInt3)
335NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_int4, NvFlowInt4)
336NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint, NvFlowUint)
337NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint2, NvFlowUint2)
338NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint3, NvFlowUint3)
339NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint4, NvFlowUint4)
340NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_float, float)
341NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_float2, NvFlowFloat2)
342NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_float3, NvFlowFloat3)
343NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_float4, NvFlowFloat4)
344NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_float4x4, NvFlowFloat4x4)
345NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_bool32, NvFlowBool32)
346NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint8, NvFlowUint8)
347NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint16, NvFlowUint16)
348NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_uint64, NvFlowUint64)
349NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_char, char)
350NV_FLOW_REFLECT_BUILTIN_IMPL(eNvFlowType_double, double)
351
352#if defined(__cplusplus)
353#define NV_FLOW_REFLECT_SIZE_OFFSET(name_size) (NvFlowUint64)NV_FLOW_REFLECT_VALIDATE_value(NvFlowUint64, name_size)
354#define NV_FLOW_REFLECT_VERSION_OFFSET(version) (NvFlowUint64)NV_FLOW_REFLECT_VALIDATE_value(NvFlowUint64, version)
355#else
356#define NV_FLOW_REFLECT_SIZE_OFFSET(name_size) (NvFlowUint64)(&((NV_FLOW_REFLECT_TYPE*)0)->name_size)
357#define NV_FLOW_REFLECT_VERSION_OFFSET(version) (NvFlowUint64)(&((NV_FLOW_REFLECT_TYPE*)0)->version)
358#endif
359
361#define NV_FLOW_REFLECT_GENERIC(reflectMode, type, name, ARRAY, VERSION, reflectHints, metadata) { \
362 reflectHints, \
363 NV_FLOW_REFLECT_XCONCAT(eNvFlowReflectMode_,reflectMode), \
364 &NV_FLOW_REFLECT_XCONCAT(type,_NvFlowReflectDataType), \
365 #name, \
366 (NvFlowUint64)NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_VALIDATE_,reflectMode)(type, name), \
367 ARRAY, \
368 VERSION, \
369 metadata \
370 },
371#define NV_FLOW_REFLECT_VALUE(type, name, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(value, type, name, 0, 0, reflectHints, metadata)
372#define NV_FLOW_REFLECT_POINTER(type, name, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(pointer, type, name, 0, 0, reflectHints, metadata)
373#define NV_FLOW_REFLECT_ARRAY(type, name, name_size, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(array, type, name, NV_FLOW_REFLECT_SIZE_OFFSET(name_size), 0, reflectHints, metadata)
374#define NV_FLOW_REFLECT_POINTER_ARRAY(type, name, name_size, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(pointerArray, type, name, NV_FLOW_REFLECT_SIZE_OFFSET(name_size), 0, reflectHints, metadata)
375#define NV_FLOW_REFLECT_VALUE_VERSIONED(type, name, version, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(valueVersioned, type, name, 0, NV_FLOW_REFLECT_VERSION_OFFSET(version), reflectHints, metadata)
376#define NV_FLOW_REFLECT_POINTER_VERSIONED(type, name, version, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(pointerVersioned, type, name, 0, NV_FLOW_REFLECT_VERSION_OFFSET(version), reflectHints, metadata)
377#define NV_FLOW_REFLECT_ARRAY_VERSIONED(type, name, name_size, version, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(arrayVersioned, type, name, NV_FLOW_REFLECT_SIZE_OFFSET(name_size), NV_FLOW_REFLECT_VERSION_OFFSET(version), reflectHints, metadata)
378#define NV_FLOW_REFLECT_POINTER_ARRAY_VERSIONED(type, name, name_size, version, reflectHints, metadata) NV_FLOW_REFLECT_GENERIC(pointerArrayVersioned, type, name, NV_FLOW_REFLECT_SIZE_OFFSET(name_size), NV_FLOW_REFLECT_VERSION_OFFSET(version), reflectHints, metadata)
379
381static const NvFlowReflectDataType function_NvFlowReflectDataType = { eNvFlowType_function, 0llu, 0, 0, 0, 0 };
382#define NV_FLOW_REFLECT_FUNCTION_POINTER(name, reflectHints, metadata) { \
383 reflectHints, \
384 eNvFlowReflectMode_pointer, \
385 &function_NvFlowReflectDataType, \
386 #name, \
387 (NvFlowUint64)(&((NV_FLOW_REFLECT_TYPE*)0)->name), \
388 0, \
389 0, \
390 metadata \
391 },
392
394static const NvFlowReflectDataType void_NvFlowReflectDataType = { eNvFlowType_void, 0llu, 0, 0, 0, 0 };
395#define NV_FLOW_REFLECT_VOID_POINTER(name, reflectHints, metadata) { \
396 reflectHints, \
397 eNvFlowReflectMode_pointer, \
398 &void_NvFlowReflectDataType, \
399 #name, \
400 (NvFlowUint64)(&((NV_FLOW_REFLECT_TYPE*)0)->name), \
401 0, \
402 0, \
403 metadata \
404 },
405
407#define NV_FLOW_REFLECT_ENUM(name, reflectHints, metadata) { \
408 reflectHints, \
409 eNvFlowReflectMode_value, \
410 &NvFlowUint_NvFlowReflectDataType, \
411 #name, \
412 (NvFlowUint64)(&((NV_FLOW_REFLECT_TYPE*)0)->name), \
413 0, \
414 0, \
415 metadata \
416 },
417
418#define NV_FLOW_REFLECT_INTERFACE() const NvFlowReflectDataType* interface_NvFlowReflectDataType
419
420#define NV_FLOW_REFLECT_INTERFACE_INIT(type) &NV_FLOW_REFLECT_XCONCAT(type,_NvFlowReflectDataType)
421
422#define NV_FLOW_REFLECT_INTERFACE_IMPL() \
423 NV_FLOW_INLINE void NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_duplicate)(NV_FLOW_REFLECT_TYPE* dst, const NV_FLOW_REFLECT_TYPE* src) \
424 { \
425 dst->interface_NvFlowReflectDataType = &NV_FLOW_REFLECT_XCONCAT(NV_FLOW_REFLECT_TYPE,_NvFlowReflectDataType); \
426 NvFlowReflectCopyByName( \
427 dst, dst->interface_NvFlowReflectDataType, \
428 src, src->interface_NvFlowReflectDataType \
429 ); \
430 }
431
432#define NV_FLOW_REFLECT_TYPE NvFlowReflectData
433NV_FLOW_REFLECT_BEGIN()
434NV_FLOW_REFLECT_VALUE(NvFlowUint, reflectHints, 0, 0)
435NV_FLOW_REFLECT_VALUE(NvFlowUint, reflectMode, 0, 0)
436NV_FLOW_REFLECT_VOID_POINTER(/*NvFlowReflectDataType,*/ dataType, 0, 0) // void to break circular reference
437NV_FLOW_REFLECT_POINTER(char, name, 0, 0)
438NV_FLOW_REFLECT_VALUE(NvFlowUint64, dataOffset, 0, 0)
439NV_FLOW_REFLECT_VALUE(NvFlowUint64, arraySizeOffset, 0, 0)
440NV_FLOW_REFLECT_END(0)
441#undef NV_FLOW_REFLECT_TYPE
442
443#define NV_FLOW_REFLECT_TYPE NvFlowReflectDataType
444NV_FLOW_REFLECT_BEGIN()
445NV_FLOW_REFLECT_ENUM(dataType, 0, 0)
446NV_FLOW_REFLECT_VALUE(NvFlowUint64, elementSize, 0, 0)
447NV_FLOW_REFLECT_POINTER(char, structTypename, 0, 0)
448NV_FLOW_REFLECT_ARRAY(NvFlowReflectData, childReflectDatas, childReflectDataCount, 0, 0)
449NV_FLOW_REFLECT_VOID_POINTER(defaultValue, 0, 0)
450NV_FLOW_REFLECT_END(0)
451#undef NV_FLOW_REFLECT_TYPE
452
453NV_FLOW_INLINE const char* NvFlowReflectTrimPrefix(const char* name)
454{
455 if (name && name[0] == 'N')
456 {
457 name++;
458 }
459 if (name && name[0] == 'v')
460 {
461 name++;
462 }
463 return name;
464}
465
466#define NV_FLOW_CAST_PAIR(X, Y) \
467 NV_FLOW_INLINE X* cast(Y* ptr) { return (X*)ptr; } \
468 NV_FLOW_INLINE Y* cast(X* ptr) { return (Y*)ptr; } \
469 NV_FLOW_INLINE const X* cast(const Y* ptr) { return (X*)ptr; } \
470 NV_FLOW_INLINE const Y* cast(const X* ptr) { return (Y*)ptr; }
471
472#define NV_FLOW_CAST_PAIR_NAMED(name, X, Y) \
473 NV_FLOW_INLINE X* name##_cast(Y* ptr) { return (X*)ptr; } \
474 NV_FLOW_INLINE Y* name##_cast(X* ptr) { return (Y*)ptr; } \
475 NV_FLOW_INLINE const X* name##_cast(const Y* ptr) { return (X*)ptr; } \
476 NV_FLOW_INLINE const Y* name##_cast(const X* ptr) { return (Y*)ptr; }
477
478
480{
481 NvFlowUint64 version;
482 const NvFlowReflectDataType* dataType;
483 NvFlowUint8** instanceDatas;
484 NvFlowUint64 instanceCount;
486
488{
489 NvFlowUint64 version;
490 NvFlowDatabaseTypeSnapshot* typeSnapshots;
491 NvFlowUint64 typeSnapshotCount;
493
494NV_FLOW_INLINE void NvFlowDatabaseSnapshot_findType(const NvFlowDatabaseSnapshot* snapshot, const NvFlowReflectDataType* findDataType, NvFlowDatabaseTypeSnapshot** pSnapshot)
495{
496 // try to find matching pointer first
497 for (NvFlowUint64 idx = 0u; idx < snapshot->typeSnapshotCount; idx++)
498 {
499 if (snapshot->typeSnapshots[idx].dataType == findDataType)
500 {
501 *pSnapshot = &snapshot->typeSnapshots[idx];
502 return;
503 }
504 }
505 // try to find by matching size and name
506 for (NvFlowUint64 idx = 0u; idx < snapshot->typeSnapshotCount; idx++)
507 {
508 if (snapshot->typeSnapshots[idx].dataType->elementSize == findDataType->elementSize &&
509 NvFlowReflectStringCompare(snapshot->typeSnapshots[idx].dataType->structTypename, findDataType->structTypename) == 0)
510 {
511 *pSnapshot = &snapshot->typeSnapshots[idx];
512 return;
513 }
514 }
515 *pSnapshot = 0;
516}
517
518NV_FLOW_INLINE void NvFlowDatabaseSnapshot_findTypeArray(const NvFlowDatabaseSnapshot* snapshot, const NvFlowReflectDataType* findDataType, void*** pData, NvFlowUint64* pCount)
519{
520 NvFlowDatabaseTypeSnapshot* typeSnapshot = 0;
521 NvFlowDatabaseSnapshot_findType(snapshot, findDataType, &typeSnapshot);
522 if (typeSnapshot)
523 {
524 *pData = (void**)typeSnapshot->instanceDatas;
525 *pCount = typeSnapshot->instanceCount;
526 }
527 else
528 {
529 *pData = 0;
530 *pCount = 0llu;
531 }
532}
533
534#define NV_FLOW_DATABASE_SNAPSHOT_FIND_TYPE_ARRAY(snapshot, type) \
535 type** type##_elements = 0; \
536 NvFlowUint64 type##_elementCount = 0llu; \
537 NvFlowDatabaseSnapshot_findTypeArray(snapshot, &type##_NvFlowReflectDataType, (void***)&type##_elements, &type##_elementCount);
538
539#endif
Definition NvFlowReflect.h:488
Definition NvFlowReflect.h:480
Definition NvFlowReflect.h:182
Definition NvFlowReflect.h:170