Skip to main content
GameDev.net gamedev.net
🔒 Locked

Constant buffer not working

Started by TheResolute Feb 8, 2013 at 9:53 PM 4 replies 3.1k views
Original Post
TheResolute
TheResolute

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

AngryPlatypus
AngryPlatypus

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.

Polarist
Polarist

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,

TheResolute
TheResolute

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.