Given: Selfmade 3D engine based on DirectX9 written in C++
Task: While render loop runs load additional textures in a background thread
Current Implementation: - Create device with D3DCREATE_MULTITHREADED - Ensure that loaded content is used by render thread only after loading finished
Problem: Loading performance is very poor because DirectX calls block most of the time
More specific: Seems that all DirectX calls are blocked for the whole duration the "Present" call waits for the vsync. That is in my case 99% of the time -> Loading thread has very few opportunities to run its DirectX calls.
Absurd observation (on first sight): Loading performance gets much better when I deactivate vsync and the render tread runs full speed. That is because the relative portion of time the render thread is inside a DirectX function is lower.
Possible but problematic solution: Do not let "Present" wait for the vsync, instead do a "while" loop with a non waiting "Present" and as long as it returns "D3DERR_WASSTILLDRAWING" do a short "Sleep".
But I do not like that solution: First I am afraid it degrades maximum performance of the render loop as the resolution of "Sleep" time is limited. Second problem is that I am using multihead rendering with several monitors and I am afraid taking away full control about vsyncing from DirectX might introduce effects like tearing on some monitors or something like that.
First question: Why? I would bet my life that blocking whole DirectX while waiting for vsync is not neccessary especially while I am only using separated resources in the loading thread. But, well, it is like Microsoft implemented it and I am afraid I have to deal with it.
Second question: Better ideas, anyone? Does anybody have a better solution for this, or enough experience to tell me that my possible solution is not problematic at all or can think of a better way.
I know that Microsoft worked on these things with DirectX11 but porting the whole thing now is not an option, it would take too much time.
Thanks for your time, Ole