1uniform float2x2 testMatrix2x2; 2uniform half4 colorRed, colorGreen; 3uniform half unknownInput; 4 5bool test() { 6 bool ok = true; 7 ok = ok && (float2x2(float2(1.0, 0.0), float2(0.0, 1.0)) == 8 float2x2(float2(1.0, 0.0), float2(0.0, 1.0))); 9 ok = ok && !(float2x2(float2(1.0, 0.0), float2(1.0, 1.0)) == 10 float2x2(float2(1.0, 0.0), float2(0.0, 1.0))); 11 12 ok = ok && ( float2x2(1) == float2x2(1)); 13 ok = ok && !( float2x2(1) == float2x2(0)); 14 ok = ok && ( float2x2(-1) == -float2x2(1)); 15 ok = ok && ( float2x2(0) == -float2x2(0)); 16 ok = ok && (-float2x2(-1) == float2x2(1)); 17 ok = ok && (-float2x2(0) == -float2x2(-0)); 18 19 ok = ok && (float2x2(1) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0))); 20 ok = ok && !(float2x2(2) == float2x2(float2(1.0, 0.0), float2(0.0, 1.0))); 21 22 ok = ok && !(float2x2(1) != float2x2(1)); 23 ok = ok && (float2x2(1) != float2x2(0)); 24 ok = ok && (float3x3(float3(1.0, 0.0, 0.0), float3(0.0, 1.0, 0.0), float3(0.0, 0.0, 1.0)) == 25 float3x3(float2x2(1.0))); 26 ok = ok && (float3x3(float3(9.0, 0.0, 0.0), float3(0.0, 9.0, 0.0), float3(0.0, 0.0, 1.0)) == 27 float3x3(float2x2(9.0))); 28 ok = ok && (float3x3(unknownInput) == float3x3(float2x2(1.0))); 29 ok = ok && (float3x3(float3(9).x00, float3(9).0x0, float3(unknownInput).00x) == 30 float3x3(float2x2(9.0))); 31 ok = ok && (float2x2(float3x3(1.0)) == float2x2(1.0)); 32 ok = ok && (float2x2(float3x3(1.0)) == float2x2(1.0)); 33 ok = ok && (float2x2(float4(1.0, 0.0, 0.0, 1.0)) == float2x2(1.0)); 34 ok = ok && (float2x2(1.0, 0.0, float2(0.0, 1.0)) == float2x2(1.0)); 35 ok = ok && (float2x2(float2(1.0, 0.0), 0.0, 1.0) == float2x2(1.0)); 36 37 ok = ok && (float4(testMatrix2x2) * float4(1)) == float4(1, 2, 3, 4); 38 ok = ok && (float4(testMatrix2x2) * float4(1)) == float4(testMatrix2x2); 39 ok = ok && (float4(testMatrix2x2) * float4(0)) == float4(0); 40 41 ok = ok && (float2x2(5.0)[0] == float2(5.0, 0.0)); 42 ok = ok && (float2x2(5.0)[1] == float2(0.0, 5.0)); 43 44 ok = ok && (float2x2(5.0)[0][0] == 5.0); 45 ok = ok && (float2x2(5.0)[0][1] == 0.0); 46 ok = ok && (float2x2(5.0)[1][0] == 0.0); 47 ok = ok && (float2x2(5.0)[1][1] == 5.0); 48 49 const float3x3 m = float3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); 50 ok = ok && (m[0] == float3(1, 2, 3)); 51 ok = ok && (m[1] == float3(4, 5, 6)); 52 ok = ok && (m[2] == float3(7, 8, 9)); 53 54 ok = ok && (m[0][0] == 1); 55 ok = ok && (m[0][1] == 2); 56 ok = ok && (m[0][2] == 3); 57 ok = ok && (m[1][0] == 4); 58 ok = ok && (m[1][1] == 5); 59 ok = ok && (m[1][2] == 6); 60 ok = ok && (m[2][0] == 7); 61 ok = ok && (m[2][1] == 8); 62 ok = ok && (m[2][2] == 9); 63 64 { 65 // This `five` is constant and should always fold. 66 const float five = 5.0; 67 ok = ok && (float2x2(five)[0] == float2(five, 0.0)); 68 ok = ok && (float2x2(five)[1] == float2(0.0, five)); 69 70 ok = ok && (float2x2(five)[0][0] == five); 71 ok = ok && (float2x2(five)[0][1] == 0.0); 72 ok = ok && (float2x2(five)[1][0] == 0.0); 73 ok = ok && (float2x2(five)[1][1] == five); 74 75 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[0] == float3(1, 2, 3)); 76 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[1] == float3(4, five, 6)); 77 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[2] == float3(7, 8, 9)); 78 } 79 { 80 // This `five` cannot be folded, but the first and third columns should still be foldable. 81 float five = 5.0; 82 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[0] == float3(1, 2, 3)); 83 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[1] == float3(4, five, 6)); 84 ok = ok && (float3x3(1, 2, 3, 4, five, 6, 7, 8, 9)[2] == float3(7, 8, 9)); 85 } 86 { 87 // Side-effecting expressions should never be folded away. 88 float num = 6.0; 89 ok = ok && (float3x3(1, 2, 3, 4, 5, num++, 7, 8, 9)[0] == float3(1, 2, 3)); 90 ok = ok && (float3x3(1, 2, 3, 4, 5, 6, num++, 8, 9)[1] == float3(4, 5, 6)); 91 ok = ok && (float3x3(1, 2, 3, 4, 5, 6, 7, num++, 9)[2] == float3(7, 8, 9)); 92 } 93 { 94 // The upper-left 2x2 of the matrix is unknown, but the bottom two rows are still foldable. 95 ok = ok && float4x4(half3x3(testMatrix2x2))[0] == float4(1, 2, 0, 0); 96 ok = ok && float4x4(half3x3(testMatrix2x2))[1] == float4(3, 4, 0, 0); 97 ok = ok && float4x4(half3x3(testMatrix2x2))[2] == float4(0, 0, 1, 0); 98 ok = ok && float4x4(half3x3(testMatrix2x2))[3] == float4(0, 0, 0, 1); 99 } 100 101 return ok; 102} 103 104half4 main(float2 coords) { 105 return test() ? colorGreen : colorRed; 106} 107