# Storing few values in an int - small gain

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?

• 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. – bummzack Sep 13 '13 at 6:30
• @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. – tobi Sep 13 '13 at 6:35
• 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. – Chewy Gumball Sep 13 '13 at 6:43
• If your fps boost is that small, it’s because the time is spent somewhere else. Use a profiler. – sam hocevar Sep 13 '13 at 6:43
• "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. – Andon M. Coleman Sep 13 '13 at 8:37