<p>From what I can find out (not having tried it myself), using a thread per core to do D3D compiles is <a href="https://twitter.com/solid_angle/status/327572869699731457">reported</a> to be safe and gives a good perf speedup, and there <a href="https://twitter.com/repi/status/327580478062333952">doesn't seem to be any contention</a> between threads in the compiler itself.</p>

<p>However, <a href="https://twitter.com/rygorous/status/327582029296324608">Fabian Giesen notes</a> that you might see lower perf when running under a debugger, due to contention in the Windows debug heap allocator, <a href="http://preshing.com/20110717/the-windows-heap-is-slow-when-launched-from-the-debugger/">which can (and probably should) be disabled</a>.</p>

<p>BTW, the functions you mentioned are both wrappers around <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd607324.aspx"><code>D3DCompile</code></a>, and don't involve the driver per se at all; they only do the GPU-independent "HLSL source to bytecode" step, and not the GPU-specific "bytecode to machine code" step. So they're entirely Microsoft code, not GPU IHV code.</p>

CC BY-SA 3.0
2016-06-17T04:11:11.553Z
2016-06-17T04:11:11.553Z
Nathan Reed
<p>To compile shaders, I currently spin up a thread per core where each thread pulls a shader from a list and calls D3DX11CompileFromFile for dx11 and D3DXCompileShaderFromFile for dx9.</p>

<p>I've heard it mentioned that spinning up multiple processes instead of multiple threads can be faster, since there is some sort of per process driver contention.</p>

<p>Has anyone tried this, or does anyone have any tips on how to speed up shader compilation?</p>

<p>I have a modern machine w/ SSD drives.</p>

<shader>
Fastest shader compilation strategy on windows dx9 and dx11?
Alan Wolfe
# Fastest shader compilation strategy on windows dx9 and dx11?

(Asked by: username_0 on 2016-06-16)

To compile shaders, I currently spin up a thread per core where each thread pulls a shader from a list and calls D3DX11CompileFromFile for dx11 and D3DXCompileShaderFromFile for dx9.

I've heard it mentioned that spinning up multiple processes instead of multiple threads can be faster, since there is some sort of per process driver contention.

Has anyone tried this, or does anyone have any tips on how to speed up shader compilation?

I have a modern machine w/ SSD drives.

**Tags:** shader


---

## 1 answers

### Answer by username_1 on 2016-06-17. Score: 4 | Accepted answer

From what I can find out (not having tried it myself), using a thread per core to do D3D compiles is [reported](https://twitter.com/solid_angle/status/327572869699731457) to be safe and gives a good perf speedup, and there [doesn't seem to be any contention](https://twitter.com/repi/status/327580478062333952) between threads in the compiler itself.

However, [Fabian Giesen notes](https://twitter.com/rygorous/status/327582029296324608) that you might see lower perf when running under a debugger, due to contention in the Windows debug heap allocator, [which can (and probably should) be disabled](http://preshing.com/20110717/the-windows-heap-is-slow-when-launched-from-the-debugger/).

BTW, the functions you mentioned are both wrappers around [`D3DCompile`](https://msdn.microsoft.com/en-us/library/windows/desktop/dd607324.aspx), and don't involve the driver per se at all; they only do the GPU-independent "HLSL source to bytecode" step, and not the GPU-specific "bytecode to machine code" step. So they're entirely Microsoft code, not GPU IHV code.


---

