direct 3d part 1: utilizing the maximum power of the gpu in your graphic-intensive windows vista...
Post on 21-Dec-2015
212 views
TRANSCRIPT
Direct 3D Part 1: Utilizing The Maximum Direct 3D Part 1: Utilizing The Maximum Power Of The GPU In Your Graphic-Power Of The GPU In Your Graphic-Intensive Windows Vista ("Longhorn") Intensive Windows Vista ("Longhorn") ApplicationApplication
Rudolph BalazRudolph BalazPRS311 PRS311 Program ManagerProgram ManagerMicrosoft CorporationMicrosoft Corporation
Session FocusSession Focus
PRS 311 (This talk)PRS 311 (This talk)Overview of Windows Vista Graphics Overview of Windows Vista Graphics StackStack
Focus on Direct3D technologiesFocus on Direct3D technologies
Discover Graphics Stack changesDiscover Graphics Stack changes
Learn how to unleash the GPULearn how to unleash the GPU
Understand what it means to your Understand what it means to your applicationapplication
PRS 416PRS 416Building applications using HLSLBuilding applications using HLSL
Cool things you can do with Direct3DCool things you can do with Direct3D
Next generation uses of the GPUNext generation uses of the GPU
Topics CoveredTopics Covered
Windows Vista Direct3D GoalsWindows Vista Direct3D GoalsMore Scalable / More ReliableMore Scalable / More Reliable
New uses of the GPUNew uses of the GPU
Better visuals and effectsBetter visuals and effects
Windows Vista Direct 3D TechnologiesWindows Vista Direct 3D TechnologiesNew Display Driver ModelNew Display Driver Model
Direct 3D 9.0Direct 3D 9.0
Direct 3D 10Direct 3D 10
Direct 3DDirect 3D
Direct access to 3D hardwareDirect access to 3D hardware
Real time frame ratesReal time frame rates
Graphics Intensive ApplicationsGraphics Intensive ApplicationsGames, Productivity, Workstation Games, Productivity, Workstation ApplicationsApplications
Native & Managed APIsNative & Managed APIs
Windows Vista Windows Vista Graphics StackGraphics Stack
Windows Vista Display Driver ModelWindows Vista Display Driver Model
Direct3D9 RuntimeDirect3D9 Runtime
DesktopDesktopWindowsWindowsManagerManager
WindowsWindowsPresentationPresentationFoundationFoundation
ApplicationsApplications
ManagedManagedDirect3D9Direct3D9
D3DX9D3DX9
EffectsEffects
Direct3D10 RuntimeDirect3D10 Runtime
D3DX10D3DX10
ManagedManagedDirect3D10Direct3D10
Subtle Windows Vista Subtle Windows Vista ChangesChanges
GDI –software onlyGDI –software only
Desktop CompositionDesktop CompositionYour timing may varyYour timing may vary
Actions may disable Desktop Actions may disable Desktop CompositionComposition
GetDC(NULL), Locking GDI primary GetDC(NULL), Locking GDI primary surfacesurface
Shader Model 2.0 baselineShader Model 2.0 baseline
Things To DoThings To Do
Don’t lock the front bufferDon’t lock the front buffer
Throttle rendering in Windowed modeThrottle rendering in Windowed mode
Test FullyTest FullyWindows XP driver modelWindows XP driver model
Windows Vista driver modelWindows Vista driver model
With/Without Desktop Window ManagerWith/Without Desktop Window Manager
Windowed/FullscreenWindowed/Fullscreen
Scalability / ReliabilityScalability / Reliability
GPU Is A Shared ResourceGPU Is A Shared Resource
PresentationPresentationDesktop ManagerDesktop Manager
ApplicationsApplications
GamesGames
MultimediaMultimedia
Workstation GraphicsWorkstation Graphics
Multi-monitorMulti-monitor
MobileMobile
Remote (terminal server)Remote (terminal server)
Scalability / ReliabilityScalability / Reliability
Windows Vista Display Driver ModelWindows Vista Display Driver Model
Virtualized graphics Virtualized graphics memorymemory
GPU Command GPU Command Scheduling & Scheduling & MultitaskingMultitasking
Command translation Command translation moved to user modemoved to user mode
Managed PrimariesManaged Primaries
Fault toleranceFault tolerance
Plug and PlayPlug and Play
Rebootless driver Rebootless driver upgradeupgrade
Shared SurfacesShared Surfaces
Secure SurfacesSecure Surfaces
Kernel ModeUser Mode
User-Mode Driver
Graphics Hardware
Kernel-Mode Driver
Application
Direct3D
DXGKrnlGPU
SchedulerVideo Memory
Manager
Display Driver Model Display Driver Model HighlightsHighlights
Driver Model DetailsDriver Model Details
Basic ModelBasic ModelAvailable in Windows VistaAvailable in Windows Vista
Virtualization is resource granularityVirtualization is resource granularity
Command Scheduling is in SoftwareCommand Scheduling is in Software
Advanced ModelAdvanced ModelAvailable Shortly after Windows VistaAvailable Shortly after Windows Vista
Page-level faulting Page-level faulting
Hardware context switchingHardware context switching
Subtle Windows Vista Subtle Windows Vista ChangesChanges
Can’t interleave GDI and D3D contentCan’t interleave GDI and D3D contentDon’t draw lines, Bit Blts, etc. on Window Don’t draw lines, Bit Blts, etc. on Window DCDC
Use Direct3D GetDC on BackbufferUse Direct3D GetDC on Backbuffer
GDI is softwareGDI is softwareNot as performant as beforeNot as performant as before
Managed PrimariesManaged PrimariesGDI popup flicker is gone for D3D9ExGDI popup flicker is gone for D3D9Ex
GDI Desktop ≠ Buffer in swap chainGDI Desktop ≠ Buffer in swap chain
Things to doThings to do
Recreate Swap chainRecreate Swap chainIf Window size ≠ Backbuffer SizeIf Window size ≠ Backbuffer Size
Desktop is rotatedDesktop is rotated
Don’t mix GDI & D3D contentDon’t mix GDI & D3D content
Scalability / ReliabilityScalability / Reliability
Direct3D 9.0 on VistaDirect3D 9.0 on Vista
Direct3D9 for VistaDirect3D9 for VistaAll Direct3D applications benefit All Direct3D applications benefit from new Driver Modelfrom new Driver Model
Improved StabilityImproved Stability
Multiple ApplicationsMultiple Applications
Direct3D 9.0c applications just workDirect3D 9.0c applications just work
Expose new driver model benefits Expose new driver model benefits to Applicationsto Applications
Direct3D9Ex Direct3D9Ex
Vista Desktop built on top of D3D9Vista Desktop built on top of D3D9
Creating a Direct3D Creating a Direct3D DeviceDevice
pD3D = Direct3DCreate9( D3D_SDK_VERSION );pD3D = Direct3DCreate9( D3D_SDK_VERSION );
pD3D->CreateDevice( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, hWnd, D3DCREATE_DIREC3D9EXD3DCREATE_DIREC3D9EX | | DD3DCREATE_SOFTWARE_VERTEXPROCESSING, 3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice &d3dpp, &pd3dDevice ) ;) ;
pd3dDevice->QueryInterface( pd3dDevice, D3DCREATEDEVICEEX, pd3dDevice->QueryInterface( pd3dDevice, D3DCREATEDEVICEEX, pd3dDeviceEx );pd3dDeviceEx );
Above is changing for Windows Vista Beta 2Above is changing for Windows Vista Beta 2
Direct3D10 not in Windows Vista Beta 1 but coming Direct3D10 not in Windows Vista Beta 1 but coming Beta 2Beta 2
Shared SurfacesShared Surfaces
CreateTexture CreateTexture
CreateVolumeTexture CreateVolumeTexture
CreateCubeTexture CreateCubeTexture
CreateRenderTarget CreateRenderTarget
CreateVertexBuffer CreateVertexBuffer
CreateIndexBuffer CreateIndexBuffer
CreateDepthStencilSurfacCreateDepthStencilSurface e
CreateOffscreenPlainSurfaCreateOffscreenPlainSurfacece
Parameter HANDLE* pSharedHandle Parameter HANDLE* pSharedHandle
Resource can be re-opened using this shared Resource can be re-opened using this shared handle.handle.
Restrictions: Restrictions: Resource attributes must matchResource attributes must match
Only creating Process can Lock surfaceOnly creating Process can Lock surface
No automatic synchronization provided.No automatic synchronization provided.
Must be D3DPOOL_DEFAULTMust be D3DPOOL_DEFAULT
Initialize Textures at Initialize Textures at CreationCreation
Parameter HANDLE* pSharedHandle Parameter HANDLE* pSharedHandle Pointer to texturePointer to texture
Restrictions: Restrictions: Must be D3DPOOL_SYSTEMMEMMust be D3DPOOL_SYSTEMMEM
Format must match texture being createdFormat must match texture being created
GPU Resource GPU Resource ManagementManagement
GPU Thread PriorityGPU Thread PriorityHRESULT HRESULT GetGPUThreadPriorityGetGPUThreadPriority(UINT *pPriority); (UINT *pPriority);
HRESULT HRESULT SetGPUThreadPrioritySetGPUThreadPriority(UINT Priority); (UINT Priority);
Resource PriorityResource PrioritySoft-pinningSoft-pinning
Per resource priorityPer resource priority
Residency CheckResidency CheckHRESULT HRESULT IDirect3DDevice9ExIDirect3DDevice9Ex::CheckResourceResidency( ::CheckResourceResidency(
[in, size_is ( NumResources )] IDirect3DResource9 * pResourceArray, [in, size_is ( NumResources )] IDirect3DResource9 * pResourceArray,
[in] UINT32 NumResources); [in] UINT32 NumResources);
Presentation ControlPresentation Control
Present same frame multiple Present same frame multiple timestimes
VBlankVBlankHRESULT HRESULT WaitForVBlankWaitForVBlank(void); (void);
Frame StatisticsFrame StatisticsHRESULT GetLastPresentIndex(UINT* pLastPresentCount);HRESULT GetLastPresentIndex(UINT* pLastPresentCount);
HRESULT GetFrameStatistics(D3DPRESENTSTATS* HRESULT GetFrameStatistics(D3DPRESENTSTATS* pPresentationStatistics); pPresentationStatistics);
typedef struct _D3DPRESENTSTATS {typedef struct _D3DPRESENTSTATS { UINT PresentCount; UINT PresentCount; UINT PresentRefreshCount; UINT PresentRefreshCount; UINT SyncRefreshCount; UINT SyncRefreshCount; LARGE_INTEGER SyncQPCTime; LARGE_INTEGER SyncQPCTime; LARGE_INTEGER SyncGPUTime; LARGE_INTEGER SyncGPUTime;} D3DPRESENTSTATS; } D3DPRESENTSTATS;
Subtle Windows Vista Subtle Windows Vista ChangesChanges
D3DPOOL_DEFAULT D3DPOOL_DEFAULT Resources never lostResources never lost
not limited by Video memorynot limited by Video memory
D3DERR_DEVICELOST - very rareD3DERR_DEVICELOST - very rareExample GPU hung and has been resetExample GPU hung and has been reset
D3DERR_DEVICEREMOVEDD3DERR_DEVICEREMOVEDNew error codeNew error code
Driver uninstalledDriver uninstalled
Hardware removedHardware removed
Unsubtle ChangesUnsubtle Changes
TestCooperativeLevel deprecatedTestCooperativeLevel deprecatedAlways returns S_OKAlways returns S_OK
Replaced by Replaced by HRESULT CheckDeviceState(HWND hWindow); HRESULT CheckDeviceState(HWND hWindow);
New Device StatesNew Device StatesD3DERR_DEVICELOST D3DERR_DEVICELOST
D3DERR_DEVICEHUNG D3DERR_DEVICEHUNG
D3DERR_DEVICEREMOVED D3DERR_DEVICEREMOVED
S_PRESENT_OCCLUDED S_PRESENT_OCCLUDED
S_PRESENT_MODE_CHANGED S_PRESENT_MODE_CHANGED
When to use Direct3D9ExWhen to use Direct3D9Ex
Eliminate Video Memory LimitEliminate Video Memory LimitCAD / Design applicationsCAD / Design applications
Resource SharingResource SharingApplication uses multiple: Windows, Application uses multiple: Windows, Monitors, etc.Monitors, etc.
Resource SchedulingResource Scheduling
Best Windows Vista ExperienceBest Windows Vista ExperienceWilling to have multiple code pathsWilling to have multiple code paths
Or only targeting newer hardwareOr only targeting newer hardware
Things to doThings to do
Use D3D9Ex on Windows VistaUse D3D9Ex on Windows Vista
Use Shared surfaces to limit memory Use Shared surfaces to limit memory usageusage
Always use D3DPOOL_DEFAULTAlways use D3DPOOL_DEFAULT
Recreate everything on Recreate everything on D3DDEVICE_REMOVEDD3DDEVICE_REMOVED
Don’t use explicit resource Don’t use explicit resource managementmanagement
Priority API’sPriority API’s
Use Use limit GPU usage when limit GPU usage when WindowedWindowed
Better Visuals and EffectsBetter Visuals and Effects
D3D10D3D10
Direct3D10Direct3D10A Tremendous Step ForwardA Tremendous Step Forward
Fundamental architecture Fundamental architecture changechangeA new foundation for future A new foundation for future releases releases Rebuilt from the ground-up Rebuilt from the ground-up
Based on your feedbackBased on your feedbackIn collaboration with the IHV’sIn collaboration with the IHV’s
New hardware pipeline and New hardware pipeline and software stacksoftware stack
Common operations Common operations refactored into a refactored into a single DLL, isolated single DLL, isolated from rapid innovation from rapid innovation on the 3D engineon the 3D engine
Enables resource Enables resource sharing between sharing between Direct3DDirect3D®®10 and 10 and future API’sfuture API’s
D3D10 +2D3D10 +1
DXGI
D3D10
DXGIDXGIDirectX Graphics InfrastructureDirectX Graphics InfrastructureDXGIDXGIDirectX Graphics InfrastructureDirectX Graphics Infrastructure
Guaranteed Feature SetGuaranteed Feature Set
Strictly-defined, consistent Strictly-defined, consistent behavior across hardwarebehavior across hardware
New Pipeline Stages and New Pipeline Stages and Primitive typesPrimitive types
Input AssemblerInput Assembler
Geometry ShaderGeometry Shader
Common Shader CoresCommon Shader Cores
Stream OutputStream Output
New resource types and New resource types and formatsformats
Ubiquity of resource accessUbiquity of resource access
……
InputAssembler
VertexShader
Rasterizer/Interpolator
PixelShader
GeometryShader
OutputMerger
Vertex Buffer
Index Buffer
Texture
Texture
Depth/Stencil
Texture
Render Target
Stream Output
CommandInput Virtualized Memory
(GPU/System Memory)
Overview: The New Overview: The New Hardware PipelineHardware Pipeline
Resource Types And Resource Types And “Views”“Views”Ubiquity of Resource UsageUbiquity of Resource Usage
Create multiple Create multiple “views” of a base “views” of a base resource for usage at resource for usage at different points in the different points in the pipelinepipeline
Pipeline OutputPipeline Output
Render TargetRender Target
and…and…
Shader Resource Shader Resource InputInput
TextureTexture
and…and…
D3D10_TEXCUBE_RTVD3D10_TEXCUBE_SRV
x
y z
uv
x
y z
Crea
teSha
derR
esou
rceVie
w
OMSe
tTar
gets
PS/V
S/GS
SetT
extu
res
CreateRenderTargetView
Geometry ShaderGeometry ShaderPer-Primitive OperationsPer-Primitive Operations
Operates on entire primitivesOperates on entire primitives [with adjacency][with adjacency]
Material selection/setup to reduce Material selection/setup to reduce # of draw() calls# of draw() calls
Set up barycentrics to exceed # of Set up barycentrics to exceed # of interpolatorsinterpolators
Compute edge lengthsCompute edge lengths
Compute plane equationsCompute plane equations
Compute silhouette edgesCompute silhouette edges
GS Inputs:
1
0 4
5
2 3
0 1 2 3
Single-Pass Render-to-Single-Pass Render-to-CubemapCubemap
x
y z
uv
Geometry Shader
ID3D10ShaderResourceView::GenMips(…)
Single Pass Render-To-Single Pass Render-To-CubemapCubemap
Stream OutputStream Output
Writes GS Output to one or Writes GS Output to one or more buffersmore buffersDrawAuto() to draw streamed-out data of DrawAuto() to draw streamed-out data of variable size without CPU interventionvariable size without CPU interventionUses:Uses:
Intra-frame re-use Intra-frame re-use Skin/morph once, render manySkin/morph once, render many
Inter-frame re-use Inter-frame re-use Iterative/procedural Iterative/procedural geometry processinggeometry processingAll-GPU particle All-GPU particle systemssystems……
VertexShader
Rasterizer/Interpolator
GeometryShader
Texture
Texture
Stream Output
Predicated RenderingPredicated Rendering
Predicate draw’s and blit’s with Predicate draw’s and blit’s with results of asynchronous queriesresults of asynchronous queries
No CPU involvement required No CPU involvement required
Occlusion culling – render bounding box, Occlusion culling – render bounding box, predicate subsequent (complex) predicate subsequent (complex) rendering on occlusion query resultrendering on occlusion query result
SummarySummary
Windows Vista Direct3D GoalsWindows Vista Direct3D Goals
Windows Vista Direct 3D Windows Vista Direct 3D TechnologiesTechnologies
Community ResourcesCommunity Resources““Windows Development” MSDN ForumsWindows Development” MSDN Forums
http://forums.microsoft.com/msdn/default.aspxhttp://forums.microsoft.com/msdn/default.aspx
General, Graphics, Tools, Performance, and General, Graphics, Tools, Performance, and AudioAudio
Notification Alerts, Messages and RSS Notification Alerts, Messages and RSS FeedsFeeds
Integrated with Visual Studio 2005Integrated with Visual Studio 2005
Advanced SearchAdvanced SearchFAQs, Answered/Unanswered QuestionsFAQs, Answered/Unanswered Questions
[email protected]@microsoft.com
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.