Sign in to follow this  
Daichi

DirectX Multithreading

Recommended Posts

Is it safe to run my DX9 game loop in a separate thread from my message-pump? Here is what I got right now. My DX class is a global. Inside my WinMain: - initialize my DX class - start my Game loop thread - start a simple 'GetMessage' Message-pump Now this works find and dandy, but If I loose my d3ddevice, I'm unable to reset it and I get this message. Direct3D9: (ERROR) :Reset can only be called from the thread that the device was created from. And I get other errors if I try to create the d3ddevice within my game thread. I suppose I can go back to a single thread and using 'PeakMessage' instead but I was hoping to try some multithreading. -Daichi

Share this post


Link to post
Share on other sites
Yes, multithreading is fine, so long as the calls to D3D are all from the same thread. If you want to make D3D calls from several threads, you need to pass the D3DCREATE_MULTITHREADED flag to IDirect3DDevice9::CreateDevice() - But IDirect3DDevice9::Reset() can only be called from the thread that called CreateDevice(). From the decumentation:
Quote:
A call to IDirect3DDevice9::Reset will fail if called on a different thread than that used to create the device being reset.


In your code, you probably reset the device in your window proc. What you really should be doing, is signalling to the render thread that it's ok to reset the device (Or spin the render thread in a TestCooperativeLevel() loop until it returns D3DERR_DEVICENOTRESET).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I wasn't having any luck with it. I'm actually doing next to nothing in my WinProc. I am using the multithreaded flag. I assume I need to Create the device in the same thread I render in? But that was just spitting out other errors. I also tried putting the message pump in it's own thread which I also didn't have much luck with. I'm obviously doing things wrong, So I think I'll give up for now and come back to it after I do more reading on the topic. :(

Or does anyone know if there are any DX multithreaded examples I could take a look at?

-Daichi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this