0
\$\begingroup\$

This might be a bit hard-to-answer question, but... I had a DirectX::XMFLOAT3 as a vertex attribute. I have changed it to just an int by placing the 3 floats into int (using only 8 bits per float). In the vertex shader I am extracting the bits like this:

// example int bits: 00000000 10011000 00011101 11111111

input.weight.x =   ( input.w >> 16 )               / 255.0f; // 10011000 / 255.0f
input.weight.y = ( ( input.w & 0x0000FF00 ) >> 8 ) / 255.0f; // 00011101 / 255.0f
input.weight.z =   ( input.w & 0x000000FF )        / 255.0f; // 11111111 / 255.0f

But with this manner I've only gained like 1-5 fps (from ~130 to ~135), how is that possible that the fps boost is that small? What's the culprit here? Is the extracting bits on GPU that heavy?

\$\endgroup\$
  • 1
    \$\begingroup\$ So you're packing 3 floats into an int and then unpacking them instead of just passing over 3 floats? I'm amazed you even get a performance gain of 5 FPS from that. \$\endgroup\$ – bummzack Sep 13 '13 at 6:30
  • \$\begingroup\$ @bummzack Yes, I thought the decreasing bandwidth usage will give me a performance gain. In the future there will be more of the values I need to pass to the shader, like 8 floats or more, so I think it's better to pass there just 2 ints instead of 8 floats. I didn't expect that it will give me almost nothing. \$\endgroup\$ – tobi Sep 13 '13 at 6:35
  • \$\begingroup\$ Why would you expect it to give you anything? You would have to be heavily bandwidth starved to get significant improvements from reducing data transfer sizes. \$\endgroup\$ – Chewy Gumball Sep 13 '13 at 6:43
  • \$\begingroup\$ If your fps boost is that small, it’s because the time is spent somewhere else. Use a profiler. \$\endgroup\$ – sam hocevar Sep 13 '13 at 6:43
  • 1
    \$\begingroup\$ "Is the extracting bits on GPU that heavy?" -- Yes, they're good at things they were built-for: floating / fixed-point, not so much arbitrary bit twiddling. In older shader models this hack would not even have been possible. \$\endgroup\$ – Andon M. Coleman Sep 13 '13 at 8:37
3
\$\begingroup\$

I don´t think this will gain you anything, in fact i rather think you will lose performance off this. You should use a profiler to get a good pinpoint of where the bottleneck is.

A good thumbrule is to never mix Interger and Float math on the gpu, this is typically a downfall. Of course there is points when it´s needed, but packing floats into int´s is really bad! rather think of using a vertexlayout that uses Float16. so you use the half precision of the floats.

Another note is that you might belive you are bandwidth bound, this is pretty common for textures rather than vertex buffers. a mesh containing one million vertexes is barley taking as much memory as a 512x512 texture is. ( worth focusing on optimizing there instead )

On the other hand, the gpu stores vertexbuffers, textures and other things on it´s internal memory, so unless you are updating your vertexbuffer every frame you don´t stream it to the gpu.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.