简体   繁体   English

D3D10常量缓冲区无法正常工作

[英]D3D10 Constant buffer not working

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 问题是缓冲区在运行期间对于float4成员的x,y,z和w在着色器中包含0,无论更新到缓冲区的数据是什么

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 任何帮助深表感谢

You need to pad your struct to make it 16 byte aligned. 您需要填充结构以使其对齐16字节。

// (C++)
struct Buffer
{
    XMMATRIX mvp_;
    XMFLOAT4 rgba_;
    int usemvp_;
    float padding[3];
};

Also you have to make sure that you are setting the constant buffer into the correct shader stage, ie VSSetConstantBuffers vs PSSetConstantBuffers. 此外,您必须确保将常量缓冲区设置为正确的着色器阶段,即VSSetConstantBuffers与PSSetConstantBuffers。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM