Skip to content

Commit c214ad4

Browse files
alex-vazquez-unity3dEvergreen
authored andcommitted
Rendering Debugger - GPU Resident Drawer - Adding feedback on the debug 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.
1 parent d5ddc79 commit c214ad4

File tree

10 files changed

+204
-100
lines changed

10 files changed

+204
-100
lines changed

Packages/com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public override void Begin(DebugUI.Widget widget, DebugState state)
414414
{
415415
var w = Cast<DebugUI.Foldout>(widget);
416416
var s = Cast<DebugStateBool>(state);
417-
417+
418418
var title = EditorGUIUtility.TrTextContent(w.displayName, w.tooltip);
419419

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

663-
EditorGUILayout.HelpBox(w.displayName, type);
663+
EditorGUILayout.HelpBox(w.message, type);
664664

665665
return true;
666666
}

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,16 @@ public enum Style
609609
/// Style used to render displayName.
610610
/// </summary>
611611
public Style style = Style.Info;
612+
613+
/// <summary>
614+
/// Message Callback to feed the new message to the widget
615+
/// </summary>
616+
public Func<string> messageCallback = null;
617+
618+
/// <summary>
619+
/// This obtains the message from the display name or from the message callback if it is not null
620+
/// </summary>
621+
public string message => messageCallback == null ? displayName : messageCallback();
612622
}
613623

614624
/// <summary>

Packages/com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerMessageBox.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine.UI;
23

34
namespace UnityEngine.Rendering.UI
@@ -36,6 +37,11 @@ internal override void SetWidget(DebugUI.Widget widget)
3637
}
3738
}
3839

40+
void Update()
41+
{
42+
nameLabel.text = m_Field.message;
43+
}
44+
3945
/// <summary>
4046
/// Method called when the box is selected
4147
/// </summary>

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/Debug/DebugDisplayGPUResidentDrawer.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,24 @@ private class SettingsPanel : DebugDisplaySettingsPanel
233233

234234
public SettingsPanel(DebugDisplayGPUResidentDrawer data)
235235
{
236-
AddWidget(new DebugUI.Container()
236+
var helpBox = new DebugUI.MessageBox()
237+
{
238+
displayName = "Not Supported",
239+
style = MessageBox.Style.Warning,
240+
messageCallback = () =>
241+
{
242+
var settings = GPUResidentDrawer.GetGlobalSettingsFromRPAsset();
243+
return GPUResidentDrawer.IsGPUResidentDrawerSupportedBySRP(settings, out var msg, out var _) ? string.Empty : msg;
244+
},
245+
isHiddenCallback = () => GPUResidentDrawer.IsEnabled()
246+
};
247+
248+
AddWidget(helpBox);
249+
250+
AddWidget(new Container()
237251
{
238252
displayName = Strings.occlusionCullingTitle,
253+
isHiddenCallback = () => !GPUResidentDrawer.IsEnabled(),
239254
children =
240255
{
241256
new DebugUI.BoolField { nameAndTooltip = Strings.occlusionTestOverlayEnable, getter = () => data.occlusionTestOverlayEnable, setter = value => data.occlusionTestOverlayEnable = value},
@@ -253,6 +268,7 @@ public SettingsPanel(DebugDisplayGPUResidentDrawer data)
253268
AddWidget(new DebugUI.Container()
254269
{
255270
displayName = Strings.drawerSettingsContainerName,
271+
isHiddenCallback = () => !GPUResidentDrawer.IsEnabled(),
256272
children =
257273
{
258274
new DebugUI.BoolField { nameAndTooltip = Strings.displayBatcherStats, getter = () => data.displayBatcherStats, setter = value => data.displayBatcherStats = value},
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#if UNITY_EDITOR
2+
using System;
3+
using UnityEditor;
4+
using UnityEditor.Rendering;
5+
#endif
6+
7+
namespace UnityEngine.Rendering
8+
{
9+
public partial class GPUResidentDrawer
10+
{
11+
static class Strings
12+
{
13+
public static readonly string drawerModeDisabled = $"{nameof(GPUResidentDrawer)} Drawer mode is disabled. Enable it on your current {nameof(RenderPipelineAsset)}";
14+
public static readonly string allowInEditModeDisabled = $"{nameof(GPUResidentDrawer)} The current mode does not allow the resident drawer. Check setting Allow In Edit Mode";
15+
public static readonly string notGPUResidentRenderPipeline = $"{nameof(GPUResidentDrawer)} Disabled due to current render pipeline not being of type {nameof(IGPUResidentRenderPipeline)}";
16+
public static readonly string rawBufferNotSupportedByPlatform = $"{nameof(GPUResidentDrawer)} The current platform does not support {BatchBufferTarget.RawBuffer.GetType()}";
17+
public static readonly string kernelNotPresent = $"{nameof(GPUResidentDrawer)} Kernel not present, please ensure the player settings includes a supported graphics API.";
18+
public static readonly string batchRendererGroupShaderStrippingModeInvalid = $"{nameof(GPUResidentDrawer)} \"BatchRendererGroup Variants\" setting must be \"Keep All\". " +
19+
" The current setting will cause errors when building a player because all DOTS instancing shaders will be stripped" +
20+
" To fix, modify Graphics settings and set \"BatchRendererGroup Variants\" to \"Keep All\".";
21+
}
22+
23+
internal static bool IsProjectSupported()
24+
{
25+
return IsProjectSupported(out string _, out LogType __);
26+
}
27+
28+
internal static bool IsProjectSupported(out string message, out LogType severity)
29+
{
30+
message = string.Empty;
31+
severity = LogType.Log;
32+
33+
// The GPUResidentDrawer only has support when the RawBuffer path of providing data
34+
// ConstantBuffer path and any other unsupported platforms early out here
35+
if (BatchRendererGroup.BufferTarget != BatchBufferTarget.RawBuffer)
36+
{
37+
severity = LogType.Warning;
38+
message = Strings.rawBufferNotSupportedByPlatform;
39+
return false;
40+
}
41+
42+
#if UNITY_EDITOR
43+
// Check the build target is supported by checking the depth downscale kernel (which has an only_renderers pragma) is present
44+
var resources = GraphicsSettings.GetRenderPipelineSettings<GPUResidentDrawerResources>();
45+
if (!resources.occluderDepthPyramidKernels.HasKernel("OccluderDepthDownscale"))
46+
{
47+
severity = LogType.Warning;
48+
message = Strings.kernelNotPresent;
49+
return false;
50+
}
51+
52+
if (EditorGraphicsSettings.batchRendererGroupShaderStrippingMode != BatchRendererGroupStrippingMode.KeepAll)
53+
{
54+
severity = LogType.Warning;
55+
message = Strings.batchRendererGroupShaderStrippingModeInvalid;
56+
return false;
57+
}
58+
#endif
59+
60+
return true;
61+
}
62+
63+
internal static bool IsGPUResidentDrawerSupportedBySRP(GPUResidentDrawerSettings settings, out string message, out LogType severity)
64+
{
65+
message = string.Empty;
66+
severity = LogType.Log;
67+
68+
// nothing to create
69+
if (settings.mode == GPUResidentDrawerMode.Disabled)
70+
{
71+
message = Strings.drawerModeDisabled;
72+
return false;
73+
}
74+
75+
#if UNITY_EDITOR
76+
// In play mode, the GPU Resident Drawer is always allowed.
77+
// In edit mode, the GPU Resident Drawer is only allowed if the user explicitly requests it with a setting.
78+
bool isAllowedInCurrentMode = EditorApplication.isPlayingOrWillChangePlaymode || settings.allowInEditMode;
79+
if (!isAllowedInCurrentMode)
80+
{
81+
message = Strings.allowInEditModeDisabled;
82+
return false;
83+
}
84+
#endif
85+
// If we are forcing the system, no need to perform further checks
86+
if (IsForcedOnViaCommandLine())
87+
return true;
88+
89+
if (GraphicsSettings.currentRenderPipeline is not IGPUResidentRenderPipeline asset)
90+
{
91+
message = Strings.notGPUResidentRenderPipeline;
92+
severity = LogType.Warning;
93+
return false;
94+
}
95+
96+
return asset.IsGPUResidentDrawerSupportedBySRP(out message, out severity) && IsProjectSupported(out message, out severity);
97+
}
98+
99+
internal static void LogMessage(string message, LogType severity)
100+
{
101+
switch (severity)
102+
{
103+
case LogType.Error:
104+
case LogType.Exception:
105+
Debug.LogError(message);
106+
break;
107+
case LogType.Warning:
108+
Debug.LogWarning(message);
109+
break;
110+
}
111+
}
112+
}
113+
}

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.Validator.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace UnityEngine.Rendering
2424
/// <summary>
2525
/// Static utility class for updating data post cull in begin camera rendering
2626
/// </summary>
27-
public class GPUResidentDrawer
27+
public partial class GPUResidentDrawer
2828
{
2929
internal static GPUResidentDrawer instance { get => s_Instance; }
3030
private static GPUResidentDrawer s_Instance = null;
@@ -97,12 +97,12 @@ public static void UpdateInstanceOccluders(RenderGraph renderGraph, in OccluderP
9797

9898
/// <summary>
9999
/// Enable or disable GPUResidentDrawer based on the project settings.
100-
/// We call this every frame bacause GPUResidentDrawer can be enabled/disabled by the settings outside the render pipeline asset.
100+
/// We call this every frame because GPUResidentDrawer can be enabled/disabled by the settings outside the render pipeline asset.
101101
/// </summary>
102102
public static void ReinitializeIfNeeded()
103103
{
104104
#if UNITY_EDITOR
105-
if (!IsForcedOnViaCommandLine() && (IsProjectSupported(false) != IsEnabled()))
105+
if (!IsForcedOnViaCommandLine() && (IsProjectSupported() != IsEnabled()))
106106
{
107107
Reinitialize();
108108
}
@@ -211,48 +211,12 @@ private static void OnAssemblyReload()
211211
}
212212
#endif
213213

214-
internal static bool IsProjectSupported(bool logReason = false)
215-
{
216-
bool supported = true;
217-
218-
// The GPUResidentDrawer only has support when the RawBuffer path of providing data
219-
// ConstantBuffer path and any other unsupported platforms early out here
220-
if (BatchRendererGroup.BufferTarget != BatchBufferTarget.RawBuffer)
221-
{
222-
if(logReason)
223-
Debug.LogWarning($"GPUResidentDrawer: The current platform does not support {BatchBufferTarget.RawBuffer.GetType()}");
224-
supported = false;
225-
}
226-
227-
#if UNITY_EDITOR
228-
// Check the build target is supported by checking the depth downscale kernel (which has an only_renderers pragma) is present
229-
var resources = GraphicsSettings.GetRenderPipelineSettings<GPUResidentDrawerResources>();
230-
if (!resources.occluderDepthPyramidKernels.HasKernel("OccluderDepthDownscale"))
231-
{
232-
if (logReason)
233-
Debug.LogWarning("GPUResidentDrawer: kernel not present, please ensure the player settings includes a supported graphics API.");
234-
supported = false;
235-
}
236-
237-
if (EditorGraphicsSettings.batchRendererGroupShaderStrippingMode != BatchRendererGroupStrippingMode.KeepAll)
238-
{
239-
if(logReason)
240-
Debug.LogWarning(
241-
"GPUResidentDrawer: \"BatchRendererGroup Variants\" setting must be \"Keep All\". " +
242-
" The current setting will cause errors when building a player because all DOTS instancing shaders will be stripped" +
243-
" To fix, modify Graphics settings and set \"BatchRendererGroup Variants\" to \"Keep All\".");
244-
supported = false;
245-
}
246-
#endif
247-
return supported;
248-
}
249-
250214
internal static bool IsEnabled()
251215
{
252216
return s_Instance is not null;
253217
}
254218

255-
private static GPUResidentDrawerSettings GetGlobalSettingsFromRPAsset()
219+
internal static GPUResidentDrawerSettings GetGlobalSettingsFromRPAsset()
256220
{
257221
var renderPipelineAsset = GraphicsSettings.currentRenderPipeline;
258222
if (renderPipelineAsset is not IGPUResidentRenderPipeline mbAsset)
@@ -328,42 +292,14 @@ private static void CleanUp()
328292
private static void Recreate(GPUResidentDrawerSettings settings)
329293
{
330294
CleanUp();
331-
332-
// nothing to create
333-
if (settings.mode == GPUResidentDrawerMode.Disabled)
334-
return;
335-
336-
#if UNITY_EDITOR
337-
// In play mode, the GPU Resident Drawer is always allowed.
338-
// In edit mode, the GPU Resident Drawer is only allowed if the user explicitly requests it with a setting.
339-
bool isAllowedInCurrentMode = EditorApplication.isPlayingOrWillChangePlaymode || settings.allowInEditMode;
340-
if (!isAllowedInCurrentMode)
295+
if (IsGPUResidentDrawerSupportedBySRP(settings, out var message, out var severity))
341296
{
342-
return;
297+
s_Instance = new GPUResidentDrawer(settings, 4096, 0);
343298
}
344-
#endif
345-
346-
bool supported = true;
347-
if (!IsForcedOnViaCommandLine())
299+
else
348300
{
349-
var mbAsset = GraphicsSettings.currentRenderPipeline as IGPUResidentRenderPipeline;
350-
if (mbAsset == null)
351-
{
352-
Debug.LogWarning("GPUResidentDrawer: Disabled due to current render pipeline not being of type IGPUResidentDrawerRenderPipeline");
353-
supported = false;
354-
}
355-
else
356-
supported &= mbAsset.IsGPUResidentDrawerSupportedBySRP(true);
357-
supported &= IsProjectSupported(true);
301+
LogMessage(message, severity);
358302
}
359-
360-
// not supported
361-
if (!supported)
362-
{
363-
return;
364-
}
365-
366-
s_Instance = new GPUResidentDrawer(settings, 4096, 0);
367303
}
368304

369305
internal GPUResidentBatcher batcher { get => m_Batcher; }

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/IGPUResidentRenderPipeline.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ static void ReinitializeGPUResidentDrawer()
101101
/// <returns>true if supported</returns>
102102
bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
103103
{
104+
bool supported = IsGPUResidentDrawerSupportedBySRP(out var message, out var severity);
105+
if (logReason && !supported)
106+
GPUResidentDrawer.LogMessage(message, severity);
107+
return supported;
108+
}
109+
110+
/// <summary>
111+
/// Is the GPU resident drawer supported on this render pipeline.
112+
/// </summary>
113+
/// <param name="message">Why the system is not supported</param>
114+
/// <param name="severity">The severity of the message</param>
115+
/// <returns>true if supported</returns>
116+
bool IsGPUResidentDrawerSupportedBySRP(out string message, out LogType severity)
117+
{
118+
message = string.Empty;
119+
severity = LogType.Log;
104120
return true;
105121
}
106122

@@ -111,7 +127,12 @@ bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
111127
/// <returns>true if supported</returns>
112128
static bool IsGPUResidentDrawerSupportedByProjectConfiguration(bool logReason = false)
113129
{
114-
return GPUResidentDrawer.IsProjectSupported(logReason);
130+
bool supported = GPUResidentDrawer.IsProjectSupported(out var message, out var severity);
131+
if (logReason && !string.IsNullOrEmpty(message))
132+
{
133+
Debug.LogWarning(message);
134+
}
135+
return supported;
115136
}
116137

117138
/// <summary>

0 commit comments

Comments
 (0)