Today has been a painful introduction to Direct3D 11 for me. I have successfully got a device initiated and displaying a blank screen (no geometry).
I'm now trying to load and apply an effect to get some geometry showing. Unfortunately, the loading and usage of an effect is tripping me up. I think the problem is down to the fact that I'm targetting 'FeatureLevel.Level_9_1' but I'm not sure.
Here is my fx file, as simple as can be:
struct VS_IN
{
float4 pos : POSITION;
};
struct PS_IN
{
float4 pos : SV_POSITION;
};
PS_IN vs_main(VS_IN input)
{
PS_IN output = (PS_IN)0;
output.pos = input.pos;
return output;
}
float4 ps_main(PS_IN input) : SV_Target
{
return float4(1, 0, 0, 1);
}
technique Render
{
pass P0
{
SetVertexShader(CompileShader(vs_2_0, vs_main()));
SetPixelShader (CompileShader(ps_2_0, ps_main()));
}
}
Note that it's simple vertex / pixel shader.
And this is me trying to load the effect:
ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile("Default.fx", "Render", "fx_5_0", /*"vs_4_0_level_9_1", */ShaderFlags.EnableStrictness, EffectFlags.None);
Effect effect = new Effect(this.device, this.effectByteCode, EffectFlags.None);
The loads succeeds (although I'm unsure if it's 'safe' to use the "fx_5_0" profile when targetting Direct3D 9, and vertex / pixel shaders 2.0)? The 'vs_4_0_level_9_1' comment was an alternative profile that I tried, with no success.
The problem occurs when I try to use the effect:
EffectTechnique tech = effect.GetTechniqueByIndex(0);
EffectPass pass = tech.GetPassByIndex(0);
InputLayout input = new InputLayout(this.device, pass.Description.Signature, new InputElement[]
{
new InputElement("POSITION0", 0, Format.R32G32B32_Float, 0, 0)
});
GetTechniqueByIndex fails with 'ID3DX11Effect::GetTechniqueByIndex: Invalid technique index (0)', which doesn't cause SlimDX to except until the InputLayout instance is created. I've tried the same with the following:
EffectTechnique tech = effect.GetTechniqueByName("Render");
EffectPass pass = tech.GetPassByIndex(0);
InputLayout input = new InputLayout(this.device, pass.Description.Signature, new InputElement[]
{
new InputElement("POSITION0", 0, Format.R32G32B32_Float, 0, 0)
});
But then the GetTechniqueByName method excepts with 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
I'm not sure where I'm going wrong - if my shader code is wrong, if it's compiled incorrectly for Direct3D 9, etc.
Hopefully someone can help me? Thanks.