Add caps bit for 2x2 matrix comparison rewrites.

This will allow us to rewrite `mat == mat` on Adreno 5xx/6xx GPUs when
running in GLSL.

Change-Id: I621e918a545a49b7ecb9c944ae59b1e7a7594bae
Bug: skia:11308
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/410996
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-05-20 18:00:39 -04:00 committed by Skia Commit-Bot
parent 77a5bc3212
commit 36c5796f0b
9 changed files with 83 additions and 0 deletions

View File

@ -564,6 +564,7 @@ sksl_settings_tests = [
"/sksl/workarounds/NegatedAtan.sksl",
"/sksl/workarounds/PowWithConstantExponent.sksl",
"/sksl/workarounds/RewriteDoWhileLoops.sksl",
"/sksl/workarounds/RewriteMatrix2x2Comparisons.sksl",
"/sksl/workarounds/RewriteMatrixVectorMultiply.sksl",
"/sksl/workarounds/TernaryShortCircuit.sksl",
]

View File

@ -0,0 +1,19 @@
/*#pragma settings RewriteMatrix2x2Comparisons*/
// This is a clone of MatrixEquality.sksl.
uniform half4 colorGreen, colorRed;
uniform half2x2 testHalf2x2;
uniform float2x2 testFloat2x2;
bool test_equality() {
bool ok = true;
ok = ok && testHalf2x2 == half2x2(1,2,3,4);
ok = ok && testFloat2x2 == half2x2(5,6,7,8);
ok = ok && testHalf2x2 != half2x2(123);
ok = ok && testFloat2x2 != half2x2(456);
return ok;
}
half4 main(float2 coords) {
return test_equality() ? colorGreen : colorRed;
}

View File

@ -45,6 +45,7 @@ GrShaderCaps::GrShaderCaps(const GrContextOptions& options) {
fMustWriteToFragColor = false;
fNoDefaultPrecisionForExternalSamplers = false;
fRewriteMatrixVectorMultiply = false;
fRewriteMatrix2x2Comparisons = false;
fFlatInterpolationSupport = false;
fPreferFlatInterpolation = false;
fNoPerspectiveInterpolationSupport = false;
@ -129,6 +130,7 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
writer->appendBool("Don't add default precision statement for samplerExternalOES",
fNoDefaultPrecisionForExternalSamplers);
writer->appendBool("Rewrite matrix-vector multiply", fRewriteMatrixVectorMultiply);
writer->appendBool("Rewrite matrix 2x2 equality comparisons", fRewriteMatrix2x2Comparisons);
writer->appendBool("Flat interpolation support", fFlatInterpolationSupport);
writer->appendBool("Prefer flat interpolation", fPreferFlatInterpolation);
writer->appendBool("No perspective interpolation support", fNoPerspectiveInterpolationSupport);
@ -178,6 +180,7 @@ void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
SkASSERT(!fMustWriteToFragColor);
SkASSERT(!fNoDefaultPrecisionForExternalSamplers);
SkASSERT(!fRewriteMatrixVectorMultiply);
SkASSERT(!fRewriteMatrix2x2Comparisons);
}
if (!options.fEnableExperimentalHardwareTessellation) {
fMaxTessellationSegments = 0;

View File

@ -176,6 +176,9 @@ public:
return fRewriteMatrixVectorMultiply;
}
// Rewrites 2x2 matrix equality comparisons to avoid an Adreno driver bug. (skia:11308)
bool rewriteMatrix2x2Comparisons() const { return fRewriteMatrix2x2Comparisons; }
// ANGLE disallows do loops altogether, and we're seeing crashes on Tegra3 with do loops in at
// least some cases.
bool canUseDoLoops() const { return fCanUseDoLoops; }
@ -320,6 +323,7 @@ private:
bool fMustWriteToFragColor : 1;
bool fNoDefaultPrecisionForExternalSamplers : 1;
bool fRewriteMatrixVectorMultiply : 1;
bool fRewriteMatrix2x2Comparisons : 1;
bool fColorSpaceMathNeedsFloat : 1;
bool fCanUseDoLoops : 1;
bool fCanUseFastMath : 1;

View File

@ -3812,6 +3812,17 @@ void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
shaderCaps->fInBlendModesFailRandomlyForAllZeroVec = true;
}
// The Adreno 5xx and 6xx produce incorrect results when comparing a pair of 2x2 matrices.
if (ctxInfo.renderer() == GrGLRenderer::kAdreno530 ||
ctxInfo.renderer() == GrGLRenderer::kAdreno5xx_other ||
ctxInfo.renderer() == GrGLRenderer::kAdreno615 ||
ctxInfo.renderer() == GrGLRenderer::kAdreno620 ||
ctxInfo.renderer() == GrGLRenderer::kAdreno630 ||
ctxInfo.renderer() == GrGLRenderer::kAdreno640 ||
ctxInfo.renderer() == GrGLRenderer::kAdreno6xx_other) {
shaderCaps->fRewriteMatrix2x2Comparisons = true;
}
// We've seen Adreno 3xx devices produce incorrect (flipped) values for gl_FragCoord, in some
// (rare) situations. It's sporadic, and mostly on older drivers. Additionally, old Adreno
// compilers (see crbug.com/skia/4078) crash when accessing .zw of gl_FragCoord, so just bypass

View File

@ -188,6 +188,10 @@ static bool detect_shader_settings(const SkSL::String& text,
static auto s_rewriteMatVecMulCaps = Factory::RewriteMatrixVectorMultiply();
*caps = s_rewriteMatVecMulCaps.get();
}
if (settingsText.consumeSuffix(" RewriteMatrix2x2Comparisons")) {
static auto s_rewriteMat2x2Eq = Factory::RewriteMatrix2x2Comparisons();
*caps = s_rewriteMat2x2Eq.get();
}
if (settingsText.consumeSuffix(" ShaderDerivativeExtensionString")) {
static auto s_derivativeCaps = Factory::ShaderDerivativeExtensionString();
*caps = s_derivativeCaps.get();

View File

@ -282,6 +282,10 @@ public:
return fRewriteMatrixVectorMultiply;
}
bool fRewriteMatrix2x2Comparisons = false;
bool rewriteMatrix2x2Comparisons() const {
return fRewriteMatrix2x2Comparisons;
}
};
using ShaderCapsClass = StandaloneShaderCaps;
@ -435,6 +439,13 @@ public:
return result;
}
static ShaderCapsPointer RewriteMatrix2x2Comparisons() {
ShaderCapsPointer result = MakeShaderCaps();
result->fRewriteMatrix2x2Comparisons = true;
result->fUsesPrecisionModifiers = true;
return result;
}
static ShaderCapsPointer RewriteMatrixVectorMultiply() {
ShaderCapsPointer result = MakeShaderCaps();
result->fVersionDeclString = "#version 400";

View File

@ -0,0 +1,16 @@
precision mediump float;
precision mediump sampler2D;
out mediump vec4 sk_FragColor;
uniform mediump vec4 colorGreen;
uniform mediump vec4 colorRed;
uniform mediump mat2 testHalf2x2;
uniform highp mat2 testFloat2x2;
mediump vec4 main() {
bool _0_ok = true;
_0_ok = _0_ok && testHalf2x2 == mat2(1.0, 2.0, 3.0, 4.0);
_0_ok = _0_ok && testFloat2x2 == mat2(5.0, 6.0, 7.0, 8.0);
_0_ok = _0_ok && testHalf2x2 != mat2(123.0);
_0_ok = _0_ok && testFloat2x2 != mat2(456.0);
return _0_ok ? colorGreen : colorRed;
}

View File

@ -0,0 +1,14 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
uniform mat2 testHalf2x2;
uniform mat2 testFloat2x2;
vec4 main() {
bool _0_ok = true;
_0_ok = _0_ok && testHalf2x2 == mat2(1.0, 2.0, 3.0, 4.0);
_0_ok = _0_ok && testFloat2x2 == mat2(5.0, 6.0, 7.0, 8.0);
_0_ok = _0_ok && testHalf2x2 != mat2(123.0);
_0_ok = _0_ok && testFloat2x2 != mat2(456.0);
return _0_ok ? colorGreen : colorRed;
}