Index: build/premake/premake5.lua =================================================================== --- build/premake/premake5.lua +++ build/premake/premake5.lua @@ -210,6 +210,11 @@ flags { "MultiProcessorCompile" } + -- Since KB4088875 Windows 7 has a soft requirement for SSE2. + -- Windows 8+ and Firefox ESR52 make it hard requirement. + -- Finally since VS2012 it's enabled implicitely when not set. + vectorextensions "SSE2" + -- use native wchar_t type (not typedef to unsigned short) nativewchar "on" Index: source/graphics/Color.cpp =================================================================== --- source/graphics/Color.cpp +++ source/graphics/Color.cpp @@ -21,12 +21,12 @@ #include "graphics/SColor.h" #include "maths/MathUtil.h" +#include "lib/sse.h" #include "ps/CLogger.h" #include "ps/CStr.h" #if HAVE_SSE -# include -# include "lib/sysdep/arch/x86_x64/x86_x64.h" +#include #endif static SColor4ub fallback_ConvertRGBColorTo4ub(const RGBColor& src) @@ -78,13 +78,12 @@ 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/graphics/ModelDef.h =================================================================== --- source/graphics/ModelDef.h +++ source/graphics/ModelDef.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -209,7 +209,7 @@ * (This is equivalent to looping over SkinPoint and SkinNormal, * but slightly more efficient.) */ - static void SkinPointsAndNormals( + static void(*SkinPointsAndNormals)( size_t numVertices, const VertexArrayIterator& Position, const VertexArrayIterator& Normal, @@ -217,19 +217,6 @@ const size_t* blendIndices, const CMatrix3D newPoseMatrices[]); -#if HAVE_SSE - /** - * SSE-optimised version of SkinPointsAndNormals. - */ - static void SkinPointsAndNormals_SSE( - size_t numVertices, - const VertexArrayIterator& Position, - const VertexArrayIterator& Normal, - const SModelVertex* vertices, - const size_t* blendIndices, - const CMatrix3D newPoseMatrices[]); -#endif - /** * Blend bone matrices together to fill bone palette. */ @@ -285,5 +272,7 @@ RenderDataMap m_RenderData; }; +extern void ModelDefActivateFastImpl(); + #endif Index: source/graphics/ModelDef.cpp =================================================================== --- source/graphics/ModelDef.cpp +++ source/graphics/ModelDef.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #include "ModelDef.h" #include "graphics/SkeletonAnimDef.h" +#include "lib/sse.h" #include "ps/FileIo.h" #include "maths/Vector4D.h" @@ -87,7 +88,16 @@ return result; } -void CModelDef::SkinPointsAndNormals( +void(*CModelDef::SkinPointsAndNormals)( + size_t numVertices, + const VertexArrayIterator& Position, + const VertexArrayIterator& Normal, + const SModelVertex* vertices, + const size_t* blendIndices, + const CMatrix3D newPoseMatrices[]) {}; + + +static void fallback_SkinPointsAndNormals( size_t numVertices, const VertexArrayIterator& Position, const VertexArrayIterator& Normal, @@ -122,7 +132,7 @@ } #if HAVE_SSE -void CModelDef::SkinPointsAndNormals_SSE( +static void sse_SkinPointsAndNormals_SSE( size_t numVertices, const VertexArrayIterator& Position, const VertexArrayIterator& Normal, @@ -471,3 +481,16 @@ return 0; } + + +extern void ModelDefActivateFastImpl() +{ +#if HAVE_SSE + if (HasSSE()) + { + CModelDef::SkinPointsAndNormals = sse_SkinPointsAndNormals_SSE; + return; + } +#endif + CModelDef::SkinPointsAndNormals = fallback_SkinPointsAndNormals; +} 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 "lib/sysdep/compiler.h" + +#if HAVE_SSE +extern inline bool HasSSE(); +#endif + +#endif // INCLUDED_SSE Index: source/lib/sse.cpp =================================================================== --- /dev/null +++ source/lib/sse.cpp @@ -0,0 +1,42 @@ +/* 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 "lib/sse.h" + +#if HAVE_SSE +#include "lib/code_generation.h" +#include "lib/debug.h" +#include "lib/sysdep/arch.h" +#if ARCH_X86_X64 +#include "lib/sysdep/arch/x86_x64/x86_x64.h" +#endif +extern inline bool HasSSE() +{ +#if ARCH_X86_X64 + return x86_x64::Cap(x86_x64::CAP_SSE); +#else + return true; +#endif +} +#endif Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -32,6 +32,7 @@ #include "graphics/GameView.h" #include "graphics/LightEnv.h" #include "graphics/MapReader.h" +#include "graphics/ModelDef.h" #include "graphics/MaterialManager.h" #include "graphics/TerrainTextureManager.h" #include "gui/CGUI.h" @@ -611,7 +612,7 @@ vp.m_Width = g_xres; vp.m_Height = g_yres; g_Renderer.SetViewport(vp); - + ModelDefActivateFastImpl(); ColorActivateFastImpl(); ModelRenderer::Init(); } Index: source/renderer/ModelRenderer.cpp =================================================================== --- source/renderer/ModelRenderer.cpp +++ source/renderer/ModelRenderer.cpp @@ -41,23 +41,11 @@ #include "renderer/TimeManager.h" #include "renderer/WaterManager.h" -#if ARCH_X86_X64 -# include "lib/sysdep/arch/x86_x64/x86_x64.h" -#endif - /////////////////////////////////////////////////////////////////////////////////////////////// // 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. @@ -98,16 +86,7 @@ return; } -#if HAVE_SSE - if (g_EnableSSE) - { - CModelDef::SkinPointsAndNormals_SSE(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); - } - else -#endif - { - CModelDef::SkinPointsAndNormals(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); - } + CModelDef::SkinPointsAndNormals(numVertices, Position, Normal, vertices, mdef->GetBlendIndices(), model->GetAnimatedBoneMatrices()); } else {