You can use 3D graphics to enhance and differentiate your Metro style app.
-
Upload
sarah-hensley -
Category
Documents
-
view
214 -
download
0
Transcript of You can use 3D graphics to enhance and differentiate your Metro style app.
www.buildwindows.com
3D Graphics in Metro Style Apps and Games
Chas BoydPrincipal Program ManagerMicrosoft Corporation
PLAT-751T
www.buildwindows.com
You can use 3D graphics to enhance and
differentiate your Metro style app.
www.buildwindows.com
Globe
A 3D foundation for geotagging, map mash-ups, etc.
demo
www.buildwindows.com
www.buildwindows.com
3D app scenarios
• Map mashups• Visualization• Data-mining• Medical• Scientific
• Games
www.buildwindows.com
www.buildwindows.com
Agenda
• A lap around Direct3D -object model• New features of Direct3D11• Supporting the whole range of PCs
• Resources available for Direct3D developers
Takeaways• You will understand how to get started writing a
3D Metro style app
www.buildwindows.com
DirectX 11.1
• DirectX11.1 is the version of DirectX11 that ships in Windows 8
• It has some minor new features added, but most of the improvements are behind the scenes in terms of integration with the other core OS components
www.buildwindows.com
Architecture
DXGI
VideoDirect3DDirectCompute
Direct2DC++ AMPMedia
Foundation
HTML, XAML
Direct3D object model
VertexDecl
VertexShader
PixelShader
OutputMergerState
Direct3D object model
GraphicsMemoryResource
s
Graphics
State
Interface
Mesh Object
TextureObject RenderTarget
Objects
Direct3D Device
www.buildwindows.com
The Direct3D device object
• Primary Direct3D API object• Represents the core rendering engine
• Properties of the device == state of graphics chip
• All rendering resources are bound to the context• Context abstraction enables multi-threading
Direct3D Device Context
Vertex Processo
r
Triangle Rasterize
r
Pixel Processo
r
Output Merger
Vertex Processo
r
www.buildwindows.com
Mesh object
• Meshes are stored in vertex buffers• Indexed with index buffers
• Vertex buffers enable mesh data to be cached in graphics memory
• Vertex declaration defines a the data formats for the hardware
Vertex BufferIndex
Buffer
Vertex DeclVertex Format
Texture object
Base Image
Shader Resource View
MIP Chain
Pixel Format
Texture Data
RenderTarget object
Swap Chain
=BackBuffer
+ FrontBuffe
r
Render Target View Pixel Format
Pixel Data
Creating a swap chainWindows::UI::Core::CoreWindow^ coreWindow; // app’s core windowMicrosoft::WRL::ComPtr<ID3D11Device1> d3dDevice; // rendererMicrosoft::WRL::ComPtr<IDXGISwapChain1> dxgiSwapChain; // front/back buffers of RT
// Obtain the final swap chain for this window from the DXGI factory.dxgiFactory->CreateSwapChainForImmersiveWindow( d3dDevice.Get(), // the Direct3D device that will render to it DX::GetIUnknown(coreWindow), // IUnknown interface on our core window &swapChainDesc, // double or triple buffered, stereo, etc. nullptr, // allow on all displays &dxgiSwapChain // the resulting swap chain object );
Depth stencil object
Depth/Stencil View
Depth Buffer
Pixel Format
Pixel Data
www.buildwindows.com
HLSL shaders
float4 SimplePixelShader( sPSInput input ) : SV_TARGET { float3 toLight = normalize( float3(1,1,0) ); float intensity = saturate( dot( input.norm, toLight ) ); return SimpleTexture.Sample( SimpleSampler, input.tex )*intensity; }
VertexDecl
VertexShader
PixelShader
OutputMergerState
Direct3D DeviceContext
www.buildwindows.com
Compiling a shader
• HLSL is compiled off-line with fxc.exe• This enables 90% of the work to happen up front
• Driver translates (JITs) to it’s own instruction set at load time
• On call to d3dDevice->CreatePixelShader()• Enables operation across hardware vendors and
generations
www.buildwindows.com
Direct3D supports a large hardware base
• Hardware is organized into a sequence of feature levels• From Feature_Level_9_1 to Feature_Level_11_1
• Many algorithms can use the same code across levels• Others may need separate codepaths for optimal
performance
• See Talk <752> Tuning GPU Usage for Any Form Factor
New Features of Direct3D11.1
www.buildwindows.com
Direct3D capabilities
Advanced features
• Tessellation• DirectCompute• Double precision• HQ texture compression
Power-oriented features
• Low-precision HLSL instructions
• Optimizations for tiling GPUs
www.buildwindows.com
Tessellation
• Available on DX11 feature level hardware• Enhances mesh quality and detail• Render using base mesh on slower PCs
• Use subdivided mesh on faster ones
www.buildwindows.com
DirectCompute
• Delivers general-purpose GPU processing to Metro style apps• Teraflops of performance
• Foundation of C++ AMP (Accelerated Massive Parallelism)
• Runs on same device object as Direct3D• So sharing resources for rendering is instantaneous
www.buildwindows.com
New shader instructions
• Technical computing needs fast double precision math
• New instructions were added for key transcendentals• Full performance on newer GPUs• Emulated on older ones
• HLSL now supports an image search instruction• msad4: Vector Sum of Absolute Differences• Accelerated in future hardware, emulated on Windows 8
drivers
www.buildwindows.com
Texture compression
• Direct3D supports texture compression• BC1 4-bits/pixel for RGB formats 6x compression ratio• BC2,3 8-bits/pixel for RGBA formats 4x compression ratio
• This is strongly recommended• Smaller package means faster downloads of your app
• Feature Level 11 hardware added 2 new formats• BC6 for high dynamic range imagery• BC7 for higher quality content
www.buildwindows.com
Texture compression example
8k x 4k image @ 24 bits/pixel = 32MPix
WorldMap.bmp 98MB 1x
WorldMap.dds (BC1) + mip maps 22MB 5x
WorldMap.zip (e.g. in .appx package) 7MB 14x
WorldMap.jpg 5.5MB 17x
www.buildwindows.com
Texture compression quality
.Worldmap.jpg
Worldmap.dds BC1 compressed
www.buildwindows.com
Power optimizations: precision
• Optimizing for power and battery life is important
• All shaders in DirectX currently default to 32-bit precision
• As of Windows 8, you can use 16-bit float or int data• Enables some hardware to work at twice the rate for the
same power
www.buildwindows.com
Optimizations: tiled renderers
• Some power-optimized GPUs use an output image cache called a tile
• These chips can get a performance boost with a special flag
m_swapChain->Present(1, 0); // present the image on the display
ComPtr<ID3D11View> view; m_renderTargetView.As(&view) // get the view on the RT
m_d3dContext->DiscardView(view.Get()); // release the view
Developer resources
www.buildwindows.com
Visual Studio 11
www.buildwindows.com
Asset compilation
• Goal: optimize 3D assets as part of build phase• Runtime app package contains only optimized data
• Keep the package download as small as possible• Don’t keep users waiting for your app!
www.buildwindows.com
Shader.cso
Asset compilation
Shader.hlsl
Author-time Asset
Build Step Run-time Asset
myApp.app
x
Packager
Package
Texture.bmp
Mesh.obj
Music.wav
Texture.dds
Mesh.vbo
Music.wma
fxc.exe
dxtex
obj2vbo
myTool
www.buildwindows.com
New samples for Metro style apps
• The samples are designed to• Make it easy to see the API calls used and how they work• Show incremental steps toward building a real app
• Samples tip: set a breakpoint in DirectXSample.h #line 18• to see HRESULTS before the exception
www.buildwindows.com
Spectrum of sample types
• Tutorials• Introduce very basic initial concepts from step 1• In-line code to favor readability over factoring of
functionality• Simple samples• Provide starting points for developers adding specific
techniques• Each sample builds on the last demonstrating another
technique• SimpleD3D, Simple3DTouch, ResourceLoading, D3DPostProcessing,
Stereo…
• E2E sample ‘starter kits’ with source• Demonstrate integration of all components (basic*.cpp)• Simple3DGame, ModernMarbleMaze
www.buildwindows.com
Hands-on Labs
• <764> Direct3D Tutorial• Basic elements of 3D graphics taught step-by-step using
Direct3D
• <709> Visual Studio 11 Visualization and Debugging• DirectX-oriented features like texture viewing, shader
analysis, mesh validation, API call debugging
• <763> Visual Studio Debugging• More chances to try out the debugging and 3D basics
www.buildwindows.com
Related sessions
• [PLAT-766T] Introduction to DirectX for Metro style apps
• [PLAT-750T] Build your first Metro style game
• [PLAT-752T] Tuning GPU usage for any form factor
• [TOOL-761T] A lap around DirectX game development tools
• [PLAT-756T] Building Xbox LIVE games for Windows 8
www.buildwindows.com
Windows 8 is the ideal platform for 3D apps.
www.buildwindows.com
Use 3D in Metro style apps
• 3D is a valuable way to differentiate your Metro style app
• Direct3D11 is the solution for 3D in Windows 8
• Direct3D is fully supported with APIs, tools, and samples
• Go build your 3D Metro style app!
www.buildwindows.com
• Feedback and questions http://forums.dev.windows.com
• Session feedbackhttp://bldw.in/SessionFeedback
thank you
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to
be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.