RFR: 8271024: Implement macOS Metal Rendering Pipeline

Kevin Rushforth kcr at openjdk.org
Thu Jun 12 23:29:31 UTC 2025


On Thu, 12 Jun 2025 05:41:23 GMT, Ambarish Rapte <arapte at openjdk.org> wrote:

> ### Description
> This is the implementation of new graphics rendering pipeline for JavaFX using Metal APIs on MacOS.
> We released two Early Access (EA) builds and have reached a stage where it is ready to be integrated.
> Default rendering pipeline on macOS has not been changed by this PR. OpenGL still stays as the default rendering pipeline and Metal rendering pipeline is optional to choose (by providing  `-Dprism.order=mtl`)
> The `-Dprism.verbose=true` option can be used to verify the rendering pipeline in use.
> 
> ### Details about the changes
> 
> **Shader changes**
> - MSLBackend class: This is the primary class that parses (Prism and Decora) jsl shaders into Metal shaders(msl)
> - There are a few additional Metal shader files added under directory : modules/javafx.graphics/src/main/native-prism-mtl/msl
> 
> **Build changes** - There are new tasks added to build.gradle for
> - Generation/ Compilation/ linking of Metal shaders
> - Compilation of Prism Java and Objective C files
> 
> **Prism** - Prism is the rendering engine of JavaFX.
> - Added Metal specific Java classes and respective native implementation which use Metal APIs
> - Java side changes:
>   - New Metal specific classes: Classes prefixed with MTL, are added here : modules/javafx.graphics/src/main/java/com/sun/prism/mtl 
>   - Modification to Prism common classes: A few limited changes were required in Prism common classes to support Metal classes. 
> - Native side changes:
>   - New Metal specific Objective C implementation is added here: modules/javafx.graphics/src/main/native-prism-mtl
> 
> **Glass** - Glass is the windowing toolkit of JavaFX
> - Existing Glass classes are refactored to support both OpenGL and Metal pipelines
> - Added Metal specific Glass implementation.
> 
> ### Testing
> - Testing performed on different hardware and macOS versions.
>   - HW - macBooks with Intel, Intel with discrete graphics card, Apple Silicon (M1, M2 and M4)
>   - macOS versions - macOS 13, macOS 14 and macOS 15
> - Functional Testing:
>   - All headful tests pass with Metal pipeline.
>   - Verified samples applications: Ensemble and toys
> - Performance Testing:
>   - Tested with RenderPerfTest: Almost all tests match/exceed es2 performance except a few that fall a little short on different hardwares. These will be addressed separately (there are open bugs already filed)
> 
> ### Note to reviewers :
> - Providing `-Dprism.order=mtl` option is a must for testing the Metal pipeline
> - It would be a good idea to test both OpenGL and Metal pipelines
> - Known issues and tasks ...

As this is a large PR I don't expect any one reviewer to review the whole thing, but I do want to make sure that each piece is reviewed by someone. So we'd like as many eyes on this as possible.

The parts we are most concerned with getting reviewed are changes in existing classes that could impact other pipelines, particularly the default ES2 pipeline on macOS

For example, there are some minor changes in the Prism base classes, which necessitated changes in the pipeline-specific classes.

The largest change in shared code is the glass refactoring to move the rendering-pipeline-specific code (OpenGL or Metal) into pipeline-specific classes.  For some classes, the existing code is split between the base class and the CGL subclass (with the MTL class being new implementation for Metal).

Here are the main classes to look at:

* GlassCGLFrameBufferObject -- renamed from GlassFrameBufferObject with minor changes
* GlassMTLFrameBufferObject -- sibling class

* GlassOffscreen -- pipeline-specific pieces moved to subclasses
    * GlassCGLOffscreen
    * GlassMTLOffscreen

* GlassLayer3D -- pipeline-specific pieces moved to sub-layers (not using inheritance)
    * GlassLayerCGL3D
    * GlassLayerMTL3D

* GlassView -- minor changes to remove OpenGL-isms and fix a few other interface issues

* GlassView3D -- pipeline-specific pieces moved to subclasses
    * GlassViewCGL3D
    * GlassViewMTL3D

@jayathirthrao can give more details on the above glass refacatoring changes if you are interested

@beldenfox If you are willing to look at it, we would be quite appreciative of your comments or suggestions on the glass refactoring.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1824#issuecomment-2968429780


More information about the openjfx-dev mailing list