10
\$\begingroup\$

I am currently thinking of what type of GBuffer I'll need for deferred shading, hence I tried also to document myself online about the most common ones and their format.

Most of the GBuffer that I've seen used the same bit size for each render target, leading also often to unused channels. However, as first guess for my GBuffer, on paper, I need two 24 bit targets and two 32 ones or three 24 and one 32.

I understand that having the same "size" each attachment can be aligned better, but practically speaking is it better to waste channels (or reserve them for future use) and having all the RTs of the same size or I should use just what needed? In the former case, why it is such advantage, will the 24 bit ones be padded to 32 anyway?

\$\endgroup\$
9
\$\begingroup\$

I understand that having the same "size" each attachment can be aligned better, but practically speaking is it better to waste channels (or reserve them for future use) and having all the RTs of the same size or I should use just what needed?

Having a unified 32bit aligned Render Targets is better, even if it means "wasting" some memory. This will be much faster than having a non 32bit aligned memory. Also you won't have the trouble of supporting multiple types of buffers, copying and combining buffers will be easier since you won't have to convert between multiple types.

32bit is the native for GPUs and CPUs, hence you will reduce the number of required cycles to read the memory. GPUs will naturally try to read 32bits, if you are trying to read unaligned memory address, such as 24 bits aligned, GPUs will read 32bits and then will shift out unwanted bytes.

Here is a detailed article of why memory alignment matters (eventhough it talks about CPUs not GPUs the high level concept still applies.)

Will the 24 bit ones be padded to 32 anyway?

Some GPUs will pad it, but it can't be guaranteed, so it lays in the driver/GPU implementation area. So you have to profile and check the results.

PS: 32bit or 64bit depending on the architecture.

\$\endgroup\$
  • 5
    \$\begingroup\$ and if they are all the same bit size you can blit them over without needing to convert \$\endgroup\$ – ratchet freak Dec 2 '14 at 12:36

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.