Skip to content

Commit 7328b86

Browse files
olivierpratEvergreen
authored andcommitted
UUM-120684 : Fixed Scene Visibility toggle button not working with GRD
1 parent 0070610 commit 7328b86

File tree

7 files changed

+201
-6
lines changed

7 files changed

+201
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ private void OnEndSceneViewCameraRendering()
26142614

26152615
public void UpdateFrame(int cameraCount)
26162616
{
2617+
DisposeSceneViewHiddenBits();
26172618
DisposeCompactVisibilityMasks();
26182619
if (cameraCount > m_LODParamsToCameraID.Capacity)
26192620
m_LODParamsToCameraID.Capacity = cameraCount;

Tests/SRPTests/Packages/com.unity.testing.urp/Scripts/Editor/MultipleViewGCTest.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ public void SetUp()
4747

4848
m_RenderRequest = new UniversalRenderPipeline.SingleCameraRequest { destination = m_RenderTexture };
4949

50-
// Render first frame where gc is ok
51-
m_sceneView.Repaint();
52-
RenderPipeline.SubmitRenderRequest(Camera.main, m_RenderRequest);
50+
// Render a couple of frames to absorb any transitory GC allocations
51+
// See https://unity.slack.com/archives/C02LJ5VSV97/p1761922938875599
52+
const int numFramesToWarmup = 3;
53+
54+
for (int i = 0; i < numFramesToWarmup; i++)
55+
{
56+
m_sceneView.Repaint();
57+
RenderPipeline.SubmitRenderRequest(Camera.main, m_RenderRequest);
58+
}
5359
}
5460

5561
[OneTimeTearDown]
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Threading.Tasks;
4+
using UnityEditor;
5+
using UnityEditor.SceneManagement;
6+
using UnityEditor.TestTools.Graphics;
7+
using UnityEngine;
8+
using UnityEngine.Rendering;
9+
using UnityEngine.SceneManagement;
10+
using UnityEngine.TestTools.Graphics;
11+
12+
public class SceneViewVisibilityTests
13+
{
14+
static int s_ForwardPlusQualityLevel = 7;
15+
int m_PreviousQualityLevelIndex = 0;
16+
17+
[SetUp]
18+
public void SetUp()
19+
{
20+
const string scenePath = "Assets/CodeBasedTests/SceneViewVisibility.unity";
21+
EditorSceneManager.OpenScene(scenePath);
22+
23+
m_PreviousQualityLevelIndex = QualitySettings.GetQualityLevel();
24+
QualitySettings.SetQualityLevel(s_ForwardPlusQualityLevel, true);
25+
}
26+
27+
[TearDown]
28+
public void TearDown()
29+
{
30+
QualitySettings.SetQualityLevel(m_PreviousQualityLevelIndex, true);
31+
}
32+
33+
async Task RunTest(GraphicsTestCase testCase, Action<SceneView> setup)
34+
{
35+
const int numFramesToWarmup = 4;
36+
37+
var sceneView = EditorWindow.CreateWindow<SceneView>();
38+
sceneView.overlayCanvas.overlaysEnabled = false;
39+
sceneView.showGrid = false;
40+
sceneView.name = "TestSceneView";
41+
42+
for (int i = 0; i < numFramesToWarmup; i++)
43+
{
44+
await Task.Yield();
45+
}
46+
47+
setup(sceneView);
48+
49+
var halfASecond = new TimeSpan(0, 0, 0, 0, 500);
50+
var captureSettings = new SceneViewCaptureSettings(128, 128, halfASecond, halfASecond, Camera.main.transform);
51+
52+
var renderPipelineAsset = GraphicsSettings.currentRenderPipeline as IGPUResidentRenderPipeline;
53+
Assert.IsNotNull(renderPipelineAsset);
54+
55+
Texture2D capturedTexture = null;
56+
Texture2D grdCapturedTexture = null;
57+
58+
// GRD not supported on OpenGLCore
59+
if (SystemInfo.graphicsDeviceType != GraphicsDeviceType.OpenGLCore)
60+
{
61+
// Capture with GRD
62+
renderPipelineAsset.gpuResidentDrawerMode = GPUResidentDrawerMode.InstancedDrawing;
63+
sceneView.Repaint();
64+
grdCapturedTexture = await EditorWindowCapture.CaptureAsync(sceneView, captureSettings);
65+
}
66+
67+
// Capture without GRD
68+
renderPipelineAsset.gpuResidentDrawerMode = GPUResidentDrawerMode.Disabled;
69+
sceneView.Repaint();
70+
capturedTexture = await EditorWindowCapture.CaptureAsync(sceneView, captureSettings);
71+
72+
sceneView.Close();
73+
74+
ImageComparisonSettings imageComparisonSettings = new()
75+
{
76+
TargetWidth = capturedTexture.width,
77+
TargetHeight = capturedTexture.height,
78+
AverageCorrectnessThreshold = 0.01f
79+
};
80+
81+
try
82+
{
83+
ImageAssert.AreEqual(testCase.ReferenceImage.Image, capturedTexture, imageComparisonSettings);
84+
}
85+
catch (Exception e)
86+
{
87+
Assert.Fail("Without GPU Resident Drawer : " + e.Message);
88+
}
89+
90+
try
91+
{
92+
if (grdCapturedTexture != null)
93+
ImageAssert.AreEqual(testCase.ReferenceImage.Image, grdCapturedTexture, imageComparisonSettings);
94+
}
95+
catch (Exception e)
96+
{
97+
Assert.Fail("With GPU Resident Drawer : " + e.Message);
98+
}
99+
}
100+
101+
void SetupGameObjectVisibility(SceneView _)
102+
{
103+
var cube = GameObject.Find("Cube");
104+
var sphere = GameObject.Find("Sphere");
105+
106+
if (cube)
107+
{
108+
SceneVisibilityManager.instance.Hide(cube, false);
109+
}
110+
111+
if (sphere)
112+
{
113+
SceneVisibilityManager.instance.Hide(sphere, false);
114+
}
115+
}
116+
117+
void SetupSceneVisibility(SceneView sceneView)
118+
{
119+
SetupGameObjectVisibility(sceneView);
120+
SceneVisibilityManager.instance.Hide(SceneManager.GetActiveScene());
121+
}
122+
123+
void SetupSceneVisibilityReset(SceneView sceneView)
124+
{
125+
SetupSceneVisibility(sceneView);
126+
SceneVisibilityManager.instance.Show(SceneManager.GetActiveScene());
127+
}
128+
129+
static void SetSceneVisibilityEnabled(SceneView sceneView, bool isEnabled)
130+
{
131+
sceneView.sceneVisActive = isEnabled;
132+
}
133+
134+
void SetupSceneVisibilityEnabled(SceneView sceneView)
135+
{
136+
SetupSceneVisibility(sceneView);
137+
SetSceneVisibilityEnabled(sceneView, false);
138+
}
139+
140+
void SetupSceneVisibilityEnabledReset(SceneView sceneView)
141+
{
142+
SetupSceneVisibilityEnabled(sceneView);
143+
SetSceneVisibilityEnabled(sceneView, true);
144+
}
145+
146+
[Test, Category("Graphics"), GraphicsTest]
147+
[Ignore("Test disabled due to needing BRG stripping level set to Keep All with increased build times, UUM-120684")]
148+
public async Task GameObjectVisibilityWorks(GraphicsTestCase testCase)
149+
{
150+
await RunTest(testCase, SetupGameObjectVisibility);
151+
}
152+
153+
[Test, Category("Graphics"), GraphicsTest]
154+
[Ignore("Test disabled due to needing BRG stripping level set to Keep All with increased build times, UUM-120684")]
155+
public async Task SceneVisibilityWorks(GraphicsTestCase testCase)
156+
{
157+
await RunTest(testCase, SetupSceneVisibility);
158+
}
159+
160+
[Test, Category("Graphics"), GraphicsTest]
161+
[Ignore("Test disabled due to needing BRG stripping level set to Keep All with increased build times, UUM-120684")]
162+
public async Task SceneVisibilityResetWorks(GraphicsTestCase testCase)
163+
{
164+
await RunTest(testCase, SetupSceneVisibilityReset);
165+
}
166+
167+
[Test, Category("Graphics"), GraphicsTest]
168+
[Ignore("Test disabled due to needing BRG stripping level set to Keep All with increased build times, UUM-120684")]
169+
public async Task SceneVisibilityEnabledWorks(GraphicsTestCase testCase)
170+
{
171+
await RunTest(testCase, SetupSceneVisibilityEnabled);
172+
}
173+
174+
[Test, Category("Graphics"), GraphicsTest]
175+
[Ignore("Test disabled due to needing BRG stripping level set to Keep All with increased build times, UUM-120684")]
176+
public async Task SceneVisibilityEnabledResetWorks(GraphicsTestCase testCase)
177+
{
178+
await RunTest(testCase, SetupSceneVisibilityEnabledReset);
179+
}
180+
}
181+

Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Test/Editor/SceneViewVisibilityTests.cs.meta

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

Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Test/Editor/Unity.Testing.SRP.Universal.Foundation.Editor.asmdef

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "UniversalFoundationEditorTests",
2+
"name": "Unity.Testing.SRP.Universal.Foundation.Editor",
33
"rootNamespace": "",
44
"references": [
55
"GUID:e18141520846dcc44b725b2f74e91229",
@@ -13,7 +13,9 @@
1313
"GUID:36d514892e55d4340b470c29fcab8b44",
1414
"GUID:55aba1c6f9cf8e949aa77aaeccd46083",
1515
"GUID:adf6f42bac617413dbcd97c993ab7077",
16-
"GUID:df380645f10b7bc4b97d4f5eb6303d95"
16+
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
17+
"GUID:4fd6538c1c56b409fb53fdf0183170ec",
18+
"GUID:5d43e37b0ccc5b643bfc49b4bfa316d2"
1719
],
1820
"includePlatforms": [
1921
"Editor"

Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/ProjectSettings/GraphicsSettings.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ GraphicsSettings:
118118
UnityEditor.Rendering.DummyRenderPipeline: {fileID: 11400000, guid: c5514e40928c24e568cf97df2b3610dd,
119119
type: 2}
120120
UnityEngine.Rendering.Tests.RenderGraphTests+RenderGraphTestPipelineInstance: {fileID: 0}
121+
m_ShaderBuildSettings:
122+
keywordDeclarationOverrides: []
121123
m_LightsUseLinearIntensity: 1
122124
m_LightsUseColorTemperature: 1
123125
m_LogWhenShaderIsCompiled: 0

Tests/SRPTests/Projects/UniversalGraphicsTest_Lighting/ProjectSettings/GraphicsSettings.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ GraphicsSettings:
115115
m_RenderPipelineGlobalSettingsMap:
116116
UnityEngine.Rendering.Universal.UniversalRenderPipeline: {fileID: 11400000, guid: 7e7acb644b0c301488c70628952b1f1c,
117117
type: 2}
118+
m_ShaderBuildSettings:
119+
keywordDeclarationOverrides: []
118120
m_LightsUseLinearIntensity: 1
119121
m_LightsUseColorTemperature: 1
120-
m_DefaultRenderingLayerMask: 1
121122
m_LogWhenShaderIsCompiled: 0
122123
m_LightProbeOutsideHullStrategy: 0
123124
m_CameraRelativeLightCulling: 0

0 commit comments

Comments
 (0)