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 7 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
@@ -42,7 +42,7 @@ public class MTLLayer extends CFRetainedResource {

// Pass the insets to native code to make adjustments in blitTexture
private static native void nativeSetInsets(long layerPtr, int top, int left);
aghaisas marked this conversation as resolved.
Show resolved Hide resolved
private static native void validate(long layerPtr, MTLSurfaceData cglsd);
private static native void validate(long layerPtr, MTLSurfaceData mtlsd);
private static native void blitTexture(long layerPtr);

private LWWindowPeer peer;
@@ -107,11 +107,11 @@ public SurfaceData getSurfaceData() {
return surfaceData;
}

public void validate(final MTLSurfaceData cglsd) {
public void validate(final MTLSurfaceData mtlsd) {
MTLRenderQueue rq = MTLRenderQueue.getInstance();
rq.lock();
try {
execute(ptr -> validate(ptr, cglsd));
execute(ptr -> validate(ptr, mtlsd));
} finally {
rq.unlock();
}
@@ -613,15 +613,6 @@ public Object getDestination() {
}


// additional cleanup
private static native void destroyCGLContext(long ctx);

public static void destroyOGLContext(long ctx) {
if (ctx != 0L) {
destroyCGLContext(ctx);
}
}

/**
* Disposes the native resources associated with the given MTLSurfaceData
* (referenced by the pData parameter). This method is invoked from
@@ -50,11 +50,11 @@ public static SurfaceDataProxy createProxy(SurfaceData srcData,
return new MTLSurfaceDataProxy(dstConfig, srcData.getTransparency());
}

MTLGraphicsConfig oglgc;
MTLGraphicsConfig mtlgc;
int transparency;

public MTLSurfaceDataProxy(MTLGraphicsConfig oglgc, int transparency) {
this.oglgc = oglgc;
public MTLSurfaceDataProxy(MTLGraphicsConfig mtlgc, int transparency) {
this.mtlgc = mtlgc;
this.transparency = transparency;
}

@@ -65,7 +65,7 @@ public SurfaceData validateSurfaceData(SurfaceData srcData,
{
if (cachedData == null) {
try {
cachedData = oglgc.createManagedSurface(w, h, transparency);
cachedData = mtlgc.createManagedSurface(w, h, transparency);
} catch (OutOfMemoryError er) {
return null;
}
@@ -59,6 +59,8 @@
- (id<MTLRenderCommandEncoder> _Nonnull)getRenderEncoder:(id<MTLTexture> _Nonnull)dest
isDstOpaque:(bool)isOpaque;

- (id<MTLRenderCommandEncoder> _Nonnull)getAAShaderRenderEncoder:(const BMTLSDOps * _Nonnull)dstOps;

// returns encoder that renders/fills geometry with current composite and with given texture
// (user must call [encoder setFragmentTexture] before any rendering)
- (id<MTLRenderCommandEncoder> _Nonnull)getTextureEncoder:(const BMTLSDOps * _Nonnull)dstOps
@@ -54,6 +54,7 @@ - (void)updateEncoder:(id<MTLRenderCommandEncoder>)encoder
@property (assign) jboolean aa;
@property (assign) jboolean text;
@property (assign) jboolean lcd;
@property (assign) jboolean aaShader;
@property (retain) MTLPaint* paint;
@end

@@ -68,6 +69,7 @@ @implementation EncoderStates {
jboolean _isAA;
jboolean _isText;
jboolean _isLCD;
jboolean _isAAShader;

//
// Cached 'mutable' states of encoder
@@ -93,6 +95,7 @@ @implementation EncoderStates {
@synthesize aa = _isAA;
@synthesize text = _isText;
@synthesize lcd = _isLCD;
@synthesize aaShader = _isAAShader;
@synthesize paint = _paint;

- (id)init {
@@ -178,6 +181,7 @@ - (void)updatePipelineState:(id<MTLRenderCommandEncoder>)encoder
&& [_composite isEqual:mtlc.composite]
&& (_isTexture == renderOptions->isTexture && (!renderOptions->isTexture || _interpolationMode == renderOptions->interpolation)) // interpolation is used only in texture mode
&& _isAA == renderOptions->isAA
&& _isAAShader == renderOptions->isAAShader
&& _isText == renderOptions->isText
&& _isLCD == renderOptions->isLCD
&& _srcFlags.isOpaque == renderOptions->srcFlags.isOpaque && _srcFlags.isPremultiplied == renderOptions->srcFlags.isPremultiplied)
@@ -188,6 +192,7 @@ - (void)updatePipelineState:(id<MTLRenderCommandEncoder>)encoder
_isTexture = renderOptions->isTexture;
_interpolationMode = renderOptions->interpolation;
_isAA = renderOptions->isAA;
_isAAShader = renderOptions->isAAShader;
_isText = renderOptions->isText;
_isLCD = renderOptions->isLCD;
_srcFlags = renderOptions->srcFlags;
@@ -283,14 +288,20 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {

- (id<MTLRenderCommandEncoder> _Nonnull)getAARenderEncoder:(const BMTLSDOps * _Nonnull)dstOps {
id<MTLTexture> dstTxt = dstOps->pTexture;
RenderOptions roptions = {JNI_FALSE, JNI_TRUE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {dstOps->isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_FALSE, JNI_TRUE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {dstOps->isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dstTxt renderOptions:&roptions];
}

- (id<MTLRenderCommandEncoder> _Nonnull)getAAShaderRenderEncoder:(const BMTLSDOps * _Nonnull)dstOps
{
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {dstOps->isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_TRUE};
return [self getEncoder:dstOps->pTexture renderOptions:&roptions];
}

- (id<MTLRenderCommandEncoder> _Nonnull)getRenderEncoder:(id<MTLTexture> _Nonnull)dest
isDstOpaque:(bool)isOpaque
{
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_FALSE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, defaultRasterFlags, {isOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

@@ -318,7 +329,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
isSrcOpaque:(bool)isSrcOpaque
isDstOpaque:(bool)isDstOpaque
{
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, {isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_TRUE};
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, {isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_TRUE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

@@ -328,7 +339,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
interpolation:(int)interpolation
isAA:(jboolean)isAA
{
RenderOptions roptions = {JNI_TRUE, isAA, interpolation, { isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE};
RenderOptions roptions = {JNI_TRUE, isAA, interpolation, { isSrcOpaque, JNI_TRUE }, {isDstOpaque, JNI_TRUE}, JNI_FALSE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dest renderOptions:&roptions];
}

@@ -343,7 +354,7 @@ - (void)setContext:(MTLContex * _Nonnull)mtlc {
- (id<MTLRenderCommandEncoder> _Nonnull) getTextEncoder:(const BMTLSDOps * _Nonnull)dstOps
isSrcOpaque:(bool)isSrcOpaque
{
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, { isSrcOpaque, JNI_TRUE }, {dstOps->isOpaque, JNI_TRUE}, JNI_TRUE, JNI_FALSE};
RenderOptions roptions = {JNI_TRUE, JNI_FALSE, INTERPOLATION_NEAREST_NEIGHBOR, { isSrcOpaque, JNI_TRUE }, {dstOps->isOpaque, JNI_TRUE}, JNI_TRUE, JNI_FALSE, JNI_FALSE};
return [self getEncoder:dstOps->pTexture renderOptions:&roptions];
}

@@ -361,6 +361,12 @@ jboolean clipDestCoords(
RETURN_IF_NULL(mtlc);
RETURN_IF_NULL(srcOps);
RETURN_IF_NULL(dstOps);
// Verify if we use a valid MTLContext
MTLSDOps *dstMTLOps = (MTLSDOps *)dstOps->privOps;
RETURN_IF_TRUE(dstMTLOps->configInfo != NULL && mtlc != dstMTLOps->configInfo->context);

MTLSDOps *srcMTLOps = (MTLSDOps *)srcOps->privOps;
RETURN_IF_TRUE(srcMTLOps->configInfo != NULL && mtlc != srcMTLOps->configInfo->context);

id<MTLTexture> srcTex = srcOps->pTexture;
id<MTLTexture> dstTex = dstOps->pTexture;
@@ -484,6 +490,9 @@ jboolean clipDestCoords(
RETURN_IF_NULL(mtlc);
RETURN_IF_NULL(srcOps);
RETURN_IF_NULL(dstOps);
// Verify if we use a valid MTLContext
MTLSDOps *dstMTLOps = (MTLSDOps *)dstOps->privOps;
RETURN_IF_TRUE(dstMTLOps->configInfo != NULL && mtlc != dstMTLOps->configInfo->context);

id<MTLTexture> dest = dstOps->pTexture;
if (dest == NULL) {
@@ -65,6 +65,7 @@ enum Clip {
- (const MTLScissorRect *) getRect;

- (void)reset;
- (void)resetStencilState;
- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2;
- (void)beginShapeClip:(BMTLSDOps *)dstOps context:(MTLContext *)mtlc;
- (void)endShapeClip:(BMTLSDOps *)dstOps context:(MTLContext *)mtlc;
@@ -26,6 +26,7 @@
#include "MTLClip.h"

#include "MTLContext.h"
#include "MTLStencilManager.h"
#include "common.h"

static MTLRenderPipelineDescriptor * templateStencilPipelineDesc = nil;
@@ -49,28 +50,6 @@ static void initTemplatePipelineDescriptors() {
templateStencilPipelineDesc.label = @"template_stencil";
}

static id<MTLDepthStencilState> getStencilState(id<MTLDevice> device) {
static id<MTLDepthStencilState> stencilState = nil;
if (stencilState == nil) {
MTLDepthStencilDescriptor* stencilDescriptor;
stencilDescriptor = [[MTLDepthStencilDescriptor new] autorelease];
stencilDescriptor.frontFaceStencil.stencilCompareFunction = MTLCompareFunctionEqual;
stencilDescriptor.frontFaceStencil.stencilFailureOperation = MTLStencilOperationKeep;

// TODO : backFaceStencil can be set to nil if all primitives are drawn as front-facing primitives
// currently, fill parallelogram uses back-facing primitive drawing - that needs to be changed.
// Once that part is changed, set backFaceStencil to nil
//stencilDescriptor.backFaceStencil = nil;

stencilDescriptor.backFaceStencil.stencilCompareFunction = MTLCompareFunctionEqual;
stencilDescriptor.backFaceStencil.stencilFailureOperation = MTLStencilOperationKeep;

stencilState = [device newDepthStencilStateWithDescriptor:stencilDescriptor];
}

return stencilState;
}

@implementation MTLClip {
jint _clipType;
MTLScissorRect _clipRect;
@@ -128,6 +107,7 @@ - (void)copyFrom:(MTLClip *)other {
_clipType = other->_clipType;
_stencilMaskGenerationInProgress = other->_stencilMaskGenerationInProgress;
_dstOps = other->_dstOps;
_mtlc = other->_mtlc;
if (other->_clipType == RECT_CLIP) {
_clipRect = other->_clipRect;
}
@@ -138,6 +118,7 @@ - (void)reset {
_stencilMaskGenerationInProgress = JNI_FALSE;
}


- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2 {
if (_clipType == SHAPE_CLIP) {
_dstOps = NULL;
@@ -301,7 +282,7 @@ - (void)setScissorOrStencil:(id<MTLRenderCommandEncoder>)encoder

if (_clipType == SHAPE_CLIP) {
// Enable stencil test
[encoder setDepthStencilState:getStencilState(device)];
[encoder setDepthStencilState:_mtlc.stencilManager.stencilState];
[encoder setStencilReferenceValue:0xFF];
}
}
@@ -38,6 +38,9 @@
#include "MTLPaints.h"
#include "MTLClip.h"
#include "EncoderManager.h"
#include "MTLSamplerManager.h"

@class MTLStencilManager;

// Constant from
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
@@ -74,6 +77,8 @@
@property (strong) id<MTLBuffer> vertexBuffer;

@property (readonly) EncoderManager * encoderManager;
@property (readonly) MTLSamplerManager * samplerManager;
@property (readonly) MTLStencilManager * stencilManager;

@property (strong)MTLPipelineStatesStorage* pipelineStateStorage;
@property (strong)MTLTexturePool* texturePool;
@@ -172,7 +177,7 @@
M01:(jdouble) m01 M11:(jdouble) m11
M02:(jdouble) m02 M12:(jdouble) m12;


- (void)reset;
- (void)resetPaint;
- (void)setColorPaint:(int)pixel;
- (void)setGradientPaintUseMask:(jboolean)useMask
@@ -30,6 +30,8 @@
#include "jlong.h"
#import "MTLContext.h"
#include "MTLRenderQueue.h"
#import "MTLSamplerManager.h"
#import "MTLStencilManager.h"


extern jboolean MTLSD_InitMTLWindow(JNIEnv *env, MTLSDOps *mtlsdo);
@@ -108,12 +110,15 @@ @implementation MTLContext {
NSObject* _bufImgOp; // TODO: pass as parameter of IsoBlit

EncoderManager * _encoderManager;
MTLSamplerManager * _samplerManager;
MTLStencilManager * _stencilManager;
}

@synthesize textureFunction,
vertexCacheEnabled, aaEnabled, device, pipelineStateStorage,
commandQueue, blitCommandQueue, vertexBuffer,
texturePool, paint=_paint;
texturePool, paint=_paint, encoderManager=_encoderManager,
samplerManager=_samplerManager, stencilManager=_stencilManager;

extern void initSamplers(id<MTLDevice> device);

@@ -137,6 +142,8 @@ - (id)initWithDevice:(id<MTLDevice>)d shadersLib:(NSString*)shadersLib {

_encoderManager = [[EncoderManager alloc] init];
[_encoderManager setContext:self];
_samplerManager = [[MTLSamplerManager alloc] initWithDevice:device];
_stencilManager = [[MTLStencilManager alloc] initWithDevice:device];
_composite = [[MTLComposite alloc] init];
_paint = [[MTLPaint alloc] init];
_transform = [[MTLTransform alloc] init];
@@ -150,8 +157,6 @@ - (id)initWithDevice:(id<MTLDevice>)d shadersLib:(NSString*)shadersLib {
blitCommandQueue = [device newCommandQueue];

_tempTransform = [[MTLTransform alloc] init];

initSamplers(device);
}
return self;
}
@@ -165,6 +170,8 @@ - (void)dealloc {
self.blitCommandQueue = nil;
self.pipelineStateStorage = nil;
[_encoderManager release];
[_samplerManager release];
[_stencilManager release];
[_composite release];
[_paint release];
[_transform release];
@@ -173,6 +180,12 @@ - (void)dealloc {
[super dealloc];
}

- (void) reset {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLContext : reset");

// Add code for context state reset here
}

- (MTLCommandBufferWrapper *) getCommandBufferWrapper {
if (_commandBufferWrapper == nil) {
J2dTraceLn(J2D_TRACE_VERBOSE, "MTLContext : commandBuffer is NULL");
@@ -210,7 +223,7 @@ + (MTLContext*) setSurfacesEnv:(JNIEnv*)env src:(jlong)pSrc dst:(jlong)pDst {
// initialize the surface as an MTLSD_WINDOW
if (!MTLSD_InitMTLWindow(env, dstOps)) {
J2dRlsTraceLn(J2D_TRACE_ERROR,
"MTLContext_SetSurfaces: could not init OGL window");
"MTLContext_SetSurfaces: could not init MTL window");
return NULL;
}
}