diff options
author | Pekka Paalanen <ppaalanen@gmail.com> | 2012-01-20 10:47:57 +0200 |
---|---|---|
committer | Pekka Paalanen <ppaalanen@gmail.com> | 2012-01-27 10:44:22 +0200 |
commit | d1f0ab63431cfa9b558afd026db87a59b841db40 (patch) | |
tree | 492138b5c53ec888fb767e28b494e86874859a54 /tests | |
parent | 1ef94c87422c1950d9c73545ddfe3d5a6bfaae99 (diff) |
compositor: simplify the matrix inversion API
The compositor will likely do an order of magnitude less matrix
inversions than point transformations with an inverse, hence we do not
really need the optimised path for single-shot invert-and-transform.
Expose only the computing of the explicit inverse matrix in the API.
However, the matrix inversion tests need access to the internal
functions. Designate a unit test build by #defining UNIT_TEST, and
export the internal functions in that case.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/matrix-test.c | 60 |
2 files changed, 25 insertions, 37 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index e9d96ac..a1f361e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,7 +6,7 @@ endif AM_CFLAGS = $(GCC_CFLAGS) -AM_CPPFLAGS = -I../src +AM_CPPFLAGS = -I../src -DUNIT_TEST matrix_test_SOURCES = \ matrix-test.c \ diff --git a/tests/matrix-test.c b/tests/matrix-test.c index 76d93ad..6fdab83 100644 --- a/tests/matrix-test.c +++ b/tests/matrix-test.c @@ -30,6 +30,11 @@ #include "matrix.h" +struct inverse_matrix { + double LU[16]; /* column-major */ + unsigned perm[4]; /* permutation */ +}; + static struct timespec begin_time; static void @@ -81,9 +86,9 @@ determinant(const struct weston_matrix *m) } static void -print_permutation_matrix(const struct weston_inverse_matrix *m) +print_permutation_matrix(const struct inverse_matrix *m) { - const unsigned *p = m->p; + const unsigned *p = m->perm; const char *row[4] = { "1 0 0 0\n", "0 1 0 0\n", @@ -95,7 +100,7 @@ print_permutation_matrix(const struct weston_inverse_matrix *m) } static void -print_LU_decomposition(const struct weston_inverse_matrix *m) +print_LU_decomposition(const struct inverse_matrix *m) { unsigned r, c; @@ -128,7 +133,7 @@ print_LU_decomposition(const struct weston_inverse_matrix *m) } static void -print_inverse_data_matrix(const struct weston_inverse_matrix *m) +print_inverse_data_matrix(const struct inverse_matrix *m) { unsigned r, c; @@ -140,7 +145,7 @@ print_inverse_data_matrix(const struct weston_inverse_matrix *m) printf("permutation: "); for (r = 0; r < 4; ++r) - printf(" %u", m->p[r]); + printf(" %u", m->perm[r]); printf("\n"); } @@ -175,22 +180,6 @@ randomize_matrix(struct weston_matrix *m) #endif } -static void -invert_matrix(struct weston_matrix *m) -{ - struct weston_inverse_matrix q; - unsigned i; - - if (weston_matrix_invert(&q, m) != 0) { - m->d[0] = NAN; - return; - } - - for (i = 0; i < 4; ++i) - weston_matrix_inverse_transform(&q, - (struct weston_vector *)&m->d[i * 4]); -} - /* Take a matrix, compute inverse, multiply together * and subtract the identity matrix to get the error matrix. * Return the largest absolute value from the error matrix. @@ -199,15 +188,14 @@ static double test_inverse(struct weston_matrix *m) { unsigned i; - struct weston_inverse_matrix q; + struct inverse_matrix q; double errsup = 0.0; - if (weston_matrix_invert(&q, m) != 0) + if (matrix_invert(q.LU, q.perm, m) != 0) return INFINITY; for (i = 0; i < 4; ++i) - weston_matrix_inverse_transform(&q, - (struct weston_vector *)&m->d[i * 4]); + inverse_transform(q.LU, q.perm, &m->d[i * 4]); m->d[0] -= 1.0f; m->d[5] -= 1.0f; @@ -309,21 +297,21 @@ static void __attribute__((noinline)) test_loop_speed_inversetransform(void) { struct weston_matrix m; - struct weston_inverse_matrix inv; + struct inverse_matrix inv; struct weston_vector v = { { 0.5, 0.5, 0.5, 1.0 } }; unsigned long count = 0; double t; - printf("\nRunning 3 s test on weston_matrix_inverse_transform()...\n"); + printf("\nRunning 3 s test on inverse_transform()...\n"); weston_matrix_init(&m); - weston_matrix_invert(&inv, &m); + matrix_invert(inv.LU, inv.perm, &m); running = 1; alarm(3); reset_timer(); while (running) { - weston_matrix_inverse_transform(&inv, &v); + inverse_transform(inv.LU, inv.perm, v.f); count++; } t = read_timer(); @@ -336,11 +324,11 @@ static void __attribute__((noinline)) test_loop_speed_invert(void) { struct weston_matrix m; - struct weston_inverse_matrix inv; + struct inverse_matrix inv; unsigned long count = 0; double t; - printf("\nRunning 3 s test on weston_matrix_invert()...\n"); + printf("\nRunning 3 s test on matrix_invert()...\n"); weston_matrix_init(&m); @@ -348,7 +336,7 @@ test_loop_speed_invert(void) alarm(3); reset_timer(); while (running) { - weston_matrix_invert(&inv, &m); + matrix_invert(inv.LU, inv.perm, &m); count++; } t = read_timer(); @@ -364,7 +352,7 @@ test_loop_speed_invert_explicit(void) unsigned long count = 0; double t; - printf("\nRunning 3 s test on computing the explicit inverse matrix...\n"); + printf("\nRunning 3 s test on weston_matrix_invert()...\n"); weston_matrix_init(&m); @@ -372,7 +360,7 @@ test_loop_speed_invert_explicit(void) alarm(3); reset_timer(); while (running) { - invert_matrix(&m); + weston_matrix_invert(&m, &m); count++; } t = read_timer(); @@ -385,7 +373,7 @@ int main(void) { struct sigaction ding; struct weston_matrix M; - struct weston_inverse_matrix Q; + struct inverse_matrix Q; int ret; double errsup; double det; @@ -402,7 +390,7 @@ int main(void) M.d[2] = 6.0; M.d[6] = 18.0; M.d[10] = -12; M.d[14] = 0.0; M.d[3] = 0.0; M.d[7] = 0.0; M.d[11] = 0.0; M.d[15] = 1.0; - ret = weston_matrix_invert(&Q, &M); + ret = matrix_invert(Q.LU, Q.perm, &M); printf("ret = %d\n", ret); printf("det = %g\n\n", determinant(&M)); |