mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 15:31:17 +01:00
Merge pull request #776 from shuffle2/improve-xsaveworkaround
Windows: Improve XSaveWorkaround to behave correctly when XSAVE processor feature is enabled, but AVX support isn't available for whatever reason.
This commit is contained in:
commit
edf660f21f
@ -7,6 +7,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
typedef decltype(&GetEnabledXStateFeatures) GetEnabledXStateFeatures_t;
|
||||||
|
|
||||||
int __cdecl EnableXSaveWorkaround()
|
int __cdecl EnableXSaveWorkaround()
|
||||||
{
|
{
|
||||||
// Some Windows environments may have hardware support for AVX/FMA,
|
// Some Windows environments may have hardware support for AVX/FMA,
|
||||||
@ -17,6 +19,24 @@ int __cdecl EnableXSaveWorkaround()
|
|||||||
// The API name is somewhat misleading - we're testing for OS support
|
// The API name is somewhat misleading - we're testing for OS support
|
||||||
// here.
|
// here.
|
||||||
if (!IsProcessorFeaturePresent(PF_XSAVE_ENABLED))
|
if (!IsProcessorFeaturePresent(PF_XSAVE_ENABLED))
|
||||||
|
{
|
||||||
|
_set_FMA3_enable(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even if XSAVE feature is enabled, we have to see if
|
||||||
|
// GetEnabledXStateFeatures function is present, and see what it says about
|
||||||
|
// AVX state.
|
||||||
|
auto kernel32Handle = GetModuleHandle(TEXT("kernel32.dll"));
|
||||||
|
if (kernel32Handle == nullptr)
|
||||||
|
{
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pGetEnabledXStateFeatures = (GetEnabledXStateFeatures_t)GetProcAddress(
|
||||||
|
kernel32Handle, "GetEnabledXStateFeatures");
|
||||||
|
if (pGetEnabledXStateFeatures == nullptr ||
|
||||||
|
(pGetEnabledXStateFeatures() & XSTATE_MASK_AVX) == 0)
|
||||||
{
|
{
|
||||||
_set_FMA3_enable(0);
|
_set_FMA3_enable(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user