Commit 57393152 by Jamie Madill Committed by Commit Bot

Auto-gen more Overlay code.

We add a new header where we auto-generate the Widget ID. We also use a new X macro to generate per-widget arrays and tables. Bug: angleproject:4965 Change-Id: Ic53e5d1c47d5712a63c98c481c15f550f1f99692 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2358520 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 4cf01e3e
{ {
"src/libANGLE/Overlay_autogen.cpp": "src/libANGLE/Overlay_autogen.cpp":
"7d26b524a7547a19410ea7de72f17b6e", "7d26b524a7547a19410ea7de72f17b6e",
"src/libANGLE/Overlay_autogen.h":
"ba1a6ffb2302b6617d2ae048efcc14d4",
"src/libANGLE/gen_overlay_widgets.py": "src/libANGLE/gen_overlay_widgets.py":
"07252fbde304fd48559ae07f8f920a08", "e596822a0a7ba713510c5427c82ce938",
"src/libANGLE/overlay_widgets.json": "src/libANGLE/overlay_widgets.json":
"2d1804eb11e4f3ea214e80bf2e63c0df" "fea3f9e3b8738c1abdd31fa64d05d883"
} }
\ No newline at end of file
...@@ -22,14 +22,10 @@ namespace gl ...@@ -22,14 +22,10 @@ namespace gl
{ {
namespace namespace
{ {
#define ANGLE_WIDGET_NAME_PROC(WIDGET_ID) {ANGLE_STRINGIFY(WIDGET_ID), WidgetId::WIDGET_ID},
constexpr std::pair<const char *, WidgetId> kWidgetNames[] = { constexpr std::pair<const char *, WidgetId> kWidgetNames[] = {
{"FPS", WidgetId::FPS}, ANGLE_WIDGET_ID_X(ANGLE_WIDGET_NAME_PROC)};
{"VulkanLastValidationMessage", WidgetId::VulkanLastValidationMessage},
{"VulkanValidationMessageCount", WidgetId::VulkanValidationMessageCount},
{"VulkanRenderPassCount", WidgetId::VulkanRenderPassCount},
{"VulkanSecondaryCommandBufferPoolWaste", WidgetId::VulkanSecondaryCommandBufferPoolWaste},
{"VulkanWriteDescriptorSetCount", WidgetId::VulkanWriteDescriptorSetCount},
};
} // namespace } // namespace
OverlayState::OverlayState() : mEnabledWidgetCount(0), mOverlayWidgets{} {} OverlayState::OverlayState() : mEnabledWidgetCount(0), mOverlayWidgets{} {}
......
...@@ -181,47 +181,18 @@ using AppendWidgetDataFunc = void (*)(const overlay::Widget *widget, ...@@ -181,47 +181,18 @@ using AppendWidgetDataFunc = void (*)(const overlay::Widget *widget,
namespace overlay_impl namespace overlay_impl
{ {
#define ANGLE_DECLARE_APPEND_WIDGET_PROC(WIDGET_ID) \
static void Append##WIDGET_ID(const overlay::Widget *widget, const gl::Extents &imageExtent, \
TextWidgetData *textWidget, GraphWidgetData *graphWidget, \
OverlayWidgetCounts *widgetCounts);
// This class interprets the generic data collected in every element into a human-understandable // This class interprets the generic data collected in every element into a human-understandable
// widget. This often means generating text specific to this item and scaling graph data to // widget. This often means generating text specific to this item and scaling graph data to
// something sensible. // something sensible.
class AppendWidgetDataHelper class AppendWidgetDataHelper
{ {
public: public:
static void AppendFPS(const overlay::Widget *widget, ANGLE_WIDGET_ID_X(ANGLE_DECLARE_APPEND_WIDGET_PROC)
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanLastValidationMessage(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanValidationMessageCount(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanCommandGraphSize(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanRenderPassCount(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanSecondaryCommandBufferPoolWaste(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
static void AppendVulkanWriteDescriptorSetCount(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts);
private: private:
static std::ostream &OutputPerSecond(std::ostream &out, const overlay::PerSecond *perSecond); static std::ostream &OutputPerSecond(std::ostream &out, const overlay::PerSecond *perSecond);
...@@ -396,21 +367,6 @@ void AppendWidgetDataHelper::AppendVulkanValidationMessageCount(const overlay::W ...@@ -396,21 +367,6 @@ void AppendWidgetDataHelper::AppendVulkanValidationMessageCount(const overlay::W
AppendTextCommon(widget, imageExtent, text.str(), textWidget, widgetCounts); AppendTextCommon(widget, imageExtent, text.str(), textWidget, widgetCounts);
} }
void AppendWidgetDataHelper::AppendVulkanCommandGraphSize(const overlay::Widget *widget,
const gl::Extents &imageExtent,
TextWidgetData *textWidget,
GraphWidgetData *graphWidget,
OverlayWidgetCounts *widgetCounts)
{
auto format = [](size_t maxValue) {
std::ostringstream text;
text << "Command Graph Size (Max: " << maxValue << ")";
return text.str();
};
AppendRunningGraphCommon(widget, imageExtent, textWidget, graphWidget, widgetCounts, format);
}
void AppendWidgetDataHelper::AppendVulkanRenderPassCount(const overlay::Widget *widget, void AppendWidgetDataHelper::AppendVulkanRenderPassCount(const overlay::Widget *widget,
const gl::Extents &imageExtent, const gl::Extents &imageExtent,
TextWidgetData *textWidget, TextWidgetData *textWidget,
...@@ -478,20 +434,12 @@ std::ostream &AppendWidgetDataHelper::OutputCount(std::ostream &out, const overl ...@@ -478,20 +434,12 @@ std::ostream &AppendWidgetDataHelper::OutputCount(std::ostream &out, const overl
namespace namespace
{ {
#define ANGLE_APPEND_WIDGET_MAP_PROC(WIDGET_ID) \
{WidgetId::WIDGET_ID, overlay_impl::AppendWidgetDataHelper::Append##WIDGET_ID},
constexpr angle::PackedEnumMap<WidgetId, AppendWidgetDataFunc> kWidgetIdToAppendDataFuncMap = { constexpr angle::PackedEnumMap<WidgetId, AppendWidgetDataFunc> kWidgetIdToAppendDataFuncMap = {
{WidgetId::FPS, overlay_impl::AppendWidgetDataHelper::AppendFPS}, ANGLE_WIDGET_ID_X(ANGLE_APPEND_WIDGET_MAP_PROC)};
{WidgetId::VulkanLastValidationMessage, } // namespace
overlay_impl::AppendWidgetDataHelper::AppendVulkanLastValidationMessage},
{WidgetId::VulkanValidationMessageCount,
overlay_impl::AppendWidgetDataHelper::AppendVulkanValidationMessageCount},
{WidgetId::VulkanRenderPassCount,
overlay_impl::AppendWidgetDataHelper::AppendVulkanRenderPassCount},
{WidgetId::VulkanSecondaryCommandBufferPoolWaste,
overlay_impl::AppendWidgetDataHelper::AppendVulkanSecondaryCommandBufferPoolWaste},
{WidgetId::VulkanWriteDescriptorSetCount,
overlay_impl::AppendWidgetDataHelper::AppendVulkanWriteDescriptorSetCount},
};
}
namespace overlay namespace overlay
{ {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBANGLE_OVERLAYWIDGETS_H_ #define LIBANGLE_OVERLAYWIDGETS_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Overlay_autogen.h"
namespace gl namespace gl
{ {
...@@ -44,30 +45,6 @@ enum class WidgetType ...@@ -44,30 +45,6 @@ enum class WidgetType
EnumCount = InvalidEnum, EnumCount = InvalidEnum,
}; };
enum class WidgetId
{
// Front-end widgets:
// Frames per second (PerSecond).
FPS,
// Vulkan backend:
// Last validation error (Text).
VulkanLastValidationMessage,
// Number of validation errors and warnings (Count).
VulkanValidationMessageCount,
// Number of RenderPasses in a frame (RunningGraph).
VulkanRenderPassCount,
// Secondary Command Buffer pool memory waste (RunningHistogram).
VulkanSecondaryCommandBufferPoolWaste,
// Number of Descriptor Set writes in a frame (RunningGraph).
VulkanWriteDescriptorSetCount,
InvalidEnum,
EnumCount = InvalidEnum,
};
namespace overlay namespace overlay
{ {
class Widget class Widget
......
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_overlay_widgets.py using data from overlay_widgets.json.
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Overlay_autogen.cpp:
// Autogenerated overlay widget declarations.
namespace gl
{
enum class WidgetId
{
// Frames per second (Count/Second).
FPS,
// Last validation error (Text).
VulkanLastValidationMessage,
// Number of validation errors and warnings (Count).
VulkanValidationMessageCount,
// Number of RenderPasses in a frame (Count).
VulkanRenderPassCount,
// Secondary Command Buffer pool memory waste (Bytes).
VulkanSecondaryCommandBufferPoolWaste,
// Number of Descriptor Set writes in a frame (Count).
VulkanWriteDescriptorSetCount,
InvalidEnum,
EnumCount = InvalidEnum,
};
// We can use this "X" macro to generate multiple code patterns.
#define ANGLE_WIDGET_ID_X(PROC) \
PROC(FPS) \
PROC(VulkanLastValidationMessage) \
PROC(VulkanValidationMessageCount) \
PROC(VulkanRenderPassCount) \
PROC(VulkanSecondaryCommandBufferPoolWaste) \
PROC(VulkanWriteDescriptorSetCount)
} // namespace gl
...@@ -13,10 +13,12 @@ from datetime import date ...@@ -13,10 +13,12 @@ from datetime import date
import json import json
import sys import sys
out_file = 'Overlay_autogen.cpp' OUT_SOURCE_FILE_NAME = 'Overlay_autogen.cpp'
in_file = 'overlay_widgets.json' OUT_HEADER_FILE_NAME = 'Overlay_autogen.h'
template_out_file = u"""// GENERATED FILE - DO NOT EDIT. IN_JSON_FILE_NAME = 'overlay_widgets.json'
OUT_SOURCE_FILE_TEMPLATE = u"""// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name}. // Generated by {script_name} using data from {input_file_name}.
// //
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved. // Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
...@@ -58,7 +60,33 @@ void Overlay::initOverlayWidgets() ...@@ -58,7 +60,33 @@ void Overlay::initOverlayWidgets()
""" """
template_init_widget = u"""{{ OUT_HEADER_FILE_TEMPLATE = u"""// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name}.
//
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// {out_file_name}:
// Autogenerated overlay widget declarations.
namespace gl
{{
enum class WidgetId
{{
{widget_ids}
InvalidEnum,
EnumCount = InvalidEnum,
}};
// We can use this "X" macro to generate multiple code patterns.
#define ANGLE_WIDGET_ID_X(PROC) \
{widget_x_defs}
}} // namespace gl
"""
WIDGET_INIT_TEMPLATE = u"""{{
const int32_t fontSize = GetFontSize({font_size}, kLargeFont); const int32_t fontSize = GetFontSize({font_size}, kLargeFont);
const int32_t offsetX = {offset_x}; const int32_t offsetX = {offset_x};
const int32_t offsetY = {offset_y}; const int32_t offsetY = {offset_y};
...@@ -78,6 +106,10 @@ widget->{subwidget}color[3] = {color_a}; ...@@ -78,6 +106,10 @@ widget->{subwidget}color[3] = {color_a};
}} }}
""" """
WIDGET_ID_TEMPLATE = """ // {comment}
{name},
"""
def extract_type_and_constructor(properties): def extract_type_and_constructor(properties):
constructor = properties['type'] constructor = properties['type']
...@@ -248,7 +280,7 @@ def generate_widget_init_helper(widget, is_graph_description=False): ...@@ -248,7 +280,7 @@ def generate_widget_init_helper(widget, is_graph_description=False):
coord0, coord2 = get_bounding_box_coords('offsetX', 'width', offset_x_is_left, is_left_aligned) coord0, coord2 = get_bounding_box_coords('offsetX', 'width', offset_x_is_left, is_left_aligned)
coord1, coord3 = get_bounding_box_coords('offsetY', 'height', offset_y_is_top, is_top_aligned) coord1, coord3 = get_bounding_box_coords('offsetY', 'height', offset_y_is_top, is_top_aligned)
return template_init_widget.format( return WIDGET_INIT_TEMPLATE.format(
subwidget='description.' if is_graph_description else '', subwidget='description.' if is_graph_description else '',
offset_x=offset_x, offset_x=offset_x,
offset_y=offset_y, offset_y=offset_y,
...@@ -282,19 +314,25 @@ def generate_widget_init(widget): ...@@ -282,19 +314,25 @@ def generate_widget_init(widget):
def main(): def main():
if len(sys.argv) == 2 and sys.argv[1] == 'inputs': if len(sys.argv) == 2 and sys.argv[1] == 'inputs':
print(in_file) print(IN_JSON_FILE_NAME)
return return
if len(sys.argv) == 2 and sys.argv[1] == 'outputs': if len(sys.argv) == 2 and sys.argv[1] == 'outputs':
print(out_file) outputs = [
OUT_SOURCE_FILE_NAME,
OUT_HEADER_FILE_NAME,
]
print(','.join(outputs))
return return
with open(in_file) as fin: with open(IN_JSON_FILE_NAME) as fin:
layout = json.loads(fin.read()) layout = json.loads(fin.read())
widgets = layout['widgets']
# Read the layouts from the json file and determine alignment of widgets (as they can refer to # Read the layouts from the json file and determine alignment of widgets (as they can refer to
# other widgets. # other widgets.
overlay_widgets = {} overlay_widgets = {}
for widget_properties in layout['widgets']: for widget_properties in widgets:
widget = OverlayWidget(widget_properties) widget = OverlayWidget(widget_properties)
overlay_widgets[widget.name] = widget overlay_widgets[widget.name] = widget
set_alignment_flags(widget, overlay_widgets) set_alignment_flags(widget, overlay_widgets)
...@@ -302,19 +340,33 @@ def main(): ...@@ -302,19 +340,33 @@ def main():
# Go over the widgets again and generate initialization code. Note that we need to iterate over # Go over the widgets again and generate initialization code. Note that we need to iterate over
# the widgets in order, so we can't use the overlay_widgets dictionary for iteration. # the widgets in order, so we can't use the overlay_widgets dictionary for iteration.
init_widgets = [] init_widgets = []
for widget_properties in layout['widgets']: for widget_properties in widgets:
init_widgets.append(generate_widget_init(overlay_widgets[widget_properties['name']])) init_widgets.append(generate_widget_init(overlay_widgets[widget_properties['name']]))
with open(out_file, 'w') as outfile: with open(OUT_SOURCE_FILE_NAME, 'w') as outfile:
outfile.write( outfile.write(
template_out_file.format( OUT_SOURCE_FILE_TEMPLATE.format(
script_name=__file__, script_name=__file__,
copyright_year=date.today().year, copyright_year=date.today().year,
input_file_name=in_file, input_file_name=IN_JSON_FILE_NAME,
out_file_name=out_file, out_file_name=OUT_SOURCE_FILE_NAME,
init_widgets='\n'.join(init_widgets))) init_widgets='\n'.join(init_widgets)))
outfile.close() outfile.close()
with open(OUT_HEADER_FILE_NAME, 'w') as outfile:
widget_ids = [WIDGET_ID_TEMPLATE.format(**widget) for widget in widgets]
widget_x_defs = ["PROC(" + widget['name'] + ")" for widget in widgets]
outfile.write(
OUT_HEADER_FILE_TEMPLATE.format(
script_name=__file__,
copyright_year=date.today().year,
input_file_name=IN_JSON_FILE_NAME,
out_file_name=OUT_SOURCE_FILE_NAME,
widget_ids=''.join(widget_ids),
widget_x_defs=' \\\n'.join(widget_x_defs)))
outfile.close()
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
"widgets": [ "widgets": [
{ {
"name": "FPS", "name": "FPS",
"comment": "Frames per second (Count/Second).",
"type": "PerSecond", "type": "PerSecond",
"color": [127, 191, 255, 255], "color": [127, 191, 255, 255],
"coords": [10, 10], "coords": [10, 10],
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
}, },
{ {
"name": "VulkanLastValidationMessage", "name": "VulkanLastValidationMessage",
"comment": "Last validation error (Text).",
"type": "Text", "type": "Text",
"color": [255, 0, 0, 255], "color": [255, 0, 0, 255],
"coords": [10, -10], "coords": [10, -10],
...@@ -46,6 +48,7 @@ ...@@ -46,6 +48,7 @@
}, },
{ {
"name": "VulkanValidationMessageCount", "name": "VulkanValidationMessageCount",
"comment": "Number of validation errors and warnings (Count).",
"type": "Count", "type": "Count",
"color": [255, 0, 0, 255], "color": [255, 0, 0, 255],
"coords": [10, "VulkanLastValidationMessage.top.adjacent"], "coords": [10, "VulkanLastValidationMessage.top.adjacent"],
...@@ -54,6 +57,7 @@ ...@@ -54,6 +57,7 @@
}, },
{ {
"name": "VulkanRenderPassCount", "name": "VulkanRenderPassCount",
"comment": "Number of RenderPasses in a frame (Count).",
"type": "RunningGraph(60)", "type": "RunningGraph(60)",
"color": [75, 200, 0, 200], "color": [75, 200, 0, 200],
"coords": [10, 100], "coords": [10, 100],
...@@ -68,6 +72,7 @@ ...@@ -68,6 +72,7 @@
}, },
{ {
"name": "VulkanSecondaryCommandBufferPoolWaste", "name": "VulkanSecondaryCommandBufferPoolWaste",
"comment": "Secondary Command Buffer pool memory waste (Bytes).",
"type": "RunningHistogram(50)", "type": "RunningHistogram(50)",
"color": [255, 200, 75, 200], "color": [255, 200, 75, 200],
"coords": [-50, 100], "coords": [-50, 100],
...@@ -83,6 +88,7 @@ ...@@ -83,6 +88,7 @@
}, },
{ {
"name": "VulkanWriteDescriptorSetCount", "name": "VulkanWriteDescriptorSetCount",
"comment": "Number of Descriptor Set writes in a frame (Count).",
"type": "RunningGraph(60)", "type": "RunningGraph(60)",
"color": [75, 200, 0, 200], "color": [75, 200, 0, 200],
"coords": [10, 220], "coords": [10, 220],
......
...@@ -243,6 +243,7 @@ libangle_headers = [ ...@@ -243,6 +243,7 @@ libangle_headers = [
"src/libANGLE/OverlayWidgets.cpp", "src/libANGLE/OverlayWidgets.cpp",
"src/libANGLE/OverlayWidgets.h", "src/libANGLE/OverlayWidgets.h",
"src/libANGLE/Overlay_autogen.cpp", "src/libANGLE/Overlay_autogen.cpp",
"src/libANGLE/Overlay_autogen.h",
"src/libANGLE/Overlay_font_autogen.cpp", "src/libANGLE/Overlay_font_autogen.cpp",
"src/libANGLE/Overlay_font_autogen.h", "src/libANGLE/Overlay_font_autogen.h",
"src/libANGLE/Program.h", "src/libANGLE/Program.h",
......
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