dx11 faster loading of hlsl files

David_Gallagher 102 Jan 23, 2012 at 07:32

In my engine I have some default shaders that are loaded on startup(but this is relevant even when using custom user end shaders) and it’s starting to take a long time to load and I’ve only got 14 shaders being created.

I’m using D3DX11CompileFromFile(), shader model 5 and am not currently using .fx files but am loading from seperate .hlsl files the VS,HS,DS,PS etc…

in dx9 i was able improve shader loading time by using .fxo files but am wondering if this is possible to do with hlsl files, information seems scarse on this or maybe I’m just missing the understanding of it comming into dx11.

does anyone know how to increase speed on the creation of shaders in hlsl shader model 5, is it just the compiling that is taking the time, is it possible to precompile? if so how can I assign the precompiled data to a blob as it doesn’t seem like that’s possible but maybe I’m just not understanding something as I’m a bit green coming into dx11 from dx9. and
I’d like to stay away from the effect file (.fx) if possible as I’m liking the way the hlsl files are currently layed out but will change if it’s the only way to get the speed up.

thanks for any advice on this.

2 Replies

Please log in or register to post a reply.

Reedbeta 167 Jan 23, 2012 at 19:03

You can use D3DX11CompileFromFile() and then you should be able to save out the blob it generates to a file, then reload it later and do CreatePixelShader() etc. on it. Assuming the D3DX11CompileFromFile() call is what’s taking most of the time, you’ll get a speedup if you only recompile when necessary (when the shader source has changed), otherwise just reload the previously compiled blob.

David_Gallagher 102 Jan 23, 2012 at 23:35

ah much better :), Thanks Reedbeta, I realized I had asked similar question to this and was overcomplicating myself and also confused as to lack of current functions dealing with this and saw I had to make my own read and write functions for the blob. my shaders now load in the blink of an eye, thanks for confirming the best way to do it.