Skip to content

Commit 12fd52a

Browse files
guillaumelevassEvergreen
authored andcommitted
Remove automatic backbuffer image resizing and standardize test resolutions to 1080p
1 parent 67773af commit 12fd52a

18 files changed

Lines changed: 426 additions & 465 deletions

File tree

Tests/SRPTests/Packages/com.unity.testing.hdrp/TestRunner/Editor/HDRP_TestSettings_Editor.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,23 @@ override public void OnInspectorGUI()
8181
EditorGUILayout.PropertyField(containsVFX);
8282
EditorGUILayout.PropertyField(doBeforeTest);
8383

84-
if(typedTarget.ImageComparisonSettings.UseBackBuffer)
84+
string resolutionSource = "";
85+
86+
if (typedTarget.ImageComparisonSettings.UseBackBuffer)
8587
{
86-
targetResolution = GetResolutionFromBackBufferResolutionEnum(typedTarget.ImageComparisonSettings.ImageResolution.ToString());
88+
// Default to 1080p when using backbuffer
89+
targetResolution = new Vector2(1920, 1080);
90+
resolutionSource = "Backbuffer Default (1920x1080)";
8791
}
8892
else
8993
{
9094
targetResolution = new Vector2(typedTarget.ImageComparisonSettings.TargetWidth, typedTarget.ImageComparisonSettings.TargetHeight);
95+
resolutionSource = $"Target {targetResolution.x}x{targetResolution.y}";
9196
}
9297

9398
liveViewSize = GUILayout.Toggle(liveViewSize, "When enabled, Game View resolution is updated live.");
9499

95-
if (GUILayout.Button("Set Game View Size") || liveViewSize && (prevWidth != targetResolution.x || prevHeight != targetResolution.y))
100+
if (GUILayout.Button($"Set Game View Size to {resolutionSource}") || liveViewSize && (prevWidth != targetResolution.x || prevHeight != targetResolution.y))
96101
{
97102
prevWidth = (int)targetResolution.x;
98103
prevHeight = (int)targetResolution.y;
@@ -114,12 +119,6 @@ override public void OnInspectorGUI()
114119
serializedObject.ApplyModifiedProperties();
115120
}
116121

117-
public Vector2 GetResolutionFromBackBufferResolutionEnum(string resolution)
118-
{
119-
string[] resolutionArray = resolution.ToString().Split('w')[1].Split('h');
120-
return new Vector2(int.Parse(resolutionArray[0]), int.Parse(resolutionArray[1]));
121-
}
122-
123122
void SetGameViewSize()
124123
{
125124
if (typedTarget == null) return;

Tests/SRPTests/Packages/com.unity.testing.urp/Scripts/Runtime/UniversalGraphicsTestSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using UnityEngine;
12
using UnityEngine.TestTools.Graphics;
23

34
public class UniversalGraphicsTestSettings : GraphicsTestSettings
@@ -16,7 +17,7 @@ public enum RenderBackendCompatibility
1617
}
1718
public RenderBackendCompatibility renderBackendCompatibility = RenderBackendCompatibility.RenderGraphAndNonRenderGraph;
1819

19-
[UnityEngine.Tooltip("If enabled, the back buffer resolution will be set to the value specified by Image Comparison Settings -> Image Resolution, before doing the back buffer capture.")]
20+
[HideInInspector]
2021
public bool SetBackBufferResolution = false;
2122

2223
public UniversalGraphicsTestSettings()

Tests/SRPTests/Packages/com.unity.testing.urp/Scripts/Runtime/UniversalGraphicsTests.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public static IEnumerator RunGraphicsTest(SceneGraphicsTestCase testCase)
2828
Watermark.showDeveloperWatermark = false;
2929
GraphicsTestLogger.Log(
3030
$"Running test case '{testCase}' with scene '{testCase.ScenePath}'.");
31-
GlobalResolutionSetter.SetResolution(RuntimePlatform.Android, width: 1920, height: 1080);
32-
GlobalResolutionSetter.SetResolution(RuntimePlatform.EmbeddedLinuxArm64, width: 1920, height: 1080);
3331

3432
SceneManager.LoadScene(testCase.ScenePath);
3533

@@ -73,22 +71,20 @@ public static IEnumerator RunGraphicsTest(SceneGraphicsTestCase testCase)
7371

7472
if (settings.SetBackBufferResolution)
7573
{
76-
// Set screen/backbuffer resolution before doing the capture in ImageAssert.AreEqual. This will avoid doing
77-
// any resizing/scaling of the rendered image when comparing with the reference image in ImageAssert.AreEqual.
78-
// This has to be done before WaitForEndOfFrame, as the request will only be applied after the frame ends.
79-
int targetWidth = settings.ImageComparisonSettings.TargetWidth;
80-
int targetHeight = settings.ImageComparisonSettings.TargetHeight;
81-
Screen.SetResolution(targetWidth, targetHeight, settings.ImageComparisonSettings.UseBackBuffer ? FullScreenMode.FullScreenWindow : Screen.fullScreenMode);
82-
83-
// Yield once to finish the current frame (this code runs before the rendering in a frame) with the former
84-
// resolution.
85-
// Yield twice to finish the next frame with the new resolution taking effect.
86-
// Note that once the yields finish and the test resumes after the next for loop, the rendering will be
87-
// in the same frame where the new resolution first took place. For effects such as motion vector
88-
// rendering it means if the aspect ratio changes after setting the resolution, the previous camera matrix
89-
// will be reset, cancelling out all the camera-based motions.
90-
// In this case (e.g. UniversalGraphicsTest_Terrain, test scene 300 and 301) increase the wait frame to 3
91-
// on the UniversalGraphicsTestSettings component.
74+
//This option is disabled and we keep it only to keep the extra wait frames and preserve the existing
75+
// reference image.
76+
77+
// Changing resolution during a test run introduce instabilities.
78+
// Decides of a resolution for a test run and leave it to that. The resolution for most
79+
// test projects is set to a constant 1080p,except when running in XR compatibility mode.
80+
81+
// XR compatibility mode changes resolution depending on the target size, because the image is
82+
// always captured from the backbuffer.
83+
84+
GraphicsTestLogger.Log(LogType.Log, "Set back buffer resolution is being deprecated and does not change the resolution anymore, it only introduces extra wait frames to the test.");
85+
86+
// Removing this line causes a subset of tests to fail. Removing it would require to update images
87+
// and revisit some tests.
9288
waitFrames = Mathf.Max(waitFrames, 2);
9389
}
9490

Tests/SRPTests/Packages/com.unity.testing.xr/Runtime/ConfigureMockHMD.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ static public int SetupTest(bool xrCompatible, int waitFrames, UnityEngine.TestT
3333
Unity.XR.MockHMD.MockHMD.SetRenderMode(Unity.XR.MockHMD.MockHMDBuildSettings.RenderMode.SinglePassInstanced);
3434

3535
// Configure MockHMD to match the original settings from the test scene
36-
UnityEngine.TestTools.Graphics.ImageAssert.GetImageResolution(settings, out int w, out int h);
36+
int w = 1920;
37+
int h = 1080;
38+
39+
if(!settings.UseBackBuffer)
40+
{
41+
w = settings.TargetWidth;
42+
h = settings.TargetHeight;
43+
}
44+
3745
Unity.XR.MockHMD.MockHMD.SetEyeResolution(w, h);
3846
Unity.XR.MockHMD.MockHMD.SetMirrorViewCrop(0.0f);
3947

Tests/SRPTests/Projects/HDRP_DXR_Tests/Assets/Tests/HDRP_DXR_Graphics_Tests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public class HDRP_Graphics_Tests
9595
public IEnumerator Run(SceneGraphicsTestCase testCase)
9696
{
9797
yield return HDRP_GraphicTestRunner.Run(testCase);
98+
}
99+
100+
[OneTimeSetUp]
101+
public void OneTimeSetUp()
102+
{
103+
// Standard resolution for backbuffer capture is 1080p
104+
Screen.SetResolution(1920, 1080, true);
98105
}
99106

100107
#if UNITY_EDITOR
@@ -148,6 +155,8 @@ public HDRP_GRD_DXR_Graphics_Tests(GpuResidentDrawerContext grdContext)
148155
[OneTimeSetUp]
149156
public void OneTimeSetUp()
150157
{
158+
// Standard resolution for backbuffer capture is 1080p
159+
Screen.SetResolution(1920, 1080, true);
151160
SceneManager.LoadScene("GraphicsTestTransitionScene", LoadSceneMode.Single);
152161
}
153162

Tests/SRPTests/Projects/HDRP_RuntimeTests/Assets/Tests/HDRP_Runtime_Graphics_Tests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public class HDRP_Runtime_Graphics_Tests
1313
: IPrebuildSetup
1414
#endif
1515
{
16+
[OneTimeSetUp]
17+
public void SetDefaultResolution()
18+
{
19+
// Standard resolution for backbuffer capture is 1080p
20+
Screen.SetResolution(1920, 1080, true);
21+
}
22+
1623
[UnityTest]
1724
[SceneGraphicsTest(@"Assets/Scenes/^[0-9]+")]
1825
[Timeout(450 * 1000)] // Set timeout to 450 sec. to handle complex scenes with many shaders (previous timeout was 300s)

Tests/SRPTests/Projects/HDRP_Tests/Assets/GraphicTests/Tests/HDRP_Graphics_Tests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public HDRP_Graphics_Tests(GpuResidentDrawerContext grdContext)
5454
[OneTimeSetUp]
5555
public void OneTimeSetUp()
5656
{
57+
// Standard resolution for backbuffer capture is 1080p
58+
Screen.SetResolution(1920, 1080, true);
5759
SceneManager.LoadScene("GraphicsTestTransitionScene", LoadSceneMode.Single);
5860
}
5961

0 commit comments

Comments
 (0)