1uniform half4 colorGreen; 2uniform half unknownInput; 3uniform half2x2 testMatrix2x2; 4 5struct S { 6 half4 ah4[1]; 7 half ah[1]; 8 half4 h4; 9 half h; 10}; 11 12struct S4 { 13 half a, b, c, d; 14}; 15 16struct S5 { 17 half a, b, c, d, e; 18}; 19 20// Each helper function needs to reference the variable multiple times, because if it's only read 21// from once, it is inlined directly whether or not it is trivial. 22half4 funcb(bool b) { 23 return half4(b, b, b, !b); 24} 25 26half4 func1(half h) { 27 return h.xxxx * h.xxxx; 28} 29 30half4 func2(half2 h2) { 31 return h2.xyxy * h2.yxyx; 32} 33 34half4 func3(half3 h3) { 35 return h3.xyzx * h3.xyzx; 36} 37 38half4 func4(half4 h4) { 39 return h4 * h4; 40} 41 42half2x2 func2x2(half2x2 m) { 43 return m * m[0][0]; 44} 45 46half4 funcS4(S4 s) { 47 return half4(s.a, s.b, s.c, 1) * s.d; 48} 49 50half4 funcS5(S5 s) { 51 return half4(s.a, s.b, s.c, s.d) * s.e; 52} 53 54noinline void keepAlive(inout half f) {} 55 56half4 main(float2 coords) { 57 S s; 58 s.ah4[0] = half4(unknownInput); 59 s.ah[0] = unknownInput; 60 s.h4 = half4(unknownInput); 61 s.h = unknownInput; 62 63 S as[1]; 64 as[0].ah4[0] = half4(unknownInput); 65 66 bool b = bool(unknownInput); 67 int i = int(unknownInput); 68 int4 i4 = i.xxxx; 69 70 // These expressions are considered "trivial" and will be cloned directly into the inlined 71 // function without a temporary variable. 72 half4 var; 73 half2x2 mat; 74 var = func1(+s.h); // field access (unary + is optimized away) 75 var = funcb(b); // variable reference 76 var = func2(s.ah4[0].yw); // var, field access, array index, swizzle 77 var = func2(as[0].ah4[0].xy); // var, array index, field access, array index, swizzle 78 var = func3(s.h4.zzz); // var, field access, swizzle 79 var = func3(colorGreen.xyz); // var, swizzle 80 var = func3(s.h.xxx); // var, field access, splat ctor (from scalar swizzle) 81 var = func4(half4(s.h)); // var, splat, field access 82 var = func4(s.ah4[0].xxxy); // var, field access, array index, swizzle 83 var = func4(colorGreen); // variable reference 84 var = func4(half4(1, 2, 3, 4)); // compound ctor, compile-time constant 85 var = func1(half(i)); // scalar-cast ctor, variable 86 var = func4(half4(i4)); // compound-cast ctor, variable 87 var = funcS4(S4(1, 2, 3, 4)); // struct with slotCount <= 4 88 mat = func2x2(half2x2(unknownInput)); // diagonal matrix, variable reference 89 90 // These expressions are considered "non-trivial" and will be placed in a temporary variable 91 // when inlining occurs. 92 var = func4(half4(testMatrix2x2)); // compound ctor, not compile-time constant 93 mat = func2x2(half2x2(colorGreen)); // compound ctor, not compile-time constant 94 mat = func2x2(half2x2(half3x3(unknownInput))); // matrix resize, diagonal matrix, var 95 var = func4(half4(1, 2, 3, unknownInput)); // compound ctor, not compile-time constant 96 var = funcS5(S5(1, 2, 3, 4, 5)); // struct with slotCount > 4 97 var = func1(-s.h); // unary minus, var, field access 98 var = funcb(!b); // prefix expression, var 99// var = func2(as[i].h4.yw); // (non-constant array index disallowed in ES2) 100 var = func3(s.h4.yyy + s.h4.zzz); // binary expression 101 var = func4(s.h4.y001); // compound ctor, not compile-time constant 102 103 keepAlive(var[0]); 104 keepAlive(mat[0][0]); 105 106 return colorGreen; 107} 108