D3D10常量缓冲区不工作 [英] D3D10 Constant buffer not working
本文介绍了D3D10常量缓冲区不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用常量缓冲区将数据传输到像素着色器
问题是缓冲区在运行时在着色器中包含x,x,y,z ,并且不管什么数据被更新到缓冲区,而是float4成员的w。
结构定义如下:
//(C ++)
struct Buffer
{
XMMATRIX mvp_;
XMFLOAT4 rgba_;
int usemvp_;
};
// HLSL
cbuffer缓冲区:register(b0)
{
matrix mvp_;
float4 rgba_;
int usemvp_;
};
任何帮助非常感谢
//(C ++ )
struct缓冲区
{
XMMATRIX mvp_;
XMFLOAT4 rgba_;
int usemvp_;
float padding [3];
};
此外,还必须确保将常量缓冲区设置为正确的着色器阶段,即VSSetConstantBuffers vs PSSetConstantBuffers。
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
解决方案
You need to pad your struct to make it 16 byte aligned.
// (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.
这篇关于D3D10常量缓冲区不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文