Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

SlimDX Constant Buffer Issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Butabee   Members   -  Reputation: 180

Like
0Likes
Like

Posted 17 October 2012 - 11:11 PM

I can't seem to get my cbuffer values into my shader correctly.

Here's my struct:

[StructLayout(LayoutKind.Explicit, Size=2048*16)]
struct cbuff
{
[FieldOffset(0)]
public Vector4[] shadebuff;
};


This is how I create the buffer:

sbuff = new SlimDX.Direct3D11.Buffer(m_device, 2048 * 16, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);

This is how I update it...


DataBox datb = m_context.MapSubresource(sbuff, MapMode.WriteDiscard, 0);
datb.Data.Write<cbuff>(m_shadebuff);
datb.Data.Position = 0;
m_context.UnmapSubresource(sbuff, 0);

m_context.VertexShader.SetConstantBuffer(sbuff, 0);


Shader def:

cbuffer cbuff : register(cb0)
{
float4 shadebuff[2048];
};

how I access it

shadebuff[0].xyz;



I'm pretty new to cbuffers, I don't know why it's not working... Any ideas?

Sponsor:

#2 MJP   Moderators   -  Reputation: 5458

Like
0Likes
Like

Posted 17 October 2012 - 11:37 PM

If you put an array inside of a structure like that in C#, all you'll have in the structure is a pointer to the array data. The actual data that you want will be in some other area of memory. This is different from C++, where you can embed a static array in a structure and it will work.

If all you have in your constant buffer is an array of float4, then you should just directly create an array of Vector4 in your C# code and pass that to DataBox.Write. There's an overload for Write that takes an array.

#3 Butabee   Members   -  Reputation: 180

Like
0Likes
Like

Posted 18 October 2012 - 12:59 AM

Thanks for the info. I got the correct data from one cbuffer coming in but now I'm having issues with a second.

It's of the same format. Can I have more than one? Or should I try to combine all my data into one cbuffer?

#4 Butabee   Members   -  Reputation: 180

Like
0Likes
Like

Posted 18 October 2012 - 02:08 AM

I got multiple buffers working... I was using the wrong register values... had to change them to b0, b1, etc...

#5 Starnick   Members   -  Reputation: 555

Like
0Likes
Like

Posted 18 October 2012 - 07:58 AM

FYI its possible to set things up to marshal arrays in structs, here's a helpful article on marshalling C# structs to cbuffers (its SharpDX, but should carry over to SlimDX):

http://timjones.tw/blog/archive/2011/03/08/marshalling-c-structures-into-directd--cbuffers-using




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS