changeset 56598:39df94054500

8233190: Use multi commandbuffer and draw back buffer in QueueFlusher
author jdv
date Tue, 26 Nov 2019 16:35:19 +0530
parents b4f3e13ea1a0
children c86f8c3d7fcc
files src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m
diffstat 4 files changed, 20 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h	Wed Nov 20 14:41:12 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h	Tue Nov 26 16:35:19 2019 +0530
@@ -241,6 +241,7 @@
 - (void) updateSamplingEncoderProperties:(id<MTLRenderCommandEncoder>) encoder dest:(id<MTLTexture>) dest;
 - (void)dealloc;
 - (void)endCommonRenderEncoder;
+- (id<MTLCommandBuffer>)createBlitCommandBuffer;
 @end
 
 /**
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m	Wed Nov 20 14:41:12 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.m	Tue Nov 26 16:35:19 2019 +0530
@@ -464,6 +464,9 @@
     }
 }
 
+- (id<MTLCommandBuffer>)createBlitCommandBuffer {
+    return [self.commandQueue commandBuffer];
+}
 - (void)dealloc {
     J2dTraceLn(J2D_TRACE_INFO, "MTLContext.dealloc");
 
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m	Wed Nov 20 14:41:12 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLLayer.m	Tue Nov 26 16:35:19 2019 +0530
@@ -80,25 +80,21 @@
         return;
     }
 
-    MTLCommandBufferWrapper * commandBufWrapper = [self.ctx pullCommandBufferWrapper];
-    if (commandBufWrapper == nil) {
-        J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nothing to do (commandBuf is null)");
-        return;
-    }
-
     if (self.nextDrawableCount != 0)
         return;
 
-    @try {
     @autoreleasepool {
         if ((self.buffer.width == 0) || (self.buffer.height == 0)) {
             J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: cannot create drawable of size 0");
             return;
         }
 
-        if (@available(macOS 10.13, *)) {
-            self.displaySyncEnabled = NO;
+        id<MTLCommandBuffer> commandBuf = [self.ctx createBlitCommandBuffer];
+        if (commandBuf == nil) {
+            J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nothing to do (commandBuf is null)");
+            return;
         }
+
         id<CAMetalDrawable> mtlDrawable = [self nextDrawable];
         if (mtlDrawable == nil) {
             J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: nextDrawable is null)");
@@ -106,7 +102,6 @@
         }
         self.nextDrawableCount++;
         J2dTraceLn6(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: src tex=%p (w=%d, h=%d), dst tex=%p (w=%d, h=%d)", self.buffer, self.buffer.width, self.buffer.height, mtlDrawable.texture, mtlDrawable.texture.width, mtlDrawable.texture.height);
-        id<MTLCommandBuffer> commandBuf = [commandBufWrapper getCommandBuffer];
         id <MTLBlitCommandEncoder> blitEncoder = [commandBuf blitCommandEncoder];
         [blitEncoder
                 copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0
@@ -117,19 +112,11 @@
 
         [commandBuf presentDrawable:mtlDrawable];
 
-        [commandBuf addCompletedHandler:^(id <MTLCommandBuffer> cmdBuff) {
-                [commandBufWrapper onComplete];
-                self.nextDrawableCount--;
-                if (@available(macOS 10.13, *)) {
-                    self.displaySyncEnabled = YES;
-                }
+        [commandBuf addCompletedHandler:^(id <MTLCommandBuffer> commandBuf) {
+            self.nextDrawableCount--;
         }];
 
         [commandBuf commit];
-        [commandBuf waitUntilCompleted];
-    }
-    } @finally {
-        [commandBufWrapper release];
     }
 }
 
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m	Wed Nov 20 14:41:12 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m	Tue Nov 26 16:35:19 2019 +0530
@@ -960,6 +960,15 @@
     if (mtlc != NULL) {
         RESET_PREVIOUS_OP();
         [mtlc endCommonRenderEncoder];
+        MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
+        id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
+        [commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
+            [cbwrapper release];
+        }];
+        [commandbuf commit];
+        if (sync) {
+            [commandbuf waitUntilCompleted];
+        }
         BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
         if (dstOps != NULL) {
             MTLSDOps *dstMTLOps = (MTLSDOps *)dstOps->privOps;