Work done so far :
A working prototype of basic feature-set with Java 2D Metal rendering pipeline has been implemented for -
- 2D Primitives rendering
- implemented AA rendering for some primitives and painting types
- optimised geometry handling (no unnecessary MTLBuffer creation)
- improved stability: fixed some severe memory management problems in primitive handling
- Multisampling (hardware accelerated) AA
- investigated multisampling AA rendering
- implemented AA parallelogram rendering via multisampling AA
- Image rendering.
- improved stability: fixed several memory management problems
- native blit operations (Blit, IsoBlit) for almost all blit primitives (of MTLBlitLoops)
- all 32bpp raster formats with ‘opaque’ flags
- all alpha-composite modes (still unsupported extra-alpha)
- clipping, transform
- textures pool (to avoid reallocations for temporary textures) with restricted size (cleaned with LRU-strategy)
- fast search in pool
- no unnecessary sync
- blit without sampling if possible
supported all parameters of blit operations
- General metal pipeline workflow
fixed resources leaks, added minor optimizations (in PipelineStateStorage and TexPool)
refactored MTLContext (splited into several classes)
fixed issues connected with changes of pipelineState
added minor optimizations (don’t change state when possible)
- Grayscale Text Rendering - Feature completion of Grayscale text rendering without cache under JDK-8225174
- Initial implementation of Grayscale text rendering with cache under JDK-8237608
Closure of main performance bottleneck task JDK-8228573 after implementing proper back/front buffer drawing under JDK-8233190
JDK-8233233 - Implement Shape Clip (for aliased rendering)
It is available in the lanai repo https://hg.openjdk.java.net/lanai/lanai/
It can be tested with J2DDemo (available at - src/demo/share/jfc/J2Ddemo) that shows working / partially working / not-working Java 2D features with Metal rendering as compared with OpenGL rendering.
VM option -Dsun.java2d.metal=True needs to be passed in to switch rendering pipeline to Metal.
Also, antialiasing needs to be turned off (which is on by default in J2DDemo)
Work in Progress :
Current focus area is - Rendering performance evaluation :
As basic blocks of rendering have been implemented, it is a good time to check on rendering performance to evaluate how Metal rendering in Java 2D fares as compared to OpenGL rendering in Java 2D. As a first step, we are using below test benchmarkings -
- RenderPerfTest (available at - src/demo/share/java2d/RenderPerfTest)
- implemented AA benchmarks
- J2DBench Tests (available at - src/demo/share/java2d/J2DBench) for drawing 2D primitives - line, rectangle, filled rectangle, ellipse, filled ellipse.
The performance numbers for Java 2D Metal rendering pipeline are not up to the mark as compared to the Java 2D OpenGL rendering pipeline. Multiple design level optimizations are being done to address this.
- Reducing number of MTLRenderEncoders that get created per render pass
- Reducing the number of drawPrimitives calls by batching data whenever possible
- Using setNeedsDisplay flag of MTLLayer and updating the layer content on AppKit thread in a callback
- Use multisampling AA for AA primitive rendering
Current numbers from RenderPerfTest (OGL vs Metal):
Bench | OGL | Metal |
---|---|---|
FlatOval(AA) | 40(16) | 41(5) |
FlatBox(AA) | 91(92) | 93(94) |
Image(AA) | 96(93) | 80(80) |
RotatedBox(AA) | 91(84) | 68(96) |
RotatedOval(AA) | 44(16) | 34(4) |
LinGradRotatedOval | 28 | 33 |
WiredBubbles(AA) | 25(11) | 23(3) |
WiredBox | 87 | 77 |
Lines | 88 | 73 |
FlatQuad(AA) | 53(9) | 52(1) |
WiredQuad(AA) | 42(11) | 43(3) |
TextNoAA | 84 | 29 |
TextLCD | 58 | 25 |
TextGray | 76 | 28 |