From 5000d27d993d9ac33ef80482eb44235298d5177e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 22 Mar 2018 18:08:19 -0400 Subject: Tidy up of Renderer (#452) * Fixed some small typos in api-users-guide.md * Fix some small typos in slang-test/main.cpp, render-test/render-d3d11.cpp * Remove exit() calls from test code. Added Slang::Result, which works in the same way as COM HRESULT. * FIx bug introduced when moving to Slang::Result - handling E_INVALIDARG on Dx11. * Fix the testing of feature levels on Dx11 renderer. * First attempt at README.md for slang-test. * Tidied up the slang-test README.md file. * Fix some small typos in tools/slang-test/main.cpp * Fix spaces -> tabs problems. Fix some small types. * Refactor Renderer implementations such that: * Class definition does not contain long implementation/s * Removed unused globals * Ordered implementation after class definition * Made renderer specific classes child classes, and use Impl postfix to differentiate * Converted tabs into spaces * First pass at Slang::ComPtr. Added slang-defines.h which sets up some fairly commonly used defines such as SLANG_FORCE_INLINE, compiler detection, os detection, and some other cross platform features. * * Fixed bug in vk renderer - where features structure not initialized on hkCreateDevice * Make member variables in Renderer implementations use prefix * Updated test README.md to document that free parameter can control what test is run * * changed setClearColor to take an array of 4 floats to make API clearer on usage * mix of type usage style - defaulted to more conventional style * * Fixed swapWith * Use SLANG_FORCE_INLINE * Don't bother initializing List data when type is POD * Added convenience macro for Result handling SLANG_RETURN_NULL_ON_ERROR --- source/core/list.h | 36 +++++++++++++++--------------------- source/core/slang-result.h | 2 ++ 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'source') diff --git a/source/core/list.h b/source/core/list.h index 68563f20c..6c4a04fc7 100644 --- a/source/core/list.h +++ b/source/core/list.h @@ -4,6 +4,7 @@ #include "allocator.h" #include "slang-math.h" #include "array-view.h" +#include "slang-defines.h" #include #include @@ -29,6 +30,17 @@ namespace Slang new (buffer + i) T(); } }; + template + class Initializer + { + public: + static void Initialize(T * buffer, int size) + { + // It's pod so no initialization required + //for (int i = 0; i < size; i++) + // new (buffer + i) T; + } + }; template class AllocateMethod @@ -67,16 +79,6 @@ namespace Slang } }; - template - class Initializer - { - public: - static void Initialize(T * buffer, int size) - { - for (int i = 0; i class List @@ -201,10 +203,10 @@ namespace Slang T* tmpBuffer = this->buffer; this->buffer = other.buffer; other.buffer = tmpBuffer; - int tmpBufferSize = this->bufferSize; + auto tmpBufferSize = this->bufferSize; this->bufferSize = other.bufferSize; other.bufferSize = tmpBufferSize; - int tmpCount = this->_count; + auto tmpCount = this->_count; this->_count = other._count; other._count = tmpCount; TAllocator tmpAlloc = _Move(this->allocator); @@ -468,15 +470,7 @@ namespace Slang } } -#ifndef FORCE_INLINE -#ifdef _MSC_VER -#define FORCE_INLINE __forceinline -#else -#define FORCE_INLINE inline -#endif -#endif - - FORCE_INLINE T & operator [](UInt id) const + SLANG_FORCE_INLINE T & operator [](UInt id) const { #if _DEBUG if(id >= _count) diff --git a/source/core/slang-result.h b/source/core/slang-result.h index da88c18b2..767d2c737 100644 --- a/source/core/slang-result.h +++ b/source/core/slang-result.h @@ -115,6 +115,8 @@ It can be useful to have a consistent short name for a facility, as used in the #define SLANG_RETURN_VOID_ON_FAIL(x) { SlangResult _res = (x); if (SLANG_FAILED(_res)) { SLANG_HANDLE_RESULT_FAIL(_res); return; } } //! Helper macro that will return false on failure. #define SLANG_RETURN_FALSE_ON_FAIL(x) { SlangResult _res = (x); if (SLANG_FAILED(_res)) { SLANG_HANDLE_RESULT_FAIL(_res); return false; } } +//! Helper macro that will return nullptr on failure. +#define SLANG_RETURN_NULL_ON_FAIL(x) { SlangResult _res = (x); if (SLANG_FAILED(_res)) { SLANG_HANDLE_RESULT_FAIL(_res); return nullptr; } } //! Helper macro that will assert if the return code from a call is failure, also returns the failure. #define SLANG_ASSERT_ON_FAIL(x) { SlangResult _res = (x); if (SLANG_FAILED(_res)) { assert(false); return _res; } } -- cgit v1.2.3