HWND and multithreading

Started by
3 comments, last by Dragon_Strike 15 years, 8 months ago
ive been thinking about the windows api window handle and multithreading... since both the main thread and render thread needs this handle... im wondering if i have to do some synchronizing or if its already thread safe? right now i simple send a copy of the HWND to my render thread which uses it to initialize direct3d...
Advertisement
Quote:Original post by Dragon_Strike
ive been thinking about the windows api window handle and multithreading...

since both the main thread and render thread needs this handle... im wondering if i have to do some synchronizing or if its already thread safe?
The HWND itself is thread safe, yes. If you use SendMessage() to send messages to your window, then your window proc needs to handle being called from multiple threads though (So you'll have to do synchronisation there).

Quote:Original post by Dragon_Strike
right now i simple send a copy of the HWND to my render thread which uses it to initialize direct3d...
CreateDevice() has to be called from the thread that handles window messages, which is usually your main thread. See Here.
I also seem to recall reading somewhere that there can be problems using D3D from a thread that isn't your main thread. And you'll definitely want to keep all D3D access in one thread in any case.
Quote:Original post by Evil Steve
Quote:Original post by Dragon_Strike
ive been thinking about the windows api window handle and multithreading...

since both the main thread and render thread needs this handle... im wondering if i have to do some synchronizing or if its already thread safe?
The HWND itself is thread safe, yes. If you use SendMessage() to send messages to your window, then your window proc needs to handle being called from multiple threads though (So you'll have to do synchronisation there).

Quote:Original post by Dragon_Strike
right now i simple send a copy of the HWND to my render thread which uses it to initialize direct3d...
CreateDevice() has to be called from the thread that handles window messages, which is usually your main thread. See Here.
I also seem to recall reading somewhere that there can be problems using D3D from a thread that isn't your main thread. And you'll definitely want to keep all D3D access in one thread in any case.


im using direct3d10... soo all direct3d resources are create and all directd functions are called in a seperate thread(not the main thread)... soo the direct3d device and everything is called in this seperate thread... is this how it should be done?

it works well.. however when i try to do frame debugging with nvperfhud it always crashes...

EDIT:

Quote:CreateDevice() has to be called from the thread that handles window messages, which is usually your main thread. See Here.
I also seem to recall reading somewhere that there can be problems using D3D from a thread that isn't your main thread. And you'll definitely want to keep all D3D access in one thread in any case.


ive read that the direct3d device has to be created in the same thread its used? is that wrong?
Quote:Original post by Dragon_Strike
im using direct3d10... soo all direct3d resources are create and all directd functions are called in a seperate thread(not the main thread)... soo the direct3d device and everything is called in this seperate thread... is this how it should be done?

it works well.. however when i try to do frame debugging with nvperfhud it always crashes...
It's possible that this is a bug with NVPerfHUD, although I'm not really sure with D3D10 stuff. In DX9, it's A Good Thing to keep all access to D3D in one single thread though.

Quote:Original post by Dragon_Strike
ive read that the direct3d device has to be created in the same thread its used? is that wrong?
I'm not sure about D3D10. In D3D9, that's true though.

It might be worth PM'ing a mod and asking them to move this thread to the DirectX forum, if your questions are mostly DirectX orientated. As for general HWND-related stuff, you could log all calls to your window proc, and dump the current thread ID to tell if it's being called from multiple threads (If you think it shouldn't be). GetCurrentThreadId will tell you that.
Quote:Original post by Evil Steve
Quote:Original post by Dragon_Strike
im using direct3d10... soo all direct3d resources are create and all directd functions are called in a seperate thread(not the main thread)... soo the direct3d device and everything is called in this seperate thread... is this how it should be done?

it works well.. however when i try to do frame debugging with nvperfhud it always crashes...
It's possible that this is a bug with NVPerfHUD, although I'm not really sure with D3D10 stuff. In DX9, it's A Good Thing to keep all access to D3D in one single thread though.

Quote:Original post by Dragon_Strike
ive read that the direct3d device has to be created in the same thread its used? is that wrong?
I'm not sure about D3D10. In D3D9, that's true though.

It might be worth PM'ing a mod and asking them to move this thread to the DirectX forum, if your questions are mostly DirectX orientated. As for general HWND-related stuff, you could log all calls to your window proc, and dump the current thread ID to tell if it's being called from multiple threads (If you think it shouldn't be). GetCurrentThreadId will tell you that.


thx... ill just create a new thread in the directx forum... since this got off topic... u answered my original question

This topic is closed to new replies.

Advertisement