Browse Source

Added a test to see hot-swapping of upscalers in action

master
Nico de Poel 2 years ago
parent
commit
edc6b9d769
  1. 25
      com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDDynamicResolution.cs
  2. 11
      com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs

25
com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDDynamicResolution.cs

@ -1,7 +1,9 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using System; using System;
using System.Collections;
using System.Diagnostics; using System.Diagnostics;
using UnityEngine.Rendering.HighDefinition.AMD;
/// <summary> /// <summary>
/// Component that controls dynamic resolution scaling in HDRP (High Definition Render Pipeline) via DRH (Dynamic Resolution Handler). /// Component that controls dynamic resolution scaling in HDRP (High Definition Render Pipeline) via DRH (Dynamic Resolution Handler).
@ -194,14 +196,32 @@ public class HDDynamicResolution : MonoBehaviour
void OnEnable() void OnEnable()
{ {
StartCoroutine(CSwapUpscalers());
} }
void OnDisable() void OnDisable()
{ {
StopAllCoroutines();
ResetScale(); ResetScale();
ResetCounters(); ResetCounters();
} }
IEnumerator CSwapUpscalers()
{
var wait = new WaitForSeconds(5f);
int pluginIndex = 0;
while (true)
{
yield return wait;
var plugins = AMDUnityPlugin.GetAvailablePlugins();
pluginIndex = (pluginIndex + 1) % plugins.Count;
AMDUnityPlugin.SetActivePlugin(pluginIndex);
}
}
void Start() void Start()
{ {
} }
@ -267,14 +287,15 @@ public class HDDynamicResolution : MonoBehaviour
GUILayout.Label( GUILayout.Label(
string.Format( string.Format(
"Resolution: {0} x {1}\nScale: {2:F3}\nCPU: {3:F3}\nGPU Ave: {4:F3} Max: {5:F3} Min: {6:F3}",
"Resolution: {0} x {1}\nScale: {2:F3}\nCPU: {3:F3}\nGPU Ave: {4:F3} Max: {5:F3} Min: {6:F3}\nUpscaler: {7}",
drsWidth, drsWidth,
drsHeight, drsHeight,
scaleX, scaleX,
m_SampledCPUFrameTime, m_SampledCPUFrameTime,
m_GPUFrameTime, m_GPUFrameTime,
m_SampledMaxGPUFrameTime, m_SampledMaxGPUFrameTime,
m_SampledMinGPUFrameTime),
m_SampledMinGPUFrameTime,
AMDUnityPlugin.ActivePlugin?.name),
m_DebugStyle); m_DebugStyle);
} }
#endif #endif

11
com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs

@ -15,8 +15,9 @@ namespace UnityEngine.Rendering.HighDefinition.AMD
new FSR2Wrapper.FSR2WrapperUpscaler(), new FSR2Wrapper.FSR2WrapperUpscaler(),
#endif #endif
}; };
internal static UpscalerPlugin ActivePlugin = AvailablePlugins[0];
private static UpscalerPlugin _activePlugin = AvailablePlugins[0];
public static UpscalerPlugin ActivePlugin => _activePlugin;
public static bool Load() => ActivePlugin.Load(); public static bool Load() => ActivePlugin.Load();
@ -70,16 +71,16 @@ namespace UnityEngine.Rendering.HighDefinition.AMD
if (newPlugin == null || !newPlugin.isSupported) if (newPlugin == null || !newPlugin.isSupported)
return false; return false;
if (newPlugin == ActivePlugin)
if (newPlugin == _activePlugin)
return true; return true;
if (!newPlugin.IsLoaded() && !newPlugin.Load()) if (!newPlugin.IsLoaded() && !newPlugin.Load())
return false; return false;
// Hot-swap the upscaler contexts, so HDRP can keep calling the same FSR2Contexts without knowing the underlying implementation has changed. // Hot-swap the upscaler contexts, so HDRP can keep calling the same FSR2Contexts without knowing the underlying implementation has changed.
GraphicsDevice.device.RecreateFeatures(ActivePlugin, newPlugin);
GraphicsDevice.device.RecreateFeatures(_activePlugin, newPlugin);
ActivePlugin = newPlugin;
_activePlugin = newPlugin;
return true; return true;
} }
} }

Loading…
Cancel
Save