Post on 14-Jan-2016
description
transcript
Introduction to Direct3D 10 Course
Introduction to Direct3D 10 Course
Porting Game Engines to Direct3D 10: Porting Game Engines to Direct3D 10:
Crysis / CryEngine2Crysis / CryEngine2
Carsten WenzelCarsten Wenzel
OverviewOverview
• IntroductionIntroduction
• D3D10 & CryEngine2D3D10 & CryEngine2
• Porting, integration issues and optimizationsPorting, integration issues and optimizations
• Random bitsRandom bits
• ConclusionConclusion
IntroductionIntroduction
• Early adaptationEarly adaptation
• Spec reviews / discussions started in 2005Spec reviews / discussions started in 2005
• Actual work began middle 2006Actual work began middle 2006
• Support from MS and IHVs was crucialSupport from MS and IHVs was crucial
D3D10 in context of a multi-platform engine (1/3)D3D10 in context of a multi-platform engine (1/3)
• API redesign offers a more concise view on API redesign offers a more concise view on how modern graphics hardware workshow modern graphics hardware works
• For the sake of performance it “offloads” a lot For the sake of performance it “offloads” a lot of responsibility to the API userof responsibility to the API user
D3D10 in context of a multi-platform engine (2/3)D3D10 in context of a multi-platform engine (2/3)
• CryEngine2 is designed to be multi-platformCryEngine2 is designed to be multi-platform
• Render implementations share one interface Render implementations share one interface and a lot of common codeand a lot of common code
– State & resource managementState & resource management
– Draw list processingDraw list processing
– Shader subsystem, etc.Shader subsystem, etc.
D3D10 in context of a multi-platform engine (3/3)D3D10 in context of a multi-platform engine (3/3)
• Certain API changes required special considerationCertain API changes required special consideration
– State objectsState objects
– Shader model 4.0Shader model 4.0
– Constant buffersConstant buffers
– Strict API validation (shader linkage, etc)Strict API validation (shader linkage, etc)
– Buffer updatesBuffer updates
• Support for new features Support for new features
– E.g. Geometry Shader, Stream Out, Texture ArraysE.g. Geometry Shader, Stream Out, Texture Arrays
Porting and making it work (1/2)Porting and making it work (1/2)
• Render code separates platform / API Render code separates platform / API dependent parts from independent partsdependent parts from independent parts
• D3D10 renderer specializes base rendererD3D10 renderer specializes base renderer
• Inherits interface and all common codeInherits interface and all common code
Porting and making it work (2/2)Porting and making it work (2/2)
• Platform / API dependent parts wrapped Platform / API dependent parts wrapped and called from common codeand called from common code
• Provided stubs implemented one at a timeProvided stubs implemented one at a time
• #ifdef#ifdef where API characteristics were where API characteristics were awkward to map to common code flowawkward to map to common code flow
Special considerations (1/5):State objects
Special considerations (1/5):State objects
• Need fine grained control over render states!Need fine grained control over render states!
• Wrap state manipulationWrap state manipulation
• Internally caches state objectsInternally caches state objects
• Currently build state objects on demandCurrently build state objects on demand
• Pre-warming cache might be worthwhilePre-warming cache might be worthwhile
Special considerations (2/5):Shader model 4.0
Special considerations (2/5):Shader model 4.0
• Use custom shader / effect systemUse custom shader / effect system
• Updated to support new API features and Updated to support new API features and enhanced HLSL syntaxenhanced HLSL syntax
• Query resource bindings Query resource bindings vvia Shader Reflectionia Shader Reflection
• Compile existing shaders as is (/Gec)Compile existing shaders as is (/Gec)
• Refactored to utilize load balancing Refactored to utilize load balancing
• Still use shader cacheStill use shader cache
Special considerations (3/5):Constant buffers
Special considerations (3/5):Constant buffers
• Group constants by frequency of updateGroup constants by frequency of update
• Each group maps to a unique CB indexEach group maps to a unique CB index
• Constants bound via semantic which encodes group idConstants bound via semantic which encodes group id
• Allows preprocessor to move constants into their Allows preprocessor to move constants into their appropriate CB scopeappropriate CB scope
– Existing shaders automatically benefit from efficient bindingExisting shaders automatically benefit from efficient binding
– Source shader scripts devoid of API specific annotationsSource shader scripts devoid of API specific annotations
– Shader authors don’t have to worry about APIShader authors don’t have to worry about API
Special considerations (4/5):Strict API validation
Special considerations (4/5):Strict API validation
• API rigorously checks how user drives itAPI rigorously checks how user drives it
• Simplifies lower API / driver levelsSimplifies lower API / driver levels
• Example: Shader linkageExample: Shader linkage
– Vertex layout / output signature has to match input Vertex layout / output signature has to match input signatures of following shadersignatures of following shader
– Dimension of each passed element has to match dimension Dimension of each passed element has to match dimension expected in following shaderexpected in following shader
– Took some time to clean up / unify signaturesTook some time to clean up / unify signatures
– Nice side effect: Signature-fixed shaders run faster on DX9Nice side effect: Signature-fixed shaders run faster on DX9
Special considerations (5/5):Buffer updates
Special considerations (5/5):Buffer updates
• Update methods for truly static / dynamic Update methods for truly static / dynamic buffers remain as in D3D9buffers remain as in D3D9
• Occasional updates of static buffers can Occasional updates of static buffers can cause severe pipeline stallscause severe pipeline stalls(e.g. updating terrain)(e.g. updating terrain)
• Staging resources as intermediate storageStaging resources as intermediate storage
• This way mesh update can be pipelinedThis way mesh update can be pipelined
Random DX10 bits used in CryEngine2Random DX10 bits used in CryEngine2
• GS used for particles and shadowsGS used for particles and shadows
• Viewports for texture atlasViewports for texture atlas
• Filtered texture lookups in vertex shader Filtered texture lookups in vertex shader (FFT water)(FFT water)
• Multi-sampled texture lookupMulti-sampled texture lookup(HDR post-processing)(HDR post-processing)
• Sample depth from z bufferSample depth from z buffer
• Render to volume textureRender to volume texture
• New D3D10 features are great New D3D10 features are great
• Perf improvements are definitely therePerf improvements are definitely there
• Expect several code revisions to drive the Expect several code revisions to drive the API in the most efficient wayAPI in the most efficient way
ConclusionConclusion
More detailsMore details
• [1] “Finding Next-Gen”, Martin Mittring, [1] “Finding Next-Gen”, Martin Mittring, SIGGRAPH 2007SIGGRAPH 2007
– Part of course 28, “Advanced Real-time Rendering Part of course 28, “Advanced Real-time Rendering in 3D Graphics in Games”in 3D Graphics in Games”
– Wed Aug 8Wed Aug 8thth, Room 7AB, 8:30 am - 5:30 pm, Room 7AB, 8:30 am - 5:30 pm
• [2] “Real-time Atmospheric Effects in Games [2] “Real-time Atmospheric Effects in Games Revisited”, Carsten Wenzel, GDC 2007Revisited”, Carsten Wenzel, GDC 2007
– Slides and course notes available onlineSlides and course notes available online
AcknowledgementsAcknowledgements
• Crytek R&D Graphics GroupCrytek R&D Graphics Group
• Many thanks to MS, NVIDIA and ATI for the Many thanks to MS, NVIDIA and ATI for the supportsupport
Questions?Questions?