Search Unity

Dynamic resolution on Windows standalone

Discussion in 'Scripting' started by SunnySunshine, May 18, 2021.

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    I'm trying to get dynamic resolution working on Windows standalone, but no matter what I do, the resolution remains unchanged.

    I have a very simple setup with a camera with "Allow Dynamic Resolution" checked, and then a script attached which invokes ScalableBufferManager.ResizeBuffers.

    Code (CSharp):
    1. public class TestDynamicResolution : MonoBehaviour
    2. {
    3.     [Range(.5f, 1f)]
    4.     public float renderScale = .5f;
    5.  
    6.     void Update()
    7.     {
    8.         ScalableBufferManager.ResizeBuffers(renderScale, renderScale);
    9.     }
    10. }
    I've also enabled Frame Timing Stats (not that it should matter though since I'm invoking ResizeBuffers "manually" anyway).

    This doesn't seem to work though, neither in editor nor in build.

    What am I doing wrong?
     
    Last edited: May 18, 2021
  2. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    Submitted a bug report #1337161.
     
  3. Jh2556

    Jh2556

    Joined:
    Sep 29, 2014
    Posts:
    18
    I'm also seeing the same behavior. :/ I can't find your bug, did you ever hear back from Unity on it?
     
  4. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    I actually got it working. The problem was that you need to force enable DX12. It even says in the docs that you need DX12 but it's easy to miss. You can do this by going to player settings and unchecking "Auto Graphics API for Windows" and then adding DX12 and putting it on top.

    The problem is that DX12 implementation in Unity isn't as optimized as other versions, so just by enabling it you will lose frames. So essentially what you're doing is reducing resolution while gaining 0 frames, i.e. there's no reason to do it. I've also noticed that some things don't work or will cause Unity to crash while DX12 is enabled, so I really can't recommend changing the API.

    So afaik there's really no officially supported way to have dynamic resolution in Unity that actually works as desired. (And no, rendering to render texture and blitting to screen doesn't work since that isn't compatible with a ton of screenspace effects).
     
    sirleto and jake1025 like this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,192
    Dynamic resolution for the SRPs works correctly without DX12.
     
    SunnySunshine likes this.
  6. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    That's great, thanks for pointing that out.

    Will come in handy for my next project.
     
  7. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    In URP you can adjust renderScale like this:
    Code (CSharp):
    1. using UnityEngine.Rendering;
    2. using UnityEngine.Rendering.Universal;
    3. public class TestDynamicResolution : MonoBehaviour
    4. {
    5.     [Range(0.25f, 2f)]
    6.     public float renderScale = 1;
    7.     void Update()
    8.     {
    9.       UniversalRenderPipelineAsset urp = (UniversalRenderPipelineAsset)GraphicsSettings.currentRenderPipeline;
    10.       urp.renderScale = renderScale;
    11.     }
    12. }
     
    SunnySunshine likes this.
  8. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    Was just gonna say that dynamic resolution doesn't seem to work in URP unless DX12 is activated. But this solution seems to work just fine in editor and build, so thanks for sharing that @polemical. Odd that this isn't included in the documetation. Rather, the DX12 only method is advocated.

    In HDRP it works just fine according to the documentation, but not in Unity 2020. No changing of any HDRP settings seems to work in Unity 2020 though. I couldn't even change from deferred to forward in a completely new, clean HDRP project, so, yeah, yikes... Another reason not to touch anything not LTS I suppose.
     
    Last edited: Jun 12, 2022
    adamgolden likes this.
  9. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    I want to add that 2020.3 does indeed work, it's just that the default HDRP project is set up differently.

    In the 2019 HDRP project, there are no individual renderpipline assets tied to different quality settings (there is only 1 quality setting, and it doesn't have a renderpipline asset). In 2020.3 however, there are multiple quality levels, each one with its own individual renderpipline asset. That's why changing the renderpipline asset referenced in the "Graphics" settings doesn't do anything, because the ones used in "Quality" options were overriding it.

    Thanks to Unity staff for pointing this out in email exchange!
     
  10. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    i am still using 2019 LTS in 2022, as well as standard built in render piple, and it seems to make no sense to use ScalableBufferManager.ResizeBuffers() here. sadly :-(

    with dx11 my super heavy loaded multi million poly scene with lotsof overdraw (jungle) runs so much better with dx11 than with dx12 ... so why should i switch to then dynamically reduce my resolution of render targets ??
     
  11. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    Indeed, for built in there's no advantage to doing so. I haven't tested how resolution scaling works in URP and HDRP, but that might be something to check out. That together with FSR or DLSS may be the approach to go if you wanna try to squeeze out more frames.
     
  12. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Great, thanks for this. Also you are not kidding about the horrible DX12 performance when using the built-in renderer. DX12 is completely unuseable, and makes Dynamic resolution pointless on built-in. I wonder if this will be updated in 2022? I'm not holding my breath.
     
    SunnySunshine likes this.