Skip to content

Commit

Permalink
Qt: Add additional early SSE4.1 check on Windows
Browse files Browse the repository at this point in the history
reshadefx uses roundss in std::unordered_map initializers, no other way
to stop this. If it's not reshade, it'll probably be something else.
  • Loading branch information
stenzek committed Dec 3, 2024
1 parent 84a1e20 commit 3ca2579
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/duckstation-qt/vcruntimecheck.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0

#include "common/intrin.h"
#include "common/windows_headers.h"
#include <shellapi.h>

Expand All @@ -15,10 +16,48 @@
static constexpr DWORD64 MIN_VERSION = MAKE_VERSION64(14, 38, 33135, 0);
static constexpr const char* DOWNLOAD_URL = "https://aka.ms/vs/17/release/vc_redist.x64.exe";

#ifdef CPU_ARCH_SSE41

// Can't rely on IsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE) because that was only added in Win10 2004,
// and you can bet that people with such ancient CPUs probably aren't running the latest OS versions either.
ALWAYS_INLINE static bool CheckCPUIDForSSE4()
{
int result[4] = {};

__cpuid(result, 0);
const int max_function_id = result[0];
if (max_function_id >= 1)
{
__cpuid(result, 1);

// The presence of SSE4.1 is indicated by bit 19 of ECX.
return (result[2] & (1 << 19)) != 0;
}

// Function 1 is not supported, so SSE4.1 cannot be present.
return false;
}

#endif

struct VCRuntimeCheckObject
{
VCRuntimeCheckObject()
{
#ifdef CPU_ARCH_SSE41
// We could end up using SSE4 instructions in fmt etc too. Gotta check for it first.
if (!CheckCPUIDForSSE4())
{
MessageBoxW(nullptr,
L"Your CPU does not support the SSE4.1 instruction set. SSE4.1 is required for this version of "
L"DuckStation. Please download and switch to the legacy SSE2 version. You can download this from "
L"www.duckstation.org under \"Other Platforms\".",
L"Hardware Check Failed", MB_OK);
TerminateProcess(GetCurrentProcess(), 0xFFFFFFFF);
return;
}
#endif

const HMODULE crt_handle = GetModuleHandleW(L"msvcp140.dll");
if (!crt_handle)
return;
Expand Down

0 comments on commit 3ca2579

Please sign in to comment.