Optimize matrix inversions and reduce GPU stalls #7367
Optimize matrix inversions and reduce GPU stalls #7367xavierjs wants to merge 15 commits intomaplibre:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7367 +/- ##
==========================================
+ Coverage 92.77% 92.79% +0.01%
==========================================
Files 289 290 +1
Lines 24017 24083 +66
Branches 5100 5099 -1
==========================================
+ Hits 22282 22348 +66
Misses 1735 1735 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for taking the time to open this PR! |
… matrix bug thanx to the unit test
I would be difficult to test the matrix type because a full test may be as costly as using the adjoint matrix formulae. Where we use specific matrix inversion there is already strong hypothesis on the matrix format (like we know it is and it should be a projection matrix, or a transform matrix, ...). |
|
Ok, thanks. Please make sure to address the other code review comments. |
I think I implemented feedback or answered to all comments in this PR. |
|
There are still two open comments that were not addressed and no replay, have you forgot to push some code? |
|
Added a last comment, thanks for the improved description. |
|
I did some mess with a rebase, I am fixing it |
4d7df8b to
1bf0984
Compare
Hi,
Thank you for considering my PR.
Issue
To compute matrix inversion, we use the general method
mat4.invertfrom thegl-matrixpackage: https://github.com/toji/gl-matrix/blob/master/src/mat4.js#L293This function compute the invert matrix using the general auto-adjoint formulae.
Proposed solution
In most cases, the matrix to invert has a specific format (transformation matrix, projection matrix, ...), so we can compute the inverse with far less operations.
In this PR, we also avoid some useless allocations, and we add 2 minor optimizations:
WebGL2context, we just rungl instanceof WebGL2RenderingContext;gl.getParameter(gl.MAX_TEXTURE_SIZE);at each raster tile loading (in generalgl.getParametercan stall the GPU for some configuration, we should cache its value when possible)Benchmarks
The performance improvement is not drastic. There is a 7% gain on the
Placementbenchmark.Misc
No related issues.
This PR does not include any visual changes and does not require additional tests.
npm run test-renderruns exactly as before.Launch Checklist
CHANGELOG.mdunder the## mainsection.