My question is simple: how much memory on GPU does one floating point value takes? I guess it is 4 bytes, but I'm not sure. So for example is it true that vec4, which holds 4 floats, each 4 bytes takes 16 bytes in sum.

I know this is very basic, maybe I've missed some point.

Thank you in advice.

  • \$\begingroup\$ I just wrote a shader that makes the assumption that a float is 4 bytes. The shader worked. \$\endgroup\$
    – RandyGaul
    Dec 16, 2013 at 10:31
  • \$\begingroup\$ @RandyGaul Haha, it's possible? \$\endgroup\$
    – luke1985
    Dec 16, 2013 at 10:34
  • \$\begingroup\$ your question is a bit confusing, in memory, a float consumes 4 bytes, given that you have an array of floats. If you refer to shader code, a float might consume a full register (4 floats) but i can't confirm this. I think it's architecture dependent. \$\endgroup\$
    – Raxvan
    Dec 16, 2013 at 10:50

1 Answer 1


Usually PC gpu are 16 bytes aligned, and even a single float will take 16 bytes. If you have four floats in a struct it will get packed into 16 bytes and will be fully utilized.

The gpu compiler wont realign your cbuffer for you when they get compiled due to packing in the cpu. So packing your cbuffer right is important! ETC:

example 1

Will be 16 bytes.

example 2
float - 16bytes ( bad packing )
int4 - 16bytes
float - 4bytes, this two will be packed into a 16bytes flaot4
float - 4bytes 
and 8 bytes of unpacked
float4 + 16 bytes

will be 64 bytes

So, a float is never 16bytes unleass it´s packed.

  • \$\begingroup\$ Does this mean that passing 2 floats as a vertex attribute to the shader in which it is a vec2 will result in 2 floats packed in this vec2 and take 16 bytes per vertex? \$\endgroup\$
    – luke1985
    Dec 16, 2013 at 11:36
  • \$\begingroup\$ Depending on where you put them, if you put them after each other they will get packed into 16 bytes. Infact, the same rules apply in c++ to infact, but the alignment is different there. \$\endgroup\$
    – Tordin
    Dec 16, 2013 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .