Sign in to follow this  
n3Xus

[DX10] Difference between passing a ConstantBuffer or a struct to the shader

Recommended Posts

Lets say that I have a constant buffer and a struct like this:
// In the shader file:

// The struct
struct Matrices
{
    float4x4 world,viewproj;
};

// The constant buffer
cbuffer CBMatrices
{
    float4x4 world,viewproj;
};

Is passing the constant buffer in this case more efficient? (I'm asking this becuase I'm having some problems setting the constant buffer data, so right now I just use a ID3D10EffectVariable and I set it as raw data. And I'm also asking it because I'm curious ^^ ).

Share this post


Link to post
Share on other sites
Constant buffers are a new way to storing data in the shader.
In reality, constants buffer in D3D10 it's the only way to store data in a shader. This apporch let you limit bandwith between CPU and GPU.

Share this post


Link to post
Share on other sites
Functionally, both techniques work fine. What's really happening is that the Effect framework is managing a hidden Constant Buffer for you.

The downside of setting each of the buffers seperately, is that if the data in the buffer doesn't change, you're still updating the values every frame. If you use a Constant Buffer, you can simply set the constant buffer for the shader (an operation that doesn't depend on its size) and all the data in it is immediately available for the shader. Doing so by setting each variable on its own means copying the data to the constant buffer before setting it.

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