In addition to CPU, another important component of SoC (System On a Chip) is the Graphic Processing Unit, commonly known as GPU. We may all know that playing 3D games requires it, but it may not be clear what role it plays. This time, we will unveil the mystery of GPU.
GPU is specially used to quickly complete some specific types of mathematical operations, especially for the calculation of floating-point, vector and matrix. It can convert the information of 3D model into 2D representation, and add different textures and shadow effects at the same time. Therefore, GPU is also a special existence in hardware.
The 3D model is composed of many small triangles. The vertices of each triangle are defined by X, Y, Z coordinates. In actual processing, the vertices of small triangles will coincide with each other. If a complex model consists of 500 small triangles, the final number of vertices to be defined is not as many as 1500. To show an abstract 3D model, three elements are indispensable: displacement, rotation (three-axis) and scaling, all of which are collectively referred to as transformation. In order not to fall into complicated and tedious mathematical operations, the best way to deal with transformation is to use a 4x4 matrix.
From 3D modeling to final display on the screen, GPU renders the scene using pipeline operation. In the early days, the pipeline operation was fixed and could not be changed. The whole operation started from reading the vertex data of the triangle, and then the GPU entered the frame buffer after processing, ready to send it to the display. GPU can also process certain effects on the scene, but these are designed and fixed by engineers, and there are few options available.
Programmable shaders
When Android was still in its infancy, desktop GPUs began to program the operations of the streamline. With the introduction of OpenGL ES 2.0 standard, the mobile GPU also began to support programmable operations. These programmable parts are called shaders. The most important two shaders are vertex shader and fragment shader. Each vertex will call the vertex shader once, so the vertex shader needs to be called three times when rendering a triangle; For fragment shader, we can simply imagine each fragment as every pixel on the screen, so every pixel fragment shader generated will be called once.
The two shaders play different roles. Vertex shaders are mainly responsible for transforming the data of 3D models into positions, texture maps or light sources in the real world, and then transforming them; The clip shader is used to set the relevant color for each pixel. A simple explanation: Vertex shaders are used to process information related to vertices, and fragment shaders are used to process color information of the screen.
After careful observation, you will notice that the processing of each vertex is independent of each other, as is the processing of each segment, which means that GPU can run shaders in parallel. In fact, GPU does the same thing. Most mobile GPUs have multiple shader cores (independent units that can programmatically execute shader functions are called shader cores), As for GPU manufacturers' claims that shader calls are better than others, this is a marketing problem.
Take the Mali GPU of ARM as an example. The x in the "MPx" suffix of the series GPU name represents how many shader cores there are, and the Mali T880 MP12 represents 12 shader cores. Each core has a complex pipeline, which means that every shader operation is completed, new operation instructions will be issued immediately. At the same time, there is more than one arithmetic unit in the core, so multiple operations can be completed in the same time. The ARM Mali GPU (including the Mali T600, T700, and T800 series) can issue one instruction per clock cycle in each pipeline, so a typical shader core can issue four instructions in parallel. The Mali GPU currently supports up to 16 cores, that is, up to 64 instructions can be issued in parallel.
All this means that GPU works in parallel to process a large amount of data, which is very different from CPU and is not a general sequential operation. But this is just a small problem. The serious fact is that the programmable shader core represents that the actual performance of each core is no longer set by GPU engineers, but depends on app developers. As a result, a poor quality shader code can make the performance of the GPU plummet. Fortunately, most 3D game developers understand this truth and will make the best optimization for shader operation.
Translation and arrangement of pictures and texts , due to the limited level of translators, you are welcome to correct any mistakes
Reward
Scan WeChat and reward the author