1uniform half4 colorGreen, colorRed; 2 3// These tests verify that constructor expressions with side-effects do not get folded away. 4 5bool test_vector() { 6 bool ok = true; 7 8 float num = 0.0; 9 ok = ok && float2(++num, 0).y == 0.0; // num => 1 10 ok = ok && float2(0, ++num).x == 0.0; // num => 2 11 12 ok = ok && float3(++num, float2(1, 0)).yz == float2(1, 0); // num => 3 13 ok = ok && float3(float2(1, 0), ++num).xy == float2(1, 0); // num => 4 14 ok = ok && float3(float2(++num, 1), 0).yz == float2(1, 0); // num => 5 15 16 ok = ok && float4(++num, float3(1, 0, 0)).yzw == float3(1, 0, 0); // num => 6 17 ok = ok && float4(1, ++num, float2(1, 0)).x == 1.0; // num => 7 18 ok = ok && float4(float2(1, 0), ++num, 1).w == 1.0; // num => 8 19 ok = ok && float4(float2(1, 0), float2(1, ++num)).xyz == float3(1, 0, 1); // num => 9 20 21 return ok && num == 9.0; 22} 23 24bool test_matrix() { 25 bool ok = true; 26 27 float num = 0.0; 28 ok = ok && float2x2(1, 2, 3, ++num)[0] == float2(1, 2); // num => 1 29 ok = ok && float2x2(float2(++num), 3, 4)[1] == float2(3, 4); // num => 2 30 31 ok = ok && float3x3(float3(1), float3(++num), float3(0))[0] == float3(1); // num => 3 32 ok = ok && float3x3(float3(1), float3(++num), float3(0))[2] == float3(0); // num => 4 33 ok = ok && float3x3(float3(++num), float3(1), float3(0))[1] == float3(1); // num => 5 34 35 ok = ok && float3x3(1, 2, 3, 4, 5, ++num, 7, 8, 9)[0] == float3(1, 2, 3); // num => 6 36 ok = ok && float3x3(1, 2, 3, 4, 5, 6, num++, 8, 9)[1] == float3(4, 5, 6); // num => 7 37 38 // num => 8 39 ok = ok && float4x4(float4(++num), float4(1), float4(2), float4(3))[1] == float4(1); 40 // num => 9 41 ok = ok && float4x4(float4(1), float4(++num), float4(2), float4(3))[2] == float4(2); 42 // num => 10 43 ok = ok && float4x4(float4(1), float4(1), float4(++num), float4(3))[3] == float4(3); 44 45 ok = ok && float4x4(1, 2, 3, 4, 46 5, 6, 7, 8, 47 9, 10, 11, 12, 48 13, 14, ++num, 16)[3].xy == float2(13, 14); // num => 11 49 50 return ok && num == 11.0; 51} 52 53half4 main(float2 coords) { 54 return test_vector() && test_matrix() ? colorGreen : colorRed; 55} 56