PDA

View Full Version : Shader Matrix Storage



glfreak
01-19-2011, 08:27 AM
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.

_arts_
01-19-2011, 09:07 AM
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.

glfreak
01-19-2011, 09:25 AM
This makes sense. Thanks for your information.

Alfonse Reinheart
01-19-2011, 10:00 AM
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.

Dark Photon
01-19-2011, 07:36 PM
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.
I have never heard this before. In what domain is this?