llvmpipe: Rendering artifacts in KiCad when using alpha test, stencil test and multisampling.
System information
- OS: Linux Mint 20.3 or Ubuntu 20.04.4 LTS (WSL2)
- GPU: Intel Corporation UHD Graphics 630 (Desktop) or NVIDIA GeForce GTX 950M (with
LIBGL_ALWAYS_SOFTWARE=1
) - Kernel version: 5.4.0-117-generic or 4.19.128-microsoft-standard
- Mesa version: 4.5 (Compatibility Profile) Mesa 22.1.1 - kisak-mesa PPA
- Desktop manager and compositor: lightdm/Xfwm or None
- KiCad version: 6.99 nightly or 6.0.5 stable
Describe the issue
In KiCad's 3D viewer in Realtime rendering mode, artifacts are seen near circular and rounded pads and line segments:
Screenshot with artifacts (GL_STENCIL_TEST enabled)
Screenshot without artifacts (GL_STENCIL_TEST disabled)
apitrace/glretrace surface export
Surface export with artifacts (--samples 4
passed to glretrace):
Surface export without artifacts (--samples 4
not passed to glretrace - multisampling disabled in context)
Apitrace
Run glretrace
with --samples 4
to see artifacts.
Regression
Used to render without artifacts in Mesa 20.0.8 (multisampling context wasn't available)
KiCad code overview
Rendering of circular or rounded pads and line segments can be summarized in this way:
-
glXChooseFBConfig
attributes configuration -
Display list(s) with triangles with the circle texture and GL_ALPHA_TEST enabled are created for segment ends, circular pads and rounded corners of pads. (
m_layer_top/bot_segment_ends
) -
GL_MULTISAMPLE is enabled.
-
"Non-rounded" part geometry is rendered (
m_layer_top/bot_triangles
) - doesn't affect the artifacts. -
Depending on 3D viewer's settings (render with or without holes), the display lists mentioned in 2. are rendered either with or without enabling GL_STENCIL_TEST:
-
GL_STENCIL_TEST is enabled, where it's used to subtract inner hole from the outer circle of pads: DrawAllCameraCulledSubtractLayer.
That method can be reduced to this and the artifacts would still appear:
glEnable( GL_STENCIL_TEST ); glStencilFunc( GL_ALWAYS, 1, 0 ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); DrawTop(); glDisable( GL_STENCIL_TEST );
-
GL_STENCIL_TEST is disabled, since there's no need to subtract holes. Artifacts do not appear: DrawAllCameraCulled.
-
KiCad bug report: https://gitlab.com/kicad/code/kicad/-/issues/11789