jzy3d-api icon indicating copy to clipboard operation
jzy3d-api copied to clipboard

[EmulGL] Software rendering performance can be significantly improved by optimising blend_pixel

Open valb3r opened this issue 2 years ago • 4 comments

switch - case inside blend_pixel causes almost 2x performance degradation due to mixing of branching and numeric pipeline

Pipeline flame graph: Screenshot 2022-04-30 at 17 11 46

As BlendFunc rarely changes during polygon rendering, one can try to use lambdas to optimise pixel blending performance

valb3r avatar Apr 30 '22 14:04 valb3r

Good catch! Is this x2 factor an estimate or did you already try?

One thing you may be interested in is BenchmarkRun and BenchmarkPlot in module jzy3d-tests-java9. It evaluates rendering time based on content to render. I used it to show how sensitive EmulGL and jGL are to the number of polygons to render, assuming these polygons (either a single, 10 or 100) always cover the same number of pixels.

Capture d’écran 2022-04-30 à 18 38 36

jzy3d avatar Apr 30 '22 16:04 jzy3d

Is this x2 factor an estimate or did you already try?

I've tested that on M1 Air with Apple Silicon, went from 120ms to 60ms per frame when I removed switch-case and kept only actual branch Will try BenchmarkRun for better consistency

valb3r avatar Apr 30 '22 17:04 valb3r

You will see that this test only involves black pixel on a flat surface. The idea was mainly to have a guess on sensitivity to number of pixels to paint vs. polygon you’re draw. It should not be hard to derive it and evaluate blending cost on a colored surface.

One point worth mentioning : EmulGL has an unsatisfying way of handling blending. The less alpha you configure, the darker polygon you have. I’ll send you links about it.

jzy3d avatar Apr 30 '22 19:04 jzy3d

Quality.Advanced() with alpha has faded colors.

image

Quality.Intermediate with no alpha has vivid colors

image

I am willing to understand where this fading effect comes from. Using alpha = 0 creates black pixels instead of background color pixels.

jzy3d avatar Apr 30 '22 19:04 jzy3d