Is there any way to get the size of a struct inside of a shader? I know how to manually calculate the size and/or pass it in via a Uniform, but am wondering if the compiler can figure it out?
Unfortunately HLSL does not have such a compile time function to give you the size of a structure. Probably the best way to go around it is to declare it manually as a macro like so:
#define MyStruct_Size (6*4)
struct MyStruct {
float4 foo;
float2 bar;
}
I’m quite curious what do you need it for, though. Structured buffers automatically convert the data to the struct type for you.