Platform ability to query system (logical) cores

This commit is contained in:
Doyle Thai 2017-06-17 16:20:35 +10:00
parent 92953e9d7c
commit 35bdbb65de
4 changed files with 99 additions and 4 deletions

View File

@ -997,7 +997,7 @@ extern "C" void DTR_Update(PlatformRenderBuffer *const platformRenderBuffer,
DTRDebug_EndCycleCount(DTRDebugCycleCount_DTR_Update_RenderPrimitiveTriangles); DTRDebug_EndCycleCount(DTRDebugCycleCount_DTR_Update_RenderPrimitiveTriangles);
} }
if (1) if (0)
{ {
LOCAL_PERSIST bool runTinyRendererOnce = false; LOCAL_PERSIST bool runTinyRendererOnce = false;
if (1 && runTinyRendererOnce) if (1 && runTinyRendererOnce)

View File

@ -441,9 +441,15 @@ i32 Win32GetModuleDirectory(char *const buf, const u32 bufLen)
return lastSlashIndex; return lastSlashIndex;
} }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, DWORD WINAPI Win32ThreadCallback(void *lpParameter)
LPWSTR lpCmdLine, int nShowCmd)
{ {
OutputDebugString("Threaded Hello World!\n");
return 0;
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Initialise Win32 Window // Initialise Win32 Window
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -563,6 +569,78 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
platformInput.flags.canUseSSE2 = IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); platformInput.flags.canUseSSE2 = IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE);
platformInput.flags.canUseRdtsc = IsProcessorFeaturePresent(PF_RDTSC_INSTRUCTION_AVAILABLE); platformInput.flags.canUseRdtsc = IsProcessorFeaturePresent(PF_RDTSC_INSTRUCTION_AVAILABLE);
// Threading
{
const i32 USE_DEFAULT_STACK_SIZE = 0;
void *threadParam = NULL;
DWORD threadId;
HANDLE threadHandle = CreateThread(NULL, USE_DEFAULT_STACK_SIZE, Win32ThreadCallback,
threadParam, 0, &threadId);
////////////////////////////////////////////////////////////////////////
// Query CPU Cores
////////////////////////////////////////////////////////////////////////
i32 numCores = 1;
i32 numLogicalCores = 0;
SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);
DqnWin32_OutputDebugString("Number of Logical Processors: %d\n",
systemInfo.dwNumberOfProcessors);
numLogicalCores = systemInfo.dwNumberOfProcessors;
DWORD logicalProcInfoRequiredSize = 0;
u8 insufficientBuffer = {};
GetLogicalProcessorInformationEx(
RelationProcessorCore, (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)insufficientBuffer,
&logicalProcInfoRequiredSize);
u8 *rawProcInfoArray =
(u8 *)DqnMemStack_Push(&globalPlatformMemory.tempStack, logicalProcInfoRequiredSize);
if (rawProcInfoArray)
{
if (GetLogicalProcessorInformationEx(
RelationProcessorCore,
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)rawProcInfoArray,
&logicalProcInfoRequiredSize))
{
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *logicalProcInfo =
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)rawProcInfoArray;
DWORD bytesRead = 0;
do
{
// NOTE: High efficiency value has greater performance and less efficiency.
PROCESSOR_RELATIONSHIP *procInfo = &logicalProcInfo->Processor;
u32 efficiency = procInfo->EfficiencyClass;
DqnWin32_OutputDebugString("Core %d: Efficiency: %d\n", numCores++, efficiency);
DQN_ASSERT(logicalProcInfo->Relationship == RelationProcessorCore);
DQN_ASSERT(procInfo->GroupCount == 1);
bytesRead += logicalProcInfo->Size;
logicalProcInfo =
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)((u8 *)logicalProcInfo +
logicalProcInfo->Size);
} while (bytesRead < logicalProcInfoRequiredSize);
}
else
{
DqnWin32_DisplayLastError("GetLogicalProcessorInformationEx() failed");
}
}
else
{
DQN_WIN32_ERROR_BOX("DqnMemStack_Push() failed", NULL);
}
DqnMemStack_Pop(&globalPlatformMemory.tempStack, rawProcInfoArray,
logicalProcInfoRequiredSize);
}
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Update Loop // Update Loop
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@ -39,7 +39,7 @@ REM wd4100 unused argument parameters
REM wd4201 nonstandard extension used: nameless struct/union REM wd4201 nonstandard extension used: nameless struct/union
REM wd4189 local variable is initialised but not referenced REM wd4189 local variable is initialised but not referenced
REM wd4505 unreferenced local function not used will be removed REM wd4505 unreferenced local function not used will be removed
set CompileFlags=-EHsc -GR- -Oi -MT -Z7 -W4 -wd4100 -wd4201 -wd4189 -wd4505 -O2 -FAsc /I..\src\external\ set CompileFlags=-EHsc -GR- -Oi -MT -Z7 -W4 -wd4100 -wd4201 -wd4189 -wd4505 -Od -FAsc /I..\src\external\
set DLLFlags=/Fm%ProjectName% /Fo%ProjectName% /Fa%ProjectName% /Fe%ProjectName% set DLLFlags=/Fm%ProjectName% /Fo%ProjectName% /Fa%ProjectName% /Fe%ProjectName%
set Win32Flags=/FmWin32DTRenderer /FeWin32DTRenderer set Win32Flags=/FmWin32DTRenderer /FeWin32DTRenderer

View File

@ -796,6 +796,8 @@ DQN_FILE_SCOPE void DqnWin32_GetClientDim (const HWND window, LONG *width, LO
DQN_FILE_SCOPE void DqnWin32_GetRectDim (RECT rect, LONG *width, LONG *height); DQN_FILE_SCOPE void DqnWin32_GetRectDim (RECT rect, LONG *width, LONG *height);
DQN_FILE_SCOPE void DqnWin32_DisplayLastError(const char *const errorPrefix); DQN_FILE_SCOPE void DqnWin32_DisplayLastError(const char *const errorPrefix);
DQN_FILE_SCOPE void DqnWin32_DisplayErrorCode(const DWORD error, const char *const errorPrefix); DQN_FILE_SCOPE void DqnWin32_DisplayErrorCode(const DWORD error, const char *const errorPrefix);
DQN_FILE_SCOPE void DqnWin32_OutputDebugString(const char *const formatStr, ...);
#endif /* DQN_WIN32_IMPLEMENTATION */ #endif /* DQN_WIN32_IMPLEMENTATION */
@ -3270,6 +3272,21 @@ DQN_FILE_SCOPE void DqnWin32_DisplayErrorCode(const DWORD error, const char *con
Dqn_sprintf(formattedError, "%s: %s", errorPrefix, errorMsg); Dqn_sprintf(formattedError, "%s: %s", errorPrefix, errorMsg);
DQN_WIN32_ERROR_BOX(formattedError, NULL); DQN_WIN32_ERROR_BOX(formattedError, NULL);
} }
DQN_FILE_SCOPE void DqnWin32_OutputDebugString(const char *const formatStr, ...)
{
LOCAL_PERSIST char str[1024] = {};
va_list argList;
va_start(argList, formatStr);
{
i32 numCopied = Dqn_vsprintf(str, formatStr, argList);
DQN_ASSERT(numCopied < DQN_ARRAY_COUNT(str));
}
va_end(argList);
OutputDebugString(str);
}
#endif // DQN_WIN32_PLATFROM #endif // DQN_WIN32_PLATFROM
FILE_SCOPE bool DqnFile_OpenInternal(const wchar_t *const path, FILE_SCOPE bool DqnFile_OpenInternal(const wchar_t *const path,