diff options
author | Brian Salomon <bsalomon@google.com> | 2018-01-22 08:43:38 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-22 14:14:18 +0000 |
commit | dba65f95e40fb1a4ea936b453b9bcb3fdbe178e1 (patch) | |
tree | 307b8b391870d8891e523fc3879c6787da5e8146 /src/sksl | |
parent | 5081eede67601e5c5c0fc343b787490603e058cc (diff) |
Add a workaround for inaccurate interpolants on Adreno 3xx.
Also ensure that sk_FragCoord x and y values are at pixel centers when
workaround is used.
Change-Id: Ib748af9e496a406a50622e00e96e1346cbb5eb26
Reviewed-on: https://skia-review.googlesource.com/97064
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.cpp | 15 | ||||
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.h | 1 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index f3400c7f5a..d02948f388 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -598,8 +598,19 @@ void GLSLCodeGenerator::writeConstructor(const Constructor& c, Precedence parent void GLSLCodeGenerator::writeFragCoord() { if (!fProgram.fSettings.fCaps->canUseFragCoord()) { - this->write("vec4(sk_FragCoord_Workaround.xyz / sk_FragCoord_Workaround.w, " - "1.0 / sk_FragCoord_Workaround.w)"); + if (!fSetupFragCoordWorkaround) { + const char* precision = usesPrecisionModifiers() ? "highp " : ""; + fFunctionHeader += precision; + fFunctionHeader += " float sk_FragCoord_InvW = 1. / sk_FragCoord_Workaround.w;\n"; + fFunctionHeader += precision; + fFunctionHeader += " vec4 sk_FragCoord_Resolved = " + "vec4(sk_FragCoord_Workaround.xyz * sk_FragCoord_InvW, sk_FragCoord_InvW);\n"; + // Ensure that we get exact .5 values for x and y. + fFunctionHeader += " sk_FragCoord_Resolved.xy = floor(sk_FragCoord_Resolved.xy) + " + "vec2(.5);\n"; + fSetupFragCoordWorkaround = true; + } + this->write("sk_FragCoord_Resolved"); return; } diff --git a/src/sksl/SkSLGLSLCodeGenerator.h b/src/sksl/SkSLGLSLCodeGenerator.h index 70ce920900..2b308e3702 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.h +++ b/src/sksl/SkSLGLSLCodeGenerator.h @@ -212,6 +212,7 @@ protected: bool fFoundGSInvocations = false; bool fSetupFragPositionGlobal = false; bool fSetupFragPositionLocal = false; + bool fSetupFragCoordWorkaround = false; typedef CodeGenerator INHERITED; }; |