• Advertisement
Sign in to follow this  

Constant buffer not working

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

I am using a constant buffer to transfer data to my pixel shader

The problem is that the buffer contains 0s in the shader during runtime for x, y, z, and w of the float4 member, regardless of what data is updated to the buffer

Structure definitions are as follows:

 

// (C++)
struct Buffer
{
    XMMATRIX mvp_;
    XMFLOAT4 rgba_;
    int usemvp_;
};


// HLSL
cbuffer Buffer : register( b0 )
{
    matrix mvp_;
    float4 rgba_;
    int usemvp_;
};
 

 

 Any help is much appreciated

Edited by TheResolute

Share this post


Link to post
Share on other sites
Advertisement

Do you store the XMMATRIX in an object which is dynamically allocated? This will give you alignment issues. Try to use a XMFLOAT4X4 for storing. You can convert between those types with XMStoreFloat4x4 and XMLoadFloat4x4.

Share this post


Link to post
Share on other sites

Are you actually using those values?  If not, the shader compiler may be optimizing away those variables.

 

It'd be easier to diagnose if you posted your code.  The constant buffer definitions seem fine,

Share this post


Link to post
Share on other sites

Thank you for your help, I realized that I never called PSSetConstantBuffers(), so I fixed that and now everything is fine

Share this post


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

  • Advertisement