PRS311: Direct3D Part 1: Utilizing the Maximum Power of

Download Report

Transcript PRS311: Direct3D Part 1: Utilizing the Maximum Power of

Direct 3D Part 1: Utilizing The Maximum Power
Of The GPU In Your Graphic-Intensive Windows
Vista ("Longhorn") Application
Rudolph Balaz
PRS311
Program Manager
Microsoft Corporation
Session Focus
PRS 311 (This talk)
Overview of Windows Vista Graphics Stack
Focus on Direct3D technologies
Discover Graphics Stack changes
Learn how to unleash the GPU
Understand what it means to your application
PRS 416
Building applications using HLSL
Cool things you can do with Direct3D
Next generation uses of the GPU
Topics Covered
Windows Vista Direct3D Goals
More Scalable / More Reliable
New uses of the GPU
Better visuals and effects
Windows Vista Direct 3D Technologies
New Display Driver Model
Direct 3D 9.0
Direct 3D 10
Direct 3D
Direct access to 3D hardware
Real time frame rates
Graphics Intensive Applications
Games, Productivity, Workstation Applications
Native & Managed APIs
Windows Vista
Graphics Stack
Applications
Desktop
Windows
Manager
Windows
Presentation
Foundation
D3DX9
Direct3D9 Runtime
Managed
Direct3D9
Managed
Direct3D10
Effects
D3DX10
Direct3D10 Runtime
Windows Vista Display Driver Model
Subtle Windows Vista Changes
GDI –software only
Desktop Composition
Your timing may vary
Actions may disable Desktop Composition
GetDC(NULL), Locking GDI primary surface
Shader Model 2.0 baseline
Things To Do
Don’t lock the front buffer
Throttle rendering in Windowed mode
Test Fully
Windows XP driver model
Windows Vista driver model
With/Without Desktop Window Manager
Windowed/Fullscreen
Scalability / Reliability
GPU Is A Shared Resource
Presentation
Desktop Manager
Applications
Games
Multimedia
Workstation Graphics
Multi-monitor
Mobile
Remote (terminal server)
Scalability / Reliability
Windows Vista Display Driver Model
Display Driver Model Highlights
Virtualized graphics
memory
GPU Command
Scheduling & Multitasking
Command translation
moved to user mode
Managed Primaries
Fault tolerance
Plug and Play
Rebootless driver upgrade
Shared Surfaces
Secure Surfaces
Application
User-Mode Driver
Direct3D
User Mode
Kernel Mode
DXGKrnl
GPU
Video Memory
Scheduler
Manager
Kernel-Mode Driver
Graphics Hardware
Driver Model Details
Basic Model
Available in Windows Vista
Virtualization is resource granularity
Command Scheduling is in Software
Advanced Model
Available Shortly after Windows Vista
Page-level faulting
Hardware context switching
Subtle Windows Vista Changes
Can’t interleave GDI and D3D content
Don’t draw lines, Bit Blts, etc. on Window DC
Use Direct3D GetDC on Backbuffer
GDI is software
Not as performant as before
Managed Primaries
GDI popup flicker is gone for D3D9Ex
GDI Desktop ≠ Buffer in swap chain
Things to do
Recreate Swap chain
If Window size ≠ Backbuffer Size
Desktop is rotated
Don’t mix GDI & D3D content
Scalability / Reliability
Direct3D 9.0 on Vista
Direct3D9 for Vista
All Direct3D applications benefit from
new Driver Model
Improved Stability
Multiple Applications
Direct3D 9.0c applications just work
Expose new driver model benefits to
Applications
Direct3D9Ex
Vista Desktop built on top of D3D9
Creating a Direct3D Device
pD3D = Direct3DCreate9( D3D_SDK_VERSION );
pD3D->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_DIREC3D9EX |
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &pd3dDevice
);
pd3dDevice->QueryInterface( pd3dDevice, D3DCREATEDEVICEEX,
pd3dDeviceEx );
Above is changing for Windows Vista Beta 2
Direct3D10 not in Windows Vista Beta 1 but coming Beta 2
Shared Surfaces
Parameter HANDLE* pSharedHandle
CreateTexture
CreateVolumeTexture
CreateCubeTexture
CreateRenderTarget
CreateVertexBuffer
CreateIndexBuffer
CreateDepthStencilSurface
CreateOffscreenPlainSurface
Resource can be re-opened using this shared handle.
Restrictions:
Resource attributes must match
Only creating Process can Lock surface
No automatic synchronization provided.
Must be D3DPOOL_DEFAULT
Initialize Textures at Creation
Parameter HANDLE* pSharedHandle
Pointer to texture
Restrictions:
Must be D3DPOOL_SYSTEMMEM
Format must match texture being created
GPU Resource Management
GPU Thread Priority
HRESULT GetGPUThreadPriority(UINT *pPriority);
HRESULT SetGPUThreadPriority(UINT Priority);
Resource Priority
Soft-pinning
Per resource priority
Residency Check
HRESULT IDirect3DDevice9Ex::CheckResourceResidency(
[in, size_is ( NumResources )] IDirect3DResource9 * pResourceArray,
[in] UINT32 NumResources);
Presentation Control
Present same frame multiple times
VBlank
HRESULT WaitForVBlank(void);
Frame Statistics
HRESULT GetLastPresentIndex(UINT* pLastPresentCount);
HRESULT GetFrameStatistics(D3DPRESENTSTATS*
pPresentationStatistics);
typedef struct _D3DPRESENTSTATS {
UINT PresentCount;
UINT PresentRefreshCount;
UINT SyncRefreshCount;
LARGE_INTEGER SyncQPCTime;
LARGE_INTEGER SyncGPUTime;
} D3DPRESENTSTATS;
Subtle Windows Vista Changes
D3DPOOL_DEFAULT
Resources never lost
not limited by Video memory
D3DERR_DEVICELOST - very rare
Example GPU hung and has been reset
D3DERR_DEVICEREMOVED
New error code
Driver uninstalled
Hardware removed
Unsubtle Changes
TestCooperativeLevel deprecated
Always returns S_OK
Replaced by
HRESULT CheckDeviceState(HWND hWindow);
New Device States
D3DERR_DEVICELOST
D3DERR_DEVICEHUNG
D3DERR_DEVICEREMOVED
S_PRESENT_OCCLUDED
S_PRESENT_MODE_CHANGED
When to use Direct3D9Ex
Eliminate Video Memory Limit
CAD / Design applications
Resource Sharing
Application uses multiple: Windows,
Monitors, etc.
Resource Scheduling
Best Windows Vista Experience
Willing to have multiple code paths
Or only targeting newer hardware
Things to do
Use D3D9Ex on Windows Vista
Use Shared surfaces to limit memory
usage
Always use D3DPOOL_DEFAULT
Recreate everything on
D3DDEVICE_REMOVED
Don’t use explicit resource management
Priority API’s
Use limit GPU usage when Windowed
Better Visuals and Effects
D3D10
Direct3D10
A Tremendous Step Forward
Fundamental architecture change
A new foundation for future
releases
Rebuilt from the ground-up
Based on your feedback
In collaboration with the IHV’s
New hardware pipeline and
software stack
DXGI
DirectX Graphics Infrastructure
Common operations
refactored into a single
DLL, isolated from rapid
innovation on the 3D
engine
Enables resource
sharing between
Direct3D®10 and future
API’s
D3D10 +2
D3D10 +1
D3D10
DXGI
Overview: The New
Hardware Pipeline
Guaranteed Feature Set
Strictly-defined, consistent
behavior across hardware
New Pipeline Stages and
Primitive types
Input Assembler
Geometry Shader
Common Shader Cores
Stream Output
New resource types and formats
Ubiquity of resource access
…
Command
Input
Input
Assembler
Virtualized Memory
(GPU/System Memory)
Vertex Buffer
Index Buffer
Vertex
Shader
Texture
Geometry
Shader
Texture
Stream Output
Rasterizer/
Interpolator
Pixel
Shader
Output
Merger
Texture
Depth/Stencil
Render Target
Resource Types And “Views”
Ubiquity of Resource Usage
y z
rce
Vie
w
x
Cr
ea
te
Sh
ad
iew
etV
arg
erT
er
Re
so
u
d
en
teR
ea
Cr
D3D10_TEXCUBE_SRV
D3D10_TEXCUBE_RTV
v
u
y z
OMSetTargets
x
PS/VS/GSSetTextures
Create multiple “views” of
a base resource for usage
at different points in the
pipeline
Pipeline Output
Render Target
and…
Shader Resource
Input
Texture
and…
Geometry Shader
Per-Primitive Operations
GS Inputs:
1
2
3
0
0
1
2
3
4
5
Operates on entire primitives
[with adjacency]
Material selection/setup to reduce # of
draw() calls
Set up barycentrics to exceed # of
interpolators
Compute edge lengths
Compute plane equations
Compute silhouette edges
Single-Pass Render-toCubemap
Geometry
Shader
v
u
ID3D10ShaderResourceView::GenMips(…)
y z
x
Single Pass Render-To-Cubemap
Stream Output
Geometry
Shader
Texture
Stream Output
Rasterizer/
Interpolator
Writes GS Output to one or
more buffers
DrawAuto() to draw streamed-out data of variable
size without CPU intervention
Uses:
Intra-frame re-use
Skin/morph once, render many
Inter-frame re-use
Iterative/procedural
geometry processing
All-GPU particle
systems
…
Predicated Rendering
Predicate draw’s and blit’s with results of
asynchronous queries
No CPU involvement required
Occlusion culling – render bounding box,
predicate subsequent (complex) rendering on
occlusion query result
Summary
Windows Vista Direct3D Goals
Windows Vista Direct 3D Technologies
Community Resources
“Windows Development” MSDN Forums
http://forums.microsoft.com/msdn/default.aspx
General, Graphics, Tools, Performance, and Audio
Notification Alerts, Messages and RSS Feeds
Integrated with Visual Studio 2005
Advanced Search
FAQs, Answered/Unanswered Questions
[email protected]
© 2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.