1# https://github.com/KhronosGroup/WebGL/blob/master/sdk/tests/conformance2/glsl3/vector-dynamic-indexing.html 2group moredynamic "More dynamic indexing tests" 3 4 case matrix_twice 5 version 300 es 6 values { output float f = 1.0; } 7 both "" 8 #version 300 es 9 precision mediump float; 10 ${DECLARATIONS} 11 12 uniform int u_zero; 13 void main() { 14 mat2 m = mat2(0.0, 0.0, 0.0, 1.0); 15 f = m[u_zero + 1][u_zero + 1]; 16 ${OUTPUT} 17 } 18 "" 19 end 20 21 case with_value_from_indexing_expression 22 version 300 es 23 values { output float f = 1.0; } 24 both "" 25 #version 300 es 26 precision mediump float; 27 ${DECLARATIONS} 28 29 uniform int u_zero; 30 void main() { 31 ivec2 i = ivec2(0, 2); 32 vec4 v = vec4(0.0, 0.2, 1.0, 0.4); 33 f = v[i[u_zero + 1]]; 34 ${OUTPUT} 35 } 36 "" 37 end 38 39 case lvalue 40 version 300 es 41 values { output float f = 1.0; } 42 both "" 43 #version 300 es 44 precision mediump float; 45 ${DECLARATIONS} 46 47 uniform int u_zero; 48 void main() { 49 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 50 v[u_zero + 1] = 5.0; 51 vec4 expected = vec4(1.0, 5.0, 3.0, 4.0); 52 f = 1.0 - distance(v, expected); 53 ${OUTPUT} 54 } 55 "" 56 end 57 58 case lvalue_with_value_from_indexing_expression 59 version 300 es 60 values { output float f = 1.0; } 61 both "" 62 #version 300 es 63 precision mediump float; 64 ${DECLARATIONS} 65 66 uniform int u_zero; 67 void main() { 68 ivec2 i = ivec2(0, 2); 69 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 70 v[i[u_zero + 1]] = 5.0; 71 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0); 72 f = 1.0 - distance(v, expected); 73 ${OUTPUT} 74 } 75 "" 76 end 77 78 case builtin_fncall_out_parameter 79 version 300 es 80 values { output float f = 1.0; } 81 both "" 82 #version 300 es 83 precision mediump float; 84 ${DECLARATIONS} 85 86 uniform int u_zero; 87 void main() { 88 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 89 modf(5.5, v[u_zero + 3]); 90 vec4 expected = vec4(1.0, 2.0, 3.0, 5.0); 91 f = 1.0 - distance(v, expected); 92 ${OUTPUT} 93 } 94 "" 95 end 96 97 case user_defined_fncall_out_parameter 98 version 300 es 99 values { output float f = 1.0; } 100 both "" 101 #version 300 es 102 precision mediump float; 103 ${DECLARATIONS} 104 105 uniform int u_zero; 106 void foo(out float f) { 107 modf(5.5, f); 108 } 109 void main() { 110 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 111 foo(v[u_zero + 3]); 112 vec4 expected = vec4(1.0, 2.0, 3.0, 5.0); 113 f = 1.0 - distance(v, expected); 114 ${OUTPUT} 115 } 116 "" 117 end 118 119 case user_defined_fncall_inout_parameter 120 version 300 es 121 values { output float f = 1.0; } 122 both "" 123 #version 300 es 124 precision mediump float; 125 ${DECLARATIONS} 126 127 uniform int u_zero; 128 void foo(inout float f) { 129 float g = f + 2.5; 130 modf(g, f); 131 } 132 void main() { 133 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 134 foo(v[u_zero + 2]); 135 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0); 136 f = 1.0 - distance(v, expected); 137 ${OUTPUT} 138 } 139 "" 140 end 141 142 case with_side_effects 143 version 300 es 144 values { output float f = 1.0; } 145 both "" 146 #version 300 es 147 precision mediump float; 148 ${DECLARATIONS} 149 150 uniform int u_zero; 151 int sideEffectCounter = 0; 152 int funcWithSideEffects() { 153 sideEffectCounter++; 154 return 2; 155 } 156 void main() { 157 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 158 v[funcWithSideEffects()] = 5.0; 159 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0); 160 f = 1.0 - distance(v, expected); 161 if (sideEffectCounter != 1) { 162 f = 0.0; 163 } 164 ${OUTPUT} 165 } 166 "" 167 end 168 169 case inout_with_side_effects 170 version 300 es 171 values { output float f = 1.0; } 172 both "" 173 #version 300 es 174 precision mediump float; 175 ${DECLARATIONS} 176 177 uniform int u_zero; 178 int sideEffectCounter = 0; 179 int funcWithSideEffects() { 180 sideEffectCounter++; 181 return 2; 182 } 183 void main() { 184 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 185 v[funcWithSideEffects()]++; 186 vec4 expected = vec4(1.0, 2.0, 4.0, 4.0); 187 f = 1.0 - distance(v, expected); 188 if (sideEffectCounter != 1) { 189 f = 0.0; 190 } 191 ${OUTPUT} 192 } 193 "" 194 end 195 196 case user_defined_fncall_inout_parameter_with_index_with_side_effects 197 version 300 es 198 values { output float f = 1.0; } 199 both "" 200 #version 300 es 201 precision mediump float; 202 ${DECLARATIONS} 203 204 uniform int u_zero; 205 int sideEffectCounter = 0; 206 void foo(inout float f) { 207 float g = f + 2.5; 208 modf(g, f); 209 } 210 int funcWithSideEffects() { 211 sideEffectCounter++; 212 return 2; 213 } 214 void main() { 215 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 216 foo(v[funcWithSideEffects()]); 217 vec4 expected = vec4(1.0, 2.0, 5.0, 4.0); 218 f = 1.0 - distance(v, expected); 219 if (sideEffectCounter != 1) { 220 f = 0.0; 221 } 222 ${OUTPUT} 223 } 224 "" 225 end 226 227 case lvalue_with_uint 228 version 300 es 229 values { output float f = 1.0; } 230 both "" 231 #version 300 es 232 precision mediump float; 233 ${DECLARATIONS} 234 235 uniform int u_zero; 236 void main() { 237 vec4 v = vec4(1.0, 2.0, 3.0, 4.0); 238 v[u_zero] = 5.0; 239 vec4 expected = vec4(5.0, 2.0, 3.0, 4.0); 240 f = 1.0 - distance(v, expected); 241 ${OUTPUT} 242 } 243 "" 244 end 245 246 case uniform 247 version 300 es 248 values { output float f = 0.0; } 249 both "" 250 #version 300 es 251 precision mediump float; 252 ${DECLARATIONS} 253 254 uniform vec4 u_zeroVec; 255 uniform int u_zero; 256 void main() { 257 f = u_zeroVec[u_zero]; 258 ${OUTPUT} 259 } 260 "" 261 end 262 263 case sequence_vector_lvalue 264 version 300 es 265 values { output bool success = true; } 266 both "" 267 #version 300 es 268 precision mediump float; 269 ${DECLARATIONS} 270 271 uniform int u_zero; 272 int sideEffectCounter = 0; 273 float func() { 274 ++sideEffectCounter; 275 return -1.0; 276 } 277 void main() { 278 vec4 v = vec4(0.0, 2.0, 4.0, 6.0); 279 float f = (func(), (++v[u_zero + sideEffectCounter])); 280 success = (abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCounter == 1); 281 ${OUTPUT} 282 } 283 "" 284 end 285 286 case matrix_twice_in_lvalue 287 version 300 es 288 values { output float f = 1.0; } 289 both "" 290 #version 300 es 291 precision mediump float; 292 ${DECLARATIONS} 293 294 uniform int u_zero; 295 void main() { 296 mat2 m = mat2(0.0, 0.0, 0.0, 0.0); 297 m[u_zero + 1][u_zero + 1] = float(u_zero + 1); 298 f = m[1][1]; 299 ${OUTPUT} 300 } 301 "" 302 end 303 304end # moredynamic 305