Skip to content

Commit bd84c29

Browse files
committed
Merge pull request godotengine#108561 from bruvzg/win_sse42_check
[Windows] Add SSE4.2 support runtime check.
2 parents 7d77683 + e363601 commit bd84c29

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

platform/windows/SCsub

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ common_win_wrap = [
3737
"console_wrapper_windows.cpp",
3838
]
3939

40+
env_wrap = env.Clone()
41+
42+
if env["arch"] == "x86_64":
43+
env_cpp_check = env.Clone()
44+
env_cpp_check.add_source_files(sources, ["cpu_feature_validation.c"])
45+
if env.msvc:
46+
if "/d2archSSE42" in env_cpp_check["CCFLAGS"]:
47+
env_cpp_check["CCFLAGS"].remove("/d2archSSE42")
48+
env.Append(LINKFLAGS=["/ENTRY:ShimMainCRTStartup"])
49+
else:
50+
if "-msse4.2" in env_cpp_check["CCFLAGS"]:
51+
env_cpp_check["CCFLAGS"].remove("-msse4.2")
52+
env.Append(LINKFLAGS=["-Wl,--entry=ShimMainCRTStartup"])
53+
4054

4155
def arrange_program_clean(prog):
4256
"""
@@ -74,7 +88,6 @@ if env.msvc:
7488

7589
# Build console wrapper app.
7690
if env["windows_subsystem"] == "gui":
77-
env_wrap = env.Clone()
7891
res_wrap_file = "godot_res_wrap.rc"
7992
res_wrap_target = "godot_res_wrap" + env["OBJSUFFIX"]
8093
res_wrap_obj = env_wrap.RES(res_wrap_target, res_wrap_file)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**************************************************************************/
2+
/* cpu_feature_validation.c */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include <windows.h>
32+
33+
#ifdef WINDOWS_SUBSYSTEM_CONSOLE
34+
extern int WINAPI mainCRTStartup();
35+
#else
36+
extern int WINAPI WinMainCRTStartup();
37+
#endif
38+
39+
extern int WINAPI ShimMainCRTStartup() {
40+
if (IsProcessorFeaturePresent(PF_SSE4_2_INSTRUCTIONS_AVAILABLE)) {
41+
#ifdef WINDOWS_SUBSYSTEM_CONSOLE
42+
return mainCRTStartup();
43+
#else
44+
return WinMainCRTStartup();
45+
#endif
46+
} else {
47+
MessageBoxW(NULL, L"A CPU with SSE4.2 instruction set support is required.", L"Godot Engine", MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
48+
return -1;
49+
}
50+
}

0 commit comments

Comments
 (0)