Skip to content

Commit bc7a1ea

Browse files
committedJul 18, 2022
8288948: Few J2DBench tests indicate lower primitive drawing performance with metal rendering pipeline
Reviewed-by: avu, prr
1 parent 84f2314 commit bc7a1ea

File tree

4 files changed

+229
-108
lines changed

4 files changed

+229
-108
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,6 +51,11 @@ enum {
5151
MTL_OP_SYNC,
5252
MTL_OP_SHAPE_CLIP_SPANS,
5353
MTL_OP_MASK_OP,
54+
MTL_OP_FILL_PARALLELOGRAM,
55+
MTL_OP_FILL_RECT,
56+
MTL_OP_DRAW_LINE,
57+
MTL_OP_DRAW_RECT,
58+
MTL_OP_DRAW_PARALLELOGRAM,
5459
MTL_OP_OTHER
5560
};
5661
/*

‎src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,13 +48,31 @@
4848

4949
extern void MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo);
5050

51+
bool isDrawOp (jint op) {
52+
switch(op) {
53+
case MTL_OP_DRAW_LINE:
54+
case MTL_OP_DRAW_RECT:
55+
case MTL_OP_DRAW_PARALLELOGRAM:
56+
case MTL_OP_FILL_RECT:
57+
case MTL_OP_FILL_PARALLELOGRAM:
58+
return true;
59+
default: return false;
60+
}
61+
}
62+
5163
void MTLRenderQueue_CheckPreviousOp(jint op) {
5264

5365
if (mtlPreviousOp == op) {
5466
// The op is the same as last time, so we can return immediately.
5567
return;
5668
}
5769

70+
if (isDrawOp(mtlPreviousOp) && !isDrawOp(op)) {
71+
// submit the vertex batch
72+
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
73+
mtlPreviousOp = op;
74+
}
75+
5876
if (op == MTL_OP_SET_COLOR) {
5977
if (mtlPreviousOp != MTL_OP_MASK_OP) {
6078
return; // SET_COLOR should not cause endEncoder
@@ -128,7 +146,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
128146
// draw ops
129147
case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
130148
{
131-
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
149+
CHECK_PREVIOUS_OP(MTL_OP_DRAW_LINE);
132150

133151
if ([mtlc useXORComposite]) {
134152
commitEncodedCommands();
@@ -144,9 +162,10 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
144162
}
145163
case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:
146164
{
147-
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
165+
CHECK_PREVIOUS_OP(MTL_OP_DRAW_RECT);
148166

149167
if ([mtlc useXORComposite]) {
168+
150169
commitEncodedCommands();
151170
J2dTraceLn(J2D_TRACE_VERBOSE,
152171
"DRAW_RECT in XOR mode - Force commit earlier draw calls before DRAW_RECT.");
@@ -228,7 +247,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
228247
}
229248
case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
230249
{
231-
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
250+
CHECK_PREVIOUS_OP(MTL_OP_DRAW_PARALLELOGRAM);
232251

233252
if ([mtlc useXORComposite]) {
234253
commitEncodedCommands();
@@ -276,7 +295,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
276295
// fill ops
277296
case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:
278297
{
279-
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
298+
CHECK_PREVIOUS_OP(MTL_OP_FILL_RECT);
280299

281300
if ([mtlc useXORComposite]) {
282301
commitEncodedCommands();
@@ -308,7 +327,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
308327
}
309328
case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
310329
{
311-
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
330+
CHECK_PREVIOUS_OP(MTL_OP_FILL_PARALLELOGRAM);
312331

313332
if ([mtlc useXORComposite]) {
314333
commitEncodedCommands();
@@ -582,6 +601,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
582601
jlong pDst = NEXT_LONG(b);
583602

584603
if (mtlc != NULL) {
604+
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
585605
[mtlc.encoderManager endEncoder];
586606
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
587607
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
@@ -609,6 +629,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
609629

610630
} else {
611631
if (mtlc != NULL) {
632+
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
612633
[mtlc.encoderManager endEncoder];
613634
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
614635
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
@@ -878,6 +899,8 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
878899
if (mtlPreviousOp == MTL_OP_MASK_OP) {
879900
MTLVertexCache_DisableMaskCache(mtlc);
880901
}
902+
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
903+
881904
[mtlc.encoderManager endEncoder];
882905
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
883906
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
@@ -923,6 +946,9 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
923946
* these would be rendered to the back-buffer - which is read in shader while rendering in XOR mode
924947
*/
925948
void commitEncodedCommands() {
949+
950+
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
951+
926952
[mtlc.encoderManager endEncoder];
927953

928954
MTLCommandBufferWrapper *cbwrapper = [mtlc pullCommandBufferWrapper];

‎src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -72,5 +72,9 @@ void MTLRenderer_FillAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
7272
jfloat fx11, jfloat fy11,
7373
jfloat dx21, jfloat dy21,
7474
jfloat dx12, jfloat dy12);
75+
void MTLRenderer_AddVertexToBatch(float x, float y);
76+
void MTLRenderer_SubmitVertexBatch(MTLContext* mtlc, BMTLSDOps* dstOps);
77+
void MTLRenderer_SetPrimitiveType(MTLPrimitiveType type);
78+
7579

7680
#endif /* MTLRenderer_h_Included */

0 commit comments

Comments
 (0)
Please sign in to comment.