Jump to content
  • Advertisement
Sign in to follow this  
jkristia

problem defining the VS input struct

This topic is 2130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have run into a problem when I tried to add the third property to my input struct, and I cannot see what I'm doing wrong, but I'm sure it is something obvious.

I have defined my C# struct, the shader struct and the layout. Checking the vertex buffer I see the POS at the right position, and 1,2,3,4 for the 'normal' vector4 and 11,22,33,44 for the last property.

When I debug the shader code with the graphical editor (can't figure out how to debug the code using the AMD PerfStudio) then I see the input struct contains 1,2,3,4 for the POS property, and the other 2 shows 'cannot display'.

 

If I remove Test from the Vertex struct without changing anything else, then it works.

 

Any idea what I'm missing?

C# SharpDX definition

 [Serializable, StructLayout(LayoutKind.Sequential, Pack=4)]
 public struct Vertex
 {
  public Vector4 Pos;
  public Vector4 Normal;
  public Vector4 Test;
  public Vertex(Vector4 pos)
  {
   Pos = pos;
   Normal = new Vector4(1,2,3,4);
   Test = new Vector4(11,22,33,44);
  }
 }

 

Layout definition

 

    rc.InputLayout = new InputLayout(rc.Device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[]
     {
  new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float,  0, 0),
  new InputElement("NORMAL"  , 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 16, 0),
  new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 32, 0)
     });

fx definition
 struct VS_IN
 {
  float4 pos : POSITION;
  float4 normal : NORMAL;
  float4 test : TEXCOORD;
 };

vertex buffer
0 [0x00000000-0x00000003] |           -0.625
1 [0x00000004-0x00000007] |           -0.625
2 [0x00000008-0x0000000b] |           -0.625
3 [0x0000000c-0x0000000f] |               +1
4 [0x00000010-0x00000013] |               +1
5 [0x00000014-0x00000017] |               +2
6 [0x00000018-0x0000001b] |               +3
7 [0x0000001c-0x0000001f] |               +4
8 [0x00000020-0x00000023] |              +11
9 [0x00000024-0x00000027] |              +22
10 [0x00000028-0x0000002b] |              +33
11 [0x0000002c-0x0000002f] |              +44
12 [0x00000030-0x00000033] |           -0.625  <-- new vertex
13 [0x00000034-0x00000037] |           +0.625

Share this post


Link to post
Share on other sites
Advertisement

argh... smile.png. That is it. I forgot to change the size when setting the vertex buffer. Still using the other vertex struct I had defined as a test.

 

rc.Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_vertexBuffer, Utilities.SizeOf<Vertex>(), 0));

Edited by jkristia

Share this post


Link to post
Share on other sites
That's a big vertex you got there wink.png

Yep, usually you can rely on the interop information for the size (Marshal.SizeOf(typeof(Vertex)) or the similar SharpDX convenience function). The offsets can also be grabbed using Marshal.OffsetOf. Or make your life even easier - given your vertex elements are tightly packed - using InputElement.AppendAligned, like so (disclaimer: unchecked)

    rc.InputLayout = new InputLayout(rc.Device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[]
      {
   new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32A32_Float,  0, 0),
   new InputElement("NORMAL"  , 0, SharpDX.DXGI.Format.R32G32B32A32_Float, InputElement.AppendAligned, 0),
   new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, InputElement.AppendAligned, 0)
      });

As an aside: You usually don't need a Vector4 for position (even less for normal). I still have to come across an MSDN entry, but a 3D vector (x,y,z) will be automatically expanded to (x,y,z,1) on the shader side, if declared as float4. You're wasting a bit of bandwidth otherwise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!