diff options
| author | Bryan Galdrikian <[email protected]> | 2017-02-21 12:07:59 -0800 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-02-21 12:07:59 -0800 |
| commit | 446ce137c6823ba9eff273bdafdaf266287c7c98 (patch) | |
| tree | d20aab3e2ed08d7b3ca71c2f40db6a93ea00c459 /NvBlast/sdk/extensions/common/source | |
| download | blast-1.0.0-beta.tar.xz blast-1.0.0-beta.zip | |
first commitv1.0.0-beta
Diffstat (limited to 'NvBlast/sdk/extensions/common/source')
5 files changed, 299 insertions, 0 deletions
diff --git a/NvBlast/sdk/extensions/common/source/NvBlastExtAllocator.h b/NvBlast/sdk/extensions/common/source/NvBlastExtAllocator.h new file mode 100644 index 0000000..d917cbf --- /dev/null +++ b/NvBlast/sdk/extensions/common/source/NvBlastExtAllocator.h @@ -0,0 +1,127 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTEXTALLOCATOR_H +#define NVBLASTEXTALLOCATOR_H + +#include "NvBlastTkFramework.h" +#include "PxAllocatorCallback.h" + + +namespace Nv +{ +namespace Blast +{ + +/** +ExtAllocator uses TkFramework allocator +*/ +class ExtAllocator +{ +public: + ExtAllocator(const char* = 0) + { + } + + void* allocate(size_t size, const char* filename, int line) + { + return NvBlastTkFrameworkGet()->getAllocatorCallback().allocate(size, nullptr, filename, line); + } + + void deallocate(void* ptr) + { + NvBlastTkFrameworkGet()->getAllocatorCallback().deallocate(ptr); + } + + + /** + Aligned allocation. + + Example using 16-byte alignment: + + // b will lie on a 16-byte boundary and point to 50 bytes of usable memory + void* b = alignedAlloc<16>(50); + */ + template<int A> + static void* alignedAlloc(size_t size, const char* filename, int line) + { + NV_COMPILE_TIME_ASSERT(A > 0 && A <= 256); + unsigned char* mem = (unsigned char*)ExtAllocator().allocate(size + A, filename, line); + const unsigned char offset = (unsigned char)((uintptr_t)A - (uintptr_t)mem % A - 1); + mem += offset; + *mem++ = offset; + return mem; + } + + template<int A> + static void* alignedAlloc(size_t size) + { + return alignedAlloc<A>(size, __FILE__, __LINE__); + } + + + /** + Version of alignedAlloc specialized 16-byte aligned allocation. + */ + static void* alignedAlloc16(size_t size) + { + return alignedAlloc<16>(size); + } + + + /** + Aligned deallocation. + + Memory freed using this function MUST have been allocated using alignedAlloc. + + Example using free: + + // Using the memory pointer b from the example above (for alignedAlloc) + alignedFree(b); + */ + static void alignedFree(void* block) + { + if (block != nullptr) + { + unsigned char* mem = (unsigned char*)block; + const unsigned char offset = *--mem; + ExtAllocator().deallocate(mem - offset); + } + }; +}; + + +/** +ExtAlignedAllocator uses ExtAllocator +*/ +template<int A> +class ExtAlignedAllocator +{ +public: + ExtAlignedAllocator(const char* = 0) + { + } + + void* allocate(size_t size, const char* filename, int line) + { + return ExtAllocator::alignedAlloc<A>(size, filename, line); + } + + void deallocate(void* ptr) + { + return ExtAllocator::alignedFree(ptr); + } +}; + +} // namespace Blast +} // namespace Nv + + +#endif // #ifndef NVBLASTEXTALLOCATOR_H diff --git a/NvBlast/sdk/extensions/common/source/NvBlastExtArray.h b/NvBlast/sdk/extensions/common/source/NvBlastExtArray.h new file mode 100644 index 0000000..9ea4777 --- /dev/null +++ b/NvBlast/sdk/extensions/common/source/NvBlastExtArray.h @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTEXTARRAY_H +#define NVBLASTEXTARRAY_H + + +#include "NvBlastExtAllocator.h" +#include "PsInlineArray.h" + + +namespace Nv +{ +namespace Blast +{ + +template <class T> +struct ExtArray +{ + typedef physx::shdfnd::Array<T, ExtAllocator> type; +}; + + +template <class T, uint32_t N> +struct ExtInlineArray +{ + typedef physx::shdfnd::InlineArray<T, N, ExtAllocator> type; +}; + +} // namespace Blast +} // namespace Nv + + +#endif // #ifndef NVBLASTEXTARRAY_H diff --git a/NvBlast/sdk/extensions/common/source/NvBlastExtDefs.h b/NvBlast/sdk/extensions/common/source/NvBlastExtDefs.h new file mode 100644 index 0000000..72b6c1d --- /dev/null +++ b/NvBlast/sdk/extensions/common/source/NvBlastExtDefs.h @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTEXTDEFS_H +#define NVBLASTEXTDEFS_H + +#include "NvBlastTkFramework.h" +#include "PxAllocatorCallback.h" +#include <new> + + +//////// Log macros that use the ExtContext log function //////// + +#define NVBLASTEXT_LOG_ERROR(_msg) NVBLAST_LOG_ERROR(NvBlastTkFrameworkGet()->getLogFn(), _msg) +#define NVBLASTEXT_LOG_WARNING(_msg) NVBLAST_LOG_WARNING(NvBlastTkFrameworkGet()->getLogFn(), _msg) +#define NVBLASTEXT_LOG_INFO(_msg) NVBLAST_LOG_INFO(NvBlastTkFrameworkGet()->getLogFn(), _msg) +#define NVBLASTEXT_LOG_DEBUG(_msg) NVBLAST_LOG_DEBUG(NvBlastTkFrameworkGet()->getLogFn(), _msg) + +#define NVBLASTEXT_CHECK(_expr, _messageType, _msg, _onFail) \ + { \ + if(!(_expr)) \ + { \ + (*NvBlastTkFrameworkGet()->getLogFn())(_messageType, _msg, __FILE__, __LINE__); \ + { _onFail; }; \ + } \ + } + +#define NVBLASTEXT_CHECK_ERROR(_expr, _msg, _onFail) NVBLASTEXT_CHECK(_expr, NvBlastMessage::Error, _msg, _onFail) +#define NVBLASTEXT_CHECK_WARNING(_expr, _msg, _onFail) NVBLASTEXT_CHECK(_expr, NvBlastMessage::Warning, _msg, _onFail) +#define NVBLASTEXT_CHECK_INFO(_expr, _msg, _onFail) NVBLASTEXT_CHECK(_expr, NvBlastMessage::Info, _msg, _onFail) +#define NVBLASTEXT_CHECK_DEBUG(_expr, _msg, _onFail) NVBLASTEXT_CHECK(_expr, NvBlastMessage::Debug, _msg, _onFail) + + +//////// Allocator macros //////// + +/** +Placement new with ExtContext allocation. +Example: Foo* foo = NVBLASTEXT_NEW(Foo, context) (params); +*/ +#define NVBLASTEXT_NEW(T) new (NvBlastTkFrameworkGet()->getAllocatorCallback().allocate(sizeof(T), #T, __FILE__, __LINE__)) T + +/** +Respective delete to NVBLASTEXT_NEW +Example: NVBLASTEXT_DELETE(foo, Foo, context); +*/ +#define NVBLASTEXT_DELETE(obj, T) \ + (obj)->~T(); \ + NvBlastTkFrameworkGet()->getAllocatorCallback().deallocate(obj) + + +//////// Util macros //////// + +// Macro to load a uint32_t (or larger) with four characters +#define NVBLASTEXT_FOURCC(_a, _b, _c, _d) ( (uint32_t)(_a) | (uint32_t)(_b)<<8 | (uint32_t)(_c)<<16 | (uint32_t)(_d)<<24 ) + + +#endif // #ifndef NVBLASTEXTDEFS_H diff --git a/NvBlast/sdk/extensions/common/source/NvBlastExtHashMap.h b/NvBlast/sdk/extensions/common/source/NvBlastExtHashMap.h new file mode 100644 index 0000000..0fa094e --- /dev/null +++ b/NvBlast/sdk/extensions/common/source/NvBlastExtHashMap.h @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTEXTHASHMAP_H +#define NVBLASTEXTHASHMAP_H + + +#include "NvBlastExtAllocator.h" +#include "PsHashMap.h" + + +namespace Nv +{ +namespace Blast +{ + +template <class Key, class Value, class HashFn = physx::shdfnd::Hash<Key>> +struct ExtHashMap +{ + typedef physx::shdfnd::HashMap<Key, Value, HashFn, ExtAllocator> type; +}; + +} // namespace Blast +} // namespace Nv + + +#endif // #ifndef NVBLASTEXTHASHMAP_H diff --git a/NvBlast/sdk/extensions/common/source/NvBlastExtHashSet.h b/NvBlast/sdk/extensions/common/source/NvBlastExtHashSet.h new file mode 100644 index 0000000..97fc0a9 --- /dev/null +++ b/NvBlast/sdk/extensions/common/source/NvBlastExtHashSet.h @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + +#ifndef NVBLASTEXTHASHSET_H +#define NVBLASTEXTHASHSET_H + + +#include "NvBlastExtAllocator.h" +#include "PsHashSet.h" + +namespace Nv +{ +namespace Blast +{ + +template <class Key, class HashFn = physx::shdfnd::Hash<Key>> +struct ExtHashSet +{ + typedef physx::shdfnd::HashSet<Key, HashFn, ExtAllocator> type; +}; + +} // namespace Blast +} // namespace Nv + + +#endif // #ifndef NVBLASTEXTHASHSET_H |