Jump to content
  • Advertisement
Sign in to follow this  
grunt123

D3D10 shader constant buffer question

This topic is 3467 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've got a question in regard to setting up shader constant buffer. When you create a constant buffer in shader, do you have to specify register? In the documentation, it says it's optional, but i've seen some weird behaviour if i don't explicitly specifiy register in cbuffer. for example, i modified HSLSwithoutFX10 sample from sdk ... cbuffer cb0 //: register(b0) { row_major float4x4 mWorldViewProj ;//: aaa : packoffset(c0); // World * View * Projection transformation float fTime ;//: bbb : packoffset(c4.x); // Time parameter. This keeps increasing // Notice, that this parameter is placed in c5.y. // If it were packed by the default packing rules, // it would be placed in c4.x }; cbuffer cb1 //:register(b1) { row_major float4x4 mWorldViewProj1 ;//: aaa : packoffset(c0); // World * View * Projection transformation float fTime1 ;//: bbb : packoffset(c4.x) ; // Time parameter. This keeps increasing // Notice, that this parameter is placed in c5.y. // If it were packed by the default packing rules, // it would be placed in c4.x }; cbuffer cb2 //: register(b2) { row_major float4x4 mWorldViewProj2 ;//: aaa : packoffset(c0); // World * View * Projection transformation float fTime2 ;//: bbb : packoffset(c4.x) ; // Time parameter. This keeps increasing // Notice, that this parameter is placed in c5.y. // If it were packed by the default packing rules, // it would be placed in c4.x }; In the game code, i set up fTime,fTime1, and fTime2 so that each variable has different value. Now, when i run the program without specifying register, fTime/fTime1/fTime2 doesn't have correct value. The program works correctly only if i specify register number (b0,b1,b2) ... any idea?

Share this post


Link to post
Share on other sites
Advertisement
I suggest using FXC on the command line with the /Cc flag for your shader. This output will give a detailed break down of what resources are required for the shader and where they must be bound. If you compile each entry point separately, you'll see how the constant buffers are assigned registers automatically vs explicitly. I imagine that in your case, you will see that register assignment is different in the two cases. As such, if you aren't binding the resource to the right location at runtime to match the shader, you'll get incorrect results.

cbuffers are automatically assigned register slots based on their order of appearance in the shader, which is further pruned for only those cbuffers used for the current shader stage being compiled. If there are variables in the global space not inside a cbuffer, they are packed into a global cbuffer which is always assigned to slot 0. You can override this default assignment by explicitly setting the register location for a cbuffer.

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!