mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-02 12:03:51 +00:00
Merge branch 'Preview4_0' into feature-vfs-security
This commit is contained in:
commit
161ffc62fe
3013 changed files with 348715 additions and 182470 deletions
|
|
@ -24,13 +24,89 @@
|
|||
#include "platformWin32/platformWin32.h"
|
||||
#include "console/console.h"
|
||||
#include "core/stringTable.h"
|
||||
#include "platform/platformCPUCount.h"
|
||||
#include <math.h>
|
||||
#include <intrin.h>
|
||||
|
||||
Platform::SystemInfo_struct Platform::SystemInfo;
|
||||
extern void PlatformBlitInit();
|
||||
extern void SetProcessorInfo(Platform::SystemInfo_struct::Processor& pInfo,
|
||||
char* vendor, U32 processor, U32 properties, U32 properties2); // platform/platformCPU.cc
|
||||
|
||||
static void getBrand(char* brand)
|
||||
{
|
||||
S32 extendedInfo[4];
|
||||
__cpuid(extendedInfo, 0x80000000);
|
||||
S32 numberExtendedIds = extendedInfo[0];
|
||||
|
||||
// Sets brand
|
||||
if (numberExtendedIds >= 0x80000004)
|
||||
{
|
||||
int offset = 0;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
S32 brandInfo[4];
|
||||
__cpuidex(brandInfo, 0x80000002 + i, 0);
|
||||
|
||||
*reinterpret_cast<int*>(brand + offset + 0) = brandInfo[0];
|
||||
*reinterpret_cast<int*>(brand + offset + 4) = brandInfo[1];
|
||||
*reinterpret_cast<int*>(brand + offset + 8) = brandInfo[2];
|
||||
*reinterpret_cast<int*>(brand + offset + 12) = brandInfo[3];
|
||||
|
||||
offset += sizeof(S32) * 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CpuFlags
|
||||
{
|
||||
// EDX Register flags
|
||||
BIT_MMX = BIT(23),
|
||||
BIT_SSE = BIT(25),
|
||||
BIT_SSE2 = BIT(26),
|
||||
BIT_3DNOW = BIT(31), // only available for amd cpus in x86
|
||||
|
||||
// These use a different value for comparison than the above flags (ECX Register)
|
||||
BIT_SSE3 = BIT(0),
|
||||
BIT_SSE3ex = BIT(9),
|
||||
BIT_SSE4_1 = BIT(19),
|
||||
BIT_SSE4_2 = BIT(20),
|
||||
|
||||
BIT_XSAVE_RESTORE = BIT(27),
|
||||
BIT_AVX = BIT(28),
|
||||
};
|
||||
|
||||
static void detectCpuFeatures(Platform::SystemInfo_struct::Processor &processor)
|
||||
{
|
||||
S32 cpuInfo[4];
|
||||
__cpuid(cpuInfo, 1);
|
||||
U32 eax = cpuInfo[0]; // eax
|
||||
U32 edx = cpuInfo[3]; // edx
|
||||
U32 ecx = cpuInfo[2]; // ecx
|
||||
|
||||
processor.properties |= (edx & BIT_MMX) ? CPU_PROP_MMX : 0;
|
||||
processor.properties |= (edx & BIT_SSE) ? CPU_PROP_SSE : 0;
|
||||
processor.properties |= (edx & BIT_SSE2) ? CPU_PROP_SSE2 : 0;
|
||||
processor.properties |= (ecx & BIT_SSE3) ? CPU_PROP_SSE3 : 0;
|
||||
processor.properties |= (ecx & BIT_SSE3ex) ? CPU_PROP_SSE3ex : 0;
|
||||
processor.properties |= (ecx & BIT_SSE4_1) ? CPU_PROP_SSE4_1 : 0;
|
||||
processor.properties |= (ecx & BIT_SSE4_2) ? CPU_PROP_SSE4_2 : 0;
|
||||
|
||||
// AVX detection requires that xsaverestore is supported
|
||||
if (ecx & BIT_XSAVE_RESTORE && ecx & BIT_AVX)
|
||||
{
|
||||
bool supportsAVX = _xgetbv(_XCR_XFEATURE_ENABLED_MASK) & 0x6;
|
||||
if (supportsAVX)
|
||||
{
|
||||
processor.properties |= CPU_PROP_AVX;
|
||||
}
|
||||
}
|
||||
|
||||
if (processor.isMultiCore)
|
||||
processor.properties |= CPU_PROP_MP;
|
||||
|
||||
#ifdef TORQUE_CPU_X64
|
||||
processor.properties |= CPU_PROP_64bit;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Processor::init()
|
||||
{
|
||||
|
|
@ -40,18 +116,13 @@ void Processor::init()
|
|||
// www.intel.com
|
||||
// http://developer.intel.com/design/PentiumII/manuals/24512701.pdf
|
||||
|
||||
Con::printf("Processor Init:");
|
||||
|
||||
Platform::SystemInfo.processor.type = CPU_X86Compatible;
|
||||
Platform::SystemInfo.processor.name = StringTable->insert("Unknown x86 Compatible");
|
||||
Platform::SystemInfo.processor.mhz = 0;
|
||||
Platform::SystemInfo.processor.properties = CPU_PROP_C | CPU_PROP_LE;
|
||||
Platform::SystemInfo.processor.properties = CPU_PROP_C | CPU_PROP_FPU | CPU_PROP_LE;
|
||||
|
||||
char vendor[0x20];
|
||||
dMemset(vendor, 0, sizeof(vendor));
|
||||
U32 properties = 0;
|
||||
U32 processor = 0;
|
||||
U32 properties2 = 0;
|
||||
|
||||
S32 vendorInfo[4];
|
||||
__cpuid(vendorInfo, 0);
|
||||
|
|
@ -59,17 +130,14 @@ void Processor::init()
|
|||
*reinterpret_cast<int*>(vendor + 4) = vendorInfo[3]; // edx
|
||||
*reinterpret_cast<int*>(vendor + 8) = vendorInfo[2]; // ecx
|
||||
|
||||
S32 cpuInfo[4];
|
||||
__cpuid(cpuInfo, 1);
|
||||
processor = cpuInfo[0]; // eax
|
||||
properties = cpuInfo[3]; // edx
|
||||
properties2 = cpuInfo[2]; // ecx
|
||||
char brand[0x40];
|
||||
dMemset(brand, 0, sizeof(brand));
|
||||
getBrand(brand);
|
||||
|
||||
SetProcessorInfo(Platform::SystemInfo.processor, vendor, processor, properties, properties2);
|
||||
SetProcessorInfo(Platform::SystemInfo.processor, vendor, brand);
|
||||
detectCpuFeatures(Platform::SystemInfo.processor);
|
||||
|
||||
// now calculate speed of processor...
|
||||
U32 nearmhz = 0; // nearest rounded mhz
|
||||
U32 mhz = 0; // calculated value.
|
||||
U32 mhz = 1000; // default if it can't be found
|
||||
|
||||
LONG result;
|
||||
DWORD data = 0;
|
||||
|
|
@ -83,56 +151,35 @@ void Processor::init()
|
|||
result = ::RegQueryValueExA (hKey, "~MHz",NULL, NULL,(LPBYTE)&data, &dataSize);
|
||||
|
||||
if (result == ERROR_SUCCESS)
|
||||
nearmhz = mhz = data;
|
||||
mhz = data;
|
||||
|
||||
::RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
Platform::SystemInfo.processor.mhz = mhz;
|
||||
|
||||
if (mhz==0)
|
||||
{
|
||||
Con::printf(" %s, (Unknown) Mhz", Platform::SystemInfo.processor.name);
|
||||
// stick SOMETHING in so it isn't ZERO.
|
||||
Platform::SystemInfo.processor.mhz = 200; // seems a decent value.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nearmhz >= 1000)
|
||||
Con::printf(" %s, ~%.2f Ghz", Platform::SystemInfo.processor.name, ((float)nearmhz)/1000.0f);
|
||||
else
|
||||
Con::printf(" %s, ~%d Mhz", Platform::SystemInfo.processor.name, nearmhz);
|
||||
if (nearmhz != mhz)
|
||||
{
|
||||
if (mhz >= 1000)
|
||||
Con::printf(" (timed at roughly %.2f Ghz)", ((float)mhz)/1000.0f);
|
||||
else
|
||||
Con::printf(" (timed at roughly %d Mhz)", mhz);
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform::SystemInfo.processor.numAvailableCores > 0
|
||||
|| Platform::SystemInfo.processor.numPhysicalProcessors > 0
|
||||
|| Platform::SystemInfo.processor.isHyperThreaded )
|
||||
Platform::SystemInfo.processor.properties |= CPU_PROP_MP;
|
||||
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_FPU)
|
||||
Con::printf( " FPU detected" );
|
||||
Con::printf("Processor Init:");
|
||||
Con::printf(" Processor: %s", Platform::SystemInfo.processor.name);
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_MMX)
|
||||
Con::printf( " MMX detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_3DNOW)
|
||||
Con::printf( " 3DNow detected" );
|
||||
Con::printf(" MMX detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE)
|
||||
Con::printf( " SSE detected" );
|
||||
if( Platform::SystemInfo.processor.properties & CPU_PROP_SSE2 )
|
||||
Con::printf( " SSE2 detected" );
|
||||
if( Platform::SystemInfo.processor.isHyperThreaded )
|
||||
Con::printf( " HT detected" );
|
||||
if( Platform::SystemInfo.processor.properties & CPU_PROP_MP )
|
||||
Con::printf( " MP detected [%i cores, %i logical, %i physical]",
|
||||
Platform::SystemInfo.processor.numAvailableCores,
|
||||
Platform::SystemInfo.processor.numLogicalProcessors,
|
||||
Platform::SystemInfo.processor.numPhysicalProcessors );
|
||||
Con::printf(" SSE detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE2)
|
||||
Con::printf(" SSE2 detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE3)
|
||||
Con::printf(" SSE3 detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE3ex)
|
||||
Con::printf(" SSE3ex detected ");
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE4_1)
|
||||
Con::printf(" SSE4.1 detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_SSE4_2)
|
||||
Con::printf(" SSE4.2 detected" );
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_AVX)
|
||||
Con::printf(" AVX detected");
|
||||
|
||||
if (Platform::SystemInfo.processor.properties & CPU_PROP_MP)
|
||||
Con::printf(" MultiCore CPU detected [%i cores, %i logical]", Platform::SystemInfo.processor.numPhysicalProcessors, Platform::SystemInfo.processor.numLogicalProcessors);
|
||||
|
||||
Con::printf(" ");
|
||||
|
||||
PlatformBlitInit();
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@
|
|||
|
||||
extern void mInstallLibrary_C();
|
||||
extern void mInstallLibrary_ASM();
|
||||
extern void mInstall_AMD_Math();
|
||||
extern void mInstall_Library_SSE();
|
||||
|
||||
//--------------------------------------
|
||||
DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
|
||||
|
|
@ -40,7 +38,6 @@ DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
|
|||
" - 'C' Enable the C math routines. C routines are always enabled.\n\n"
|
||||
" - 'FPU' Enable floating point unit routines.\n\n"
|
||||
" - 'MMX' Enable MMX math routines.\n\n"
|
||||
" - '3DNOW' Enable 3dNow! math routines.\n\n"
|
||||
" - 'SSE' Enable SSE math routines.\n\n"
|
||||
"@ingroup Math")
|
||||
|
||||
|
|
@ -72,10 +69,6 @@ DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
|
|||
properties |= CPU_PROP_MMX;
|
||||
continue;
|
||||
}
|
||||
if (dStricmp(str, "3DNOW") == 0) {
|
||||
properties |= CPU_PROP_3DNOW;
|
||||
continue;
|
||||
}
|
||||
if (dStricmp(str, "SSE") == 0) {
|
||||
properties |= CPU_PROP_SSE;
|
||||
continue;
|
||||
|
|
@ -116,17 +109,11 @@ void Math::init(U32 properties)
|
|||
if (properties & CPU_PROP_MMX)
|
||||
{
|
||||
Con::printf(" Installing MMX extensions");
|
||||
if (properties & CPU_PROP_3DNOW)
|
||||
{
|
||||
Con::printf(" Installing 3DNow extensions");
|
||||
mInstall_AMD_Math();
|
||||
}
|
||||
}
|
||||
|
||||
if (properties & CPU_PROP_SSE)
|
||||
{
|
||||
Con::printf(" Installing SSE extensions");
|
||||
mInstall_Library_SSE();
|
||||
}
|
||||
|
||||
Con::printf(" ");
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#if defined( TORQUE_OS_WIN )
|
||||
|
||||
#include "platform/platformCPUCount.h"
|
||||
#include "console/console.h"
|
||||
#include <windows.h>
|
||||
#include <intrin.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -52,12 +53,10 @@ namespace CPUInfo {
|
|||
return bitSetCount;
|
||||
}
|
||||
|
||||
EConfig CPUCount( U32& TotAvailLogical, U32& TotAvailCore, U32& PhysicalNum )
|
||||
EConfig CPUCount( U32& TotAvailLogical, U32& TotAvailCore )
|
||||
{
|
||||
EConfig StatusFlag = CONFIG_UserConfigIssue;
|
||||
TotAvailLogical = 0;
|
||||
TotAvailCore = 0;
|
||||
PhysicalNum = 0;
|
||||
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
|
||||
DWORD returnLength = 0;
|
||||
|
|
@ -68,42 +67,37 @@ namespace CPUInfo {
|
|||
|
||||
rc = GetLogicalProcessorInformation( buffer, &returnLength );
|
||||
|
||||
// if we fail, assume single threaded
|
||||
if( FALSE == rc )
|
||||
{
|
||||
free( buffer );
|
||||
return StatusFlag;
|
||||
Con::errorf("Unable to determine CPU Count, assuming 1 core");
|
||||
TotAvailCore = 1;
|
||||
TotAvailLogical = 1;
|
||||
return CONFIG_SingleCoreAndHTNotCapable;
|
||||
}
|
||||
|
||||
#pragma push
|
||||
#pragma warning (disable: 6011)
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = buffer;
|
||||
|
||||
DWORD byteOffset = 0;
|
||||
while( byteOffset + sizeof( SYSTEM_LOGICAL_PROCESSOR_INFORMATION ) <= returnLength )
|
||||
{
|
||||
switch( ptr->Relationship )
|
||||
{
|
||||
|
||||
case RelationProcessorCore:
|
||||
if (ptr->Relationship == RelationProcessorCore)
|
||||
{
|
||||
TotAvailCore++;
|
||||
|
||||
// A hyperthreaded core supplies more than one logical processor.
|
||||
TotAvailLogical += CountSetBits( ptr->ProcessorMask );
|
||||
break;
|
||||
|
||||
case RelationProcessorPackage:
|
||||
// Logical processors share a physical package.
|
||||
PhysicalNum++;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
TotAvailLogical += CountSetBits(ptr->ProcessorMask);
|
||||
}
|
||||
|
||||
byteOffset += sizeof( SYSTEM_LOGICAL_PROCESSOR_INFORMATION );
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
free( buffer );
|
||||
#pragma pop
|
||||
|
||||
StatusFlag = CONFIG_SingleCoreAndHTNotCapable;
|
||||
EConfig StatusFlag = CONFIG_SingleCoreAndHTNotCapable;
|
||||
|
||||
if( TotAvailCore == 1 && TotAvailLogical > TotAvailCore )
|
||||
StatusFlag = CONFIG_SingleCoreHTEnabled;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue