Skip to content

Commit

Permalink
com.unity.render-pipelines.core@11.0.0 in Unity 2021.1.3f1
Browse files Browse the repository at this point in the history
## [11.0.0] - 2020-10-21

### Added
- Support for the PlayStation 5 platform has been added.
- Support for the XboxSeries platform has been added.
- New API in DynamicResolutionHandler to handle multicamera rendering for hardware mode. Changing cameras and resetting scaling per camera should be safe.
- New API functions with no side effects in DynamicResolutionHandler, to retrieve resolved drs scale and to apply DRS on a size.

### Fixed
- Fixed the default background color for previews to use the original color.
- Fixed a bug in FreeCamera which would only provide a speed boost for the first frame when pressing the Shfit key.
- Fixed spacing between property fields on the Volume Component Editors.
- Fixed ALL/NONE to maintain the state on the Volume Component Editors.
- Fixed the selection of the Additional properties from ALL/NONE when the option "Show additional properties" is disabled
- Fixed ACES tonemaping for Nintendo Switch by forcing some shader color conversion functions to full float precision.
- Fixed missing warning UI about Projector component being unsupported (case 1300327).
- Fixed the display name of a Volume Parameter when is defined the attribute InspectorName
- Fixed ACES tonemaping on mobile platforms by forcing some shader color conversion functions to full float precision.
- Fix crash on VolumeComponentWithQualityEditor when the current Pipeline is not HDRP
- Calculating correct rtHandleScale by considering the possible pixel rounding when DRS is on
  • Loading branch information
Unity Technologies committed Apr 7, 2021
1 parent d84c562 commit b3ef030
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Support for the PlayStation 5 platform has been added.
- Support for the XboxSeries platform has been added.
- New API in DynamicResolutionHandler to handle multicamera rendering for hardware mode. Changing cameras and resetting scaling per camera should be safe.
- New API functions with no side effects in DynamicResolutionHandler, to retrieve resolved drs scale and to apply DRS on a size.

### Fixed
- Fixed the default background color for previews to use the original color.
Expand All @@ -19,7 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed ACES tonemaping for Nintendo Switch by forcing some shader color conversion functions to full float precision.
- Fixed missing warning UI about Projector component being unsupported (case 1300327).
- Fixed the display name of a Volume Parameter when is defined the attribute InspectorName
- Fixed ACES tonemaping on mobile platforms by forcing some shader color conversion functions to full float precision.
- Fix crash on VolumeComponentWithQualityEditor when the current Pipeline is not HDRP
- Calculating correct rtHandleScale by considering the possible pixel rounding when DRS is on

## [10.2.0] - 2020-10-19

Expand Down
2 changes: 1 addition & 1 deletion Editor/Volume/VolumeComponentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void CreateComponentTree(List<Element> tree)
{
tree.Add(new GroupElement(0, "Volume Overrides"));

var types = VolumeManager.instance.baseComponentTypes;
var types = VolumeManager.instance.baseComponentTypeArray;
var rootNode = new PathNode();

foreach (var t in types)
Expand Down
262 changes: 208 additions & 54 deletions Runtime/Common/DynamicResolutionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace UnityEngine.Rendering
{
Expand Down Expand Up @@ -30,20 +31,38 @@ public enum DynamicResScalePolicyType
/// </summary>
public class DynamicResolutionHandler
{
private bool m_Enabled = false;
private float m_MinScreenFraction = 1.0f;
private float m_MaxScreenFraction = 1.0f;
private float m_CurrentFraction = 1.0f;
private float m_PrevFraction = -1.0f;
private bool m_ForcingRes = false;
private bool m_CurrentCameraRequest = true;
private bool m_ForceSoftwareFallback = false;

private float m_PrevHWScaleWidth = 1.0f;
private float m_PrevHWScaleHeight = 1.0f;
private Vector2Int m_LastScaledSize = new Vector2Int(0, 0);
private bool m_Enabled;
private float m_MinScreenFraction;
private float m_MaxScreenFraction;
private float m_CurrentFraction;
private bool m_ForcingRes;
private bool m_CurrentCameraRequest;
private float m_PrevFraction;
private bool m_ForceSoftwareFallback;

private float m_PrevHWScaleWidth;
private float m_PrevHWScaleHeight;
private Vector2Int m_LastScaledSize;

private void Reset()
{
m_Enabled = false;
m_MinScreenFraction = 1.0f;
m_MaxScreenFraction = 1.0f;
m_CurrentFraction = 1.0f;
m_ForcingRes = false;
m_CurrentCameraRequest = true;
m_PrevFraction = -1.0f;
m_ForceSoftwareFallback = false;

m_PrevHWScaleWidth = 1.0f;
m_PrevHWScaleHeight = 1.0f;
m_LastScaledSize = new Vector2Int(0, 0);
filter = DynamicResUpscaleFilter.Bilinear;
}

private DynamicResScalePolicyType m_ScalerType = DynamicResScalePolicyType.ReturnsMinMaxLerpFactor;
private static DynamicResScalePolicyType s_ScalerType = DynamicResScalePolicyType.ReturnsMinMaxLerpFactor;
private static PerformDynamicRes s_DynamicResMethod = DefaultDynamicResMethod;

// Debug
private Vector2Int cachedOriginalSize;
Expand All @@ -59,22 +78,96 @@ public class DynamicResolutionHandler
/// </summary>
public Vector2Int finalViewport { get; set; }


private DynamicResolutionType type;

private PerformDynamicRes m_DynamicResMethod = null;
private static DynamicResolutionHandler s_Instance = new DynamicResolutionHandler();
private GlobalDynamicResolutionSettings m_CachedSettings = GlobalDynamicResolutionSettings.NewDefault();

private const int CameraDictionaryMaxcCapacity = 32;
private WeakReference m_OwnerCameraWeakRef = null;
private static Dictionary<int, DynamicResolutionHandler> s_CameraInstances = new Dictionary<int, DynamicResolutionHandler>(CameraDictionaryMaxcCapacity);
private static DynamicResolutionHandler s_DefaultInstance = new DynamicResolutionHandler();

private static int s_ActiveCameraId = 0;
private static DynamicResolutionHandler s_ActiveInstance = s_DefaultInstance;

//private global state of ScalableBufferManager
private static bool s_ActiveInstanceDirty = true;
private static float s_GlobalHwFraction = 1.0f;
private static bool s_GlobalHwUpresActive = false;

private bool FlushScalableBufferManagerState()
{
if (s_GlobalHwUpresActive == HardwareDynamicResIsEnabled() && s_GlobalHwFraction == m_CurrentFraction)
return false;

s_GlobalHwUpresActive = HardwareDynamicResIsEnabled();
s_GlobalHwFraction = m_CurrentFraction;
ScalableBufferManager.ResizeBuffers(s_GlobalHwFraction, s_GlobalHwFraction);
return true;
}

private static DynamicResolutionHandler GetOrCreateDrsInstanceHandler(Camera camera)
{
if (camera == null)
return null;

DynamicResolutionHandler instance = null;
var key = camera.GetInstanceID();
if (!s_CameraInstances.TryGetValue(key, out instance))
{
//if this camera is not available in the map of cameras lets try creating one.

//first and foremost, if we exceed the dictionary capacity, lets try and recycle an object that is dead.
if (s_CameraInstances.Count >= CameraDictionaryMaxcCapacity)
{
int recycledInstanceKey = 0;
DynamicResolutionHandler recycledInstance = null;
foreach (var kv in s_CameraInstances)
{
//is this object dead? that is, belongs to a camera that was destroyed?
if (kv.Value.m_OwnerCameraWeakRef == null || !kv.Value.m_OwnerCameraWeakRef.IsAlive)
{
recycledInstance = kv.Value;
recycledInstanceKey = kv.Key;
break;
}
}

if (recycledInstance != null)
{
instance = recycledInstance;
s_CameraInstances.Remove(recycledInstanceKey);
}
}

//if we didnt find a dead object, we create one from scratch.
if (instance == null)
{
instance = new DynamicResolutionHandler();
instance.m_OwnerCameraWeakRef = new WeakReference(camera);
}
else
{
//otherwise, we found a dead object, lets reset it, and have a weak ref to this camera,
//so we can possibly recycle it in the future by checking the camera's weak pointer state.
instance.Reset();
instance.m_OwnerCameraWeakRef.Target = camera;
}

s_CameraInstances.Add(key, instance);
}
return instance;
}

/// <summary>
/// Get the instance of the global dynamic resolution handler.
/// </summary>
public static DynamicResolutionHandler instance { get { return s_Instance; } }
public static DynamicResolutionHandler instance { get { return s_ActiveInstance; } }


private DynamicResolutionHandler()
{
m_DynamicResMethod = DefaultDynamicResMethod;
filter = DynamicResUpscaleFilter.Bilinear;
Reset();
}

// TODO: Eventually we will need to provide a good default implementation for this.
Expand Down Expand Up @@ -107,6 +200,25 @@ private void ProcessSettings(GlobalDynamicResolutionSettings settings)
m_CurrentFraction = fraction;
}
}
m_CachedSettings = settings;
}

public Vector2 GetResolvedScale()
{
if (!m_Enabled || !m_CurrentCameraRequest)
{
return new Vector2(1.0f, 1.0f);
}

float scaleFractionX = m_CurrentFraction;
float scaleFractionY = m_CurrentFraction;
if (!m_ForceSoftwareFallback && type == DynamicResolutionType.Hardware)
{
scaleFractionX = ScalableBufferManager.widthScaleFactor;
scaleFractionY = ScalableBufferManager.heightScaleFactor;
}

return new Vector2(scaleFractionX, scaleFractionY);
}

/// <summary>
Expand All @@ -116,8 +228,18 @@ private void ProcessSettings(GlobalDynamicResolutionSettings settings)
/// <param name="scalerType">The type of scaler that is used, this is used to indicate the return type of the scaler to the dynamic resolution system.</param>
static public void SetDynamicResScaler(PerformDynamicRes scaler, DynamicResScalePolicyType scalerType = DynamicResScalePolicyType.ReturnsMinMaxLerpFactor)
{
s_Instance.m_ScalerType = scalerType;
s_Instance.m_DynamicResMethod = scaler;
s_ScalerType = scalerType;
s_DynamicResMethod = scaler;
}

/// <summary>
/// Will clear the currently used camera. Use this function to restore the default instance when UpdateAndUseCamera is called.
/// </summary>
public static void ClearSelectedCamera()
{
s_ActiveInstance = s_DefaultInstance;
s_ActiveCameraId = 0;
s_ActiveInstanceDirty = true;
}

/// <summary>
Expand All @@ -129,6 +251,34 @@ public void SetCurrentCameraRequest(bool cameraRequest)
m_CurrentCameraRequest = cameraRequest;
}

/// <summary>
/// Update the state of the dynamic resolution system for a specific camera.
/// Call this function also to switch context between cameras (will set the current camera as active).
// Passing a null camera has the same effect as calling Update without the camera parameter.
/// </summary>
/// <param name="camera">Camera used to select a specific instance tied to this DynamicResolutionHandler instance.
/// </param>
/// <param name="settings">(optional) The settings that are to be used by the dynamic resolution system. passing null for the settings will result in the last update's settings used.</param>
/// <param name="OnResolutionChange">An action that will be called every time the dynamic resolution system triggers a change in resolution.</param>
public static void UpdateAndUseCamera(Camera camera, GlobalDynamicResolutionSettings? settings = null, Action OnResolutionChange = null)
{
int newCameraId;
if (camera == null)
{
s_ActiveInstance = s_DefaultInstance;
newCameraId = 0;
}
else
{
s_ActiveInstance = GetOrCreateDrsInstanceHandler(camera);
newCameraId = camera.GetInstanceID();
}

s_ActiveInstanceDirty = newCameraId != s_ActiveCameraId;
s_ActiveCameraId = newCameraId;
s_ActiveInstance.Update(settings.HasValue ? settings.Value : s_ActiveInstance.m_CachedSettings, OnResolutionChange);
}

/// <summary>
/// Update the state of the dynamic resolution system.
/// </summary>
Expand All @@ -138,49 +288,47 @@ public void Update(GlobalDynamicResolutionSettings settings, Action OnResolution
{
ProcessSettings(settings);

if (!m_Enabled) return;
if (!m_Enabled && !s_ActiveInstanceDirty)
{
s_ActiveInstanceDirty = false;
return;
}

if (!m_ForcingRes)
{
if (m_ScalerType == DynamicResScalePolicyType.ReturnsMinMaxLerpFactor)
if (s_ScalerType == DynamicResScalePolicyType.ReturnsMinMaxLerpFactor)
{
float currLerp = m_DynamicResMethod();
float currLerp = s_DynamicResMethod();
float lerpFactor = Mathf.Clamp(currLerp, 0.0f, 1.0f);
m_CurrentFraction = Mathf.Lerp(m_MinScreenFraction, m_MaxScreenFraction, lerpFactor);
}
else if (m_ScalerType == DynamicResScalePolicyType.ReturnsPercentage)
else if (s_ScalerType == DynamicResScalePolicyType.ReturnsPercentage)
{
float percentageRequested = Mathf.Max(m_DynamicResMethod(), 5.0f);
float percentageRequested = Mathf.Max(s_DynamicResMethod(), 5.0f);
m_CurrentFraction = Mathf.Clamp(percentageRequested / 100.0f, m_MinScreenFraction, m_MaxScreenFraction);
}
}

if (m_CurrentFraction != m_PrevFraction)
{
m_PrevFraction = m_CurrentFraction;
bool hardwareResolutionChanged = false;
bool softwareResolutionChanged = m_CurrentFraction != m_PrevFraction;

if (!m_ForceSoftwareFallback && type == DynamicResolutionType.Hardware)
{
ScalableBufferManager.ResizeBuffers(m_CurrentFraction, m_CurrentFraction);
}
m_PrevFraction = m_CurrentFraction;

if (OnResolutionChange != null)
OnResolutionChange();
}
else
if (!m_ForceSoftwareFallback && type == DynamicResolutionType.Hardware)
{
// Unity can change the scale factor by itself so we need to trigger the Action if that happens as well.
if (!m_ForceSoftwareFallback && type == DynamicResolutionType.Hardware)
hardwareResolutionChanged = FlushScalableBufferManagerState();
if (ScalableBufferManager.widthScaleFactor != m_PrevHWScaleWidth ||
ScalableBufferManager.heightScaleFactor != m_PrevHWScaleHeight)
{
if (ScalableBufferManager.widthScaleFactor != m_PrevHWScaleWidth ||
ScalableBufferManager.heightScaleFactor != m_PrevHWScaleHeight)
{
if (OnResolutionChange != null)
OnResolutionChange();
}
hardwareResolutionChanged = true;
}
}


if ((softwareResolutionChanged || hardwareResolutionChanged) && OnResolutionChange != null)
OnResolutionChange();

s_ActiveInstanceDirty = false;
m_PrevHWScaleWidth = ScalableBufferManager.widthScaleFactor;
m_PrevHWScaleHeight = ScalableBufferManager.heightScaleFactor;
}
Expand Down Expand Up @@ -234,6 +382,7 @@ public void ForceSoftwareFallback()

/// <summary>
/// Applies to the passed size the scale imposed by the dynamic resolution system.
/// Note: this function has the side effect of caching the last scale size.
/// </summary>
/// <param name="size">The starting size of the render target that will be scaled by dynamic resolution.</param>
/// <returns>The parameter size scaled by the dynamic resolution system.</returns>
Expand All @@ -246,21 +395,26 @@ public Vector2Int GetScaledSize(Vector2Int size)
return size;
}

float scaleFractionX = m_CurrentFraction;
float scaleFractionY = m_CurrentFraction;
if (!m_ForceSoftwareFallback && type == DynamicResolutionType.Hardware)
{
scaleFractionX = ScalableBufferManager.widthScaleFactor;
scaleFractionY = ScalableBufferManager.heightScaleFactor;
}
Vector2Int scaledSize = ApplyScalesOnSize(size);
m_LastScaledSize = scaledSize;
return scaledSize;
}

Vector2Int scaledSize = new Vector2Int(Mathf.CeilToInt(size.x * scaleFractionX), Mathf.CeilToInt(size.y * scaleFractionY));
/// <summary>
/// Applies to the passed size the scale imposed by the dynamic resolution system.
/// Note: this function is pure (has no side effects), this function does not cache the pre-scale size
/// </summary>
/// <param name="size">The size to apply the scaling</param>
/// <returns>The parameter size scaled by the dynamic resolution system.</returns>
public Vector2Int ApplyScalesOnSize(Vector2Int size)
{
Vector2 resolvedScales = GetResolvedScale();
Vector2Int scaledSize = new Vector2Int(Mathf.CeilToInt(size.x * resolvedScales.x), Mathf.CeilToInt(size.y * resolvedScales.y));
if (m_ForceSoftwareFallback || type != DynamicResolutionType.Hardware)
{
scaledSize.x += (1 & scaledSize.x);
scaledSize.y += (1 & scaledSize.y);
}
m_LastScaledSize = scaledSize;

return scaledSize;
}
Expand Down
Loading

0 comments on commit b3ef030

Please sign in to comment.