Android Matrix multiplyMM detail

I was wondering if anyone has any knowledge about

android.opengl.Matrix.multiplyMM

so that they can share.

.

The reason for the request is that when learning through OpenGL ES, the method is widely used for all types of calculations. However, there is android.renderscript.Matrix4f , which, it seems to me, works with more natural than with primitive arrays of float []. The problem is that the Matrix4f multiplication function uses a time matrix to perform the operation, which leads to memory inefficiency.

One way to solve this is to create your own Matrix4f and write multiply (). I based it on the following example. It may look awful, but it saves me all the functions set (), get () and looping, which gives an increase in performance.

But then I still did not want to hand over multiplyMM. In the source file, you can read that the method is native, so it should be evaluated faster ( yes? ). And that again made me think.

.

So does anyone know:

  • What is the main algorithm in multiplyMM? Does he use temporary files?
  • Is it faster to use than self-recording?
+6
source share
1 answer

1) The algorithm is matrix multiplication. This is the same as what you learned in your class of linear algebra. (Source: http://androidxref.com/source/xref/frameworks/base/core/jni/android/opengl/util.cpp )

Does multiplyMM temporary partitions? It is native, so it does not matter. If there is a temporary variable, it is allocated on the stack. No GC, because it is native.

2) Maybe. Just because it is written in C ++, which does not speed up code execution. What for? There is overhead for moving from Java land to native code, and it is possible that the overhead outweighs the benefits derived from native code.

Despite all this, there are two more things to keep in mind: 1) Do not prematurely optimize your code if you are not sure that this is a performance bottleneck, and 2) if you are not sure, take some measurements. Profile your code to draw the right conclusions.

+8
source

Source: https://habr.com/ru/post/973406/


All Articles