Main Page Class List Class Members

NvBlastMemory.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27
28
29 #ifndef NVBLASTMEMORY_H
30 #define NVBLASTMEMORY_H
31
32 #include <math.h>
33
34 namespace Nv
35 {
36 namespace Blast
37 {
38
39
45 template<typename T>
46 NV_INLINE T align16(T value)
47 {
48 return (value + 0xF)&~(T)0xF;
49 }
50
51
54 template <typename T>
55 NV_INLINE T pointerOffset(void* p, ptrdiff_t offset)
56 {
57 return reinterpret_cast<T>(reinterpret_cast<char*>(p)+offset);
58 }
59
60 template <typename T>
61 NV_INLINE T pointerOffset(const void* p, ptrdiff_t offset)
62 {
63 return reinterpret_cast<T>(reinterpret_cast<const char*>(p)+offset);
64 }
65
66 NV_INLINE const void* pointerOffset(const void* p, ptrdiff_t offset)
67 {
68 return pointerOffset<const void*>(p, offset);
69 }
70
71 NV_INLINE void* pointerOffset(void* p, ptrdiff_t offset)
72 {
73 return pointerOffset<void*>(p, offset);
74 }
75
76 } // namespace Blast
77 } // namespace Nv
78
79
81 #define NvBlastBlockData(_dataType, _name, _accessor) \
82 _dataType* _accessor() const \
83 { \
84 return (_dataType*)((uintptr_t)this + _name); \
85 } \
86 uint32_t _name
87
88
90 #define NvBlastBlockArrayData(_dataType, _name, _accessor, _sizeExpr) \
91 _dataType* _accessor() const \
92 { \
93 return (_dataType*)((uintptr_t)this + _name); \
94 } \
95 uint32_t _accessor##ArraySize() const \
96 { \
97 return _sizeExpr; \
98 } \
99 uint32_t _name
100
101
105 #define NvBlastCreateOffsetStart(_baseOffset) \
106 size_t _lastOffset = _baseOffset; \
107 size_t _lastSize = 0
108
110 #define NvBlastCreateOffsetAlign16(_name, _size) \
111 _name = align16(_lastOffset + _lastSize); \
112 _lastOffset = _name; \
113 _lastSize = _size
114
116 #define NvBlastCreateOffsetEndAlign16() \
117 align16(_lastOffset + _lastSize)
118
119
121 #if NV_WINDOWS_FAMILY
122 #include <malloc.h>
123 #define NvBlastAlloca(x) _alloca(x)
124 #elif NV_LINUX || NV_ANDROID
125 #include <alloca.h>
126 #define NvBlastAlloca(x) alloca(x)
127 #elif NV_APPLE_FAMILY
128 #include <alloca.h>
129 #define NvBlastAlloca(x) alloca(x)
130 #elif NV_PS4
131 #include <memory.h>
132 #define NvBlastAlloca(x) alloca(x)
133 #elif NV_XBOXONE
134 #include <malloc.h>
135 #define NvBlastAlloca(x) alloca(x)
136 #endif
137
138 #define NvBlastAllocaAligned16(x) (void*)(((uintptr_t)PxAlloca(x + 0xF) + 0xF) & ~(uintptr_t)0xF)
139
140
141 #endif // #ifndef NVBLASTMEMORY_H
Nv::Blast::pointerOffset
NV_INLINE T pointerOffset(void *p, ptrdiff_t offset)
Definition: NvBlastMemory.h:55
NV_INLINE
#define NV_INLINE
Definition: NvPreprocessor.h:350
Nv::Blast::align16
NV_INLINE T align16(T value)
Definition: NvBlastMemory.h:46
Nv
Definition: NvBlastArray.h:37