Commit a04070a
authored
Optimize gradient rendering on CPU (#1301)
Resolves #1300. This gets rid of all the interleave/deinterleave ops,
and just performs a bunch of straight array copies.
There's some nuance around handling NaNs. Previously, there were two
select operations done: one at the beginning, to set the LUT indices to
be in bounds if the corresponding *t* value was NaN, and one for each
channel to make the color value completely transparent if the
corresponding non-extended *t* value was NaN.
The second select operation is a bit awkward since the channel values
are now packed together, so I've added an extra transparent color value
to the end of each gradient LUT. If a *t* value is NaN, we set the LUT
index to that value instead. This only requires one select. It's a bit
ugly that we do this for all gradients in `vello_common` even though
it's only necessary for radial gradients on the CPU path; I'm very open
to ideas on how to make it better.
(EDIT: I've gone ahead and applied the same trick to the GPU path as
well.)
I've also wrapped all the gradient paint operations in `vectorize`
calls, since they were missing before and not actually being vectorized
as a result.
On my machine (Ryzen 7 7700x), this takes
`fine/gradient/linear/opaque_u8_avx2` from 830ns/iter to 620ns/iter, and
`fine/gradient/linear/opaque_f32_avx2` from 850ns/iter to 660ns/iter.
`fine/gradient/linear/opaque_f32_scalar` regresses from 890ns/iter to
1.1µs/iter, and I'm not sure why.
The `fine/gradient/linear/opaque_u8` benches appear to use the `lowp`
module's gradient painter, but the *tests* use the `common` module's
gradient painter. I don't know how to benchmark the latter, so the
`fine/gradient/linear/opaque_u8_avx2` gain seems to be solely from
adding the `vectorize` wrapper.1 parent 9c38a4a commit a04070a
File tree
6 files changed
+140
-132
lines changed- sparse_strips
- vello_common/src
- vello_cpu/src/fine
- common/gradient
- lowp
- vello_hybrid/src
- vello_sparse_shaders/shaders
6 files changed
+140
-132
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
710 | 720 | | |
711 | 721 | | |
712 | 722 | | |
| |||
734 | 744 | | |
735 | 745 | | |
736 | 746 | | |
737 | | - | |
| 747 | + | |
738 | 748 | | |
739 | 749 | | |
740 | 750 | | |
741 | 751 | | |
742 | 752 | | |
743 | | - | |
| 753 | + | |
744 | 754 | | |
745 | 755 | | |
746 | 756 | | |
| |||
960 | 970 | | |
961 | 971 | | |
962 | 972 | | |
| 973 | + | |
963 | 974 | | |
964 | 975 | | |
965 | 976 | | |
966 | 977 | | |
967 | | - | |
| 978 | + | |
968 | 979 | | |
969 | 980 | | |
970 | | - | |
971 | | - | |
972 | | - | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
973 | 986 | | |
974 | 987 | | |
975 | 988 | | |
| |||
995 | 1008 | | |
996 | 1009 | | |
997 | 1010 | | |
998 | | - | |
| 1011 | + | |
999 | 1012 | | |
1000 | 1013 | | |
1001 | 1014 | | |
| |||
1019 | 1032 | | |
1020 | 1033 | | |
1021 | 1034 | | |
| 1035 | + | |
1022 | 1036 | | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
1028 | 1041 | | |
1029 | 1042 | | |
1030 | 1043 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1035 | 1049 | | |
1036 | 1050 | | |
1037 | 1051 | | |
| |||
1046 | 1060 | | |
1047 | 1061 | | |
1048 | 1062 | | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1049 | 1083 | | |
1050 | 1084 | | |
1051 | 1085 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 53 | + | |
60 | 54 | | |
61 | 55 | | |
62 | 56 | | |
63 | 57 | | |
64 | 58 | | |
65 | 59 | | |
66 | | - | |
67 | 60 | | |
68 | 61 | | |
69 | 62 | | |
| |||
72 | 65 | | |
73 | 66 | | |
74 | 67 | | |
75 | | - | |
| 68 | + | |
76 | 69 | | |
77 | 70 | | |
78 | 71 | | |
79 | 72 | | |
80 | 73 | | |
81 | 74 | | |
82 | 75 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
92 | 87 | | |
93 | 88 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 89 | + | |
145 | 90 | | |
146 | 91 | | |
147 | 92 | | |
148 | 93 | | |
149 | 94 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
164 | 123 | | |
165 | 124 | | |
166 | 125 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
174 | 142 | | |
175 | 143 | | |
176 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
271 | 274 | | |
272 | 275 | | |
273 | 276 | | |
274 | 277 | | |
275 | 278 | | |
276 | 279 | | |
277 | 280 | | |
278 | | - | |
| 281 | + | |
279 | 282 | | |
280 | 283 | | |
281 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 84 | + | |
| 85 | + | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
| |||
272 | 271 | | |
273 | 272 | | |
274 | 273 | | |
275 | | - | |
| 274 | + | |
276 | 275 | | |
277 | 276 | | |
278 | 277 | | |
279 | 278 | | |
| 279 | + | |
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| |||
0 commit comments