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?
SlimDX Constant Buffer Issues
Started by Butabee, Oct 17 2012 11:11 PM
4 replies to this topic
Sponsor:
#2 Moderators - Reputation: 5458
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.
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.
#5 Members - Reputation: 555
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
http://timjones.tw/blog/archive/2011/03/08/marshalling-c-structures-into-directd--cbuffers-using
Starnick
Tesla Graphics Engine | AssimpNet | DevILNet |






