Skip to content
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

8260931: Implement JEP 382: New macOS Rendering Pipeline #2403

Closed
wants to merge 47 commits into from
Closed
Changes from 9 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0b8d96b
Project Lanai Patch
aghaisas Feb 4, 2021
5476874
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 8, 2021
8ed7b5f
Lanai PR#174 - 8261234 - kcr
aghaisas Feb 8, 2021
6044adc
Lanai PR#175 - 8261304 - aghaisas
aghaisas Feb 8, 2021
fdf3be9
Lanai PR#176 - 8261399 - jdv
aghaisas Feb 9, 2021
6417328
Lanai PR#177 - 8261430 - aghaisas
aghaisas Feb 9, 2021
9a72538
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 11, 2021
9c13bb3
Lanai PR#178 - 8261273 - avu
aghaisas Feb 11, 2021
6a3f96e
Lanai PR#179 - 8261402 - avu
aghaisas Feb 11, 2021
102494b
Lanai PR#180 - 8261546 - jdv
aghaisas Feb 11, 2021
7340d06
Lanai PR#181 - 8261143 - aghaisas
aghaisas Feb 11, 2021
a7df89b
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 15, 2021
edf247d
Lanai PR#182 - 8261547 - psadhukhan
aghaisas Feb 15, 2021
8b5bf34
Lanai PR#184 - 8261620 - aghaisas
aghaisas Feb 15, 2021
d2548e0
Lanai PR#185 - 8261632 - jdv
aghaisas Feb 15, 2021
0d8aedc
Lanai PR#186 - 8261638 - avu
aghaisas Feb 15, 2021
3942a5b
Lanai PR#187 - 8261704 - jdv
aghaisas Feb 15, 2021
90af90d
Lanai PR#189 - 8261712 - avu
aghaisas Feb 15, 2021
1c0c0c1
Lanai PR#190 - 8261706 - jdv
aghaisas Feb 15, 2021
7b0b0dc
Lanai PR#191 - 8261705 - jdv
aghaisas Feb 15, 2021
10ebb70
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Feb 21, 2021
9432c5a
Lanai PR#192 - 8261789 - aghaisas
aghaisas Feb 21, 2021
68220fb
Lanai PR#193 - 8261734 - avu
aghaisas Feb 21, 2021
30284b9
Lanai PR#194 - 8261703 - jdv
aghaisas Feb 21, 2021
e2f78dd
Lanai PR#195 - 8261908 - jdv
aghaisas Feb 21, 2021
1e0ff66
Lanai PR#196 - 8260715 - avu
aghaisas Feb 21, 2021
8c598a6
Lanai PR#197 - 8261960 - jdv
aghaisas Feb 21, 2021
a2983f0
Lanai PR#198 - 8261646 - avu
aghaisas Feb 21, 2021
614be05
Lanai PR#199 - 8262091 - aghaisas
aghaisas Feb 21, 2021
30dab8d
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 1, 2021
bf888a2
Lanai PR#200 - 8262115 - aghaisas
aghaisas Mar 1, 2021
6e2e528
Lanai PR#201 - 8261891 - avu
aghaisas Mar 1, 2021
9059255
Lanai PR#202 - 8262293 - avu
aghaisas Mar 1, 2021
e0fbc42
Lanai PR#203 - 8262313 - jdv
aghaisas Mar 1, 2021
c9ebcbc
Lanai PR#205 - 8262496 - avu
aghaisas Mar 1, 2021
5cb1fd9
Lanai PR#206 - 8262729 - aghaisas
aghaisas Mar 1, 2021
09519fd
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 8, 2021
3995be1
Lanai PR#207 - 8262750 - jdv
aghaisas Mar 8, 2021
5660744
Lanai PR#208 - 8262928 - jdv
aghaisas Mar 8, 2021
e459f1a
Lanai PR#209 - 8262936 - jdv
aghaisas Mar 8, 2021
de45693
Lanai PR#210 - 8263159 - jdv
aghaisas Mar 8, 2021
b065a49
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 10, 2021
d27ff90
Lanai PR#211 - 8262882 - aghaisas
aghaisas Mar 10, 2021
9a27831
Lanai PR#212 - 8259825 - aghaisas
aghaisas Mar 10, 2021
3980ecb
Lanai PR#213 - 8263325 - avu
aghaisas Mar 10, 2021
c4309ab
Merge branch 'master' into 8260931_lanai_JEP_branch
aghaisas Mar 11, 2021
369c3d2
Lanai PR#214 - 8263324 - avu
aghaisas Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -372,7 +372,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {

if (_encoder == nil) {
_destination = dest;
_useStencil = [_mtlc.clip isShape];
_useStencil = [_mtlc.clip isShape] && !_mtlc.clip.stencilMaskGenerationInProgress;
forceUpdate = JNI_TRUE;

MTLCommandBufferWrapper *cbw = [_mtlc getCommandBufferWrapper];
@@ -699,7 +699,6 @@ void copyFromMTLBuffer(void *pDst, id<MTLBuffer> srcBuf, jint offset, jint len,

id<MTLCommandBuffer> cb = [mtlc createCommandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [cb blitCommandEncoder];
[blitEncoder synchronizeTexture:srcOps->pTexture slice:0 level:0];
[blitEncoder copyFromTexture:srcOps->pTexture
sourceSlice:0
sourceLevel:0
@@ -117,14 +117,16 @@
JNI_COCOA_ENTER(env);
NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
[retArray addObject: [NSNumber numberWithInt: (int)displayID]];
[retArray addObject: [NSString stringWithUTF8String: JNU_GetStringPlatformChars(env, shadersLibName, 0)]];
char *str = JNU_GetStringPlatformChars(env, shadersLibName, 0);
[retArray addObject: [NSString stringWithUTF8String: str]];

[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
[MTLGraphicsConfigUtil _tryLoadMetalLibrary: retArray];
}];

NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
ret = (jboolean)[num boolValue];
JNU_ReleaseStringPlatformChars(env, shadersLibName, str);
JNI_COCOA_EXIT(env);
return ret;
}
@@ -148,14 +150,16 @@
JNI_COCOA_ENTER(env);
NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
[retArray addObject: [NSNumber numberWithInt: (int)displayID]];
[retArray addObject: [NSString stringWithUTF8String: JNU_GetStringPlatformChars(env, mtlShadersLib, 0)]];
char *str = JNU_GetStringPlatformChars(env, mtlShadersLib, 0);
[retArray addObject: [NSString stringWithUTF8String: str]];

[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
[MTLGraphicsConfigUtil _getMTLConfigInfo: retArray];
}];

NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
ret = (jlong)[num longValue];
JNU_ReleaseStringPlatformChars(env, mtlShadersLib, str);
JNI_COCOA_EXIT(env);
return ret;
}
@@ -91,6 +91,17 @@ - (void) blitTexture {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: cannot create drawable of size 0");
return;
}

NSUInteger src_x = self.leftInset * self.contentsScale;
NSUInteger src_y = self.topInset * self.contentsScale;
NSUInteger src_w = self.buffer.width - src_x;
NSUInteger src_h = self.buffer.height - src_y;

if (src_h <= 0 || src_w <= 0) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: Invalid src width or height.");
return;
}

id<MTLCommandBuffer> commandBuf = [self.ctx createBlitCommandBuffer];
if (commandBuf == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLLayer.blitTexture: commandBuf is null");
@@ -102,12 +113,13 @@ - (void) blitTexture {
return;
}
self.nextDrawableCount++;

id <MTLBlitCommandEncoder> blitEncoder = [commandBuf blitCommandEncoder];

[blitEncoder
copyFromTexture:self.buffer sourceSlice:0 sourceLevel:0
sourceOrigin:MTLOriginMake((jint)(self.leftInset*self.contentsScale), (jint)(self.topInset*self.contentsScale), 0)
sourceSize:MTLSizeMake(self.buffer.width, self.buffer.height, 1)
sourceOrigin:MTLOriginMake(src_x, src_y, 0)
sourceSize:MTLSizeMake(src_w, src_h, 1)
toTexture:mtlDrawable.texture destinationSlice:0 destinationLevel:0 destinationOrigin:MTLOriginMake(0, 0, 0)];
[blitEncoder endEncoding];

@@ -56,6 +56,11 @@ NSMutableDictionary<NSString*, id<MTLComputePipelineState>> * computeStates;
vertexShaderId:(NSString *)vertexShaderId
fragmentShaderId:(NSString *)fragmentShaderId;

- (id<MTLRenderPipelineState>) getPipelineState:(MTLRenderPipelineDescriptor *) pipelineDescriptor
vertexShaderId:(NSString *)vertexShaderId
fragmentShaderId:(NSString *)fragmentShaderId
stencilNeeded:(bool)stencilNeeded;

- (id<MTLRenderPipelineState>) getPipelineState:(MTLRenderPipelineDescriptor *) pipelineDescriptor
vertexShaderId:(NSString *)vertexShaderId
fragmentShaderId:(NSString *)fragmentShaderId
@@ -93,6 +93,20 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
stencilNeeded:NO];
}

- (id<MTLRenderPipelineState>) getPipelineState:(MTLRenderPipelineDescriptor *) pipelineDescriptor
vertexShaderId:(NSString *)vertexShaderId
fragmentShaderId:(NSString *)fragmentShaderId
stencilNeeded:(bool)stencilNeeded
{
RenderOptions defaultOptions = {JNI_FALSE, JNI_FALSE, 0/*unused*/, {JNI_FALSE, JNI_TRUE}, {JNI_FALSE, JNI_TRUE}, JNI_FALSE};
return [self getPipelineState:pipelineDescriptor
vertexShaderId:vertexShaderId
fragmentShaderId:fragmentShaderId
composite:nil
renderOptions:&defaultOptions
stencilNeeded:stencilNeeded];
}

// Base method to obtain MTLRenderPipelineState.
// NOTE: parameters compositeRule, srcFlags, dstFlags are used to set MTLRenderPipelineColorAttachmentDescriptor multipliers
- (id<MTLRenderPipelineState>) getPipelineState:(MTLRenderPipelineDescriptor *) pipelineDescriptor
@@ -315,6 +315,10 @@ void MTLRenderer_DrawPoly(MTLContext *mtlc, BMTLSDOps * dstOps,
}
}

const int SCANLINE_MAX_VERTEX_SIZE = 4096;
const int VERTEX_STRUCT_SIZE = 8;
const int NUM_OF_VERTICES_PER_SCANLINE = 3;

void
MTLRenderer_DrawScanlines(MTLContext *mtlc, BMTLSDOps * dstOps,
jint scanlineCount, jint *scanlines)
@@ -325,27 +329,80 @@ void MTLRenderer_DrawPoly(MTLContext *mtlc, BMTLSDOps * dstOps,
J2dTraceLn(J2D_TRACE_ERROR, "MTLRenderer_DrawScanlines: dest is null");
return;
}
RETURN_IF_NULL(scanlines);
int vertexSize = NUM_OF_VERTICES_PER_SCANLINE
* scanlineCount * VERTEX_STRUCT_SIZE;
J2dTraceLn1(J2D_TRACE_INFO, "MTLRenderer_DrawScanlines: Total vertex size : %d", vertexSize);
if (vertexSize == 0) return;

id<MTLRenderCommandEncoder> mtlEncoder = [mtlc.encoderManager getRenderEncoder:dstOps];

if (mtlEncoder == nil) return;

struct Vertex verts[2*scanlineCount];

for (int j = 0, i = 0; j < scanlineCount; j++) {
// Translate each vertex by a fraction so
// that we hit pixel centers.
float x1 = ((float)*(scanlines++)) + 0.2f;
float x2 = ((float)*(scanlines++)) + 1.2f;
float y = ((float)*(scanlines++)) + 0.5f;
struct Vertex v1 = {{x1, y}};
struct Vertex v2 = {{x2, y}};
verts[i++] = v1;
verts[i++] = v2;
}
if (vertexSize <= SCANLINE_MAX_VERTEX_SIZE) {
struct Vertex verts[NUM_OF_VERTICES_PER_SCANLINE * scanlineCount];

for (int j = 0, i = 0; j < scanlineCount; j++) {
// Translate each vertex by a fraction so
// that we hit pixel centers.
float x1 = ((float)*(scanlines++)) + 0.2f;
float x2 = ((float)*(scanlines++)) + 1.2f;
float y = ((float)*(scanlines++)) + 0.5f;
struct Vertex v1 = {{x1, y}};
struct Vertex v2 = {{x2, y}};
verts[i++] = v1;
verts[i++] = v2;
}

[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2*scanlineCount];
[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0
vertexCount:NUM_OF_VERTICES_PER_SCANLINE * scanlineCount];
} else {
int remainingScanlineCount = vertexSize;
do {
if (remainingScanlineCount > SCANLINE_MAX_VERTEX_SIZE) {
struct Vertex verts[SCANLINE_MAX_VERTEX_SIZE/ VERTEX_STRUCT_SIZE];

for (int j = 0, i = 0; j < (SCANLINE_MAX_VERTEX_SIZE / (VERTEX_STRUCT_SIZE * 2)); j++) {
// Translate each vertex by a fraction so
// that we hit pixel centers.
float x1 = ((float)*(scanlines++)) + 0.2f;
float x2 = ((float)*(scanlines++)) + 1.2f;
float y = ((float)*(scanlines++)) + 0.5f;
struct Vertex v1 = {{x1, y}};
struct Vertex v2 = {{x2, y}};
verts[i++] = v1;
verts[i++] = v2;
}

[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0
vertexCount:(SCANLINE_MAX_VERTEX_SIZE / VERTEX_STRUCT_SIZE)];
remainingScanlineCount -= SCANLINE_MAX_VERTEX_SIZE;
} else {
struct Vertex verts[remainingScanlineCount / VERTEX_STRUCT_SIZE];

for (int j = 0, i = 0; j < (remainingScanlineCount / (VERTEX_STRUCT_SIZE * 2)); j++) {
// Translate each vertex by a fraction so
// that we hit pixel centers.
float x1 = ((float)*(scanlines++)) + 0.2f;
float x2 = ((float)*(scanlines++)) + 1.2f;
float y = ((float)*(scanlines++)) + 0.5f;
struct Vertex v1 = {{x1, y}};
struct Vertex v2 = {{x2, y}};
verts[i++] = v1;
verts[i++] = v2;
}

[mtlEncoder setVertexBytes:verts length:sizeof(verts) atIndex:MeshVertexBuffer];
[mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0
vertexCount:(remainingScanlineCount / VERTEX_STRUCT_SIZE)];
remainingScanlineCount -= remainingScanlineCount;
}
J2dTraceLn1(J2D_TRACE_INFO,
"MTLRenderer_DrawScanlines: Remaining vertex size %d", remainingScanlineCount);
} while (remainingScanlineCount != 0);
}
}

void
@@ -714,8 +771,9 @@ void MTLRenderer_FillSpans(MTLContext *mtlc, BMTLSDOps * dstOps, jint spanCount,
id<MTLRenderPipelineState> pipelineState =
[mtlc.pipelineStateStorage
getPipelineState:templateAAPipelineDesc
vertexShaderId:@"vert_col_aa"
vertexShaderId:@"vert_col_aa"
fragmentShaderId:@"frag_col_aa"
stencilNeeded:mtlc.clip.isShape
];

[encoder setRenderPipelineState:pipelineState];
@@ -32,7 +32,7 @@
/**
* Constants that control the size of the vertex cache.
*/
#define MTLVC_MAX_INDEX 1536
#define MTLVC_MAX_INDEX 250

/**
* Constants that control the size of the texture tile cache used for