Commit 4cf01e3e by Jamie Madill Committed by Commit Bot

Clean up Overlay code duplication.

Adds common helper functions for Running Graphs and Histograms. Bug: angleproject:4965 Change-Id: I8c7295217c637e377b74b4a336eb151b8a7c9596 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2358518 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent ee0a9a34
......@@ -12,6 +12,8 @@
#include "libANGLE/Overlay.h"
#include "libANGLE/Overlay_font_autogen.h"
#include <functional>
namespace gl
{
namespace
......@@ -234,6 +236,23 @@ class AppendWidgetDataHelper
TextWidgetData *textWidget,
OverlayWidgetCounts *widgetCounts);
using FormatGraphTitleFunc = std::function<std::string(size_t maxValue)>;
static void AppendRunningGraphCommon(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts,
FormatGraphTitleFunc formatFunc);
using FormatHistogramTitleFunc =
std::function<std::string(size_t peakRange, size_t maxValueRange, size_t numRanges)>;
static void AppendRunningHistogramCommon(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts,
FormatHistogramTitleFunc formatFunc);
static void AppendGraphCommon(const overlay::Widget *widget,
const gl::Extents &imageExtent,
const std::vector<size_t> runningValues,
......@@ -276,6 +295,65 @@ void AppendWidgetDataHelper::AppendGraphCommon(const overlay::Widget *widget,
++(*widgetCounts)[WidgetInternalType::Graph];
}
void AppendWidgetDataHelper::AppendRunningGraphCommon(
const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts,
AppendWidgetDataHelper::FormatGraphTitleFunc formatFunc)
{
const overlay::RunningGraph *graph = static_cast<const overlay::RunningGraph *>(widget);
const size_t maxValue =
*std::max_element(graph->runningValues.begin(), graph->runningValues.end());
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / maxValue;
AppendGraphCommon(widget, imageExtent, graph->runningValues, graph->lastValueIndex + 1,
graphScale, graphWidget, widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
std::string text = formatFunc(maxValue);
AppendTextCommon(&graph->description, imageExtent, text, textWidget, widgetCounts);
}
}
// static
void AppendWidgetDataHelper::AppendRunningHistogramCommon(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts,
FormatHistogramTitleFunc formatFunc)
{
const overlay::RunningHistogram *secondaryCommandBufferPoolWaste =
static_cast<const overlay::RunningHistogram *>(widget);
std::vector<size_t> histogram = CreateHistogram(secondaryCommandBufferPoolWaste->runningValues);
auto peakRangeIt = std::max_element(histogram.rbegin(), histogram.rend());
const size_t peakRangeValue = *peakRangeIt;
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / peakRangeValue;
auto maxValueIter =
std::find_if(histogram.rbegin(), histogram.rend(), [](size_t value) { return value != 0; });
AppendGraphCommon(widget, imageExtent, histogram, 0, graphScale, graphWidget, widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
size_t peakRange = std::distance(peakRangeIt, histogram.rend() - 1);
size_t maxValueRange = std::distance(maxValueIter, histogram.rend() - 1);
std::string text = formatFunc(peakRange, maxValueRange, histogram.size());
AppendTextCommon(&secondaryCommandBufferPoolWaste->description, imageExtent, text,
textWidget, widgetCounts);
}
}
void AppendWidgetDataHelper::AppendFPS(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
......@@ -324,25 +402,13 @@ void AppendWidgetDataHelper::AppendVulkanCommandGraphSize(const overlay::Widget
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts)
{
const overlay::RunningGraph *commandGraphSize =
static_cast<const overlay::RunningGraph *>(widget);
const size_t maxValue = *std::max_element(commandGraphSize->runningValues.begin(),
commandGraphSize->runningValues.end());
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / maxValue;
AppendGraphCommon(widget, imageExtent, commandGraphSize->runningValues,
commandGraphSize->lastValueIndex + 1, graphScale, graphWidget, widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
auto format = [](size_t maxValue) {
std::ostringstream text;
text << "Command Graph Size (Max: " << maxValue << ")";
AppendTextCommon(&commandGraphSize->description, imageExtent, text.str(), textWidget,
widgetCounts);
}
return text.str();
};
AppendRunningGraphCommon(widget, imageExtent, textWidget, graphWidget, widgetCounts, format);
}
void AppendWidgetDataHelper::AppendVulkanRenderPassCount(const overlay::Widget *widget,
......@@ -351,25 +417,13 @@ void AppendWidgetDataHelper::AppendVulkanRenderPassCount(const overlay::Widget *
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts)
{
const overlay::RunningGraph *renderPassCount =
static_cast<const overlay::RunningGraph *>(widget);
const size_t maxValue = *std::max_element(renderPassCount->runningValues.begin(),
renderPassCount->runningValues.end());
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / maxValue;
AppendGraphCommon(widget, imageExtent, renderPassCount->runningValues,
renderPassCount->lastValueIndex + 1, graphScale, graphWidget, widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
auto format = [](size_t maxValue) {
std::ostringstream text;
text << "RenderPass Count (Max: " << maxValue << ")";
AppendTextCommon(&renderPassCount->description, imageExtent, text.str(), textWidget,
widgetCounts);
}
return text.str();
};
AppendRunningGraphCommon(widget, imageExtent, textWidget, graphWidget, widgetCounts, format);
}
void AppendWidgetDataHelper::AppendVulkanSecondaryCommandBufferPoolWaste(
......@@ -379,28 +433,15 @@ void AppendWidgetDataHelper::AppendVulkanSecondaryCommandBufferPoolWaste(
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts)
{
const overlay::RunningHistogram *secondaryCommandBufferPoolWaste =
static_cast<const overlay::RunningHistogram *>(widget);
std::vector<size_t> histogram = CreateHistogram(secondaryCommandBufferPoolWaste->runningValues);
auto maxValueIter = std::max_element(histogram.rbegin(), histogram.rend());
const size_t maxValue = *maxValueIter;
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / maxValue;
AppendGraphCommon(widget, imageExtent, histogram, 0, graphScale, graphWidget, widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
auto format = [](size_t peakRange, size_t maxValueRange, size_t numRanges) {
std::ostringstream text;
size_t peak = std::distance(maxValueIter, histogram.rend() - 1);
size_t peakPercent = (peak * 100 + 50) / histogram.size();
size_t peakPercent = (peakRange * 100 + 50) / numRanges;
text << "CB Pool Waste (Peak: " << peakPercent << "%)";
AppendTextCommon(&secondaryCommandBufferPoolWaste->description, imageExtent, text.str(),
textWidget, widgetCounts);
}
return text.str();
};
AppendRunningHistogramCommon(widget, imageExtent, textWidget, graphWidget, widgetCounts,
format);
}
void AppendWidgetDataHelper::AppendVulkanWriteDescriptorSetCount(const overlay::Widget *widget,
......@@ -409,26 +450,13 @@ void AppendWidgetDataHelper::AppendVulkanWriteDescriptorSetCount(const overlay::
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts)
{
const overlay::RunningGraph *writeDescriptorSetCount =
static_cast<const overlay::RunningGraph *>(widget);
const size_t maxValue = *std::max_element(writeDescriptorSetCount->runningValues.begin(),
writeDescriptorSetCount->runningValues.end());
const int32_t graphHeight = std::abs(widget->coords[3] - widget->coords[1]);
const float graphScale = static_cast<float>(graphHeight) / maxValue;
AppendGraphCommon(widget, imageExtent, writeDescriptorSetCount->runningValues,
writeDescriptorSetCount->lastValueIndex + 1, graphScale, graphWidget,
widgetCounts);
if ((*widgetCounts)[WidgetInternalType::Text] <
kWidgetInternalTypeMaxWidgets[WidgetInternalType::Text])
{
auto format = [](size_t maxValue) {
std::ostringstream text;
text << "WriteDescriptorSet Count (Max: " << maxValue << ")";
AppendTextCommon(&writeDescriptorSetCount->description, imageExtent, text.str(), textWidget,
widgetCounts);
}
return text.str();
};
AppendRunningGraphCommon(widget, imageExtent, textWidget, graphWidget, widgetCounts, format);
}
std::ostream &AppendWidgetDataHelper::OutputPerSecond(std::ostream &out,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment