Constant buffer not working

Started by
4 comments, last by TheResolute 11 years, 2 months ago

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

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.

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,

Please consider reading that:

http://www.gamedev.net/topic/620539-constant-buffer-update/

I read somewhere the other day that you have to use XMMatrixTranspose() in DX11 otherwise you'll get NaN in the pixel shader.

http://stackoverflow.com/questions/14150922/directx-11-shader-error-pixel-shader-receiving-only-nan/14164755#14164755

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

This topic is closed to new replies.

Advertisement