HLSL: Index to unaligned/packed floats

心已入冬 提交于 2019-12-02 10:49:35

问题


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 it 100 constant registers. Each constant register is a float4, so it's allocating 4 times as much space as is needed.

I need a way to make it allocate just 25 constant registers and store four values in each of them.

Ideally I'd like a method where it still looks like a float[] on both the CPU and GPU (Right now I am calling EffectParamter.SetValue(Single[]), I'm using XNA). But manually packing and unpacking a float4[] is an option, too.

Also: what are the performance implications for doing this? Is it actually worth it? (For me, this will save about one batch in every four or five).


回答1:


Does that helps?:

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


来源:https://stackoverflow.com/questions/2866778/hlsl-index-to-unaligned-packed-floats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!