# Floating point memory usage on gpu

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.

• I just wrote a shader that makes the assumption that a float is 4 bytes. The shader worked. Dec 16, 2013 at 10:31
• @RandyGaul Haha, it's possible? Dec 16, 2013 at 10:34
• 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. Dec 16, 2013 at 10:50

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
cbuffer
float
flaot2
float

Will be 16 bytes.

example 2
cbuffer
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.

• 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? Dec 16, 2013 at 11:36
• 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. Dec 16, 2013 at 11:56