diff --git a/modules/javafx.graphics/src/main/native-prism-mtl/ClearRttShaders.metal b/modules/javafx.graphics/src/main/native-prism-mtl/ClearRttShaders.metal index f6d2d07b8e..6d8240c1c1 100644 --- a/modules/javafx.graphics/src/main/native-prism-mtl/ClearRttShaders.metal +++ b/modules/javafx.graphics/src/main/native-prism-mtl/ClearRttShaders.metal @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,11 +41,10 @@ typedef struct CLEAR_VS_OUTPUT } CLEAR_VS_OUTPUT; [[vertex]] CLEAR_VS_OUTPUT clearVF(const uint v_id [[ vertex_id ]], - constant CLEAR_VS_INPUT* v_in [[ buffer(0) ]], - constant float4x4& mvp_matrix [[ buffer(1) ]]) + constant CLEAR_VS_INPUT* v_in [[ buffer(0) ]]) { CLEAR_VS_OUTPUT out; - out.position = vector_float4(v_in[v_id].position.xy, 0.0, 1.0) * mvp_matrix; + out.position = vector_float4(v_in[v_id].position.xy, 0.0, 1.0); return out; } diff --git a/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.h b/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.h index fe3b206fc3..3742354a5c 100644 --- a/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.h +++ b/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,7 +80,6 @@ typedef enum VertexInputIndex { // clear rtt CLEAR_VS_INPUT clearScissorRectVertices[4]; id<MTLBuffer> clearEntireRttVerticesBuf; - id<MTLBuffer> identityMatrixBuf; id<MTLBuffer> indexBuffer; id<MTLDevice> device; diff --git a/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.m b/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.m index 193fa5688c..0fc50ad19b 100644 --- a/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.m +++ b/modules/javafx.graphics/src/main/native-prism-mtl/MetalContext.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -85,13 +85,6 @@ - (id) createContext:(dispatch_data_t)shaderLibData pixelBuffer = [device newBufferWithLength:4 options:MTLResourceStorageModeShared]; // clearing rtt related initialization - identityMatrixBuf = [device newBufferWithLength:sizeof(simd_float4x4) - options:MTLResourceStorageModePrivate]; - id<MTLBuffer> tMatBuf = [self getTransientBufferWithLength:sizeof(simd_float4x4)]; - simd_float4x4* identityMatrix = (simd_float4x4*)tMatBuf.contents; - - *identityMatrix = matrix_identity_float4x4; - clearEntireRttVerticesBuf = [device newBufferWithLength:sizeof(CLEAR_VS_INPUT) * 4 options:MTLResourceStorageModePrivate]; id<MTLBuffer> tclearVertBuf = [self getTransientBufferWithLength:sizeof(CLEAR_VS_INPUT) * 4]; @@ -133,12 +126,6 @@ - (id) createContext:(dispatch_data_t)shaderLibData destinationOffset:(NSUInteger)0 size:tclearVertBuf.length]; - [blitEncoder copyFromBuffer:tMatBuf - sourceOffset:(NSUInteger)0 - toBuffer:identityMatrixBuf - destinationOffset:(NSUInteger)0 - size:tMatBuf.length]; - [blitEncoder endEncoding]; } [self commitCurrentCommandBuffer:false]; @@ -546,20 +533,12 @@ - (void) clearRTT:(float)red if (isScissorEnabled) { CTX_LOG(@" MetalContext.clearRTT() clearing scissor rect"); - [renderEncoder setVertexBytes:&mvpMatrix - length:sizeof(mvpMatrix) - atIndex:VertexInputMatrixMVP]; - [renderEncoder setVertexBytes:clearScissorRectVertices length:sizeof(clearScissorRectVertices) atIndex:VertexInputIndexVertices]; } else { CTX_LOG(@" MetalContext.clearRTT() clearing whole rtt"); - [renderEncoder setVertexBuffer:identityMatrixBuf - offset:0 - atIndex:VertexInputMatrixMVP]; - [renderEncoder setVertexBuffer:clearEntireRttVerticesBuf offset:0 atIndex:VertexInputIndexVertices]; @@ -620,14 +599,22 @@ - (void) setClipRect:(int)x y:(int)y width:(int)width height:(int)height scissorRect.height = height; isScissorEnabled = true; - clearScissorRectVertices[0].position.x = scissorRect.x; - clearScissorRectVertices[0].position.y = scissorRect.y; - clearScissorRectVertices[1].position.x = scissorRect.x; - clearScissorRectVertices[1].position.y = scissorRect.y + scissorRect.height; - clearScissorRectVertices[2].position.x = scissorRect.x + scissorRect.width; - clearScissorRectVertices[2].position.y = scissorRect.y; - clearScissorRectVertices[3].position.x = scissorRect.x + scissorRect.width; - clearScissorRectVertices[3].position.y = scissorRect.y + scissorRect.height; + // Create device space (-1, 1) coordinates of scissor rect. + float halfWidth = (float)currRtt.width / 2.0f; + float halfHeight = (float)currRtt.height / 2.0f; + float x1 = (scissorRect.x - halfWidth) / halfWidth; + float y1 = - (scissorRect.y - halfHeight) / halfHeight; + float x2 = ((scissorRect.x + scissorRect.width) - halfWidth) / halfWidth; + float y2 = - ((scissorRect.y + scissorRect.height) - halfHeight) / halfHeight; + + clearScissorRectVertices[0].position.x = x1; + clearScissorRectVertices[0].position.y = y1; + clearScissorRectVertices[1].position.x = x1; + clearScissorRectVertices[1].position.y = y2; + clearScissorRectVertices[2].position.x = x2; + clearScissorRectVertices[2].position.y = y1; + clearScissorRectVertices[3].position.x = x2; + clearScissorRectVertices[3].position.y = y2; } CTX_LOG(@"<<<< MetalContext.setClipRect()"); } @@ -891,10 +878,6 @@ - (void)dealloc [shadersUsedInCB release]; shadersUsedInCB = nil; } - if (identityMatrixBuf != nil) { - [identityMatrixBuf release]; - identityMatrixBuf = nil; - } if (clearEntireRttVerticesBuf != nil) { [clearEntireRttVerticesBuf release];