Traditional Culture Encyclopedia - Photography major - I often hear about the acceleration of graphics cards. What is the concept of this acceleration?

I often hear about the acceleration of graphics cards. What is the concept of this acceleration?

Primary graphics accelerated graphics

First words: graphics accelerator card. Is an expansion card used to speed up graphics processing. What is the so-called graphics processing? The computer in the era of pure text, the kind of commands and words line by line, is not called graphics processing. -P Graphics and characters are two things that the computer outputs to "see".

First, the text, the forgotten era

Real text processing, unfortunately, has been completely eliminated after DOS. So there is no so-called "word accelerator card" because the current graphics card can work normally under Windows even if it has no word processing function at all. At this point, some people may ask: isn't the text in Windows just "text"? The answer is: for you, yes. But to a computer, it is not text. Text in Windows is also a graphic. Those words were drawn by the window. Open fonts in control panel. What do you see? All kinds of fonts, right? These are not stored in the graphics card, but in the hard disk. When Windows receives a command to print a line on the window, it will dispatch a "drawing" program to read fonts from the hard disk and draw them on the screen. Now it's clear that the interface of Windows is entirely based on graphics. So the graphics accelerator card is very important for Windows. Ok, now, let's forget the text! -_-

Second, the definition of graphics, pixels and so on

Let's look at the definition of graphics. There are two distinct definitions of graphics in a computer. The first is called raster graphics, and the second is called vector graphics. The so-called "raster graphics", every computer player has extensive contact. Now you open the "brush" program of Windows, draw a few circles, lines and colors at will, and then enlarge your picture by 8 times (I don't need to instruct you to do this, do I? ! ) What do you see? Is your figure made up of small squares? Each small square is called a pixel. In other words, your graphics are made up of small pixels.

Staring at a pixel, what do you find? That's right, a pixel has only one color! ( #%@#%^@)。 Anyone who knows a little about chromatics should know that light is composed of red, green and blue in any proportion. A pixel in this picture is also composed of red, green and blue. In the most extensive cg animation, each primary color is composed of eight binary numbers 0 or 1, that is, eight bits, that is, the expressive force of each color is 2 8 = 256, which is called "color scale". Have you studied statistics? Each primary color has 256 levels, so how many colors are the expressive force of the three primary colors R/G/B? Well, forget it, I'll tell you. You must multiply them. The result is 256x256x256 = ...16777216 species. Wow? ! So much? Ok, let's use the computer's usual thousand-digit system: 16,777,216 =16m. This is what people often say: 16 mega color, true color and so on.

There is an episode here. If a dye occupies 8 positions, then R/G/B always occupies 8+8+8 = 24 positions. But for the current 32-bit computer system, 24 bits is a very uncomfortable length. It should be that 24 bits are too small for a computer to process 32 bits at a time, but processing two 24 bits at a time is beyond the processing capacity of 32 bits. What do we do? Only after the 24-bit color can we add 8-bit empty data. Such a pixel's color will occupy 32 bits, which just corresponds to the processing power of a 32-bit system. It feels much more comfortable. "Empty data? You mean wasting 8 bits of data per pixel? " The answer is no. Although the last eight digits have no influence on the display of graphics, people always try to make full use of the existing resources because there are eight more digits here. So another concept is added to the pixel: transparency. That is, we all know the Alpha value of pixels. It's a good idea to save α with 8 useless bits. In this way, we can mix one pixel with another according to the transparency of the pixel to produce overlapping effect. This is the legendary alpha mixed special effects. It's simple, right? Here, we use a more professional format to represent the most commonly used pixels: R8G8B8A8. Wow, what? Ok, take it apart: R8, G8, B8 and A8, which are red 8, green 8, blue 8 and transparent 8. It's good to bluff ~ :P

So much for raster graphics. Next, it's time for another hero to appear: vector graphics. Don't underestimate it, a large part of the current 3D image foundation is based on it.

A raster graphic is a point, but what is a vector graphic? In fact, it is also a point, but there is a mathematical formula. Let's put it this way: If raster graphics tell the computer what color to draw at each point, then vector graphics teach the computer how to draw a graphic. Such as a circle. If it is represented by raster graphics, there must be a large number of pixels to describe the color of each point in the circle. Represented by vector graphics: it is a circle, the center of the circle, the radius of the circle (or the color of the circle). It's that simple. When the computer draws these two pictures, it is a completely different job. When drawing a raster image, the computer reads out all the pixel data, and then copies the original model to the display buffer, so that we can see the circle on the screen. Drawing a vector circle is completely different: first, the computer must determine the center and radius of the circle, and then find out which area of the screen the circle will fall in. This very important step is called setup. After finding the screen area where the circle is located, you can fill this area with the specified color. This step is called rasterization. When the area where the circle is located is filled in, we naturally see the circle. b)

This is the initial basis of cg animation. Keep in mind the definitions of raster graphics and vector graphics, and the drawing method of vector graphics. Generally speaking, there are two steps, namely setting and rasterizing. This is very important in the future knowledge of 3D graphics.

Logical acceleration of graphics acceleration

A long time ago, all drawing work was done by our great and sacred CPU. At that time, the graphics card was really used to "show things off". Its job is to "move" the data processed by CPU to the display. At that time, CPU worked really hard. Now, the CPU is getting faster and faster, but the work is getting less and less. Let me talk about several stages of graphics acceleration first. 2D image acceleration, Windows acceleration and 3D image acceleration. :rolleyes:

First, simple and rigid 2D acceleration.

2D acceleration is a product with a long history. Its function is to replace CPU with display chip and move the data in memory block by block. For example, if you want to move a window, what does the CPU do in the era without 2D acceleration: 1, find the address of the window in the video memory, 2, copy a line of data to the destination address, 3, and repeat 2 until all lines are copied. It's done. In this way, when the window is very large, the amount of data to be processed by the CPU will increase exponentially, resulting in the window moving slower than snail crawling ... Want to experience it? Ok, enter the device manager, delete your graphics card driver, and then restart ... enjoy it! Hmm. How interesting

With 2D acceleration, the CPU does a lot less, but it still has to guide the display chip to be a porter. CPU's job: 1, find the address of the window in the video memory, and 2, send the command "Copy this line to the destination" to the graphics card. 3. Repeat 2 until all the lines have been copied. At first glance, it seems almost the same as before, but the second step is the key.

Now let's break down the second step: no 2D acceleration: 1, reading 32-bit data (in the introductory article! ) to write 32-bit data to the destination. 2. Repeat 1 until all pixels in a row have been processed. With 2D acceleration, the only task is: 1, send a command to the graphics card to copy this line. In this way, 2D acceleration can really release the burden of CPU to a great extent. So now everyone just mentions a window and moves it. Smooth, isn't it? The graphics card is responsible for moving the window.

Second, strange Windows acceleration.

For every PC programmer, Windows can be described as "weird". There are so many proprietary things in Windows that the graphics card has to make an acceleration plan for Windows itself. There are almost no graphics cards with all Windows acceleration functions. At present, the speed of CPU is enough to make up for the defect that Windows does not have all hardware acceleration. Generally speaking, it includes the acceleration of mouse cursor, icon, special window, etc.

Mouse acceleration is to use the hardware of the graphics card to handle the mouse cursor of Windows. The mouse cursor you see now does not belong to the same layer as other contents on the desktop. It is painted on the "top layer" of the graphics card. I don't need to introduce the specific content in detail. Anyway, I'll tell you a way to tell. Open an animation window, that is, a window whose content has been changing, and then move the mouse cursor up. If the cursor keeps flashing, the graphics card will not accelerate the mouse cursor. Conversely, if the mouse cursor does not move, the graphics card will accelerate the mouse cursor.

Icon acceleration is the function of the graphics card to draw Windows icons. This function is really rare, but for the 32-bit transparent chart commonly used in Windows xp at present, the modern graphics accelerator card can play a certain degree of acceleration function.

Special window acceleration: Isn't window acceleration handled by 2D acceleration function? What's special about it? Of course there is. Move a window, hehe, now you know what the computer is doing. However, when the top window blocks the window you moved, that is, an "always in front" window (called "always in front" by Windows) blocks the desktop, and you move a window below it ... How to explain it? ? At this time, what Windows has to do is slightly different. It first finds the exposed part of the window, then divides the whole window into small pieces one by one, and then moves to the target position one by one. Is it more troublesome? And if you use a graphics card with Windows acceleration, the graphics card can handle all this by itself. Let's not say that Windows has accelerated, because it's so huge that I haven't fully understood it. Then, it's our protagonist's turn to appear-:Charles:

Third, complex and huge 3D acceleration.

Everyone likes to render 3D animations (except those that are dizzy at first sight). Who is not excited to see the virtual protagonist jumping around on the screen, killing and saving the world? Speaking of 3D acceleration, because it is too complicated, I plan to divide it into five parts, from simple to complex, from past to future, covering the basic knowledge of 3D acceleration, so that everyone can know more about the work of our unknown 3D accelerator card.

3. 1: color triangle

That's how the world began. People think of using triangles to represent 3D objects. It's actually quite simple. Students who have studied geometry in high school know that three points determine a plane. So triangles are always flat. Such a complex curved surface object is approximately represented by a small plane, which will be much more convenient in painting. Let's look at the process of drawing triangles: I have already talked about the process of drawing vector diagrams in my last article. In fact, triangles are also equivalent to vector diagrams. It consists of three vertices. There are two steps in drawing: 1. Find the position of the triangle on the screen. 2. Make this place full of color. That's what I call the process of setting and rasterizing. Because the object is a triangle, we give these two processes another name: triangle setting and triangle rasterization. Hehe, it smells like modern graphics! At the beginning, 3D graphics only had color, no texture, texture and so on, so the generated images felt like sudden light. At that time, there was no concept of 3D games, and professionals would not care about it. ...

3.2: Mapping? Skin ...+mixed color

Obviously, people will not be satisfied with forever watching things made up of bare triangles jumping around on the screen. So slowly someone thought: How about we put texture stickers on triangles? Speaking of texture, look at your furniture. The wood grain on their surface is really like the texture map used for triangles! Texture mapping is similar to wallpaper and stickers in real families in the field of 3D graphics. At that time, in the early days of the invention of texture mapping, there was strong opposition! Some people think texture mapping is useless, so that some companies even produced graphics cards that didn't support texture mapping during that time (can you imagine a graphics card without TMU? I forgot the name of the company! However, texture mapping still shows its powerful charm. In today's 3D graphics technology, texture mapping is an independent subject.

Some people may ask, how does the texture map stick to the triangle? The explanation of this process is complicated. You can try to imagine that the texture map needs coordinates to specify, just like you draw a fixed point on a newly made table and paste the sticker at the fixed point. In other words, the vertices of each triangle contain mapping coordinates, so that the texture map can be pasted to the corresponding position according to the mapping coordinates during processing. How to post it? ! I haven't said it yet. Oh, by the way, hehe, how to post it? Here's the thing: in the triangle setting stage, the mapping coordinates are also applied to each pixel. Specifically, knowing the mapping coordinates of vertices, then the mapping coordinates of any point in the triangle should also be calculated, right? ! By the way, it's interpolation. Using interpolation, you can get the mapping coordinates corresponding to each point of the pixel of the triangle to be drawn, right? With this mapping coordinate, it is much simpler. We use coordinates to get the corresponding coordinate color from the map. Isn't that just pasting a map? Hehe, this paragraph is a bit circuitous, which is also my poor writing skills. Please read it carefully several times. Excuse me!

In addition, the color mixing caused by texture mapping should also be included in this section. Color mixing ... I know! Isn't it just mixing the operations of two pixels into one pixel with the Alpha value of one pixel? Yes, but color mixing is not limited to alpha mixing. There are many kinds of mixing methods. For example, add the color of a triangle pixel to the color of the original pixel on the screen, so that it looks like the triangle is "highlighted". The flame, halo and so on in the game are all done by addition. Similarly, it is also possible to subtract, multiply or divide the colors of two pixels, which is all-color mixing. It is precisely because of color mixing that all kinds of cool game special effects can be realized.

3.3: Graphics card revolution

The functions mentioned above have been put into some graphics chips. In this way, all these tasks are liberated from the CPU. All right! But CPU is still not satisfied: I want more freedom! People try their best to reduce the burden of CPU. So, in the end, even the Pandora's box before the triangle setting and triangle rasterization process was liberated. This is: geometric transformation and illumination operation (transform &; Lighting, temperature and humidity; l).

Having said that, we have to talk about these two pure mathematical processes. Geometric transformation: As we all know, the 3D graphics we see on the screen are drawn from a certain viewpoint. How is this done? Also, how do 3D objects move in the whole scene? This involves the topic before graphic processing: three-dimensional space geometry. Each 3D object has a data array to represent its position and direction, which we call a matrix. This matrix stores the position, rotation direction, zoom size and other information of objects in the scene. So when an object moves, we don't need to change the positions of all triangles in detail, just change the information in the matrix, and the whole object moves. And the application of matrix is not limited to this. Finally, the whole scene should be transformed into a 3D space centered on the camera, which is also related to the matrix.

Illumination, another mathematical process, is to calculate the intensity of illumination received by the triangle through the position, distance and included angle of the vertex of the triangle relative to the light source in the scene.

In the past, these two pure mathematical processes needed CPU to complete. After the CPU calculates all triangle data, it sends these data to the graphics card for setting and rasterization. But then people found that these operations were too rigid and could be integrated into the display chip! This is the origin of hardware geometric transformation.

Therefore, at this point, the CPU has nothing to do. Modify the matrix of the object, set the required parameters, and then send a command to the display chip: draw! Don't worry about the rest. ...

3.4: the birth of a new CPU: GPU

So can the display chip here be called graphics processing unit? NVidia said so, but as a real processor, it is incomplete without programmability. Tired of using layers of graphics cards, programmers shouted: set me free! They urgently need a design that breaks the current rigid function of hardware. Because everything is made of hardware, the flexibility is completely lost. According to the circuit design, the display chip can only deal with triangles, becoming a rigid "triangle processor". At this time, people began to reflect, people think that giving programmers the greatest freedom is the key to writing good 3D programs. So-designed a programmable graphics chip. This kind of chip is different from previous T&: The biggest difference of L chip is that all its behaviors are programmable. Thus, its function has been promoted to an infinite height.

On the other hand, when there is no hardware 3D acceleration, everything is done by CPU, which is slow but flexible. Then, all the hardware, flexibility has declined again and again. Finally, the programmable graphics chip realizes the perfect combination of speed and flexibility. At this time, what programmers do seems to be back to the primitive times: write their own programs to illuminate, change and rasterize triangles. But what about this? They like freedom!

Everything is fine, and we are happy to say: this is what I want. Are you satisfied? But the truth is not as perfect as you think. God likes playing tricks on people. .....

3.5: The truth? Fallacy?

After so many years of development, the technology of rasterizing 3D graphics can be said to be mature. However, the graphics it generates seem to have never been so real. No matter how hard people try, its picture is still animated, which is always a little worse than the "movie quality" in people's minds. ...

What's going on? At the same time, ray tracing, another branch of 3D graphics, is developing rapidly. Ray tracing graphics and grating graphics are based on completely different theories, and their research results are also incompatible. The theoretical basis of ray tracing graphics is to trace each ray from the eyes and accurately calculate the subsequent colors of these rays after reflection, refraction and scattering. Because of its complex principle, this subject needs less manpower and material resources than grating graphics, so its advantages have just gradually emerged. It will take about ten years to put it into civil use and real-time processing. If it succeeds, all grating graphics theories will be completely overthrown now.