Skip to content

Commit

Permalink
Hide the D3D11 backend if Windows version is older than Win8
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Feb 14, 2017
1 parent b51bcd2 commit b5034c4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 82 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ add_library(Common STATIC
Common/Misc.cpp
Common/MsgHandler.cpp
Common/MsgHandler.h
Common/OSVersion.cpp
Common/OSVersion.h
Common/StringUtils.cpp
Common/StringUtils.h
Common/ThreadPools.cpp
Expand Down
4 changes: 3 additions & 1 deletion Common/Common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
<ClInclude Include="MemoryUtil.h" />
<ClInclude Include="MipsEmitter.h" />
<ClInclude Include="MsgHandler.h" />
<ClInclude Include="OSVersion.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="StringUtils.h" />
<ClInclude Include="Swap.h" />
Expand Down Expand Up @@ -300,6 +301,7 @@
<ClCompile Include="MipsEmitter.cpp" />
<ClCompile Include="Misc.cpp" />
<ClCompile Include="MsgHandler.cpp" />
<ClCompile Include="OSVersion.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
Expand All @@ -326,4 +328,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion Common/Common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<ClInclude Include="Vulkan\VulkanMemory.h">
<Filter>Vulkan</Filter>
</ClInclude>
<ClInclude Include="OSVersion.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp" />
Expand Down Expand Up @@ -135,6 +136,7 @@
<ClCompile Include="MemArenaWin32.cpp" />
<ClCompile Include="MemArenaAndroid.cpp" />
<ClCompile Include="MemArenaDarwin.cpp" />
<ClCompile Include="OSVersion.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Crypto">
Expand All @@ -150,4 +152,4 @@
<UniqueIdentifier>{c14d66ef-5f7c-4565-975a-72774e7ccfb9}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
</Project>
87 changes: 87 additions & 0 deletions Common/OSVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

#ifdef _MSC_VER

#include <cstdint>
#include "OSVersion.h"
#include "Common/CommonWindows.h"

bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor) {
uint64_t conditionMask = 0;
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwMajorVersion = major;
osvi.dwMinorVersion = minor;
osvi.wServicePackMajor = spMajor;
osvi.wServicePackMinor = spMinor;
uint32_t op = VER_EQUAL;

VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, op);
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, op);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, op);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, op);

const uint32_t typeMask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR;

return VerifyVersionInfo(&osvi, typeMask, conditionMask) != FALSE;
}

std::string GetWindowsVersion() {
const bool IsWindowsXPSP2 = DoesVersionMatchWindows(5, 1, 2, 0);
const bool IsWindowsXPSP3 = DoesVersionMatchWindows(5, 1, 3, 0);
const bool IsWindowsVista = DoesVersionMatchWindows(6, 0);
const bool IsWindowsVistaSP1 = DoesVersionMatchWindows(6, 0, 1, 0);
const bool IsWindowsVistaSP2 = DoesVersionMatchWindows(6, 0, 2, 0);
const bool IsWindows7 = DoesVersionMatchWindows(6, 1);
const bool IsWindows7SP1 = DoesVersionMatchWindows(6, 1, 1, 0);
const bool IsWindows8 = DoesVersionMatchWindows(6, 2);
const bool IsWindows8_1 = DoesVersionMatchWindows(6, 3);

if (IsWindowsXPSP2)
return "Microsoft Windows XP, Service Pack 2";

if (IsWindowsXPSP3)
return "Microsoft Windows XP, Service Pack 3";

if (IsWindowsVista)
return "Microsoft Windows Vista";

if (IsWindowsVistaSP1)
return "Microsoft Windows Vista, Service Pack 1";

if (IsWindowsVistaSP2)
return "Microsoft Windows Vista, Service Pack 2";

if (IsWindows7)
return "Microsoft Windows 7";

if (IsWindows7SP1)
return "Microsoft Windows 7, Service Pack 1";

if (IsWindows8)
return "Microsoft Windows 8 or greater"; // "Applications not manifested for Windows 10 will return the Windows 8 OS version value (6.2)."

if (IsWindows8_1)
return "Microsoft Windows 8.1";

return "Unsupported version of Microsoft Windows.";
}

std::string GetWindowsSystemArchitecture() {
SYSTEM_INFO sysinfo;
ZeroMemory(&sysinfo, sizeof(SYSTEM_INFO));
GetNativeSystemInfo(&sysinfo);

if (sysinfo.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_AMD64)
return "(x64)";
// Need to check for equality here, since ANDing with 0 is always 0.
else if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
return "(x86)";
else if (sysinfo.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_ARM)
return "(ARM)";
else
return "(Unknown)";
}

#endif
11 changes: 11 additions & 0 deletions Common/OSVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <string>

#ifdef _MSC_VER

bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor = 0, uint32_t spMinor = 0);
std::string GetWindowsVersion();
std::string GetWindowsSystemArchitecture();

#endif
8 changes: 8 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include "Common/KeyMap.h"
#include "Common/FileUtil.h"
#include "Common/OSVersion.h"
#include "Core/Config.h"
#include "Core/Host.h"
#include "Core/System.h"
Expand Down Expand Up @@ -159,6 +160,13 @@ void GameSettingsScreen::CreateViews() {
#if !defined(_WIN32)
renderingBackendChoice->HideChoice(1); // D3D9
renderingBackendChoice->HideChoice(2); // D3D11
#else
if (!DoesVersionMatchWindows(6, 2)) {
// Hide the D3D11 choice if Windows version is older than Windows 8.
// We will later be able to support Windows 7 and Vista (unofficially) as well,
// but we currently depend on a texture format that's only available in Win8+.
renderingBackendChoice->HideChoice(2); // D3D11
}
#endif
#if !defined(_WIN32)
// TODO: Add dynamic runtime check for Vulkan support on Android
Expand Down
82 changes: 2 additions & 80 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cmath>

#include "Common/CommonWindows.h"
#include "Common/OSVersion.h"

#include <Wbemidl.h>
#include <shellapi.h>
#include <mmsystem.h>
Expand Down Expand Up @@ -85,86 +87,6 @@ void Vibrate(int length_ms) {
// Ignore on PC
}

bool DoesVersionMatchWindows(const u32 major, const u32 minor, const u32 spMajor = 0, const u32 spMinor = 0) {
u64 conditionMask = 0;
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));

osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwMajorVersion = major;
osvi.dwMinorVersion = minor;
osvi.wServicePackMajor = spMajor;
osvi.wServicePackMinor = spMinor;
u32 op = VER_EQUAL;

VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, op);
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, op);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, op);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, op);

const u32 typeMask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR;

return VerifyVersionInfo(&osvi, typeMask, conditionMask) != FALSE;
}

std::string GetWindowsVersion() {
const bool IsWindowsXPSP2 = DoesVersionMatchWindows(5, 1, 2, 0);
const bool IsWindowsXPSP3 = DoesVersionMatchWindows(5, 1, 3, 0);
const bool IsWindowsVista = DoesVersionMatchWindows(6, 0);
const bool IsWindowsVistaSP1 = DoesVersionMatchWindows(6, 0, 1, 0);
const bool IsWindowsVistaSP2 = DoesVersionMatchWindows(6, 0, 2, 0);
const bool IsWindows7 = DoesVersionMatchWindows(6, 1);
const bool IsWindows7SP1 = DoesVersionMatchWindows(6, 1, 1, 0);
const bool IsWindows8 = DoesVersionMatchWindows(6, 2);
const bool IsWindows8_1 = DoesVersionMatchWindows(6, 3);


if (IsWindowsXPSP2)
return "Microsoft Windows XP, Service Pack 2";

if (IsWindowsXPSP3)
return "Microsoft Windows XP, Service Pack 3";

if (IsWindowsVista)
return "Microsoft Windows Vista";

if (IsWindowsVistaSP1)
return "Microsoft Windows Vista, Service Pack 1";

if (IsWindowsVistaSP2)
return "Microsoft Windows Vista, Service Pack 2";

if (IsWindows7)
return "Microsoft Windows 7";

if (IsWindows7SP1)
return "Microsoft Windows 7, Service Pack 1";

if (IsWindows8)
return "Microsoft Windows 8 or greater"; // "Applications not manifested for Windows 10 will return the Windows 8 OS version value (6.2)."

if (IsWindows8_1)
return "Microsoft Windows 8.1";

return "Unsupported version of Microsoft Windows.";
}

std::string GetWindowsSystemArchitecture() {
SYSTEM_INFO sysinfo;
ZeroMemory(&sysinfo, sizeof(SYSTEM_INFO));
GetNativeSystemInfo(&sysinfo);

if (sysinfo.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_AMD64)
return "(x64)";
// Need to check for equality here, since ANDing with 0 is always 0.
else if (sysinfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
return "(x86)";
else if (sysinfo.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_ARM)
return "(ARM)";
else
return "(Unknown)";
}

// Adapted mostly as-is from http://www.gamedev.net/topic/495075-how-to-retrieve-info-about-videocard/?view=findpost&p=4229170
// so credit goes to that post's author, and in turn, the author of the site mentioned in that post (which seems to be down?).
std::string GetVideoCardDriverVersion() {
Expand Down

0 comments on commit b5034c4

Please sign in to comment.