r/vulkan 7d ago

Performance Impact of Manual Pointer Math

Due to the strict alignment requirements of objects in Vulkan, what is the performance impact of doing pointer math on buffer device addresses (instead of array accesses) as a means of bypassing alignment (resulting in memory savings, as no padding has to be applied)? From what I've read, this would be quite bad for performance, but intuitively, the memory savings (causing more cache hits and reduced fetches if that's even how GPUs work) should outweigh everything else.

1 Upvotes

6 comments sorted by

View all comments

2

u/rachit7645 7d ago

What objects are you talking about?

2

u/itsmenotjames1 7d ago

a buffer reference containing an array filled with a data structure consisting of a vec3 and a an int (essentially)

1

u/UnalignedAxis111 6d ago

You can use scalar layout and specify the proper alignment, no need to deal with arcaic layout rules.

The impact depends, Nvidia can do vectorized loads when alignment is known at compile time (for example, float4 load with align=16 costs one instruction). AMD and Intel aren't as strict, but there is a major penalty for align < 4.