[D3D11] Problems with shader reflection

Started by
3 comments, last by hupsilardee 12 years, 2 months ago
Trying to get shader reflection working, so I can load a shader then assign variables easily using the name (like with the old ID3DXConstantTable)

However, reflection only seems to work for new shader models, which is useless to me at the moment because my graphics card only supports shader model 3. Why wont it work for shader model 4?

The following shader will compile correctly for both vs_3_0 and vs_4_0, without any changes to the shader code. However, reflection fails for vs_3_0, but succeeds for vs_4_0


float4x4 World;
float4x4 View;
float4x4 Proj;

float4 VertexShaderFunc(float4 iPos : POSITION0) : SV_POSITION
{
float4 worldPos = mul(iPos, World);
float4 viewPos = mul(worldPos, View);
float4 projPos = mul(viewPos, Proj);

return projPos;
}


The code to load:

// error handling removed for brevity
ID3D10Blob* pShader = NULL;
ID3D10Blob* pErrors = NULL;

char function[] = "VertexShaderFunc";
char profile[] = "vs_3_0";

HRESULT hr = D3DX11CompileFromFile("VertexShader.txt", NULL, NULL, function, profile,
0, 0, NULL, &pShader, &pErrors, NULL);

ID3D11ShaderReflection* pReflection;
hr = D3DReflect(pShader->GetBufferPointer(), pShader->GetBufferSize(), IID_ID3D11ShaderReflection,
(void**)&pReflection);


what can i do?
Advertisement
Bump: Nobody know why D3D can't reflect a shader successfully compiled VS_3_0 shader?
I don't personally have any experience with this personally, but some of the other DX MVPs have suggested that you need to use the downlevel shader targets since vs_3_0 is not directly supported. So for instance you need to use this: vs_4_0_level_9_3 for an equivalent to shader model 3 (although you have to note that this is not directly the same as vs_3_0!!).

Give that a shot and see if it works out for you.
Oh, I'd never even heard of vs_4_0_level_9_3 before, and I read the documentation and tutorial sections quite carefully...
Thanks for the heads up, I'll try that immediately!
It kind of worked (D3D_FEATURE_LEVEL_9_3 + hardware device), but I can't use SV_INSTANCEID sad.png
Other than that, constant buffers and reflection worked flawlessly! Also, ps_4_0_level_9_3 compiles ok but the shader doesn't want to be created (it was fine with a D3D_FEATURE_LEVEL_10_1 + WARP device)... I assume that's down to my graphics card and not the shader. (ps_4_0_level_9_2 worked though).
Thanks Jason!

This topic is closed to new replies.

Advertisement