OSDN Git Service

Use static_assert instead of meta macros.
authorNicolas Capens <capn@google.com>
Fri, 27 May 2016 17:19:49 +0000 (13:19 -0400)
committerNicolas Capens <capn@google.com>
Sat, 28 May 2016 15:09:35 +0000 (15:09 +0000)
Change-Id: Id1e3a50d56475c495a3cfb82553c5bd4c48a0fc3
Reviewed-on: https://swiftshader-review.googlesource.com/5425
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/Common/MetaMacro.hpp [deleted file]
src/D3D9/Capabilities.hpp
src/OpenGL/common/debug.h
src/OpenGL/libEGL/Config.cpp
src/OpenGL/libGLES_CM/libGLES_CM.cbp
src/OpenGL/libGLESv2/libGLESv2.cbp
src/Renderer/PixelProcessor.cpp
src/Renderer/Sampler.cpp
src/Renderer/Vertex.hpp
src/SwiftShader/SwiftShader.vcxproj
src/SwiftShader/SwiftShader.vcxproj.filters

diff --git a/src/Common/MetaMacro.hpp b/src/Common/MetaMacro.hpp
deleted file mode 100644 (file)
index f717d75..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-// 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
index 768ad1d..27bf193 100644 (file)
@@ -16,7 +16,6 @@
 #define D3D9_Capabilities_hpp
 
 #include "Config.hpp"
-#include "MetaMacro.hpp"
 
 #include <d3d9.h>
 
@@ -479,18 +478,18 @@ namespace D3D9
        };
 
        // Shader Model 3.0 requirements
-       META_ASSERT(MAX_VERTEX_SHADER_CONST >= 256);
-       META_ASSERT(MAX_PIXEL_SHADER_CONST == 224);
-       META_ASSERT(MAX_VERTEX_INPUTS == 16);
-       META_ASSERT(MAX_VERTEX_OUTPUTS == 12);
-       META_ASSERT(MAX_PIXEL_INPUTS == 10);
+       static_assert(MAX_VERTEX_SHADER_CONST >= 256, "");
+       static_assert(MAX_PIXEL_SHADER_CONST == 224, "");
+       static_assert(MAX_VERTEX_INPUTS == 16, "");
+       static_assert(MAX_VERTEX_OUTPUTS == 12, "");
+       static_assert(MAX_PIXEL_INPUTS == 10, "");
 
        // Back-end minimum requirements
-       META_ASSERT(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST);
-       META_ASSERT(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST);
-       META_ASSERT(sw::MAX_VERTEX_INPUTS >= MAX_VERTEX_INPUTS);
-       META_ASSERT(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS);
-       META_ASSERT(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS);
+       static_assert(sw::VERTEX_UNIFORM_VECTORS >= MAX_VERTEX_SHADER_CONST, "");
+       static_assert(sw::FRAGMENT_UNIFORM_VECTORS >= MAX_PIXEL_SHADER_CONST, "");
+       static_assert(sw::MAX_VERTEX_INPUTS >= MAX_VERTEX_INPUTS, "");
+       static_assert(sw::MAX_VERTEX_OUTPUTS >= MAX_VERTEX_OUTPUTS, "");
+       static_assert(sw::MAX_FRAGMENT_INPUTS >= MAX_PIXEL_INPUTS, "");
 }
 
 #endif   // D3D9_Capabilities_hpp
index dc8ea98..bbf7521 100644 (file)
@@ -90,7 +90,4 @@ namespace es
 
 #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_
index 9a5839e..835b198 100644 (file)
@@ -211,10 +211,10 @@ bool CompareConfig::operator()(const Config &x, const Config &y) const
                        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);
 
-       META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER);
+       static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
        SORT_SMALLER(mColorBufferType);
 
        SORT_SMALLER(mRedSize);
@@ -300,10 +300,10 @@ bool SortConfig::operator()(const Config *x, const Config *y) const
                        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);
 
-       META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER);
+       static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "");
        SORT_SMALLER(mColorBufferType);
 
        // By larger total number of color bits, only considering those that are requested to be > 0.
index 770fe95..a35b6f8 100644 (file)
                <Unit filename="../../Common/Math.hpp" />
                <Unit filename="../../Common/Memory.cpp" />
                <Unit filename="../../Common/Memory.hpp" />
-               <Unit filename="../../Common/MetaMacro.hpp" />
                <Unit filename="../../Common/MutexLock.hpp" />
                <Unit filename="../../Common/Resource.cpp" />
                <Unit filename="../../Common/Resource.hpp" />
index 980889b..e4ea4a4 100644 (file)
                <Unit filename="../../Common/Math.hpp" />
                <Unit filename="../../Common/Memory.cpp" />
                <Unit filename="../../Common/Memory.hpp" />
-               <Unit filename="../../Common/MetaMacro.hpp" />
                <Unit filename="../../Common/MutexLock.hpp" />
                <Unit filename="../../Common/Resource.cpp" />
                <Unit filename="../../Common/Resource.hpp" />
index d8f1be2..e3154b6 100644 (file)
@@ -17,7 +17,6 @@
 #include "PixelPipeline.hpp"
 #include "PixelProgram.hpp"
 #include "PixelShader.hpp"
-#include "MetaMacro.hpp"
 #include "Surface.hpp"
 #include "Primitive.hpp"
 #include "Constants.hpp"
index 7518715..1aa4ccc 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "Sampler.hpp"
 
-#include "MetaMacro.hpp"
 #include "Context.hpp"
 #include "Surface.hpp"
 #include "CPUID.hpp"
index 78bcf14..9ae8d14 100644 (file)
@@ -16,7 +16,6 @@
 #define Vertex_hpp
 
 #include "Color.hpp"
-#include "Common/MetaMacro.hpp"
 #include "Common/Types.hpp"
 #include "Main/Config.hpp"
 
@@ -93,7 +92,7 @@ namespace sw
                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
index 3285351..c2d7c14 100644 (file)
     <ClInclude Include="..\Common\Half.hpp" />\r
     <ClInclude Include="..\Common\Math.hpp" />\r
     <ClInclude Include="..\Common\Memory.hpp" />\r
-    <ClInclude Include="..\Common\MetaMacro.hpp" />\r
     <ClInclude Include="..\Common\MutexLock.hpp" />\r
     <ClInclude Include="..\Common\Resource.hpp" />\r
     <ClInclude Include="..\Common\Timer.hpp" />\r
index e4976e0..b7618d0 100644 (file)
     <ClInclude Include="..\Common\Memory.hpp">\r
       <Filter>Header Files\Common</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="..\Common\MetaMacro.hpp">\r
-      <Filter>Header Files\Common</Filter>\r
-    </ClInclude>\r
     <ClInclude Include="..\Common\MutexLock.hpp">\r
       <Filter>Header Files\Common</Filter>\r
     </ClInclude>\r