This topic is 1166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey guys,

I am currently trying to automatically load a directory full of compiled shader objects (*.cso) built at compile time by MVS2013. The problem I have is that I seem to be unable to determine if a CSO is a vertex shader or pixel shader by any means other than calling CreateVertexShader and seeing if it fails or not. While this works it is certainly not a desirable solution and it clogs up the output with debug messages and first chance exceptions.

I've been searching around, found out about shader reflection but the documentation on that is far from complete. Does anyone have a nice solution to this? I'd like to avoid particular file naming conventions or directory structures if possible. This seems like a trivial problem and I've probably just overlooked something really simple.

Thanks

Share on other sites

Thanks unbird, thats exactly what I was looking for.

For anyone else who is interested I found that D3D11_SHADER_DESC::Version = 65600 for a vertex shader and 64 for a pixel shader, note that I'm using vs_4_0 and ps_4_0.

If anyone can find a more comprehensive answer than that it'd be more than welcome.

Share on other sites
Looking at hex values it's more obvious:

vs_5_0 : 0x10050
hs_5_0 : 0x30050
ds_5_0 : 0x40050
gs_5_0 : 0x20050
ps_5_0 : 0x00050
cs_5_0 : 0x50050

vs_4_0 : 0x10040
gs_4_0 : 0x20040
ps_4_0 : 0x00040
cs_4_0 : 0x50040

Seems high-word is stage, low-word is shader model.

Cheers

Share on other sites

Looking at hex values it's more obvious:

vs_5_0 : 0x10050
hs_5_0 : 0x30050
ds_5_0 : 0x40050
gs_5_0 : 0x20050
ps_5_0 : 0x00050
cs_5_0 : 0x50050

vs_4_0 : 0x10040
gs_4_0 : 0x20040
ps_4_0 : 0x00040
cs_4_0 : 0x50040

Seems high-word is stage, low-word is shader model.

Cheers

Its interesting that pixel shader is zero on the high word, and the order doesn't seem to follow a logical pattern.  I wonder how they chose the order???

Share on other sites
Its interesting that pixel shader is zero on the high word, and the order doesn't seem to follow a logical pattern.  I wonder how they chose the order???

Seems evident enough.  The first two shader stages that were available in the earliest hardware - ps and vs - are 0 and 1 (although I would have expected vs to be 0 and ps 1, but maybe there are historical reasons going back to D3D8 days for that).  gs was available next in D3D10 and that's 2.  Then the tesselation stages are 3 and 4, and finally compute is 5.

Since the D3D11 shader compiler can be used to compile downlevel shaders (down to SM2 IIRC) which can then be loaded by D3D9 programs, the order is obviously fixed for backward compatibility reasons.

Share on other sites

The information in this thread is pure gold, i am currently loading my shaders from three different directories called pixel, geom and vertex because I didn't know where to look to do this - this is an absolute lifesaver. Thanks!

Edit: I've knocked up a quick function which should work for this, i plan to use this function myself - you're welcome to it also:

/**
* Parameters:
*	bufsize:   Size of compiled shader data
* Returns:
*/
{
reflector->Release();
return vtype;
}


Have fun!

Edited by braindigitalis