#why is my vec3 16 bytes and an array of 3 float 12?

10 messages · Page 1 of 1 (latest)

slate hedge
#

I'm trying to push some constants to my shader nothing fancy the usual camera structure: pos, dir, upVec, rightVec
each of those variable is a 3d vector of 12bytes, for a total of 48 bytes
and I've made the same structure in my shader using vec3
but somehow they end up wrong, so I've looked it up with Nsigh and yeah for some reason each vector is spaced out by 16 bytes (screen1)
so I try using an array of 3 float, because that essentially the same and every work fine (screen2)
so that's weird isn't it?

happy to keep using array, but I'm interested to understand why it does that
thanks for your time 🙂

dull moss
#

A three- or four-component vector has a base alignment equal to four times its scalar alignment.

#

An array or structure type has an extended alignment equal to the largest extended alignment of any of its members, rounded up to a multiple of 16.

slate hedge
#

true, Vulkan documentation can be a bit raw
I know I should have a read through those pages, but it's hard specially when your not an expert and there is so many concept that you don't understand.
I'm still reading it but bit by bit when I can play with it, I learn better that way 🙂
Thanks for your help

dull moss
#

imo those few paragraphs are the clearest description compared to what you find on google

#

it' literally:
if std140
read extended section
if std430
read base section

#

if it says "scalar" read the scalar section for that specific thing

#

uniform buffers are 140 by default

#

storage buffers are 430 by default