From e36360122618b10214da0a3d6d7dbdbc1fb6fff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Sun, 13 Jul 2025 00:55:26 +0300 Subject: [PATCH] [Windows] Add SSE4.2 support runtime check. --- platform/windows/SCsub | 15 ++++++- platform/windows/cpu_feature_validation.c | 50 +++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 platform/windows/cpu_feature_validation.c diff --git a/platform/windows/SCsub b/platform/windows/SCsub index 338b6f4d1d7..df76b475880 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -37,6 +37,20 @@ common_win_wrap = [ "console_wrapper_windows.cpp", ] +env_wrap = env.Clone() + +if env["arch"] == "x86_64": + env_cpp_check = env.Clone() + env_cpp_check.add_source_files(sources, ["cpu_feature_validation.c"]) + if env.msvc: + if "/d2archSSE42" in env_cpp_check["CCFLAGS"]: + env_cpp_check["CCFLAGS"].remove("/d2archSSE42") + env.Append(LINKFLAGS=["/ENTRY:ShimMainCRTStartup"]) + else: + if "-msse4.2" in env_cpp_check["CCFLAGS"]: + env_cpp_check["CCFLAGS"].remove("-msse4.2") + env.Append(LINKFLAGS=["-Wl,--entry=ShimMainCRTStartup"]) + def arrange_program_clean(prog): """ @@ -74,7 +88,6 @@ if env.msvc: # Build console wrapper app. if env["windows_subsystem"] == "gui": - env_wrap = env.Clone() res_wrap_file = "godot_res_wrap.rc" res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"] res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file) diff --git a/platform/windows/cpu_feature_validation.c b/platform/windows/cpu_feature_validation.c new file mode 100644 index 00000000000..ce52ba95d9e --- /dev/null +++ b/platform/windows/cpu_feature_validation.c @@ -0,0 +1,50 @@ +/**************************************************************************/ +/* cpu_feature_validation.c */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 + +#ifdef WINDOWS_SUBSYSTEM_CONSOLE +extern int WINAPI mainCRTStartup(); +#else +extern int WINAPI WinMainCRTStartup(); +#endif + +extern int WINAPI ShimMainCRTStartup() { + if (IsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE)) { +#ifdef WINDOWS_SUBSYSTEM_CONSOLE + return mainCRTStartup(); +#else + return WinMainCRTStartup(); +#endif + } else { + MessageBoxW(NULL, L"A CPU with SSE4.2 instruction set support is required.", L"Godot Engine", MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); + return -1; + } +}