| uniform float2x2 testMatrix2x2; |
| uniform float3x3 testMatrix3x3; |
| uniform float4 testInputs; |
| uniform half4 colorRed, colorGreen; |
| uniform half unknownInput; |
| |
| bool test_no_op_mat2_X_vec2() { |
| const float2x2 i = float2x2(1.0); |
| const float2x2 z = float2x2(0.0); |
| const float2x2 n = float2x2(-1.0); |
| |
| float2 v, vv; |
| v = testInputs.xy * i; |
| v = i * testInputs.xy; |
| if (v != testInputs.xy) return false; |
| |
| v = v * i; |
| v = i * v; |
| v *= i; |
| if (v != testInputs.xy) return false; |
| |
| v = testInputs.xy * n; |
| v = n * testInputs.xy; |
| if (v != -testInputs.xy) return false; |
| |
| vv = v * z; |
| vv = z * v; |
| return vv == z[0]; |
| } |
| |
| bool test_no_op_mat3_X_vec3() { |
| const float3x3 i = float3x3(1.0); |
| const float3x3 z = float3x3(0.0); |
| const float3x3 n = float3x3(-1.0); |
| |
| float3 v, vv; |
| v = testInputs.xyz * i; |
| v = i * testInputs.xyz; |
| if (v != testInputs.xyz) return false; |
| |
| v = v * i; |
| v = i * v; |
| v *= i; |
| if (v != testInputs.xyz) return false; |
| |
| v = testInputs.xyz * n; |
| v = n * testInputs.xyz; |
| if (v != -testInputs.xyz) return false; |
| |
| vv = v * z; |
| vv = z * v; |
| return vv == z[0]; |
| } |
| |
| bool test_no_op_mat4_X_vec4() { |
| const float4x4 i = float4x4(1.0); |
| const float4x4 z = float4x4(0.0); |
| const float4x4 n = float4x4(-1.0); |
| |
| float4 v, vv; |
| v = testInputs * i; |
| v = i * testInputs; |
| if (v != testInputs) return false; |
| |
| v = v * i; |
| v = i * v; |
| v *= i; |
| if (v != testInputs) return false; |
| |
| v = testInputs * n; |
| v = n * testInputs; |
| if (v != -testInputs) return false; |
| |
| vv = v * z; |
| vv = z * v; |
| return vv == z[0]; |
| } |
| |
| bool test_no_op_vec2_X_mat2() { |
| const float2 n = float2(-1.0); |
| const float2 i = float2(1.0); |
| const float2 z = float2(0.0); |
| |
| // These operations can be optimized; multiplying a zero vector across any matrix always results |
| // in a zero vector. |
| float2 v, vv; |
| vv = z * testMatrix2x2; |
| vv = testMatrix2x2 * z; |
| if (vv != z) return false; |
| |
| // These operations can't be simplified; they do real work. |
| v = i * testMatrix2x2; |
| if (v != float2(3, 7)) return false; |
| v = testMatrix2x2 * i; |
| if (v != float2(4, 6)) return false; |
| |
| v = n * testMatrix2x2; |
| if (v != -float2(3, 7)) return false; |
| v = testMatrix2x2 * n; |
| return v == -float2(4, 6); |
| } |
| |
| bool test_no_op_vec3_X_mat3() { |
| const float3 n = float3(-1.0); |
| const float3 i = float3(1.0); |
| const float3 z = float3(0.0); |
| |
| // These operations can be optimized; multiplying a zero vector across any matrix always results |
| // in a zero vector. |
| float3 v, vv; |
| vv = z * testMatrix3x3; |
| vv = testMatrix3x3 * z; |
| if (vv != z) return false; |
| |
| // These operations can't be simplified; they do real work. |
| v = i * testMatrix3x3; |
| if (v != float3(6, 15, 24)) return false; |
| v = testMatrix3x3 * i; |
| if (v != float3(12, 15, 18)) return false; |
| |
| v = n * testMatrix3x3; |
| if (v != -float3(6, 15, 24)) return false; |
| v = testMatrix3x3 * n; |
| return v == -float3(12, 15, 18); |
| } |
| |
| bool test_no_op_vec4_X_mat4() { |
| const float4 n = float4(-1.0); |
| const float4 i = float4(1.0); |
| const float4 z = float4(0.0); |
| float4x4 testMatrix4x4 = float4x4(testMatrix2x2[0], testMatrix2x2[1], |
| testMatrix2x2[0], testMatrix2x2[1], |
| testMatrix2x2[0], testMatrix2x2[1], |
| testMatrix2x2[0], testMatrix2x2[1]); |
| |
| // These operations can be optimized; multiplying a zero vector across any matrix always results |
| // in a zero vector. |
| float4 v, vv; |
| vv = z * testMatrix4x4; |
| vv = testMatrix4x4 * z; |
| if (vv != z) return false; |
| |
| // These operations can't be simplified; they do real work. |
| v = i * testMatrix4x4; |
| if (v != float4(10, 10, 10, 10)) return false; |
| v = testMatrix4x4 * i; |
| if (v != float4(4, 8, 12, 16)) return false; |
| |
| v = n * testMatrix4x4; |
| if (v != -float4(10, 10, 10, 10)) return false; |
| v = testMatrix4x4 * n; |
| return v == -float4(4, 8, 12, 16); |
| } |
| |
| half4 main(float2 coords) { |
| return test_no_op_mat2_X_vec2() && |
| test_no_op_mat3_X_vec3() && |
| test_no_op_mat4_X_vec4() && |
| test_no_op_vec2_X_mat2() && |
| test_no_op_vec3_X_mat3() && |
| test_no_op_vec4_X_mat4() ? colorGreen : colorRed; |
| } |