Difference between revisions of "GPU Instancer Pro:BestPractices"

From GurBu Wiki
Jump to: navigation, search
(Replaced content with "About GPU Instance Pro | Getting Started | Terminology | GPU_Instancer_Pro:B...")
(Tag: Replaced)
Line 1: Line 1:
 
[[GPU_Instancer_Pro|About GPU Instance Pro]] | [[GPU_Instancer_Pro:GettingStarted|Getting Started]] | [[GPU_Instancer_Pro:Terminology|Terminology]] | [[GPU_Instancer_Pro:BestPractices|Best Practices]] | [[GPU_Instancer_Pro:APIDocumentation|API Documentation]] | [[GPU_Instancer_Pro:FAQ|F.A.Q.]]
 
[[GPU_Instancer_Pro|About GPU Instance Pro]] | [[GPU_Instancer_Pro:GettingStarted|Getting Started]] | [[GPU_Instancer_Pro:Terminology|Terminology]] | [[GPU_Instancer_Pro:BestPractices|Best Practices]] | [[GPU_Instancer_Pro:APIDocumentation|API Documentation]] | [[GPU_Instancer_Pro:FAQ|F.A.Q.]]
 +
 +
 +
GPU Instancer provides an out of the box solution for improving performance and it comes with a very easy to use interface to get started. Although GPUI internally makes use of quite complicated optimization techniques, it is designed to make it very easy to use these techniques in your project without going through their extensive learning curves (or development times). However, by following certain rules of thumb, you can use these techniques as intended and get the most out of GPUI.
 +
 +
 +
In this page, you will find best practices for using GPUI that will help you get better performance.
 +
 +
 +
__TOC__
 +
 +
 +
== Instance Counts ==
 +
 +
''The rule of thumb to follow here is to have only the prefabs that have high instance counts rendering with GPUI, while minimizing the amount of the defined GPUI prototypes on the managers as much as possible.''
 +
 +
[[File:GPUI-PrefabInstancing001.png|left|thumb|50k Asteroids in the PrefabInstancingDemo Scene]]
 +
 +
 +
When using the Prefab Manager in your scene, the best practice is to add the distinctively repeating prefabs in the scene to the manager as prototypes. For example, in the included '''AsteroidDemo''' scene, you can see that there are three asteroid prototypes. When the scene generates these asteroids around the planet, the resulting instance counts are around 16.5k for each. GPUI will draw each of these prototypes in a single draw call - however, since the asteroid prefabs are using LOD Groups on them with three LOD levels on each, the result is 9 draw calls (3 x 3) for all of these asteroids. Please note that the '''AsteroidHazeQuad''' prefab (which is basically a quad with a custom shader on it; it makes the scene look dynamic and foggy) is not added to the manager as a prototype. Thus, the idea is that the asteroids (with a lot more instance counts than the haze quads) will gain a lot more from instancing than the haze quads. Notice that the planet and the sun are also not defined as prototypes since there is only one of each in the scene and therefore they would not gain anything from instancing.
 +
 +
 +
Thus, using GPUI for prototypes with very low instance counts is not recommended. GPUI uses a single draw call for every mesh/material combination, and does all culling operations in the GPU. While these operations are very fast and cost efficient, it is unnecessary to use GPU resources if the instance counts are too low and the performance gain from instancing them will not be noticeable.
 +
 +
 +
Furthermore, since prefabs with low instance counts will not gain a noticeable performance boost from [[GPU_Instancer_Pro:Terminology#GPU_Instancing|GPU Instancing]], it is usually better to let Unity handle their rendering. Unity uses [https://docs.unity3d.com/Manual/DrawCallBatching.html draw call batching] techniques on the background (such as dynamic batching). These techniques depend on the CPU to run and tax their operations on the CPU memory. When there are many instances of the same prefabs, these operations turn out to be too costly and the reduction in batch counts dwarf in comparison to GPU Instancing. This is where GPUI shines the most. But where the instance counts are noticeably low, the cost on the CPU when using these techniques becomes trivial - yet they will still reduce batch counts and thus draw calls. While using GPU instancing, on the other hand, since meshes are not combined, every mesh/material combination will always be one draw call. Please also note that there is no magic number here to use as a minimum instance count since it depends so much on the poly-counts of the meshes, how they are distributed in the scene etc.
 +
 +
<div style="clear: both"></div>
 +
 +
 +
In short, [[GPU_Instancer:Terminology#GPU_Instancing|GPU Instancing]] will help you the most when there are many instances of the same prototype, and it is not recommended to add prototypes with low instance counts.

Revision as of 02:59, 11 April 2024

About GPU Instance Pro | Getting Started | Terminology | Best Practices | API Documentation | F.A.Q.


GPU Instancer provides an out of the box solution for improving performance and it comes with a very easy to use interface to get started. Although GPUI internally makes use of quite complicated optimization techniques, it is designed to make it very easy to use these techniques in your project without going through their extensive learning curves (or development times). However, by following certain rules of thumb, you can use these techniques as intended and get the most out of GPUI.


In this page, you will find best practices for using GPUI that will help you get better performance.



Instance Counts

The rule of thumb to follow here is to have only the prefabs that have high instance counts rendering with GPUI, while minimizing the amount of the defined GPUI prototypes on the managers as much as possible.

50k Asteroids in the PrefabInstancingDemo Scene


When using the Prefab Manager in your scene, the best practice is to add the distinctively repeating prefabs in the scene to the manager as prototypes. For example, in the included AsteroidDemo scene, you can see that there are three asteroid prototypes. When the scene generates these asteroids around the planet, the resulting instance counts are around 16.5k for each. GPUI will draw each of these prototypes in a single draw call - however, since the asteroid prefabs are using LOD Groups on them with three LOD levels on each, the result is 9 draw calls (3 x 3) for all of these asteroids. Please note that the AsteroidHazeQuad prefab (which is basically a quad with a custom shader on it; it makes the scene look dynamic and foggy) is not added to the manager as a prototype. Thus, the idea is that the asteroids (with a lot more instance counts than the haze quads) will gain a lot more from instancing than the haze quads. Notice that the planet and the sun are also not defined as prototypes since there is only one of each in the scene and therefore they would not gain anything from instancing.


Thus, using GPUI for prototypes with very low instance counts is not recommended. GPUI uses a single draw call for every mesh/material combination, and does all culling operations in the GPU. While these operations are very fast and cost efficient, it is unnecessary to use GPU resources if the instance counts are too low and the performance gain from instancing them will not be noticeable.


Furthermore, since prefabs with low instance counts will not gain a noticeable performance boost from GPU Instancing, it is usually better to let Unity handle their rendering. Unity uses draw call batching techniques on the background (such as dynamic batching). These techniques depend on the CPU to run and tax their operations on the CPU memory. When there are many instances of the same prefabs, these operations turn out to be too costly and the reduction in batch counts dwarf in comparison to GPU Instancing. This is where GPUI shines the most. But where the instance counts are noticeably low, the cost on the CPU when using these techniques becomes trivial - yet they will still reduce batch counts and thus draw calls. While using GPU instancing, on the other hand, since meshes are not combined, every mesh/material combination will always be one draw call. Please also note that there is no magic number here to use as a minimum instance count since it depends so much on the poly-counts of the meshes, how they are distributed in the scene etc.


In short, GPU Instancing will help you the most when there are many instances of the same prototype, and it is not recommended to add prototypes with low instance counts.