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