Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX and windows message thread which thread?

Started by J81 Apr 14, 2005 at 6:07 PM 3 replies 1.2k views
Original Post
J81
J81
Do all Direct3D calls have to be used on the windows message/event thread. Like the DX9.0c examples? I think in DX8.0 they were not. It’s clear from the docs all calls must be “strongly segregate” I’m just checking that you can either put all the calls on the message thread or on the application thread(s) but not both. Are there any advantages having the DirectX calls on the message thread. The bit in the docs that seems slightly confusing is below. (Apologies if I’m breaking copyright by quoting MS docs) “In particular, an application must be sure to strongly segregate its window message handling threads from its Direct3D threads. An application that causes a mode change on one thread but makes Direct3D calls on a different thread in its window procedure is in danger of deadlock. For these reasons, Direct3D is designed so that the methods IDirect3DDevice9::Reset, IDirect3D9::CreateDevice, IDirect3DDevice9::TestCooperativeLevel, or the final Release of IDirect3DDevice9 can only be called from the same thread that handles window messages.”
circlesoft
circlesoft
Interpreting the docs (it's okay to quote them, by the way [smile]), it looks like those functions listed *must* be called from the message thread. You can call other D3D functions from any thread.

However, it is not suggested to take a multi-threaded approach to D3D. If you want to use multi-threading, you have to create the device with D3DCREATE_MULTITHREADED, which tells the runtime to enter critical sections more frequently. The performance penalty of this can be severe. For that reason, it is suggested that you keep D3D running in a single-threaded environment.
DrunkenHyena
DrunkenHyena
I'd adjust that recommendation to "keep your D3D calls in a single thread". There are plenty of good things you can do with multiple threads, but I wouldn't call D3D from them. For example, if one thread handles your IO, then rather than have it make any calls to D3D directly it should send a "message" to your main D3D thread for it to handle it.
Stay Casual,KenDrunken Hyena</FON
J81
J81
Thanks, no plans to call DirectX from multiple threads just had to make sure about that message thread :-)
J81
J81
As far as I can see in the Direct3d samples contrary to the quote above they call IDirect3D9::CreateDevice in the app thread rather than in the message thread. Which is the way I do it also. Else where in the docs it seems to indicate as long as all the calls are in the same thread all is well.

[Edited by - J81 on April 15, 2005 4:52:50 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.