diff options
Diffstat (limited to 'samples/SampleBase/utils')
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/PxInputDataFromPxFileBuf.h | 136 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/SampleProfiler.cpp | 480 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/SampleProfiler.h | 192 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/SampleTime.h | 150 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/UIHelpers.h | 146 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/Utils.cpp | 82 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/SampleBase/utils/Utils.h | 236 |
7 files changed, 711 insertions, 711 deletions
diff --git a/samples/SampleBase/utils/PxInputDataFromPxFileBuf.h b/samples/SampleBase/utils/PxInputDataFromPxFileBuf.h index ff0ab39..e25c5e8 100644..100755 --- a/samples/SampleBase/utils/PxInputDataFromPxFileBuf.h +++ b/samples/SampleBase/utils/PxInputDataFromPxFileBuf.h @@ -1,69 +1,69 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef PXINPUTDATAFROMPXFILEBUF_H -#define PXINPUTDATAFROMPXFILEBUF_H - -#include <PsFileBuffer.h> - - -// Copied from APEX -class PxInputDataFromPxFileBuf : public physx::PxInputData -{ -public: - PxInputDataFromPxFileBuf(physx::PxFileBuf& fileBuf) : mFileBuf(fileBuf) {} - - // physx::PxInputData interface - virtual uint32_t getLength() const - { - return mFileBuf.getFileLength(); - } - - virtual void seek(uint32_t offset) - { - mFileBuf.seekRead(offset); - } - - virtual uint32_t tell() const - { - return mFileBuf.tellRead(); - } - - // physx::PxInputStream interface - virtual uint32_t read(void* dest, uint32_t count) - { - return mFileBuf.read(dest, count); - } - - PX_NOCOPY(PxInputDataFromPxFileBuf) -private: - physx::PxFileBuf& mFileBuf; -}; - - +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef PXINPUTDATAFROMPXFILEBUF_H
+#define PXINPUTDATAFROMPXFILEBUF_H
+
+#include <PsFileBuffer.h>
+
+
+// Copied from APEX
+class PxInputDataFromPxFileBuf : public physx::PxInputData
+{
+public:
+ PxInputDataFromPxFileBuf(physx::PxFileBuf& fileBuf) : mFileBuf(fileBuf) {}
+
+ // physx::PxInputData interface
+ virtual uint32_t getLength() const
+ {
+ return mFileBuf.getFileLength();
+ }
+
+ virtual void seek(uint32_t offset)
+ {
+ mFileBuf.seekRead(offset);
+ }
+
+ virtual uint32_t tell() const
+ {
+ return mFileBuf.tellRead();
+ }
+
+ // physx::PxInputStream interface
+ virtual uint32_t read(void* dest, uint32_t count)
+ {
+ return mFileBuf.read(dest, count);
+ }
+
+ PX_NOCOPY(PxInputDataFromPxFileBuf)
+private:
+ physx::PxFileBuf& mFileBuf;
+};
+
+
#endif //PXINPUTDATAFROMPXFILEBUF_H
\ No newline at end of file diff --git a/samples/SampleBase/utils/SampleProfiler.cpp b/samples/SampleBase/utils/SampleProfiler.cpp index 4bbaeac..43b2754 100644..100755 --- a/samples/SampleBase/utils/SampleProfiler.cpp +++ b/samples/SampleBase/utils/SampleProfiler.cpp @@ -1,240 +1,240 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#include "SampleProfiler.h" -#include <map> -#include <iostream> -#include <fstream> -#include <stack> - -using namespace std::chrono; - -struct ProfileData -{ - steady_clock::time_point start; - - microseconds time; - microseconds prevTime; - microseconds maxTime; - uint32_t calls; - uint32_t prevCalls; - - ProfileData() : time(0), prevTime(0), maxTime(0), calls(0), prevCalls(0) - {} -}; - -struct Node -{ - ProfileData data; - std::map<const char*, Node> childs; - Node* parent; -}; - -static std::map<const char*, Node> s_roots; -static Node* s_currentNode; -static bool s_beginEndMismatch; -static microseconds s_overhead; -static microseconds s_prevOverhead; - -void SampleProfilerInit() -{ - s_roots.clear(); - s_currentNode = nullptr; - s_beginEndMismatch = false; - s_overhead = microseconds(); -} - -void SampleProfilerBegin(const char* name) -{ - auto start = steady_clock::now(); - { - Node* parent = s_currentNode; - if (s_currentNode == nullptr) - { - s_currentNode = &s_roots[name]; - } - else - { - s_currentNode = &s_currentNode->childs[name]; - } - s_currentNode->parent = parent; - s_currentNode->data.calls++; - s_currentNode->data.start = steady_clock::now(); - } - s_overhead += duration_cast<microseconds>(steady_clock::now() - start); -} - -void SampleProfilerEnd() -{ - auto start = steady_clock::now(); - { - if (s_currentNode) - { - auto& data = s_currentNode->data; - data.time += duration_cast<microseconds>(steady_clock::now() - data.start); - data.maxTime = data.time > data.maxTime ? data.time : data.maxTime; - s_currentNode = s_currentNode->parent; - } - else - { - s_beginEndMismatch = true; - } - } - s_overhead += duration_cast<microseconds>(steady_clock::now() - start); -} - -struct SampleProfilerTreeIteratorImpl final : public SampleProfilerTreeIterator -{ - struct StackNode - { - Node* node; - const char* name; - }; - - SampleProfilerTreeIteratorImpl(std::map<const char*, Node>& roots) - { - for (auto& root : roots) - { - m_stack.emplace(StackNode { &root.second, root.first }); - } - - next(); - } - - virtual const Data* data() const override - { - return m_valid ? &m_data : nullptr; - } - - Node* node() - { - return m_node; - } - - virtual bool isDone() const - { - return !m_valid; - } - - virtual void next() - { - if (!m_stack.empty()) - { - auto& e = m_stack.top(); - m_stack.pop(); - m_node = e.node; - m_data.depth = 0; - m_data.hash = (uint64_t)m_node; - for (const Node* p = m_node; p != nullptr; p = p->parent) - { - m_data.depth++; - } - m_data.name = e.name; - m_data.calls = m_node->data.prevCalls; - m_data.time = m_node->data.prevTime; - m_data.maxTime = m_node->data.maxTime; - m_data.hasChilds = !m_node->childs.empty(); - - for (auto it = m_node->childs.rbegin(); it != m_node->childs.rend(); ++it) - { - m_stack.emplace(StackNode { &(*it).second, (*it).first }); - } - m_valid = true; - } - else - { - m_valid = false; - } - } - - virtual void release() - { - delete this; - } - - bool m_valid; - Data m_data; - Node* m_node; - std::stack<StackNode > m_stack; -}; - -void SampleProfilerReset() -{ - for (SampleProfilerTreeIteratorImpl it(s_roots); !it.isDone(); it.next()) - { - auto& data = it.node()->data; - data.prevTime = data.time; - data.prevCalls = data.calls; - data.time = microseconds(); - data.calls = 0; - } - s_currentNode = nullptr; - s_beginEndMismatch = false; - s_prevOverhead = s_overhead; - s_overhead = microseconds(); -} - -bool SampleProfilerIsValid() -{ - return !s_beginEndMismatch; -} - -microseconds SampleProfilerGetOverhead() -{ - return s_prevOverhead; -} - -SampleProfilerTreeIterator* SampleProfilerCreateTreeIterator() -{ - return SampleProfilerIsValid() ? new SampleProfilerTreeIteratorImpl(s_roots) : nullptr; -} - -void SampleProfilerDumpToFile(const char* path) -{ - std::ofstream myfile(path, std::ios_base::out); - if (myfile.is_open()) - { - if (s_beginEndMismatch) - { - myfile << "Error: Begin/End Mismatch.\n"; - } - else - { - myfile << "[Root]\n"; - for(SampleProfilerTreeIteratorImpl it(s_roots); !it.isDone(); it.next()) - { - auto data = it.data(); - for (uint32_t i = 0; i < data->depth; ++i) - myfile << "\t"; - myfile << data->name << " --> calls: " << data->calls << ", total: " << data->time.count() * 0.001 << "ms\n"; - } - } - - myfile.close(); - } -} +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "SampleProfiler.h"
+#include <map>
+#include <iostream>
+#include <fstream>
+#include <stack>
+
+using namespace std::chrono;
+
+struct ProfileData
+{
+ steady_clock::time_point start;
+
+ microseconds time;
+ microseconds prevTime;
+ microseconds maxTime;
+ uint32_t calls;
+ uint32_t prevCalls;
+
+ ProfileData() : time(0), prevTime(0), maxTime(0), calls(0), prevCalls(0)
+ {}
+};
+
+struct Node
+{
+ ProfileData data;
+ std::map<const char*, Node> childs;
+ Node* parent;
+};
+
+static std::map<const char*, Node> s_roots;
+static Node* s_currentNode;
+static bool s_beginEndMismatch;
+static microseconds s_overhead;
+static microseconds s_prevOverhead;
+
+void SampleProfilerInit()
+{
+ s_roots.clear();
+ s_currentNode = nullptr;
+ s_beginEndMismatch = false;
+ s_overhead = microseconds();
+}
+
+void SampleProfilerBegin(const char* name)
+{
+ auto start = steady_clock::now();
+ {
+ Node* parent = s_currentNode;
+ if (s_currentNode == nullptr)
+ {
+ s_currentNode = &s_roots[name];
+ }
+ else
+ {
+ s_currentNode = &s_currentNode->childs[name];
+ }
+ s_currentNode->parent = parent;
+ s_currentNode->data.calls++;
+ s_currentNode->data.start = steady_clock::now();
+ }
+ s_overhead += duration_cast<microseconds>(steady_clock::now() - start);
+}
+
+void SampleProfilerEnd()
+{
+ auto start = steady_clock::now();
+ {
+ if (s_currentNode)
+ {
+ auto& data = s_currentNode->data;
+ data.time += duration_cast<microseconds>(steady_clock::now() - data.start);
+ data.maxTime = data.time > data.maxTime ? data.time : data.maxTime;
+ s_currentNode = s_currentNode->parent;
+ }
+ else
+ {
+ s_beginEndMismatch = true;
+ }
+ }
+ s_overhead += duration_cast<microseconds>(steady_clock::now() - start);
+}
+
+struct SampleProfilerTreeIteratorImpl final : public SampleProfilerTreeIterator
+{
+ struct StackNode
+ {
+ Node* node;
+ const char* name;
+ };
+
+ SampleProfilerTreeIteratorImpl(std::map<const char*, Node>& roots)
+ {
+ for (auto& root : roots)
+ {
+ m_stack.emplace(StackNode { &root.second, root.first });
+ }
+
+ next();
+ }
+
+ virtual const Data* data() const override
+ {
+ return m_valid ? &m_data : nullptr;
+ }
+
+ Node* node()
+ {
+ return m_node;
+ }
+
+ virtual bool isDone() const
+ {
+ return !m_valid;
+ }
+
+ virtual void next()
+ {
+ if (!m_stack.empty())
+ {
+ auto& e = m_stack.top();
+ m_stack.pop();
+ m_node = e.node;
+ m_data.depth = 0;
+ m_data.hash = (uint64_t)m_node;
+ for (const Node* p = m_node; p != nullptr; p = p->parent)
+ {
+ m_data.depth++;
+ }
+ m_data.name = e.name;
+ m_data.calls = m_node->data.prevCalls;
+ m_data.time = m_node->data.prevTime;
+ m_data.maxTime = m_node->data.maxTime;
+ m_data.hasChilds = !m_node->childs.empty();
+
+ for (auto it = m_node->childs.rbegin(); it != m_node->childs.rend(); ++it)
+ {
+ m_stack.emplace(StackNode { &(*it).second, (*it).first });
+ }
+ m_valid = true;
+ }
+ else
+ {
+ m_valid = false;
+ }
+ }
+
+ virtual void release()
+ {
+ delete this;
+ }
+
+ bool m_valid;
+ Data m_data;
+ Node* m_node;
+ std::stack<StackNode > m_stack;
+};
+
+void SampleProfilerReset()
+{
+ for (SampleProfilerTreeIteratorImpl it(s_roots); !it.isDone(); it.next())
+ {
+ auto& data = it.node()->data;
+ data.prevTime = data.time;
+ data.prevCalls = data.calls;
+ data.time = microseconds();
+ data.calls = 0;
+ }
+ s_currentNode = nullptr;
+ s_beginEndMismatch = false;
+ s_prevOverhead = s_overhead;
+ s_overhead = microseconds();
+}
+
+bool SampleProfilerIsValid()
+{
+ return !s_beginEndMismatch;
+}
+
+microseconds SampleProfilerGetOverhead()
+{
+ return s_prevOverhead;
+}
+
+SampleProfilerTreeIterator* SampleProfilerCreateTreeIterator()
+{
+ return SampleProfilerIsValid() ? new SampleProfilerTreeIteratorImpl(s_roots) : nullptr;
+}
+
+void SampleProfilerDumpToFile(const char* path)
+{
+ std::ofstream myfile(path, std::ios_base::out);
+ if (myfile.is_open())
+ {
+ if (s_beginEndMismatch)
+ {
+ myfile << "Error: Begin/End Mismatch.\n";
+ }
+ else
+ {
+ myfile << "[Root]\n";
+ for(SampleProfilerTreeIteratorImpl it(s_roots); !it.isDone(); it.next())
+ {
+ auto data = it.data();
+ for (uint32_t i = 0; i < data->depth; ++i)
+ myfile << "\t";
+ myfile << data->name << " --> calls: " << data->calls << ", total: " << data->time.count() * 0.001 << "ms\n";
+ }
+ }
+
+ myfile.close();
+ }
+}
diff --git a/samples/SampleBase/utils/SampleProfiler.h b/samples/SampleBase/utils/SampleProfiler.h index 644538f..e838ce5 100644..100755 --- a/samples/SampleBase/utils/SampleProfiler.h +++ b/samples/SampleBase/utils/SampleProfiler.h @@ -1,97 +1,97 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef SAMPLEPROFILER_H -#define SAMPLEPROFILER_H - -#include <chrono> - -#if NV_PROFILE - -void SampleProfilerInit(); -void SampleProfilerBegin(const char* name); -void SampleProfilerEnd(); -void SampleProfilerReset(); - -struct SampleProfilerScoped -{ - SampleProfilerScoped(const char* name) - { - SampleProfilerBegin(name); - } - - ~SampleProfilerScoped() - { - SampleProfilerEnd(); - } -}; - -#define PROFILER_INIT() SampleProfilerInit() -#define PROFILER_BEGIN(x) SampleProfilerBegin(x) -#define PROFILER_END() SampleProfilerEnd() -#define PROFILER_SCOPED(x) SampleProfilerScoped __scopedProfiler__(x) -#define PROFILER_SCOPED_FUNCTION() SampleProfilerScoped __scopedProfiler__(__FUNCTION__) -#define PROFILER_RESET() SampleProfilerReset() - -#else - -#define PROFILER_INIT() -#define PROFILER_BEGIN(x) -#define PROFILER_END() -#define PROFILER_SCOPED(x) -#define PROFILER_SCOPED_FUNCTION() -#define PROFILER_RESET() - -#endif - -void SampleProfilerDumpToFile(const char* path); -bool SampleProfilerIsValid(); -std::chrono::microseconds SampleProfilerGetOverhead(); - -struct SampleProfilerTreeIterator -{ - struct Data - { - uint64_t hash; - const char* name; - bool hasChilds; - uint32_t depth; - std::chrono::microseconds time; - std::chrono::microseconds maxTime; - uint32_t calls; - }; - - virtual const Data* data() const = 0; - virtual bool isDone() const = 0; - virtual void next() = 0; - virtual void release() = 0; -}; - -SampleProfilerTreeIterator* SampleProfilerCreateTreeIterator(); - +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef SAMPLEPROFILER_H
+#define SAMPLEPROFILER_H
+
+#include <chrono>
+
+#if NV_PROFILE
+
+void SampleProfilerInit();
+void SampleProfilerBegin(const char* name);
+void SampleProfilerEnd();
+void SampleProfilerReset();
+
+struct SampleProfilerScoped
+{
+ SampleProfilerScoped(const char* name)
+ {
+ SampleProfilerBegin(name);
+ }
+
+ ~SampleProfilerScoped()
+ {
+ SampleProfilerEnd();
+ }
+};
+
+#define PROFILER_INIT() SampleProfilerInit()
+#define PROFILER_BEGIN(x) SampleProfilerBegin(x)
+#define PROFILER_END() SampleProfilerEnd()
+#define PROFILER_SCOPED(x) SampleProfilerScoped __scopedProfiler__(x)
+#define PROFILER_SCOPED_FUNCTION() SampleProfilerScoped __scopedProfiler__(__FUNCTION__)
+#define PROFILER_RESET() SampleProfilerReset()
+
+#else
+
+#define PROFILER_INIT()
+#define PROFILER_BEGIN(x)
+#define PROFILER_END()
+#define PROFILER_SCOPED(x)
+#define PROFILER_SCOPED_FUNCTION()
+#define PROFILER_RESET()
+
+#endif
+
+void SampleProfilerDumpToFile(const char* path);
+bool SampleProfilerIsValid();
+std::chrono::microseconds SampleProfilerGetOverhead();
+
+struct SampleProfilerTreeIterator
+{
+ struct Data
+ {
+ uint64_t hash;
+ const char* name;
+ bool hasChilds;
+ uint32_t depth;
+ std::chrono::microseconds time;
+ std::chrono::microseconds maxTime;
+ uint32_t calls;
+ };
+
+ virtual const Data* data() const = 0;
+ virtual bool isDone() const = 0;
+ virtual void next() = 0;
+ virtual void release() = 0;
+};
+
+SampleProfilerTreeIterator* SampleProfilerCreateTreeIterator();
+
#endif //SAMPLEPROFILER_H
\ No newline at end of file diff --git a/samples/SampleBase/utils/SampleTime.h b/samples/SampleBase/utils/SampleTime.h index 0de529f..876f86b 100644..100755 --- a/samples/SampleBase/utils/SampleTime.h +++ b/samples/SampleBase/utils/SampleTime.h @@ -1,76 +1,76 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef SAMPLE_TIME_H -#define SAMPLE_TIME_H - -#include <stdint.h> - -class Time -{ -public: - Time() : m_lastTickCount(getTimeTicks()) {} - - double Time::getElapsedSeconds() - { - const int64_t lastTickCount = m_lastTickCount; - m_lastTickCount = getTimeTicks(); - return (m_lastTickCount - lastTickCount) * s_secondsPerTick; - } - - double Time::peekElapsedSeconds() const - { - return (getTimeTicks() - m_lastTickCount) * s_secondsPerTick; - } - - double Time::getLastTime() const - { - return m_lastTickCount * s_secondsPerTick; - } - -private: - static double getTickDuration() - { - LARGE_INTEGER a; - QueryPerformanceFrequency(&a); - return 1.0 / (double)a.QuadPart; - } - - int64_t getTimeTicks() const - { - LARGE_INTEGER a; - QueryPerformanceCounter(&a); - return a.QuadPart; - } - - int64_t m_lastTickCount; - static const double s_secondsPerTick; -}; - - +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef SAMPLE_TIME_H
+#define SAMPLE_TIME_H
+
+#include <stdint.h>
+
+class Time
+{
+public:
+ Time() : m_lastTickCount(getTimeTicks()) {}
+
+ double Time::getElapsedSeconds()
+ {
+ const int64_t lastTickCount = m_lastTickCount;
+ m_lastTickCount = getTimeTicks();
+ return (m_lastTickCount - lastTickCount) * s_secondsPerTick;
+ }
+
+ double Time::peekElapsedSeconds() const
+ {
+ return (getTimeTicks() - m_lastTickCount) * s_secondsPerTick;
+ }
+
+ double Time::getLastTime() const
+ {
+ return m_lastTickCount * s_secondsPerTick;
+ }
+
+private:
+ static double getTickDuration()
+ {
+ LARGE_INTEGER a;
+ QueryPerformanceFrequency(&a);
+ return 1.0 / (double)a.QuadPart;
+ }
+
+ int64_t getTimeTicks() const
+ {
+ LARGE_INTEGER a;
+ QueryPerformanceCounter(&a);
+ return a.QuadPart;
+ }
+
+ int64_t m_lastTickCount;
+ static const double s_secondsPerTick;
+};
+
+
#endif
\ No newline at end of file diff --git a/samples/SampleBase/utils/UIHelpers.h b/samples/SampleBase/utils/UIHelpers.h index 15a9169..3f0e29a 100644..100755 --- a/samples/SampleBase/utils/UIHelpers.h +++ b/samples/SampleBase/utils/UIHelpers.h @@ -1,74 +1,74 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef UI_HELPERS_H -#define UI_HELPERS_H - -#include "imgui.h" -#include "PxVec3.h" - - -static void ImGui_DragFloat3Dir(const char* label, float v[3]) -{ - if (ImGui::Button("Normalize")) - { - ((physx::PxVec3*)v)->normalize(); - } - ImGui::SameLine(); - ImGui::DragFloat3(label, v); -}; - - -#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) - -template<int valuesCount = 90> -class PlotLinesInstance -{ -public: - PlotLinesInstance() - { - memset(m_values, 0, sizeof(float) * valuesCount); - } - - void plot(const char* label, float newValue, const char* overlay_text, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 80)) - { - for (; ImGui::GetTime() > m_time + 1.0f / 60.0f; m_time += 1.0f / 60.0f) - { - m_values[m_offset] = newValue; - m_offset = (m_offset + 1) % valuesCount; - } - ImGui::PlotLines(label, m_values, valuesCount, m_offset, overlay_text, scale_min, scale_max, graph_size); - } - -private: - float m_values[valuesCount]; - int m_offset; - float m_time = ImGui::GetTime(); -}; - +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef UI_HELPERS_H
+#define UI_HELPERS_H
+
+#include "imgui.h"
+#include "PxVec3.h"
+
+
+static void ImGui_DragFloat3Dir(const char* label, float v[3])
+{
+ if (ImGui::Button("Normalize"))
+ {
+ ((physx::PxVec3*)v)->normalize();
+ }
+ ImGui::SameLine();
+ ImGui::DragFloat3(label, v);
+};
+
+
+#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR)))
+
+template<int valuesCount = 90>
+class PlotLinesInstance
+{
+public:
+ PlotLinesInstance()
+ {
+ memset(m_values, 0, sizeof(float) * valuesCount);
+ }
+
+ void plot(const char* label, float newValue, const char* overlay_text, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 80))
+ {
+ for (; ImGui::GetTime() > m_time + 1.0f / 60.0f; m_time += 1.0f / 60.0f)
+ {
+ m_values[m_offset] = newValue;
+ m_offset = (m_offset + 1) % valuesCount;
+ }
+ ImGui::PlotLines(label, m_values, valuesCount, m_offset, overlay_text, scale_min, scale_max, graph_size);
+ }
+
+private:
+ float m_values[valuesCount];
+ int m_offset;
+ float m_time = ImGui::GetTime();
+};
+
#endif //UI_HELPERS_H
\ No newline at end of file diff --git a/samples/SampleBase/utils/Utils.cpp b/samples/SampleBase/utils/Utils.cpp index 7a9b2e5..41677f7 100644..100755 --- a/samples/SampleBase/utils/Utils.cpp +++ b/samples/SampleBase/utils/Utils.cpp @@ -1,41 +1,41 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#include "Utils.h" - -#include <string> -#include <cstdarg> - -HRESULT messagebox_printf(const char* caption, UINT mb_type, const char* format, ...) -{ - va_list args; - va_start(args, format); - char formatted_text[512]; - _vsnprintf(formatted_text, 512, format, args); - return MessageBoxA(nullptr, formatted_text, caption, mb_type); -} +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#include "Utils.h"
+
+#include <string>
+#include <cstdarg>
+
+HRESULT messagebox_printf(const char* caption, UINT mb_type, const char* format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ char formatted_text[512];
+ _vsnprintf(formatted_text, 512, format, args);
+ return MessageBoxA(nullptr, formatted_text, caption, mb_type);
+}
diff --git a/samples/SampleBase/utils/Utils.h b/samples/SampleBase/utils/Utils.h index 4a1e15c..507257b 100644..100755 --- a/samples/SampleBase/utils/Utils.h +++ b/samples/SampleBase/utils/Utils.h @@ -1,119 +1,119 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and 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. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved. - - -#ifndef UTILS_H -#define UTILS_H - -#include <DeviceManager.h> -#include <assert.h> - -#include "PxPreprocessor.h" - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// MACROS -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -#ifndef V_RETURN -#define V_RETURN(x) \ - { \ - hr = (x); \ - if(FAILED(hr)) \ - { \ - return hr; \ - } \ - } -#endif - -#ifndef V -#define V(x) \ - { \ - HRESULT hr = (x); \ - _ASSERT(SUCCEEDED(hr)); \ - } -#endif - -#ifndef SAFE_RELEASE -#define SAFE_RELEASE(p) \ - { \ - if(p) \ - { \ - (p)->Release(); \ - (p) = NULL; \ - } \ - } -#endif - -#ifndef SAFE_DELETE -#define SAFE_DELETE(p) \ - { \ - if(p) \ - { \ - delete (p); \ - (p) = NULL; \ - } \ - } -#endif - -#define ASSERT_PRINT(cond, format, ...) \ - if(!(cond)) \ - { \ - messagebox_printf("Assertion Failed!", MB_OK | MB_ICONERROR, #cond "\n" format, __VA_ARGS__); \ - assert(cond); \ - } - -HRESULT messagebox_printf(const char* caption, UINT mb_type, const char* format, ...); - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -static const char* strext(const char* str) -{ - const char* ext = NULL; // by default no extension found! - while (str) - { - str = strchr(str, '.'); - if (str) - { - str++; - ext = str; - } - } - return ext; -} - -static inline float lerp(float a, float b, float t) { return a + (b - a) * t; } - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and 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.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
+
+
+#ifndef UTILS_H
+#define UTILS_H
+
+#include <DeviceManager.h>
+#include <assert.h>
+
+#include "PxPreprocessor.h"
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// MACROS
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#ifndef V_RETURN
+#define V_RETURN(x) \
+ { \
+ hr = (x); \
+ if(FAILED(hr)) \
+ { \
+ return hr; \
+ } \
+ }
+#endif
+
+#ifndef V
+#define V(x) \
+ { \
+ HRESULT hr = (x); \
+ _ASSERT(SUCCEEDED(hr)); \
+ }
+#endif
+
+#ifndef SAFE_RELEASE
+#define SAFE_RELEASE(p) \
+ { \
+ if(p) \
+ { \
+ (p)->Release(); \
+ (p) = NULL; \
+ } \
+ }
+#endif
+
+#ifndef SAFE_DELETE
+#define SAFE_DELETE(p) \
+ { \
+ if(p) \
+ { \
+ delete (p); \
+ (p) = NULL; \
+ } \
+ }
+#endif
+
+#define ASSERT_PRINT(cond, format, ...) \
+ if(!(cond)) \
+ { \
+ messagebox_printf("Assertion Failed!", MB_OK | MB_ICONERROR, #cond "\n" format, __VA_ARGS__); \
+ assert(cond); \
+ }
+
+HRESULT messagebox_printf(const char* caption, UINT mb_type, const char* format, ...);
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+static const char* strext(const char* str)
+{
+ const char* ext = NULL; // by default no extension found!
+ while (str)
+ {
+ str = strchr(str, '.');
+ if (str)
+ {
+ str++;
+ ext = str;
+ }
+ }
+ return ext;
+}
+
+static inline float lerp(float a, float b, float t) { return a + (b - a) * t; }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
#endif
\ No newline at end of file |