From ada835918000e6f3bc6eb31848cf80c1b22e5a9e Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Mon, 29 Jun 2020 13:54:23 -0700 Subject: [PATCH] UI 10x speedup with hardware antialias (#1787) * enable MSAA, disable nvg antialias * less opaque and clean up Co-authored-by: Comma Device old-commit-hash: b62da571b4108487cfc4d2dbd1970a504ba0a317 --- selfdrive/common/framebuffer.cc | 3 +++ selfdrive/ui/paint.cc | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/selfdrive/common/framebuffer.cc b/selfdrive/common/framebuffer.cc index d39fa8cb49..30604deb2e 100644 --- a/selfdrive/common/framebuffer.cc +++ b/selfdrive/common/framebuffer.cc @@ -102,6 +102,9 @@ extern "C" FramebufferState* framebuffer_init( EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, + // enable MSAA + EGL_SAMPLE_BUFFERS, 1, + EGL_SAMPLES, 4, EGL_NONE, }; diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 24f4a9d4af..a58425748f 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -289,7 +289,7 @@ static inline bool valid_frame_pt(UIState *s, float x, float y) { return x >= 0 && x <= s->rgb_width && y >= 0 && y <= s->rgb_height; } -static void update_lane_line_data(UIState *s, const float *points, float off, bool is_ghost, model_path_vertices_data *pvd, float valid_len) { +static void update_lane_line_data(UIState *s, const float *points, float off, model_path_vertices_data *pvd, float valid_len) { pvd->cnt = 0; int rcount = fmin(MODEL_PATH_MAX_VERTICES_CNT / 2, valid_len); for (int i = 0; i < rcount; i++) { @@ -305,7 +305,7 @@ static void update_lane_line_data(UIState *s, const float *points, float off, bo } for (int i = rcount; i > 0; i--) { float px = (float)i; - float py = is_ghost?(points[i]-off):(points[i]+off); + float py = points[i] + off; const vec4 p_car_space = (vec4){{px, py, 0., 1.}}; const vec3 p_full_frame = car_space_to_full_frame(s, p_car_space); if(!valid_frame_pt(s, p_full_frame.v[0], p_full_frame.v[1])) @@ -317,16 +317,16 @@ static void update_lane_line_data(UIState *s, const float *points, float off, bo } static void update_all_lane_lines_data(UIState *s, const PathData &path, model_path_vertices_data *pstart) { - update_lane_line_data(s, path.points, 0.025*path.prob, false, pstart, path.validLen); + update_lane_line_data(s, path.points, 0.025*path.prob, pstart, path.validLen); float var = fmin(path.std, 0.7); - update_lane_line_data(s, path.points, -var, true, pstart + 1, path.validLen); - update_lane_line_data(s, path.points, var, true, pstart + 2, path.validLen); + update_lane_line_data(s, path.points, -var, pstart + 1, path.validLen); + update_lane_line_data(s, path.points, var, pstart + 2, path.validLen); } static void ui_draw_lane(UIState *s, const PathData *path, model_path_vertices_data *pstart, NVGcolor color) { ui_draw_lane_line(s, pstart, color); float var = fmin(path->std, 0.7); - color.a /= 4; + color.a /= 25; ui_draw_lane_line(s, pstart + 1, color); ui_draw_lane_line(s, pstart + 2, color); } @@ -758,7 +758,7 @@ void ui_draw(UIState *s) { nvgBeginFrame(s->vg, s->fb_w, s->fb_h, 1.0f); ui_draw_sidebar(s); if (s->started && s->active_app == cereal::UiLayoutState::App::NONE && s->status != STATUS_STOPPED && s->vision_seen) { - ui_draw_vision(s); + ui_draw_vision(s); } nvgEndFrame(s->vg); glDisable(GL_BLEND); @@ -858,7 +858,13 @@ static const mat4 full_to_wide_frame_transform = {{ void ui_nvg_init(UIState *s) { // init drawing +#ifdef QCOM + // on QCOM, we enable MSAA + s->vg = nvgCreate(0); +#else s->vg = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG); +#endif + assert(s->vg); s->font_courbd = nvgCreateFont(s->vg, "courbd", "../assets/fonts/courbd.ttf");