sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.68k stars 641 forks source link

SharpDX.Direct3D11.ShaderResourceViewDescription.BufferResource ElementCount and ElementWidth members alias #1041

Closed helmutbressler closed 6 years ago

helmutbressler commented 6 years ago

Setting one member changes also the other. At least in the NuGet packet version 4.1

Sorry, I'm quite new to SharpDX, I couldn't manage to build it from source on my own. Ohterwise I would have checked where this behaviour is coming from.

amerkoleci commented 6 years ago

Thats correct as the are basically union, even in C/C++:

typedef struct D3D11_BUFFER_SRV {
  union {
    UINT FirstElement;
    UINT ElementOffset;
  };
  union {
    UINT NumElements;
    UINT ElementWidth;
  };
} D3D11_BUFFER_SRV;
[StructLayout(LayoutKind.Explicit)]
public struct BufferResource
{
    [FieldOffset(0)]
    public int FirstElement;

    [FieldOffset(0)]
    public int ElementOffset;

    [FieldOffset(4)]
    public int ElementCount;

    [FieldOffset(4)]
    public int ElementWidth;
}
helmutbressler commented 6 years ago

That makes totally sense to me now. I should have checked the d3d11 documentation before posting. Apologies for bothering you with that (, but at least I know now that I did the SRV setup in my code incorrect). Thank you very much!

amerkoleci commented 6 years ago

No problem :) Glad to help out.