Browse Source

Allow live switching between FP16 and FP32

armasr
Nico de Poel 10 months ago
parent
commit
d088d440f5
  1. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs
  2. 6
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs
  3. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs

3
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Editor/PostProcessLayerEditor.cs

@ -34,6 +34,7 @@ namespace UnityEditor.Rendering.PostProcessing
SerializedProperty m_FsrQualityMode;
SerializedProperty m_FsrPerformSharpen;
SerializedProperty m_FsrSharpness;
SerializedProperty m_FsrEnableFP16;
SerializedProperty m_FsrExposureSource;
SerializedProperty m_FsrExposureTexture;
SerializedProperty m_FsrPreExposure;
@ -94,6 +95,7 @@ namespace UnityEditor.Rendering.PostProcessing
m_FsrQualityMode = FindProperty(x => x.upscaling.qualityMode);
m_FsrPerformSharpen = FindProperty(x => x.upscaling.performSharpenPass);
m_FsrSharpness = FindProperty(x => x.upscaling.sharpness);
m_FsrEnableFP16 = FindProperty(x => x.upscaling.enableFP16);
m_FsrExposureSource = FindProperty(x => x.upscaling.exposureSource);
m_FsrExposureTexture = FindProperty(x => x.upscaling.exposure);
m_FsrPreExposure = FindProperty(x => x.upscaling.preExposure);
@ -230,6 +232,7 @@ namespace UnityEditor.Rendering.PostProcessing
EditorGUILayout.PropertyField(m_FsrQualityMode);
EditorGUILayout.PropertyField(m_FsrPerformSharpen);
EditorGUILayout.PropertyField(m_FsrSharpness);
EditorGUILayout.PropertyField(m_FsrEnableFP16);
EditorGUILayout.PropertyField(m_FsrExposureSource);
if (m_FsrExposureSource.intValue == (int)Upscaling.ExposureSource.Manual) EditorGUILayout.PropertyField(m_FsrExposureTexture);
EditorGUILayout.PropertyField(m_FsrPreExposure);

6
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs

@ -34,6 +34,8 @@ namespace UnityEngine.Rendering.PostProcessing
public bool performSharpenPass = true;
[Tooltip("Strength of the sharpening effect.")]
[Range(0, 1)] public float sharpness = 0.8f;
public bool enableFP16 = true;
[Tooltip("Choose where to get the exposure value from. Use auto-exposure from either the upscaler or Unity, provide a manual exposure texture, or use a default value.")]
public ExposureSource exposureSource = ExposureSource.Auto;
@ -112,6 +114,7 @@ namespace UnityEngine.Rendering.PostProcessing
private Fsr2.QualityMode _prevQualityMode;
private ExposureSource _prevExposureSource;
private Vector2Int _prevUpscaleSize;
private bool _prevFP16;
private Rect _originalRect;
@ -165,7 +168,7 @@ namespace UnityEngine.Rendering.PostProcessing
// Monitor for any resolution changes and recreate the upscaler context if necessary
// We can't create an upscaler context without info from the post-processing context, so delay the initial setup until here
if (!_initialized || _upscaler == null || _upscaleSize.x != _prevUpscaleSize.x || _upscaleSize.y != _prevUpscaleSize.y ||
upscalerType != _prevUpscalerType || qualityMode != _prevQualityMode || exposureSource != _prevExposureSource)
upscalerType != _prevUpscalerType || qualityMode != _prevQualityMode || exposureSource != _prevExposureSource || enableFP16 != _prevFP16)
{
DestroyUpscaler();
CreateUpscaler(context);
@ -199,6 +202,7 @@ namespace UnityEngine.Rendering.PostProcessing
_prevQualityMode = qualityMode;
_prevExposureSource = exposureSource;
_prevUpscaleSize = _upscaleSize;
_prevFP16 = enableFP16;
_callbacks = callbacksFactory(context);

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASRUpscaler.cs

@ -17,7 +17,7 @@ namespace UnityEngine.Rendering.PostProcessing
public override void CreateContext(PostProcessRenderContext context, Upscaling config)
{
// Initialize ASR context
Asr.InitializationFlags flags = Asr.InitializationFlags.EnableFP16Usage;
Asr.InitializationFlags flags = config.enableFP16 ? Asr.InitializationFlags.EnableFP16Usage : 0;
if (context.camera.allowHDR) flags |= Asr.InitializationFlags.EnableHighDynamicRange;
if (config.exposureSource == Upscaling.ExposureSource.Auto) flags |= Asr.InitializationFlags.EnableAutoExposure;
if (RuntimeUtilities.IsDynamicResolutionEnabled(context.camera)) flags |= Asr.InitializationFlags.EnableDynamicResolution;

Loading…
Cancel
Save