How do you multithread in Directx 11?,
Members - Reputation: 360
Posted 13 August 2012 - 03:27 AM
Moderators - Reputation: 48930
Posted 13 August 2012 - 04:07 AM
How many milliseconds does your game currently use to perform all of it's D3D calls on the CPU? Multi-threading your D3D calls is an optimisation, and the first step in optimizing is always to take measurements.
from what I heard,to really make the performance acceptable,you have to implement multithreading?
Keep in mind, the bulk of rendering takes place on the GPU, with the CPU only managing resources and submitting commands - so you'll only need to multi-thread your CPU code if you need to submit a LOT of commands, or if you do a lot of resource management at the same time as rendering.
Members - Reputation: 360
Posted 13 August 2012 - 04:20 AM
Members - Reputation: 1815
Posted 13 August 2012 - 08:24 AM
You aren't listening to what Hodgman is saying here. Do you know how much of that time is spent queuing up draw calls on the CPU? What he's getting at is that you may actually be GPU limited-- that is, your CPU is mostly farting around waiting for the GPU to do the work assigned to it. You'd ultimately end up making the CPU fart around even more for no actual performance gain and in fact stand to make it worse if you handle threading poorly-- many professionals still can't get this right, although that's probably more the result of mediocre teaching than any inherent difficulty.
It takes 7 miliseconds to render a large building with 10 large directional lights and about 11 miliseconds for 60 large directional lights.I'm not very happy about the performance right now and I'm gonna optimize some more and implement instancing,but from what I understood modern engines like Frostbite 2 have both instancing and multi-threaded rendering.The thing is I have no idea how to implement multithreading,what changes do I have to make to my device and context creation?Currently I'm just using D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &DEVICE, NULL, &CONTEXT));
For what it's worth, though, this and this (and even more specifically, these two methods) should help get you started.
Crossbones+ - Reputation: 4005
Posted 14 August 2012 - 12:07 AM
Each thread that handles rendering tasks has its own deferred context. Once the secondary threads have done their tasks for the frame (which usually is the CPU-side heavy lifting), you play back their finished command lists on the primary context to actually submit the state changes and draw commands to the device.
The SDK has a programming guide article about this: "Immediate and Deferred Rendering".
Members - Reputation: 1169
Posted 14 August 2012 - 12:20 AM