Index: source/graphics/Color.cpp =================================================================== --- source/graphics/Color.cpp +++ source/graphics/Color.cpp @@ -20,13 +20,13 @@ #include "graphics/Color.h" #include "graphics/SColor.h" +#include "lib/sse.h" #include "maths/MathUtil.h" #include "ps/CLogger.h" #include "ps/CStr.h" #if HAVE_SSE # include -# include "lib/sysdep/arch/x86_x64/x86_x64.h" #endif static SColor4ub fallback_ConvertRGBColorTo4ub(const RGBColor& src) @@ -78,13 +78,9 @@ void ColorActivateFastImpl() { #if HAVE_SSE - if (x86_x64::Cap(x86_x64::CAP_SSE)) - { + if (HasSSE()) ConvertRGBColorTo4ub = sse_ConvertRGBColorTo4ub; - return; - } #endif - debug_printf("No SSE available. Slow fallback routines will be used.\n"); } /** Index: source/lib/sse.h =================================================================== --- /dev/null +++ source/lib/sse.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2020 Wildfire Games. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef INCLUDED_SSE +#define INCLUDED_SSE + +#include "sysdep/compiler.h" + +#if HAVE_SSE +extern bool HasSSE(); +#endif + +#endif INCLUDED_SSE Index: source/lib/sse.cpp =================================================================== --- /dev/null +++ source/lib/sse.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2020 Wildfire Games. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "precompiled.h" + +#include "sse.h" + +#include "code_generation.h" +#include "debug.h" +#include "sysdep/arch.h" + +#if HAVE_SSE +#if ARCH_X86_X64 +# include "sysdep/arch/x86_x64/x86_x64.h" +#endif +bool HasSSE() +{ + bool hasSSE = false; +#if ARCH_X86_X64 + hasSSE = x86_x64::Cap(x86_x64::CAP_SSE); +#else + hasSSE = true; +#endif +#ifndef NDEBUG + ONCE( + if (!hasSSE) + debug_printf("No SSE available. Slow fallback routines will be used.\n"); + ); +#endif + return hasSSE; +} +#endif Index: source/renderer/ModelRenderer.cpp =================================================================== --- source/renderer/ModelRenderer.cpp +++ source/renderer/ModelRenderer.cpp @@ -28,6 +28,7 @@ #include "lib/allocators/arena.h" #include "lib/hash.h" #include "lib/ogl.h" +#include "lib/sse.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" #include "ps/CLogger.h" @@ -48,16 +49,8 @@ /////////////////////////////////////////////////////////////////////////////////////////////// // ModelRenderer implementation -#if ARCH_X86_X64 -static bool g_EnableSSE = false; -#endif - void ModelRenderer::Init() { -#if ARCH_X86_X64 - if (x86_x64::Cap(x86_x64::CAP_SSE)) - g_EnableSSE = true; -#endif } // Helper function to copy object-space position and normal vectors into arrays. @@ -99,7 +92,7 @@ } #if HAVE_SSE - if (g_EnableSSE) + if (HasSSE()) { CModelDef::SkinPointsAndNormals_SSE(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); }