Sign in to follow this  
Corefanatic

cbuffers lifetime in a pipeline

Recommended Posts

Corefanatic    176
Hi there,
A quick question I have is about how long is a lifetime of a constant buffer within a frame. Let's assume all my vertex shaders have the same set of constant buffers:

cbuffer cbPerObject
{
float4x4 matWorld;
}

cbuffer cbPerFrame
{
float4x4 matView;
float4x4 matProj;
}

At the moment I naturally set the perObject cb with every object I draw, and perFrame with each new vertex shader I set to the pipeline. What I am wondering is, if my shaders have the the same layout , would the perFrame cb stay attached from one vertex shader to another?

Share this post


Link to post
Share on other sites
iedoc    2525
If i'm understanding the question right, constant buffers will stay attached to whichever shaders you bind them to, and will stay attached until you change them. If you have not bound a cb to specific shader, then that shader will not use it. Even if you have two identical vertex shaders, you will still have to bind a cb to each of them explicitly, not just to one if you want both of them to use the cb.

Share this post


Link to post
Share on other sites
mhagain    13430
You can bind a cbuffer at the start of a frame and have it remain valid for the entire frame, yes. I do this with a few global values and it works quite well. You may want to look to set explicit register slots in your HLSL code (like "cbuffer cbPerObject : register(b1)", for example) to make this more predictable, especially if you're using Effects.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this