41
UNREAL ENGINE - OPTIMIZATION UNREAL ENGINE - OPTIMIZATION Adam Frańczak Adam Frańczak Playsoft Playsoft [email protected] [email protected]

infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

  • View
    315

  • Download
    5

Embed Size (px)

DESCRIPTION

Adam Frańczak / Playsoft Techniki optymalizacyjne w UDK/UE3. Prezentacja z konferencji infoShare 2013 w Gdańsku. Presented at infoShare 2013 conference in Gdańsk, Poland.

Citation preview

Page 1: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

UNREAL ENGINE - OPTIMIZATIONUNREAL ENGINE - OPTIMIZATION

Adam FrańczakAdam FrańczakPlaysoftPlaysoft

[email protected]@playsoft.fr

Page 2: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OVERVIEWOVERVIEW

● About UEAbout UE● Application examplesApplication examples● OptimizationOptimization● Tools for optimization in UE3 Tools for optimization in UE3 ● OptimizationOptimization in UE3 in UE3● OptimizationOptimization: : examplesexamples

Page 3: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINE● Developer – Epic GamesDeveloper – Epic Games

● First version – 1998First version – 1998

● Operating system – cross-platformOperating system – cross-platform

● Stable release – February/2013 Unreal Engine3Stable release – February/2013 Unreal Engine3

● Unreal Engine 4 ? - Unreal Engine 4 ? - stillstill in in progressprogress

Page 4: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINEEditor:

Page 5: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINEUnreal Script example:Unreal Script example:

var FastBallFinish m_FastBallFinish;var FastBallFinish m_FastBallFinish;

event PreBeginPlay(){event PreBeginPlay(){

super.PreBeginPlay();super.PreBeginPlay();

ConsoleCommand("stat fps");ConsoleCommand("stat fps");

SetPlayerTimer(); SetPlayerTimer();

}}

auto state PrepRound{auto state PrepRound{

function BeginState(Name function BeginState(Name PreviousStateName) {PreviousStateName) {

}}

Begin:Begin:

CheckStartRound();CheckStartRound();

}}

Kismet exampleKismet example:

Page 6: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINE

UE3 has support for many UE3 has support for many platformsplatforms likelike:

Page 7: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINEmobile and PC examplesmobile and PC examples

Page 8: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

ABOUT UNREAL ENGINEABOUT UNREAL ENGINEgames and applicationsgames and applications

Page 9: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OPTIMIZATIONOPTIMIZATION

Page 10: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OPTIMIZATIONOPTIMIZATION

Optimization - is the process of modifying a software system to make Optimization - is the process of modifying a software system to make some aspect of it work more efficiently or to use less resources.some aspect of it work more efficiently or to use less resources.

Levels of optimization:Levels of optimization:

● DesignDesign

● Source CodeSource Code

● CompileCompile

● AssemblyAssembly

● Run timeRun time

Page 11: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OPTIMIZATION IN UEOPTIMIZATION IN UE

„„UE3 has a large number of tools and techniques to help you win the UE3 has a large number of tools and techniques to help you win the battle with an optimization!”battle with an optimization!”

● STATS COMMANDSTATS COMMAND

● GAME PROFILERGAME PROFILER

● MEMLEAK-CHECKMEMLEAK-CHECK

● SHADER ANALIZERSHADER ANALIZER

and and moremore

Page 12: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

STAT COMMANDSSTAT COMMANDSSTATSTAT COMMANDS in Unreal Engine 3 provides the ability to view a lot COMMANDS in Unreal Engine 3 provides the ability to view a lot of statistics about various aspects of the game and engine.of statistics about various aspects of the game and engine.

Most Most importantimportant STAT COMMANDS: STAT COMMANDS:

●STAT FPS – just FPSSTAT FPS – just FPS●STAT UNIT – show information about time spent for the current STAT UNIT – show information about time spent for the current frame on the CPU, the time spent in the game thread and time spent frame on the CPU, the time spent in the game thread and time spent in the render threadin the render thread●STAT MEMORY – display information about memorySTAT MEMORY – display information about memory●STAT ENGINESTAT ENGINE●STAT GAME - STAT GAME - ●STAT OBJECT – show information about object creation and STAT OBJECT – show information about object creation and destructiondestruction

Page 13: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

STAT COMMANDS (screens)STAT COMMANDS (screens)

Page 14: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMLEAKCHECKMEMLEAKCHECKHelp to understand where and when memory is being used in our Help to understand where and when memory is being used in our game.game.

Output Sections:Output Sections:

● headerheader

● class listclass list

● specific object listspecific object list

● platform memoryplatform memory

● game specific memorygame specific memory

● rendering memoryrendering memory

● package memorypackage memory

● assets listassets list

● actor listactor list

● level listlevel list

Page 15: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMLEAKCHECKMEMLEAKCHECKProvides to use and understand where and when memory is being use Provides to use and understand where and when memory is being use in our game.in our game.

Output Sections:Output Sections:

● headerheader

● class listclass list

● specific object listspecific object list

● platform memoryplatform memory

● game specific memorygame specific memory

● rendering memoryrendering memory

● package memorypackage memory

● assets listassets list

● actor listactor list

● level listlevel list

Page 16: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMLEAKCHECK (screens)MEMLEAKCHECK (screens)

Page 17: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

GAMEPLAYPROFILERGAMEPLAYPROFILER

The gameplay profiler is a tool that makes use of data captured during The gameplay profiler is a tool that makes use of data captured during profiling sessions and it allows you to dig deeper into gameplay code profiling sessions and it allows you to dig deeper into gameplay code to analyze time spent on performing functionsto analyze time spent on performing functions.

Page 18: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

GAMEPLAYPROFILERGAMEPLAYPROFILER

Page 19: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OTHER TOOLSOTHER TOOLSLightMap densityLightMap density

Page 20: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OTHER TOOLSOTHER TOOLSShader complexityShader complexity

Page 21: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

OTHER TOOLSOTHER TOOLSTexture densityTexture density

Page 22: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

GENERAL RULESGENERAL RULES

● Identify your budget (for assets , textures, sound etc.)Identify your budget (for assets , textures, sound etc.)

● Instill the mindset of making certain that people are using the Instill the mindset of making certain that people are using the minimal amount of data / cpu cycles to create what they wantminimal amount of data / cpu cycles to create what they want

● Remember that the game has to run within the constraints of the Remember that the game has to run within the constraints of the target platforms – this process requires constant monitoringtarget platforms – this process requires constant monitoring.

Page 23: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

RULESRULES

● Identify slow but low visual impact cases Identify slow but low visual impact cases

● Ideally find enough potential optimizations that if they were all Ideally find enough potential optimizations that if they were all implemented, the scene would be < 33ms implemented, the scene would be < 33ms

● Use detailed draw event information to quickly identify what each Use detailed draw event information to quickly identify what each draw call is in the editor draw call is in the editor

● Record Actor name, Resource name (static mesh, particle emitter, Record Actor name, Resource name (static mesh, particle emitter, etc), Material nameetc), Material name

Page 24: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

RULESRULES

● Provide LD's with suggestions on what to change, with clear Provide LD's with suggestions on what to change, with clear directions and screenshotsdirections and screenshots

● LD's and artists decide which optimizations are worth while, make LD's and artists decide which optimizations are worth while, make content changes content changes

● This ensures that art is responsible for quality decisionsThis ensures that art is responsible for quality decisions

● Repeat steps 1-3 if needed.Repeat steps 1-3 if needed.

Page 25: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

DRAW CALLSDRAW CALLS

Number of draw call is very important. Each material is a separate Number of draw call is very important. Each material is a separate draw call, so if you have 1 mesh with 4 materials, it is 4 draw calls.draw call, so if you have 1 mesh with 4 materials, it is 4 draw calls.

Remember: Remember: keep draw calls downkeep draw calls down

● Combine meshes that use the same texture and shaderCombine meshes that use the same texture and shader

● Aggressive cullingAggressive culling

Page 26: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

DRAW CALLSDRAW CALLS

Page 27: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

TEXTURESTEXTURES

The first thing to look at is the "Over Budget" value in STAT The first thing to look at is the "Over Budget" value in STAT STREAMING. If it's „0” you're ok. If it's non-zero, you're using more STREAMING. If it's „0” you're ok. If it's non-zero, you're using more textures than can fit in the texture pool and you should reduce textures than can fit in the texture pool and you should reduce memory usage and/or increase the texture pool size.memory usage and/or increase the texture pool size.

Use only square and require power of two for mobile devices.Use only square and require power of two for mobile devices.

If it is possible just turn off alpha channelIf it is possible just turn off alpha channel

Page 28: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

TEXTURESTEXTURESTextures Groups: groups of textures which are handled specially.Textures Groups: groups of textures which are handled specially.

● TEXTUREGROUP_SkyboxTEXTUREGROUP_Skybox (textures are always fully streamed in, (textures are always fully streamed in, they're automatically marked Forced).they're automatically marked Forced).

● TEXTUREGROUP_UI (TEXTUREGROUP_UI (textures have all their mip-levels removed textures have all their mip-levels removed during cooking)during cooking)

● TEXTUREGROUP_Lightmapse (TEXTUREGROUP_Lightmapse (extra boost factors from .ini extra boost factors from .ini settings)settings)

● TEXTUREGROUP_ShadowmapTEXTUREGROUP_Shadowmap

● TEXTUREGROUP_CharacterTEXTUREGROUP_Character (groups has a slight preference in (groups has a slight preference in that they can be the first ones to stream in when loading a map that they can be the first ones to stream in when loading a map and will be the last textures to stream out in a panic stream out)and will be the last textures to stream out in a panic stream out)

Page 29: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMORYMEMORY

Memory usage is always a concern for video games, especially those Memory usage is always a concern for video games, especially those destined for consoles or mobile devices where memory is limited. This destined for consoles or mobile devices where memory is limited. This extends from the amount of space taken up by content assets on disk extends from the amount of space taken up by content assets on disk to memory usage of different systems during runtime. These are all to memory usage of different systems during runtime. These are all extremely important pieces of information that make it possible to extremely important pieces of information that make it possible to constrain memory usage within acceptable limitsconstrain memory usage within acceptable limits.

Page 30: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMORYMEMORY

Important rules:Important rules:

● Budget: Decide what to use memory on. Budget: Decide what to use memory on.

● Make sure all assets are optimal and don't have unnecessary Make sure all assets are optimal and don't have unnecessary references. references.

● Make sure you have enough buffer (for fragmentation) to keep Make sure you have enough buffer (for fragmentation) to keep your game runningyour game running

Page 31: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

MEMORYMEMORY

Possibilities include:Possibilities include:

● The level that has too many Static MeshesThe level that has too many Static Meshes

● AI that create too many projectiles and particlesAI that create too many projectiles and particles

● Code that allocates too much memoryCode that allocates too much memory

Page 32: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

SPAWN VS POOLING OBJECTSSPAWN VS POOLING OBJECTS

Using object pooling for ephemeral objects is faster than creating and Using object pooling for ephemeral objects is faster than creating and destroying them.destroying them.

However: However: if you keep allocating memory on top of the pools you just if you keep allocating memory on top of the pools you just created, you might trigger garbage collection even more oftencreated, you might trigger garbage collection even more often

Remember: performance will suffer if you allocate pools that are too Remember: performance will suffer if you allocate pools that are too large or keep them active when the objects they contain will not be large or keep them active when the objects they contain will not be needed for some timeneeded for some time

Page 33: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICE

Use the kismet and sequences if it is possible:Use the kismet and sequences if it is possible:

● Fast and easy toggle on or toggle off all objectsFast and easy toggle on or toggle off all objects

● Precisely run scriptsPrecisely run scripts

● Precisely run movies/cinematicsPrecisely run movies/cinematics

● Acces to matineAcces to matine

● Level streamingLevel streaming

Page 34: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICE

ExampleExample::

Page 35: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICE

Page 36: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICE

● Native functionality instead of UnrealScript codeNative functionality instead of UnrealScript code

● Execute code only as often as neededExecute code only as often as needed

● Find bottlenecks by measuring execution timeFind bottlenecks by measuring execution time

function MyFunction() {function MyFunction() {

local float ExecutionTime;local float ExecutionTime;

Clock(ExecutionTime);Clock(ExecutionTime);

UnClock(ExecutionTime); UnClock(ExecutionTime);

Log("Time spent executing something:" @ ExecutionTime @ "ms"); Log("Time spent executing something:" @ ExecutionTime @ "ms");

}}

Page 37: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICESpeed comparison of loops: (different loops have different Speed comparison of loops: (different loops have different overhead times)overhead times)

while( i!=n ){while( i!=n ){

stuff[i++] = vect(1,0,0)*FRand() + vect(0,1,0)*FRand() + vect(0,0,1)*FRand();stuff[i++] = vect(1,0,0)*FRand() + vect(0,1,0)*FRand() + vect(0,0,1)*FRand();

} // } // While loop takes 0.93 time unit While loop takes 0.93 time unit

if( n!=0 ){if( n!=0 ){

do{do{

stuff[i++] = vect(1,0,0)*FRand() + vect(0,1,0)*FRand() + vect(0,0,1)*FRand();stuff[i++] = vect(1,0,0)*FRand() + vect(0,1,0)*FRand() + vect(0,0,1)*FRand();

}until( i==n )}until( i==n )

} //} //Until loop takes 0.90 time unitUntil loop takes 0.90 time unit

Page 38: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICEDisable engine events when you don't need themDisable engine events when you don't need them

event PostBeginPlay{event PostBeginPlay{

// all events are enabled by default, so disable Tick event to start with // all events are enabled by default, so disable Tick event to start with

Disable('Tick'); Disable('Tick');

} }

event Trigger(Actor Sender, Pawn Instigator){ event Trigger(Actor Sender, Pawn Instigator){

// tell engine to call Tick event from now on // tell engine to call Tick event from now on

Enable('Tick'); Enable('Tick');

} }

event Tick(float DeltaTime) { event Tick(float DeltaTime) {

// do something -- executed only after the actor has been triggered// do something -- executed only after the actor has been triggered

}}

Page 39: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

GOOD IDEASGOOD IDEAS

Remember:Remember:

● particle systems are not cheap particle systems are not cheap

- automated flipbook texture creation from expensive animated - automated flipbook texture creation from expensive animated materialsmaterials

● Considerations for different devicesConsiderations for different devices

- screen resolution vs memory- screen resolution vs memory

- per-pixel rendering performance- per-pixel rendering performance

Page 40: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

CODE – GOOD PRACTICECODE – GOOD PRACTICE

and remember at the end and remember at the end REFINE YOUR ALGORITHMS.REFINE YOUR ALGORITHMS.

Page 41: infoShare 2013: Adam Frańczak - Techniki optymalizacyjne w UDK/ UE3

THANK YOUTHANK YOU

[email protected]

udkdev.net