// Check if the matrix 'inverse' operation on 3x3 matrix is constant folded. TEST_F(ConstantFoldingTest, Fold3x3MatrixInverse) { const std::string &shaderString = "#version 300 es\n" "precision mediump float;\n" "in float i;\n" "out vec3 my_Vec;\n" "void main() {\n" " const mat3 m3 = inverse(mat3(11.0f, 13.0f, 19.0f,\n" " 23.0f, 29.0f, 31.0f,\n" " 37.0f, 41.0f, 43.0f));\n" " mat3 m = m3 * mat3(i);\n" " my_Vec = m3[0];\n" "}\n"; compile(shaderString); float inputElements[] = { 11.0f, 13.0f, 19.0f, 23.0f, 29.0f, 31.0f, 37.0f, 41.0f, 43.0f }; std::vector<float> input(inputElements, inputElements + 9); ASSERT_FALSE(constantVectorFoundInAST(input)); float outputElements[] = { 3.0f / 85.0f, -11.0f / 34.0f, 37.0f / 170.0f, -79.0f / 340.0f, 23.0f / 68.0f, -12.0f / 85.0f, 13.0f / 68.0f, -3.0f / 68.0f, -1.0f / 34.0f }; std::vector<float> result(outputElements, outputElements + 9); const float floatFaultTolerance = 0.000001f; ASSERT_TRUE(constantVectorNearFoundInAST(result, floatFaultTolerance)); }
// Check if the matrix 'inverse' operation on 4x4 matrix is constant folded. TEST_F(ConstantFoldingTest, Fold4x4MatrixInverse) { const std::string &shaderString = "#version 300 es\n" "precision mediump float;\n" "out mat4 my_Matrix;" "void main() {\n" " const mat4 m4 = inverse(mat4(29.0f, 31.0f, 37.0f, 41.0f,\n" " 43.0f, 47.0f, 53.0f, 59.0f,\n" " 61.0f, 67.0f, 71.0f, 73.0f,\n" " 79.0f, 83.0f, 89.0f, 97.0f));\n" " my_Matrix = m4;\n" "}\n"; compile(shaderString); float inputElements[] = { 29.0f, 31.0f, 37.0f, 41.0f, 43.0f, 47.0f, 53.0f, 59.0f, 61.0f, 67.0f, 71.0f, 73.0f, 79.0f, 83.0f, 89.0f, 97.0f }; std::vector<float> input(inputElements, inputElements + 16); ASSERT_FALSE(constantVectorFoundInAST(input)); float outputElements[] = { 43.0f / 126.0f, -11.0f / 21.0f, -2.0f / 21.0f, 31.0f / 126.0f, -5.0f / 7.0f, 9.0f / 14.0f, 1.0f / 14.0f, -1.0f / 7.0f, 85.0f / 126.0f, -11.0f / 21.0f, 43.0f / 210.0f, -38.0f / 315.0f, -2.0f / 7.0f, 5.0f / 14.0f, -6.0f / 35.0f, 3.0f / 70.0f }; std::vector<float> result(outputElements, outputElements + 16); const float floatFaultTolerance = 0.00001f; ASSERT_TRUE(constantVectorNearFoundInAST(result, floatFaultTolerance)); }