PDA

View Full Version : glTestFenceNV block or not?



ltqin
02-04-2010, 08:48 PM
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");
...
RenderScene();
// set fence
if(glSetFenceNV)
glSetFenceNV(m_nFenceID,GL_ALL_COMPLETED_NV);
SwapBuffers(m_hCurrentDC);
}

if(glTestFenceNV)
{
CSimpleTimeCount timer(L"wait v-sync");
while (!glTestFenceNV(m_nFenceID))
{
CSimpleTimeCount timer(L"wait v-sync2");
Sleep(5);
}
}

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?

Alfonse Reinheart
02-04-2010, 10:45 PM
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.

Ysaneya
02-05-2010, 02:58 AM
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 ?

ltqin
02-07-2010, 06:47 PM
Am I right assuming that your CSimpleTimeCount class displays the elpased time between the constructor and destructor, at the moment the object is deconstructed ?

yes


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.

ltqin
02-07-2010, 07:19 PM
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

Ysaneya
02-08-2010, 04:20 AM
If you do:



if(glTestFenceNV)
{
CSimpleTimeCount timer(L"Timer");
SomeWork();
}


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:



if(glTestFenceNV)
{
CSimpleTimeCount timer(L"v-sync3");
glTestFenceNV(m_nFenceID);
}


Y.