Skip to content

Commit 1faefc5

Browse files
arttu-peltonenEvergreen
authored andcommitted
Fix opening "Project Settings > Graphics" caused RG Viewer to become empty
Fix https://jira.unity3d.com/browse/UUM-66952 Graphics Settings UI on URP needs to recreate the render pipeline whenever user changes the "Compatibility mode" checkbox in graphics settings. This change was being detected incorrectly, causing render pipeline to be recreated every time the tab is selected on URP, which in turn triggers RG Viewer to be refreshed. Fixed the issue and added a unit test for it. Also did a minor adjustment of empty state texts based on QA & UX feedback.
1 parent 6825230 commit 1faefc5

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed

Packages/com.unity.render-pipelines.core/Editor/RenderGraph/RenderGraphViewer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ static partial class Classes
127127
enum EmptyStateReason
128128
{
129129
None = 0,
130+
NoGraphRegistered,
130131
NoExecutionRegistered,
131132
NoDataAvailable,
132133
WaitingForCameraRender,
@@ -137,7 +138,8 @@ enum EmptyStateReason
137138
static readonly string[] kEmptyStateMessages =
138139
{
139140
"",
140-
L10n.Tr("The selected camera is not active. Activate the selected camera to display data in the Render Graph viewer."),
141+
L10n.Tr("No Render Graph has been registered. The Render Graph Viewer is only functional when Render Graph API is in use."),
142+
L10n.Tr("The selected camera has not rendered anything yet. Interact with the selected camera to display data in the Render Graph Viewer."),
141143
L10n.Tr("No data to display. Click refresh to capture data."),
142144
L10n.Tr("Waiting for the selected camera to render. Depending on the camera, you may need to trigger rendering by selecting the Scene or Game view."),
143145
L10n.Tr("No passes to display. Select a different Pass Filter to display contents."),
@@ -1399,6 +1401,12 @@ void RebuildGraphViewerUI()
13991401
ClearGraphViewerUI();
14001402
ClearEmptyStateMessage();
14011403

1404+
if (m_RegisteredGraphs.Count == 0)
1405+
{
1406+
SetEmptyStateMessage(EmptyStateReason.NoGraphRegistered);
1407+
return;
1408+
}
1409+
14021410
if (!CaptureEnabled())
14031411
{
14041412
SetEmptyStateMessage(EmptyStateReason.NoExecutionRegistered);

Packages/com.unity.render-pipelines.universal/Editor/Settings/PropertyDrawers/URPRenderGraphPropertyDrawer.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,29 @@ class RenderGraphPropertyDrawer : PropertyDrawer
1414
private const string k_EnableRenderCompatibilityModeLabel = "Compatibility Mode (Render Graph Disabled)";
1515
private const string k_EnableRenderCompatibilityModeHelpBoxLabel = "Unity no longer develops or improves the rendering path that does not use Render Graph API. Use the Render Graph API when developing new graphics features.";
1616

17+
bool m_EnableCompatibilityModeValue;
18+
1719
/// <inheritdoc/>
1820
public override VisualElement CreatePropertyGUI(SerializedProperty property)
1921
{
2022
m_Root = new VisualElement();
2123
var enableCompatilityModeProp = property.FindPropertyRelative(k_EnableRenderCompatibilityPropertyName);
2224
var enableCompatibilityMode = new PropertyField(enableCompatilityModeProp, k_EnableRenderCompatibilityModeLabel);
2325

24-
// UITK raises ValueChangeCallback at bind time, so we need to ignore the first event
25-
bool firstTime = true;
26+
// UITK raises ValueChangeCallback at various times, so we need to track the actual value
27+
m_EnableCompatibilityModeValue = enableCompatilityModeProp.boolValue;
2628

2729
m_Root.Add(enableCompatibilityMode);
2830
enableCompatibilityMode.RegisterValueChangeCallback((onchanged) =>
2931
{
3032
m_Root.Q<HelpBox>("HelpBoxWarning").style.display = (onchanged.changedProperty.boolValue) ? DisplayStyle.Flex : DisplayStyle.None;
31-
if (firstTime)
33+
34+
bool newValue = onchanged.changedProperty.boolValue;
35+
if (m_EnableCompatibilityModeValue != newValue)
3236
{
33-
firstTime = false;
34-
return;
37+
m_EnableCompatibilityModeValue = newValue;
38+
GraphicsSettings.GetRenderPipelineSettings<RenderGraphSettings>()?.NotifyValueChanged(onchanged.changedProperty.name);
3539
}
36-
37-
GraphicsSettings.GetRenderPipelineSettings<RenderGraphSettings>()?.NotifyValueChanged(onchanged.changedProperty.name);
3840
});
3941

4042
m_Root.Add(new HelpBox(k_EnableRenderCompatibilityModeHelpBoxLabel, HelpBoxMessageType.Warning)

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/Common/Runtime/RenderPipelineScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public RenderPipelineScope(Type renderPipelineType, bool forceInitialization = f
7171
}
7272
}
7373

74-
static void ForceInitialization()
74+
public static void ForceInitialization()
7575
{
7676
if (Camera.main != null)
7777
Camera.main.Render();
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections;
3+
using Common;
4+
using NUnit.Framework;
5+
using UnityEditor;
6+
using UnityEngine;
7+
using UnityEngine.Rendering;
8+
using UnityEngine.Rendering.HighDefinition;
9+
using UnityEngine.Rendering.Universal;
10+
using UnityEngine.TestTools;
11+
12+
namespace MultipleSRP.EditMode
13+
{
14+
public class GraphicsSettingsTests
15+
{
16+
RenderPipelineAsset m_GraphicsSettingsRPAsset;
17+
RenderPipelineAsset m_QualitySettingsRPAsset;
18+
19+
[SetUp]
20+
public void SetUp()
21+
{
22+
m_GraphicsSettingsRPAsset = GraphicsSettings.defaultRenderPipeline;
23+
m_QualitySettingsRPAsset = QualitySettings.renderPipeline;
24+
GraphicsSettings.defaultRenderPipeline = null;
25+
QualitySettings.renderPipeline = null;
26+
}
27+
28+
[TearDown]
29+
public void TearDown()
30+
{
31+
RenderPipelineManager.activeRenderPipelineDisposed -= PipelineDisposedCallback;
32+
GraphicsSettings.defaultRenderPipeline = m_GraphicsSettingsRPAsset;
33+
QualitySettings.renderPipeline = m_QualitySettingsRPAsset;
34+
}
35+
36+
void CloseOpenProjectSettingsWindows()
37+
{
38+
var projectSettingsWindows = Resources.FindObjectsOfTypeAll(typeof(ProjectSettingsWindow));
39+
if (projectSettingsWindows != null && projectSettingsWindows.Length > 0)
40+
{
41+
foreach (var window in projectSettingsWindows)
42+
(window as EditorWindow).Close();
43+
}
44+
}
45+
46+
void PipelineDisposedCallback()
47+
{
48+
Assert.Fail("Render Pipeline was disposed as a side effect of opening Project Settings > Graphics");
49+
}
50+
51+
[UnityTest]
52+
public IEnumerator RenderPipelineNotRecreatedWhenActivatingGraphicsSettingsTab(
53+
[Values(typeof(UniversalRenderPipelineAsset), typeof(HDRenderPipelineAsset))]
54+
Type rpType)
55+
{
56+
CloseOpenProjectSettingsWindows();
57+
58+
const string graphicsSettingsPath = "Project/Graphics";
59+
const string playerSettingsPath = "Project/Player";
60+
61+
IEnumerator WaitAFewFrames()
62+
{
63+
for (int i = 0; i < 10; i++)
64+
yield return null;
65+
}
66+
67+
using (new RenderPipelineScope(rpType, forceInitialization: true))
68+
{
69+
yield return WaitAFewFrames();
70+
71+
// Open Project Settings > Graphics (may trigger RP recreate on not-up-to-date projects)
72+
SettingsService.OpenProjectSettings(graphicsSettingsPath);
73+
yield return WaitAFewFrames();
74+
75+
// Switch to Player Settings tab
76+
SettingsService.OpenProjectSettings(playerSettingsPath);
77+
yield return WaitAFewFrames();
78+
79+
// Ensure the RP is actually initialized so that disposal is possible, subscribe to disposed event
80+
RenderPipelineScope.ForceInitialization();
81+
RenderPipelineManager.activeRenderPipelineDisposed += PipelineDisposedCallback;
82+
83+
// Switch back to Graphics Settings tab, wait in case RP recreate is triggered
84+
var window = SettingsService.OpenProjectSettings(graphicsSettingsPath);
85+
yield return WaitAFewFrames();
86+
87+
// All good if we reached here, cleanup
88+
RenderPipelineManager.activeRenderPipelineDisposed -= PipelineDisposedCallback;
89+
window.Close();
90+
}
91+
}
92+
}
93+
}

Tests/SRPTests/Projects/MultipleSRP_Tests/Assets/Tests/EditMode/GraphicsSettingsTests.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.

0 commit comments

Comments
 (0)