• Advertisement
Sign in to follow this  

cbuffers lifetime in a pipeline

This topic is 2133 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

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
Advertisement
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
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
the cb will stay bound until you change it. I use a cbPerScene buffer, that is only set once per scene at initialization time

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement