00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTMEMORY_H
00030 #define NVBLASTMEMORY_H
00031
00032 #include <math.h>
00033
00034 namespace Nv
00035 {
00036 namespace Blast
00037 {
00038
00039
00045 template<typename T>
00046 NV_INLINE T align16(T value)
00047 {
00048 return (value + 0xF)&~(T)0xF;
00049 }
00050
00051
00054 template <typename T>
00055 NV_INLINE T pointerOffset(void* p, ptrdiff_t offset)
00056 {
00057 return reinterpret_cast<T>(reinterpret_cast<char*>(p)+offset);
00058 }
00059
00060 template <typename T>
00061 NV_INLINE T pointerOffset(const void* p, ptrdiff_t offset)
00062 {
00063 return reinterpret_cast<T>(reinterpret_cast<const char*>(p)+offset);
00064 }
00065
00066 NV_INLINE const void* pointerOffset(const void* p, ptrdiff_t offset)
00067 {
00068 return pointerOffset<const void*>(p, offset);
00069 }
00070
00071 NV_INLINE void* pointerOffset(void* p, ptrdiff_t offset)
00072 {
00073 return pointerOffset<void*>(p, offset);
00074 }
00075
00076 }
00077 }
00078
00079
00081 #define NvBlastBlockData(_dataType, _name, _accessor) \
00082 _dataType* _accessor() const \
00083 { \
00084 return (_dataType*)((uintptr_t)this + _name); \
00085 } \
00086 uint32_t _name
00087
00088
00090 #define NvBlastBlockArrayData(_dataType, _name, _accessor, _sizeExpr) \
00091 _dataType* _accessor() const \
00092 { \
00093 return (_dataType*)((uintptr_t)this + _name); \
00094 } \
00095 uint32_t _accessor##ArraySize() const \
00096 { \
00097 return _sizeExpr; \
00098 } \
00099 uint32_t _name
00100
00101
00105 #define NvBlastCreateOffsetStart(_baseOffset) \
00106 size_t _lastOffset = _baseOffset; \
00107 size_t _lastSize = 0
00108
00110 #define NvBlastCreateOffsetAlign16(_name, _size) \
00111 _name = align16(_lastOffset + _lastSize); \
00112 _lastOffset = _name; \
00113 _lastSize = _size
00114
00116 #define NvBlastCreateOffsetEndAlign16() \
00117 align16(_lastOffset + _lastSize)
00118
00119
00121 #if NV_WINDOWS_FAMILY
00122 #include <malloc.h>
00123 #define NvBlastAlloca(x) _alloca(x)
00124 #elif NV_LINUX || NV_ANDROID
00125 #include <alloca.h>
00126 #define NvBlastAlloca(x) alloca(x)
00127 #elif NV_APPLE_FAMILY
00128 #include <alloca.h>
00129 #define NvBlastAlloca(x) alloca(x)
00130 #elif NV_PS4
00131 #include <memory.h>
00132 #define NvBlastAlloca(x) alloca(x)
00133 #elif NV_XBOXONE
00134 #include <malloc.h>
00135 #define NvBlastAlloca(x) alloca(x)
00136 #endif
00137
00138 #define NvBlastAllocaAligned16(x) (void*)(((uintptr_t)PxAlloca(x + 0xF) + 0xF) & ~(uintptr_t)0xF)
00139
00140
00141 #endif // #ifndef NVBLASTMEMORY_H