Search Unity

Question How to check if a device supports rendering to texture?

Discussion in 'General Graphics' started by mikikubs, May 5, 2023.

  1. mikikubs

    mikikubs

    Joined:
    Apr 5, 2020
    Posts:
    14
    As my game was crashing on multiple devices, I came to an unexpected realization: some phones don't support rendering to image for some reason? So I just want a way to check if the device supports it. I understand there's a function
    SystemInfo.SupportsRenderTextureFormat(), but I'm not sure how to use it and I have a limited way of testing this on other devices and the documentation doesn't make it very clear. Or perhaps I should change the Color Format of the render texture?
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    766
    Hi, some devices support a RenderTexture format only for specific usage(s). You can find more information here.

    For example,
    Code (CSharp):
    1. using UnityEngine.Experimental.Rendering;
    2.  
    3. bool supportRender = SystemInfo.IsFormatSupported(GraphicsFormat.xxx, FormatUsage.Render);
    4.  
    5. if (!supportRender)
    6.     // we should change the RT to another format.
     
    mikikubs likes this.
  3. mikikubs

    mikikubs

    Joined:
    Apr 5, 2020
    Posts:
    14
    Thank you for your answer! I will look into it.
     
  4. mikikubs

    mikikubs

    Joined:
    Apr 5, 2020
    Posts:
    14
    Code (CSharp):
    1.     public bool SupportsRenderOfPausedMenuGameTexture()
    2.     {
    3.         return SupportsRender(pausedMenuGameTexture.depthStencilFormat, pausedMenuGameTexture.format);
    4.     }
    5.  
    6.     public static bool SupportsRender()
    7.     {
    8.         return SupportsRender(GraphicsFormat.R8G8B8A8_UNorm, RenderTextureFormat.ARGB32);
    9.     }
    10.  
    11.     public static bool SupportsRender(GraphicsFormat format, RenderTextureFormat renderTextureFormat)
    12.     {
    13.         return SystemInfo.IsFormatSupported(format, FormatUsage.Render) && SystemInfo.SupportsRenderTextureFormat(renderTextureFormat);
    14.     }
    Do you think this is a correct way of handling this? Should I pass RenderTexture.depthStencilFormat to the SystemInfo.IsFormatSupported() function, or something else? Thank you for explaining this and pointing me at a very right direction!
     
  5. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    766
    I think you can ignore the depth stencil format and check the color format only. Unity should find a compatible depth format for the RT.

    By the way, have you tried using
    GraphicsFormat.R8G8B8A8_SRGB
    for rendering? This format is widely supported on old mobiles and it should be fine to store colors (paused menu). "UNorm" is usually used to store non-color data like smoothness.
     
    mikikubs likes this.
  6. mikikubs

    mikikubs

    Joined:
    Apr 5, 2020
    Posts:
    14
    I will try it, thank you! I used that one only because it was set as default for my RenderTexture and I thought it would be appropriate. Thank you once again, so far my game has more errors per day than users per day xd (solely because of this render texture)
     
    wwWwwwW1 likes this.