Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 51172c4

Browse files
committedJun 25, 2020
8248301: Lanai - Change MTLStorageMode of MTLSurfaceData texture (render backbuffer) to private
1 parent ebaa2c3 commit 51172c4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void drawTex2Tex(MTLContext *mtlc,
170170
}
171171

172172
static
173-
id<MTLTexture> replaceTextureRegion(id<MTLTexture> dest, const SurfaceDataRasInfo * srcInfo, const MTLRasterFormatInfo * rfi, int dx1, int dy1, int dx2, int dy2) {
173+
id<MTLTexture> replaceTextureRegion(MTLContext *mtlc, id<MTLTexture> dest, const SurfaceDataRasInfo * srcInfo, const MTLRasterFormatInfo * rfi, int dx1, int dy1, int dx2, int dy2) {
174174
const int dw = dx2 - dx1;
175175
const int dh = dy2 - dy1;
176176

@@ -242,7 +242,20 @@ void drawTex2Tex(MTLContext *mtlc,
242242
MTLRegion region = MTLRegionMake2D(dx1, dy1, dw, dh);
243243
if (result != nil)
244244
dest = result;
245-
[dest replaceRegion:region mipmapLevel:0 withBytes:raster bytesPerRow:srcInfo->scanStride];
245+
246+
@autoreleasepool {
247+
id <MTLBlitCommandEncoder> blitEncoder = [mtlc.encoderManager createBlitEncoder];
248+
249+
J2dTraceLn4(J2D_TRACE_VERBOSE, "replaceTextureRegion src (dw, dh) : [%d, %d] dest (dx1, dy1) =[%d, %d]",
250+
dw, dh, dx1, dy1);
251+
252+
id <MTLBuffer> buff = [[mtlc.device newBufferWithBytes:raster length:srcInfo->scanStride * dh options:MTLResourceStorageModeManaged] autorelease];
253+
[blitEncoder copyFromBuffer:buff
254+
sourceOffset:0 sourceBytesPerRow:srcInfo->scanStride sourceBytesPerImage:srcInfo->scanStride * dh sourceSize:MTLSizeMake(dw, dh, 1)
255+
toTexture:dest destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(dx1, dy1, 0)];
256+
[blitEncoder endEncoding];
257+
}
258+
246259
return result;
247260
}
248261

@@ -271,7 +284,7 @@ void drawTex2Tex(MTLContext *mtlc,
271284
[texHandle release];
272285

273286
id<MTLTexture> texBuff = texHandle.texture;
274-
id<MTLTexture> swizzledTexture = replaceTextureRegion(texBuff, srcInfo, rfi, 0, 0, sw, sh);
287+
id<MTLTexture> swizzledTexture = replaceTextureRegion(mtlc, texBuff, srcInfo, rfi, 0, 0, sw, sh);
275288
if (useBlitEncoder) {
276289
id <MTLBlitCommandEncoder> blitEncoder = [mtlc.encoderManager createBlitEncoder];
277290
[blitEncoder copyFromTexture:swizzledTexture != nil ? swizzledTexture : texBuff
@@ -618,7 +631,7 @@ jboolean clipDestCoords(
618631
#ifdef TRACE_BLIT
619632
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE," [replaceTextureRegion]");
620633
#endif //TRACE_BLIT
621-
replaceTextureRegion(dest, &srcInfo, &rfi, (int) dx1, (int) dy1, (int) dx2, (int) dy2);
634+
replaceTextureRegion(mtlc, dest, &srcInfo, &rfi, (int) dx1, (int) dy1, (int) dx2, (int) dy2);
622635
} else {
623636
#ifdef TRACE_BLIT
624637
J2dTraceImpl(J2D_TRACE_VERBOSE, JNI_TRUE," [via pooled + blit]");

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

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque
7373
}
7474
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: MTLPixelFormatBGRA8Unorm width: width height: height mipmapped: NO];
7575
textureDescriptor.usage = MTLTextureUsageUnknown;
76+
textureDescriptor.storageMode = MTLStorageModePrivate;
7677
bmtlsdo->pTexture = [ctx.device newTextureWithDescriptor: textureDescriptor];
7778

7879
MTLTextureDescriptor *stencilDataDescriptor =

0 commit comments

Comments
 (0)
This repository has been archived.