Adding Elements ?

Started by
13 comments, last by unbird 11 years ago

Hello,

I've spent the day getting a triangle to render in SlimDX and reading up on things. It was all going well until I tried to make the shader a little more complex. I just want to add a per-vertex colour. But when I did my vertex layout broke and I'm not sure why. The exception being thrown is the following:


 
An unhandled exception of type 'SlimDX.Direct3D11.Direct3D11Exception' occurred in SlimDX.dll
 
Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

I managed to find a thread that seems related: http://www.gamedev.net/topic/607455-slimdx-directx11-inputlayout-failure/

I'm not sure if that really helps or not as I don't fully understand it. He seems to be passing his DataStream as the signature which I'm not doing( Or if I am it's in such a way that I don't realise I am. ). I'm using the ShaderByteCode from the vertex program. This all worked for a triangle with only positional data being sent. It breaks on the Layout creation line.


 
            var elements = new[] { new DX.InputElement("POSITION", 0, GI.Format.R32G32B32_Float, 0),
                                   new DX.InputElement("COLOR", 0, GI.Format.R32G32B32A32_Float, DX.InputElement.AppendAligned)
            };
 
//Breaks on this line.
            VertexLayout = new DX.InputLayout(CoreComponents.mVideo.mDevice, HLSL.ShaderSignature.GetInputSignature(VPByte), elements);

The shader looks like this:


 
struct a2v {
float3 p : POSITION;
float4 c : COLOR0;
};
 
struct v2f {
float4 p : SV_POSITION;
float4 c : TEXCOORD0;
};
 
v2f vp(a2v a2vin) {
v2f v2fout;
 
v2fout.p  = float4(a2vin.p, 1);
v2fout.c  = a2vin.c;
 
return v2fout;
}
 
float4 fp(v2f v2fin): SV_TARGET {
return v2fin.c;
}

Any help or advice would be appreciated. Thank you.

Advertisement
From a quick glance your code looks fine, so the problem might originate from elsewhere. Use D3D11_CREATE_DEVICE_DEBUG to get more information about why that call fails. Depending on what IDE you use (e.g. VS 2010 Express does not support native code debugging), you also want to install DebugView to grab the debug messages.

From a quick glance your code looks fine, so the problem might originate from elsewhere. Use D3D11_CREATE_DEVICE_DEBUG to get more information about why that call fails. Depending on what IDE you use (e.g. VS 2010 Express does not support native code debugging), you also want to install DebugView to grab the debug messages.

Thanks unbird, I'll give those suggestions a try and get back.


DebugView gives me the following output.


[5956] 
[5956] *** HR originated: -2147024774
[5956] ***   Source File: d:\iso_whid\x86fre\base\isolation\com\copyout.cpp, line 1391
[5956] 
[5956] 
[5956] *** HR propagated: -2147024774
[5956] ***   Source File: d:\iso_whid\x86fre\base\isolation\com\identityauthority.cpp, line 278
[5956] 
I've changed my vertex program as I think the problem is that the elements don't match the signature. But it's still throwing the same exception.
struct v2f {
float4 p : SV_POSITION;
float4 c : COLOR;
};
v2f vp(float3 p : POSITION,
float4 c : COLOR) {
v2f v2fout;
v2fout.p = float4(p, 1);
v2fout.c = c;
return v2fout;
}
Adding the debug flag to the device creation doesn't seem to help( I'm not entirely sure what I'm looking for ). The output is the same.


A first chance exception of type 'SlimDX.Direct3D11.Direct3D11Exception' occurred in SlimDX.dll
An unhandled exception of type 'SlimDX.Direct3D11.Direct3D11Exception' occurred in SlimDX.dll
Additional information: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)
You should get more info than that, I think. Did the device creation succeed with that flag ? If yes, post some more of your code: How you load your shader, how you compile, etc.

Edit, ah sorry for being stupid: In SlimDX the debug flag is of course DeviceCreationFlags.Debug.

You should get more info than that, I think. Did the device creation succeed with that flag ? If yes, post some more of your code: How you load your shader, how you compile, etc.

I'm doing things pretty much the way the SlimDX tutorial did.


// Device creation.
 
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                Usage             = Usage.RenderTargetOutput,
                OutputHandle      = hHandle,
                IsWindowed        = bWindowed,
                ModeDescription   = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Flags             = SwapChainFlags.AllowModeSwitch,
                SwapEffect        = SwapEffect.Discard
            };
 
            SlimDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out mDevice, out mSwapChain);
 
// Shaders.


        public void CreateVertexProgram(String strFilename, String strEntry, String strTarget) {
            VPByte        = HLSL.ShaderBytecode.CompileFromFile(strFilename, strEntry, strTarget, HLSL.ShaderFlags.Debug, HLSL.EffectFlags.None);
            VertexProgram = new DX.VertexShader(CoreComponents.mVideo.mDevice, VPByte);
        }
 
        public void CreateFragmentProgram(String strFilename, String strEntry, String strTarget) {
            FPByte          = HLSL.ShaderBytecode.CompileFromFile(strFilename, strEntry, strTarget, HLSL.ShaderFlags.None, HLSL.EffectFlags.None);
            FragmentProgram = new DX.PixelShader(CoreComponents.mVideo.mDevice, FPByte);
        }

I tried your code and found the bug. The debug layer does actually tell me the problem:

D3D11: ERROR: ID3D11Device::CreateInputLayout: Element[1]'s slot (-1) too high. Max slot index for current feature level is 15. [ STATE_CREATION ERROR #154: CREATEINPUTLAYOUT_INVALIDSLOT ]

You're using InputElement wrong: The last entry in that particular constructor is the slot number, not the offset. That overload actually uses InputElement.AppendAligned per default. This works:


var elements = new[] {
  new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
  new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0)
};

I wonder why you don't get proper debug messages.

Yep, it's working now. Thank you unbird.

You're welcome. But I really recommend getting the debug messages working - you can't sensibly develop without them.

Maybe it's this sucker again. Cephalo had a similar problem here and successfully uninstalled that nasty update (again: at your own risk, if it's actually the problem).

It's not failing but I'm not seeing any DX debug output. I am using VS2012 and Windows 8 so I assume I'm covered there. Do I need to turn it on ? -- I remember something about DX9 needing a checkbox ticked somewhere in order to get debug output.

This topic is closed to new replies.

Advertisement