ppt模板-配色簡潔內(nèi)容豐富.pptx
Adam SchaefferMicrosoft CorporationSESSION CODE: WPH3 0 8 銳普PPT論壇chinakui首發(fā) Consistent sets of hardware capabilities defined by MicrosoftResolutionTouch InputCPU / GPURAMHardware keyboard is optional Low level controlStraight to the metalRaw performance tuning High level abstractionRely on compiler and runtimeDeveloper productivity Powerful and expressiveType safety reduces hard-to-track-down bugsReflectionInitializer syntaxGreat tooling (IntelliSense)Similar enough to C that learning and porting are easyBlazingly fast compilesC# Usually within a few percent of native performanceAwesome generational garbage collectionPerformance shootout: Raymond Chen vs. Rico Marianihttp:/ 0 0 5 /0 5 /1 0 /4 1 6 1 5 1 .aspx Significant delta between managed and native.NET Compact FrameworkSimplistic mark-and-sweep garbage collectionXbox is not a general purpose computerUnforgiving in-order CPU architectureRequires custom VMX instructions for optimal math perfSecurity architecture poses challenges for jitted code In between Windows and Xbox 3 6 0.NET Compact FrameworkKeep an eye on garbage collection!ARMv7 CPUMore forgiving toward jitted codeARM jitter is more mature than PPC Instance methodInterfaceDelegate / eventReflectionVirtual method C+ allows independent choice of.NET types dictate their allocation and usage semanticsData typeThe memory in which a type lives (placement new)How a type instance is referenced (T, T*, Tc = Matrix.Multiply(a, b); / copies 192 bytes! Matrix.Multiply(ref a, ref b, out c); C+ .NETAllocate Initially fast, becoming slower as fragmentation increases Very fast, apart from periodic garbage collectionsFree Fast InstantaneousFragmentation Increases over time NoneCache coherency Requires custom allocators Things allocated close in time are also close in physical locationGarbage collection is not optionalCant have type safety without automatic memory management Triggered per megabyte of allocation1 Starts with root references (stack variables, statics)2 Recursively follows all references to see what other objects can be reached3 Anything we didnt reach must be garbage4 Compacts the heap, sliding live objects down to fill holes5 Frameworks designed for performance Frameworks designed for performanceMake it run Less OftenIf you never allocate, GC will never run Make it Finish QuicklyCollection time is proportional to how many object references must be traversedUse object pools Simple heap = fast collectionUse value types and integer handles Explicitly forces a garbage collectionUse wisely to give yourself more headroomAfter loadingDuring pauses in gameplayDont call every frame! Beware of boxingstring vs. StringBuilderUse WeakReference to track GC frequencyhttp:/ 0 0 7 /1 0 /1 2 /monitoring-the-garbage-collector.aspxUse CLR Profiler on WindowsSee MIX1 0 talk: “Development and Debugging Tools for Windows Phone 7 Series”Use .NET Reflector to peek behind the curtainhttp:/www.red- Plus hardware accelerated 2D sprite drawingBasicEffectSkinnedEffectEnvironmentMapEffectAlphaTestEffectDualTextureEffect 0-3 directional lights Blinn-Phong shading Optional texture Optional fog Optional vertex colorBasicEffectVertex Cost Pixel CostNo lighting 5 1One vertex light 40 1Three vertex lights 60 1Three pixel lights 18 50+ Texture +1 +2+ Fog +4 +2 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 Vertex Cost Pixel CostTwo Textures 7 6+ Fog +4 +2 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 writesAlphaTestEffectVertex Cost Pixel Cost, =, 6 6=, != 6 10+ Fog +4 +2 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 Vertex Cost Pixel CostOne vertex light 55 4Three vertex lights 75 4Three pixel lights 33 51+ Two bones +7 +0+ Four bones +13 +0+ Fog +0 +2 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 Vertex Cost Pixel CostOne light 32 6Three lights 36 6+ Fresnel +7 +0+ Specular +0 +2+ Fog +0 +2 Framerate Numberof PixelsPixel Cost Framerate 3 0 hz refresh rate No point updating faster than the display! Game.TargetElapsedTime = TimeSpan.FromSeconds(1 f / 3 0 ); Pixel Cost Prefer cheaper effects Minimize overdrawMany known algorithms:Distance, frustum, BSP, sort front to backImplement “overdraw x-ray mode” Draw untextured with additive blendingBrighter areas indicate overdraw Numberof Pixels 8 0 0 x4 8 0 is 2 5 % more pixels than Xbox 1Great for textToo many pixels for intensive games8 0 0 x4 8 0 = 3 8 4 ,0 0 0 pixels6 0 0 x3 6 0 = 2 1 6 ,0 0 0 pixels (5 6 %) Dedicated hardware scaler Does not consume any GPU Higher quality than bilinear upsampling Avoid PreferRenderTargetUsage.PreserveContentsRenderTargetUsage.DiscardContentsdevice.BlendState = new BlendState .;/ At startupstatic BlendState myState = new BlendState .;/ Per frameDevice.BlendState = myState;VertexBuffer.SetData(.)device.DrawUserPrimitives(.);/ orDynamicVertexBuffer.SetData(., SetDataOptions.NoOverwrite); Great performance comes from great knowledgeUnderstandActionsValue types vs. reference typesGarbage collectionC# compiler magic (foreach, iterator methods, closures)Cost of the different graphical effect optionsUse CLR Profiler and .NET ReflectorRender smaller than display resolution, rely on scaler