Files
UnrealEngineUWP/Engine/Source/Developer/FunctionalTesting/Public/AutomationBlueprintFunctionLibrary.h
guillaume abadie b000ccbd8e Changes default screen percentage behavior in editor to take more advantage of TSR's upscaling behavior already enabled by default
1) Editor viewports now display at high DPI by default for better Gen5-console feeling in editor on high DPI monitors.

2) Realtime editor viewports now display at screen percentage based on the display pixel count. Fix screen percentage independent of the pixel range could either render not enough pixel at low display resolution or be too slow at high display resolution. Given the level editor viewport can scale in size based on editor user layout preference, monitor, the screen percentage automatically scalling based on display pixel count gives a better experience of quality consistency/GPU cost for rendering frame, especially when going level editor fullscreen with F11 or not. The curve to compute rendering resolution from display resolution is in BaseEngine.ini

3) Non-realtime editor viewports still display at a screen percentage based on OS DPI scale, independent of the display pixel count because use spatial upscaler and therefore need consistent sharpness not worst than editor fonts, but keep same rendering resolution as before to not increase out of GPU memory errors. The performance of potentially rendering at high resolution than a realtime viewport is ignored given the non real-time viewports are not rendering every frame.

4) PIE viewports now override r.ScreenPercentage by default to have consistent resolution quality and performance between realtime editor viewport and gameplay viewport by default without risk of introducing out of GPU memory errors loosing possibly unsaved editor work if the game's graphic settings default to a screen percentage higher. To advertise discoverability of this change, any update to the r.ScreenPercentage cvar will lead to a message display in console/log if overriden by editor settings or dynamic resolution settings.

5) As much as a project can change the default anti-aliasing method, can also configure on a per project basis the default screen percentage behavior in project preference that the editor user can then override locally for his/her own use with his editor settings. For instance mobile only or forward renderer MSAA only video games.

6) When working very high end work-in progress rendering tech project in a econemic context where lattest GPUs are hard to get, the range of GPU performance can vary greatly between contributor of the same projects. To provide more robustness for lowerend GPU of collegues with tech not yet scaling, the project settings now offer a MaxRenderingResolution for editor viewports that can also be overriden on a per user basis.

7) Automated screenshot already takes care of forcing r.ScreenPercentage.

#rb none
#preflight 61e58d4a873f2ea48f33facd

#ROBOMERGE-AUTHOR: guillaume.abadie
#ROBOMERGE-SOURCE: CL 18633512 in //UE5/Release-5.0/... via CL 18633532 via CL 18633538
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v899-18417669)

[CL 18637384 by guillaume abadie in ue5-main branch]
2022-01-18 04:31:45 -05:00

247 lines
9.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Engine/LatentActionManager.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "AutomationScreenshotOptions.h"
#include "HAL/IConsoleManager.h"
#include "Templates/UniquePtr.h"
#include "Misc/AutomationTest.h"
#include "AutomationBlueprintFunctionLibrary.generated.h"
class ACameraActor;
/**
* FAutomationTaskStatusBase - abstract class for task status
*/
class FAutomationTaskStatusBase
{
public:
virtual ~FAutomationTaskStatusBase() = default;
bool IsDone() const { return Done; };
virtual void SetDone() { Done = true; };
protected:
bool Done = false;
};
/**
* UAutomationEditorTask
*/
UCLASS(BlueprintType, Transient)
class FUNCTIONALTESTING_API UAutomationEditorTask : public UObject
{
GENERATED_BODY()
public:
virtual ~UAutomationEditorTask() = default;
/** Query if the Editor task is done */
UFUNCTION(BlueprintCallable, Category = "Automation")
bool IsTaskDone() const;
/** Query if a task was setup */
UFUNCTION(BlueprintCallable, Category = "Automation")
bool IsValidTask() const;
void BindTask(TUniquePtr<FAutomationTaskStatusBase> inTask);
private:
TUniquePtr<FAutomationTaskStatusBase> Task;
};
USTRUCT(BlueprintType)
struct FAutomationWaitForLoadingOptions
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category = "Automation")
bool WaitForReplicationToSettle = false;
};
/**
*
*/
UCLASS(meta=(ScriptName="AutomationLibrary"))
class FUNCTIONALTESTING_API UAutomationBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Automation")
static void FinishLoadingBeforeScreenshot();
static bool TakeAutomationScreenshotInternal(UObject* WorldContextObject, const FString& ScreenShotName, const FString& Notes, FAutomationScreenshotOptions Options);
static FAutomationScreenshotData BuildScreenshotData(const FString& MapOrContext, const FString& ScreenShotName, int32 Width, int32 Height);
static FIntPoint GetAutomationScreenshotSize(const FAutomationScreenshotOptions& Options);
/**
* Takes a screenshot of the game's viewport. Does not capture any UI.
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (Latent, HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", LatentInfo = "LatentInfo", Name = "" ))
static void TakeAutomationScreenshot(UObject* WorldContextObject, FLatentActionInfo LatentInfo, const FString& Name, const FString& Notes, const FAutomationScreenshotOptions& Options);
/**
* Takes a screenshot of the game's viewport, from a particular camera actors POV. Does not capture any UI.
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (Latent, HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", LatentInfo = "LatentInfo", NameOverride = "" ))
static void TakeAutomationScreenshotAtCamera(UObject* WorldContextObject, FLatentActionInfo LatentInfo, ACameraActor* Camera, const FString& NameOverride, const FString& Notes, const FAutomationScreenshotOptions& Options);
/**
*
*/
static bool TakeAutomationScreenshotOfUI_Immediate(UObject* WorldContextObject, const FString& Name, const FAutomationScreenshotOptions& Options);
UFUNCTION(BlueprintCallable, Category = "Automation", meta = ( Latent, HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", LatentInfo = "LatentInfo", NameOverride = "" ))
static void TakeAutomationScreenshotOfUI(UObject* WorldContextObject, FLatentActionInfo LatentInfo, const FString& Name, const FAutomationScreenshotOptions& Options);
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static void EnableStatGroup(UObject* WorldContextObject, FName GroupName);
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static void DisableStatGroup(UObject* WorldContextObject, FName GroupName);
UFUNCTION(BlueprintCallable, Category = "Automation")
static float GetStatIncAverage(FName StatName);
UFUNCTION(BlueprintCallable, Category = "Automation")
static float GetStatIncMax(FName StatName);
UFUNCTION(BlueprintCallable, Category = "Automation")
static float GetStatExcAverage(FName StatName);
UFUNCTION(BlueprintCallable, Category = "Automation")
static float GetStatExcMax(FName StatName);
UFUNCTION(BlueprintCallable, Category = "Automation")
static float GetStatCallCount(FName StatName);
/**
* Lets you know if any automated tests are running, or are about to run and the automation system is spinning up tests.
*/
UFUNCTION(BlueprintPure, Category="Automation")
static bool AreAutomatedTestsRunning();
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (Latent, HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", LatentInfo = "LatentInfo"))
static void AutomationWaitForLoading(UObject* WorldContextObject, FLatentActionInfo LatentInfo, FAutomationWaitForLoadingOptions Options);
/**
* take high res screenshot in editor.
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (AdvancedDisplay="Camera, bMaskEnabled, bCaptureHDR, ComparisonTolerance, ComparisonNotes"))
static UAutomationEditorTask* TakeHighResScreenshot(int32 ResX, int32 ResY, FString Filename, ACameraActor* Camera = nullptr, bool bMaskEnabled = false, bool bCaptureHDR = false, EComparisonTolerance ComparisonTolerance = EComparisonTolerance::Low, FString ComparisonNotes = TEXT(""), float Delay = 0.0);
/**
* request image comparison.
* @param ImageFilePath Absolute path to the image location. All 8bit RGBA channels supported formats by the engine are accepted.
* @param ComparisonName Optional name for the comparison, by default the basename of ImageFilePath is used
* @return True if comparison was successfully enqueued
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (AdvancedDisplay = "ComparisonName, ComparisonTolerance, ComparisonNotes", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static bool CompareImageAgainstReference(FString ImageFilePath, FString ComparisonName = TEXT(""), EComparisonTolerance ComparisonTolerance = EComparisonTolerance::Low, FString ComparisonNotes = TEXT(""), UObject* WorldContextObject = nullptr);
/**
* Add Telemetry data to currently running automated test.
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (AdvancedDisplay = "Context"))
static void AddTestTelemetryData(FString DataPoint, float Measurement, FString Context = TEXT(""));
/**
* Set Telemetry data storage name of currently running automated test.
*/
UFUNCTION(BlueprintCallable, Category = "Automation")
static void SetTestTelemetryStorage(FString StorageName);
/**
*
*/
UFUNCTION(BlueprintPure, Category="Automation")
static FAutomationScreenshotOptions GetDefaultScreenshotOptionsForGameplay(EComparisonTolerance Tolerance = EComparisonTolerance::Low, float Delay = 0.2);
/**
*
*/
UFUNCTION(BlueprintPure, Category="Automation")
static FAutomationScreenshotOptions GetDefaultScreenshotOptionsForRendering(EComparisonTolerance Tolerance = EComparisonTolerance::Low, float Delay = 0.2);
/**
* Mute the report of log error and warning matching a pattern during an automated test
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (AdvancedDisplay = "Occurrences, ExactMatch"))
static void AddExpectedLogError(FString ExpectedPatternString, int32 Occurrences = 1, bool ExactMatch = false);
/**
* Sets all other settings based on an overall value
* @param Value 0:Cinematic, 1:Epic...etc.
*/
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static void SetScalabilityQualityLevelRelativeToMax(UObject* WorldContextObject, int32 Value = 1);
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static void SetScalabilityQualityToEpic(UObject* WorldContextObject);
UFUNCTION(BlueprintCallable, Category = "Automation", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
static void SetScalabilityQualityToLow(UObject* WorldContextObject);
};
#if WITH_AUTOMATION_TESTS
template<typename T>
class FConsoleVariableSwapperTempl
{
public:
FConsoleVariableSwapperTempl(FString InConsoleVariableName);
void Set(T Value);
void Restore();
private:
bool bModified;
FString ConsoleVariableName;
T OriginalValue;
};
class FAutomationTestScreenshotEnvSetup
{
public:
FAutomationTestScreenshotEnvSetup();
~FAutomationTestScreenshotEnvSetup();
// Disable AA, auto-exposure, motion blur, contact shadow if InOutOptions.bDisableNoisyRenderingFeatures.
// Update screenshot comparison tolerance stored in InOutOptions.
// Set visualization buffer name if required.
void Setup(UWorld* InWorld, FAutomationScreenshotOptions& InOutOptions);
/** Restore the old settings. */
void Restore();
private:
FConsoleVariableSwapperTempl<int32> DefaultFeature_AntiAliasing;
FConsoleVariableSwapperTempl<int32> DefaultFeature_AutoExposure;
FConsoleVariableSwapperTempl<int32> DefaultFeature_MotionBlur;
FConsoleVariableSwapperTempl<int32> MotionBlurQuality;
FConsoleVariableSwapperTempl<int32> ScreenSpaceReflectionQuality;
FConsoleVariableSwapperTempl<int32> EyeAdaptationQuality;
FConsoleVariableSwapperTempl<int32> ContactShadows;
FConsoleVariableSwapperTempl<float> TonemapperGamma;
FConsoleVariableSwapperTempl<float> TonemapperSharpen;
FConsoleVariableSwapperTempl<float> ScreenPercentage;
FConsoleVariableSwapperTempl<int32> ScreenPercentageMode;
FConsoleVariableSwapperTempl<int32> EditorViewportOverrideGameScreenPercentage;
FConsoleVariableSwapperTempl<float> SecondaryScreenPercentage;
TWeakObjectPtr<UWorld> WorldPtr;
TSharedPtr< class FAutomationViewExtension, ESPMode::ThreadSafe > AutomationViewExtension;
};
#endif