Sign in to follow this  
siri

Adding Elements ?

Recommended Posts

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.

Share this post


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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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)
Edited by siri

Share this post


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

Share this post


Link to post
Share on other sites

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);
        }

Share this post


Link to post
Share on other sites

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

 

[tt]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 ][/tt]

 

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.

Share this post


Link to post
Share on other sites

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

 

Maybe it's [url="http://www.gamedev.net/topic/639532-d3d11createdevice-failed/"]this sucker again[/url]. Cephalo had a similar problem [url="http://www.gamedev.net/topic/641267-debugging-dx11-shaders-as-a-hobbyist/"] here and successfully uninstalled that nasty update[/url] (again: at your own risk, if it's actually the problem). 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Ok, I still use VS 2010 (Express). VS 2012 seems to support native code debugging, even Express (s. here). It's for SharpDX but should apply to SlimDX too, hopefully. In that case you might ditch DebugView completely, since the messages should appear in the VS debug log.

Edit: The control panel still exists (it's the same for all DirectX stuff, not only graphics), but instead of a simple checkbox you explicitly select the application you want messages from. Can't confirm that it works, I always use the creation flag. Also: Not sure if that tool still comes with the newest DX SDK, I still haven't installed it. Edited by unbird

Share this post


Link to post
Share on other sites

I added it to the list, though I think the cp might be from the June SDK I have installed, still no output. I also installed the remote debugger but that didn't help either.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this