Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DLSS After Post
Adding DLSS injection points after depth of field and after post process. This should also mitigate some performance concerns over high depth of field / post process costs. 
Fogbugz: https://fogbugz.unity3d.com/f/cases/resolve/1385178/
Documentation team jira: https://jira.unity3d.com/browse/DOCF-1143
  • Loading branch information
kecho committed Apr 15, 2022
1 parent 3965a3a commit 63db6f5
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 22 deletions.
Expand Up @@ -215,6 +215,13 @@ public enum UpsamplerScheduleType
/// </summary>
BeforePost,

/// <summary>
/// Indicates that upscaling should happen after depth of field but before other post processing.
/// This means that everything runs at the source resolution during rasterization and depth of field, and other post processes
/// will run at full resolution. More performant alternative for temporal upscalers at the expense of reduced image quality.
/// </summary>
AfterDepthOfField,

/// <summary>
/// Indicates that upscaling must happen after post processing.
/// This means that everything in the frame runs at the source resolution, and upscaling happens after
Expand Down
Expand Up @@ -73,6 +73,7 @@ public static GlobalDynamicResolutionSettings NewDefault() => new GlobalDynamicR
DLSSUseOptimalSettings = true,
DLSSPerfQualitySetting = 0,
DLSSSharpness = 0.5f,
DLSSInjectionPoint = DynamicResolutionHandler.UpsamplerScheduleType.BeforePost,

fsrOverrideSharpness = false,
fsrSharpness = FSRUtils.kDefaultSharpnessLinear
Expand All @@ -89,6 +90,9 @@ public static GlobalDynamicResolutionSettings NewDefault() => new GlobalDynamicR
/// <summary>Opaque quality setting of NVIDIA Deep Learning Super Sampling (DLSS). Use the system enum UnityEngine.NVIDIA.DLSSQuality to set the quality.</summary>
public uint DLSSPerfQualitySetting;

/// <summary>The injection point at which to apply DLSS upscaling.</summary>
public DynamicResolutionHandler.UpsamplerScheduleType DLSSInjectionPoint;

/// <summary>Toggle NVIDIA Deep Learning Super Sampling (DLSS) automatic recommendation system for scaling and sharpness.
/// If this is on, the manually established scale callback for Dynamic Resolution Scaling is ignored. The sharpness setting of DLSS is also ignored.
/// </summary>
Expand Down
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added the culling matrix and near plane for lights, so that they can be custom-culled with the BatchRenderGroup API.
- Added an optional CPU simulation for the water system.
- Added new Unity material ball matching the new Unity logo.
- Adding injection points options for DLSS (After Depth of Field and After Post) which should mitigate some of the performance cost in post process.

### Changed
- Moved custom Sensor Lidar path tracing code to the SensorSDK package.
Expand Down
Expand Up @@ -81,6 +81,7 @@ These settings control the draw distance and resolution of the decals atlas that
| **Enable** | Enable the checkbox to make HDRP support dynamic resolution in your Unity Project. |
| **- Enable DLSS** | Enable the checkbox to make HDRP support NVIDIA Deep Learning Super Sampling (DLSS).<br/>This property only appears if you enable the NVIDIA package (com.unity.modules.nvidia) in your Unity project. |
| **-- Mode** | Use the drop-down to select which performance mode DLSS operates on. The options are:<br/>&#8226; **Balanced**: - Balances performance with quality.<br/>&#8226; **MaxPerf**: - Fast performance, lower quality.<br/>&#8226; **MaxQuality**: - High quality, lower performance.<br/>&#8226; **UltraPerformance**: - Fastest performance, lowest quality. |
| **-- Injection Point** | Use the drop-down to select at which point DLSS runs in the rendering pipeline: <br/>&#8226; **Before Post**: - DLSS runs when all post processing effects are at full resolution.<br/>&#8226; **After Depth Of Field**: - Depth of field runs at a low resolution and DLSS upscales everything in the next rendering step. All other post processing effects run at full resolution. <br/>&#8226; **After Post Process**: - DLSS runs at the end of the pipeline when all post process are at low resolution.<br/>&#8226; |
| **-- Use Optimal Settings** | Enable the checkbox to make DLSS control the Sharpness and Screen Percentage automatically. |
| **-- Sharpness** | Controls how the DLSS upsampler renders edges on the image. More sharpness usually means more contrast and a clearer image but can increase flickering and fireflies. Unity ignores this property if you enable **Use Optimal Settings**. |
| **- Dynamic Resolution Type** | Use the drop-down to select the type of dynamic resolution HDRP uses:<br />&#8226; **Software**: This option allocates render targets to accommodate the maximum resolution possible, then rescales the viewport accordingly. This allows the viewport to render at varying resolutions. |
Expand Down
Expand Up @@ -237,9 +237,23 @@ public class Styles
public static readonly GUIContent enabled = EditorGUIUtility.TrTextContent("Enable", "When enabled, HDRP dynamically lowers the resolution of render targets to reduce the workload on the GPU.");
public static readonly GUIContent enableDLSS = EditorGUIUtility.TrTextContent("Enable DLSS", "Enables NVIDIA Deep Learning Super Sampling (DLSS).");
public static readonly GUIContent DLSSQualitySettingContent = EditorGUIUtility.TrTextContent("Mode", "Selects a performance quality setting for NVIDIA Deep Learning Super Sampling (DLSS).");
public static readonly GUIContent DLSSInjectionPoint = EditorGUIUtility.TrTextContent("Injection Point", "The injection point at which to apply DLSS upscaling.");
public static readonly GUIContent DLSSUseOptimalSettingsContent = EditorGUIUtility.TrTextContent("Use Optimal Settings", "Sets the sharpness and scale automatically for NVIDIA Deep Learning Super Sampling, depending on the values of quality settings. When DLSS Optimal Settings is on, the percentage settings for Dynamic Resolution Scaling are ignored.");
public static readonly GUIContent DLSSSharpnessContent = EditorGUIUtility.TrTextContent("Sharpness", "NVIDIA Deep Learning Super Sampling pixel sharpness of upsampler. Controls how the DLSS upsampler will render edges on the image. More sharpness usually means more contrast and clearer image but can increase flickering and fireflies. This setting is ignored if use optimal settings is used");

public static readonly GUIContent[] DLSSInjectionPointNames =
{
new GUIContent("Before Post Process (Default)"),
new GUIContent("After Depth Of Field (Low depth of field cost)"),
new GUIContent("After Post Process (Low post process cost)")
};
public static readonly int[] DLSSInjectionPointValues =
{
(int)DynamicResolutionHandler.UpsamplerScheduleType.BeforePost,
(int)DynamicResolutionHandler.UpsamplerScheduleType.AfterDepthOfField,
(int)DynamicResolutionHandler.UpsamplerScheduleType.AfterPost
};

public const string DLSSPackageLabel = "NVIDIA Deep Learning Super Sampling (DLSS) is not active in this project. To activate it, install the NVIDIA package.";

public const string DLSSFeatureDetectedMsg = "Unity detected NVIDIA Deep Learning Super Sampling and will ignore the Fallback Upscale Filter.";
Expand Down
Expand Up @@ -548,6 +548,8 @@ static void Drawer_SectionDynamicResolutionSettings(SerializedHDRenderPipelineAs

serialized.renderPipelineSettings.dynamicResolutionSettings.DLSSPerfQualitySetting.intValue = (int)(object)v;

int injectionPointVal = EditorGUILayout.IntPopup(Styles.DLSSInjectionPoint, serialized.renderPipelineSettings.dynamicResolutionSettings.DLSSInjectionPoint.intValue, Styles.DLSSInjectionPointNames, Styles.DLSSInjectionPointValues);
serialized.renderPipelineSettings.dynamicResolutionSettings.DLSSInjectionPoint.intValue = injectionPointVal;
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.dynamicResolutionSettings.DLSSUseOptimalSettings, Styles.DLSSUseOptimalSettingsContent);

using (new EditorGUI.DisabledScope(serialized.renderPipelineSettings.dynamicResolutionSettings.DLSSUseOptimalSettings.boolValue))
Expand Down
Expand Up @@ -11,6 +11,7 @@ class SerializedDynamicResolutionSettings
public SerializedProperty enableDLSS;
public SerializedProperty useMipBias;
public SerializedProperty DLSSPerfQualitySetting;
public SerializedProperty DLSSInjectionPoint;
public SerializedProperty DLSSUseOptimalSettings;
public SerializedProperty DLSSSharpness;
public SerializedProperty fsrOverrideSharpness;
Expand All @@ -32,6 +33,7 @@ public SerializedDynamicResolutionSettings(SerializedProperty root)
enableDLSS = root.Find((GlobalDynamicResolutionSettings s) => s.enableDLSS);
useMipBias = root.Find((GlobalDynamicResolutionSettings s) => s.useMipBias);
DLSSPerfQualitySetting = root.Find((GlobalDynamicResolutionSettings s) => s.DLSSPerfQualitySetting);
DLSSInjectionPoint = root.Find((GlobalDynamicResolutionSettings s) => s.DLSSInjectionPoint);
DLSSUseOptimalSettings = root.Find((GlobalDynamicResolutionSettings s) => s.DLSSUseOptimalSettings);
DLSSSharpness = root.Find((GlobalDynamicResolutionSettings s) => s.DLSSSharpness);
fsrOverrideSharpness = root.Find((GlobalDynamicResolutionSettings s) => s.fsrOverrideSharpness);
Expand Down
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

#if ENABLE_NVIDIA && ENABLE_NVIDIA_MODULE
namespace UnityEngine.NVIDIA
Expand Down Expand Up @@ -187,6 +188,10 @@ private DebugUI.Widget InternalCreateWidget()
displayName = "DLSS Supported",
getter = () => m_Data.dlssSupported ? "True" : "False",
},
new DebugUI.Value {
displayName = "DLSS Injection Point",
getter = () => HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.DLSSInjectionPoint
},
m_DlssViewStateTable
}
};
Expand Down
Expand Up @@ -725,9 +725,20 @@ internal bool IsTAAUEnabled()
return DynamicResolutionHandler.instance.DynamicResolutionEnabled() && DynamicResolutionHandler.instance.filter == DynamicResUpscaleFilter.TAAU && !IsDLSSEnabled();
}

internal bool UpsampleHappensBeforePost()
internal DynamicResolutionHandler.UpsamplerScheduleType UpsampleSyncPoint()
{
return IsDLSSEnabled() || IsTAAUEnabled();
if (IsDLSSEnabled())
{
return HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.DLSSInjectionPoint;
}
else if (IsTAAUEnabled())
{
return DynamicResolutionHandler.UpsamplerScheduleType.BeforePost;
}
else
{
return DynamicResolutionHandler.UpsamplerScheduleType.AfterPost;
}
}

internal bool allowDeepLearningSuperSampling => m_AdditionalCameraData == null ? false : m_AdditionalCameraData.allowDeepLearningSuperSampling;
Expand Down Expand Up @@ -832,7 +843,7 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
UpdateAntialiasing();

// ORDER is important: we read the upsamplerSchedule when we decide if we need to refresh the history buffers, so be careful when moving this
DynamicResolutionHandler.instance.upsamplerSchedule = UpsampleHappensBeforePost() ? DynamicResolutionHandler.UpsamplerScheduleType.BeforePost : DynamicResolutionHandler.UpsamplerScheduleType.AfterPost;
DynamicResolutionHandler.instance.upsamplerSchedule = UpsampleSyncPoint();

// Handle memory allocation.
if (allocateHistoryBuffers)
Expand Down Expand Up @@ -962,7 +973,7 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
Vector2Int scaledSize = DynamicResolutionHandler.instance.GetScaledSize(new Vector2Int(actualWidth, actualHeight));
actualWidth = scaledSize.x;
actualHeight = scaledSize.y;
globalMipBias += DynamicResolutionHandler.instance.CalculateMipBias(scaledSize, nonScaledViewport, UpsampleHappensBeforePost());
globalMipBias += DynamicResolutionHandler.instance.CalculateMipBias(scaledSize, nonScaledViewport, UpsampleSyncPoint() <= DynamicResolutionHandler.UpsamplerScheduleType.AfterDepthOfField);
lowResScale = DynamicResolutionHandler.instance.GetLowResMultiplier(lowResScale);
}

Expand Down

0 comments on commit 63db6f5

Please sign in to comment.