PostProcessing icon indicating copy to clipboard operation
PostProcessing copied to clipboard

Fix to reduce the amount of allocations required when using MSVO and Dynamic Resolution

Open robinb-u3d opened this issue 5 years ago • 2 comments

The existing dynamic resolution strategy manually scales the temporary intermediate textures to the correct size required for the current dynamic resolution scale. This allows the effect to run correctly and for a given fixed scaling factor will keep the memory usage constant however if dynamic resolution is being scaled over time then every time it changes scaling factor the temporary intermediate textures will be reallocated causing an increase in memory pressure while this happens and possibly generating more VRAM fragmentation (depending on the platform).

This PR make the temporary intermediate textures be full size dynamic resolution textures themselves. The behavior of this PR and the existing behavior should match when dynamic resolution is not being used. However when dynamic resolution is being used this PR changes the following:

  • We now allocate the temporary intermediate textures at full size all the time so for a fixed dynamic resolution scaling of 0.5 this PR will increase VRAM usage as we will now allocate all textures at 1.0 size and then make sure of dynamic resolution to access a 0.5 scaled version using the same memory.
  • The temporary intermediate textures are now dynamic, this means they may have less chance of matching other temporary textures used by other systems and so increase the memory usage of this project.
  • Changing the dynamic scaling factor will no longer cause these textures to be reallocated thus VRAM usage should be consistent no matter what level of dynamic scaling factor is used and reduce memory fragmentation and allocation overheads.

Fixing this behavior showed up a bug in how Unity handles viewport setting when using dynamic resolution on some render targets at least on PS4 and possibly other dynamic resolution platforms. This PR requires a fixed Unity version to work correctly otherwise the temporary intermediate textures are not rendered to correctly when the scale is not 1.0.

robinb-u3d avatar Oct 16 '20 08:10 robinb-u3d

Ahh good testing Yamato, so the min supported version is 2018.4 and it appears that useDynamicScale in a RenderTextureDescriptor doesn't exist until 2019.1. This will make things more tricky to fix in a way that doesn't break the behavior in 2018.4. I would have to keep the existing behavior in 2018.4 so that it worked but allocated lots and then in 2019.4 make it move over to using dynamic intermediate targets.

robinb-u3d avatar Oct 16 '20 09:10 robinb-u3d

I think I see how to do that.

robinb-u3d avatar Oct 16 '20 09:10 robinb-u3d