Commit a4810f71 by Brian Osman Committed by Commit Bot

Fix several bugs in the timeout logic of clientWait

1) timeout is unsigned, and clients tend to pass large unsigned values (like -1) to mean "wait as long as possible". Casting to signed at the start of the math meant that everything was negative, so we would never actually wait for fences to be signalled. 2) When going from nanoseconds to seconds, we should divide by 10^9, not multiply by 10^6. 3) Even with all of this, it's possible for a sufficiently large counter frequency to still cause overflow, so detect that case and clamp. Change-Id: I9e728aac72d8dc0b15582732b6fd4d87c90bd140 Reviewed-on: https://chromium-review.googlesource.com/707202Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 8886f0fc
......@@ -169,9 +169,15 @@ gl::Error Sync11::clientWait(GLbitfield flags, GLuint64 timeout, GLenum *outResu
BOOL success = QueryPerformanceCounter(&currentCounter);
ASSERT(success);
LONGLONG timeoutInSeconds = static_cast<LONGLONG>(timeout) * static_cast<LONGLONG>(1000000ll);
LONGLONG timeoutInSeconds = static_cast<LONGLONG>(timeout / 1000000000ull);
LONGLONG endCounter = currentCounter.QuadPart + mCounterFrequency * timeoutInSeconds;
// Extremely unlikely, but if mCounterFrequency is large enough, endCounter can wrap
if (endCounter < currentCounter.QuadPart)
{
endCounter = MAXLONGLONG;
}
int loopCount = 0;
while (currentCounter.QuadPart < endCounter && !result)
{
......
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