libweston: introduce linalg.h
The goal is to create a more intuitive libear algebra API, that includes 3x3 matrices and 3-vectors, eventually superseding all
existing matrix code: weston_matrix
, calls to LittleCMS matrix
routines (plugin API), and ad hoc matrix code in tests/
. The latter two are mostly already dealt with here, but the weston_matrix
removal is left for later.
I did consider graphene and cglm, but I did not like their API - cglm design is corrupted by GLSL conventions, and too much is transposed in graphene. Mesa and wlroots didn't have quite what I was looking for to steal, either. So, this is yet another home-grown matrix multiplication and inversion API.
Manual CPU-specific optimization are out of scope, we'll just rely on the compiler auto-vectorizer. I did test row-major layout, but column-major was twice as fast in matrix-vector multiplication, tested in my fourbyfour project's speed benchmark. Btw. matrix-vector multiplication speed is on par with weston_matrix
.
linalg-types.h
can be used from e.g. libweston.h
so that structures can
embed linalg types but without forcing every user of libweston.h
to
compile all the inline functions.
la_mat4
implements most of weston_matrix
, and some more. This is just
for starters. la_mat3
implementation is a trivially edited copy of la_mat4
.
The matrix inversion is a copy from weston_matrix
. Both 4x4 and 3x3 inversions come with tests.
I manually tested weston-simple-egl
and weston-simple-dmabuf-egl
, but I cannot test the touch screen calibrators or ivi-shell.
Merge request reports
Activity
- Resolved by Pekka Paalanen
- Resolved by Pekka Paalanen
- Resolved by Derek Foreman
This is in very good shape, and I have little more than trivial nitpicks to offer in review.
Is there a grand plan leading to the demise of weston_matrix, or will we end up carrying it along indefinitely?
- include/libweston/linalg-4.h 0 → 100644
89 } 90 91 /** Construct a 2D x-y rotation matrix 92 * 93 * \param cos_th Cosine of the angle. 94 * \param sin_th Sine of the angle. 95 */ 96 static inline union la_mat4 97 la_mat4_rotation_xy(double cos_th, double sin_th) 98 { 99 return LA_MAT4( 100 cos_th, -sin_th, 0.0, 0.0, 101 sin_th, cos_th, 0.0, 0.0, 102 0.0, 0.0, 1.0, 0.0, 103 0.0, 0.0, 0.0, 1.0); 104 }