cbuffers lifetime in a pipeline

Started by
2 comments, last by iedoc 12 years, 1 month ago
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?
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.
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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

the cb will stay bound until you change it. I use a cbPerScene buffer, that is only set once per scene at initialization time

This topic is closed to new replies.

Advertisement