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.Rendering;
using System;
using System.Collections;
using System.Diagnostics;
using UnityEngine.Rendering.HighDefinition.AMD;
/// <summary>
/// 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()
{
StartCoroutine(CSwapUpscalers());
}
void OnDisable()
{
StopAllCoroutines();
ResetScale();
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()
{
}
@ -267,14 +287,15 @@ public class HDDynamicResolution : MonoBehaviour
GUILayout.Label(
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,
drsHeight,
scaleX,
m_SampledCPUFrameTime,
m_GPUFrameTime,
m_SampledMaxGPUFrameTime,
m_SampledMinGPUFrameTime),
m_SampledMinGPUFrameTime,
AMDUnityPlugin.ActivePlugin?.name),
m_DebugStyle);
}
#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(),
#endif
};
internal static UpscalerPlugin ActivePlugin = AvailablePlugins[0];
private static UpscalerPlugin _activePlugin = AvailablePlugins[0];
public static UpscalerPlugin ActivePlugin => _activePlugin;
public static bool Load() => ActivePlugin.Load();
@ -70,16 +71,16 @@ namespace UnityEngine.Rendering.HighDefinition.AMD
if (newPlugin == null || !newPlugin.isSupported)
return false;
if (newPlugin == ActivePlugin)
if (newPlugin == _activePlugin)
return true;
if (!newPlugin.IsLoaded() && !newPlugin.Load())
return false;
// 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;
}
}

Loading…
Cancel
Save