Просмотр исходного кода

Added support for sorting results according to diff score against the local baseline images, in addition to the official baseline images.
(This wasn't directly related the shader details tool work, but I happened to have these changes and it's convenient to just put them on the same feature branch).

Signed-off-by: santorac <[email protected]>

santorac 3 лет назад
Родитель
Сommit
0299257c35

+ 56 - 18
Gem/Code/Source/Automation/ScriptReporter.cpp

@@ -23,6 +23,11 @@ namespace AtomSampleViewer
     {
         "All Results", "Warnings & Errors", "Errors Only",
     };
+    
+    static const char* SortOptions[] =
+    {
+        "Sort by Script", "Sort by Official Baseline Diff Score", "Sort by Local Baseline Diff Score",
+    };
 
     namespace ScreenshotPaths
     {
@@ -148,7 +153,8 @@ namespace AtomSampleViewer
     void ScriptReporter::Reset()
     {
         m_scriptReports.clear();
-        m_descendingThresholdReports.clear();
+        m_reportsSortedByOfficialBaslineScore.clear();
+        m_reportsSortedByLocaBaslineScore.clear();
         m_currentScriptIndexStack.clear();
         m_invalidationMessage.clear();
         m_uniqueTimestamp = GenerateTimestamp();
@@ -422,7 +428,10 @@ namespace AtomSampleViewer
             ImGui::Combo("Display", &displayOption, DiplayOptions, AZ_ARRAY_SIZE(DiplayOptions));
             m_displayOption = (DisplayOption)displayOption;
 
-            ImGui::Checkbox("Show Script Reports Sorted By Threshold", &m_showReportsSortedByThreshold);
+            int sortOption = m_currentSortOption;
+            ImGui::Combo("Sort Results", &sortOption, SortOptions, AZ_ARRAY_SIZE(SortOptions));
+            m_currentSortOption = (SortOption)sortOption;
+
             ImGui::Checkbox("Force Show 'Update' Buttons", &m_forceShowUpdateButtons);
             ImGui::Checkbox("Force Show 'Export Png Diff' Buttons", &m_forceShowExportPngDiffButtons);
 
@@ -431,7 +440,7 @@ namespace AtomSampleViewer
 
             ImGui::Separator();
 
-            if (!m_showReportsSortedByThreshold)
+            if (m_currentSortOption == SortOption::Unsorted)
             {
                 for (ScriptReport& scriptReport : m_scriptReports)
                 {
@@ -540,24 +549,49 @@ namespace AtomSampleViewer
             }
             else
             {
-                for (const auto& [threshold, reportIndex] : m_descendingThresholdReports)
+                const SortedReportIndexMap* sortedReportMap = nullptr;
+                if (m_currentSortOption == SortOption::OfficialBaselineDiffScore)
+                {
+                    sortedReportMap = &m_reportsSortedByOfficialBaslineScore;
+                }
+                else if (m_currentSortOption == SortOption::LocalBaselineDiffScore)
                 {
-                    ScriptReport& scriptReport = m_scriptReports[reportIndex.first];
-                    ScreenshotTestInfo& screenshotResult = scriptReport.m_screenshotTests[reportIndex.second];
+                    sortedReportMap = &m_reportsSortedByLocaBaslineScore;
+                }
 
-                    const bool screenshotPassed = screenshotResult.m_officialComparisonResult.m_resultCode == ImageComparisonResult::ResultCode::Pass;
+                AZ_Assert(sortedReportMap, "Unhandled m_currentSortOption");
 
-                    AZStd::string fileName;
-                    AzFramework::StringFunc::Path::GetFullFileName(screenshotResult.m_screenshotFilePath.c_str(), fileName);
+                if (sortedReportMap)
+                {
+                    for (const auto& [threshold, reportIndex] : *sortedReportMap)
+                    {
+                        ScriptReport& scriptReport = m_scriptReports[reportIndex.first];
+                        ScreenshotTestInfo& screenshotResult = scriptReport.m_screenshotTests[reportIndex.second];
 
-                    AZStd::string header = AZStd::string::format("%s %s %s '%s' %f",
-                        screenshotPassed ? "PASSED" : "FAILED",
-                        scriptReport.m_scriptAssetPath.c_str(),
-                        fileName.c_str(),
-                        screenshotResult.m_toleranceLevel.m_name.c_str(),
-                        screenshotResult.m_officialComparisonResult.m_finalDiffScore);
+                        float diffScore = 0.0f;
+                        if (m_currentSortOption == SortOption::OfficialBaselineDiffScore)
+                        {
+                            diffScore = screenshotResult.m_officialComparisonResult.m_standardDiffScore;
+                        }
+                        else if (m_currentSortOption == SortOption::LocalBaselineDiffScore)
+                        {
+                            diffScore = screenshotResult.m_localComparisonResult.m_standardDiffScore;
+                        }
+
+                        const bool screenshotPassed = screenshotResult.m_officialComparisonResult.m_resultCode == ImageComparisonResult::ResultCode::Pass;
+
+                        AZStd::string fileName;
+                        AzFramework::StringFunc::Path::GetFullFileName(screenshotResult.m_screenshotFilePath.c_str(), fileName);
 
-                    ShowScreenshotTestInfoTreeNode(header, scriptReport, screenshotResult);
+                        AZStd::string header = AZStd::string::format("%f %s %s %s '%s'",
+                            diffScore,
+                            screenshotPassed ? "PASSED" : "FAILED",
+                            scriptReport.m_scriptAssetPath.c_str(),
+                            fileName.c_str(),
+                            screenshotResult.m_toleranceLevel.m_name.c_str());
+
+                        ShowScreenshotTestInfoTreeNode(header, scriptReport, screenshotResult);
+                    }
                 }
             }
             ResetTextHighlight();
@@ -822,8 +856,12 @@ namespace AtomSampleViewer
             const AZStd::vector<ScriptReporter::ScreenshotTestInfo>& screenshotTestInfos = m_scriptReports[i].m_screenshotTests;
             for (size_t j = 0; j < screenshotTestInfos.size(); ++j)
             {
-                m_descendingThresholdReports.insert(AZStd::pair<float, ReportIndex>(
-                    screenshotTestInfos[j].m_officialComparisonResult.m_finalDiffScore,
+                m_reportsSortedByOfficialBaslineScore.insert(AZStd::pair<float, ReportIndex>(
+                    screenshotTestInfos[j].m_officialComparisonResult.m_standardDiffScore,
+                    ReportIndex{ i, j }));
+
+                m_reportsSortedByLocaBaslineScore.insert(AZStd::pair<float, ReportIndex>(
+                    screenshotTestInfos[j].m_localComparisonResult.m_standardDiffScore,
                     ReportIndex{ i, j }));
             }
         }

+ 14 - 2
Gem/Code/Source/Automation/ScriptReporter.h

@@ -224,6 +224,15 @@ namespace AtomSampleViewer
             WarningsAndErrors,
             ErrorsOnly
         };
+        
+        // Controls how screenshot reports are sorted
+        // Must match static const char* DiplayOptions in .cpp file
+        enum SortOption : int
+        {
+            Unsorted,
+            OfficialBaselineDiffScore,
+            LocalBaselineDiffScore
+        };
 
         static void ReportScriptError(const AZStd::string& message);
         static void ReportScriptWarning(const AZStd::string& message);
@@ -289,8 +298,11 @@ namespace AtomSampleViewer
             void UpdateColorSettings();
         };
 
-        AZStd::multimap<float, ReportIndex, AZStd::greater<float>> m_descendingThresholdReports;
-        bool m_showReportsSortedByThreshold = true;
+        using SortedReportIndexMap = AZStd::multimap<float, ReportIndex, AZStd::greater<float>>;
+
+        SortedReportIndexMap m_reportsSortedByOfficialBaslineScore;
+        SortedReportIndexMap m_reportsSortedByLocaBaslineScore;
+        SortOption m_currentSortOption = SortOption::OfficialBaselineDiffScore;
 
         ImGuiMessageBox m_messageBox;