Repository navigation
Description
Dynamic Resolution Rendering is an adaptive runtime technique to adjust the size of intermediate render targets in the application in order to ease fillrate pressure related performance problems. It was introduced by Intel at GDC in 2011.
The coarse idea with the technique is to at the beginning of each application frame, deduce if the application was GPU bound the previous frame, and if so, shrink the render targets by some %, either horizontally, vertically, or both.
This technique is mainstream, and a lot of performance heavy console games on PS4 and Xbox One utilize DRR to keep within framerate budgets, e.g. https://www.youtube.com/watch?v=ZZkSd3-uh40.
Likewise gaming engines widely support dynamic resolution on native APIs:
- Unity: https://docs.unity3d.com/Manual/DynamicResolution.html
- UE4: https://docs.unrealengine.com/4.27/en-US/RenderingAndGraphics/DynamicResolution/
and this technique is very appealing due to its ease of deployment, i.e. it requires no complex asset authoring or programmer intervention from game developers, hence its popularity.
A rather verbose end-user perspective dive into this technique can be seen at https://www.youtube.com/watch?v=180nuQJccTA .
The "cheap way" technique for implementing this kind of on-the-fly rescaling is to allocate the largest render target that will be needed, and then use the viewport function (glViewport() etc.) to choose a subrectangle of the full render target at each frame depending on the performance characteristics.
This works, but has major drawbacks that shaders that sample such render targets now need to carry source UV rescaling factors, and depending on the sampling technique needed, may need to forego hardware texture filtering and manually implement border/wrap sampling. If an application uses a lot of shaders, this can cause an awkward amount of maintenance necessary to set up the custom UV scaling, and/or lowered performance due to custom sampling.
The "modern way" to implement DRR is to create texture views with the given size. Microsoft has an article about how to achieve this with Direct3D 12, by enabling developers to allocate one big chunk of memory for the largest sized render target, and then recreating a texture to that memory area each frame. My understanding is that Vulkan and Metal do the same, though haven't worked with those APIs in detail to dig up what the exact API names there is.
I was looking through the WebGPU spec on how texture views are created, but was not able to reason that WebGPU would support the modern way for DRR. I wonder if I missed this? Or if not, would it be possible to spec this kind of functionality into WebGPU?
Sidenote: dynamic performance techniques like this rely a solid support from the computing platform to allow continuously evaluating whether a game is CPU bound or GPU bound or both. Simply measuring if a game title is under 60fps is not enough, because the game could be fully CPU bound, and reacting to that by lowering rendering resolution would cause worse visual quality without any performance gain.
In other words, engines that implement support for dynamic performance do want to continuously measure GPU load, so if such facilities were not available due to security concerns (items like #2218 or #2191), or partial hardware availability concerns (items like #1956, #2046, #2156), that would prevent implementing Dynamic Resolution Rendering altogether.
Activity
Kangz commentedon Dec 2, 2021
There is no explicit memory management in WebGPU so it's not possible to do resizing within the same allocation. There's been ideas in a similar spaces described before like #63 but nothing concrete in the spec. But also browsers should be doing suballocations themselves for some kinds of resources, so destroying / recreating the texture might be cheap enough. (since internally it would end up calling
D3D12Device::CreatePlacedResourcelike the article you linked does)To be honest I'm not sure how WebGPU would support the usecase you describe without a concept special-cased for it, because we can't do any kind of manual memory management (because of the API needs to be asynchronous). If there's a way to do it with UV scaling and viewport cropping it looks mildly annoying but maybe not worth adding a whole new concept for it?
There's no ubiquitous support for timestamps in the APIs we target, however you should be able to get some kind of timestamps on all desktop GPUs and a large fraction of mobile devices, if browsers choose to expose it. In this case, even if the resolution is quantized, I think you'd be able to measure the GPU load and adjust things as needed. But you'd still need a fallback if the extension is not available.
kvark commentedon Dec 2, 2021
This is an interesting read, thanks @juj for filing!
Honestly, I don't find the downsides of going with UV scaling that scary, for the following reasons.
First, we are talking about sampling from a screen-sized texture only, not any texture. The more "deferred" your pipeline is, the more post-process it has, the more it affects you. Even then, we are talking about just a handful of different views sampled this way. This isn't involving a variety of shaders, it should be straightforward to do.
Secondly, postfx and gbuffer passes don't generally start off some normalized UV coordinates. They can do
textureLoad, which doesn't change for this. Or they can use[[frag_coord]]scaled by the inverse size. This is something engines already do, as far as I understand, so this approach already requires you to pass in the target size in uniforms - nothing changes for it if you go DRR.TL;DR: we might need to keep this on the radar for any future proposals of memory pools, but for now (i.e. V1 and nearest future) this shouldn't be our concern.
juj commentedon Dec 13, 2021
Thanks for the replies - After consulting our core graphics team more around this area, the consensus was that the main difficulty here for Unity is around encapsulation: in Unity users can (and often do) author shaders of their own, and the manual viewport UV scaling based method leaks this abstraction to the users to need to worry about, and Unity has a history of a lot of existing shader code - which would not be compatible unless rewritten.
Unity has multiple distinct renderers (e.g. "built-in", URP, HDRP and Hybrid) and The Unity HDRP renderer backend has had an opportunity to come up with a custom framebuffer sampling API to ensure all user shaders will be able to account for DRR, but e.g. the built-in renderer does not have this capability.
However the understanding is that most WebGPU users would be looking to specifically enable using Unity HDRP on the web, therefore this would not be a blocking issue then. So happy to close this issue out.