unity optimization tips, tricks and tools

50
Unity Optimization: Tips, Tricks, and Tools Kelly Gawne, Games Engineer September 2016

Upload: intel-software

Post on 09-Jan-2017

463 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Unity Optimization Tips, Tricks and Tools

Unity Optimization: Tips, Tricks, and ToolsKelly Gawne, Games EngineerSeptember 2016

Page 2: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice Intel Confidential 2

Agenda

• Intro• Optimization Thoughts• Profiling• Optimizations• Questions

Page 3: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 3

Optimization Ideology

• Don’t.• Don’t yet.• Profile and identify your largest bottleneck.• Test, address, test again.• Repeat as desired.

Page 4: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 4

Where is the bottleneck?

The Core Optimization Question:

Page 5: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 5

CPU Limitations• Draw Call Preparation• Scripting• Physics • Memory• Etc.

GPU Limitations• Memory bandwidth• Resolution• Shader or Geometric

Complexity• Lighting• Etc.

The Core Optimization Question: CPU or GPU?

Page 6: Unity Optimization Tips, Tricks and Tools

Profiling

Page 7: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 7

A Profiling Toolbox

Unity Profiler

Unity Render Stats Overlay Intel GPA System Analyzer

Intel GPA Frame Analyzer

Page 8: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 8

Unity Render Stats

Page 9: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 9

Unity Profiler

Page 10: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 10

Intel GPA System Analyzer

Page 11: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 11

Intel GPA Frame Analyzer

Page 12: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 12

Unity: Watch the profilerDecrease resolution. If framerate improves, GPU-bound

GPA:Use the experiments:• If turning on NULL HW

increases framerate, GPU-Bound

• If NULL HW doesn’t help but DISABLE DRAW CALLS does, driver-bound

• If neither help, CPU-bound

Where’s that bottleneck?

Page 13: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 13

CPU:Check the Unity Profiler: What’s so expensive?Is it a constant cost?Are there hitches or frametime spikes?

GPU:Is there a killer draw call?Are lots of little calls eating up frametime?Is everything rendered essential?

Where next?

Page 14: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 14

Profile, Optimize, Profile

Page 15: Unity Optimization Tips, Tricks and Tools

Optimization

Page 16: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 16

Scripting

Page 17: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 17

Script Frustum Culling Co-routines

Help, I Can’t Stop Update()ing

Page 18: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 18

Scripting Fades

Page 19: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 19

Scripting with Memory in Mind

Garbage Collection (GC)

Page 20: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 20

Object PoolingReuse objects in a pool instead of instantiating and destroying them.Great for: bullets, explosionsCatch 22:

Heap memory cost, could trigger GCSlower GCLong-lasting, large groups aren’t ideal

Garbage Collection Avoidance• Use structs instead of classes• Cache references to objects• Minimize runtime allocations

Scripting with Memory in Mind

Page 21: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 21

Physics

Page 22: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 22

Physics

• Use primitive colliders over mesh colliders

• Tweak fixed delta time• Don’t move static colliders• If it needs to move, add a rigidbody

and uncheck static

Page 23: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 23

Model Geometry

Page 24: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 24

Model Geometry

The number of vertices processed by the GPU is greater than the number of geometric vertices in the model.

Why? Vertices can be split for multiple normals/UV coordinates/etc

Two Good Modeling Rules:1. Don’t use more triangles than you need. 2. Reduce UV seams and hard edges when possible

Page 25: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 25

Model Geometry: LOD

• Switch out mesh based on objects distance from camera

• Customizable camera distances• Dramatic reduction in memory requirements by

frame

Page 26: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 26

Level of Detail (LOD)

Page 27: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 27

Model Geometry: Occlusion Culling

Page 28: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 28

Model Geometry: Occlusion Culling

Be sure to set occlusion areas, Unity defaults to using the whole scene

Page 29: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 29

Batching

Page 30: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 30

Batching

The number of vertices processed by the GPU is greater than the number of geometric vertices in the model.

Why? Vertices can be split for multiple normals/UV coordinates/etc

Two Good Modeling Rules:1. Don’t use more triangles than you need. 2. Reduce UV seams and hard edges when possible

Page 31: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 31

Static BatchingUnity automatically performsDoes not affect culling (unlike manual)No performance gain unless material is shared texture atlasCons: Memory overhead

Dynamic BatchingFor small meshes (<900 vertex attributes)Incurs per-vertex CPU overhead, only a win if the CPU vertex transform work < extra draw call expense.

Batching

Page 32: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 32

Textures and Shaders

Page 33: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 33

Textures

• Compress when possible

• Generate Mipmaps• UNLESS 2D game, UI element• 33% more memory per

texture

Page 34: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 34

Texture Atlasing

Combine multiple textures into oneTexture2D.PackTextures.

Why?•Reduce Material and Texture count•Reduce engine overhead on Material setup•Reduce engine overhead on Texture switch•Allow for more static batching

Page 35: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 35

Shaders

Built-ins aren’t built for your gameOnly compute what you need• Reduce complex math operations (e.g. pow, exp, log, cos, sin, tan).

Consider a lookup texture if applicable• Avoid writing your own versions of operations (e.g. normalize, dot,

inversesqrt) as the built-in's ensure the driver can optimize as much as possible.

• Float v. half v. fixed is largely ignored on desktop GPUs (everything is float on modern GPUs). Worry about it for mobile if you need it

Page 36: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 36

Lighting and Shadows

Page 37: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 37

Pros:Uses per-pixel, per-vertex and SHReal-time shadows and per-pixel effects

Cons:Can lead to many draws to same pixel

Lighting Path Quick Notes: Forward

Page 38: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 38

Pros:Lighting complexity unrelated to sceneTrade heavy lighting computation for memory

Lighting Path Quick Notes: Deferred

Cons:Semi-transparent not supported directlyNo anti-aliasingNo Receive Shadows flag support

Page 39: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 39

Lightmapping

Page 40: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 40

Lightmapping

Mark all static geometry.Place light probes to fill all dynamic object pathsBake

Page 41: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 41

HDR

If you’re using HDR effect like Bloom and Flare using deferred rendering, check HDR to reduce draw calls.

Each camera has an HDR checkbox

Page 42: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 42

ShadowsAvoid Realtime ShadowsSoft shadows have a greater GPU overheadUse cascaded shadow maps for directional lightsTweak your shadow settings:• Shadow Filtering: hard/soft• Shadow Resolution: Resolution of shadow map• Shadow Projection: Stable/Close fit• Shadow Cascades: 0, 2, 4• Shadow Distance: Max distance object’s shadow can project

Page 43: Unity Optimization Tips, Tricks and Tools

Final Thoughts

Page 44: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice 44

Final Thoughts

• Design with optimization in mind

• Know what you’re optimizing for• If there’s an issue, profile first.• Profile, optimize, profile.• Make fast, fantastic games.

Page 45: Unity Optimization Tips, Tricks and Tools

Questions?Kelly GawneIntel Games [email protected]

45

software.intel.com/gpahttps://github.com/GameTechDev/UnityPerformanceSandbox

Page 46: Unity Optimization Tips, Tricks and Tools
Page 47: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice Intel Confidential

Legal Disclaimer & Optimization NoticeINFORMATION IN THIS DOCUMENT IS PROVIDED “AS IS”. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO THIS INFORMATION INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products.

Copyright © 2014, Intel Corporation. All rights reserved. Intel, Pentium, Xeon, Xeon Phi, Core, VTune, Cilk, and the Intel logo are trademarks of Intel Corporation in the U.S. and other countries.

Optimization NoticeIntel’s compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #2011080447

Page 48: Unity Optimization Tips, Tricks and Tools

Backup

48

Page 49: Unity Optimization Tips, Tricks and Tools

Copyright © 2015, Intel Corporation. All rights reserved. *Other names and brands may be claimed as the property of others.

Optimization Notice Intel Confidential 49

Intel® GPA Release Notes

https://software.intel.com/en-us/articles/intel-gpa-release-notes

Page 50: Unity Optimization Tips, Tricks and Tools