[Windows] Add SSE4.2 support runtime check.

This commit is contained in:
Pāvels Nadtočajevs 2025-07-13 00:55:26 +03:00
parent c6d130abd9
commit e363601226
No known key found for this signature in database
GPG key ID: 8413210218EF35D2
2 changed files with 64 additions and 1 deletions

View file

@ -37,6 +37,20 @@ common_win_wrap = [
"console_wrapper_windows.cpp", "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): def arrange_program_clean(prog):
""" """
@ -74,7 +88,6 @@ if env.msvc:
# Build console wrapper app. # Build console wrapper app.
if env["windows_subsystem"] == "gui": if env["windows_subsystem"] == "gui":
env_wrap = env.Clone()
res_wrap_file = "godot_res_wrap.rc" res_wrap_file = "godot_res_wrap.rc"
res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"] res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file) res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)

View file

@ -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 <windows.h>
#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;
}
}