Skip to content

Commit

Permalink
8288948: Few J2DBench tests indicate lower primitive drawing performa…
Browse files Browse the repository at this point in the history
…nce with metal rendering pipeline

Reviewed-by: avu, prr
  • Loading branch information
aghaisas committed Jul 18, 2022
1 parent 84f2314 commit bc7a1ea
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 108 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -51,6 +51,11 @@ enum {
MTL_OP_SYNC,
MTL_OP_SHAPE_CLIP_SPANS,
MTL_OP_MASK_OP,
MTL_OP_FILL_PARALLELOGRAM,
MTL_OP_FILL_RECT,
MTL_OP_DRAW_LINE,
MTL_OP_DRAW_RECT,
MTL_OP_DRAW_PARALLELOGRAM,
MTL_OP_OTHER
};
/*
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -48,13 +48,31 @@

extern void MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo);

bool isDrawOp (jint op) {
switch(op) {
case MTL_OP_DRAW_LINE:
case MTL_OP_DRAW_RECT:
case MTL_OP_DRAW_PARALLELOGRAM:
case MTL_OP_FILL_RECT:
case MTL_OP_FILL_PARALLELOGRAM:
return true;
default: return false;
}
}

void MTLRenderQueue_CheckPreviousOp(jint op) {

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

if (isDrawOp(mtlPreviousOp) && !isDrawOp(op)) {
// submit the vertex batch
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
mtlPreviousOp = op;
}

if (op == MTL_OP_SET_COLOR) {
if (mtlPreviousOp != MTL_OP_MASK_OP) {
return; // SET_COLOR should not cause endEncoder
Expand Down Expand Up @@ -128,7 +146,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
// draw ops
case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
{
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
CHECK_PREVIOUS_OP(MTL_OP_DRAW_LINE);

if ([mtlc useXORComposite]) {
commitEncodedCommands();
Expand All @@ -144,9 +162,10 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
}
case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:
{
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
CHECK_PREVIOUS_OP(MTL_OP_DRAW_RECT);

if ([mtlc useXORComposite]) {

commitEncodedCommands();
J2dTraceLn(J2D_TRACE_VERBOSE,
"DRAW_RECT in XOR mode - Force commit earlier draw calls before DRAW_RECT.");
Expand Down Expand Up @@ -228,7 +247,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
}
case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
{
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
CHECK_PREVIOUS_OP(MTL_OP_DRAW_PARALLELOGRAM);

if ([mtlc useXORComposite]) {
commitEncodedCommands();
Expand Down Expand Up @@ -276,7 +295,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
// fill ops
case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:
{
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
CHECK_PREVIOUS_OP(MTL_OP_FILL_RECT);

if ([mtlc useXORComposite]) {
commitEncodedCommands();
Expand Down Expand Up @@ -308,7 +327,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
}
case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
{
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
CHECK_PREVIOUS_OP(MTL_OP_FILL_PARALLELOGRAM);

if ([mtlc useXORComposite]) {
commitEncodedCommands();
Expand Down Expand Up @@ -582,6 +601,7 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
jlong pDst = NEXT_LONG(b);

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

} else {
if (mtlc != NULL) {
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
[mtlc.encoderManager endEncoder];
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
Expand Down Expand Up @@ -878,6 +899,8 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
if (mtlPreviousOp == MTL_OP_MASK_OP) {
MTLVertexCache_DisableMaskCache(mtlc);
}
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);

[mtlc.encoderManager endEncoder];
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
Expand Down Expand Up @@ -923,6 +946,9 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
* these would be rendered to the back-buffer - which is read in shader while rendering in XOR mode
*/
void commitEncodedCommands() {

MTLRenderer_SubmitVertexBatch(mtlc, dstOps);

[mtlc.encoderManager endEncoder];

MTLCommandBufferWrapper *cbwrapper = [mtlc pullCommandBufferWrapper];
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -72,5 +72,9 @@ void MTLRenderer_FillAAParallelogram(MTLContext *mtlc, BMTLSDOps * dstOps,
jfloat fx11, jfloat fy11,
jfloat dx21, jfloat dy21,
jfloat dx12, jfloat dy12);
void MTLRenderer_AddVertexToBatch(float x, float y);
void MTLRenderer_SubmitVertexBatch(MTLContext* mtlc, BMTLSDOps* dstOps);
void MTLRenderer_SetPrimitiveType(MTLPrimitiveType type);


#endif /* MTLRenderer_h_Included */

0 comments on commit bc7a1ea

Please sign in to comment.