Archived

This topic is now archived and is closed to further replies.

Really weird performance problem with Direct3D

This topic is 5014 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I have a very weird problem with Direct3D (using DirectX 7). My program loop - simplified - looks like this: while (loop) { render_some_test_stuff(); do_some_other_stuff(); Sleep(10); frame++; } This results in a framerate of 100. At least, the loop shown above is executed 100 times per second. I do not *see* 100 frames each second though! Instead it looks more like 10 FPS. If I remove the call to Sleep, the loop is executed more than a few thousand times per second, but the ''visible frame rate'' drops to 2 to 3 frames per second... this is so weird, I''m totally clueless. My only guess is that it has got something to do with swapping between buffers or something? You can find my test program here (virus/trojan free AFAIK, plz report if it''s infected!): http://130.89.227.64/foddex/test.zip At program start you can specify if you want the OpenGL or the Direct3D implementation (my render engine needs to support both). The OpenGL implementation uses VSYNC and shows a very smooth scene (on my GeForce 4 440 Go), the Direct3D implementation is kinda crappy. Test it yourself to see what I''m talking about. Does anyone have any idea what this problem can be? Thanks in advance! Marc

Share this post


Link to post
Share on other sites
This won''t help you but I also had this problem. I haven''t worked through it yet (I''m just a hobbiest with limited time and a bad computer) but I wanted to let you know that it''s not just you.

Not to distract from Mark''s problem but my code was a simple loop that just drew a square that I moved by changing the world transform. If I had the loop setup for ~10 iterations I''d only see the first and last frames. If I set it up for 1000 iteration then I''d actually see the square move around.

I''m wondering if it has something to do with the presentation interval / refresh rate settings (I just used the default).



"Good code will come and go, but bad code sticks around."

Share this post


Link to post
Share on other sites
quote:
Original post by RenderTarget
Are you handling Windows messages in your loop? Windows hates you if you don''t.

That''s my first thought.

I like pie.


Yeah I do handle them: WM_ACTIVATE, WM_CLOSE, WM_QUIT, WM_KEY*, WM_MOUSE*, WM_MOVE, WM_SYSCOMMAND. Did I miss one maybe?

Share this post


Link to post
Share on other sites
quote:
Original post by EverIce
In my comp. at the office it seems the same fps in gl a d3d.

What''s your OS ?




Hmm I run my program on my laptop: Windows 2000, P4 1.6 Ghz, GeForce 4 440 Go. I bet you have way faster hardware than that, aren''t you? Because I tested it on my other PC after your post, a P4 2.67 Ghz with a Radeon 9800 Pro 256 MB, and it seems to run way better on that one...

But it cannot be a video-card performance issue, since both cards can do the Far Cry demo and my program only shows 4 triangles

Share this post


Link to post
Share on other sites
quote:
Original post by EverIce
You won''t believe it. win2000 1.3Cel, 128mb, 4Mb integrated IBM video card ! 68 Fps !

It''s getting more weird.


Weird .... :S

Well I''ve decided to put some code online, I''ve been looking at this code for days now and I''m not getting anywhere. Maybe if someone else can take a quick look at it, he or she could find the problem?

The Direct3D implementation of my abstract renderer class is located here:

http://130.89.227.64/foddex/test/renderer_direct3d.cpp
http://130.89.227.64/foddex/test/renderer_direct3d.h

To show how I use the renderer engine, I also have the code of my main program online:

http://130.89.227.64/foddex/test/main.cpp

This code cannot be compiled without changing it, since there''s alot of stuff missing that''s not directly related to my problem.

Many thanks in advance to anyone who takes a look at the code!

Marc

Share this post


Link to post
Share on other sites
Why not remove all the D3D stuff between starting and ending the scene: i.e. don''t set texture states, render states, textures, don''t render anything, don''t set VB''s or IB''s. Can you check yoru FPS.

Could you still check yiour FPS?

Probably not.

Then just try rendering very very basic with no textures, colours etc.

Sorry if you''ve shown that in your posted code but I haven''t had a chance to look at that yet.

Good Luck

matt

Share this post


Link to post
Share on other sites
Hi matt! Thanks for your suggestion, but the big problem is: there's almost nothing to remove I do nothing fancy, no special vertex buffers, I'm setting hardly any renderstates. Just 2 triangles and a quad... (i'm still in my Direct3D testing-phase )
So I guess it's not so much a video-card performance issue, but more something I do wrong in Direct3D

By the way, can I use D3DX and 'normal' D3D stuff together? None of the MS-SDK examples do it, but I don't know if it's a bad thing

Marc

[edited by - Marc aka Foddex on March 24, 2004 10:35:35 AM]

[edited by - Marc aka Foddex on March 24, 2004 10:35:46 AM]

Share this post


Link to post
Share on other sites
FYI,
When I had this problem (see previous post of mine) I was using ther _REF device! As a stab in the dark, try using the _REF device but I''m willing to bet your problem won''t go away.

I was also using DirectX 8.



"Good code will come and go, but bad code sticks around."

Share this post


Link to post
Share on other sites
quote:
Original post by TreborZehn
FYI,
When I had this problem (see previous post of mine) I was using ther _REF device! As a stab in the dark, try using the _REF device but I''m willing to bet your problem won''t go away.

I was also using DirectX 8.



"Good code will come and go, but bad code sticks around."


Hi! How do I know whether or not I use the _REF device? I assume that with "_REF device" you mean some identifier that has the text _REF in it, right?
My code, where devices are concerned, looks like this:


m_device = (struct _GUID *)&IID_IDirect3DHALDevice;
....
m_d3d->EnumZBufferFormats( *m_device, EnumZBufferCallback, (VOID*)&ddpfZBuffer );
....
if( IsEqualIID( *m_device, IID_IDirect3DHALDevice ) )
ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
else
ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
....
if( FAILED( m_d3d->CreateDevice( *m_device, m_ddbbuff, &m_d3ddevice)))


Does look alright, doesn''t it? Please take a look at my source code (URL mentioned earlier), maybe you spot something unusual....

Marc

Share this post


Link to post
Share on other sites
I'm a little confused. I'm talking about C++ here but it looks like you might be using a managed version of DirectX? Anyway, D3D code usually contains a statement something like this...


g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice )


To ensure that your problem isn't a hardware problem you can use a "reference" device that's part of the SDK that does everything in software. To use it you specify D3DDEVTYPE_REF instead of D3DDEVTYPE_HAL. You'd have to look in your documentation of your "CreateDevice" call to see how to use it.

"Good code will come and go, but bad code sticks around."

[edited by - TreborZehn on March 24, 2004 5:13:19 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by TreborZehn
I'm a little confused. I'm talking about C++ here but it looks like you might be using a managed version of DirectX? Anyway, D3D code usually contains a statement something like this...


g_pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice )


To ensure that your problem isn't a hardware problem you can use a "reference" device that's part of the SDK that does everything in software. To use it you specify D3DDEVTYPE_REF instead of D3DDEVTYPE_HAL. You'd have to look in your documentation of your "CreateDevice" call to see how to use it.

"Good code will come and go, but bad code sticks around."


Hi! Thanks for taking the time to think of a solution for my problem, but I'm afraid you didn't notice that I'm using DirectX 7.0. The D3DADAPTER_xxxx identifiers do not appear in any of DirectX 7.0's header files :-/

[edited by - Marc aka Foddex on March 24, 2004 5:21:34 PM]

Share this post


Link to post
Share on other sites
There are two kinds of devices you can use with Direct3D (nominally): HAL and REF. HAL is the hardware layer--the normal one that you''ll generally use. REF is software-only. It''s used to test for correctness. If your code is doing wrong things, and you suspect a driver issue, you can run as a REF device and see what the proper behavior is, since the driver isn''t involved.

HAL is fast. REF is slooooow. It''s only ever used for debug purposes, and in demos to show off features even when cool hardware isn''t present. For game code, you''ll want to make sure your device is HAL, maybe with a command line for REF if you want to.

Oh, and my goodness, use DirectX9. So much tastier.

I like pie.

Share this post


Link to post
Share on other sites
quote:
Original post by RenderTarget
There are two kinds of devices you can use with Direct3D (nominally): HAL and REF. HAL is the hardware layer--the normal one that you''ll generally use. REF is software-only. It''s used to test for correctness. If your code is doing wrong things, and you suspect a driver issue, you can run as a REF device and see what the proper behavior is, since the driver isn''t involved.

HAL is fast. REF is slooooow. It''s only ever used for debug purposes, and in demos to show off features even when cool hardware isn''t present. For game code, you''ll want to make sure your device is HAL, maybe with a command line for REF if you want to.

Oh, and my goodness, use DirectX9. So much tastier.

I like pie.


Yeah I know DX9 is cooler than DX7 But I''m coding for a company who''s customers have outdated hardware and software. So I''m kinda stuck with DX7

But the good news is:
I SOLVED IT! :)

I updated my MSVC++6 version by installing Service Pack 5 and voila: all the problems are gone. I was linking against some old outdated lib''s I guess w00t!

Share this post


Link to post
Share on other sites