Skip to content

Commit

Permalink
UI 10x speedup with hardware antialias (commaai#1787)
Browse files Browse the repository at this point in the history
* enable MSAA, disable nvg antialias

* less opaque and clean up

Co-authored-by: Comma Device <[email protected]>
  • Loading branch information
geohot and Comma Device committed Jun 29, 2020
1 parent df86c47 commit b62da57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions selfdrive/common/framebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
20 changes: 13 additions & 7 deletions selfdrive/ui/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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]))
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b62da57

Please sign in to comment.