HLSL: index for uneven / packed floats

I have a vertex shader (2.0) doing some instancing - each vertex specifies an index into an array.

If I have an array like this:

float instanceData[100];

      

The compiler allocates 100 permanent registers. Each persistent register is float4

, so it allocates 4 times more space than needed.

I need it to allocate only 25 persistent registers and store four values ​​in each one.

Ideally, I want a method that still looks float[]

on both CPU and GPU (I'm calling now EffectParamter.SetValue(Single[])

, I'm using XNA). But manual packing and unpacking is float4[]

also an option.

Also: what are the performance implications for this? Is it really worth it? (For me this would save about one batch every four or five).

+1


source to share


1 answer


Does it help ?:



float4 packedInstanceData[25];
...
float data = packedInstanceData[index / 4][index % 4];

      

+3


source







All Articles