Shader Matrix Storage

Hello,

I’m wondering if there’s any technical reason that a matrix is stored in shader matrix variable/uniform in column major order (hence transposed) by default, and this is regardless of whatever you specify for the [transpose] parameter in the glUniformMatrix.

I mean is it just a convention or there’s a real technical reason for this to be the default even in Direct3D HLSL, it’s the default, unless otherwise specified.

Thanks.

If I remember well, column major order is the default in UK (and USA) for storing matrices. In Europe (so except UK), we use row major orders.

It’s the only difference, there’s no differences in accessibility speed or so.

This makes sense. Thanks for your information.

I mean is it just a convention or there’s a real technical reason for this to be the default even in Direct3D HLSL, it’s the default, unless otherwise specified.

There are several reasons. First, column major is the convention used by pretty much every mathematics textbook ever written. They settled on column major years ago.

Second, it does make vector/matrix multiplies easier to do. In a row-major matrix, the 4 vectors are the rows of the matrix. To multiply this with a vector takes 4 dot products. In a column-major matrix, the 4 vectors are columns. To multiply this with a vector takes 4 vector MAD instructions. And nowadays, with IEEE-754-2008 support for FMA, you get better precision from doing 4 FMAs than 4 dot products. And likely better performance.

I have never heard this before. In what domain is this?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.