Skip to content

Commit

Permalink
Rendering Debugger - GPU Resident Drawer - Adding feedback on the deb…
Browse files Browse the repository at this point in the history
…ug panel why some settings are not applied.

Fix this issue:

https://jira.unity3d.com/browse/UUM-67130

Extracted the information why the GPU Resident drawer is not supported and added that feedback into the Rendering Debugger.

Also, now the panel shows the warning and hides modifiying the GPU Resident Drawer if it is not enabled.

The `RecreateIfNeeded`, is need to be handled per Render, as ther IsEnabled depends on settings that come directly from GraphicsSettings, and not from Render Pipeline Graphics settings, Therfore, when you changed something the GPU Resident drawer was not recreated.

Added capabilities to the debug message box, to display new message.
  • Loading branch information
alex-vazquez-unity3d authored and Evergreen committed Apr 9, 2024
1 parent d5ddc79 commit c214ad4
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public override void Begin(DebugUI.Widget widget, DebugState state)
{
var w = Cast<DebugUI.Foldout>(widget);
var s = Cast<DebugStateBool>(state);

var title = EditorGUIUtility.TrTextContent(w.displayName, w.tooltip);

Action<GenericMenu> fillContextMenuAction = null;
Expand Down Expand Up @@ -660,7 +660,7 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
_ => MessageType.None
};

EditorGUILayout.HelpBox(w.displayName, type);
EditorGUILayout.HelpBox(w.message, type);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,16 @@ public enum Style
/// Style used to render displayName.
/// </summary>
public Style style = Style.Info;

/// <summary>
/// Message Callback to feed the new message to the widget
/// </summary>
public Func<string> messageCallback = null;

/// <summary>
/// This obtains the message from the display name or from the message callback if it is not null
/// </summary>
public string message => messageCallback == null ? displayName : messageCallback();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using UnityEngine.UI;

namespace UnityEngine.Rendering.UI
Expand Down Expand Up @@ -36,6 +37,11 @@ internal override void SetWidget(DebugUI.Widget widget)
}
}

void Update()
{
nameLabel.text = m_Field.message;
}

/// <summary>
/// Method called when the box is selected
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,24 @@ private class SettingsPanel : DebugDisplaySettingsPanel

public SettingsPanel(DebugDisplayGPUResidentDrawer data)
{
AddWidget(new DebugUI.Container()
var helpBox = new DebugUI.MessageBox()
{
displayName = "Not Supported",
style = MessageBox.Style.Warning,
messageCallback = () =>
{
var settings = GPUResidentDrawer.GetGlobalSettingsFromRPAsset();
return GPUResidentDrawer.IsGPUResidentDrawerSupportedBySRP(settings, out var msg, out var _) ? string.Empty : msg;
},
isHiddenCallback = () => GPUResidentDrawer.IsEnabled()
};

AddWidget(helpBox);

AddWidget(new Container()
{
displayName = Strings.occlusionCullingTitle,
isHiddenCallback = () => !GPUResidentDrawer.IsEnabled(),
children =
{
new DebugUI.BoolField { nameAndTooltip = Strings.occlusionTestOverlayEnable, getter = () => data.occlusionTestOverlayEnable, setter = value => data.occlusionTestOverlayEnable = value},
Expand All @@ -253,6 +268,7 @@ public SettingsPanel(DebugDisplayGPUResidentDrawer data)
AddWidget(new DebugUI.Container()
{
displayName = Strings.drawerSettingsContainerName,
isHiddenCallback = () => !GPUResidentDrawer.IsEnabled(),
children =
{
new DebugUI.BoolField { nameAndTooltip = Strings.displayBatcherStats, getter = () => data.displayBatcherStats, setter = value => data.displayBatcherStats = value},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEditor.Rendering;
#endif

namespace UnityEngine.Rendering
{
public partial class GPUResidentDrawer
{
static class Strings
{
public static readonly string drawerModeDisabled = $"{nameof(GPUResidentDrawer)} Drawer mode is disabled. Enable it on your current {nameof(RenderPipelineAsset)}";
public static readonly string allowInEditModeDisabled = $"{nameof(GPUResidentDrawer)} The current mode does not allow the resident drawer. Check setting Allow In Edit Mode";
public static readonly string notGPUResidentRenderPipeline = $"{nameof(GPUResidentDrawer)} Disabled due to current render pipeline not being of type {nameof(IGPUResidentRenderPipeline)}";
public static readonly string rawBufferNotSupportedByPlatform = $"{nameof(GPUResidentDrawer)} The current platform does not support {BatchBufferTarget.RawBuffer.GetType()}";
public static readonly string kernelNotPresent = $"{nameof(GPUResidentDrawer)} Kernel not present, please ensure the player settings includes a supported graphics API.";
public static readonly string batchRendererGroupShaderStrippingModeInvalid = $"{nameof(GPUResidentDrawer)} \"BatchRendererGroup Variants\" setting must be \"Keep All\". " +
" The current setting will cause errors when building a player because all DOTS instancing shaders will be stripped" +
" To fix, modify Graphics settings and set \"BatchRendererGroup Variants\" to \"Keep All\".";
}

internal static bool IsProjectSupported()
{
return IsProjectSupported(out string _, out LogType __);
}

internal static bool IsProjectSupported(out string message, out LogType severity)
{
message = string.Empty;
severity = LogType.Log;

// The GPUResidentDrawer only has support when the RawBuffer path of providing data
// ConstantBuffer path and any other unsupported platforms early out here
if (BatchRendererGroup.BufferTarget != BatchBufferTarget.RawBuffer)
{
severity = LogType.Warning;
message = Strings.rawBufferNotSupportedByPlatform;
return false;
}

#if UNITY_EDITOR
// Check the build target is supported by checking the depth downscale kernel (which has an only_renderers pragma) is present
var resources = GraphicsSettings.GetRenderPipelineSettings<GPUResidentDrawerResources>();
if (!resources.occluderDepthPyramidKernels.HasKernel("OccluderDepthDownscale"))
{
severity = LogType.Warning;
message = Strings.kernelNotPresent;
return false;
}

if (EditorGraphicsSettings.batchRendererGroupShaderStrippingMode != BatchRendererGroupStrippingMode.KeepAll)
{
severity = LogType.Warning;
message = Strings.batchRendererGroupShaderStrippingModeInvalid;
return false;
}
#endif

return true;
}

internal static bool IsGPUResidentDrawerSupportedBySRP(GPUResidentDrawerSettings settings, out string message, out LogType severity)
{
message = string.Empty;
severity = LogType.Log;

// nothing to create
if (settings.mode == GPUResidentDrawerMode.Disabled)
{
message = Strings.drawerModeDisabled;
return false;
}

#if UNITY_EDITOR
// In play mode, the GPU Resident Drawer is always allowed.
// In edit mode, the GPU Resident Drawer is only allowed if the user explicitly requests it with a setting.
bool isAllowedInCurrentMode = EditorApplication.isPlayingOrWillChangePlaymode || settings.allowInEditMode;
if (!isAllowedInCurrentMode)
{
message = Strings.allowInEditModeDisabled;
return false;
}
#endif
// If we are forcing the system, no need to perform further checks
if (IsForcedOnViaCommandLine())
return true;

if (GraphicsSettings.currentRenderPipeline is not IGPUResidentRenderPipeline asset)
{
message = Strings.notGPUResidentRenderPipeline;
severity = LogType.Warning;
return false;
}

return asset.IsGPUResidentDrawerSupportedBySRP(out message, out severity) && IsProjectSupported(out message, out severity);
}

internal static void LogMessage(string message, LogType severity)
{
switch (severity)
{
case LogType.Error:
case LogType.Exception:
Debug.LogError(message);
break;
case LogType.Warning:
Debug.LogWarning(message);
break;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace UnityEngine.Rendering
/// <summary>
/// Static utility class for updating data post cull in begin camera rendering
/// </summary>
public class GPUResidentDrawer
public partial class GPUResidentDrawer
{
internal static GPUResidentDrawer instance { get => s_Instance; }
private static GPUResidentDrawer s_Instance = null;
Expand Down Expand Up @@ -97,12 +97,12 @@ public static void UpdateInstanceOccluders(RenderGraph renderGraph, in OccluderP

/// <summary>
/// Enable or disable GPUResidentDrawer based on the project settings.
/// We call this every frame bacause GPUResidentDrawer can be enabled/disabled by the settings outside the render pipeline asset.
/// We call this every frame because GPUResidentDrawer can be enabled/disabled by the settings outside the render pipeline asset.
/// </summary>
public static void ReinitializeIfNeeded()
{
#if UNITY_EDITOR
if (!IsForcedOnViaCommandLine() && (IsProjectSupported(false) != IsEnabled()))
if (!IsForcedOnViaCommandLine() && (IsProjectSupported() != IsEnabled()))
{
Reinitialize();
}
Expand Down Expand Up @@ -211,48 +211,12 @@ private static void OnAssemblyReload()
}
#endif

internal static bool IsProjectSupported(bool logReason = false)
{
bool supported = true;

// The GPUResidentDrawer only has support when the RawBuffer path of providing data
// ConstantBuffer path and any other unsupported platforms early out here
if (BatchRendererGroup.BufferTarget != BatchBufferTarget.RawBuffer)
{
if(logReason)
Debug.LogWarning($"GPUResidentDrawer: The current platform does not support {BatchBufferTarget.RawBuffer.GetType()}");
supported = false;
}

#if UNITY_EDITOR
// Check the build target is supported by checking the depth downscale kernel (which has an only_renderers pragma) is present
var resources = GraphicsSettings.GetRenderPipelineSettings<GPUResidentDrawerResources>();
if (!resources.occluderDepthPyramidKernels.HasKernel("OccluderDepthDownscale"))
{
if (logReason)
Debug.LogWarning("GPUResidentDrawer: kernel not present, please ensure the player settings includes a supported graphics API.");
supported = false;
}

if (EditorGraphicsSettings.batchRendererGroupShaderStrippingMode != BatchRendererGroupStrippingMode.KeepAll)
{
if(logReason)
Debug.LogWarning(
"GPUResidentDrawer: \"BatchRendererGroup Variants\" setting must be \"Keep All\". " +
" The current setting will cause errors when building a player because all DOTS instancing shaders will be stripped" +
" To fix, modify Graphics settings and set \"BatchRendererGroup Variants\" to \"Keep All\".");
supported = false;
}
#endif
return supported;
}

internal static bool IsEnabled()
{
return s_Instance is not null;
}

private static GPUResidentDrawerSettings GetGlobalSettingsFromRPAsset()
internal static GPUResidentDrawerSettings GetGlobalSettingsFromRPAsset()
{
var renderPipelineAsset = GraphicsSettings.currentRenderPipeline;
if (renderPipelineAsset is not IGPUResidentRenderPipeline mbAsset)
Expand Down Expand Up @@ -328,42 +292,14 @@ private static void CleanUp()
private static void Recreate(GPUResidentDrawerSettings settings)
{
CleanUp();

// nothing to create
if (settings.mode == GPUResidentDrawerMode.Disabled)
return;

#if UNITY_EDITOR
// In play mode, the GPU Resident Drawer is always allowed.
// In edit mode, the GPU Resident Drawer is only allowed if the user explicitly requests it with a setting.
bool isAllowedInCurrentMode = EditorApplication.isPlayingOrWillChangePlaymode || settings.allowInEditMode;
if (!isAllowedInCurrentMode)
if (IsGPUResidentDrawerSupportedBySRP(settings, out var message, out var severity))
{
return;
s_Instance = new GPUResidentDrawer(settings, 4096, 0);
}
#endif

bool supported = true;
if (!IsForcedOnViaCommandLine())
else
{
var mbAsset = GraphicsSettings.currentRenderPipeline as IGPUResidentRenderPipeline;
if (mbAsset == null)
{
Debug.LogWarning("GPUResidentDrawer: Disabled due to current render pipeline not being of type IGPUResidentDrawerRenderPipeline");
supported = false;
}
else
supported &= mbAsset.IsGPUResidentDrawerSupportedBySRP(true);
supported &= IsProjectSupported(true);
LogMessage(message, severity);
}

// not supported
if (!supported)
{
return;
}

s_Instance = new GPUResidentDrawer(settings, 4096, 0);
}

internal GPUResidentBatcher batcher { get => m_Batcher; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ static void ReinitializeGPUResidentDrawer()
/// <returns>true if supported</returns>
bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
{
bool supported = IsGPUResidentDrawerSupportedBySRP(out var message, out var severity);
if (logReason && !supported)
GPUResidentDrawer.LogMessage(message, severity);
return supported;
}

/// <summary>
/// Is the GPU resident drawer supported on this render pipeline.
/// </summary>
/// <param name="message">Why the system is not supported</param>
/// <param name="severity">The severity of the message</param>
/// <returns>true if supported</returns>
bool IsGPUResidentDrawerSupportedBySRP(out string message, out LogType severity)
{
message = string.Empty;
severity = LogType.Log;
return true;
}

Expand All @@ -111,7 +127,12 @@ bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
/// <returns>true if supported</returns>
static bool IsGPUResidentDrawerSupportedByProjectConfiguration(bool logReason = false)
{
return GPUResidentDrawer.IsProjectSupported(logReason);
bool supported = GPUResidentDrawer.IsProjectSupported(out var message, out var severity);
if (logReason && !string.IsNullOrEmpty(message))
{
Debug.LogWarning(message);
}
return supported;
}

/// <summary>
Expand Down
Loading

0 comments on commit c214ad4

Please sign in to comment.