practical game- programming. stefan reinaltersproing interactive media gmbh 2 / 32 overview consoles...
Post on 28-Dec-2015
222 Views
Preview:
TRANSCRIPT
Practical game-Practical game-programmingprogramming
2 / 32Stefan Reinalter Sproing Interactive Media GmbH
OverviewOverviewConsoles in generalConsoles in generalPC/Console differencePC/Console differenceDevelopment environmentsDevelopment environmentsMemory managementMemory managementMemory fragmentationMemory fragmentationMultiplatform developmentMultiplatform developmentOptimizationOptimizationTRC/LOT-GuidelinesTRC/LOT-Guidelines
3 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general XBoxXBox
CPU:CPU: 733 MHz chip (Pentium III 733 MHz chip (Pentium III Coppermine-based); 32 KB L1 cache, 128 Coppermine-based); 32 KB L1 cache, 128 KB on-die L2 cacheKB on-die L2 cache
GPU:GPU: 233MHz custom chip (similar to 233MHz custom chip (similar to NVidia Geforce 3)NVidia Geforce 3)
Memory:Memory: 64 MB (shared memory) 64 MB (shared memory)I/0:I/0: 4x DVD, 10GB hard disk 4x DVD, 10GB hard disk
4 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general PlayStation 2PlayStation 2
CPU:CPU: 128-bit „Emotion Engine“ clocked at 294 128-bit „Emotion Engine“ clocked at 294 MHzMHz
Vector Units VU0 and VU1Vector Units VU0 and VU1 16 KB Instruction cache, 8 KB Data cache, 16 16 KB Instruction cache, 8 KB Data cache, 16
KB ScratchpadKB Scratchpad GraphicsGraphics: "Graphics Synthesizer" : "Graphics Synthesizer"
clocked at 147 MHz clocked at 147 MHz I/O Processor, SPU2, IPUI/O Processor, SPU2, IPU Memory:Memory: 32 MB 32 MB VRAMVRAM: 4 MB (framebuffer, z-buffer, : 4 MB (framebuffer, z-buffer,
textures)textures) I/0:I/0: 4x DVD, no hard disk 4x DVD, no hard disk
5 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general Nintendo DSNintendo DS
CPU:CPU: Main ARM946E-S (67 MHz); Sub: Main ARM946E-S (67 MHz); Sub: ARM7TDMI (33 MHz) ARM7TDMI (33 MHz)
Graphics 2D: Graphics 2D: BG: 4 Background-Layer per BG: 4 Background-Layer per Display, OBJ: max. 128 Sprites Display, OBJ: max. 128 Sprites
Graphics 3D: Graphics 3D: max. 120.000 max. 120.000 polygons/secondpolygons/second
Memory:Memory: 4 MB 4 MB VRAMVRAM: depends on which : depends on which
mode is usedmode is usedI/0:I/0: cartridge, size varies cartridge, size varies
6 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general WiiWii
CPU:CPU: PowerPC-based „Broadway“ PowerPC-based „Broadway“GraphicsGraphics: ATI „Hollywood“: ATI „Hollywood“Memory:Memory: 24 MB „internal“ 1T-SRAM, 64 24 MB „internal“ 1T-SRAM, 64
MB „external“ GDDR3 SDRAMMB „external“ GDDR3 SDRAMVRAMVRAM: can use internal and external, but : can use internal and external, but
speed variesspeed variesI/0:I/0: double-layer DVD double-layer DVD
7 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general XBox 360XBox 360
CPU:CPU: Triple-core PowerPC-based IBM Triple-core PowerPC-based IBM XenonXenon
GraphicsGraphics: ATI Xenos: ATI XenosMemory:Memory: 512 MB (unified memory) 512 MB (unified memory)VRAMVRAM: „10 MB eDRAM“: „10 MB eDRAM“I/0:I/0: 12x DVD, hard disk 12x DVD, hard disk
optionaloptional
8 / 32Stefan Reinalter Sproing Interactive Media GmbH
Consoles in generalConsoles in general PlayStation 3PlayStation 3
CPU:CPU: Cell CellGraphicsGraphics: NVidia RSX (based on G70): NVidia RSX (based on G70)Memory:Memory: 256 MB 256 MBVRAMVRAM: 256 MB: 256 MBI/0:I/0: 2x Blu-ray, hard disk 2x Blu-ray, hard disk
9 / 32Stefan Reinalter Sproing Interactive Media GmbH
PC/Console differencePC/Console difference CPU/GPU/cache sizes differCPU/GPU/cache sizes differ
Know your hardware, use it efficientlyKnow your hardware, use it efficiently Memory size differs greatlyMemory size differs greatly
Data, assets, and code size; everything Data, assets, and code size; everything plays a roleplays a role
Amount of memory is carved out of stone; Amount of memory is carved out of stone; there is no virtual memorythere is no virtual memory
OS/SDK often needs a lot of precious OS/SDK often needs a lot of precious memorymemory
VRAM size differs greatlyVRAM size differs greatlyNew strategies needed, exploit hardwareNew strategies needed, exploit hardwareAssets must cope with that as wellAssets must cope with that as well
10 / 32Stefan Reinalter Sproing Interactive Media GmbH
PC/Console differencePC/Console difference Multithreaded/parallel programming essential Multithreaded/parallel programming essential
for PS2/XBox360/PS3for PS2/XBox360/PS3EE, VU0, VU1, GS, IOP, IPU perform EE, VU0, VU1, GS, IOP, IPU perform
„independently“ on PS2, DMA acts as link„independently“ on PS2, DMA acts as linkEntirely new algorithms needed for PS3 Entirely new algorithms needed for PS3
(concept of „SPU Shaders“)(concept of „SPU Shaders“)still not mainstream in PC developmentstill not mainstream in PC development
Seek-times and bandwidths differ Seek-times and bandwidths differ Hard disk on PC, DVD on consolesHard disk on PC, DVD on consolesCartridges on handhelds (Nintendo DS)Cartridges on handhelds (Nintendo DS)
No seek timesNo seek times
11 / 32Stefan Reinalter Sproing Interactive Media GmbH
PC/Console differencePC/Console difference Some algorithms simply won‘t work out-of-the-Some algorithms simply won‘t work out-of-the-
boxbox(Predicated) Tiled Rendering on XBox360 -> (Predicated) Tiled Rendering on XBox360 ->
Framebuffer doesn‘t fit into eDRAMFramebuffer doesn‘t fit into eDRAM Render in tilesRender in tiles Vertex shaders get executed for every tile -> Vertex shaders get executed for every tile ->
Problems with memexport!Problems with memexport!Many different strategies for known problemsMany different strategies for known problems
E.g. there are more than 7 ways to skin a characterE.g. there are more than 7 ways to skin a characterMoving stuff traditionally done on the GPU to Moving stuff traditionally done on the GPU to
the CPU/SPU (backface culling, PP effects)the CPU/SPU (backface culling, PP effects)
12 / 32Stefan Reinalter Sproing Interactive Media GmbH
Development environmentsDevelopment environments Dev-kitsDev-kits
Most of them have more memory than the Most of them have more memory than the real systemreal system Can be used for development/prototypingCan be used for development/prototyping
Provide DVD emulationProvide DVD emulation Don’t have to burn a CD/DVD everytimeDon’t have to burn a CD/DVD everytime
May provide LAN connection for e.g. real-May provide LAN connection for e.g. real-time editing or sharing amongst team-time editing or sharing amongst team-membersmembers
May have hardware bugsMay have hardware bugsMay contain extra-hardware (e.g. Profiler)May contain extra-hardware (e.g. Profiler)Cost more than the real systemCost more than the real system
13 / 32Stefan Reinalter Sproing Interactive Media GmbH
Development environmentsDevelopment environments Different compilersDifferent compilers
Mostly a specific GCC is used on consolesMostly a specific GCC is used on consolesFirst revisions may not at all be bug-freeFirst revisions may not at all be bug-free
Helps to understand assembly code to see what Helps to understand assembly code to see what the compiler doesthe compiler does
Different compiler feature-setsDifferent compiler feature-setsMay not compile hardcore C++ features at May not compile hardcore C++ features at
allallMay have problems with some features, May have problems with some features,
e.g. templatese.g. templatesWork with different warning-levels, Work with different warning-levels,
complaining about different thingscomplaining about different things
14 / 32Stefan Reinalter Sproing Interactive Media GmbH
Development environmentsDevelopment environments SN SystemsSN Systems
Provides Windows development tools for Provides Windows development tools for consoles (PS2, PSP, GC, DS, PS3)consoles (PS2, PSP, GC, DS, PS3)
ProDGProDG CompilerCompiler MS Visual Studio integrationMS Visual Studio integration DebuggerDebugger
PS2/GC compiler based on older GCC PS2/GC compiler based on older GCC (2.95.5)(2.95.5)
DS compiler is a complete rewriteDS compiler is a complete rewriteAdditional console-specific features (e.g. Additional console-specific features (e.g.
vector unit code for PS2, 128bit datatypes)vector unit code for PS2, 128bit datatypes)
15 / 32Stefan Reinalter Sproing Interactive Media GmbH
Development environmentsDevelopment environments Console toolsConsole tools
Statistical profilerStatistical profilerDebuggerDebuggerConsole I/OConsole I/OGFX profiler (PIX, Shader debugger, etc.)GFX profiler (PIX, Shader debugger, etc.)PS2 Performance analyzer: captures the PS2 Performance analyzer: captures the
complete console status (DMA, GS, etc.)complete console status (DMA, GS, etc.) Provides insight into inner workings, Provides insight into inner workings,
produces produces a lota lot of data of data Needs experienced people only to Needs experienced people only to
understand the dataunderstand the data
16 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management Crucial in console developmentCrucial in console development
Remember: no virtual memory!Remember: no virtual memory!Xbox has MMU for “virtual memory”, can’t Xbox has MMU for “virtual memory”, can’t
swap howeverswap howeverGameCube has “virtual memory”, actually GameCube has “virtual memory”, actually
swaps into Sound-RAMswaps into Sound-RAMMain missing part is still a harddiskMain missing part is still a harddisk
17 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management Avoid allocations every frameAvoid allocations every frame
Shouldn‘t do that on the PC either, reallyShouldn‘t do that on the PC either, really Avoid small allocations, prefer large ones Avoid small allocations, prefer large ones
insteadinsteadHelps with fragmentation as wellHelps with fragmentation as wellUse own allocation scheme for small Use own allocation scheme for small
allocations you can‘t get rid of (e.g. STL, allocations you can‘t get rid of (e.g. STL, Strings)Strings)
Small allocationsSmall allocationsUse group allocationsUse group allocationsUse freelistsUse freelistsUse memory poolsUse memory pools
18 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management STL usageSTL usage
Choose the right tool for the jobChoose the right tool for the jobTry to reserve memory in advance, e.g. Try to reserve memory in advance, e.g.
myVector.reserve(1000);myVector.reserve(1000); Is/can be used on consoles, although some Is/can be used on consoles, although some
people/studios roll their own containerspeople/studios roll their own containers Don‘t do this before profiling!Don‘t do this before profiling!
Use hash tables if possibleUse hash tables if possible
19 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management STL usageSTL usage
Choose the right tool for the jobChoose the right tool for the jobTry to reserve memory in advance, e.g. Try to reserve memory in advance, e.g.
myVector.reserve(1000);myVector.reserve(1000); Is/can be used on consoles, although some Is/can be used on consoles, although some
people/studios roll their own containerspeople/studios roll their own containers Don‘t do this before profiling!Don‘t do this before profiling!
Use hash tables if possibleUse hash tables if possiblePROFILE!
20 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management You can never have enough memoryYou can never have enough memory
Try to reduce memory consumption at the Try to reduce memory consumption at the algorithmic level, rather than brute-force algorithmic level, rather than brute-force optimizationoptimization
Code size can get in your way too, make Code size can get in your way too, make sure to study the compiler settingssure to study the compiler settings
Write your own memory dumpWrite your own memory dumpMake use of map filesMake use of map filesDon‘t store what you won‘t needDon‘t store what you won‘t needUse member/method reordering as a last Use member/method reordering as a last
resort!resort!
21 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory managementMemory management You can never have enough memoryYou can never have enough memory
Try to reduce memory consumption at the Try to reduce memory consumption at the algorithmic level, rather than brute-force algorithmic level, rather than brute-force optimizationoptimization
Code size can get in your way too, make Code size can get in your way too, make sure to study the compiler settingssure to study the compiler settings
Write your own memory dumpWrite your own memory dumpMake use of map filesMake use of map filesDon‘t store what you won‘t needDon‘t store what you won‘t needUse member/method reordering as a last Use member/method reordering as a last
resort!resort!
PROFILE!
22 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory fragmentationMemory fragmentation What is it?What is it?
Memory gets fragmented during run-timeMemory gets fragmented during run-timeE.g. A,B,C get allocated; A,C get freed; E.g. A,B,C get allocated; A,C get freed;
B leaves a gap (Bad Idea™) B leaves a gap (Bad Idea™)Not something PC developers worry aboutNot something PC developers worry about
How does it emerge?How does it emerge?Due to allocation/deallocation during run-Due to allocation/deallocation during run-
timetimeDepends on order of allocations, can’t be Depends on order of allocations, can’t be
eliminated completely (only under specific eliminated completely (only under specific circumstances)circumstances)
23 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory fragmentationMemory fragmentation Why is it bad?Why is it bad?
Longer playtime means less memoryLonger playtime means less memory Not really less memory, but the largest Not really less memory, but the largest
available block gets smalleravailable block gets smallerLess memory suddenly becomes no Less memory suddenly becomes no
memorymemory Largest available block might not be big enough Largest available block might not be big enough
anymore anymore No memory becomes (random) game crashNo memory becomes (random) game crash
But the memory But the memory wouldwould be there be thereRandom crashes can be Random crashes can be extremelyextremely
difficult to finddifficult to find
24 / 32Stefan Reinalter Sproing Interactive Media GmbH
Memory fragmentationMemory fragmentation What to do against it?What to do against it?
Use memory poolsUse memory poolsUse own allocation schemesUse own allocation schemesAvoid small allocationsAvoid small allocationsWrite your own heap implementation Write your own heap implementation
(different pools for small allocations, (different pools for small allocations, coalescing/defragmenting heap for other coalescing/defragmenting heap for other allocations)allocations)
Last resort: Use memory images (your Last resort: Use memory images (your team will end up in a sea of fire for that…)team will end up in a sea of fire for that…)
Be clever! Be clever! Rearrangement of allocations can be a life Rearrangement of allocations can be a life
saversaver
25 / 32Stefan Reinalter Sproing Interactive Media GmbH
Multiplatform developmentMultiplatform development Different APIs for developmentDifferent APIs for development
DirectX on XboxDirectX on XboxMore “down to the metal” on PS2More “down to the metal” on PS2Library routines provided by Microsoft, Library routines provided by Microsoft,
Sony, NintendoSony, NintendoOwn large codebase for file-I/O, input-Own large codebase for file-I/O, input-
devices, memory tracking, etc.devices, memory tracking, etc. Different CPUs and GPUsDifferent CPUs and GPUs
Capabilities differ, one platform might have Capabilities differ, one platform might have more features than the othermore features than the other
One platform might outperform the other One platform might outperform the other (CPU- or GPU-wise)(CPU- or GPU-wise)
26 / 32Stefan Reinalter Sproing Interactive Media GmbH
Multiplatform developmentMultiplatform development Platform-specific featuresPlatform-specific features
Use them, but stay multiplatform Use them, but stay multiplatform (especially in high-level code)(especially in high-level code)
Up to 10 different buildsUp to 10 different buildsHard to make sure that a build doesn’t Hard to make sure that a build doesn’t
break when there just isn’t time for break when there just isn’t time for rebuilding all of themrebuilding all of them
This is where an automated build system This is where an automated build system comes in handycomes in handy
Input devices differInput devices differMouse and keyboard vs. Wii-MoteMouse and keyboard vs. Wii-Mote
27 / 32Stefan Reinalter Sproing Interactive Media GmbH
Multiplatform developmentMultiplatform development Output devices differOutput devices differ
High-resolution monitor vs. Pal-TVHigh-resolution monitor vs. Pal-TVUser-defined Hz vs. PAL/NTSC 50/60hzUser-defined Hz vs. PAL/NTSC 50/60hzColors are different on PAL and NTSC Colors are different on PAL and NTSC
systemssystems Requires different assetsRequires different assets
Remember the 4 MB VRam on the PS2?Remember the 4 MB VRam on the PS2? Might be hard to fit XBox/PC-textures in thereMight be hard to fit XBox/PC-textures in there
Assets might be graphics, sounds, as well Assets might be graphics, sounds, as well as codeas code
Requirements/guidelines differ (more on that Requirements/guidelines differ (more on that later)later)
28 / 32Stefan Reinalter Sproing Interactive Media GmbH
OptimizationOptimization Most important rule:Most important rule:
Don’t optimize without prior profiling!Don’t optimize without prior profiling! No need to optimize your math-library when it’s No need to optimize your math-library when it’s
not going to be the bottleneck anywaynot going to be the bottleneck anyway Optimization requires finding a bottleneckOptimization requires finding a bottleneck
Improving 20% of the code is responsible Improving 20% of the code is responsible for 80% of the results (80/20 law, Pareto for 80% of the results (80/20 law, Pareto principle)principle)
90% of the execution time is spent 90% of the execution time is spent executing 10% of the code (90/10 law)executing 10% of the code (90/10 law)
29 / 32Stefan Reinalter Sproing Interactive Media GmbH
OptimizationOptimization Most important rule:Most important rule:
Don’t optimize without prior profiling!Don’t optimize without prior profiling! No need to optimize your math-library when it’s No need to optimize your math-library when it’s
not going to be the bottleneck anywaynot going to be the bottleneck anyway Optimization requires finding a bottleneckOptimization requires finding a bottleneck
Improving 20% of the code is responsible Improving 20% of the code is responsible for 80% of the results (80/20 law, Pareto for 80% of the results (80/20 law, Pareto principle)principle)
90% of the execution time is spent 90% of the execution time is spent executing 10% of the code (90/10 law)executing 10% of the code (90/10 law)
You know
what…
30 / 32Stefan Reinalter Sproing Interactive Media GmbH
OptimizationOptimization Only optimize when really necessaryOnly optimize when really necessary
Try to optimize at the algorithmic level firstTry to optimize at the algorithmic level first O(n) will almost always outperform O(n^x)O(n) will almost always outperform O(n^x)
Try to help the compiler when he can‘t Try to help the compiler when he can‘t optimize (e.g. because of aliasing)optimize (e.g. because of aliasing)
Use assembly language and know your Use assembly language and know your hardware!hardware! Changes will get tedious (Assembly -> High-Changes will get tedious (Assembly -> High-
level language -> Assembly)level language -> Assembly) But a tremendous speed-up is possibleBut a tremendous speed-up is possible
31 / 32Stefan Reinalter Sproing Interactive Media GmbH
TRC/LOT-GuidelinesTRC/LOT-Guidelines Games must fulfill guidelines for the respective Games must fulfill guidelines for the respective
platform(s)platform(s) These guidelines come from the console-These guidelines come from the console-
manufacturer (Microsoft, Sony, Nintendo)manufacturer (Microsoft, Sony, Nintendo) Contain requirements e.g. aboutContain requirements e.g. about
button handling in menusbutton handling in menusareas where to display graphics on the areas where to display graphics on the
screenscreensafety-messagessafety-messages
Can be tedious to implementCan be tedious to implementMust be implemented 100%, otherwise Must be implemented 100%, otherwise
you‘re simply not allowed to ship your game!you‘re simply not allowed to ship your game!
32 / 32Stefan Reinalter Sproing Interactive Media GmbH
TRC/LOT-GuidelinesTRC/LOT-Guidelines Are sometimes not that easy to understandAre sometimes not that easy to understand
Might be contradictoryMight be contradictory Every game must go through platform-QAEvery game must go through platform-QA
Can‘t develop whatever you want on Can‘t develop whatever you want on consoles, must first get approval for thisconsoles, must first get approval for this
Approval processApproval processConcept, game designConcept, game designTechnical requirementsTechnical requirementsSeveral stages to go throughSeveral stages to go through
Questions ?Questions ?
top related