Jump to content
  • Advertisement
Sign in to follow this  
hupsilardee

DX11 [D3D11] Problems with shader reflection

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!