<p>How much data is passed from the CPU to the GPU per frame depends on the engine you are using and its needs. Usually, you want to keep it minimal to avoid that the GPU needs to wait for data because the CPU can't deliver it fast enough. I can not guarantee you, that the following is always the same for all engines and graphic APIs since I have only written OpenGL code myself so far, but to my knowledge, it is quite similar.</p>
<p>What you usually do is that you send all data that doesn't change to the GPU at the beginning. Objects (meshes) and textures are typical candidates for this. Animated meshes like characters can also be loaded in advance by providing a default position.</p>
<p>The object data consists of vertices. They are control points that store the position of each point and an arbitrary set of additional information. A typical additional piece of information might be a color, surface normal, or texture coordinate (this does not specify which texture). Note, that there is no information at this point, how those vertices are connected. This is why I put &quot;meshes&quot; into parenthesis in the previous section.</p>
<p>Now you have a bunch of vertex groups and textures and it is time to render our scene. We assume, that all work that is not related to rendering is done by the CPU. Most of it can also be done by the GPU, but lets keep it simple.</p>
<p>The CPU calculates where every object is positioned in the current frame, including the camera. It also calculates the skeletal state of our animated characters. Now, to render a single object, we need to provide the following information to the GPU:</p>
<ul>
<li>the object data we want to use</li>
<li>the textures we want to use</li>
<li>connectivity of the vertices</li>
<li>the shader program we want to use</li>
<li>the data the shader program requires to do its job (usually some transformation matrices and vectors)</li>
</ul>
<p>The first two are just IDs we got from our API/engine when we uploaded the data. You should know for all your objects, which mesh and texture IDs they use. The third point, connectivity, actually tells the GPU how the single vertices are connected to each other. In OpenGL, there are several ways to specify this. A lot of them assume a specific order in the data, for example that 3 vertices in a row represent a single triangle. But there are also explicit ways by providing an index list to the GPU (This is usually also done at startup).</p>
<p>Now that the GPU knows which data to use and how it is connected, it needs to know what to do with it. This is done by selecting a shader program.</p>
<p>Shaders are small programs that run on the GPU. They have several stages that turn your mesh into actual pixels on your screen (<a href="https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview" rel="nofollow noreferrer">see OpenGL rendering pipeline</a>). You usually compile several of them at the beginning when uploading all the other data. Those programs generally also need some additional information to run and you need to pass that to the GPU. What that data is, strongly depends on the effects you want to use, but something you need very often are the transformations needed to place a vertex in relation to the camera and the projection you want to use (perspective, parallel). Now the shader program can calculate each vertex position on the screen, create triangles from it and color each of its pixel as desired (using the textures you specified). You do this for every object in your scene (that is not culled).</p>
<p><strong>To sum it up:</strong></p>
<p>For a single object in a basic OpenGL engine, you pass the IDs of its vertex data, textures and shader program to the GPU, which are just numbers. Then you pass all data needed by the shader program. This is mostly a bunch of floats for the transformations. Finally, you also tell the GPU how the data is connected for your current &quot;draw call&quot;. There is also not much data transfer involved here, since you either have your data ordered in a specific way and need to tell the GPU just which method to use or you have uploaded a connectivity list upfront and tell the GPU the ID of the index list it should use.</p>
<p>Please note, that the described procedure is based on the approach that is described in most tutorials. Modern engines use several optimization techniques to balance CPU and GPU processing power so that they are always busy. This might require more involved data transfer. Also note, that the data transfer itself has bandwidth limitations that need to be considered.</p>

CC BY-SA 4.0
2021-08-10T12:41:21.520Z
Thanks for a great answer. Do you have a link to an explanation of some different ways to specify connectivity?
Jojo
CC BY-SA 4.0
2021-08-10T13:17:54.300Z
You can check the API description of [`glDrawArrays`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawArrays.xhtml). It gives you a list of possible inputs like `GL_TRIANGLES` or `GL_TRIANGLE_STRIP`. However, it is not explained there how the data needs to be ordered and how the API uses it. Maybe you should read some simple tutorials like [this one](https://learnopengl.com/Getting-started/Hello-Triangle) and some of the following chapters. It should give you a good idea how the things that I described work. You don't need to code anything. Just read it. ;)
wychmaster
CC BY-SA 4.0
2021-08-10T08:56:48.690Z
2021-08-10T08:56:48.690Z
wychmaster
<p>The short answer to this question is: <strong>everything</strong></p>
<p>On any give frame almost any kind of data my be needed to render that new and wonderful object that just popped into view. It's shader needs to be loaded and compiled, its textures, buffer data, specializations, push constants, if you can dream it up for a render call then it needs to find its way to the GPU on a per frame basis.</p>
<p>This is the reason GPU's have rich and diverse paths for loading data, along with dedicated hardware and code for handling all the red tape that goes along with it.</p>
<p><em>What is its format</em>:
Again the answer to this question is: <strong>everything</strong> GPU's handle specialized data types that we don't see on the CPU while doing c/c++/whatever programming. Normalized 8 bit floating point values for example.</p>
<p>For technology demo's and simple scene's much of that data can be preloaded, but for any program that is going to do meaningful work, expect any kind of data to be loaded on a per frame basis.</p>
<p>Don't imagine <em>great big arrays</em>, imagine rich and diverse data. Tutorials will focus on the great big arrays, but they are just the tip of the iceberg.</p>
<p>Finally, don't image the CPU as driving everything. Thanks to compute shaders the GPU is taking more control of the action.</p>

CC BY-SA 4.0
2021-08-10T12:44:38.277Z
I understood from the other answer that textures would be passed to the VRAM at the start rather than each frame. Are you saying they're passed each frame? Or just when a new texture is needed it's passed that frame?
Jojo
CC BY-SA 4.0
2021-08-10T13:30:21.100Z
Whenever possible the majority of textures are sent early on, but in a large program, the number and size of texture data will far surpass the available memory and texture data will need to be uploaded dynamically. (and textures that are no longer in needed will be removed or overwritten)
pmw1234
CC BY-SA 4.0
2021-08-10T14:45:32.830Z
But you won't need to transfer that data every single frame. Loading and freeing data can usually be done less frequently, for example when hitting sector boundaries.
wychmaster
CC BY-SA 4.0
2021-08-10T15:10:07.147Z
Now we are splitting hairs, keeping the hardware transfer units busy and avoiding bottlenecks is an interesting subject. One solution to long start up times is to load only the lower mip levels since they can be brought in exponentially faster, then continuing to load higher mip levels interactively will require a load every frame. This extends nicely to distance objects that get only the low mip levels loaded and higher mip levels are loaded only as the camera passes a certain distance from the object. Using this system textures are continually being loaded.
pmw1234
CC BY-SA 4.0
2021-08-10T15:15:32.150Z
My answer was in support of the other answer here, with a slightly different take on the subject, the 40 thousand foot view so to speak.
pmw1234
CC BY-SA 4.0
2021-08-11T11:15:21.107Z
Avoiding data transfer bottlenecks is indeed a valid point. I just haven't seen any engine where data uploading happens every frame, but I am no AAA game developer. Maybe it is really necessary for high-end production code. Anyways, good point.
wychmaster
CC BY-SA 4.0
2021-08-11T14:14:50.363Z
What is 'mip level'?
Jojo
CC BY-SA 4.0
2021-08-11T15:29:00.960Z
@Joe Check [this link](https://en.wikipedia.org/wiki/Mipmap)
wychmaster
CC BY-SA 4.0
2021-08-10T12:31:37.087Z
2021-08-10T12:31:37.087Z
pmw1234
<p>I've been reading a bit about the graphics pipeline for processing on a graphics card, and I'm interested to know in what kind of format data is passed from the CPU to the GPU when rendering 3D graphics, for example for a video game.</p>
<p>I understood that the CPU would calculate what's actually going on inside the game each frame, for example it might have some internal representation of the different characters on the screen and maybe calculate some collision detection between them, and then it might move them around a bit and output the change to the GPU. Then the GPU must receive some information corresponding to many different triangles in different locations, and it has rasterize them and add textures and then combine them all together into a HD pixel array.</p>
<p>So what would be a kind of schematic overview of the form of the data passed to the GPU each frame? I imagine something like a great big array of sets of three points which respond to the vertices of triangles, with associated textures or pointers to textures or something? I expect there would need to be additional information passed each frame as well as the actual triangles and textures, and I'm interested to know what this would be also.</p>
<p>Also, is there some kind of standard format for this, or does it depend on the hardware?</p>

<gpu><hardware>
What data is passed from the CPU to the GPU each frame?
Jojo
# What data is passed from the CPU to the GPU each frame?

(Asked by: username_0 on 2021-08-09)

I've been reading a bit about the graphics pipeline for processing on a graphics card, and I'm interested to know in what kind of format data is passed from the CPU to the GPU when rendering 3D graphics, for example for a video game.

I understood that the CPU would calculate what's actually going on inside the game each frame, for example it might have some internal representation of the different characters on the screen and maybe calculate some collision detection between them, and then it might move them around a bit and output the change to the GPU. Then the GPU must receive some information corresponding to many different triangles in different locations, and it has rasterize them and add textures and then combine them all together into a HD pixel array.

So what would be a kind of schematic overview of the form of the data passed to the GPU each frame? I imagine something like a great big array of sets of three points which respond to the vertices of triangles, with associated textures or pointers to textures or something? I expect there would need to be additional information passed each frame as well as the actual triangles and textures, and I'm interested to know what this would be also.

Also, is there some kind of standard format for this, or does it depend on the hardware?

**Tags:** gpu, hardware


---

## 2 answers

### Answer by username_1 on 2021-08-10. Score: 3 | Accepted answer

How much data is passed from the CPU to the GPU per frame depends on the engine you are using and its needs. Usually, you want to keep it minimal to avoid that the GPU needs to wait for data because the CPU can't deliver it fast enough. I can not guarantee you, that the following is always the same for all engines and graphic APIs since I have only written OpenGL code myself so far, but to my knowledge, it is quite similar.

What you usually do is that you send all data that doesn't change to the GPU at the beginning. Objects (meshes) and textures are typical candidates for this. Animated meshes like characters can also be loaded in advance by providing a default position.

The object data consists of vertices. They are control points that store the position of each point and an arbitrary set of additional information. A typical additional piece of information might be a color, surface normal, or texture coordinate (this does not specify which texture). Note, that there is no information at this point, how those vertices are connected. This is why I put "meshes" into parenthesis in the previous section.

Now you have a bunch of vertex groups and textures and it is time to render our scene. We assume, that all work that is not related to rendering is done by the CPU. Most of it can also be done by the GPU, but lets keep it simple.

The CPU calculates where every object is positioned in the current frame, including the camera. It also calculates the skeletal state of our animated characters. Now, to render a single object, we need to provide the following information to the GPU:

* the object data we want to use
* the textures we want to use
* connectivity of the vertices
* the shader program we want to use
* the data the shader program requires to do its job (usually some transformation matrices and vectors)

The first two are just IDs we got from our API/engine when we uploaded the data. You should know for all your objects, which mesh and texture IDs they use. The third point, connectivity, actually tells the GPU how the single vertices are connected to each other. In OpenGL, there are several ways to specify this. A lot of them assume a specific order in the data, for example that 3 vertices in a row represent a single triangle. But there are also explicit ways by providing an index list to the GPU (This is usually also done at startup).

Now that the GPU knows which data to use and how it is connected, it needs to know what to do with it. This is done by selecting a shader program.

Shaders are small programs that run on the GPU. They have several stages that turn your mesh into actual pixels on your screen ([see OpenGL rendering pipeline](https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview)). You usually compile several of them at the beginning when uploading all the other data. Those programs generally also need some additional information to run and you need to pass that to the GPU. What that data is, strongly depends on the effects you want to use, but something you need very often are the transformations needed to place a vertex in relation to the camera and the projection you want to use (perspective, parallel). Now the shader program can calculate each vertex position on the screen, create triangles from it and color each of its pixel as desired (using the textures you specified). You do this for every object in your scene (that is not culled).

**To sum it up:**

For a single object in a basic OpenGL engine, you pass the IDs of its vertex data, textures and shader program to the GPU, which are just numbers. Then you pass all data needed by the shader program. This is mostly a bunch of floats for the transformations. Finally, you also tell the GPU how the data is connected for your current "draw call". There is also not much data transfer involved here, since you either have your data ordered in a specific way and need to tell the GPU just which method to use or you have uploaded a connectivity list upfront and tell the GPU the ID of the index list it should use.

Please note, that the described procedure is based on the approach that is described in most tutorials. Modern engines use several optimization techniques to balance CPU and GPU processing power so that they are always busy. This might require more involved data transfer. Also note, that the data transfer itself has bandwidth limitations that need to be considered.

> **Comments:**
> **username_0**: Thanks for a great answer. Do you have a link to an explanation of some different ways to specify connectivity?  
> **username_1**: You can check the API description of [`glDrawArrays`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawArrays.xhtml). It gives you a list of possible inputs like `GL_TRIANGLES` or `GL_TRIANGLE_STRIP`. However, it is not explained there how the data needs to be ordered and how the API uses it. Maybe you should read some simple tutorials like [this one](https://learnopengl.com/Getting-started/Hello-Triangle) and some of the following chapters. It should give you a good idea how the things that I described work. You don't need to code anything. Just read it. ;)  

---

### Answer by username_2 on 2021-08-10. Score: 1

The short answer to this question is: **everything**

On any give frame almost any kind of data my be needed to render that new and wonderful object that just popped into view. It's shader needs to be loaded and compiled, its textures, buffer data, specializations, push constants, if you can dream it up for a render call then it needs to find its way to the GPU on a per frame basis.

This is the reason GPU's have rich and diverse paths for loading data, along with dedicated hardware and code for handling all the red tape that goes along with it.

*What is its format*:
Again the answer to this question is: **everything** GPU's handle specialized data types that we don't see on the CPU while doing c/c++/whatever programming. Normalized 8 bit floating point values for example.

For technology demo's and simple scene's much of that data can be preloaded, but for any program that is going to do meaningful work, expect any kind of data to be loaded on a per frame basis.

Don't imagine *great big arrays*, imagine rich and diverse data. Tutorials will focus on the great big arrays, but they are just the tip of the iceberg.

Finally, don't image the CPU as driving everything. Thanks to compute shaders the GPU is taking more control of the action.

> **Comments:**
> **username_0**: I understood from the other answer that textures would be passed to the VRAM at the start rather than each frame. Are you saying they're passed each frame? Or just when a new texture is needed it's passed that frame?  
> **username_2**: Whenever possible the majority of textures are sent early on, but in a large program, the number and size of texture data will far surpass the available memory and texture data will need to be uploaded dynamically. (and textures that are no longer in needed will be removed or overwritten)  
> **username_1**: But you won't need to transfer that data every single frame. Loading and freeing data can usually be done less frequently, for example when hitting sector boundaries.  
> **username_2**: Now we are splitting hairs, keeping the hardware transfer units busy and avoiding bottlenecks is an interesting subject. One solution to long start up times is to load only the lower mip levels since they can be brought in exponentially faster, then continuing to load higher mip levels interactively will require a load every frame. This extends nicely to distance objects that get only the low mip levels loaded and higher mip levels are loaded only as the camera passes a certain distance from the object. Using this system textures are continually being loaded.  
> **username_2**: My answer was in support of the other answer here, with a slightly different take on the subject, the 40 thousand foot view so to speak.  
> **username_1**: Avoiding data transfer bottlenecks is indeed a valid point. I just haven't seen any engine where data uploading happens every frame, but I am no AAA game developer. Maybe it is really necessary for high-end production code. Anyways, good point.  
> **username_0**: What is 'mip level'?  
> **username_1**: @Joe Check [this link](https://en.wikipedia.org/wiki/Mipmap)  

---

