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?
3 replies to this topic
Sponsor:
#2 Members - Reputation: 499
Posted 17 March 2012 - 09:49 AM
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.
Braynzar Soft - DirectX Lessons & Game Programming Resources!
#3 Members - Reputation: 3828
Posted 17 March 2012 - 10:17 AM
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.
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.
#4 Members - Reputation: 499
Posted 17 March 2012 - 10:20 AM
the cb will stay bound until you change it. I use a cbPerScene buffer, that is only set once per scene at initialization time
Braynzar Soft - DirectX Lessons & Game Programming Resources!






