资源预览内容
第1页 / 共32页
第2页 / 共32页
第3页 / 共32页
第4页 / 共32页
第5页 / 共32页
第6页 / 共32页
第7页 / 共32页
第8页 / 共32页
第9页 / 共32页
第10页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Building a High Performance 3D Games for Windows Phone,Adam Schaeffer Microsoft Corporation,SESSION CODE: WPH308,Consistent sets of hardware capabilities defined by Microsoft,Windows Phone 7 Hardware,Resolution Touch Input CPU / GPU RAM Hardware keyboard is optional,The CPU,The Evolution Of Programming,Low level control,Straight to the metal,Raw performance tuning,High level abstraction,Rely on compiler and runtime,Developer productivity,Why C# r0 x0rz,Powerful and expressive,Type safety reduces hard-to-track-down bugs,Reflection,Initializer syntax,Great tooling (IntelliSense),Similar enough to C that learning and porting are easy,Blazingly fast compiles,C#,.NET on Windows,Usually within a few percent of native performance,Awesome generational garbage collection,Performance shootout: Raymond Chen vs. Rico Mariani http:/,.NET on Xbox 360,360,Significant delta between managed and native,.NET Compact Framework Simplistic mark-and-sweep garbage collection,Xbox is not a general purpose computer Unforgiving in-order CPU architecture Requires custom VMX instructions for optimal math perf Security architecture poses challenges for jitted code,.NET on Windows Phone 7,In between Windows and Xbox 360,.NET Compact Framework Keep an eye on garbage collection!,ARMv7 CPU More forgiving toward jitted code ARM jitter is more mature than PPC,Ways To Call Code,Instance method,Interface,Delegate / event,Reflection,Virtual method,Choose Your Own Address,C+ allows independent choice of,.NET types dictate their allocation and usage semantics,Data type The memory in which a type lives (placement new) How a type instance is referenced (T, T*, T c = Matrix.Multiply(a, b); / copies 192 bytes! Matrix.Multiply(ref a, ref b, out c);,Memory Management,Garbage collection is not optional Cant have type safety without automatic memory management,Mark and Sweep,Triggered per megabyte of allocation,1,Starts with root references (stack variables, statics),2,Recursively follows all references to see what other objects can be reached,3,Anything we didnt reach must be garbage,4,Compacts the heap, sliding live objects down to fill holes,5,Frameworks designed for performance,Frameworks designed for performance,Two Ways To Keep GC Happy,Make it run Less Often,If you never allocate, GC will never run,Make it Finish Quickly,Collection time is proportional to how many object references must be traversed,Use object pools,Simple heap = fast collection,Use value types and integer handles,GC.Collect,Explicitly forces a garbage collection,Use wisely to give yourself more headroom After loading During pauses in gameplay,Dont call every frame!,Avoiding Allocation,Beware of boxing,string vs. StringBuilder,Use WeakReference to track GC frequency http:/,Use CLR Profiler on Windows See MIX10 talk: “Development and Debugging Tools for Windows Phone 7 Series”,Use .NET Reflector to peek behind the curtain http:/www.red-,The GPU,Plus hardware accelerated 2D sprite drawing,Five Configurable Effects,BasicEffect,SkinnedEffect,EnvironmentMapEffect,AlphaTestEffect,DualTextureEffect,BasicEffect,0-3 directional lights Blinn-Phong shading Optional texture Optional fog Optional vertex color,BasicEffect,DualTextureEffect,DualTextureEffect,For lightmaps, detail textures, decals Blends two textures Separate texture coordinates Modulate 2X combine mode (A*B*2) Good visuals at low pixel cost,AlphaTestEffect,For billboards and imposters Adds alpha test operations (pixel kill) Standard blending is free with all effects Only need alpha test if you want to disable depth/stencil writes,AlphaTestEffect,SkinnedEffect,SkinnedEffect,For animated models and instancing Game code animates bones on CPU Vertex skinning performed by GPU Up to 72 bones One, two, or four weights per vertex,EnvironmentMapEffect,EnvironmentMapEffect,Oooh, shiny! Diffuse texture + cube environment map Cheap way to fake many complex lights Fresnel term simulates behavior when light reaches a surface and some reflects, some penetrates,A Balancing Act,Framerate,Number of Pixels,Pixel Cost,Balancing Framerate,Framerate,30 hz refresh rate No point updating faster than the display! Game.TargetElapsedTime = TimeSpan.FromSeconds(1f / 30);,A Balancing Act,Pixel Cost,Prefer cheaper effects Minimize overdraw Many known algorithms: Distance, frustum, BSP, sort front to back Implement “overdraw x-ray mode” Draw untextured with additive blending Brighter areas indicate overdraw,A Balancing Act,Number of Pixels,800 x480 is 25% more pixels than Xbox 1 Great for text Too many pixels for intensive games 800 x480 = 384,000 pixels 600 x360 = 216,000 pixels (56%) Dedicated hardware scaler Does not consume any GPU Higher quality than bilinear upsampling,Scaler Demo,XNA Framework API Cheat Sheet,Summary,Great performance comes from great knowledge,Understand,Actions,Value types vs. reference types Garbage collection C# compiler magic (foreach, iterator methods, closures) Cost of the different graphical effect options,Use CLR Profiler and .
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号