you can use 3d graphics to enhance and differentiate your metro style app

43
www.buildwindows.com 3D Graphics in Metro Style Apps and Games Chas Boyd Principal Program Manager Microsoft Corporation PLAT-751T

Upload: sarah-hensley

Post on 24-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Page 2: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

You can use 3D graphics to enhance and

differentiate your Metro style app.

Page 3: 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

Page 4: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Page 5: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

3D app scenarios

• Map mashups• Visualization• Data-mining• Medical• Scientific

• Games

Page 6: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Page 7: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 8: You can use 3D graphics to enhance and differentiate your 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

Page 9: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Architecture

DXGI

VideoDirect3DDirectCompute

Direct2DC++ AMPMedia

Foundation

HTML, XAML

Page 10: You can use 3D graphics to enhance and differentiate your Metro style app

Direct3D object model

Page 11: You can use 3D graphics to enhance and differentiate your Metro style app

VertexDecl

VertexShader

PixelShader

OutputMergerState

Direct3D object model

GraphicsMemoryResource

s

Graphics

State

Interface

Mesh Object

TextureObject RenderTarget

Objects

Direct3D Device

Page 12: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 13: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 14: You can use 3D graphics to enhance and differentiate your Metro style app

Texture object

Base Image

Shader Resource View

MIP Chain

Pixel Format

Texture Data

Page 15: You can use 3D graphics to enhance and differentiate your Metro style app

RenderTarget object

Swap Chain

=BackBuffer

+ FrontBuffe

r

Render Target View Pixel Format

Pixel Data

Page 16: You can use 3D graphics to enhance and differentiate your Metro style app

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 );

Page 17: You can use 3D graphics to enhance and differentiate your Metro style app

Depth stencil object

Depth/Stencil View

Depth Buffer

Pixel Format

Pixel Data

Page 18: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 19: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 20: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 21: You can use 3D graphics to enhance and differentiate your Metro style app

New Features of Direct3D11.1

Page 22: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 23: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 24: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 25: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 26: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 27: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 28: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Texture compression quality

.Worldmap.jpg

Worldmap.dds BC1 compressed

Page 29: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 30: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 31: You can use 3D graphics to enhance and differentiate your Metro style app

Developer resources

Page 32: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Visual Studio 11

Page 33: You can use 3D graphics to enhance and differentiate your Metro style app

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!

Page 34: You can use 3D graphics to enhance and differentiate your Metro style 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

Page 35: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 36: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 37: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 38: You can use 3D graphics to enhance and differentiate your Metro style app

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

Page 39: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

Windows 8 is the ideal platform for 3D apps.

Page 40: You can use 3D graphics to enhance and differentiate your Metro style app

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!

Page 41: You can use 3D graphics to enhance and differentiate your Metro style app

www.buildwindows.com

• Feedback and questions http://forums.dev.windows.com

• Session feedbackhttp://bldw.in/SessionFeedback

thank you

Page 42: You can use 3D graphics to enhance and differentiate your Metro style app

© 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.

Page 43: You can use 3D graphics to enhance and differentiate your Metro style app