From b809efbbfae3efc1f5940a34f36cb07bf46166c5 Mon Sep 17 00:00:00 2001 From: Ethan Nicholas Date: Thu, 12 Apr 2018 14:39:21 -0400 Subject: [PATCH] workaround for buggy macOS GLSL shader compiler Bug: skia: Change-Id: Ib77e11d80f93f76e65eac6119dbf2bd03523aaf9 Reviewed-on: https://skia-review.googlesource.com/117626 Reviewed-by: Ethan Nicholas Commit-Queue: Ethan Nicholas --- src/sksl/SkSLIRGenerator.cpp | 19 +++++++++---------- tests/SkSLGLSLTest.cpp | 21 ++++++++------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 56d8e5e952..a0de551bb3 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -613,8 +613,7 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< } std::unique_ptr IRGenerator::getNormalizeSkPositionCode() { - // sk_Position = float4(sk_Position.x * rtAdjust.x + sk_Position.w * rtAdjust.y, - // sk_Position.y * rtAdjust.z + sk_Position.w * rtAdjust.w, + // sk_Position = float4(sk_Position.xy * rtAdjust.xz + sk_Position.ww * rtAdjust.yw, // 0, // sk_Position.w); ASSERT(fSkPerVertex && fRTAdjust); @@ -627,16 +626,15 @@ std::unique_ptr IRGenerator::getNormalizeSkPositionCode() { #define ADJUST (fRTAdjustInterfaceBlock ? \ FIELD(fRTAdjustInterfaceBlock, fRTAdjustFieldIndex) : \ REF(fRTAdjust)) - #define SWIZZLE(expr, field) std::unique_ptr(new Swizzle(fContext, expr, { field })) - #define OP(left, op, right) std::unique_ptr(\ - new BinaryExpression(-1, left, op, right, *fContext.fFloat_Type)) + #define SWIZZLE(expr, ...) std::unique_ptr(new Swizzle(fContext, expr, \ + { __VA_ARGS__ })) + #define OP(left, op, right) std::unique_ptr( \ + new BinaryExpression(-1, left, op, right, \ + *fContext.fFloat2_Type)) std::vector> children; - children.push_back(OP(OP(SWIZZLE(POS, 0), Token::STAR, SWIZZLE(ADJUST, 0)), + children.push_back(OP(OP(SWIZZLE(POS, 0, 1), Token::STAR, SWIZZLE(ADJUST, 0, 2)), Token::PLUS, - OP(SWIZZLE(POS, 3), Token::STAR, SWIZZLE(ADJUST, 1)))); - children.push_back(OP(OP(SWIZZLE(POS, 1), Token::STAR, SWIZZLE(ADJUST, 2)), - Token::PLUS, - OP(SWIZZLE(POS, 3), Token::STAR, SWIZZLE(ADJUST, 3)))); + OP(SWIZZLE(POS, 3, 3), Token::STAR, SWIZZLE(ADJUST, 1, 3)))); children.push_back(std::unique_ptr(new FloatLiteral(fContext, -1, 0.0))); children.push_back(SWIZZLE(POS, 3)); std::unique_ptr result = OP(POS, Token::EQ, @@ -646,6 +644,7 @@ std::unique_ptr IRGenerator::getNormalizeSkPositionCode() { return std::unique_ptr(new ExpressionStatement(std::move(result))); } + void IRGenerator::convertFunction(const ASTFunction& f) { const Type* returnType = this->convertType(*f.fReturnType); if (!returnType) { diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 0b9ed35006..fe30ef49fd 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1136,9 +1136,8 @@ DEF_TEST(SkSLFragCoord, r) { "in vec4 pos;\n" "void main() {\n" " sk_FragCoord_Workaround = (gl_Position = pos);\n" - " gl_Position = vec4(gl_Position.x * sk_RTAdjust.x + gl_Position.w * sk_RTAdjust.y, " - "gl_Position.y * sk_RTAdjust.z + gl_Position.w * sk_RTAdjust.w, 0.0, " - "gl_Position.w);\n" + " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * sk_RTAdjust.yw," + " 0.0, gl_Position.w);\n" "}\n", SkSL::Program::kVertex_Kind); @@ -1818,10 +1817,8 @@ DEF_TEST(SkSLNormalization, r) { "uniform vec4 sk_RTAdjust;\n" "void main() {\n" " gl_Position = vec4(1.0);\n" - " gl_Position = vec4(gl_Position.x * sk_RTAdjust.x + gl_Position.w * sk_RTAdjust.y, " - "gl_Position.y * sk_RTAdjust.z + gl_Position.w * sk_RTAdjust.w, " - "0.0, " - "gl_Position.w);\n" + " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " + "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" "}\n", SkSL::Program::kVertex_Kind); test(r, @@ -1845,16 +1842,14 @@ DEF_TEST(SkSLNormalization, r) { "void main() {\n" " gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(gl_InvocationID));\n" " {\n" - " gl_Position = vec4(gl_Position.x * sk_RTAdjust.x + gl_Position.w * " - "sk_RTAdjust.y, gl_Position.y * sk_RTAdjust.z + gl_Position.w * " - "sk_RTAdjust.w, 0.0, gl_Position.w);\n" + " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " + "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" " EmitVertex();\n" " }\n" " gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(gl_InvocationID));\n" " {\n" - " gl_Position = vec4(gl_Position.x * sk_RTAdjust.x + gl_Position.w * " - "sk_RTAdjust.y, gl_Position.y * sk_RTAdjust.z + gl_Position.w * " - "sk_RTAdjust.w, 0.0, gl_Position.w);\n" + " gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * " + "sk_RTAdjust.yw, 0.0, gl_Position.w);\n" " EmitVertex();\n" " }\n" " EndPrimitive();\n"