Out of curiosity (and peace of the mind...) I wondered how DirectX decides which attribute from a struct
corresponds to the right variable inside an HLSL cbuffer-register(x) (apart from the order/type they are declared with).
My main concern is my structs not only have member variables but 2 constructors each. So how can I be sure the constructors are not at the beginning of my struct definition (memory wise - C++ question I guess) so my variables would overflow after my cbuffer ? Additionnaly, can I only rely on declare-order/type matching ?
Is there a more precise/explicit way than doing :
struct foo {
int a;
int b;
int c;
foo () {}
foo (int a, int b, int c) : a{a}, b{b}, c{c} {}
}
D3D11_BUFFER_DESC constantBufferDesc;
...
constantBufferDesc.ByteWidth = sizeof(foo) + (16 - sizeof(foo) % 16);
hr = g_d3dDevice->CreateBuffer(...);
g_d3dDeviceContext->VSSetConstantBuffers(0, 1, &fooBuffer);
g_d3dDeviceContext->UpdateSubresource(&fooBuffer, 0, nullptr, &foo, 0, 0);
With HLSL :
cbuffer foo: register(b0) {
// constructor here ?
int a;
// constructor here ?
int b;
int c;
// constructor here ?
}
I am aware this is more a C++ question - Thanks for your insight.
ByteWidth = sizeof(foo) + (16 - sizeof(foo) % 16);
. Should I use__declspec(align(16))
instead ? \$\endgroup\$