Related Contents:

  1. OpenGL– An introduction to the graphics API
  2. OpenGL– Related terms explained
  3. OpenGL– Environment configuration
  4. OpenGL- Case 1- Draw a triangle
  5. OpenGL– Case 2 — Draw a square
  6. OpenGL– Image rip
  7. OpenGL–3D mathematics related (Vectors and Matrices)
  8. OpenGL– Matrix transformations and matrix stacks

This content we look at the causes of image tearing, and in order to reduce the probability of occurrence is what kind of scheme to optimize.

Relevant concepts

Before we begin, let’s understand what a CPU and GPU are, what they are used for, and whether a GPU and a graphics card are the same thing.

CPU

  • CPU (central processing unit), is one of the main electronic computer equipment, the core of the computer accessories.
  • In the computer architecture, CPU is the core hardware for controlling and allocating all hardware resources (memory, input and output units, etc.) and performing general operations. All software layer operations in a computer system are eventually mapped to CPU operations through the instruction set.
  • CPU bits are usually 32 or 64 bits, which are the number of floating point numbers that the processor can calculate at one time. In general, the higher the number of digits, the faster the operation.
  • CPU is mainly responsible for multi-task management, scheduling, it is the leader, responsible for command.

The GPU and graphics

  • A GPU (image processing chip) similar in appearance to a CPU.
  • GPU is the core of the graphics card, GPU, video memory, circuit board and BIOS firmware together constitute the graphics card, so GPU is not equal to the graphics card.
  • GPU is mainly used for a lot of double computing, it is a computing expert, but protocol, management is not its expertise. Its computational execution is very strong.
  • Video card is also called display adapter, divided intoDiscrete graphicsIntegrated graphics. Independent graphics card is mainly composed of GPU, video memory and interface circuit, while integrated graphics card has no independent video memory (use memory on the motherboard).
  • Both independent and integrated graphics cards have gpus.

Image tear

frame

Frame – equivalent to every frame on the film, a frame is a still picture, successive frames together form animation, etc. The number of Frames we usually talk about is the number of Frames of pictures transmitted in 1 Second, which can also be understood as the number of times that the GPU(graphics processor) can refresh Per Second, usually expressed as FPS (Frames Per Second).

Each frame is a still image, which morphs into an illusion of movement in rapid succession (similar to the page-turning comic book of childhood). A higher frame rate (the number of frames needed to achieve an animation) results in smoother, more realistic animations. The more frames per second (FPS), the smoother the action will be.

The principle of screen display image

To make it easier to understand, CRT displays are used here. To display the image, the CRT monitor’s electron gun scans from top to bottom in the same way as the image above. When all the scans are complete, the monitor displays a frame, and then the gun returns to its original position for the next scan.

To synchronize the display with the system’s video controller, the display (or other hardware) generates a series of timing signals using a hardware clock. When the gun moves to a new line and is ready to scan, the monitor emits a horizontal synchronization signal, or HSync; When a frame is drawn and the gun returns to its original position, the display sends a vertical synchronization signal, or VSync, before it is ready to draw the next frame.

The monitor usually refreshes at a fixed rate, which is the frequency at which the VSync signal is generated. Although today’s devices are mostly LCD screens, the principle remains the same.

CRT monitor, technically known as “Cathode Ray Tube”, is a monitor that uses Cathode Ray tubes. CRT displays rely on an electron beam to excite phosphors on the inner surface of the screen. Since the phosphors burn out soon after being lit, the electron gun must repeatedly excite these points. With interest can go online search, it is old-fashioned big head display.

Image display process

  1. The CPU calculates what to display and submits it to the GPU
  2. After the GPU rendering is completed, the rendering result will be put intoFrameBuffer
  3. The video controller reads the frame buffer line by line, after possibleD/a conversionPass to the display for display

Tear cause and vertical synchronization

In the beginning, there is only one frame buffer. In this case, reading and flushing of the frame buffer can be very efficient.

1. Double buffer

To solve the efficiency problem, the display system later introduced two buffers, also known as double buffering mechanism. In this case, the GPU will first render for a while and put it into a buffer for the video controller to read. After the next frame is rendered, the GPU will directly point the video controller’s pointer to the second buffer. That’s a huge increase in efficiency.

2. The picture is torn

Dual buffers solve the previous efficiency problem of single buffers, but introduce a new problem. When the video controller has not finished reading, that is, the screen content has not completed the display of 1 frame, THE GPU will submit a new frame to the frame buffer and exchange the two buffers. The video controller then reads the second half of the new frame and displays it on the screen, causing the tear in the image we started with.

3. Vsync

To address the tearing problem caused by dual buffers, gpus have introduced a new mechanism called vertical synchronization (V-sync). When VSync is enabled, the GPU waits for the VSync signal from the display before rendering a new frame and updating the buffer. This eliminates the tearing and increases the smoothness of the picture. However, it consumes more computing resources and also introduces some latency.

conclusion

The above is all about the screen tear content, if there is wrong place or do not understand the place welcome to leave a message below. Speaking of image tearing, many people may also think of interface lag and off-screen rendering, which will be discussed in the future, thanks ~

Harmonious learning, not impatient ~