Shader/Const buffer problem

Started by
2 comments, last by MJP 11 years, 7 months ago
I've got a const buffer struct defined in my application code, which you can see here:


struct cbDOFProperties
{
float _focalWidth;
float _focalDepth;
float _farClip;
float _padding;

XMFLOAT2 _filterTaps[12];
};


Now the same in my shader:

cbuffer cbDOFProperties : register(b0)
{
float _focalWidth;
float _focalDepth;
float _farClip;
float _padding;


float2 _filterTaps[12];
};


The problem I'm having is that I'm getting a warning telling me:
D3D11: WARNING: ID3D11DeviceContext::DrawIndexed: The size of the Constant Buffer at slot 0 of the Pixel Shader unit is too small (112 bytes provided, 208 bytes, at least, expected).

I don't get it. the size of a float2 would be 2*4 byte = 8 bytes * 12 = 96 bytes + 4x floats = 112 bytes like it tells me I've provided. Then why is it expecting 208 ???
Advertisement
Arrays in constant buffers will be padded to 4 floats per element, as described here.
Hmm might be a stupid question but how would I give "him" more data in this case ?

edit: [s]nvm got it[/s]
Hmm or not... how do I correctly set an array to a constant buffer ?
Declare it as an array of XMFLOAT4 in your C++ structure, and only set the X and Y values.

This topic is closed to new replies.

Advertisement