Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Showcase Community FSR support for the Built-In Renderer

Discussion in 'General Graphics' started by tatoforever, Aug 4, 2021.

  1. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    I went ahead and implemented FSR already, works on builtin with OnRenderImage and also have a PPStack version that should works on all render pipelines:
    https://github.com/tatoforever/AMD_FSR
     
  2. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    Thats amazing @tatoforever ! Thanks for making this also available for Default RP.
     
  3. yukosan

    yukosan

    Joined:
    Mar 12, 2020
    Posts:
    2
    Thanks for sharing. @tatoforever
    I tried this but performance dropped even more.
    Tested 2019.4.18f1 (Built-in Renderer) - AMD RX 480 GPU
     
    Last edited: Sep 2, 2021
    tntfoz likes this.
  4. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Same here unfortunately with 2019.4.30f1 and built-in pipeline, using nVidia RTX 2080.

    @tatoforever are you able to share a minimal project on your GitHub just to sanity check with? Thanks!
     
  5. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    I'm going to add a project with a free Ocean Shader package that I found on the web, it showcases clearly differences between AMD FSR and without it.
    Btw, I updated my latest implementation for both PPV2 stack and OnRenderImage versions. The new changes now is that im downscaling the scene by rendering it directly to a temp render target for OnRenderImage and using DynamicResolution to render the scene to a smaller RT on PPV2 stack version. There's not actual change to the screen resolution.
     
    Lars-Steenhoff, tntfoz and atomicjoe like this.
  6. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Last edited: Jun 18, 2023
  7. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Many thanks @tatoforever this new version works great! Very much appreciate the time you've spent getting FSR working with the built-in pipeline.
     
    tatoforever likes this.
  8. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Thanks! There's a new update some moment ago that add support for half precision. If your target platform/hardware support it, you might benefit a lot from it.
    Also cudoz to @atomicjoe, he's been helping playtesting and contributing a bit to it too.
    Next is URP support but I can't find a proper documentation on URP to create custom PP. I know for sure that (depending on the URP version you have) it can support PPV2 and my implementation ships with a PPV2 version but is much slower than the OnRenderImage One.
     
    Last edited: Sep 15, 2021
    tntfoz, sameng and atomicjoe like this.
  9. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
    PPV2 for URP is deprecated in 2019.3 onwards (IIRC). There's a new, much faster, much more capable system for post-processing now, but it's totally undocumented of course.
     
    tatoforever likes this.
  10. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Thanks for making this available! However I tried it, is your implementation not compatible for macOS Metal? I thought that FSR was platform agnostic. I just get a black game view.
     
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Does it work on Editor (Metal mode)?
     
  12. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Unfortunately not. I'm on an intel mac, latest macOS, tried a few different unity 2020.3 LTS, same result.

    I looked into the frame debugger and it looks like the OutputTexture just isn't being written to. It's just black. When I do a raw Bit(src, dest) everything works (the rendered src is low res)

    I tried changing Upscale() in the compute shader to "OutputTexture[pos] = AF4(1,1,1,1)" but weirdly the OutputTexture is still black. So I think it's just not being written to by the KMain shader.

    When I disable the FSR component, the image shows up.

    Same thing with the PPv2 version of the effect. Let me know if there's anything else I can provide.
     
  13. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Do you know if your GPU support compute shaders and half precision registers?
     
  14. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Definitely supports compute shaders and I'm assuming it supports half precision.

    It's a 2019 16" macbook, Radeon Pro 5500.
    I also just tried on my other machine, a 2016 macbook with a Radeon Pro 460--same result.
     
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Do you have a windows machine where you can try it? Maybe is a limitation of AMD FX it self, cause I don't see why it shoun't work on your machine if it supports Compute Shaders well.
     
  16. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Maybe Metal doesn't like to have the camera render texture switched like that...
    Try THIS VERSION, it uses an auxiliary camera to render instead.
    Be sure to check it ON PLAY MODE.
     
    tatoforever likes this.
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    He said he also tried PPV2 and the problem persist. The scene is rendered to a temp rendertexture only OnRenderImage version, on PPV2 is all DynamicResolution.
     
    atomicjoe likes this.
  18. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Oh, then it's not gonna fix it :p
    @sameng try THIS VERSION of the compute shaders, that's the one I use on Android GLES and Vulkan without issues.
     
    tatoforever likes this.
  19. sameng

    sameng

    Joined:
    Oct 1, 2014
    Posts:
    184
    Thanks for sharing! Unfortunately still doesn't work :(

    See attached image of the Frame Debugger.


    Also, I noticed a warning. Maybe it's just a Metal issue?

    Unknown preprocessor directive 'extension' at kernel KMain: ffx_a.hlsl:570

    I also tried commenting out all the #extension lines, and the warnings all go away, but it's still black.
     
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Is probably a driver/metal thing. If you can try on a windows machine that might confirm it.
     
  21. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    For what it's worth, AMD itself doesn't promote FSR to be compatible on Metal, instead their site says:
    "Works with both DirectX® 11, 12 and Vulkan® APIs."
     
  22. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    It's working on GLES3 on Android too, just to confirm it.
     
  23. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Could you make a build for OpenGL, GLCORE, Vulkan or even run your macbook on windows using Bootcamp?
    That way we would know for sure if it's because of Metal or because of these specific graphic cards.
     
  24. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    ... how well? I wonder if it's good on switch too?
     
  25. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Using the half precision modified computer shaders, on the Nvidia Shield (which has the same SoC as the Switch) at a scale factor of 1.3 on 1080p res, the upsampling is not noticeable and the performance is quite higher than at native res. (enough to go from 54fps to 60fps rock solid with vsync on my test scene)
    This is WITHOUT sharpening (which is faster).
    On my tests, sharpening is only noticeable and useful on 1440p and 2160p resolutions, at any scale factor. So you can safely disable the sharpening pass on resolutions lower than 1440p and boost performance.
    Also, the upsampling is not worth it at resolutions lower than 1080p: it degrades the image too much and is too expensive.
    Even at 1080p res, the scale factor should only be at 1.3 and never more, otherwise the degradation is too much.
    So, YES, for the Switch, it should be very useful for dock mode.
    Not useful on handheld mode though.

    Scale factor 1.3 equals 1440 x 810 render resolution on a screen resolution of 1920 x 1080.
     
    Last edited: Sep 17, 2021
  26. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    One more thing:
    This upsampler NEEDS a very high quality antialiasing, otherwise it's worthless.
    For that, you can either use MSAA x4 or better x8, or you must use a temporal antialiasing at maximum quality. It Doesn't work with FXAA alone. (but you can use it to increase MSAA quality on the cheap)
    I haven't tried it with Unity's TAA, since it's integrated in Unity's Postprocess Stack (which I don't use), but adding either MSAA or TAA does have an impact on performance, so this upsampler is only really useful if you were already going to use MSAA or TAA.
    Otherwise, it's more performant to just use FXAA and render at native resolution.
     
    hippocoder and tatoforever like this.
  27. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I tried and this looks pixelated. I loaded the scene with the water. Is there a trick to it?
     
  28. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Well, yes, you need Temporal Antialiasing for it to work on textures, surfaces and shaders, since MSAA only works on edges of polygons.
    Also, specular highlights are prone to aliasing very easily and can only be solved with temporal antialiasing.
     
    PutridEx likes this.
  29. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    doesn´t the script by default have Temporal Antialiasing enabled? At least that´s what it's set on the editor. And it still looks very pixelated
     
  30. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    No. The script doesn't do any antialiasing.
    If you use it with Unity's post process stack, then you can enable it there.
     
  31. tntfoz

    tntfoz

    Joined:
    Sep 29, 2016
    Posts:
    129
    Thanks again! You and @atomicjoe are doing awesome work!
     
    atomicjoe likes this.
  32. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    The merit of the port goes all to @tatoforever , I just tuned it. :)
     
  33. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    maybe a tutorial on the scripts would be helpful. There is zero documentation.
     
  34. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    1- put AMD_FIDELITY_FX_FSR script on your camera
    2- set the scale factor as needed: higher values = less input resolution and hence, lower quality
    3- enable sharpening if wished
    The End.

    Also, move the cursor over each settings to get more info as tooltips.
     
  35. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
  36. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Yeah but for instance there is no mention of the temporary antialising setting or anything on those 3 steps you mentioned. All the settings on those 3 steps are on the demo scene and it looked horrible.
     
  37. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I don't know if you have noticed but this is a FREE port of an AMD technique.
    If you want to know how to best use it, go and read the AMD documentation or don't use it.
    If you want to complain about the results, go to AMD and complain to them.
    You would know everything there is to know about FSM if you had read the AMD documentation I linked up there.
    Everybody here is doing work for free.
    You should appreciate it instead of complaining like an entitled 5 year old.
     
  38. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    wtf. I just said there is no documentation and without it is very hard to get it to work properly. I read the AMD documentation and obviously, it has no Unity references. That's why I asked for help and suggested adding a tutorial. Chill a bit.
     
  39. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Dude, I have literally said everything there is to it up there. I don't know what else you want!
     
  40. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,240
    Very excited to try this! On my GTX 1060, I get a dramatic reduction with the script (from 19ms to 13ms) in the water demo. But with the PPV2 version, even after enabled Dynamic Resolution on the camera (and Frame Timings on player settings), I don't see any improvement when enabling the AMD FSR component on that PPV2 component. Any tips? Or maybe it's fine just to use the script version (would be simpler anyways in our game....)

    Also, the readme says: "AMD recommends to run FSR just after Anti-Aliasing and before any other post processing that add noise, banding or distort the image" -- but in the water demo, the AMD FSR script is above the PPV with TAA....isn't that opposite what this tip says to do? (Or do I totally have that backwards?)

    And thanks so much, tatoforever, for doing this!
     
  41. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The algo uses antialiasing to determine where edges are when upscaling, so regarding after antialiasing, it's not about the performance especially - it's about the quality.
     
  42. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    Hi - just want to say thanks very much for this BUT:

    From my initial experiments using the version at github (I have not yet tried dropbox) with both 2018.4 and 2019.4 on a windows it laptop 1070mobile GPU DX12 I get the following results using frame debugger / stats:

    1) OnRender camera filter - works, reduces camera rendering resolution depending on scale factor slider and speeds up frame rate in water scene. Does not allow PPV2 effects to display however.
    2) As a component of PPV2, runs and executes shaders but does not scale down the camera rendering resolution so no speed benefit (possibly slower actually I suppose as the upsampling is not running on a lower res input). This is probably a unity issue

    I agree with @gecko that from my understanding the PPV2 filter is in the wrong place of the stack, i.e. at the end with AfterStack when presumably it should be BeforeStack ? This is an easy code change however.

    I will have a go with the dropbox links above later today. Would love to get this working with PPV2!
     
  43. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    The dropbox versions are the same as the github version for PPV2.

    EDIT: Fixed to support PPV2. Thanks @jamespaterson :)
     
    Last edited: Oct 8, 2021
  44. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    Update: Using the modified code provided by the authors on dropbox here:

    https://www.dropbox.com/s/0yr9liu558aw942/AMD_FSR_ALTERNATIVE.zip?dl=0

    I was able to get FidelityFX running with PPV2 and downsampling with 2019.4. Huzzah! I might also work on 2018.4 (untested). Issues: PPV2 runs in the downsampled space, before upsampling. This, from the docs of FidelityFX is not how it is supposed to work I think. It also means screen-space effects such as grain scale with the scaling of FidelityFX.
    I was able to hack together a little solution to this by taking the render buffer output from the AUX and adding it in as another PPV2 filter, meaning it could run before e.g. grain etc which I think is closer to how it is supposed to work.

    However (and this may be fixable) at the moment the pipeline implies sRGB input <> output, so HDR appears to be lost. This makes it difficult to do glowing objects using bloom etc.
     
    imDanOush likes this.
  45. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    Sorry, this came in whilst I was posting above. I think the difference is the AUX version where the camera renders to a rendertexture and then is displayed with a proxy allows the dynamic camera scaling to work in unity.
     
  46. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Oh, you may be using a combination of OnRenderImage + PPV2 then.
    I'm not sure how it will perform, since the alternative version is not meant to be used like that (hence why it removes HDR) and it will potentially be doing more texture copies than strictly needed, but if it works, it works! :p
    (I made the dropbox versions)
    I could probably look into it.
    I don't personally use the PPV2 anymore, since I made my own postprocess code, but I can understand the need for it.
     
    jamespaterson likes this.
  47. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    Thanks for the dropbox code it was very helpful. :) I was able to get HDR bloom to work by modifying the creation of the rendertextures in AMD_FIDELITY_FX_FSR_ALTERNATIVE to DefaultHDR rather than Default. From the docs of FidelityFX it is probably not meant to work with input like this. But I am minded to roll with it anyway because my game is mostly explosions and glowing stuff. Cheers!

    Heres a screenshot with PPV2 with too much bloom, vignetting and grain + hacked HDR FidelityFX.
    upload_2021-10-8_13-39-17.png
     
    atomicjoe likes this.
  48. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    There is NEVER too much bloom. :D
     
    jamespaterson likes this.
  49. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    I have patched the dropbox alternative version to include your fix for PPV2 as an option.
    Nice feedback! :)
     
    imDanOush and jamespaterson like this.
  50. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    395
    :) My pleasure and thanks again to you and everyone else for your work on this, really helpful!