Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the DirectX Effects framework and I want to create an input layout automatically when compiling an effect. I've tried to call ID3DX11Effect->GetVariableByName() with the shader's name, to obtain a pointer to a ID3DX11EffectVariable interface, then doing ID3DX11EffectVariable->AsShader() to obtain a pointer to a ID3DX11EffectShaderVariable interface. The problem is that the pointer returned by ID3DX11Effect->GetVariableByName() is not valid (the IsValid() method returns false). So how can I get a pointer to the shaders of an effect file ?

share|improve this question
up vote 1 down vote accepted

The effect framework is based around the concepts of techniques and passes, so you will need to go through these to get to your shader. The API will let you get a list of techniques in the effect and a list of passes in a technique; you can then extract the shaders from the pass.

Here is the code from my engine that extracts the vertex shader from the first pass of the first technique of an effect and goes through its input signature. I've removed the error checking for brevity, but you can see how it would work.

ID3DX11EffectTechnique * pTech = m_pEffect->GetTechniqueByIndex(0);

ID3DX11EffectPass * pPass = pTech->GetPassByIndex(0);
D3DX11_PASS_DESC passDesc;


ID3DX11EffectShaderVariable * pVs;
pVs = vsPassDesc.pShaderVariable->AsShader();

pVs->GetShaderDesc(0, &vsDesc);

// Build the vertex format
for (UINT iInput = 0; iInput < vsDesc.NumInputSignatureEntries; ++iInput)
    pVs->GetInputSignatureElementDesc(0, iInput, &inputDesc);
    // do something with the input element...
share|improve this answer
Thanks, I got it working now. Although I'm not certain if I should continue using the effects framework, since its pretty much dead from what I've been reading. – user25894 Feb 3 '13 at 20:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.