From a3d1fb73f957b290bf80009a6b68ecee6f94347e Mon Sep 17 00:00:00 2001 From: Alexander Galazin Date: Tue, 22 Aug 2017 15:59:49 +0200 Subject: [PATCH] Add more allowed 'dot' alternatives Expanded dot may be re-associated in multiple ways. Add all possible alternatives to prevent precision failures. Components: AOSP VK-GL-CTS issue: 634 Google issue: 28767510 Affects: dEQP-GLES3.functional.shaders.builtin_functions.precision.dot.* dEQP-GLES3.functional.shaders.builtin_functions.precision.reflect.* dEQP-GLES31.functional.shaders.builtin_functions.precision.dot.* dEQP-GLES31.functional.shaders.builtin_functions.precision.reflect.* Change-Id: I2a91add1b92363acab2172179320cd880da779ec (cherry picked from commit e00e942ef2600253cf9ae16815922fa6617d68bf) --- modules/glshared/glsBuiltinPrecisionTests.cpp | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/glshared/glsBuiltinPrecisionTests.cpp b/modules/glshared/glsBuiltinPrecisionTests.cpp index da69f89..afe990b 100644 --- a/modules/glshared/glsBuiltinPrecisionTests.cpp +++ b/modules/glshared/glsBuiltinPrecisionTests.cpp @@ -2924,12 +2924,32 @@ public: protected: ExprP doExpand (ExpandContext&, const ArgExprs& args) const { - ExprP val = args.a[0] * args.b[0]; + ExprP op[Size]; + // Precompute all products. + for (int ndx = 0; ndx < Size; ++ndx) + op[ndx] = args.a[ndx] * args.b[ndx]; - for (int ndx = 1; ndx < Size; ++ndx) - val = val + args.a[ndx] * args.b[ndx]; + int idx[Size]; + //Prepare an array of indices. + for (int ndx = 0; ndx < Size; ++ndx) + idx[ndx] = ndx; - return val; + ExprP res = op[0]; + // Compute the first dot alternative: SUM(a[i]*b[i]), i = 0 .. Size-1 + for (int ndx = 1; ndx < Size; ++ndx) + res = res + op[ndx]; + + // Generate all permutations of indices and + // using a permutation compute a dot alternative. + // Generates all possible variants fo summation of products in the dot product expansion expression. + do { + ExprP alt = constant(0.0f); + for (int ndx = 0; ndx < Size; ++ndx) + alt = alt + op[idx[ndx]]; + res = alternatives(res, alt); + } while (std::next_permutation(idx, idx + Size)); + + return res; } }; -- 2.7.4