Jump to content

  • Log In with Google      Sign In   
  • Create Account


[D3D11] Problems with shader reflection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 05 February 2012 - 09:32 AM

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?

Sponsor:

#2 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 06 February 2012 - 03:25 AM

Bump: Nobody know why D3D can't reflect a shader successfully compiled VS_3_0 shader?

#3 Jason Z   Crossbones+   -  Reputation: 4901

Like
0Likes
Like

Posted 06 February 2012 - 04:21 AM

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.

#4 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 06 February 2012 - 12:52 PM

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!

#5 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 06 February 2012 - 01:01 PM

It kind of worked (D3D_FEATURE_LEVEL_9_3 + hardware device), but I can't use SV_INSTANCEID Posted Image
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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS