Jump to content
  • Advertisement
Sign in to follow this  
My_Mind_Is_Going

Question about DX10 constant buffers

This topic is 2991 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 working with DX10 without Effects, and I'm a little confused about how to manage my constant buffers. Let's say I have two buffers, one for scene variables and one for per-object variables like this:

cbuffer SceneVars
{
float4x4 View;
float4x4 Projection;
float4x4 ViewProj;
};

cbuffer ObjectVars
{
float4x4 World;
};

When I bind a buffer in the application code, with something like VSSetConstantBuffers, how does it know which buffer in the shader I'm binding it to? Are they indexed by the order they appear in the shader, so VSSetConstantBuffers(0,...) would assign to SceneVars and VSSetConstantBuffers(1,...) would assign to ObjectVars? I also notice I can declare variables at global scope in the shader, do these automatically take slot 0 or something?

If anyone can clarify some of this for me (or point me to the relevant documentation) it would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
cbuffer SceneVars
{
float4x4 View;
float4x4 Projection;
float4x4 ViewProj;
} : register(b0);

otherwise the order the first buffer would default to 0.

Share this post


Link to post
Share on other sites
I'm not sure I understand, so I want to assign each buffer a start register like "register(prev_buffer_start + sizeof(prev_buffer))" to control the layout in memory, and then I can bind them at indices in that order from the application?

It's strange, I've seen several examples where they say you should break your data into multiple buffers depending on how frequently they're updated, but there's never any mention of how to control the ordering like this.

Share this post


Link to post
Share on other sites
The buffer register doesn't control the layout in memory, it just determines which slot a constant buffer gets assigned to (in other words, the value you pass to VS/GS/PSSetConstantBuffers for StartSlot). So regardless of the size and layout of two constant buffers, you can always assign them to b0 and b1. It's not like DX9 where you had a flat set of constant registers.

To control the layout of your data in a constant buffer, you use packoffset. If you don't use packoffset, then the members are packed according to the rules listed here. This page gives a full rundown of how constants work, including the default constant buffer.

Share this post


Link to post
Share on other sites
Quote:
Original post by My_Mind_Is_Going
Are they indexed by the order they appear in the shader

did some1 mention about this yet?

Share this post


Link to post
Share on other sites
Quote:
Original post by katsh
Quote:
Original post by My_Mind_Is_Going
Are they indexed by the order they appear in the shader

did some1 mention about this yet?


I don't believe it's defined, or at least in any way that you can rely on. Your best bet is to either explicitly assign constant buffers to a register, or use the reflection API to query the slot.

Share this post


Link to post
Share on other sites
sorry My_Mind_Is_Going,this is your thread but i wanted to know this.

thanx DieterVW and MJP. i understand.

well,then,how do i specify the "register" from app side.

and (sorry for only questions),

about ID3D11DeviceContext::VSSetConstantBuffers method

document says
-----------------------------------------------
void VSSetConstantBuffers(
UINT StartSlot,
UINT NumBuffers,
ID3D11Buffer *const *ppConstantBuffers
);

StartSlot
[in] Index into the device's zero-based array to begin setting constant buffers to...
-----------------------------------------------

what is "slot" <----is this register?

you can avoid me. just want to know if you have enough time.



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!