Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

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

Draft
wants to merge 5 commits into
base: v2
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions PostProcessing/Runtime/Effects/MultiScaleVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,19 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
// Adjust the scaled dimensions based off the dynamic resolution resolution used at the moment.
m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
m_ScaledHeights[0] = camera.scaledPixelHeight;
#endif

#endif
float widthScalingFactor = ScalableBufferManager.widthScaleFactor;
float heightScalingFactor = ScalableBufferManager.heightScaleFactor;
// L1 -> L6 sizes
for (int i = 1; i < 7; i++)
{
int div = 1 << i;
m_Widths[i] = (m_Widths[0] + (div - 1)) / div;
m_Heights[i] = (m_Heights[0] + (div - 1)) / div;
m_ScaledWidths[i] = (m_ScaledWidths[0] + (div - 1)) / div;
m_ScaledHeights[i] = (m_ScaledHeights[0] + (div - 1)) / div;
// Scaled width and heights have to match their calculations like will happen with dynamic resolution otherwise with odd numbers you can get a difference between what the dynamic resolution version
// generates and what we use here.
m_ScaledWidths[i] = Mathf.CeilToInt(m_Widths[i] * widthScalingFactor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just comparing the maths to what the Switch does for scaling, Switch clamps the values between 1 and Width or 1 and Height. That's probably just the switch code being overly cautious e.g. the scale factor shouldn't be more than 1, but just double checking that wouldn't be needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I've checked the engine code and the scaling factors are clamped to a max of 1 so we shouldn't need to clamp on the top end but I suppose it's possible this will produce a 0 sized render target in some cases which it sounds like Switch catches, I'm not sure if we catch this case on all platforms and might end up with a 0 sized RT which I don't imagine would produce good results.

m_ScaledHeights[i] = Mathf.CeilToInt(m_Heights[i] * heightScalingFactor);
}

// Allocate temporary textures
Expand Down