Skip to content

Commit d019f30

Browse files
jayathirthraoarapte
authored andcommittedAug 17, 2023
8314401: Clear color attachment at appropriate stage

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed
 

‎modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.h

+2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ typedef enum VertexInputIndex {
157157
- (void) setCameraPosition:(float)x
158158
y:(float)y z:(float)z;
159159
- (vector_float4) getCameraPosition;
160+
- (MTLScissorRect) getScissorRect;
160161
- (bool) isDepthEnabled;
162+
- (bool) isScissorEnabled;
161163
- (void) dealloc;
162164

163165
@end

‎modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.m

+25-15
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ - (void) setRTT:(MetalRTTexture*)rttPtr
8181
rtt = rttPtr;
8282
CTX_LOG(@"-> Native: MetalContext.setRTT() %lu , %lu",
8383
[rtt getTexture].width, [rtt getTexture].height);
84-
rttPassDesc.colorAttachments[0].texture = [rtt getTexture];
84+
if ([rttPtr isMSAAEnabled]) {
85+
rttPassDesc.colorAttachments[0].storeAction = MTLStoreActionStoreAndMultisampleResolve;
86+
rttPassDesc.colorAttachments[0].texture = [rtt getMSAATexture];
87+
rttPassDesc.colorAttachments[0].resolveTexture = [rtt getTexture];
88+
} else {
89+
rttPassDesc.colorAttachments[0].storeAction = MTLStoreActionStore;
90+
rttPassDesc.colorAttachments[0].texture = [rtt getTexture];
91+
rttPassDesc.colorAttachments[0].resolveTexture = nil;
92+
}
8593
[self resetClip];
8694
}
8795

@@ -510,21 +518,9 @@ - (NSInteger) setDeviceParametersFor3D
510518
CTX_LOG(@"MetalContext_setDeviceParametersFor3D()");
511519
id<MTLCommandBuffer> commandBuffer = [self getCurrentCommandBuffer];
512520
phongRPD = [MTLRenderPassDescriptor new];
513-
if (!rttCleared) {
514-
phongRPD.colorAttachments[0].loadAction = MTLLoadActionClear;
515-
}
516-
if (clearDepthTexture &&
517-
depthEnabled) {
518-
phongRPD.depthAttachment.loadAction = MTLLoadActionClear;
519-
}
520-
phongRPD.colorAttachments[0].clearColor =
521-
MTLClearColorMake(clearColor[0],
522-
clearColor[1],
523-
clearColor[2],
524-
clearColor[3]);
521+
phongRPD.colorAttachments[0].loadAction = MTLLoadActionLoad;
525522

526523
if ([[self getRTT] isMSAAEnabled]) {
527-
phongRPD.colorAttachments[0].loadAction = MTLLoadActionClear;
528524
phongRPD.colorAttachments[0].storeAction = MTLStoreActionStoreAndMultisampleResolve;
529525
phongRPD.colorAttachments[0].texture = [rtt getMSAATexture];
530526
phongRPD.colorAttachments[0].resolveTexture = [rtt getTexture];
@@ -535,8 +531,12 @@ - (NSInteger) setDeviceParametersFor3D
535531
}
536532
if (depthEnabled) {
537533
phongRPD.depthAttachment.clearDepth = 1.0;
538-
if ([[self getRTT] isMSAAEnabled]) {
534+
if (clearDepthTexture) {
539535
phongRPD.depthAttachment.loadAction = MTLLoadActionClear;
536+
} else {
537+
phongRPD.depthAttachment.loadAction = MTLLoadActionLoad;
538+
}
539+
if ([[self getRTT] isMSAAEnabled]) {
540540
phongRPD.depthAttachment.storeAction = MTLStoreActionStoreAndMultisampleResolve;
541541
phongRPD.depthAttachment.texture = [rtt getDepthMSAATexture];
542542
phongRPD.depthAttachment.resolveTexture = [rtt getDepthTexture];
@@ -583,11 +583,21 @@ - (vector_float4) getCameraPosition
583583
return cPos;
584584
}
585585

586+
- (MTLScissorRect) getScissorRect
587+
{
588+
return scissorRect;
589+
}
590+
586591
- (bool) isDepthEnabled
587592
{
588593
return depthEnabled;
589594
}
590595

596+
- (bool) isScissorEnabled
597+
{
598+
return isScissorEnabled;
599+
}
600+
591601
// TODO: MTL: This was copied from GlassHelper, and could be moved to a utility class.
592602
+ (NSString*) nsStringWithJavaString:(jstring)javaString withEnv:(JNIEnv*)env
593603
{

‎modules/javafx.graphics/src/main/native-prism-mtl/MetalMeshView.m

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ - (void) render
200200
if (wireframe) {
201201
[phongEncoder setTriangleFillMode:MTLTriangleFillModeLines];
202202
}
203+
if ([context isScissorEnabled]) {
204+
[phongEncoder setScissorRect:[context getScissorRect]];
205+
}
203206
vsUniforms.mvp_matrix = [context getMVPMatrix];
204207
vsUniforms.world_matrix = [context getWorldMatrix];
205208
vsUniforms.cameraPos = [context getCameraPosition];

‎modules/javafx.graphics/src/main/native-prism-mtl/MetalPipelineManager.m

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ - (void) init:(MetalContext*) ctx libPath:(NSString*) path
8282
pipeDesc.fragmentFunction = func;
8383
pipeDesc.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm; //rtt.pixelFormat
8484

85+
if ([[context getRTT] isMSAAEnabled]) {
86+
pipeDesc.sampleCount = 4;
87+
} else {
88+
pipeDesc.sampleCount = 1;
89+
}
90+
8591
[self setPipelineCompositeBlendMode:pipeDesc];
8692

8793
id<MTLRenderPipelineState> pipeState = [[context getDevice] newRenderPipelineStateWithDescriptor:pipeDesc error:&error];

0 commit comments

Comments
 (0)