Commit a0f7fd1f by Maxime Grégoire

Windows timer implementation for Command Queues.

Change-Id: I9b18a3a8cf1d80bd3e06989004dcdad76bb16df9 Reviewed-on: https://swiftshader-review.googlesource.com/3710Reviewed-by: 's avatarMaxime Grégoire <mgregoire@google.com> Tested-by: 's avatarMaxime Grégoire <mgregoire@google.com>
parent 6b2ded87
......@@ -528,6 +528,75 @@ void Event::setDeviceData(void *data)
p_device_data = data;
}
#if defined(_WIN32)
LARGE_INTEGER getFILETIMEoffset()
{
SYSTEMTIME s;
FILETIME f;
LARGE_INTEGER t;
s.wYear = 1970;
s.wMonth = 1;
s.wDay = 1;
s.wHour = 0;
s.wMinute = 0;
s.wSecond = 0;
s.wMilliseconds = 0;
SystemTimeToFileTime(&s, &f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
return (t);
}
void clock_gettime(timeval *tv)
{
LARGE_INTEGER t;
FILETIME f;
double microseconds;
static LARGE_INTEGER offset;
static double frequencyToMicroseconds;
static int initialized = 0;
static BOOL usePerformanceCounter = 0;
if(!initialized)
{
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if(usePerformanceCounter)
{
QueryPerformanceCounter(&offset);
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
}
else
{
offset = getFILETIMEoffset();
frequencyToMicroseconds = 10.;
}
}
if(usePerformanceCounter)
{
QueryPerformanceCounter(&t);
}
else
{
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
}
t.QuadPart -= offset.QuadPart;
microseconds = (double)t.QuadPart / frequencyToMicroseconds;
t.QuadPart = microseconds;
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_usec = t.QuadPart % 1000000;
}
#endif
void Event::updateTiming(Timing timing)
{
if(timing >= Max)
......@@ -542,14 +611,21 @@ void Event::updateTiming(Timing timing)
return;
}
struct timespec tp;
cl_ulong rs;
#if defined(_WIN32)
struct timeval tv;
clock_gettime(&tv);
rs = tv.tv_usec;
rs += tv.tv_sec * 1000000;
#else
struct timespec tp;
if(clock_gettime(CLOCK_MONOTONIC, &tp) != 0)
clock_gettime(CLOCK_REALTIME, &tp);
rs = tp.tv_nsec;
rs += tp.tv_sec * 1000000;
#endif
p_timing[timing] = rs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment