简体   繁体   English

DX11最小缓冲区大小

[英]DX11 minimum buffer sizes

After creating a few constant buffers, some of them started to not initialize correctly. 创建一些常量缓冲区后,其中一些缓冲区开始无法正确初始化。

A constant buffer is created with a struct called MiscStream, which is defined: 使用名为MiscStream的结构创建常量缓冲区,该结构定义为:

struct MiscStream {
    int rw,rh;
    float shine_factor;
    float dist_factor;
    int random_number;
};

And initialized with: 并初始化为:

D3D11_BUFFER_DESC dx_misc_buffer_desc;
ID3D11Buffer* dx_misc_buffer;

ZeroMemory(&dx_misc_buffer_desc,sizeof dx_misc_buffer_desc);

    dx_misc_buffer_desc.BindFlags=D3D11_BIND_CONSTANT_BUFFER;
    dx_misc_buffer_desc.Usage=D3D11_USAGE_DYNAMIC;
    dx_misc_buffer_desc.ByteWidth=sizeof(MiscStream);
    dx_misc_buffer_desc.StructureByteStride=0;
    dx_misc_buffer_desc.CPUAccessFlags=D3D11_CPU_ACCESS_WRITE;
    dx_misc_buffer_desc.MiscFlags=0;

hr=dx_device->CreateBuffer(&dx_misc_buffer_desc,NULL,&dx_misc_buffer);

hr would be returned as E_INVALIDARG, and the program would fail. hr将作为E_INVALIDARG返回,程序将失败。

Many of the other constant buffers are set up this way, but they all had vectors and matrices in their structures. 许多其他常量缓冲区都是通过这种方式设置的,但是它们的结构中都具有向量和矩阵。

I changed the MiscStruct to 我将MiscStruct更改为

struct MiscStream {
    D3DXVECTOR3 __r;
    int rw,rh;
    float shine_factor;
    float dist_factor;
    int random_number;
};

And it worked without error. 它的工作没有错误。

Is there a minimum structure size? 是否有最小结构尺寸? What is happening? 怎么了?

From MSDN : MSDN

For a constant buffer ( BindFlags of D3D11_BUFFER_DESC set to D3D11_BIND_CONSTANT_BUFFER), you must set the ByteWidth value of D3D11_BUFFER_DESC in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT. 对于恒定缓冲区(将D3D11_BUFFER_DESC的BindFlags设置为D3D11_BIND_CONSTANT_BUFFER),必须将D3D11_BUFFER_DESC的ByteWidth值设置为16的倍数,并且小于或等于D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT。

So you were probably failing on the "multiple of 16" restriction. 因此,您可能未能达到“ 16的倍数”限制。 Depending on your packing settings, this can be different from adding up the sizes of the individual elements so check with sizeof() to see what the real struct size is. 根据您的打包设置,这可能与将各个元素的大小相加不同,因此请使用sizeof()检查实际结构的大小。

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

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