You can use 3D graphics to enhance and differentiate your Metro style app.

Download Report

Transcript You can use 3D graphics to enhance and differentiate your Metro style app.

You can use 3D graphics to enhance and differentiate your Metro style app.

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

• • • • 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

• 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

HTML, XAML

Direct3D object model

Direct3D object model

Graphics State Interface Graphics Memory Resources Vertex Decl Mesh Object Vertex Shader Pixel Shader Direct3D Device Texture Object OutputMerger State RenderTarget Objects

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 Format

• • 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 Decl

Texture object

Shader Resource View Pixel Format MIP Chain Texture Data Base Image

RenderTarget object

Render Target View Pixel Format Swap Chain = BackBuffer + FrontBuffer Pixel Data

CoreWindow ComPtr ID3D11Device1 ComPtr IDXGISwapChain1 // app’s core window // renderer // front/back buffers of RT // Obtain the final swap chain for this window from the DXGI factory.

nullptr // the Direct3D device that will render to it // IUnknown interface on our core window // double or triple buffered, stereo, etc.

// allow on all displays // the resulting swap chain object

Depth stencil object

Depth/Stencil View Pixel Format Pixel Data Depth Buffer

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; } Vertex Decl Vertex Shader Pixel Shader Direct3D Device OutputMerger State Context

• • 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

• • 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

Advanced features • • • • Tessellation DirectCompute Double precision HQ texture compression Power-oriented features • • Low-precision HLSL instructions Optimizations for tiling GPUs

• • • Available on DX11 feature level hardware Enhances mesh quality and detail Render using base mesh on slower PCs • Use subdivided mesh on faster ones

• • 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

• • • • 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

• • • 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

8k x 4k image @ 24 bits/pixel = 32MPix WorldMap.bmp

WorldMap.dds (BC1) + mip maps WorldMap.zip (e.g. in .appx package) WorldMap.jpg

98MB 22MB 7MB 14x 5.5MB

17x 1x 5x

.Worldmap.jpg

Worldmap.dds

BC1 compressed

• 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

• • 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 view; m_renderTargetView.As(&view) m_d3dContext->DiscardView(view.Get()); // get the view on the RT // release the view

Developer resources

• • 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!

Asset compilation

Author-time Asset Build Step Shader.hlsl

Texture.bmp

Mesh.obj

Music.wav

Run-time Asset Shader.cso

Texture.dds

Mesh.vbo

Music.wma

Packager Package myApp.

appx

• • • 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

• • • • • 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

• • <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

• • • • • [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

Windows 8 is the ideal platform for 3D 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!

http://forums.dev.windows.com

http://bldw.in/SessionFeedback