Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8252371: LCD text rendered with Metal pipeline is corrupted
  • Loading branch information
jayathirthrao committed Aug 26, 2020
1 parent ca68b18 commit 0e80c21f1ab3d5f6c7d17a8c92cd67c47305569a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
@@ -54,6 +54,12 @@ struct TxtShaderInOut {
float2 tpCoords;
};

struct LCDShaderInOut {
float4 position [[position]];
float2 orig_pos;
float2 texCoords;
};

struct GradShaderInOut {
float4 position [[position]];
float2 texCoords;
@@ -108,6 +114,15 @@ vertex TxtShaderInOut vert_txt(TxtVertexInput in [[stage_in]], constant Transfor
return out;
}

vertex LCDShaderInOut vert_txt_lcd(TxtVertexInput in [[stage_in]], constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
LCDShaderInOut out;
float4 pos4 = float4(in.position, 0.0, 1.0);
out.position = transform.transformMatrix*pos4;
out.orig_pos = in.position;
out.texCoords = in.texCoords;
return out;
}

vertex TxtShaderInOut vert_txt_tp(TxtVertexInput in [[stage_in]], constant AnchorData& anchorData [[buffer(FrameUniformBuffer)]], constant TransformMatrix& transform [[buffer(MatrixBuffer)]])
{
TxtShaderInOut out;
@@ -392,7 +407,7 @@ fragment half4 frag_tp(
* Cr = (Ag*(Cs^Ga) + (1-Ag)*(Cd^Ga)) ^ (1/Ga)
*/
fragment float4 lcd_color(
TxtShaderInOut vert [[stage_in]],
LCDShaderInOut vert [[stage_in]],
texture2d<float, access::sample> glyphTexture [[texture(0)]],
texture2d<float, access::sample> dstTexture [[texture(1)]],
constant LCDFrameUniforms& uniforms [[buffer(1)]])
@@ -401,8 +416,9 @@ fragment float4 lcd_color(
float3 gamma = uniforms.gamma;
float3 invgamma = uniforms.invgamma;

constexpr sampler glyphTextureSampler (mag_filter::linear,
min_filter::linear);
constexpr sampler glyphTextureSampler (address::repeat,
mag_filter::nearest,
min_filter::nearest);

// load the RGB value from the glyph image at the current texcoord
float3 glyph_clr = float3(glyphTexture.sample(glyphTextureSampler, vert.texCoords));
@@ -411,10 +427,10 @@ fragment float4 lcd_color(
// zero coverage, so skip this fragment
discard_fragment();
}
constexpr sampler dstTextureSampler (mag_filter::linear,
min_filter::linear);

// load the RGB value from the corresponding destination pixel
float3 dst_clr = float3(dstTexture.sample(dstTextureSampler, vert.texCoords));
uint2 texCoord = {(unsigned int)(vert.orig_pos.x), (unsigned int)(vert.orig_pos.y)};
float4 dst_clr = dstTexture.read(texCoord);

// gamma adjust the dest color
float3 dst_adj = pow(dst_clr.rgb, gamma);
@@ -374,7 +374,7 @@
id<MTLRenderPipelineState> pipelineState =
[mtlc.pipelineStateStorage
getPipelineState:templateLCDPipelineDesc
vertexShaderId:@"vert_txt"
vertexShaderId:@"vert_txt_lcd"
fragmentShaderId:@"lcd_color"
];

@@ -437,7 +437,7 @@
id<MTLRenderPipelineState> pipelineState =
[mtlc.pipelineStateStorage
getPipelineState:templateLCDPipelineDesc
vertexShaderId:@"vert_txt"
vertexShaderId:@"vert_txt_lcd"
fragmentShaderId:@"lcd_color"
];

@@ -876,6 +876,7 @@
glyphMode = MODE_NOT_INITED;
isCachedDestValid = JNI_FALSE;
J2dTraceLn1(J2D_TRACE_INFO, "totalGlyphs = %d", totalGlyphs);
jboolean flushBeforeLCD = JNI_FALSE;

for (glyphCounter = 0; glyphCounter < totalGlyphs; glyphCounter++) {
J2dTraceLn(J2D_TRACE_INFO, "Entered for loop for glyph list");
@@ -928,6 +929,18 @@
ok = MTLTR_DrawGrayscaleGlyphNoCache(mtlc, ginfo, x, y, dstOps);
}
} else {
if (!flushBeforeLCD) {
[mtlc.encoderManager endEncoder];
MTLCommandBufferWrapper* cbwrapper = [mtlc pullCommandBufferWrapper];

id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
[cbwrapper release];
}];

[commandbuf commit];
flushBeforeLCD = JNI_TRUE;
}
void* dstTexture = dstOps->textureLCD;

// LCD-optimized glyph data

0 comments on commit 0e80c21

Please sign in to comment.