I am experimenting with structured buffers and I came across something strange with indexing elements inside of a struct.
My code:
struct InstanceData
{
float3 translation;
float3 color;
uint id[16];
};
StructuredBuffer<InstanceData> data;
In my vertex shader, I am trying to access the buffer like this:
... data[InstanceID].id[VertexID] ...
But I get this error:
error X3512: sampler array index must be a literal expression
As this isn't a sampler array, I am a bit confused. When I plug in a constant for the id index, this is the HLSL assembly output:
ld_structured_indexable(buffer)(mixed,mixed,mixed,mixed) r0.x, v0.x, l(28), t1.x
The third argument is an immediate-mode constant. I'm hoping that this is simply an HLSL compiler limitation, but if not, I would like to make this into a feature request for all items in a structure to be dynamically indexable.
I have some workarounds in mind, but they aren't ideal from a design standpoint.
Thanks,
Seth