Skip to content
Snippets Groups Projects

libweston: introduce linalg.h

Open Pekka Paalanen requested to merge pq/weston:mr/linalg into main
1 unresolved thread

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

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Derek Foreman
    • 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?

  • Pekka Paalanen added 4 commits

    added 4 commits

    • 2f4fe469 - libweston, clients, tests: implement weston_matrix in terms of la_mat4
    • c0bdbf51 - tests: replace lcmsMAT3 with la_mat3
    • 0789ff4b - tests: change BPC to la_mat4
    • 433bf42d - color-lcms: use la_mat4 for matrix stages

    Compare with previous version

  • Pekka Paalanen resolved all threads

    resolved all threads

  • Author Owner

    All comments addressed so far.

  • Derek Foreman approved this merge request

    approved this merge request

  • This LGTM. Anyone else want to give it a look?

  • Reviewed up to (including) tests: add linalg-3 test cases. The API looks pretty good to me.

  • Leandro Ribeiro
    Leandro Ribeiro @leandrohrb started a thread on commit ebed11bc
  • 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 }
    Please register or sign in to reply
    Loading