4
votes

In DirectX11, when creating a Shader Resource View to a buffer; we have to fill in the D3D11_BUFFER_SRV structure.

The structure looks like this:

typedef struct D3D11_BUFFER_SRV {
  union {
    UINT FirstElement;
    UINT ElementOffset;
  };
  union {
    UINT NumElements;
    UINT ElementWidth;
  };
} D3D11_BUFFER_SRV;

I can't seem to find any documentation on which field in each union I'm supposed to use and when, or even really what they mean. The MSDN page (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476094%28v=vs.85%29.aspx) gives a fairly obvious description of each field, but nothing much helpful.

1

1 Answers

4
votes

As far as I know, for a structured buffer, D3D11 always interprets the values in these unions as first index and number of entries which means you always want to use FirstElement and NumElements.

ElementWidth doesn't seem needed because the element size is already declared with D3D11_BUFFER_DESC::StructureByteStride. Also the documentation is misleading because FirstElement is really the index to the first element, not an offset in bytes.

There really is no reason for the other two values. My only guess is that this structure was intended to be used somewhere else maybe in conjunction with a flag that said how to interpret the unions, but I've never seen it used any other way.