skia2/tests/sksl/runtime/Switch.skvm
John Stiles cb40008b43 Implement switch in SkVM.
SkVM implements switches as a pseudo-loop; breaks are handled with the
condition mask just like a for loop. Fallthrough is handled via a
scratch Value in a temporary slot. `writeStore` neeeded to be refactored
to support writing into slot(s) without an associated Variable.

At IR generation time, SwitchStatements are now emitted without error
even in strict-ES2 mode. The GLSL code generator currently reports these
as an error in strict-ES2 mode, but this will be fixed in a followup
coming shortly (the switch will be rewritten as ifs inside a one-shot
loop, similar to our IR-rewrite strategy).

Change-Id: I5507257246c42a35d2f46b4b9a89492a5ffeff9b
Bug: skia:12450
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/451421
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-09-23 19:58:55 +00:00

39 lines
925 B
Plaintext

17 registers, 36 instructions:
0 r0 = uniform32 ptr0 4
1 r1 = uniform32 ptr0 8
2 r2 = uniform32 ptr0 C
3 r3 = uniform32 ptr0 10
4 r4 = uniform32 ptr0 14
5 r5 = uniform32 ptr0 18
6 r6 = uniform32 ptr0 1C
7 r7 = uniform32 ptr0 20
8 r8 = splat 0 (0)
9 r9 = splat FFFFFFFF (nan)
10 r10 = trunc r1
11 r8 = eq_i32 r8 r10
12 r11 = bit_and r7 r8
13 r12 = bit_and r6 r8
14 r13 = bit_and r5 r8
15 r14 = bit_and r4 r8
16 r15 = bit_xor r9 r8
17 r8 = bit_and r8 r15
18 r16 = splat 1 (1.4012985e-45)
19 r10 = eq_i32 r16 r10
20 r10 = bit_or r8 r10
21 r10 = bit_and r10 r15
22 r11 = select r10 r3 r11
23 r12 = select r10 r2 r12
24 r13 = select r10 r1 r13
25 r14 = select r10 r0 r14
26 r10 = bit_xor r9 r10
27 r10 = bit_and r15 r10
28 r11 = select r10 r7 r11
29 r12 = select r10 r6 r12
30 r13 = select r10 r5 r13
31 r14 = select r10 r4 r14
loop:
32 store32 ptr1 r14
33 store32 ptr2 r13
34 store32 ptr3 r12
35 store32 ptr4 r11