1uniform half4 colorRed, colorGreen; 2 3bool test_matrix_op_matrix_float() { 4 bool ok = true; 5 6 // Addition, subtraction and division operate componentwise. 7 { 8 const float3x2 splat_4 = float3x2(4, 4, 4, 4, 4, 4); 9 float3x2 m; 10 11 m = float3x2(2); m += splat_4; ok = ok && (m == float3x2(6, 4, 4, 6, 4, 4)); 12 m = float3x2(2); m -= splat_4; ok = ok && (m == float3x2(-2, -4, -4, -2, -4, -4)); 13 m = float3x2(2); m /= splat_4; ok = ok && (m == float3x2(0.5)); 14 } 15 { 16 const float2x3 splat_4 = float2x3(4, 4, 4, 4, 4, 4); 17 float2x3 m; 18 19 m = splat_4; m += float2x3(2); ok = ok && (m == float2x3(6, 4, 4, 4, 6, 4)); 20 m = splat_4; m -= float2x3(2); ok = ok && (m == float2x3(2, 4, 4, 4, 2, 4)); 21 m = splat_4; m /= float2x3(2,2,2,2,2,2); ok = ok && (m == float2x3(2, 2, 2, 2, 2, 2)); 22 } 23 { 24 float4x3 m = float4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); 25 m += float4x3(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5); 26 ok = ok && (m == float4x3(17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17)); 27 } 28 { 29 float4x2 m = float4x2(10, 20, 30, 40, 50, 60, 70, 80); 30 m -= float4x2(1, 2, 3, 4, 5, 6, 7, 8); 31 ok = ok && (m == float4x2(9, 18, 27, 36, 45, 54, 63, 72)); 32 } 33 { 34 float2x4 m = float2x4(10, 20, 30, 40, 10, 20, 30, 40); 35 m /= float2x4(10, 10, 10, 10, 5, 5, 5, 5); 36 ok = ok && (m == float2x4(1, 2, 3, 4, 2, 4, 6, 8)); 37 } 38 { 39 // Multiplication performs a proper matrix multiply. 40 float2x3 m = float2x3(7, 9, 11, 8, 10, 12); 41 m *= float2x2(1, 4, 2, 5); 42 ok = ok && (m == float2x3(39, 49, 59, 54, 68, 82)); 43 } 44 return ok; 45} 46 47bool test_matrix_op_matrix_half() { 48 bool ok = true; 49 50 // Addition, subtraction and division operate componentwise. 51 { 52 const half3x2 splat_4 = half3x2(4, 4, 4, 4, 4, 4); 53 half3x2 m; 54 55 m = half3x2(2); m += splat_4; ok = ok && (m == half3x2(6, 4, 4, 6, 4, 4)); 56 m = half3x2(2); m -= splat_4; ok = ok && (m == half3x2(-2, -4, -4, -2, -4, -4)); 57 m = half3x2(2); m /= splat_4; ok = ok && (m == half3x2(0.5)); 58 } 59 { 60 const half2x3 splat_4 = half2x3(4, 4, 4, 4, 4, 4); 61 half2x3 m; 62 63 m = splat_4; m += half2x3(2); ok = ok && (m == half2x3(6, 4, 4, 4, 6, 4)); 64 m = splat_4; m -= half2x3(2); ok = ok && (m == half2x3(2, 4, 4, 4, 2, 4)); 65 m = splat_4; m /= half2x3(2,2,2,2,2,2); ok = ok && (m == half2x3(2, 2, 2, 2, 2, 2)); 66 } 67 { 68 half4x3 m = half4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); 69 m += half4x3(16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5); 70 ok = ok && (m == half4x3(17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17)); 71 } 72 { 73 half4x2 m = half4x2(10, 20, 30, 40, 50, 60, 70, 80); 74 m -= half4x2(1, 2, 3, 4, 5, 6, 7, 8); 75 ok = ok && (m == half4x2(9, 18, 27, 36, 45, 54, 63, 72)); 76 } 77 { 78 half2x4 m = half2x4(10, 20, 30, 40, 10, 20, 30, 40); 79 m /= half2x4(10, 10, 10, 10, 5, 5, 5, 5); 80 ok = ok && (m == half2x4(1, 2, 3, 4, 2, 4, 6, 8)); 81 } 82 { 83 // Multiplication performs a proper matrix multiply. 84 half2x3 m = half2x3(7, 9, 11, 8, 10, 12); 85 m *= half2x2(1, 4, 2, 5); 86 ok = ok && (m == half2x3(39, 49, 59, 54, 68, 82)); 87 } 88 return ok; 89} 90 91half4 main(float2 coords) { 92 return (test_matrix_op_matrix_float() && 93 test_matrix_op_matrix_half()) ? colorGreen : colorRed; 94} 95