
A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In column-major order, the leftmost index “varies the fastest”: for example the array:
is represented in the column-major order as:
Column-major order is also known as the Fortran order, as the Fortran programming language uses it.


A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In row-major order, the rightmost index “varies the fastest”: for example the array:
is represented in the row-major order as:
Row-major order is also known as the C order, as the C programming language uses it. New Numpy arrays are by default in row-major order.

Matrix Ordering
Matrix packing order for uniform parameters is set to column-major by default. This means each column of the matrix is stored in a single constant register. On the other hand, a row-major matrix packs each row of the matrix in a single constant register. Matrix packing can be changed with the #pragmapack_matrix directive, or with the row_major or the column_major keyword.
The data in a matrix is loaded into shader constant registers before a shader runs. There are two choices for how the matrix data is read: in row-major order or in column-major order. Column-major order means that each matrix column will be stored in a single constant register, and row-major order means that each row of the matrix will be stored in a single constant register. This is an important consideration for how many constant registers are used for a matrix.
A row-major matrix is laid out like the following:
11 | 12 | 13 | 14 |
21 | 22 | 23 | 24 |
31 | 32 | 33 | 34 |
41 | 42 | 43 | 44 |
A column-major matrix is laid out like the following:
11 | 21 | 31 | 41 |
12 | 22 | 32 | 42 |
13 | 23 | 33 | 43 |
14 | 24 | 34 | 44 |
Row-major and column-major matrix ordering determine the order the matrix components are read from shader inputs. Once the data is written into constant registers, matrix order has no effect on how the data is used or accessed from within shader code. Also, matrices declared in a shader body do not get packed into constant registers. Row-major and column-major packing order has no influence on the packing order of constructors (which always follows row-major ordering).
The order of the data in a matrix can be declared at compile time or the compiler will order the data at runtime for the most efficient use.
Examples
HLSL uses two special types, a vector type and a matrix type to make programming 2D and 3D graphics easier. Each of these types contain more than one component; a vector contains up to four components, and a matrix contains up to 16 components. When vectors and matrices are used in standard HLSL equations, the math performed is designed to work per-component. For instance, HLSL implements this multiply:
덧글