servo / pathfinder

A fast, practical GPU rasterizer for fonts and vector graphics
Apache License 2.0
3.6k stars 203 forks source link

Artifacts when rendering custom SVGs #67

Closed trishume closed 5 years ago

trishume commented 6 years ago

I was taking a look at some of the SVGs from http://w3.impa.br/~diego/projects/GanEtAl14/ in the current PathFinder and noticed many of them have artifacts. The Boston map has hairlines and the contours one has hairline cracks and is missing a bunch of triangles.

screen shot 2018-02-07 at 6 36 17 pm

I also noticed the performance appears to be substantially worse than the numbers you gave way back when you had your Metal-based prototype. The Boston map and paper1 take around 35ms to render. Both of these are substantially smaller than the Paris map I had you render before (which I couldn't get to load now) which you said back then rendered in 3-4ms. Do you know why this might be?

pcwalton commented 6 years ago

A lot of the performance problems come down to vertex shading load. One of the problems with the VS load is that cubic-to-quadratic Bézier approximation was needlessly precise. I pushed a fix for that.

pcwalton commented 6 years ago

I should be able to reduce the vertex shading load by quite a bit, by consolidating duplicate vertices.

pcwalton commented 6 years ago

Yeah, so in theory we perform 8x the vertex shading load that is required (not counting additional vertices created from cubic-to-quadratic Bézier conversion). Each of these steps at most doubles the number of vertices to be shaded over those present in the input:

  1. The partitioning (trapezoidation) process.
  2. Instanced rendering.
  3. The depth prepass.

(1) is difficult to remove; it would require some sort of curve-aware triangulation algorithm that does not add Steiner vertices. (2) should be fixable by generating more traditional meshes instead of using instanced rendering on B-quads. (3) is fixable by either skipping the depth prepass (probably undesirable) or by transform feedback (OpenGL/OpenGL ES 3.0+, WebGL 2). Opt-in transform feedback seems doable, so I would say that we can probably cut the number of vertices to be transformed by a factor of 4.

pcwalton commented 6 years ago

Another possibility is to do a path simplification prepass if we know the resolution we're likely to be rendering at. This could be a dramatic win.

pcwalton commented 5 years ago

Not applicable to Pathfinder 3.