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

Started by
2 comments, last by n3Xus 15 years, 4 months ago
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 ^^ ).
Advertisement
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.
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.
Sirob Yes.» - status: Work-O-Rama.
Thank you both for the explanation!

This topic is closed to new replies.

Advertisement