📜 ⬆️ ⬇️

Hell Visualization 1.1 - Book 1: Overview

Ad visualization 1.1:
Lack of knowledge can sometimes be a virtue, because you naively say to yourself: “Pff ... is it really difficult?” And just dive into the problem with your head. I started this article by thinking: “Hmm ... What is Draw Call?”. During the "5-minute" study, I did not find an explanation that satisfied me. I checked the clock and, as there was still 30 minutes left until sleep, I said ...
Pff ... Is it difficult to write yourself?
... and just started. It was two months ago and since then I have continuously read, written and asked many questions.

It was the most difficult and low-level research I've ever done, and for me non-programmer it was a nightmare consisting of “yes, but in this particular case ...” and “depends on the implementation of the API ...”. It was my personal hell of visualization, but I went through it and brought something with myself: Four books, each of which is an attempt to explain one of the parts of the visualization from the point of view of the artist. I hope you enjoy it.



Today, artists need to be well-versed: From a computer point of view, your gaming resources are just sets of vertices and texture data. The conversion of these raw data into a “next generation” image is primarily done by your central processing unit ( CPU ) and graphics processing unit ( GPU ).
')

1. Copying data into RAM for quick access


First, all the necessary data is loaded from your hard disk ( HDD ) into random access memory ( RAM ) for quick access. After that, the necessary polygonal grids and textures are loaded into the graphics card memory ( VRAM ). This is done because the graphics card has significantly faster access to VRAM and in most cases does not have access to RAM.



Before the renderer can get down to work, the CPU sets some global values ​​that describe how the polygon mesh should be displayed. This set of values ​​is called a Render State .

2. Setting Render State Values


Render State is some kind of global definition of how a polygonal mesh should be rendered. It contains information about:
“Vertex and pixel shaders, textures, materials, lighting, transparency and so forth. [...] "[ Real-Time Rendering : p. 711]
It is important that each polygonal mesh that the CPU sends to the GPU for drawing will be displayed with these conditions! You can draw a stone, a chair, or a sword — they will all use the same rendering parameters (such as material), unless you change the Render State before the next grid is displayed.



After the preparation is finished, the CPU can finally turn to the GPU and tell it what to draw. This command is known as Draw Call .

3. Draw Call


Draw Call is a command to display a single polygonal grid. It is given by the central processor. It gets a graphics processor. The command points only to the polygon mesh to be displayed, and does not contain any information about the material, since it is already defined through the Render State setting. At this point, the polygonal mesh is in the graphics card memory (VRAM).



After the command is given, the GPU takes the parameters of the Render State (material, texture, shader, ...) and all the vertex data and converts this information with the help of some magic into beautiful (hopefully) pixels on your screen. This conversion process is called a pipeline .

4. Conveyor


As I said above, game resources are, in some way, just sets of vertices and texture data. To transform them into a stunning picture, the graphics card needs to create triangles from the vertices, calculate their illuminance, display texture pixels on them, and much more. These actions are called states. Conveyor states.

Depending on what materials you read, you find that almost everything is done by the graphics processor. But sometimes it is said that, for example, the creation of triangles and fragments is done by other parts of the graphics card.


This example of the pipeline is extremely simplified and should be interpreted only as giving a general idea. I tried to portray it as well as I could, but as a non-programmer, I have trouble understanding when the example becomes so simple that it leads you in the wrong direction. So please do not take it seriously and look at all the other wonderful sources that I cited at the end of the article. Or feel free to send me a letter, tweet or Facebook message to improve the animation / explanation. :)


Here is an example with a single GPU core:


A visualization is simply the execution of a huge number of small tasks, such as calculating something for thousands of vertices or drawing millions of pixels on the screen. At least (it would be good) at 30 frames per second.

It is important to be able to calculate these things at the same time , rather than each vertex / pixel one by one. In the good old days, processors had only one core and there was no graphic acceleration - they could only do one thing at a time. The games looked like ... retro. Modern CPUs have 6-8 cores, while GPUs contain several thousand (they are not as complex as CPU cores, but they are ideal for passing through a huge amount of vertex and pixel data).

When data (for example, a bunch of vertices) get to the pipeline stage, the work on the transformation of points / pixels is divided between several cores so that the majority of these small elements are formed in parallel into the big picture:



Now we know that the GPU can process everything in parallel. But what about the communication between the CPU and the GPU? Is the CPU waiting for the moment when the GPU finishes its work and is able to receive new commands?



Not!


Fortunately, no! The reason is that such communication will form “bottlenecks” (for example, when the CPU cannot deliver commands quickly enough) and make parallel operation impossible. The solution is a list in which commands can be added to the CPU and read by the GPU independently of each other! Such a list is called a command buffer .

5. Command buffer


The command buffer allows the CPU and GPU to operate independently of each other. If the CPU wants to display something, it places the command in the queue, and when the resources appear in the GPU, it takes a command from the list and executes it (but since the list is organized as a FIFO , the GPU can take only the oldest command from the list ( which was added first) and execute it).



However, the commands may be different. One of the examples is Draw Call, the other can be a change to the Render State.

This concludes the first book. Now you should have a general understanding of these game resources, Draw Calls, Render States, and the interaction between the CPU and the GPU.

the end

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


All Articles