Jump to content
  • Advertisement
Sign in to follow this  
myvraccount

Array in constant buffer

This topic is 890 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'm using SharpDX (compatible with SlimDX) and trying to put arrays into a constant buffer.

 

I made a struct and gave it a StructLayout with LayoutKind.Explicit and I manually set Size also.

 

Inside the struct, I make arrays with attributes FieldOffset and MarshalAs in which I set UnmanagedType.ByValArray and I manually set SizeConst.

 

When I instantiate the struct, I create the arrays to the size I specified.  Then I populate them with the values I want.

 

Then I update the constant buffer with my struct data, and the size is divisible by 16.

 

In the shader, I have the arrays of corresponding data types set to the sizes to match the ones in C#.  It's all inside a tbuffer.

 

But then when I run the pixel shader, all the values it reads from the arrays seem to be 0, regardless of what values I set in it.

 

I know the constant buffer in general is working, because it was working before I added the arrays to the structure.

 

So what could be wrong?

Share this post


Link to post
Share on other sites
Advertisement

I tried some more stuff but it still doesn't work:

 

I tried to make the tbuffer a cbuffer because it didn't seem to be compatible with tbuffers (but the reason I made it a tbuffer in the first place was that I got an error that the cbuffer was bigger than it was allowed to be).

 

But then I separated it into to structs, and kept that part without arrays as a cbuffer and put all arrays into a tbuffer.

 

I also made two ConstantBuffer objects - one for each structure type, and I set them to slot 0 and slot 1 and I update them both just before trying to draw anything.

 

Also, I tried setting the cbuffer to : register (b0) and the tbuffer to : register (t1) - is that right?

 

Now it's only drawing an image if I give it hard-coded numbers in the pixel shader, so I know it's able to draw, but it still gets 0 (looks black) whenever it reads any number as a color from an array in the tbuffer.

Share this post


Link to post
Share on other sites

I can't.  I don't have it with me and I'm not at liberty to divulge.  I'm not sure why everyone always wants to see the code every single time though, no matter how detailed my explanation is.

 

Really all I need is any possible explanation of how to use constant or texture buffers with arrays in them and get the data into the array so that it actually gets into the pixel shader.

 

I wouldn't think it should be this insufferably difficult to do.

Share this post


Link to post
Share on other sites

Yeah I know, but I don't have it here.

 

What I really need is any source code or a link so it that has a complete example (even a simple one) of just how to put arrays into a buffer and get them to be used by the pixel shader.  That's all.

Share this post


Link to post
Share on other sites


What I really need is any source code or a link so it that has a complete example (even a simple one) of just how to put arrays into a buffer and get them to be used by the pixel shader.  That's all.

 

In that case, You can google search for tutorials and sample codes on the subject. Unbird's post-link could be a starting place

Share this post


Link to post
Share on other sites

I have searched for them and the ones I used didn't work.  That's why I came here.

 

Thanks for the datastream idea, unbird.  I'll try it.

Share this post


Link to post
Share on other sites

Well I tried it but it didn't work.

 

By the way, I did it slightly differently, because I'm not using an array, I'm using a structure that contains several arrays of different types.  And I'm putting it in a texture buffer rather than a constant buffer (the constant buffers don't provide enough memory).

 

So the way I did it was to use Write<> rather than WriteRange.  But I set up the buffer description the same but with the size in bytes that I need.

 

Other than that, I did it how you said, but I still got a black screen.

 

Also, when I update my constant buffer resource (I do that for the constant buffer, and the texture buffer, because I couldn't find a different function for that), I tried setting it with only the first 2 parameters but was afraid it may be overwriting it so I also tried setting the third (optional) parameter (it's an int called subresource or something) and I set it to 0 for the constant buffer and 1 for the texture buffer (that corresponds to the registers they use although they're called b0 and t1 respectively).  I don't know if this is correct but I tried it with and without it.

 

Anyway, whatever I do, it's always a black screen.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!