pathfinder icon indicating copy to clipboard operation
pathfinder copied to clipboard

Artifact when rendering large numbers of overlapping paths

Open alec-deason opened this issue 4 years ago • 9 comments

I'm seeing artifacts when rendering scenes with large numbers of paths that overlap. It looks like it's related to the renderer's tiles somehow but it isn't strictly a paths per tile issue (see the third image). Here's the roof from the canvas_minimal example drawn on top of itself thousands of times:

screenshot

Obviously that's a pathological case but the artifacts start to show up with a much smaller number of overlaps (30 in this case):

screenshot

I'm seeing it in real use as well where complex objects are drawn on top of other paths:

screenshot

The bottom half of the screen in that example should be solid black but instead has lines of sky color showing through. That also shows the artifact in tiles which don't actually contain a large number of paths, like the ground on the right edge where there should just be two paths overlapping, one for the sky and one for the ground.

The code I used to produce the top two images: https://gist.github.com/alec-deason/2518dfce805c8222ab96c7c336336555

The only issue I could find that looks similar is the lines shown here: https://github.com/servo/pathfinder/issues/284#issuecomment-597564528_

I'm seeing this in both the GL and WebGL renderers on an Intel GPU on Linux and latest commit to pathfinder.

alec-deason avatar Jul 18 '20 19:07 alec-deason

Sorry, I mispoke in the description. The sky in the last picture is not a path, it's just the clear color. So what's showing through the ground is the clear color not another path. That seems like it might be an important distinction.

alec-deason avatar Jul 20 '20 17:07 alec-deason

Yeah, the problem is that when overflow the mask texture the resizing is currently buggy for one frame (that's the first and third images).

pcwalton avatar Jul 21 '20 17:07 pcwalton

Oh, lovely. If I render a second time the worst of the artifacts do indeed go away. I still see the faint vertical lines in the second example but that isn't actually a problem in my use case.

Is there a way to preallocate if I know what I'm going to need? Skimming through the code, I don't see anything obvious.

alec-deason avatar Jul 21 '20 17:07 alec-deason

It's impossible to predict how big the textures are. We just need to fix the bug.

pcwalton avatar Jul 22 '20 22:07 pcwalton

Ok, makes sense. Thanks.

alec-deason avatar Jul 22 '20 22:07 alec-deason

This is the D3D11 mode, right?

pcwalton avatar Jul 23 '20 03:07 pcwalton

I was requesting a GL3.0 context from surfman, which I think puts me in D3D10. I just tried it again requesting a GL4.0 context and see the same artifacts.

alec-deason avatar Jul 23 '20 03:07 alec-deason

https://github.com/servo/pathfinder/pull/418 fixes the biggest problems here. 1-character fix :)

The remaining issue with the 1-pixel-wide vertical lines seems to be caused by accumulation of floating-point error. I had worried that it indicated a fundamental problem with the lookup table approach for area, but I don't think it does, because if it did it wouldn't be a vertical line and would manifest itself only with lines of a certain slope, rather than all lines. So it's probably some subtle bug, not something fundamental.

pcwalton avatar Jul 28 '20 00:07 pcwalton

That's the best kind of fix. And it resolves the main issue for me. Thanks!

alec-deason avatar Jul 28 '20 00:07 alec-deason