Commit a26bade1 by Nicolas Capens

Use static_assert instead of meta macros.

Change-Id: Id1e3a50d56475c495a3cfb82553c5bd4c48a0fc3 Reviewed-on: https://swiftshader-review.googlesource.com/5425Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 53318fa7
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_MetaMacro_hpp
#define sw_MetaMacro_hpp
// Disables the "identifier was truncated to '255' characters in the browser information" warning
#ifdef _MSC_VER
#pragma warning(disable: 4786)
#endif
namespace Meta
{
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1]
template<class T>
struct IsVoid
{
enum {res = false};
};
template<>
struct IsVoid<void>
{
enum {res = true};
};
#define META_IS_VOID(T) Meta::IsVoid<T>::res
template<bool>
struct Select
{
template<class T0, class T1>
struct Type
{
typedef T1 Res;
};
};
template<>
struct Select<true>
{
template<class T0, class T1>
struct Type
{
typedef T0 Res;
};
};
#define META_SELECT(i, T0, T1) Meta::Select<i>::template Type<T0, T1>::Res
template<class B0, class B1>
struct Inherit : B0, B1
{
};
#define META_INHERIT(B0, B1) Meta::Inherit<B0, B1>
template<class B0, class B1>
class Catenate
{
typedef typename META_SELECT(META_IS_VOID(B0), B1, B0) T0;
typedef typename META_SELECT(META_IS_VOID(B0), void, B1) T1;
public:
typedef typename META_INHERIT(T0, T1) T01;
typedef typename META_SELECT(META_IS_VOID(T1), T0, T01) Res;
private:
typedef typename META_SELECT(META_IS_VOID(T1), int, T1) CheckedT1;
META_ASSERT(META_IS_VOID(T1) || sizeof(Res) == sizeof(T0) + sizeof(CheckedT1));
};
#define META_CATENATE(B0, B1) Meta::Catenate<B0, B1>::Res
template<bool condition, class B0, class B1>
class ConditionalInherit
{
typedef typename META_CATENATE(B0, B1) MetaInherit;
public:
typedef typename META_SELECT(condition, MetaInherit, B0) Res;
};
#define META_CONDITIONAL_INHERIT(condition, B0, B1) Meta::ConditionalInherit<condition, B0, B1>::Res
}
#endif // sw_MetaMacro_hpp
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define D3D9_Capabilities_hpp #define D3D9_Capabilities_hpp
#include "Config.hpp" #include "Config.hpp"
#include "MetaMacro.hpp"
#include <d3d9.h> #include <d3d9.h>
...@@ -479,18 +478,18 @@ namespace D3D9 ...@@ -479,18 +478,18 @@ namespace D3D9
}; };
// Shader Model 3.0 requirements // Shader Model 3.0 requirements
META_ASSERT(MAX_VERTEX_SHADER_CONST >= 256); static_assert(MAX_VERTEX_SHADER_CONST >= 256, "");
META_ASSERT(MAX_PIXEL_SHADER_CONST == 224); static_assert(MAX_PIXEL_SHADER_CONST == 224, "");
META_ASSERT(MAX_VERTEX_INPUTS == 16); static_assert(MAX_VERTEX_INPUTS == 16, "");
META_ASSERT(MAX_VERTEX_OUTPUTS == 12); static_assert(MAX_VERTEX_OUTPUTS == 12, "");
META_ASSERT(MAX_PIXEL_INPUTS == 10); static_assert(MAX_PIXEL_INPUTS == 10, "");
// Back-end minimum requirements // Back-end minimum requirements
META_ASSERT(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST); static_assert(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST, "");
META_ASSERT(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST); static_assert(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST, "");
META_ASSERT(sw::MAX_VERTEX_INPUTS >= MAX_VERTEX_INPUTS); static_assert(sw::MAX_VERTEX_INPUTS >= MAX_VERTEX_INPUTS, "");
META_ASSERT(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS); static_assert(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS, "");
META_ASSERT(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS); static_assert(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS, "");
} }
#endif // D3D9_Capabilities_hpp #endif // D3D9_Capabilities_hpp
...@@ -90,7 +90,4 @@ namespace es ...@@ -90,7 +90,4 @@ namespace es
#endif // __ANDROID__ #endif // __ANDROID__
// A macro functioning as a compile-time assert to validate constant conditions
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1]
#endif // COMMON_DEBUG_H_ #endif // COMMON_DEBUG_H_
...@@ -211,10 +211,10 @@ bool CompareConfig::operator()(const Config &x, const Config &y) const ...@@ -211,10 +211,10 @@ bool CompareConfig::operator()(const Config &x, const Config &y) const
return x.attribute < y.attribute; \ return x.attribute < y.attribute; \
} }
META_ASSERT(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG); static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "");
SORT_SMALLER(mConfigCaveat); SORT_SMALLER(mConfigCaveat);
META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER); static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
SORT_SMALLER(mColorBufferType); SORT_SMALLER(mColorBufferType);
SORT_SMALLER(mRedSize); SORT_SMALLER(mRedSize);
...@@ -300,10 +300,10 @@ bool SortConfig::operator()(const Config *x, const Config *y) const ...@@ -300,10 +300,10 @@ bool SortConfig::operator()(const Config *x, const Config *y) const
return x->attribute < y->attribute; \ return x->attribute < y->attribute; \
} }
META_ASSERT(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG); static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "");
SORT_SMALLER(mConfigCaveat); SORT_SMALLER(mConfigCaveat);
META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER); static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
SORT_SMALLER(mColorBufferType); SORT_SMALLER(mColorBufferType);
// By larger total number of color bits, only considering those that are requested to be > 0. // By larger total number of color bits, only considering those that are requested to be > 0.
......
...@@ -152,7 +152,6 @@ ...@@ -152,7 +152,6 @@
<Unit filename="../../Common/Math.hpp" /> <Unit filename="../../Common/Math.hpp" />
<Unit filename="../../Common/Memory.cpp" /> <Unit filename="../../Common/Memory.cpp" />
<Unit filename="../../Common/Memory.hpp" /> <Unit filename="../../Common/Memory.hpp" />
<Unit filename="../../Common/MetaMacro.hpp" />
<Unit filename="../../Common/MutexLock.hpp" /> <Unit filename="../../Common/MutexLock.hpp" />
<Unit filename="../../Common/Resource.cpp" /> <Unit filename="../../Common/Resource.cpp" />
<Unit filename="../../Common/Resource.hpp" /> <Unit filename="../../Common/Resource.hpp" />
......
...@@ -151,7 +151,6 @@ ...@@ -151,7 +151,6 @@
<Unit filename="../../Common/Math.hpp" /> <Unit filename="../../Common/Math.hpp" />
<Unit filename="../../Common/Memory.cpp" /> <Unit filename="../../Common/Memory.cpp" />
<Unit filename="../../Common/Memory.hpp" /> <Unit filename="../../Common/Memory.hpp" />
<Unit filename="../../Common/MetaMacro.hpp" />
<Unit filename="../../Common/MutexLock.hpp" /> <Unit filename="../../Common/MutexLock.hpp" />
<Unit filename="../../Common/Resource.cpp" /> <Unit filename="../../Common/Resource.cpp" />
<Unit filename="../../Common/Resource.hpp" /> <Unit filename="../../Common/Resource.hpp" />
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "PixelPipeline.hpp" #include "PixelPipeline.hpp"
#include "PixelProgram.hpp" #include "PixelProgram.hpp"
#include "PixelShader.hpp" #include "PixelShader.hpp"
#include "MetaMacro.hpp"
#include "Surface.hpp" #include "Surface.hpp"
#include "Primitive.hpp" #include "Primitive.hpp"
#include "Constants.hpp" #include "Constants.hpp"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "Sampler.hpp" #include "Sampler.hpp"
#include "MetaMacro.hpp"
#include "Context.hpp" #include "Context.hpp"
#include "Surface.hpp" #include "Surface.hpp"
#include "CPUID.hpp" #include "CPUID.hpp"
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define Vertex_hpp #define Vertex_hpp
#include "Color.hpp" #include "Color.hpp"
#include "Common/MetaMacro.hpp"
#include "Common/Types.hpp" #include "Common/Types.hpp"
#include "Main/Config.hpp" #include "Main/Config.hpp"
...@@ -93,7 +92,7 @@ namespace sw ...@@ -93,7 +92,7 @@ namespace sw
int padding[3]; int padding[3];
}); });
META_ASSERT((sizeof(Vertex) & 0x0000000F) == 0); static_assert((sizeof(Vertex) & 0x0000000F) == 0, "Vertex size not a multiple of 16 bytes (alignment requirement)");
} }
#endif // Vertex_hpp #endif // Vertex_hpp
...@@ -432,7 +432,6 @@ ...@@ -432,7 +432,6 @@
<ClInclude Include="..\Common\Half.hpp" /> <ClInclude Include="..\Common\Half.hpp" />
<ClInclude Include="..\Common\Math.hpp" /> <ClInclude Include="..\Common\Math.hpp" />
<ClInclude Include="..\Common\Memory.hpp" /> <ClInclude Include="..\Common\Memory.hpp" />
<ClInclude Include="..\Common\MetaMacro.hpp" />
<ClInclude Include="..\Common\MutexLock.hpp" /> <ClInclude Include="..\Common\MutexLock.hpp" />
<ClInclude Include="..\Common\Resource.hpp" /> <ClInclude Include="..\Common\Resource.hpp" />
<ClInclude Include="..\Common\Timer.hpp" /> <ClInclude Include="..\Common\Timer.hpp" />
......
...@@ -304,9 +304,6 @@ ...@@ -304,9 +304,6 @@
<ClInclude Include="..\Common\Memory.hpp"> <ClInclude Include="..\Common\Memory.hpp">
<Filter>Header Files\Common</Filter> <Filter>Header Files\Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Common\MetaMacro.hpp">
<Filter>Header Files\Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\MutexLock.hpp"> <ClInclude Include="..\Common\MutexLock.hpp">
<Filter>Header Files\Common</Filter> <Filter>Header Files\Common</Filter>
</ClInclude> </ClInclude>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment