glTestFenceNV block or not?

The OpenGL extensions guide say:The glTestFenceNV function always returns immediately.but i try it,it seem spend a lot of time,so make high cpu usage
my test code:

   CSimpleTimeCount  timer(L"RealDraw");
   // set fence
     CSimpleTimeCount  timer(L"wait v-sync");
     while (!glTestFenceNV(m_nFenceID))  
	CSimpleTimeCount  timer(L"wait v-sync2");

CSimpleTimeCount obj auto computer time when destroy
result is:

RealDraw's time is:230 ns
wait v-sync2's time is:5446 ns
wait v-sync's time is:11462 ns

so glTestFenceNV take 6000ns befor return?

The glTestFenceNV function always returns immediately.

Immediately does not mean “instantly,” or even “quickly.” What it’s saying is that it will not wait until the fence has been reached to return. So it isn’t a synchronization function; it is different form glFinishFenceNV, which will return only when the fence has finished.

Am I right assuming that your CSimpleTimeCount class displays the elpased time between the constructor and destructor, at the moment the object is deconstructed ?

If so, your numbers include the Sleep(5), which has some variability. Wouldn’t that make your results totally meaningless ?


because “wait v-sync2” item show only once bettwen “RealDraw” and “wait v-sync”, elpased time is 5446 ns(=5.5ms),and cpu have 30~40% usage(cpu is two core),
so i conclude that glTestFenceNV have cpu for a while,like to use while(1) or spinlocker.

in fact my question is:
I have a simple doublebuffer Windows OpenGL app. When I run it it takes about 10% CPU usage on my computer. Now, I want to run it another computer and it takes up about 50% CPU time.and when i have updated my display card driver, it also takes 50% CPU time. so my guess is that there is a difference in the drivers with the implementation of V-sync block, where it doesn’t release the CPU on the new driver. My computer has a Nvidia NVS 160M,old driver support opengl 1.1~2.1,new driver only support 3.0.

so i use NV_fence extension,but is cannt resolve my question

If you do:

  CSimpleTimeCount timer(L"Timer");

The result of your timer includes the time spent in SomeWork().

I just don’t see where the problem is. You’re benchmarking a Sleep(5) call here, so it’s only normal that the result of your timer is around 5 ms.

Replace your Sleep(5) by a Sleep(100), and you’ll see that your v-sync2 time changes too.

If you really want to check how long a single call to glTestFenceNV takes (to see if it’s blocking or not), don’t Sleep and don’t make a loop:

  CSimpleTimeCount timer(L"v-sync3");