Erratic RDSTC with Direct3D 
Author Message
 Erratic RDSTC with Direct3D

I'm having some very strange problems when trying to measure the
performance
of Direct3D operations. My code is as follows:
// funny block: timing of the loop below depends on the number of
assignment statements here
c_0 = 0;
.....
.....
.....
.....
c_0 = 0;
if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
t0 = tsc();
// I want to time this loop here
for (c_1 = 0; c_1 < loop_total; c_1 ++){}
t1 = tsc();
total_cycles_elapsed = t1-t0;
sprintf( buffer, "\naverage cycles_elapsed = %lf,
total_cycles_elapsed = %lf",
total_cycles_elapsed/double (loop_total), total_cycles_elapsed);
OutputDebugString (buffer);
m_pd3dDevice->EndScene();

Quote:
}

Here's the funny part: if I have 8 statements in the "funny block",
such as
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
the timing output would be as follows:
average cycles_elapsed = 5.167622, total_cycles_elapsed =
516762208.000000
average cycles_elapsed = 5.198122, total_cycles_elapsed =
519812160.000000
average cycles_elapsed = 5.180695, total_cycles_elapsed =
518069504.000000
average cycles_elapsed = 5.175938, total_cycles_elapsed =
517593760.000000
average cycles_elapsed = 5.252802, total_cycles_elapsed =
525280192.000000
average cycles_elapsed = 5.117760, total_cycles_elapsed =
511775968.000000
average cycles_elapsed = 5.129462, total_cycles_elapsed =
512946240.000000
average cycles_elapsed = 5.081827, total_cycles_elapsed =
508182688.000000
............................
But if I have 9 statements in the "funny block", such as
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
c_0 = 0;
the timing goes up significantly:
average cycles_elapsed = 7.591117, total_cycles_elapsed =
759111744.000000
average cycles_elapsed = 7.616155, total_cycles_elapsed =
761615488.000000
average cycles_elapsed = 7.573227, total_cycles_elapsed =
757322688.000000
average cycles_elapsed = 7.605620, total_cycles_elapsed =
760562048.000000
average cycles_elapsed = 7.606230, total_cycles_elapsed =
760623040.000000
.............................
I'm totally flabbergasted, to say the least, by this kind of totally
inexplicable behavior. I'm sure it's not a problem with alignment since
as soon as I move the loop outside of the BeginScene() /EndScene()
block, the timing is always between 5.0 and 5.2.
PS. Here's my tsc ()
double tsc ()
{
unsigned __int32
cycles_high,
cycles_low;
__int64 current_cycles;
_asm
{
CPUID
pushad
RDTSC
mov cycles_high, edx
mov cycles_low, eax
popad
Quote:
}

current_cycles = ((unsigned __int64) cycles_high << 32) |
cycles_low;
return (double (current_cycles));

Quote:
}

Sent via Deja.com http://www.*-*-*.com/
Before you buy.


Wed, 11 Sep 2002 03:00:00 GMT  
 Erratic RDSTC with Direct3D


Quote:

> I'm having some very strange problems when trying to measure the
> performance of Direct3D operations. My code is as follows:
> // funny block: timing of the loop below depends on the number of
> assignment statements here
> c_0 = 0;
> .....
> .....
> .....
> .....
> c_0 = 0;
> if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
> {
> t0 = tsc();
> // I want to time this loop here
> for (c_1 = 0; c_1 < loop_total; c_1 ++){}
> Here's the funny part: if I have 8 statements in the "funny block",
> average cycles_elapsed = 5.167622, total_cycles_elapsed =
> But if I have 9 statements in the "funny block", such as
> average cycles_elapsed = 7.591117, total_cycles_elapsed =
> I'm totally flabbergasted, to say the least, by this kind of totally
> inexplicable behavior. I'm sure it's not a problem with alignment since
> as soon as I move the loop outside of the BeginScene() /EndScene()
> block, the timing is always between 5.0 and 5.2.

I'm rotten at c, and worse at c-- .  I don't know if tsc() as you've
coded it is a function call [as it seems], or an inline [prefered].

My first guess would be a code alignment problem.  The extra c_0 = 0
statements may push the empty loop to split across a  16-byte ifetch
block.  Get your compiler to dump the asm and have a close look at it.

-- Robert



Wed, 11 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help with RDSTC instruction

2. Direct3D

3. Direct3D rendering limitations?

4. vrml to direct3d

5. FireGL and Direct3D under NT

6. Direct3d VRML Browsers

7. Direct3D headers for Asm

8. Direct3D, *not* OpenGL

9. erratic behavior of push buttons in Dolphin 98?

10. Browse with No key acting erratic with MS SQL

11. erratic date control / bug in LabVIEW?

12. Erratic internal error 1210 in clipper 5.2e app using DBFCDX - Error (0/1)

 

 
Powered by phpBB® Forum Software