-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8288948: Few J2DBench tests indicate lower primitive drawing performance with metal rendering pipeline #9245
8288948: Few J2DBench tests indicate lower primitive drawing performance with metal rendering pipeline #9245
Conversation
👋 Welcome back aghaisas! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overal looks good
src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
need a review from @prrace |
MTLRenderer_AddVertexToBatch(fx, fy); | ||
MTLRenderer_AddVertexToBatch(fx+fw, fy); | ||
|
||
MTLRenderer_AddVertexToBatch(fx+fw, fy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there several duplicates here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier logic used to draw a rectangle with MTLPrimitiveTypeLineStrip. Hence, 5 vertices were specified to draw 4 sides of the rectangle.
Now, the logic has been changed to use MTLPrimitiveTypeLine. Hence, 4 lines need to be specified separately by specifying 8 vertices. There are duplicates since the lines are connected.
We cannot use MTLPrimitiveTypeLineStrip if we want to batch the subsequent draw calls as it draws an unwanted line between previous rectangle and current rectangle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use MTLPrimitiveTypeLineStrip if we want to batch the subsequent draw calls as it draws an unwanted line between previous rectangle and current rectangle.
Even if the alpha will be transparent? Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there will be a transparent line between previous rectangle and current rectangle.
This PR introduces batching of vertices of successive draw calls of the same primitive. If we keep on adding vertices to a common buffer and finally encode draw operation using MTLPrimitiveTypeLineStrip, all those vertices will be connected. If color is changed in between these successive draw calls, we end the current vertex batch and start a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what about the usage of MTLPrimitiveTypeLineStrip and the transparent color to hide the "unwanted line between previous rectangle and current rectangle"? OR it is not possible to draw the lines using different colors in one step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OR it is not possible to draw the lines using different colors in one step?
Exactly this is the point. If the color is changed (alpha change is also treated as color change) in between these successive draw calls, we end the current vertex batch and issue a draw command for accumulated vertices.
This is the reason MTLPrimitiveTypeLineStrip and MTLPrimitiveTriangleStrip cannot be used with our current vertex batching logic.
@aghaisas This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 314 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit bc7a1ea.
Your commit was automatically rebased without conflicts. |
J2DBench test option files attached to JDK-8288948 indicate lower drawing performance on macOS with Metal rendering pipeline as compared to OpenGL rendering pipeline.
Analysis :
Current implementation of 2D primitives (Line, Rectangle, Parallelogram - Draw/Fill operations) in Metal rendering pipeline follow below structure-
setVertexBytes()
calldrawPrimitives()
callsetFragmentBytes()
call in MTLRenderCommandEncoder state update.Root Cause of slower performance :
It is found that the multiple calls to MTLRenderCommandEncoder
drawPrimitives()
by using MTLRenderCommandEncodersetVertexBytes()
to send a tiny amount of data each time slows down the rendering.Fix :
MTLRenderCommandEncoder
setVertexBytes()
can accept 4KB of buffer at a time.The primitive drawing logic is modified to collate adjacent draw calls as below -
a) Vertex data buffer is sent to the GPU using MTLRenderCommandEncoder
setVertexBytes()
call.b) A single (or multiple) draw command(s) are issued using MTLRenderCommandEncoder
drawPrimitives()
call.More insight :
In general, an application requires a mix of 2D shapes, images and text of different color and sizes.
The performance test that we have measure rendering performance of extreme cases such as -
This PR optimizes the Java2D Metal rendering pipeline implementation for the first case where the same primitive is drawn repeatedly without changing its color. Our current architecture needs to be tweaked to address slower performance shown by RenderPerf tests. If needed, that needs to be done separately.
Results :
The performance results are attached to the JBS.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9245/head:pull/9245
$ git checkout pull/9245
Update a local copy of the PR:
$ git checkout pull/9245
$ git pull https://git.openjdk.org/jdk pull/9245/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9245
View PR using the GUI difftool:
$ git pr show -t 9245
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9245.diff