Tools & Tech
RSS Feed
Resolve your resolves
Why unnecessary resolves should be your enemy
by Jon Story and Holger Gruen, AMD
An increased reliance on post-processing effects has made the resolve a common operation - but you might be surprised at the wasted resolves hidden in your code and the damage they're doing to your frame rate...
Over the last few years it has become common place for PC games to make use of Multi-Sample Anti-Aliasing (MSAA) to achieve higher quality rendering. MSAA is a very effective and efficient method for reducing the unsightly ‘jaggies’ that result from the triangle rasterization process. At the same time, most game engines also employ post processing techniques such as depth-of-field, motion blur, colour correction and refraction. Post-processing has become increasingly popular, as it provides a way to carry out complex computations, but only pay the cost for visible pixels. It is not unheard of for an engine to contain up to 20 passes, and these techniques usually require a copy of the main render target as a texture input.
Figure 1
If the engine is making use of MSAA, then the render target will need to be resolved before it can be used in the next pass. This is accomplished through calls to IDirect3DDevice9::StretchRect or ID3D10Device::ResolveSubresource, depending on which version of Direct3D is being used. As modern game engines tend to apply multiple post-processing techniques, it is easy to understand how the application could trigger a loop of resolves, as shown in Figure 1.
It is critically important to understand that a resolve is not a free operation, and that performing multiple resolves per frame can have a very serious impact on performance. This statement is true for all graphics hardware. To take a real world example, the developers of a recently released PC title managed to reduce their resolve count from a staggering 22 to just 12. This generated a saving of around 12 ms per frame, at a resolution of 1280x1024 with 4xAA.
The goal of this paper is to describe how to minimize the resolve count in the rendering pipeline without compromising the quality of post-processing effects or deferred shading techniques. The resolves that should be removed fall into two categories: redundant resolves and harmful resolves, and these will be described in detail later. But first, let’s consider the resolves that are necessary for good image quality.
USEFUL RESOLVES
We know that the use of MSAA render targets is only helpful when draw calls produce visible jaggies. In an ideal world the main geometry pass would be rendered in MSAA mode, and then resolved to a non-MSAA render target. Any subsequent post processing passes would all be completed in non-MSAA mode. This would therefore give rise to just a single resolve per frame.
There are, however, two reasons why a post processing technique may need to be performed in MSAA mode:
1. If a post processing technique enables subsample based depth testing, it can result in an update to some of the subsamples of a pixel.
2. In a similar way, if alpha blending is enabled, then subsample data is preserved through the blend operation.
In these cases it does indeed make sense to resolve the render target for further passes. However, these two examples are the exception and for full screen passes that do not enable depth testing or alpha blending, there is precious little point in using MSAA mode.
REDUNDANT RESOLVES
Figure 2
A technique that does not actually draw any geometry, other than a full screen quad, will usually write the same color to all subsamples in a MSAA render target as depicted in Figure 2. The reason for this is that the pixel shader is only run once per pixel and the whole pixel is covered. Effectively the MSAA buffer has been turned into a non-MSAA buffer, and every further resolve operation on this surface is redundant. Aside from the obvious redundancy, once the same color has been written to all subsamples of the corresponding pixels, note that the MSAA depth buffer does not actually match the silhouettes of the objects anymore.
Clearly the solution is to render these passes in non-MSAA mode, thus completely avoiding the need to perform resolves. The recommended way to avoid these unnecessary resolves is as follows:
Figure 3
1. Create the main frame buffer (swap chain) in non-MSAA mode.
2. Create an intermediate MSAA render target where the main scene geometry is rendered, and anything else that would result in jaggies.
3. Perform a resolve of the intermediate MSAA render target to a non-MSAA surface.
4. Ping pong between non-MSAA render targets for the remaining passes as shown in Figure 3.
To add a real world example to this discussion, the following sequence of passes was uncovered during the analysis of a recently released PC title:
1. Render the geometry pass into the main MSAA render target M
2. Resolve M into a non-MSAA render target A
3. Render A on to M using a full-screen quad
4. Resolve M into A
5. Render water to M
6. Resolve M into A for further post-processing
It is fairly obvious from an initial glance at this sequence, that steps 2 through 4 are totally redundant. In fact step 3 is actually harmful from a quality stand point, as it destroys the subsample color information. Clearly it is possible to jump directly from step 1 to 5, having removed no less than two resolve operations, while maintaining the subsample color information.
So why would the developer fail to spot this? The answer lies in the fact that modern engines are highly object oriented, and that several developers are making changes to the rendering code over time.
Apparently, step 3 was originally a valid post processing effect, and when it was changed, it effectively became just a copy operation which made steps 2 and 3 redundant. The resolve in step 4 was triggered because M was accidently added as an input to step 5.
As you can see, it is very easy to introduce redundant resolves into the rendering pipeline. It always pays to be on top of the various passes carried out during a frame, and is generally good practice to regularly inspect PIX dumps for unexpected behavior.
HARMFUL RESOLVES
It is common for deferred rendering techniques to store information such as depth, position, normal, velocity and material ID to an intermediate render target. If this is carried out in MSAA mode, then the data would need to be resolved before being put to use later in the frame. The problem here is that the fixed function resolve operation will simply perform an average of the subsamples. This is very unlikely to yield the developer’s intended result, and will most probably result in graphical artifacts.
Let us consider the case where material IDs are to be resolved. I think we would all have to agree that averaging material IDs is never going to make any sense, and that performing such an operation would, in a worst case scenario, produce invalid IDs. So how should we deal with this kind of data, when a standard fixed function resolve is clearly not the way to go?
In DX10 it is possible to write a pixel shader that can read the subsamples of an input texture. In the case of a deferred lighting technique, it would then be possible to accumulate all lighting calculations on each subsample, and then finally average the results. In this way the shader has effectively performed a custom resolve. DX10.1 capable hardware removes a further limitation by allowing access to the subsamples of the depth buffer, which can eliminate the need for a separate depth pass.
Another prominent example of a technique that suffers from using fixed function resolved data is non-linear tone mapping. The only correct way to perform tone mapping in a multi-sampling context is to tone map every subsample using a shader based custom resolve.
In DX9 it is not possible to do this, so it may be that the resulting artifacts have to be tolerated, although it should be said that the implementation of explicit super sampling could achieve similar results. For performance reasons it may be necessary to carry out post-processing with data produced by a harmful resolve, though this should be kept to a minimum.
CALL TO ACTION
It is very important to appreciate that a resolve is not a free operation – in fact it is a decidedly expensive procedure, and should therefore be kept to a minimum. Keep in mind that most resolves are either redundant or harmful. To avoid redundancy, remember to resolve the main MSAA render target as early as possible, and then work in non-MSAA mode for post processing effects. Write shader based custom resolves, to properly deal with high quality post processing and deferred rendering techniques. Remember that it’s easy to over look what is really happening among the various rendering passes, so regular analysis is essential to resolving your resolves!
FEEDBACK
We would welcome your feedback on any aspects of this paper, as well as any recommendations you may have for how we can better support developers with regard to this topic.
Please send your feedback to: jon.story@amd.com or holger.gruen@amd.com.
Other Tools & Tech
- Creative Ürban Suit
Jan 08 - Build Rome in a day
- KEY RELEASE: XSI ICE
Nov 18 - Inside the new visual XSI interface
- GUIDE: User Interface technology
Oct 13 - Our round up of the latest UI tools and middleware
- KEY RELEASE: Unity v2.1
Oct 10 - We take a look at the rapidly maturing mid-level game engine
- Epic Diaries: Bourne Again
Oct 08 - How UE3 helped power Bourne's small-screen debut
- Sulpha, so good
Sep 19 - SCEE's Oliver Hume unveils the firm's new PS3 audio tool
- Hands on advice
Aug 29 - TUTORIAL: Nintendo DS development
- Not Flash, Just Scaleform
Aug 26 - KEY RELEASE: Scaleform GFx
- TOOL FOCUS: Metaforic
Aug 20 - We look at the latest anti-piracy tool
- TOOL FOCUS: AI.implant
Aug 19 - Artificial intelligence package gets back into games
- TOOL FOCUS: Gamespy
Aug 18 - The latest on one of the industry's most popular online technologies
- Epic Diaries: August 2008
Aug 14 - An update on what's going on in the world of Unreal Engine 3
- A viewpoint from Nvidia on Larrabee
Aug 13 - The full, cautious and sceptical statement from Nvidia on next-gen graphics
- Bright rising Eastern star
Aug 06 - KEY RELEASE: Testronic Labs' MMO testing kit VENUS Blue
- Life in the Engine Room
Jul 25 - GAMEFEST 08: Unreal Engine 3 developers share experiences
- Character Building - Part 1
Jul 22 - TUTORIAL: Character Design
- Character Building - Part 2
Jul 22 - TUTORIAL: Character Design
- Latest Intel on the Make Something Unreal Contest
Jul 21 -
- Triggering the light fantastic
Jul 18 - KEY RELEASE: Fork Particle v2.5
- Physical exercises
Jun 20 - Why physics is now more than a gameplay gimmick
- Intelligent decisions
Jun 17 -
- Vicious Competition
Jun 16 -
- Heard About: Death Jr 2
Jun 16 - Looking at the franchise's audio migration from PSP to Wii
- The 'Force remains strong
Jun 13 - KEY RELEASE: We look at the evolution of Perforce
- Audio Q&A: MGS on DSP
Jun 11 - Xbox 360's audio guru Guy Whitmore quizzed
- Building a virtual office
Jun 10 - Multi-site development - part 2 of 2
- Decoding the Future
Jun 10 - Multi-site development - part 1 of 2
- Networking opportunities
May 20 - An overview of the development landscape for online games
- Horsepower for courses
May 12 - GUIDE: Game engines
- Heard About: Battlefield Bad Company
Apr 18 - Behind the scenes of EA DICE's next-gen sound design
- The Power of Touch
Apr 16 - A guide to using haptic devices for art and design
- Heard About: SingStar PS3
Apr 03 - London Studios' Dan Bardino on the production of Sony's singing game
- Sound for a pound
Mar 20 - Guide: Audio engines
- Autodesk's move into middleware
Mar 18 - Behind the scenes of the Kynogon acquisition
- Never Say Die
Mar 14 - An introduction to Havok Behaviour
- iPhone development
Feb 14 - An iPhone / iPod Touch programming primer
- The Epic Diaries: February
Feb 14 - Epic's monthly update on all things Unreal
- Enter the light
Feb 13 - KEY RELEASE: We look at Geomerics' Enlighten
- Striking the right pose
Feb 11 - Character animation tools round-up
- Where next for NVidia and Ageia?
Feb 07 - ANALYSIS: How the recent acquisition could affect developers
- Q&A: France's Play All initiative
Feb 05 - The nuts and bolts of building a shared tech framework
- Mobile Antix
Jan 16 - How one company plans to revolutionise mobile development
- Q&A: Microsoft Research Labs' Joaquin Quiñonero Candela
Jan 04 - On new XNA contest Silicon Minds and work with Lionhead and Rare
- Killer Characters
Jan 02 - An overview of the leading character animaton tools
- Part of the process
Dec 13 - Our round up of source control and build managers
- The Epic Diaries: December
Dec 07 - Epic's monthly update on all things Unreal
- Visual arts
Nov 23 - What's new in Microsoft Visual Studio 2008
- Brain Training
Nov 15 - An overview of the artificial intelligence field
- Security tools round-up
Nov 09 - Keeping your code locked and bolted
- Heard About: Sega Rally
Oct 16 - All about the audio in Sega's racing remake
- Poetry in motion
Oct 08 - The latest moves in the mocap market
- Heard About: Harry Potter and the Order of the Phoenix
Sep 19 - The audio production of the new movie tie-in
- In-house Party
Sep 12 - UK independents talk up the benefits of in-house tech
- Designing for Next-Gen Game Audio
Sep 05 - Rob Bridgett
- MMO Engine Round-Up
Aug 29 - Building the online planet
- Quick thinking
Aug 24 - Part 2 of 2: Further exploration of EA’s fast prototyping strategy
- Grand Rapids
Aug 23 - Part 1 of 2: How EA is implementing rapid prototyping
- Designing games for the Wiimote
Aug 22 - Making games for Nintendo's motion sensor
- Arcade Fire
Aug 21 - Stainless Games offers eleven top-tips for Xbox Live Arcade development
- Heard About: Heavenly Sword
Aug 14 - Ninja Theory and SCEE discuss the audio production of a PS3 epic
- Brief Encounters
Aug 07 - How to prep your outsourcing partners
- Lost in Translation?
Jul 19 - Guide to getting audio translation right
- Transition Tips
Jul 16 - Swordfish Studios' advice on getting ready for next-gen production
- Deal... or no deal?
Jul 06 - How to get a good contract
- 8 steps to a successful studio
Jul 06 - Simple advice for your business
- Succesful networking
Jul 04 - Online gaming best practices
- Avoiding crash and burn
Jul 04 - Ensuring staff stay happy
- Casual creations
Jul 04 - Justin Felker
- Sell your studio
Jun 28 - Nav Sunner















